2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
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"
44 #if FEATURE_EXT_framebuffer_object
45 #include "main/fbobject.h"
46 #include "main/texrender.h"
49 #include "main/syncobj.h"
52 #include "shader/program.h"
53 #include "shader/prog_execute.h"
54 #include "shader/shader_api.h"
56 #include "swrast/swrast.h"
58 #include "driverfuncs.h"
64 * Plug in default functions for all pointers in the dd_function_table
66 * Device drivers should call this function and then plug in any
67 * functions which it wants to override.
68 * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
70 * \param table the dd_function_table to initialize
73 _mesa_init_driver_functions(struct dd_function_table
*driver
)
75 _mesa_bzero(driver
, sizeof(*driver
));
77 driver
->GetString
= NULL
; /* REQUIRED! */
78 driver
->UpdateState
= NULL
; /* REQUIRED! */
79 driver
->GetBufferSize
= NULL
; /* REQUIRED! */
80 driver
->ResizeBuffers
= _mesa_resize_framebuffer
;
83 driver
->Finish
= NULL
;
86 /* framebuffer/image functions */
87 driver
->Clear
= _swrast_Clear
;
88 driver
->Accum
= _swrast_Accum
;
89 driver
->RasterPos
= _tnl_RasterPos
;
90 driver
->DrawPixels
= _swrast_DrawPixels
;
91 driver
->ReadPixels
= _swrast_ReadPixels
;
92 driver
->CopyPixels
= _swrast_CopyPixels
;
93 driver
->Bitmap
= _swrast_Bitmap
;
95 /* Texture functions */
96 driver
->ChooseTextureFormat
= _mesa_choose_tex_format
;
97 driver
->TexImage1D
= _mesa_store_teximage1d
;
98 driver
->TexImage2D
= _mesa_store_teximage2d
;
99 driver
->TexImage3D
= _mesa_store_teximage3d
;
100 driver
->TexSubImage1D
= _mesa_store_texsubimage1d
;
101 driver
->TexSubImage2D
= _mesa_store_texsubimage2d
;
102 driver
->TexSubImage3D
= _mesa_store_texsubimage3d
;
103 driver
->GetTexImage
= _mesa_get_teximage
;
104 driver
->CopyTexImage1D
= _mesa_meta_CopyTexImage1D
;
105 driver
->CopyTexImage2D
= _mesa_meta_CopyTexImage2D
;
106 driver
->CopyTexSubImage1D
= _mesa_meta_CopyTexSubImage1D
;
107 driver
->CopyTexSubImage2D
= _mesa_meta_CopyTexSubImage2D
;
108 driver
->CopyTexSubImage3D
= _mesa_meta_CopyTexSubImage3D
;
109 driver
->GenerateMipmap
= _mesa_generate_mipmap
;
110 driver
->TestProxyTexImage
= _mesa_test_proxy_teximage
;
111 driver
->CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
112 driver
->CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
113 driver
->CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
114 driver
->CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
115 driver
->CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
116 driver
->CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
117 driver
->GetCompressedTexImage
= _mesa_get_compressed_teximage
;
118 driver
->CompressedTextureSize
= _mesa_compressed_texture_size
;
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
= _mesa_memcpy
;
127 driver
->IsTextureResident
= NULL
;
128 driver
->PrioritizeTexture
= NULL
;
129 driver
->ActiveTexture
= NULL
;
130 driver
->UpdateTexturePalette
= NULL
;
133 driver
->CopyColorTable
= _mesa_meta_CopyColorTable
;
134 driver
->CopyColorSubTable
= _mesa_meta_CopyColorSubTable
;
135 driver
->CopyConvolutionFilter1D
= _mesa_meta_CopyConvolutionFilter1D
;
136 driver
->CopyConvolutionFilter2D
= _mesa_meta_CopyConvolutionFilter2D
;
138 /* Vertex/fragment programs */
139 driver
->BindProgram
= NULL
;
140 driver
->NewProgram
= _mesa_new_program
;
141 driver
->DeleteProgram
= _mesa_delete_program
;
143 /* simple state commands */
144 driver
->AlphaFunc
= NULL
;
145 driver
->BlendColor
= NULL
;
146 driver
->BlendEquationSeparate
= NULL
;
147 driver
->BlendFuncSeparate
= NULL
;
148 driver
->ClearColor
= NULL
;
149 driver
->ClearDepth
= NULL
;
150 driver
->ClearIndex
= NULL
;
151 driver
->ClearStencil
= NULL
;
152 driver
->ClipPlane
= NULL
;
153 driver
->ColorMask
= NULL
;
154 driver
->ColorMaterial
= NULL
;
155 driver
->CullFace
= NULL
;
156 driver
->DrawBuffer
= NULL
;
157 driver
->DrawBuffers
= NULL
;
158 driver
->FrontFace
= NULL
;
159 driver
->DepthFunc
= NULL
;
160 driver
->DepthMask
= NULL
;
161 driver
->DepthRange
= NULL
;
162 driver
->Enable
= NULL
;
163 driver
->Fogfv
= NULL
;
165 driver
->IndexMask
= NULL
;
166 driver
->Lightfv
= NULL
;
167 driver
->LightModelfv
= NULL
;
168 driver
->LineStipple
= NULL
;
169 driver
->LineWidth
= NULL
;
170 driver
->LogicOpcode
= NULL
;
171 driver
->PointParameterfv
= NULL
;
172 driver
->PointSize
= NULL
;
173 driver
->PolygonMode
= NULL
;
174 driver
->PolygonOffset
= NULL
;
175 driver
->PolygonStipple
= NULL
;
176 driver
->ReadBuffer
= NULL
;
177 driver
->RenderMode
= NULL
;
178 driver
->Scissor
= NULL
;
179 driver
->ShadeModel
= NULL
;
180 driver
->StencilFuncSeparate
= NULL
;
181 driver
->StencilOpSeparate
= NULL
;
182 driver
->StencilMaskSeparate
= NULL
;
183 driver
->TexGen
= NULL
;
184 driver
->TexEnv
= NULL
;
185 driver
->TexParameter
= NULL
;
186 driver
->TextureMatrix
= NULL
;
187 driver
->Viewport
= NULL
;
190 driver
->VertexPointer
= NULL
;
191 driver
->NormalPointer
= NULL
;
192 driver
->ColorPointer
= NULL
;
193 driver
->FogCoordPointer
= NULL
;
194 driver
->IndexPointer
= NULL
;
195 driver
->SecondaryColorPointer
= NULL
;
196 driver
->TexCoordPointer
= NULL
;
197 driver
->EdgeFlagPointer
= NULL
;
198 driver
->VertexAttribPointer
= NULL
;
199 driver
->LockArraysEXT
= NULL
;
200 driver
->UnlockArraysEXT
= NULL
;
203 driver
->GetBooleanv
= NULL
;
204 driver
->GetDoublev
= NULL
;
205 driver
->GetFloatv
= NULL
;
206 driver
->GetIntegerv
= NULL
;
207 driver
->GetInteger64v
= NULL
;
208 driver
->GetPointerv
= NULL
;
211 _mesa_init_buffer_object_functions(driver
);
214 _mesa_init_query_object_functions(driver
);
217 _mesa_init_sync_object_functions(driver
);
220 #if FEATURE_EXT_framebuffer_object
221 driver
->NewFramebuffer
= _mesa_new_framebuffer
;
222 driver
->NewRenderbuffer
= _mesa_new_soft_renderbuffer
;
223 driver
->RenderTexture
= _mesa_render_texture
;
224 driver
->FinishRenderTexture
= _mesa_finish_render_texture
;
225 driver
->FramebufferRenderbuffer
= _mesa_framebuffer_renderbuffer
;
228 #if FEATURE_EXT_framebuffer_blit
229 driver
->BlitFramebuffer
= _swrast_BlitFramebuffer
;
232 /* APPLE_vertex_array_object */
233 driver
->NewArrayObject
= _mesa_new_array_object
;
234 driver
->DeleteArrayObject
= _mesa_delete_array_object
;
235 driver
->BindArrayObject
= NULL
;
238 driver
->NeedValidate
= GL_FALSE
;
239 driver
->ValidateTnlModule
= NULL
;
240 driver
->CurrentExecPrimitive
= 0;
241 driver
->CurrentSavePrimitive
= 0;
242 driver
->NeedFlush
= 0;
243 driver
->SaveNeedFlush
= 0;
245 driver
->ProgramStringNotify
= _tnl_program_string
;
246 driver
->FlushVertices
= NULL
;
247 driver
->SaveFlushVertices
= NULL
;
248 driver
->NotifySaveBegin
= NULL
;
249 driver
->LightingSpaceChange
= NULL
;
252 driver
->NewList
= NULL
;
253 driver
->EndList
= NULL
;
254 driver
->BeginCallList
= NULL
;
255 driver
->EndCallList
= NULL
;
258 /* XXX temporary here */
259 _mesa_init_glsl_driver_functions(driver
);
264 * Call the ctx->Driver.* state functions with current values to initialize
266 * Only the Intel drivers use this so far.
269 _mesa_init_driver_state(GLcontext
*ctx
)
271 ctx
->Driver
.AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
273 ctx
->Driver
.BlendColor(ctx
, ctx
->Color
.BlendColor
);
275 ctx
->Driver
.BlendEquationSeparate(ctx
,
276 ctx
->Color
.BlendEquationRGB
,
277 ctx
->Color
.BlendEquationA
);
279 ctx
->Driver
.BlendFuncSeparate(ctx
,
280 ctx
->Color
.BlendSrcRGB
,
281 ctx
->Color
.BlendDstRGB
,
282 ctx
->Color
.BlendSrcA
, ctx
->Color
.BlendDstA
);
284 ctx
->Driver
.ColorMask(ctx
,
285 ctx
->Color
.ColorMask
[RCOMP
],
286 ctx
->Color
.ColorMask
[GCOMP
],
287 ctx
->Color
.ColorMask
[BCOMP
],
288 ctx
->Color
.ColorMask
[ACOMP
]);
290 ctx
->Driver
.CullFace(ctx
, ctx
->Polygon
.CullFaceMode
);
291 ctx
->Driver
.DepthFunc(ctx
, ctx
->Depth
.Func
);
292 ctx
->Driver
.DepthMask(ctx
, ctx
->Depth
.Mask
);
294 ctx
->Driver
.Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
295 ctx
->Driver
.Enable(ctx
, GL_BLEND
, ctx
->Color
.BlendEnabled
);
296 ctx
->Driver
.Enable(ctx
, GL_COLOR_LOGIC_OP
, ctx
->Color
.ColorLogicOpEnabled
);
297 ctx
->Driver
.Enable(ctx
, GL_COLOR_SUM
, ctx
->Fog
.ColorSumEnabled
);
298 ctx
->Driver
.Enable(ctx
, GL_CULL_FACE
, ctx
->Polygon
.CullFlag
);
299 ctx
->Driver
.Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
300 ctx
->Driver
.Enable(ctx
, GL_DITHER
, ctx
->Color
.DitherFlag
);
301 ctx
->Driver
.Enable(ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
302 ctx
->Driver
.Enable(ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
303 ctx
->Driver
.Enable(ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
304 ctx
->Driver
.Enable(ctx
, GL_POLYGON_STIPPLE
, ctx
->Polygon
.StippleFlag
);
305 ctx
->Driver
.Enable(ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.Enabled
);
306 ctx
->Driver
.Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
._Enabled
);
307 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_1D
, GL_FALSE
);
308 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_2D
, GL_FALSE
);
309 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_RECTANGLE_NV
, GL_FALSE
);
310 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_3D
, GL_FALSE
);
311 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
313 ctx
->Driver
.Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
314 ctx
->Driver
.Fogfv(ctx
, GL_FOG_MODE
, 0);
315 ctx
->Driver
.Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
316 ctx
->Driver
.Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
317 ctx
->Driver
.Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
319 ctx
->Driver
.FrontFace(ctx
, ctx
->Polygon
.FrontFace
);
322 GLfloat f
= (GLfloat
) ctx
->Light
.Model
.ColorControl
;
323 ctx
->Driver
.LightModelfv(ctx
, GL_LIGHT_MODEL_COLOR_CONTROL
, &f
);
326 ctx
->Driver
.LineWidth(ctx
, ctx
->Line
.Width
);
327 ctx
->Driver
.LogicOpcode(ctx
, ctx
->Color
.LogicOp
);
328 ctx
->Driver
.PointSize(ctx
, ctx
->Point
.Size
);
329 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) ctx
->PolygonStipple
);
330 ctx
->Driver
.Scissor(ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
331 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
332 ctx
->Driver
.ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
333 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_FRONT
,
334 ctx
->Stencil
.Function
[0],
336 ctx
->Stencil
.ValueMask
[0]);
337 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_BACK
,
338 ctx
->Stencil
.Function
[1],
340 ctx
->Stencil
.ValueMask
[1]);
341 ctx
->Driver
.StencilMaskSeparate(ctx
, GL_FRONT
, ctx
->Stencil
.WriteMask
[0]);
342 ctx
->Driver
.StencilMaskSeparate(ctx
, GL_BACK
, ctx
->Stencil
.WriteMask
[1]);
343 ctx
->Driver
.StencilOpSeparate(ctx
, GL_FRONT
,
344 ctx
->Stencil
.FailFunc
[0],
345 ctx
->Stencil
.ZFailFunc
[0],
346 ctx
->Stencil
.ZPassFunc
[0]);
347 ctx
->Driver
.StencilOpSeparate(ctx
, GL_BACK
,
348 ctx
->Stencil
.FailFunc
[1],
349 ctx
->Stencil
.ZFailFunc
[1],
350 ctx
->Stencil
.ZPassFunc
[1]);
353 ctx
->Driver
.DrawBuffer(ctx
, ctx
->Color
.DrawBuffer
[0]);