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