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