227710fb025818d4b72c767dc6767792f02f151f
[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 "main/glheader.h"
27 #include "main/imports.h"
28 #include "main/arrayobj.h"
29 #include "main/context.h"
30 #include "main/framebuffer.h"
31 #include "main/mipmap.h"
32 #include "main/queryobj.h"
33 #include "main/renderbuffer.h"
34 #include "main/shaderobj.h"
35 #include "main/texcompress.h"
36 #include "main/texformat.h"
37 #include "main/texgetimage.h"
38 #include "main/teximage.h"
39 #include "main/texobj.h"
40 #include "main/texstore.h"
41 #if FEATURE_ARB_vertex_buffer_object
42 #include "main/bufferobj.h"
43 #endif
44 #if FEATURE_EXT_framebuffer_object
45 #include "main/fbobject.h"
46 #include "main/texrender.h"
47 #endif
48 #if FEATURE_ARB_sync
49 #include "main/syncobj.h"
50 #endif
51 #if FEATURE_EXT_transform_feedback
52 #include "main/transformfeedback.h"
53 #endif
54
55 #include "program/program.h"
56 #include "tnl/tnl.h"
57 #include "swrast/swrast.h"
58
59 #include "driverfuncs.h"
60 #include "meta.h"
61
62
63
64 /**
65 * Plug in default functions for all pointers in the dd_function_table
66 * structure.
67 * Device drivers should call this function and then plug in any
68 * functions which it wants to override.
69 * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
70 *
71 * \param table the dd_function_table to initialize
72 */
73 void
74 _mesa_init_driver_functions(struct dd_function_table *driver)
75 {
76 memset(driver, 0, sizeof(*driver));
77
78 driver->GetString = NULL; /* REQUIRED! */
79 driver->UpdateState = NULL; /* REQUIRED! */
80 driver->GetBufferSize = NULL; /* REQUIRED! */
81 driver->ResizeBuffers = _mesa_resize_framebuffer;
82 driver->Error = NULL;
83
84 driver->Finish = NULL;
85 driver->Flush = NULL;
86
87 /* framebuffer/image functions */
88 driver->Clear = _swrast_Clear;
89 driver->Accum = _swrast_Accum;
90 driver->RasterPos = _tnl_RasterPos;
91 driver->DrawPixels = _swrast_DrawPixels;
92 driver->ReadPixels = _swrast_ReadPixels;
93 driver->CopyPixels = _swrast_CopyPixels;
94 driver->Bitmap = _swrast_Bitmap;
95
96 /* Texture functions */
97 driver->ChooseTextureFormat = _mesa_choose_tex_format;
98 driver->TexImage1D = _mesa_store_teximage1d;
99 driver->TexImage2D = _mesa_store_teximage2d;
100 driver->TexImage3D = _mesa_store_teximage3d;
101 driver->TexSubImage1D = _mesa_store_texsubimage1d;
102 driver->TexSubImage2D = _mesa_store_texsubimage2d;
103 driver->TexSubImage3D = _mesa_store_texsubimage3d;
104 driver->GetTexImage = _mesa_get_teximage;
105 driver->CopyTexImage1D = _mesa_meta_CopyTexImage1D;
106 driver->CopyTexImage2D = _mesa_meta_CopyTexImage2D;
107 driver->CopyTexSubImage1D = _mesa_meta_CopyTexSubImage1D;
108 driver->CopyTexSubImage2D = _mesa_meta_CopyTexSubImage2D;
109 driver->CopyTexSubImage3D = _mesa_meta_CopyTexSubImage3D;
110 driver->GenerateMipmap = _mesa_meta_GenerateMipmap;
111 driver->TestProxyTexImage = _mesa_test_proxy_teximage;
112 driver->CompressedTexImage1D = _mesa_store_compressed_teximage1d;
113 driver->CompressedTexImage2D = _mesa_store_compressed_teximage2d;
114 driver->CompressedTexImage3D = _mesa_store_compressed_teximage3d;
115 driver->CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
116 driver->CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
117 driver->CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
118 driver->GetCompressedTexImage = _mesa_get_compressed_teximage;
119 driver->BindTexture = NULL;
120 driver->NewTextureObject = _mesa_new_texture_object;
121 driver->DeleteTexture = _mesa_delete_texture_object;
122 driver->NewTextureImage = _mesa_new_texture_image;
123 driver->FreeTexImageData = _mesa_free_texture_image_data;
124 driver->MapTexture = NULL;
125 driver->UnmapTexture = NULL;
126 driver->TextureMemCpy = memcpy;
127 driver->IsTextureResident = NULL;
128 driver->UpdateTexturePalette = NULL;
129
130 /* imaging */
131 driver->CopyColorTable = _mesa_meta_CopyColorTable;
132 driver->CopyColorSubTable = _mesa_meta_CopyColorSubTable;
133 driver->CopyConvolutionFilter1D = _mesa_meta_CopyConvolutionFilter1D;
134 driver->CopyConvolutionFilter2D = _mesa_meta_CopyConvolutionFilter2D;
135
136 /* Vertex/fragment programs */
137 driver->BindProgram = NULL;
138 driver->NewProgram = _mesa_new_program;
139 driver->DeleteProgram = _mesa_delete_program;
140
141 /* simple state commands */
142 driver->AlphaFunc = NULL;
143 driver->BlendColor = NULL;
144 driver->BlendEquationSeparate = NULL;
145 driver->BlendFuncSeparate = NULL;
146 driver->ClearColor = NULL;
147 driver->ClearDepth = 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->Lightfv = NULL;
163 driver->LightModelfv = NULL;
164 driver->LineStipple = NULL;
165 driver->LineWidth = NULL;
166 driver->LogicOpcode = NULL;
167 driver->PointParameterfv = NULL;
168 driver->PointSize = NULL;
169 driver->PolygonMode = NULL;
170 driver->PolygonOffset = NULL;
171 driver->PolygonStipple = NULL;
172 driver->ReadBuffer = NULL;
173 driver->RenderMode = NULL;
174 driver->Scissor = NULL;
175 driver->ShadeModel = NULL;
176 driver->StencilFuncSeparate = NULL;
177 driver->StencilOpSeparate = NULL;
178 driver->StencilMaskSeparate = NULL;
179 driver->TexGen = NULL;
180 driver->TexEnv = NULL;
181 driver->TexParameter = NULL;
182 driver->Viewport = NULL;
183
184 /* buffer objects */
185 _mesa_init_buffer_object_functions(driver);
186
187 /* query objects */
188 _mesa_init_query_object_functions(driver);
189
190 #if FEATURE_ARB_sync
191 _mesa_init_sync_object_functions(driver);
192 #endif
193
194 #if FEATURE_EXT_framebuffer_object
195 driver->NewFramebuffer = _mesa_new_framebuffer;
196 driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
197 driver->RenderTexture = _mesa_render_texture;
198 driver->FinishRenderTexture = _mesa_finish_render_texture;
199 driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
200 #endif
201
202 #if FEATURE_EXT_framebuffer_blit
203 driver->BlitFramebuffer = _swrast_BlitFramebuffer;
204 #endif
205
206 /* APPLE_vertex_array_object */
207 driver->NewArrayObject = _mesa_new_array_object;
208 driver->DeleteArrayObject = _mesa_delete_array_object;
209 driver->BindArrayObject = NULL;
210
211 _mesa_init_shader_object_functions(driver);
212
213 #if FEATURE_EXT_transform_feedback
214 _mesa_init_transform_feedback_functions(driver);
215 #endif
216
217 /* T&L stuff */
218 driver->NeedValidate = GL_FALSE;
219 driver->ValidateTnlModule = NULL;
220 driver->CurrentExecPrimitive = 0;
221 driver->CurrentSavePrimitive = 0;
222 driver->NeedFlush = 0;
223 driver->SaveNeedFlush = 0;
224
225 driver->ProgramStringNotify = _tnl_program_string;
226 driver->FlushVertices = NULL;
227 driver->SaveFlushVertices = NULL;
228 driver->NotifySaveBegin = NULL;
229 driver->LightingSpaceChange = NULL;
230
231 /* display list */
232 driver->NewList = NULL;
233 driver->EndList = NULL;
234 driver->BeginCallList = NULL;
235 driver->EndCallList = NULL;
236 }
237
238
239 /**
240 * Call the ctx->Driver.* state functions with current values to initialize
241 * driver state.
242 * Only the Intel drivers use this so far.
243 */
244 void
245 _mesa_init_driver_state(GLcontext *ctx)
246 {
247 ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
248
249 ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
250
251 ctx->Driver.BlendEquationSeparate(ctx,
252 ctx->Color.BlendEquationRGB,
253 ctx->Color.BlendEquationA);
254
255 ctx->Driver.BlendFuncSeparate(ctx,
256 ctx->Color.BlendSrcRGB,
257 ctx->Color.BlendDstRGB,
258 ctx->Color.BlendSrcA, ctx->Color.BlendDstA);
259
260 if (ctx->Driver.ColorMaskIndexed) {
261 GLuint i;
262 for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
263 ctx->Driver.ColorMaskIndexed(ctx, i,
264 ctx->Color.ColorMask[0][RCOMP],
265 ctx->Color.ColorMask[0][GCOMP],
266 ctx->Color.ColorMask[0][BCOMP],
267 ctx->Color.ColorMask[0][ACOMP]);
268 }
269 }
270 else {
271 ctx->Driver.ColorMask(ctx,
272 ctx->Color.ColorMask[0][RCOMP],
273 ctx->Color.ColorMask[0][GCOMP],
274 ctx->Color.ColorMask[0][BCOMP],
275 ctx->Color.ColorMask[0][ACOMP]);
276 }
277
278 ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
279 ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
280 ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
281
282 ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
283 ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
284 ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
285 ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
286 ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
287 ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
288 ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
289 ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
290 ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
291 ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
292 ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
293 ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
294 ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil._Enabled);
295 ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
296 ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
297 ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
298 ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
299 ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
300
301 ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
302 ctx->Driver.Fogfv(ctx, GL_FOG_MODE, 0);
303 ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
304 ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
305 ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
306
307 ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
308
309 {
310 GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
311 ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
312 }
313
314 ctx->Driver.LineWidth(ctx, ctx->Line.Width);
315 ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
316 ctx->Driver.PointSize(ctx, ctx->Point.Size);
317 ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
318 ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
319 ctx->Scissor.Width, ctx->Scissor.Height);
320 ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
321 ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
322 ctx->Stencil.Function[0],
323 ctx->Stencil.Ref[0],
324 ctx->Stencil.ValueMask[0]);
325 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
326 ctx->Stencil.Function[1],
327 ctx->Stencil.Ref[1],
328 ctx->Stencil.ValueMask[1]);
329 ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
330 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
331 ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
332 ctx->Stencil.FailFunc[0],
333 ctx->Stencil.ZFailFunc[0],
334 ctx->Stencil.ZPassFunc[0]);
335 ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
336 ctx->Stencil.FailFunc[1],
337 ctx->Stencil.ZFailFunc[1],
338 ctx->Stencil.ZPassFunc[1]);
339
340
341 ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
342 }