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.
30 #include "framebuffer.h"
33 #include "prog_execute.h"
35 #include "renderbuffer.h"
36 #include "texcompress.h"
37 #include "texformat.h"
41 #if FEATURE_ARB_vertex_buffer_object
42 #include "bufferobj.h"
44 #if FEATURE_EXT_framebuffer_object
46 #include "texrender.h"
48 #include "shader_api.h"
51 #include "driverfuncs.h"
53 #include "swrast/swrast.h"
58 * Plug in default functions for all pointers in the dd_function_table
60 * Device drivers should call this function and then plug in any
61 * functions which it wants to override.
62 * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
64 * \param table the dd_function_table to initialize
67 _mesa_init_driver_functions(struct dd_function_table
*driver
)
69 _mesa_bzero(driver
, sizeof(*driver
));
71 driver
->GetString
= NULL
; /* REQUIRED! */
72 driver
->UpdateState
= NULL
; /* REQUIRED! */
73 driver
->GetBufferSize
= NULL
; /* REQUIRED! */
74 driver
->ResizeBuffers
= _mesa_resize_framebuffer
;
77 driver
->Finish
= NULL
;
80 /* framebuffer/image functions */
81 driver
->Clear
= _swrast_Clear
;
82 driver
->Accum
= _swrast_Accum
;
83 driver
->RasterPos
= _tnl_RasterPos
;
84 driver
->DrawPixels
= _swrast_DrawPixels
;
85 driver
->ReadPixels
= _swrast_ReadPixels
;
86 driver
->CopyPixels
= _swrast_CopyPixels
;
87 driver
->Bitmap
= _swrast_Bitmap
;
89 /* Texture functions */
90 driver
->ChooseTextureFormat
= _mesa_choose_tex_format
;
91 driver
->TexImage1D
= _mesa_store_teximage1d
;
92 driver
->TexImage2D
= _mesa_store_teximage2d
;
93 driver
->TexImage3D
= _mesa_store_teximage3d
;
94 driver
->TexSubImage1D
= _mesa_store_texsubimage1d
;
95 driver
->TexSubImage2D
= _mesa_store_texsubimage2d
;
96 driver
->TexSubImage3D
= _mesa_store_texsubimage3d
;
97 driver
->GetTexImage
= _mesa_get_teximage
;
98 driver
->CopyTexImage1D
= _swrast_copy_teximage1d
;
99 driver
->CopyTexImage2D
= _swrast_copy_teximage2d
;
100 driver
->CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
101 driver
->CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
102 driver
->CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
103 driver
->GenerateMipmap
= _mesa_generate_mipmap
;
104 driver
->TestProxyTexImage
= _mesa_test_proxy_teximage
;
105 driver
->CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
106 driver
->CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
107 driver
->CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
108 driver
->CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
109 driver
->CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
110 driver
->CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
111 driver
->GetCompressedTexImage
= _mesa_get_compressed_teximage
;
112 driver
->CompressedTextureSize
= _mesa_compressed_texture_size
;
113 driver
->BindTexture
= NULL
;
114 driver
->NewTextureObject
= _mesa_new_texture_object
;
115 driver
->DeleteTexture
= _mesa_delete_texture_object
;
116 driver
->NewTextureImage
= _mesa_new_texture_image
;
117 driver
->FreeTexImageData
= _mesa_free_texture_image_data
;
118 driver
->TextureMemCpy
= _mesa_memcpy
;
119 driver
->IsTextureResident
= NULL
;
120 driver
->PrioritizeTexture
= NULL
;
121 driver
->ActiveTexture
= NULL
;
122 driver
->UpdateTexturePalette
= NULL
;
125 driver
->CopyColorTable
= _swrast_CopyColorTable
;
126 driver
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
127 driver
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
128 driver
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
130 /* Vertex/fragment programs */
131 driver
->BindProgram
= NULL
;
132 driver
->NewProgram
= _mesa_new_program
;
133 driver
->DeleteProgram
= _mesa_delete_program
;
134 #if FEATURE_MESA_program_debug
135 driver
->GetProgramRegister
= _mesa_get_program_register
;
136 #endif /* FEATURE_MESA_program_debug */
138 /* simple state commands */
139 driver
->AlphaFunc
= NULL
;
140 driver
->BlendColor
= NULL
;
141 driver
->BlendEquationSeparate
= NULL
;
142 driver
->BlendFuncSeparate
= NULL
;
143 driver
->ClearColor
= NULL
;
144 driver
->ClearDepth
= NULL
;
145 driver
->ClearIndex
= NULL
;
146 driver
->ClearStencil
= NULL
;
147 driver
->ClipPlane
= NULL
;
148 driver
->ColorMask
= NULL
;
149 driver
->ColorMaterial
= NULL
;
150 driver
->CullFace
= NULL
;
151 driver
->DrawBuffer
= NULL
;
152 driver
->DrawBuffers
= NULL
;
153 driver
->FrontFace
= NULL
;
154 driver
->DepthFunc
= NULL
;
155 driver
->DepthMask
= NULL
;
156 driver
->DepthRange
= NULL
;
157 driver
->Enable
= NULL
;
158 driver
->Fogfv
= NULL
;
160 driver
->IndexMask
= NULL
;
161 driver
->Lightfv
= NULL
;
162 driver
->LightModelfv
= NULL
;
163 driver
->LineStipple
= NULL
;
164 driver
->LineWidth
= NULL
;
165 driver
->LogicOpcode
= NULL
;
166 driver
->PointParameterfv
= NULL
;
167 driver
->PointSize
= NULL
;
168 driver
->PolygonMode
= NULL
;
169 driver
->PolygonOffset
= NULL
;
170 driver
->PolygonStipple
= NULL
;
171 driver
->ReadBuffer
= NULL
;
172 driver
->RenderMode
= NULL
;
173 driver
->Scissor
= NULL
;
174 driver
->ShadeModel
= NULL
;
175 driver
->StencilFuncSeparate
= NULL
;
176 driver
->StencilOpSeparate
= NULL
;
177 driver
->StencilMaskSeparate
= NULL
;
178 driver
->TexGen
= NULL
;
179 driver
->TexEnv
= NULL
;
180 driver
->TexParameter
= NULL
;
181 driver
->TextureMatrix
= NULL
;
182 driver
->Viewport
= NULL
;
185 driver
->VertexPointer
= NULL
;
186 driver
->NormalPointer
= NULL
;
187 driver
->ColorPointer
= NULL
;
188 driver
->FogCoordPointer
= NULL
;
189 driver
->IndexPointer
= NULL
;
190 driver
->SecondaryColorPointer
= NULL
;
191 driver
->TexCoordPointer
= NULL
;
192 driver
->EdgeFlagPointer
= NULL
;
193 driver
->VertexAttribPointer
= NULL
;
194 driver
->LockArraysEXT
= NULL
;
195 driver
->UnlockArraysEXT
= NULL
;
198 driver
->GetBooleanv
= NULL
;
199 driver
->GetDoublev
= NULL
;
200 driver
->GetFloatv
= NULL
;
201 driver
->GetIntegerv
= NULL
;
202 driver
->GetPointerv
= NULL
;
204 #if FEATURE_ARB_vertex_buffer_object
205 driver
->NewBufferObject
= _mesa_new_buffer_object
;
206 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
207 driver
->BindBuffer
= NULL
;
208 driver
->BufferData
= _mesa_buffer_data
;
209 driver
->BufferSubData
= _mesa_buffer_subdata
;
210 driver
->GetBufferSubData
= _mesa_buffer_get_subdata
;
211 driver
->MapBuffer
= _mesa_buffer_map
;
212 driver
->UnmapBuffer
= _mesa_buffer_unmap
;
215 #if FEATURE_EXT_framebuffer_object
216 driver
->NewFramebuffer
= _mesa_new_framebuffer
;
217 driver
->NewRenderbuffer
= _mesa_new_soft_renderbuffer
;
218 driver
->RenderTexture
= _mesa_render_texture
;
219 driver
->FinishRenderTexture
= _mesa_finish_render_texture
;
220 driver
->FramebufferRenderbuffer
= _mesa_framebuffer_renderbuffer
;
223 #if FEATURE_EXT_framebuffer_blit
224 driver
->BlitFramebuffer
= _swrast_BlitFramebuffer
;
228 driver
->NewQueryObject
= _mesa_new_query_object
;
229 driver
->DeleteQuery
= _mesa_delete_query
;
230 driver
->BeginQuery
= _mesa_begin_query
;
231 driver
->EndQuery
= _mesa_end_query
;
232 driver
->WaitQuery
= _mesa_wait_query
;
234 /* APPLE_vertex_array_object */
235 driver
->NewArrayObject
= _mesa_new_array_object
;
236 driver
->DeleteArrayObject
= _mesa_delete_array_object
;
237 driver
->BindArrayObject
= NULL
;
240 driver
->NeedValidate
= GL_FALSE
;
241 driver
->ValidateTnlModule
= NULL
;
242 driver
->CurrentExecPrimitive
= 0;
243 driver
->CurrentSavePrimitive
= 0;
244 driver
->NeedFlush
= 0;
245 driver
->SaveNeedFlush
= 0;
247 driver
->ProgramStringNotify
= _tnl_program_string
;
248 driver
->FlushVertices
= NULL
;
249 driver
->SaveFlushVertices
= NULL
;
250 driver
->NotifySaveBegin
= NULL
;
251 driver
->LightingSpaceChange
= NULL
;
254 driver
->NewList
= NULL
;
255 driver
->EndList
= NULL
;
256 driver
->BeginCallList
= NULL
;
257 driver
->EndCallList
= NULL
;
260 /* XXX temporary here */
261 _mesa_init_glsl_driver_functions(driver
);
266 * Call the ctx->Driver.* state functions with current values to initialize
268 * Only the Intel drivers use this so far.
271 _mesa_init_driver_state(GLcontext
*ctx
)
273 ctx
->Driver
.AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
275 ctx
->Driver
.BlendColor(ctx
, ctx
->Color
.BlendColor
);
277 ctx
->Driver
.BlendEquationSeparate(ctx
,
278 ctx
->Color
.BlendEquationRGB
,
279 ctx
->Color
.BlendEquationA
);
281 ctx
->Driver
.BlendFuncSeparate(ctx
,
282 ctx
->Color
.BlendSrcRGB
,
283 ctx
->Color
.BlendDstRGB
,
284 ctx
->Color
.BlendSrcA
, ctx
->Color
.BlendDstA
);
286 ctx
->Driver
.ColorMask(ctx
,
287 ctx
->Color
.ColorMask
[RCOMP
],
288 ctx
->Color
.ColorMask
[GCOMP
],
289 ctx
->Color
.ColorMask
[BCOMP
],
290 ctx
->Color
.ColorMask
[ACOMP
]);
292 ctx
->Driver
.CullFace(ctx
, ctx
->Polygon
.CullFaceMode
);
293 ctx
->Driver
.DepthFunc(ctx
, ctx
->Depth
.Func
);
294 ctx
->Driver
.DepthMask(ctx
, ctx
->Depth
.Mask
);
296 ctx
->Driver
.Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
297 ctx
->Driver
.Enable(ctx
, GL_BLEND
, ctx
->Color
.BlendEnabled
);
298 ctx
->Driver
.Enable(ctx
, GL_COLOR_LOGIC_OP
, ctx
->Color
.ColorLogicOpEnabled
);
299 ctx
->Driver
.Enable(ctx
, GL_COLOR_SUM
, ctx
->Fog
.ColorSumEnabled
);
300 ctx
->Driver
.Enable(ctx
, GL_CULL_FACE
, ctx
->Polygon
.CullFlag
);
301 ctx
->Driver
.Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
302 ctx
->Driver
.Enable(ctx
, GL_DITHER
, ctx
->Color
.DitherFlag
);
303 ctx
->Driver
.Enable(ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
304 ctx
->Driver
.Enable(ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
305 ctx
->Driver
.Enable(ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
306 ctx
->Driver
.Enable(ctx
, GL_POLYGON_STIPPLE
, ctx
->Polygon
.StippleFlag
);
307 ctx
->Driver
.Enable(ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.Enabled
);
308 ctx
->Driver
.Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
309 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_1D
, GL_FALSE
);
310 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_2D
, GL_FALSE
);
311 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_RECTANGLE_NV
, GL_FALSE
);
312 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_3D
, GL_FALSE
);
313 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
315 ctx
->Driver
.Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
316 ctx
->Driver
.Fogfv(ctx
, GL_FOG_MODE
, 0);
317 ctx
->Driver
.Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
318 ctx
->Driver
.Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
319 ctx
->Driver
.Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
321 ctx
->Driver
.FrontFace(ctx
, ctx
->Polygon
.FrontFace
);
324 GLfloat f
= (GLfloat
) ctx
->Light
.Model
.ColorControl
;
325 ctx
->Driver
.LightModelfv(ctx
, GL_LIGHT_MODEL_COLOR_CONTROL
, &f
);
328 ctx
->Driver
.LineWidth(ctx
, ctx
->Line
.Width
);
329 ctx
->Driver
.LogicOpcode(ctx
, ctx
->Color
.LogicOp
);
330 ctx
->Driver
.PointSize(ctx
, ctx
->Point
.Size
);
331 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) ctx
->PolygonStipple
);
332 ctx
->Driver
.Scissor(ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
333 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
334 ctx
->Driver
.ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
335 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_FRONT
,
336 ctx
->Stencil
.Function
[0],
338 ctx
->Stencil
.ValueMask
[0]);
339 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_BACK
,
340 ctx
->Stencil
.Function
[1],
342 ctx
->Stencil
.ValueMask
[1]);
343 ctx
->Driver
.StencilMaskSeparate(ctx
, GL_FRONT
, ctx
->Stencil
.WriteMask
[0]);
344 ctx
->Driver
.StencilMaskSeparate(ctx
, GL_BACK
, ctx
->Stencil
.WriteMask
[1]);
345 ctx
->Driver
.StencilOpSeparate(ctx
, GL_FRONT
,
346 ctx
->Stencil
.FailFunc
[0],
347 ctx
->Stencil
.ZFailFunc
[0],
348 ctx
->Stencil
.ZPassFunc
[0]);
349 ctx
->Driver
.StencilOpSeparate(ctx
, GL_BACK
,
350 ctx
->Stencil
.FailFunc
[1],
351 ctx
->Stencil
.ZFailFunc
[1],
352 ctx
->Stencil
.ZPassFunc
[1]);
355 ctx
->Driver
.DrawBuffer(ctx
, ctx
->Color
.DrawBuffer
[0]);