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/context.h"
30 #include "main/framebuffer.h"
31 #include "main/mipmap.h"
32 #include "main/queryobj.h"
33 #include "main/readpix.h"
34 #include "main/renderbuffer.h"
35 #include "main/shaderobj.h"
36 #include "main/texcompress.h"
37 #include "main/texformat.h"
38 #include "main/texgetimage.h"
39 #include "main/teximage.h"
40 #include "main/texobj.h"
41 #include "main/texstore.h"
42 #include "main/bufferobj.h"
43 #include "main/fbobject.h"
44 #include "main/samplerobj.h"
45 #include "main/syncobj.h"
46 #include "main/texturebarrier.h"
47 #include "main/transformfeedback.h"
49 #include "program/program.h"
51 #include "swrast/swrast.h"
53 #include "driverfuncs.h"
59 * Plug in default functions for all pointers in the dd_function_table
61 * Device drivers should call this function and then plug in any
62 * functions which it wants to override.
63 * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
65 * \param table the dd_function_table to initialize
68 _mesa_init_driver_functions(struct dd_function_table
*driver
)
70 memset(driver
, 0, sizeof(*driver
));
72 driver
->GetString
= NULL
; /* REQUIRED! */
73 driver
->UpdateState
= NULL
; /* REQUIRED! */
74 driver
->GetBufferSize
= NULL
; /* REQUIRED! */
75 driver
->ResizeBuffers
= _mesa_resize_framebuffer
;
78 driver
->Finish
= NULL
;
81 /* framebuffer/image functions */
82 driver
->Clear
= _swrast_Clear
;
83 driver
->Accum
= _swrast_Accum
;
84 driver
->RasterPos
= _tnl_RasterPos
;
85 driver
->DrawPixels
= _swrast_DrawPixels
;
86 driver
->ReadPixels
= _mesa_readpixels
;
87 driver
->CopyPixels
= _swrast_CopyPixels
;
88 driver
->Bitmap
= _swrast_Bitmap
;
90 /* Texture functions */
91 driver
->ChooseTextureFormat
= _mesa_choose_tex_format
;
92 driver
->TexImage1D
= _mesa_store_teximage1d
;
93 driver
->TexImage2D
= _mesa_store_teximage2d
;
94 driver
->TexImage3D
= _mesa_store_teximage3d
;
95 driver
->TexSubImage1D
= _mesa_store_texsubimage1d
;
96 driver
->TexSubImage2D
= _mesa_store_texsubimage2d
;
97 driver
->TexSubImage3D
= _mesa_store_texsubimage3d
;
98 driver
->GetTexImage
= _mesa_meta_GetTexImage
;
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
= _swrast_new_texture_image
;
115 driver
->DeleteTextureImage
= _swrast_delete_texture_image
;
116 driver
->AllocTextureImageBuffer
= _swrast_alloc_texture_image_buffer
;
117 driver
->FreeTextureImageBuffer
= _swrast_free_texture_image_buffer
;
118 driver
->MapTextureImage
= _swrast_map_teximage
;
119 driver
->UnmapTextureImage
= _swrast_unmap_teximage
;
120 driver
->MapTexture
= NULL
;
121 driver
->UnmapTexture
= NULL
;
122 driver
->IsTextureResident
= NULL
;
123 driver
->DrawTex
= _mesa_meta_DrawTex
;
125 /* Vertex/fragment programs */
126 driver
->BindProgram
= NULL
;
127 driver
->NewProgram
= _mesa_new_program
;
128 driver
->DeleteProgram
= _mesa_delete_program
;
130 /* simple state commands */
131 driver
->AlphaFunc
= NULL
;
132 driver
->BlendColor
= NULL
;
133 driver
->BlendEquationSeparate
= NULL
;
134 driver
->BlendFuncSeparate
= NULL
;
135 driver
->ClearColor
= NULL
;
136 driver
->ClearDepth
= NULL
;
137 driver
->ClearStencil
= NULL
;
138 driver
->ClipPlane
= NULL
;
139 driver
->ColorMask
= NULL
;
140 driver
->ColorMaterial
= NULL
;
141 driver
->CullFace
= NULL
;
142 driver
->DrawBuffer
= NULL
;
143 driver
->DrawBuffers
= NULL
;
144 driver
->FrontFace
= NULL
;
145 driver
->DepthFunc
= NULL
;
146 driver
->DepthMask
= NULL
;
147 driver
->DepthRange
= NULL
;
148 driver
->Enable
= NULL
;
149 driver
->Fogfv
= NULL
;
151 driver
->Lightfv
= NULL
;
152 driver
->LightModelfv
= NULL
;
153 driver
->LineStipple
= NULL
;
154 driver
->LineWidth
= NULL
;
155 driver
->LogicOpcode
= NULL
;
156 driver
->PointParameterfv
= NULL
;
157 driver
->PointSize
= NULL
;
158 driver
->PolygonMode
= NULL
;
159 driver
->PolygonOffset
= NULL
;
160 driver
->PolygonStipple
= NULL
;
161 driver
->ReadBuffer
= NULL
;
162 driver
->RenderMode
= NULL
;
163 driver
->Scissor
= NULL
;
164 driver
->ShadeModel
= NULL
;
165 driver
->StencilFuncSeparate
= NULL
;
166 driver
->StencilOpSeparate
= NULL
;
167 driver
->StencilMaskSeparate
= NULL
;
168 driver
->TexGen
= NULL
;
169 driver
->TexEnv
= NULL
;
170 driver
->TexParameter
= NULL
;
171 driver
->Viewport
= NULL
;
174 _mesa_init_buffer_object_functions(driver
);
177 _mesa_init_query_object_functions(driver
);
179 _mesa_init_sync_object_functions(driver
);
181 driver
->NewFramebuffer
= _mesa_new_framebuffer
;
182 driver
->NewRenderbuffer
= _mesa_new_soft_renderbuffer
;
183 driver
->MapRenderbuffer
= _mesa_map_soft_renderbuffer
;
184 driver
->UnmapRenderbuffer
= _mesa_unmap_soft_renderbuffer
;
185 driver
->RenderTexture
= _swrast_render_texture
;
186 driver
->FinishRenderTexture
= _swrast_finish_render_texture
;
187 driver
->FramebufferRenderbuffer
= _mesa_framebuffer_renderbuffer
;
188 driver
->ValidateFramebuffer
= _mesa_validate_framebuffer
;
190 driver
->BlitFramebuffer
= _swrast_BlitFramebuffer
;
192 _mesa_init_texture_barrier_functions(driver
);
194 /* APPLE_vertex_array_object */
195 driver
->NewArrayObject
= _mesa_new_array_object
;
196 driver
->DeleteArrayObject
= _mesa_delete_array_object
;
197 driver
->BindArrayObject
= NULL
;
199 _mesa_init_shader_object_functions(driver
);
201 _mesa_init_transform_feedback_functions(driver
);
203 _mesa_init_sampler_object_functions(driver
);
206 driver
->CurrentExecPrimitive
= 0;
207 driver
->CurrentSavePrimitive
= 0;
208 driver
->NeedFlush
= 0;
209 driver
->SaveNeedFlush
= 0;
211 driver
->ProgramStringNotify
= _tnl_program_string
;
212 driver
->FlushVertices
= NULL
;
213 driver
->SaveFlushVertices
= NULL
;
214 driver
->PrepareExecBegin
= NULL
;
215 driver
->NotifySaveBegin
= NULL
;
216 driver
->LightingSpaceChange
= NULL
;
219 driver
->NewList
= NULL
;
220 driver
->EndList
= NULL
;
221 driver
->BeginCallList
= NULL
;
222 driver
->EndCallList
= NULL
;
224 /* GL_ARB_texture_storage */
225 driver
->AllocTextureStorage
= _swrast_AllocTextureStorage
;
230 * Call the ctx->Driver.* state functions with current values to initialize
232 * Only the Intel drivers use this so far.
235 _mesa_init_driver_state(struct gl_context
*ctx
)
237 ctx
->Driver
.AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
239 ctx
->Driver
.BlendColor(ctx
, ctx
->Color
.BlendColor
);
241 ctx
->Driver
.BlendEquationSeparate(ctx
,
242 ctx
->Color
.Blend
[0].EquationRGB
,
243 ctx
->Color
.Blend
[0].EquationA
);
245 ctx
->Driver
.BlendFuncSeparate(ctx
,
246 ctx
->Color
.Blend
[0].SrcRGB
,
247 ctx
->Color
.Blend
[0].DstRGB
,
248 ctx
->Color
.Blend
[0].SrcA
,
249 ctx
->Color
.Blend
[0].DstA
);
251 if (ctx
->Driver
.ColorMaskIndexed
) {
253 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
254 ctx
->Driver
.ColorMaskIndexed(ctx
, i
,
255 ctx
->Color
.ColorMask
[i
][RCOMP
],
256 ctx
->Color
.ColorMask
[i
][GCOMP
],
257 ctx
->Color
.ColorMask
[i
][BCOMP
],
258 ctx
->Color
.ColorMask
[i
][ACOMP
]);
262 ctx
->Driver
.ColorMask(ctx
,
263 ctx
->Color
.ColorMask
[0][RCOMP
],
264 ctx
->Color
.ColorMask
[0][GCOMP
],
265 ctx
->Color
.ColorMask
[0][BCOMP
],
266 ctx
->Color
.ColorMask
[0][ACOMP
]);
269 ctx
->Driver
.CullFace(ctx
, ctx
->Polygon
.CullFaceMode
);
270 ctx
->Driver
.DepthFunc(ctx
, ctx
->Depth
.Func
);
271 ctx
->Driver
.DepthMask(ctx
, ctx
->Depth
.Mask
);
273 ctx
->Driver
.Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
274 ctx
->Driver
.Enable(ctx
, GL_BLEND
, ctx
->Color
.BlendEnabled
);
275 ctx
->Driver
.Enable(ctx
, GL_COLOR_LOGIC_OP
, ctx
->Color
.ColorLogicOpEnabled
);
276 ctx
->Driver
.Enable(ctx
, GL_COLOR_SUM
, ctx
->Fog
.ColorSumEnabled
);
277 ctx
->Driver
.Enable(ctx
, GL_CULL_FACE
, ctx
->Polygon
.CullFlag
);
278 ctx
->Driver
.Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
279 ctx
->Driver
.Enable(ctx
, GL_DITHER
, ctx
->Color
.DitherFlag
);
280 ctx
->Driver
.Enable(ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
281 ctx
->Driver
.Enable(ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
282 ctx
->Driver
.Enable(ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
283 ctx
->Driver
.Enable(ctx
, GL_POLYGON_STIPPLE
, ctx
->Polygon
.StippleFlag
);
284 ctx
->Driver
.Enable(ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.Enabled
);
285 ctx
->Driver
.Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
._Enabled
);
286 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_1D
, GL_FALSE
);
287 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_2D
, GL_FALSE
);
288 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_RECTANGLE_NV
, GL_FALSE
);
289 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_3D
, GL_FALSE
);
290 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
292 ctx
->Driver
.Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
294 GLfloat mode
= (GLfloat
) ctx
->Fog
.Mode
;
295 ctx
->Driver
.Fogfv(ctx
, GL_FOG_MODE
, &mode
);
297 ctx
->Driver
.Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
298 ctx
->Driver
.Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
299 ctx
->Driver
.Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
301 ctx
->Driver
.FrontFace(ctx
, ctx
->Polygon
.FrontFace
);
304 GLfloat f
= (GLfloat
) ctx
->Light
.Model
.ColorControl
;
305 ctx
->Driver
.LightModelfv(ctx
, GL_LIGHT_MODEL_COLOR_CONTROL
, &f
);
308 ctx
->Driver
.LineWidth(ctx
, ctx
->Line
.Width
);
309 ctx
->Driver
.LogicOpcode(ctx
, ctx
->Color
.LogicOp
);
310 ctx
->Driver
.PointSize(ctx
, ctx
->Point
.Size
);
311 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) ctx
->PolygonStipple
);
312 ctx
->Driver
.Scissor(ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
313 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
314 ctx
->Driver
.ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
315 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_FRONT
,
316 ctx
->Stencil
.Function
[0],
318 ctx
->Stencil
.ValueMask
[0]);
319 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_BACK
,
320 ctx
->Stencil
.Function
[1],
322 ctx
->Stencil
.ValueMask
[1]);
323 ctx
->Driver
.StencilMaskSeparate(ctx
, GL_FRONT
, ctx
->Stencil
.WriteMask
[0]);
324 ctx
->Driver
.StencilMaskSeparate(ctx
, GL_BACK
, ctx
->Stencil
.WriteMask
[1]);
325 ctx
->Driver
.StencilOpSeparate(ctx
, GL_FRONT
,
326 ctx
->Stencil
.FailFunc
[0],
327 ctx
->Stencil
.ZFailFunc
[0],
328 ctx
->Stencil
.ZPassFunc
[0]);
329 ctx
->Driver
.StencilOpSeparate(ctx
, GL_BACK
,
330 ctx
->Stencil
.FailFunc
[1],
331 ctx
->Stencil
.ZFailFunc
[1],
332 ctx
->Stencil
.ZPassFunc
[1]);
335 ctx
->Driver
.DrawBuffer(ctx
, ctx
->Color
.DrawBuffer
[0]);