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_meta_GenerateMipmap
;
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
->BindTexture
= NULL
;
119 driver
->NewTextureObject
= _mesa_new_texture_object
;
120 driver
->DeleteTexture
= _mesa_delete_texture_object
;
121 driver
->NewTextureImage
= _mesa_new_texture_image
;
122 driver
->FreeTexImageData
= _mesa_free_texture_image_data
;
123 driver
->MapTexture
= NULL
;
124 driver
->UnmapTexture
= NULL
;
125 driver
->TextureMemCpy
= _mesa_memcpy
;
126 driver
->IsTextureResident
= NULL
;
127 driver
->UpdateTexturePalette
= NULL
;
130 driver
->CopyColorTable
= _mesa_meta_CopyColorTable
;
131 driver
->CopyColorSubTable
= _mesa_meta_CopyColorSubTable
;
132 driver
->CopyConvolutionFilter1D
= _mesa_meta_CopyConvolutionFilter1D
;
133 driver
->CopyConvolutionFilter2D
= _mesa_meta_CopyConvolutionFilter2D
;
135 /* Vertex/fragment programs */
136 driver
->BindProgram
= NULL
;
137 driver
->NewProgram
= _mesa_new_program
;
138 driver
->DeleteProgram
= _mesa_delete_program
;
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
;
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
->Viewport
= NULL
;
186 driver
->GetBooleanv
= NULL
;
187 driver
->GetDoublev
= NULL
;
188 driver
->GetFloatv
= NULL
;
189 driver
->GetIntegerv
= NULL
;
190 driver
->GetInteger64v
= NULL
;
191 driver
->GetPointerv
= NULL
;
194 _mesa_init_buffer_object_functions(driver
);
197 _mesa_init_query_object_functions(driver
);
200 _mesa_init_sync_object_functions(driver
);
203 #if FEATURE_EXT_framebuffer_object
204 driver
->NewFramebuffer
= _mesa_new_framebuffer
;
205 driver
->NewRenderbuffer
= _mesa_new_soft_renderbuffer
;
206 driver
->RenderTexture
= _mesa_render_texture
;
207 driver
->FinishRenderTexture
= _mesa_finish_render_texture
;
208 driver
->FramebufferRenderbuffer
= _mesa_framebuffer_renderbuffer
;
211 #if FEATURE_EXT_framebuffer_blit
212 driver
->BlitFramebuffer
= _swrast_BlitFramebuffer
;
215 /* APPLE_vertex_array_object */
216 driver
->NewArrayObject
= _mesa_new_array_object
;
217 driver
->DeleteArrayObject
= _mesa_delete_array_object
;
218 driver
->BindArrayObject
= NULL
;
221 driver
->NeedValidate
= GL_FALSE
;
222 driver
->ValidateTnlModule
= NULL
;
223 driver
->CurrentExecPrimitive
= 0;
224 driver
->CurrentSavePrimitive
= 0;
225 driver
->NeedFlush
= 0;
226 driver
->SaveNeedFlush
= 0;
228 driver
->ProgramStringNotify
= _tnl_program_string
;
229 driver
->FlushVertices
= NULL
;
230 driver
->SaveFlushVertices
= NULL
;
231 driver
->NotifySaveBegin
= NULL
;
232 driver
->LightingSpaceChange
= NULL
;
235 driver
->NewList
= NULL
;
236 driver
->EndList
= NULL
;
237 driver
->BeginCallList
= NULL
;
238 driver
->EndCallList
= NULL
;
241 /* XXX temporary here */
242 _mesa_init_glsl_driver_functions(driver
);
247 * Call the ctx->Driver.* state functions with current values to initialize
249 * Only the Intel drivers use this so far.
252 _mesa_init_driver_state(GLcontext
*ctx
)
254 ctx
->Driver
.AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
256 ctx
->Driver
.BlendColor(ctx
, ctx
->Color
.BlendColor
);
258 ctx
->Driver
.BlendEquationSeparate(ctx
,
259 ctx
->Color
.BlendEquationRGB
,
260 ctx
->Color
.BlendEquationA
);
262 ctx
->Driver
.BlendFuncSeparate(ctx
,
263 ctx
->Color
.BlendSrcRGB
,
264 ctx
->Color
.BlendDstRGB
,
265 ctx
->Color
.BlendSrcA
, ctx
->Color
.BlendDstA
);
267 if (ctx
->Driver
.ColorMaskIndexed
) {
269 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
270 ctx
->Driver
.ColorMaskIndexed(ctx
, i
,
271 ctx
->Color
.ColorMask
[0][RCOMP
],
272 ctx
->Color
.ColorMask
[0][GCOMP
],
273 ctx
->Color
.ColorMask
[0][BCOMP
],
274 ctx
->Color
.ColorMask
[0][ACOMP
]);
278 ctx
->Driver
.ColorMask(ctx
,
279 ctx
->Color
.ColorMask
[0][RCOMP
],
280 ctx
->Color
.ColorMask
[0][GCOMP
],
281 ctx
->Color
.ColorMask
[0][BCOMP
],
282 ctx
->Color
.ColorMask
[0][ACOMP
]);
285 ctx
->Driver
.CullFace(ctx
, ctx
->Polygon
.CullFaceMode
);
286 ctx
->Driver
.DepthFunc(ctx
, ctx
->Depth
.Func
);
287 ctx
->Driver
.DepthMask(ctx
, ctx
->Depth
.Mask
);
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
);
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
);
314 ctx
->Driver
.FrontFace(ctx
, ctx
->Polygon
.FrontFace
);
317 GLfloat f
= (GLfloat
) ctx
->Light
.Model
.ColorControl
;
318 ctx
->Driver
.LightModelfv(ctx
, GL_LIGHT_MODEL_COLOR_CONTROL
, &f
);
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],
331 ctx
->Stencil
.ValueMask
[0]);
332 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_BACK
,
333 ctx
->Stencil
.Function
[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]);
348 ctx
->Driver
.DrawBuffer(ctx
, ctx
->Color
.DrawBuffer
[0]);