Merge branch 'gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / common / driverfuncs.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "glheader.h"
27 #include "imports.h"
28 #include "arrayobj.h"
29 #include "buffers.h"
30 #include "context.h"
31 #include "framebuffer.h"
32 #include "mipmap.h"
33 #include "queryobj.h"
34 #include "renderbuffer.h"
35 #include "texcompress.h"
36 #include "texformat.h"
37 #include "teximage.h"
38 #include "texobj.h"
39 #include "texstore.h"
40 #if FEATURE_ARB_vertex_buffer_object
41 #include "bufferobj.h"
42 #endif
43 #if FEATURE_EXT_framebuffer_object
44 #include "fbobject.h"
45 #include "texrender.h"
46 #endif
47
48 #include "shader/program.h"
49 #include "shader/prog_execute.h"
50 #include "shader/shader_api.h"
51 #include "driverfuncs.h"
52 #include "tnl/tnl.h"
53 #include "swrast/swrast.h"
54
55
56
57 /**
58 * Plug in default functions for all pointers in the dd_function_table
59 * structure.
60 * Device drivers should call this function and then plug in any
61 * functions which it wants to override.
62 * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
63 *
64 * \param table the dd_function_table to initialize
65 */
66 void
67 _mesa_init_driver_functions(struct dd_function_table *driver)
68 {
69 _mesa_bzero(driver, sizeof(*driver));
70
71 driver->GetString = NULL; /* REQUIRED! */
72 driver->UpdateState = NULL; /* REQUIRED! */
73 driver->GetBufferSize = NULL; /* REQUIRED! */
74 driver->ResizeBuffers = _mesa_resize_framebuffer;
75 driver->Error = NULL;
76
77 driver->Finish = NULL;
78 driver->Flush = NULL;
79
80 /* framebuffer/image functions */
81 driver->Clear = _swrast_Clear;
82 driver->Accum = _swrast_Accum;
83 driver->RasterPos = _tnl_RasterPos;
84 driver->DrawPixels = _swrast_DrawPixels;
85 driver->ReadPixels = _swrast_ReadPixels;
86 driver->CopyPixels = _swrast_CopyPixels;
87 driver->Bitmap = _swrast_Bitmap;
88
89 /* Texture functions */
90 driver->ChooseTextureFormat = _mesa_choose_tex_format;
91 driver->TexImage1D = _mesa_store_teximage1d;
92 driver->TexImage2D = _mesa_store_teximage2d;
93 driver->TexImage3D = _mesa_store_teximage3d;
94 driver->TexSubImage1D = _mesa_store_texsubimage1d;
95 driver->TexSubImage2D = _mesa_store_texsubimage2d;
96 driver->TexSubImage3D = _mesa_store_texsubimage3d;
97 driver->GetTexImage = _mesa_get_teximage;
98 driver->CopyTexImage1D = _swrast_copy_teximage1d;
99 driver->CopyTexImage2D = _swrast_copy_teximage2d;
100 driver->CopyTexSubImage1D = _swrast_copy_texsubimage1d;
101 driver->CopyTexSubImage2D = _swrast_copy_texsubimage2d;
102 driver->CopyTexSubImage3D = _swrast_copy_texsubimage3d;
103 driver->GenerateMipmap = _mesa_generate_mipmap;
104 driver->TestProxyTexImage = _mesa_test_proxy_teximage;
105 driver->CompressedTexImage1D = _mesa_store_compressed_teximage1d;
106 driver->CompressedTexImage2D = _mesa_store_compressed_teximage2d;
107 driver->CompressedTexImage3D = _mesa_store_compressed_teximage3d;
108 driver->CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
109 driver->CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
110 driver->CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
111 driver->GetCompressedTexImage = _mesa_get_compressed_teximage;
112 driver->CompressedTextureSize = _mesa_compressed_texture_size;
113 driver->BindTexture = NULL;
114 driver->NewTextureObject = _mesa_new_texture_object;
115 driver->DeleteTexture = _mesa_delete_texture_object;
116 driver->NewTextureImage = _mesa_new_texture_image;
117 driver->FreeTexImageData = _mesa_free_texture_image_data;
118 driver->MapTexture = NULL;
119 driver->UnmapTexture = NULL;
120 driver->TextureMemCpy = _mesa_memcpy;
121 driver->IsTextureResident = NULL;
122 driver->PrioritizeTexture = NULL;
123 driver->ActiveTexture = NULL;
124 driver->UpdateTexturePalette = NULL;
125
126 /* imaging */
127 driver->CopyColorTable = _swrast_CopyColorTable;
128 driver->CopyColorSubTable = _swrast_CopyColorSubTable;
129 driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
130 driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
131
132 /* Vertex/fragment programs */
133 driver->BindProgram = NULL;
134 driver->NewProgram = _mesa_new_program;
135 driver->DeleteProgram = _mesa_delete_program;
136 #if FEATURE_MESA_program_debug
137 driver->GetProgramRegister = _mesa_get_program_register;
138 #endif /* FEATURE_MESA_program_debug */
139
140 /* simple state commands */
141 driver->AlphaFunc = NULL;
142 driver->BlendColor = NULL;
143 driver->BlendEquationSeparate = NULL;
144 driver->BlendFuncSeparate = NULL;
145 driver->ClearColor = NULL;
146 driver->ClearDepth = NULL;
147 driver->ClearIndex = NULL;
148 driver->ClearStencil = NULL;
149 driver->ClipPlane = NULL;
150 driver->ColorMask = NULL;
151 driver->ColorMaterial = NULL;
152 driver->CullFace = NULL;
153 driver->DrawBuffer = NULL;
154 driver->DrawBuffers = NULL;
155 driver->FrontFace = NULL;
156 driver->DepthFunc = NULL;
157 driver->DepthMask = NULL;
158 driver->DepthRange = NULL;
159 driver->Enable = NULL;
160 driver->Fogfv = NULL;
161 driver->Hint = NULL;
162 driver->IndexMask = NULL;
163 driver->Lightfv = NULL;
164 driver->LightModelfv = NULL;
165 driver->LineStipple = NULL;
166 driver->LineWidth = NULL;
167 driver->LogicOpcode = NULL;
168 driver->PointParameterfv = NULL;
169 driver->PointSize = NULL;
170 driver->PolygonMode = NULL;
171 driver->PolygonOffset = NULL;
172 driver->PolygonStipple = NULL;
173 driver->ReadBuffer = NULL;
174 driver->RenderMode = NULL;
175 driver->Scissor = NULL;
176 driver->ShadeModel = NULL;
177 driver->StencilFuncSeparate = NULL;
178 driver->StencilOpSeparate = NULL;
179 driver->StencilMaskSeparate = NULL;
180 driver->TexGen = NULL;
181 driver->TexEnv = NULL;
182 driver->TexParameter = NULL;
183 driver->TextureMatrix = NULL;
184 driver->Viewport = NULL;
185
186 /* vertex arrays */
187 driver->VertexPointer = NULL;
188 driver->NormalPointer = NULL;
189 driver->ColorPointer = NULL;
190 driver->FogCoordPointer = NULL;
191 driver->IndexPointer = NULL;
192 driver->SecondaryColorPointer = NULL;
193 driver->TexCoordPointer = NULL;
194 driver->EdgeFlagPointer = NULL;
195 driver->VertexAttribPointer = NULL;
196 driver->LockArraysEXT = NULL;
197 driver->UnlockArraysEXT = NULL;
198
199 /* state queries */
200 driver->GetBooleanv = NULL;
201 driver->GetDoublev = NULL;
202 driver->GetFloatv = NULL;
203 driver->GetIntegerv = NULL;
204 driver->GetPointerv = NULL;
205
206 #if FEATURE_ARB_vertex_buffer_object
207 driver->NewBufferObject = _mesa_new_buffer_object;
208 driver->DeleteBuffer = _mesa_delete_buffer_object;
209 driver->BindBuffer = NULL;
210 driver->BufferData = _mesa_buffer_data;
211 driver->BufferSubData = _mesa_buffer_subdata;
212 driver->GetBufferSubData = _mesa_buffer_get_subdata;
213 driver->MapBuffer = _mesa_buffer_map;
214 driver->UnmapBuffer = _mesa_buffer_unmap;
215 #endif
216
217 #if FEATURE_EXT_framebuffer_object
218 driver->NewFramebuffer = _mesa_new_framebuffer;
219 driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
220 driver->RenderTexture = _mesa_render_texture;
221 driver->FinishRenderTexture = _mesa_finish_render_texture;
222 driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
223 #endif
224
225 #if FEATURE_EXT_framebuffer_blit
226 driver->BlitFramebuffer = _swrast_BlitFramebuffer;
227 #endif
228
229 /* query objects */
230 driver->NewQueryObject = _mesa_new_query_object;
231 driver->DeleteQuery = _mesa_delete_query;
232 driver->BeginQuery = _mesa_begin_query;
233 driver->EndQuery = _mesa_end_query;
234 driver->WaitQuery = _mesa_wait_query;
235
236 /* APPLE_vertex_array_object */
237 driver->NewArrayObject = _mesa_new_array_object;
238 driver->DeleteArrayObject = _mesa_delete_array_object;
239 driver->BindArrayObject = NULL;
240
241 /* T&L stuff */
242 driver->NeedValidate = GL_FALSE;
243 driver->ValidateTnlModule = NULL;
244 driver->CurrentExecPrimitive = 0;
245 driver->CurrentSavePrimitive = 0;
246 driver->NeedFlush = 0;
247 driver->SaveNeedFlush = 0;
248
249 driver->ProgramStringNotify = _tnl_program_string;
250 driver->FlushVertices = NULL;
251 driver->SaveFlushVertices = NULL;
252 driver->NotifySaveBegin = NULL;
253 driver->LightingSpaceChange = NULL;
254
255 /* display list */
256 driver->NewList = NULL;
257 driver->EndList = NULL;
258 driver->BeginCallList = NULL;
259 driver->EndCallList = NULL;
260
261
262 /* XXX temporary here */
263 _mesa_init_glsl_driver_functions(driver);
264 }
265
266
267 /**
268 * Call the ctx->Driver.* state functions with current values to initialize
269 * driver state.
270 * Only the Intel drivers use this so far.
271 */
272 void
273 _mesa_init_driver_state(GLcontext *ctx)
274 {
275 ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
276
277 ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
278
279 ctx->Driver.BlendEquationSeparate(ctx,
280 ctx->Color.BlendEquationRGB,
281 ctx->Color.BlendEquationA);
282
283 ctx->Driver.BlendFuncSeparate(ctx,
284 ctx->Color.BlendSrcRGB,
285 ctx->Color.BlendDstRGB,
286 ctx->Color.BlendSrcA, ctx->Color.BlendDstA);
287
288 ctx->Driver.ColorMask(ctx,
289 ctx->Color.ColorMask[RCOMP],
290 ctx->Color.ColorMask[GCOMP],
291 ctx->Color.ColorMask[BCOMP],
292 ctx->Color.ColorMask[ACOMP]);
293
294 ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
295 ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
296 ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
297
298 ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
299 ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
300 ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
301 ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
302 ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
303 ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
304 ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
305 ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
306 ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
307 ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
308 ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
309 ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
310 ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled);
311 ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
312 ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
313 ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
314 ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
315 ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
316
317 ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
318 ctx->Driver.Fogfv(ctx, GL_FOG_MODE, 0);
319 ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
320 ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
321 ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
322
323 ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
324
325 {
326 GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
327 ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
328 }
329
330 ctx->Driver.LineWidth(ctx, ctx->Line.Width);
331 ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
332 ctx->Driver.PointSize(ctx, ctx->Point.Size);
333 ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
334 ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
335 ctx->Scissor.Width, ctx->Scissor.Height);
336 ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
337 ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
338 ctx->Stencil.Function[0],
339 ctx->Stencil.Ref[0],
340 ctx->Stencil.ValueMask[0]);
341 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
342 ctx->Stencil.Function[1],
343 ctx->Stencil.Ref[1],
344 ctx->Stencil.ValueMask[1]);
345 ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
346 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
347 ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
348 ctx->Stencil.FailFunc[0],
349 ctx->Stencil.ZFailFunc[0],
350 ctx->Stencil.ZPassFunc[0]);
351 ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
352 ctx->Stencil.FailFunc[1],
353 ctx->Stencil.ZFailFunc[1],
354 ctx->Stencil.ZPassFunc[1]);
355
356
357 ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
358 }