mesa: make buffer object-related driver fallback functions static
[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/buffers.h"
30 #include "main/context.h"
31 #include "main/framebuffer.h"
32 #include "main/mipmap.h"
33 #include "main/queryobj.h"
34 #include "main/renderbuffer.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
49 #include "shader/program.h"
50 #include "shader/prog_execute.h"
51 #include "shader/shader_api.h"
52 #include "tnl/tnl.h"
53 #include "swrast/swrast.h"
54
55 #include "driverfuncs.h"
56
57
58
59 /**
60 * Plug in default functions for all pointers in the dd_function_table
61 * structure.
62 * Device drivers should call this function and then plug in any
63 * functions which it wants to override.
64 * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
65 *
66 * \param table the dd_function_table to initialize
67 */
68 void
69 _mesa_init_driver_functions(struct dd_function_table *driver)
70 {
71 _mesa_bzero(driver, sizeof(*driver));
72
73 driver->GetString = NULL; /* REQUIRED! */
74 driver->UpdateState = NULL; /* REQUIRED! */
75 driver->GetBufferSize = NULL; /* REQUIRED! */
76 driver->ResizeBuffers = _mesa_resize_framebuffer;
77 driver->Error = NULL;
78
79 driver->Finish = NULL;
80 driver->Flush = NULL;
81
82 /* framebuffer/image functions */
83 driver->Clear = _swrast_Clear;
84 driver->Accum = _swrast_Accum;
85 driver->RasterPos = _tnl_RasterPos;
86 driver->DrawPixels = _swrast_DrawPixels;
87 driver->ReadPixels = _swrast_ReadPixels;
88 driver->CopyPixels = _swrast_CopyPixels;
89 driver->Bitmap = _swrast_Bitmap;
90
91 /* Texture functions */
92 driver->ChooseTextureFormat = _mesa_choose_tex_format;
93 driver->TexImage1D = _mesa_store_teximage1d;
94 driver->TexImage2D = _mesa_store_teximage2d;
95 driver->TexImage3D = _mesa_store_teximage3d;
96 driver->TexSubImage1D = _mesa_store_texsubimage1d;
97 driver->TexSubImage2D = _mesa_store_texsubimage2d;
98 driver->TexSubImage3D = _mesa_store_texsubimage3d;
99 driver->GetTexImage = _mesa_get_teximage;
100 driver->CopyTexImage1D = _swrast_copy_teximage1d;
101 driver->CopyTexImage2D = _swrast_copy_teximage2d;
102 driver->CopyTexSubImage1D = _swrast_copy_texsubimage1d;
103 driver->CopyTexSubImage2D = _swrast_copy_texsubimage2d;
104 driver->CopyTexSubImage3D = _swrast_copy_texsubimage3d;
105 driver->GenerateMipmap = _mesa_generate_mipmap;
106 driver->TestProxyTexImage = _mesa_test_proxy_teximage;
107 driver->CompressedTexImage1D = _mesa_store_compressed_teximage1d;
108 driver->CompressedTexImage2D = _mesa_store_compressed_teximage2d;
109 driver->CompressedTexImage3D = _mesa_store_compressed_teximage3d;
110 driver->CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
111 driver->CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
112 driver->CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
113 driver->GetCompressedTexImage = _mesa_get_compressed_teximage;
114 driver->CompressedTextureSize = _mesa_compressed_texture_size;
115 driver->BindTexture = NULL;
116 driver->NewTextureObject = _mesa_new_texture_object;
117 driver->DeleteTexture = _mesa_delete_texture_object;
118 driver->NewTextureImage = _mesa_new_texture_image;
119 driver->FreeTexImageData = _mesa_free_texture_image_data;
120 driver->MapTexture = NULL;
121 driver->UnmapTexture = NULL;
122 driver->TextureMemCpy = _mesa_memcpy;
123 driver->IsTextureResident = NULL;
124 driver->PrioritizeTexture = NULL;
125 driver->ActiveTexture = NULL;
126 driver->UpdateTexturePalette = NULL;
127
128 /* imaging */
129 driver->CopyColorTable = _swrast_CopyColorTable;
130 driver->CopyColorSubTable = _swrast_CopyColorSubTable;
131 driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
132 driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
133
134 /* Vertex/fragment programs */
135 driver->BindProgram = NULL;
136 driver->NewProgram = _mesa_new_program;
137 driver->DeleteProgram = _mesa_delete_program;
138
139 /* simple state commands */
140 driver->AlphaFunc = NULL;
141 driver->BlendColor = NULL;
142 driver->BlendEquationSeparate = NULL;
143 driver->BlendFuncSeparate = NULL;
144 driver->ClearColor = NULL;
145 driver->ClearDepth = NULL;
146 driver->ClearIndex = NULL;
147 driver->ClearStencil = NULL;
148 driver->ClipPlane = NULL;
149 driver->ColorMask = NULL;
150 driver->ColorMaterial = NULL;
151 driver->CullFace = NULL;
152 driver->DrawBuffer = NULL;
153 driver->DrawBuffers = NULL;
154 driver->FrontFace = NULL;
155 driver->DepthFunc = NULL;
156 driver->DepthMask = NULL;
157 driver->DepthRange = NULL;
158 driver->Enable = NULL;
159 driver->Fogfv = NULL;
160 driver->Hint = NULL;
161 driver->IndexMask = 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->TextureMatrix = NULL;
183 driver->Viewport = NULL;
184
185 /* vertex arrays */
186 driver->VertexPointer = NULL;
187 driver->NormalPointer = NULL;
188 driver->ColorPointer = NULL;
189 driver->FogCoordPointer = NULL;
190 driver->IndexPointer = NULL;
191 driver->SecondaryColorPointer = NULL;
192 driver->TexCoordPointer = NULL;
193 driver->EdgeFlagPointer = NULL;
194 driver->VertexAttribPointer = NULL;
195 driver->LockArraysEXT = NULL;
196 driver->UnlockArraysEXT = NULL;
197
198 /* state queries */
199 driver->GetBooleanv = NULL;
200 driver->GetDoublev = NULL;
201 driver->GetFloatv = NULL;
202 driver->GetIntegerv = NULL;
203 driver->GetPointerv = NULL;
204
205 _mesa_init_buffer_object_functions(driver);
206
207 #if FEATURE_EXT_framebuffer_object
208 driver->NewFramebuffer = _mesa_new_framebuffer;
209 driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
210 driver->RenderTexture = _mesa_render_texture;
211 driver->FinishRenderTexture = _mesa_finish_render_texture;
212 driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
213 #endif
214
215 #if FEATURE_EXT_framebuffer_blit
216 driver->BlitFramebuffer = _swrast_BlitFramebuffer;
217 #endif
218
219 /* query objects */
220 driver->NewQueryObject = _mesa_new_query_object;
221 driver->DeleteQuery = _mesa_delete_query;
222 driver->BeginQuery = _mesa_begin_query;
223 driver->EndQuery = _mesa_end_query;
224 driver->WaitQuery = _mesa_wait_query;
225 driver->CheckQuery = _mesa_check_query;
226
227 /* APPLE_vertex_array_object */
228 driver->NewArrayObject = _mesa_new_array_object;
229 driver->DeleteArrayObject = _mesa_delete_array_object;
230 driver->BindArrayObject = NULL;
231
232 /* T&L stuff */
233 driver->NeedValidate = GL_FALSE;
234 driver->ValidateTnlModule = NULL;
235 driver->CurrentExecPrimitive = 0;
236 driver->CurrentSavePrimitive = 0;
237 driver->NeedFlush = 0;
238 driver->SaveNeedFlush = 0;
239
240 driver->ProgramStringNotify = _tnl_program_string;
241 driver->FlushVertices = NULL;
242 driver->SaveFlushVertices = NULL;
243 driver->NotifySaveBegin = NULL;
244 driver->LightingSpaceChange = NULL;
245
246 /* display list */
247 driver->NewList = NULL;
248 driver->EndList = NULL;
249 driver->BeginCallList = NULL;
250 driver->EndCallList = NULL;
251
252
253 /* XXX temporary here */
254 _mesa_init_glsl_driver_functions(driver);
255 }
256
257
258 /**
259 * Call the ctx->Driver.* state functions with current values to initialize
260 * driver state.
261 * Only the Intel drivers use this so far.
262 */
263 void
264 _mesa_init_driver_state(GLcontext *ctx)
265 {
266 ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
267
268 ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
269
270 ctx->Driver.BlendEquationSeparate(ctx,
271 ctx->Color.BlendEquationRGB,
272 ctx->Color.BlendEquationA);
273
274 ctx->Driver.BlendFuncSeparate(ctx,
275 ctx->Color.BlendSrcRGB,
276 ctx->Color.BlendDstRGB,
277 ctx->Color.BlendSrcA, ctx->Color.BlendDstA);
278
279 ctx->Driver.ColorMask(ctx,
280 ctx->Color.ColorMask[RCOMP],
281 ctx->Color.ColorMask[GCOMP],
282 ctx->Color.ColorMask[BCOMP],
283 ctx->Color.ColorMask[ACOMP]);
284
285 ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
286 ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
287 ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
288
289 ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
290 ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
291 ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
292 ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
293 ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
294 ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
295 ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
296 ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
297 ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
298 ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
299 ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
300 ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
301 ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil._Enabled);
302 ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
303 ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
304 ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
305 ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
306 ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
307
308 ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
309 ctx->Driver.Fogfv(ctx, GL_FOG_MODE, 0);
310 ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
311 ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
312 ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
313
314 ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
315
316 {
317 GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
318 ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
319 }
320
321 ctx->Driver.LineWidth(ctx, ctx->Line.Width);
322 ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
323 ctx->Driver.PointSize(ctx, ctx->Point.Size);
324 ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
325 ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
326 ctx->Scissor.Width, ctx->Scissor.Height);
327 ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
328 ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
329 ctx->Stencil.Function[0],
330 ctx->Stencil.Ref[0],
331 ctx->Stencil.ValueMask[0]);
332 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
333 ctx->Stencil.Function[1],
334 ctx->Stencil.Ref[1],
335 ctx->Stencil.ValueMask[1]);
336 ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
337 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
338 ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
339 ctx->Stencil.FailFunc[0],
340 ctx->Stencil.ZFailFunc[0],
341 ctx->Stencil.ZPassFunc[0]);
342 ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
343 ctx->Stencil.FailFunc[1],
344 ctx->Stencil.ZFailFunc[1],
345 ctx->Stencil.ZPassFunc[1]);
346
347
348 ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
349 }