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