2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
26 #include "main/glheader.h"
27 #include "main/imports.h"
28 #include "main/accum.h"
29 #include "main/arrayobj.h"
30 #include "main/context.h"
31 #include "main/formatquery.h"
32 #include "main/framebuffer.h"
33 #include "main/mipmap.h"
34 #include "main/queryobj.h"
35 #include "main/readpix.h"
36 #include "main/renderbuffer.h"
37 #include "main/shaderobj.h"
38 #include "main/texcompress.h"
39 #include "main/texformat.h"
40 #include "main/texgetimage.h"
41 #include "main/teximage.h"
42 #include "main/texobj.h"
43 #include "main/texstorage.h"
44 #include "main/texstore.h"
45 #include "main/bufferobj.h"
46 #include "main/fbobject.h"
47 #include "main/samplerobj.h"
48 #include "main/syncobj.h"
49 #include "main/texturebarrier.h"
50 #include "main/transformfeedback.h"
52 #include "program/program.h"
54 #include "swrast/swrast.h"
55 #include "swrast/s_renderbuffer.h"
57 #include "driverfuncs.h"
63 * Plug in default functions for all pointers in the dd_function_table
65 * Device drivers should call this function and then plug in any
66 * functions which it wants to override.
67 * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
69 * \param table the dd_function_table to initialize
72 _mesa_init_driver_functions(struct dd_function_table
*driver
)
74 memset(driver
, 0, sizeof(*driver
));
76 driver
->GetString
= NULL
; /* REQUIRED! */
77 driver
->UpdateState
= NULL
; /* REQUIRED! */
79 driver
->Finish
= NULL
;
82 /* framebuffer/image functions */
83 driver
->Clear
= _swrast_Clear
;
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
->QuerySamplesForFormat
= _mesa_query_samples_for_format
;
93 driver
->TexImage
= _mesa_store_teximage
;
94 driver
->TexSubImage
= _mesa_store_texsubimage
;
95 driver
->GetTexSubImage
= _mesa_meta_GetTexSubImage
;
96 driver
->ClearTexSubImage
= _mesa_meta_ClearTexSubImage
;
97 driver
->CopyTexSubImage
= _mesa_meta_CopyTexSubImage
;
98 driver
->GenerateMipmap
= _mesa_meta_GenerateMipmap
;
99 driver
->TestProxyTexImage
= _mesa_test_proxy_teximage
;
100 driver
->CompressedTexImage
= _mesa_store_compressed_teximage
;
101 driver
->CompressedTexSubImage
= _mesa_store_compressed_texsubimage
;
102 driver
->GetCompressedTexSubImage
= _mesa_GetCompressedTexSubImage_sw
;
103 driver
->BindTexture
= NULL
;
104 driver
->NewTextureObject
= _mesa_new_texture_object
;
105 driver
->DeleteTexture
= _mesa_delete_texture_object
;
106 driver
->NewTextureImage
= _swrast_new_texture_image
;
107 driver
->DeleteTextureImage
= _swrast_delete_texture_image
;
108 driver
->AllocTextureImageBuffer
= _swrast_alloc_texture_image_buffer
;
109 driver
->FreeTextureImageBuffer
= _swrast_free_texture_image_buffer
;
110 driver
->MapTextureImage
= _swrast_map_teximage
;
111 driver
->UnmapTextureImage
= _swrast_unmap_teximage
;
112 driver
->DrawTex
= _mesa_meta_DrawTex
;
114 /* Vertex/fragment programs */
115 driver
->BindProgram
= NULL
;
116 driver
->NewProgram
= _mesa_new_program
;
117 driver
->DeleteProgram
= _mesa_delete_program
;
119 /* simple state commands */
120 driver
->AlphaFunc
= NULL
;
121 driver
->BlendColor
= NULL
;
122 driver
->BlendEquationSeparate
= NULL
;
123 driver
->BlendFuncSeparate
= NULL
;
124 driver
->ClipPlane
= NULL
;
125 driver
->ColorMask
= NULL
;
126 driver
->ColorMaterial
= NULL
;
127 driver
->CullFace
= NULL
;
128 driver
->DrawBuffer
= NULL
;
129 driver
->DrawBuffers
= NULL
;
130 driver
->FrontFace
= NULL
;
131 driver
->DepthFunc
= NULL
;
132 driver
->DepthMask
= NULL
;
133 driver
->DepthRange
= NULL
;
134 driver
->Enable
= NULL
;
135 driver
->Fogfv
= NULL
;
136 driver
->Lightfv
= NULL
;
137 driver
->LightModelfv
= NULL
;
138 driver
->LineStipple
= NULL
;
139 driver
->LineWidth
= NULL
;
140 driver
->LogicOpcode
= NULL
;
141 driver
->PointParameterfv
= NULL
;
142 driver
->PointSize
= NULL
;
143 driver
->PolygonMode
= NULL
;
144 driver
->PolygonOffset
= NULL
;
145 driver
->PolygonStipple
= NULL
;
146 driver
->ReadBuffer
= NULL
;
147 driver
->RenderMode
= NULL
;
148 driver
->Scissor
= NULL
;
149 driver
->ShadeModel
= NULL
;
150 driver
->StencilFuncSeparate
= NULL
;
151 driver
->StencilOpSeparate
= NULL
;
152 driver
->StencilMaskSeparate
= NULL
;
153 driver
->TexGen
= NULL
;
154 driver
->TexEnv
= NULL
;
155 driver
->TexParameter
= NULL
;
156 driver
->Viewport
= NULL
;
159 _mesa_init_buffer_object_functions(driver
);
162 _mesa_init_query_object_functions(driver
);
164 _mesa_init_sync_object_functions(driver
);
166 driver
->NewFramebuffer
= _mesa_new_framebuffer
;
167 driver
->NewRenderbuffer
= _swrast_new_soft_renderbuffer
;
168 driver
->MapRenderbuffer
= _swrast_map_soft_renderbuffer
;
169 driver
->UnmapRenderbuffer
= _swrast_unmap_soft_renderbuffer
;
170 driver
->RenderTexture
= _swrast_render_texture
;
171 driver
->FinishRenderTexture
= _swrast_finish_render_texture
;
172 driver
->FramebufferRenderbuffer
= _mesa_FramebufferRenderbuffer_sw
;
173 driver
->ValidateFramebuffer
= _mesa_validate_framebuffer
;
175 driver
->BlitFramebuffer
= _swrast_BlitFramebuffer
;
176 driver
->DiscardFramebuffer
= NULL
;
178 _mesa_init_texture_barrier_functions(driver
);
180 /* APPLE_vertex_array_object */
181 driver
->DeleteArrayObject
= _mesa_delete_vao
;
182 driver
->BindArrayObject
= NULL
;
184 _mesa_init_shader_object_functions(driver
);
186 _mesa_init_transform_feedback_functions(driver
);
188 _mesa_init_sampler_object_functions(driver
);
191 driver
->CurrentExecPrimitive
= 0;
192 driver
->CurrentSavePrimitive
= 0;
193 driver
->NeedFlush
= 0;
194 driver
->SaveNeedFlush
= 0;
196 driver
->ProgramStringNotify
= _tnl_program_string
;
197 driver
->FlushVertices
= NULL
;
198 driver
->SaveFlushVertices
= NULL
;
199 driver
->NotifySaveBegin
= NULL
;
200 driver
->LightingSpaceChange
= NULL
;
203 driver
->NewList
= NULL
;
204 driver
->EndList
= NULL
;
205 driver
->BeginCallList
= NULL
;
206 driver
->EndCallList
= NULL
;
208 /* GL_ARB_texture_storage */
209 driver
->AllocTextureStorage
= _mesa_AllocTextureStorage_sw
;
211 /* GL_ARB_texture_view */
212 driver
->TextureView
= NULL
;
214 /* GL_ARB_texture_multisample */
215 driver
->GetSamplePosition
= NULL
;
220 * Call the ctx->Driver.* state functions with current values to initialize
222 * Only the Intel drivers use this so far.
225 _mesa_init_driver_state(struct gl_context
*ctx
)
227 ctx
->Driver
.AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
229 ctx
->Driver
.BlendColor(ctx
, ctx
->Color
.BlendColor
);
231 ctx
->Driver
.BlendEquationSeparate(ctx
,
232 ctx
->Color
.Blend
[0].EquationRGB
,
233 ctx
->Color
.Blend
[0].EquationA
);
235 ctx
->Driver
.BlendFuncSeparate(ctx
,
236 ctx
->Color
.Blend
[0].SrcRGB
,
237 ctx
->Color
.Blend
[0].DstRGB
,
238 ctx
->Color
.Blend
[0].SrcA
,
239 ctx
->Color
.Blend
[0].DstA
);
241 ctx
->Driver
.ColorMask(ctx
,
242 ctx
->Color
.ColorMask
[0][RCOMP
],
243 ctx
->Color
.ColorMask
[0][GCOMP
],
244 ctx
->Color
.ColorMask
[0][BCOMP
],
245 ctx
->Color
.ColorMask
[0][ACOMP
]);
247 ctx
->Driver
.CullFace(ctx
, ctx
->Polygon
.CullFaceMode
);
248 ctx
->Driver
.DepthFunc(ctx
, ctx
->Depth
.Func
);
249 ctx
->Driver
.DepthMask(ctx
, ctx
->Depth
.Mask
);
251 ctx
->Driver
.Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
252 ctx
->Driver
.Enable(ctx
, GL_BLEND
, ctx
->Color
.BlendEnabled
);
253 ctx
->Driver
.Enable(ctx
, GL_COLOR_LOGIC_OP
, ctx
->Color
.ColorLogicOpEnabled
);
254 ctx
->Driver
.Enable(ctx
, GL_COLOR_SUM
, ctx
->Fog
.ColorSumEnabled
);
255 ctx
->Driver
.Enable(ctx
, GL_CULL_FACE
, ctx
->Polygon
.CullFlag
);
256 ctx
->Driver
.Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
257 ctx
->Driver
.Enable(ctx
, GL_DITHER
, ctx
->Color
.DitherFlag
);
258 ctx
->Driver
.Enable(ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
259 ctx
->Driver
.Enable(ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
260 ctx
->Driver
.Enable(ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
261 ctx
->Driver
.Enable(ctx
, GL_POLYGON_STIPPLE
, ctx
->Polygon
.StippleFlag
);
262 ctx
->Driver
.Enable(ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.EnableFlags
);
263 ctx
->Driver
.Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
._Enabled
);
264 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_1D
, GL_FALSE
);
265 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_2D
, GL_FALSE
);
266 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_RECTANGLE_NV
, GL_FALSE
);
267 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_3D
, GL_FALSE
);
268 ctx
->Driver
.Enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
270 ctx
->Driver
.Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
272 GLfloat mode
= (GLfloat
) ctx
->Fog
.Mode
;
273 ctx
->Driver
.Fogfv(ctx
, GL_FOG_MODE
, &mode
);
275 ctx
->Driver
.Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
276 ctx
->Driver
.Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
277 ctx
->Driver
.Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
279 ctx
->Driver
.FrontFace(ctx
, ctx
->Polygon
.FrontFace
);
282 GLfloat f
= (GLfloat
) ctx
->Light
.Model
.ColorControl
;
283 ctx
->Driver
.LightModelfv(ctx
, GL_LIGHT_MODEL_COLOR_CONTROL
, &f
);
286 ctx
->Driver
.LineWidth(ctx
, ctx
->Line
.Width
);
287 ctx
->Driver
.LogicOpcode(ctx
, ctx
->Color
.LogicOp
);
288 ctx
->Driver
.PointSize(ctx
, ctx
->Point
.Size
);
289 ctx
->Driver
.PolygonStipple(ctx
, (const GLubyte
*) ctx
->PolygonStipple
);
290 ctx
->Driver
.Scissor(ctx
);
291 ctx
->Driver
.ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
292 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_FRONT
,
293 ctx
->Stencil
.Function
[0],
295 ctx
->Stencil
.ValueMask
[0]);
296 ctx
->Driver
.StencilFuncSeparate(ctx
, GL_BACK
,
297 ctx
->Stencil
.Function
[1],
299 ctx
->Stencil
.ValueMask
[1]);
300 ctx
->Driver
.StencilMaskSeparate(ctx
, GL_FRONT
, ctx
->Stencil
.WriteMask
[0]);
301 ctx
->Driver
.StencilMaskSeparate(ctx
, GL_BACK
, ctx
->Stencil
.WriteMask
[1]);
302 ctx
->Driver
.StencilOpSeparate(ctx
, GL_FRONT
,
303 ctx
->Stencil
.FailFunc
[0],
304 ctx
->Stencil
.ZFailFunc
[0],
305 ctx
->Stencil
.ZPassFunc
[0]);
306 ctx
->Driver
.StencilOpSeparate(ctx
, GL_BACK
,
307 ctx
->Stencil
.FailFunc
[1],
308 ctx
->Stencil
.ZFailFunc
[1],
309 ctx
->Stencil
.ZPassFunc
[1]);
312 ctx
->Driver
.DrawBuffer(ctx
, ctx
->Color
.DrawBuffer
[0]);