mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / drivers / common / driverfuncs.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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 * THE AUTHORS 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.
23 */
24
25
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"
51
52 #include "program/program.h"
53 #include "tnl/tnl.h"
54 #include "swrast/swrast.h"
55 #include "swrast/s_renderbuffer.h"
56
57 #include "driverfuncs.h"
58 #include "meta.h"
59
60
61
62 /**
63 * Plug in default functions for all pointers in the dd_function_table
64 * structure.
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).
68 *
69 * \param table the dd_function_table to initialize
70 */
71 void
72 _mesa_init_driver_functions(struct dd_function_table *driver)
73 {
74 memset(driver, 0, sizeof(*driver));
75
76 driver->GetString = NULL; /* REQUIRED! */
77 driver->UpdateState = NULL; /* REQUIRED! */
78 driver->GetBufferSize = NULL; /* REQUIRED! */
79 driver->ResizeBuffers = _mesa_resize_framebuffer;
80
81 driver->Finish = NULL;
82 driver->Flush = NULL;
83
84 /* framebuffer/image functions */
85 driver->Clear = _swrast_Clear;
86 driver->Accum = _mesa_accum;
87 driver->RasterPos = _tnl_RasterPos;
88 driver->DrawPixels = _swrast_DrawPixels;
89 driver->ReadPixels = _mesa_readpixels;
90 driver->CopyPixels = _swrast_CopyPixels;
91 driver->Bitmap = _swrast_Bitmap;
92
93 /* Texture functions */
94 driver->ChooseTextureFormat = _mesa_choose_tex_format;
95 driver->QuerySamplesForFormat = _mesa_query_samples_for_format;
96 driver->TexImage = _mesa_store_teximage;
97 driver->TexSubImage = _mesa_store_texsubimage;
98 driver->GetTexImage = _mesa_meta_GetTexImage;
99 driver->CopyTexSubImage = _mesa_meta_CopyTexSubImage;
100 driver->GenerateMipmap = _mesa_meta_GenerateMipmap;
101 driver->TestProxyTexImage = _mesa_test_proxy_teximage;
102 driver->CompressedTexImage = _mesa_store_compressed_teximage;
103 driver->CompressedTexSubImage = _mesa_store_compressed_texsubimage;
104 driver->GetCompressedTexImage = _mesa_get_compressed_teximage;
105 driver->BindTexture = NULL;
106 driver->NewTextureObject = _mesa_new_texture_object;
107 driver->DeleteTexture = _mesa_delete_texture_object;
108 driver->NewTextureImage = _swrast_new_texture_image;
109 driver->DeleteTextureImage = _swrast_delete_texture_image;
110 driver->AllocTextureImageBuffer = _swrast_alloc_texture_image_buffer;
111 driver->FreeTextureImageBuffer = _swrast_free_texture_image_buffer;
112 driver->MapTextureImage = _swrast_map_teximage;
113 driver->UnmapTextureImage = _swrast_unmap_teximage;
114 driver->DrawTex = _mesa_meta_DrawTex;
115
116 /* Vertex/fragment programs */
117 driver->BindProgram = NULL;
118 driver->NewProgram = _mesa_new_program;
119 driver->DeleteProgram = _mesa_delete_program;
120
121 /* simple state commands */
122 driver->AlphaFunc = NULL;
123 driver->BlendColor = NULL;
124 driver->BlendEquationSeparate = NULL;
125 driver->BlendFuncSeparate = NULL;
126 driver->ClipPlane = NULL;
127 driver->ColorMask = NULL;
128 driver->ColorMaterial = NULL;
129 driver->CullFace = NULL;
130 driver->DrawBuffer = NULL;
131 driver->DrawBuffers = NULL;
132 driver->FrontFace = NULL;
133 driver->DepthFunc = NULL;
134 driver->DepthMask = NULL;
135 driver->DepthRange = NULL;
136 driver->Enable = NULL;
137 driver->Fogfv = NULL;
138 driver->Hint = NULL;
139 driver->Lightfv = NULL;
140 driver->LightModelfv = NULL;
141 driver->LineStipple = NULL;
142 driver->LineWidth = NULL;
143 driver->LogicOpcode = NULL;
144 driver->PointParameterfv = NULL;
145 driver->PointSize = NULL;
146 driver->PolygonMode = NULL;
147 driver->PolygonOffset = NULL;
148 driver->PolygonStipple = NULL;
149 driver->ReadBuffer = NULL;
150 driver->RenderMode = NULL;
151 driver->Scissor = NULL;
152 driver->ShadeModel = NULL;
153 driver->StencilFuncSeparate = NULL;
154 driver->StencilOpSeparate = NULL;
155 driver->StencilMaskSeparate = NULL;
156 driver->TexGen = NULL;
157 driver->TexEnv = NULL;
158 driver->TexParameter = NULL;
159 driver->Viewport = NULL;
160
161 /* buffer objects */
162 _mesa_init_buffer_object_functions(driver);
163
164 /* query objects */
165 _mesa_init_query_object_functions(driver);
166
167 _mesa_init_sync_object_functions(driver);
168
169 driver->NewFramebuffer = _mesa_new_framebuffer;
170 driver->NewRenderbuffer = _swrast_new_soft_renderbuffer;
171 driver->MapRenderbuffer = _swrast_map_soft_renderbuffer;
172 driver->UnmapRenderbuffer = _swrast_unmap_soft_renderbuffer;
173 driver->RenderTexture = _swrast_render_texture;
174 driver->FinishRenderTexture = _swrast_finish_render_texture;
175 driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
176 driver->ValidateFramebuffer = _mesa_validate_framebuffer;
177
178 driver->BlitFramebuffer = _swrast_BlitFramebuffer;
179 driver->DiscardFramebuffer = NULL;
180
181 _mesa_init_texture_barrier_functions(driver);
182
183 /* APPLE_vertex_array_object */
184 driver->NewArrayObject = _mesa_new_array_object;
185 driver->DeleteArrayObject = _mesa_delete_array_object;
186 driver->BindArrayObject = NULL;
187
188 _mesa_init_shader_object_functions(driver);
189
190 _mesa_init_transform_feedback_functions(driver);
191
192 _mesa_init_sampler_object_functions(driver);
193
194 /* T&L stuff */
195 driver->CurrentExecPrimitive = 0;
196 driver->CurrentSavePrimitive = 0;
197 driver->NeedFlush = 0;
198 driver->SaveNeedFlush = 0;
199
200 driver->ProgramStringNotify = _tnl_program_string;
201 driver->FlushVertices = NULL;
202 driver->SaveFlushVertices = NULL;
203 driver->NotifySaveBegin = NULL;
204 driver->LightingSpaceChange = NULL;
205
206 /* display list */
207 driver->NewList = NULL;
208 driver->EndList = NULL;
209 driver->BeginCallList = NULL;
210 driver->EndCallList = NULL;
211
212 /* GL_ARB_texture_storage */
213 driver->AllocTextureStorage = _mesa_alloc_texture_storage;
214
215 /* GL_ARB_texture_multisample */
216 driver->GetSamplePosition = NULL;
217 }
218
219
220 /**
221 * Call the ctx->Driver.* state functions with current values to initialize
222 * driver state.
223 * Only the Intel drivers use this so far.
224 */
225 void
226 _mesa_init_driver_state(struct gl_context *ctx)
227 {
228 ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
229
230 ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
231
232 ctx->Driver.BlendEquationSeparate(ctx,
233 ctx->Color.Blend[0].EquationRGB,
234 ctx->Color.Blend[0].EquationA);
235
236 ctx->Driver.BlendFuncSeparate(ctx,
237 ctx->Color.Blend[0].SrcRGB,
238 ctx->Color.Blend[0].DstRGB,
239 ctx->Color.Blend[0].SrcA,
240 ctx->Color.Blend[0].DstA);
241
242 if (ctx->Driver.ColorMaskIndexed) {
243 GLuint i;
244 for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
245 ctx->Driver.ColorMaskIndexed(ctx, i,
246 ctx->Color.ColorMask[i][RCOMP],
247 ctx->Color.ColorMask[i][GCOMP],
248 ctx->Color.ColorMask[i][BCOMP],
249 ctx->Color.ColorMask[i][ACOMP]);
250 }
251 }
252 else {
253 ctx->Driver.ColorMask(ctx,
254 ctx->Color.ColorMask[0][RCOMP],
255 ctx->Color.ColorMask[0][GCOMP],
256 ctx->Color.ColorMask[0][BCOMP],
257 ctx->Color.ColorMask[0][ACOMP]);
258 }
259
260 ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
261 ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
262 ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
263
264 ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
265 ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
266 ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
267 ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
268 ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
269 ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
270 ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
271 ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
272 ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
273 ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
274 ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
275 ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
276 ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil._Enabled);
277 ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
278 ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
279 ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
280 ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
281 ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
282
283 ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
284 {
285 GLfloat mode = (GLfloat) ctx->Fog.Mode;
286 ctx->Driver.Fogfv(ctx, GL_FOG_MODE, &mode);
287 }
288 ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
289 ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
290 ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
291
292 ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
293
294 {
295 GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
296 ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
297 }
298
299 ctx->Driver.LineWidth(ctx, ctx->Line.Width);
300 ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
301 ctx->Driver.PointSize(ctx, ctx->Point.Size);
302 ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
303 ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
304 ctx->Scissor.Width, ctx->Scissor.Height);
305 ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
306 ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
307 ctx->Stencil.Function[0],
308 ctx->Stencil.Ref[0],
309 ctx->Stencil.ValueMask[0]);
310 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
311 ctx->Stencil.Function[1],
312 ctx->Stencil.Ref[1],
313 ctx->Stencil.ValueMask[1]);
314 ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
315 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
316 ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
317 ctx->Stencil.FailFunc[0],
318 ctx->Stencil.ZFailFunc[0],
319 ctx->Stencil.ZPassFunc[0]);
320 ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
321 ctx->Stencil.FailFunc[1],
322 ctx->Stencil.ZFailFunc[1],
323 ctx->Stencil.ZPassFunc[1]);
324
325
326 ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
327 }