Remove _mesa_memcpy in favor of plain memcpy.
[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 * 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/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/renderbuffer.h"
34 #include "main/texcompress.h"
35 #include "main/texformat.h"
36 #include "main/texgetimage.h"
37 #include "main/teximage.h"
38 #include "main/texobj.h"
39 #include "main/texstore.h"
40 #if FEATURE_ARB_vertex_buffer_object
41 #include "main/bufferobj.h"
42 #endif
43 #if FEATURE_EXT_framebuffer_object
44 #include "main/fbobject.h"
45 #include "main/texrender.h"
46 #endif
47 #if FEATURE_ARB_sync
48 #include "main/syncobj.h"
49 #endif
50
51 #include "shader/program.h"
52 #include "shader/shader_api.h"
53 #include "tnl/tnl.h"
54 #include "swrast/swrast.h"
55
56 #include "driverfuncs.h"
57 #include "meta.h"
58
59
60
61 /**
62 * Plug in default functions for all pointers in the dd_function_table
63 * structure.
64 * Device drivers should call this function and then plug in any
65 * functions which it wants to override.
66 * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
67 *
68 * \param table the dd_function_table to initialize
69 */
70 void
71 _mesa_init_driver_functions(struct dd_function_table *driver)
72 {
73 _mesa_bzero(driver, sizeof(*driver));
74
75 driver->GetString = NULL; /* REQUIRED! */
76 driver->UpdateState = NULL; /* REQUIRED! */
77 driver->GetBufferSize = NULL; /* REQUIRED! */
78 driver->ResizeBuffers = _mesa_resize_framebuffer;
79 driver->Error = NULL;
80
81 driver->Finish = NULL;
82 driver->Flush = NULL;
83
84 /* framebuffer/image functions */
85 driver->Clear = _swrast_Clear;
86 driver->Accum = _swrast_Accum;
87 driver->RasterPos = _tnl_RasterPos;
88 driver->DrawPixels = _swrast_DrawPixels;
89 driver->ReadPixels = _swrast_ReadPixels;
90 driver->CopyPixels = _swrast_CopyPixels;
91 driver->Bitmap = _swrast_Bitmap;
92
93 /* Texture functions */
94 driver->ChooseTextureFormat = _mesa_choose_tex_format;
95 driver->TexImage1D = _mesa_store_teximage1d;
96 driver->TexImage2D = _mesa_store_teximage2d;
97 driver->TexImage3D = _mesa_store_teximage3d;
98 driver->TexSubImage1D = _mesa_store_texsubimage1d;
99 driver->TexSubImage2D = _mesa_store_texsubimage2d;
100 driver->TexSubImage3D = _mesa_store_texsubimage3d;
101 driver->GetTexImage = _mesa_get_teximage;
102 driver->CopyTexImage1D = _mesa_meta_CopyTexImage1D;
103 driver->CopyTexImage2D = _mesa_meta_CopyTexImage2D;
104 driver->CopyTexSubImage1D = _mesa_meta_CopyTexSubImage1D;
105 driver->CopyTexSubImage2D = _mesa_meta_CopyTexSubImage2D;
106 driver->CopyTexSubImage3D = _mesa_meta_CopyTexSubImage3D;
107 driver->GenerateMipmap = _mesa_meta_GenerateMipmap;
108 driver->TestProxyTexImage = _mesa_test_proxy_teximage;
109 driver->CompressedTexImage1D = _mesa_store_compressed_teximage1d;
110 driver->CompressedTexImage2D = _mesa_store_compressed_teximage2d;
111 driver->CompressedTexImage3D = _mesa_store_compressed_teximage3d;
112 driver->CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
113 driver->CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
114 driver->CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
115 driver->GetCompressedTexImage = _mesa_get_compressed_teximage;
116 driver->BindTexture = NULL;
117 driver->NewTextureObject = _mesa_new_texture_object;
118 driver->DeleteTexture = _mesa_delete_texture_object;
119 driver->NewTextureImage = _mesa_new_texture_image;
120 driver->FreeTexImageData = _mesa_free_texture_image_data;
121 driver->MapTexture = NULL;
122 driver->UnmapTexture = NULL;
123 driver->TextureMemCpy = memcpy;
124 driver->IsTextureResident = NULL;
125 driver->UpdateTexturePalette = NULL;
126
127 /* imaging */
128 driver->CopyColorTable = _mesa_meta_CopyColorTable;
129 driver->CopyColorSubTable = _mesa_meta_CopyColorSubTable;
130 driver->CopyConvolutionFilter1D = _mesa_meta_CopyConvolutionFilter1D;
131 driver->CopyConvolutionFilter2D = _mesa_meta_CopyConvolutionFilter2D;
132
133 /* Vertex/fragment programs */
134 driver->BindProgram = NULL;
135 driver->NewProgram = _mesa_new_program;
136 driver->DeleteProgram = _mesa_delete_program;
137
138 /* simple state commands */
139 driver->AlphaFunc = NULL;
140 driver->BlendColor = NULL;
141 driver->BlendEquationSeparate = NULL;
142 driver->BlendFuncSeparate = NULL;
143 driver->ClearColor = NULL;
144 driver->ClearDepth = NULL;
145 driver->ClearIndex = NULL;
146 driver->ClearStencil = NULL;
147 driver->ClipPlane = NULL;
148 driver->ColorMask = NULL;
149 driver->ColorMaterial = NULL;
150 driver->CullFace = NULL;
151 driver->DrawBuffer = NULL;
152 driver->DrawBuffers = NULL;
153 driver->FrontFace = NULL;
154 driver->DepthFunc = NULL;
155 driver->DepthMask = NULL;
156 driver->DepthRange = NULL;
157 driver->Enable = NULL;
158 driver->Fogfv = NULL;
159 driver->Hint = NULL;
160 driver->IndexMask = NULL;
161 driver->Lightfv = NULL;
162 driver->LightModelfv = NULL;
163 driver->LineStipple = NULL;
164 driver->LineWidth = NULL;
165 driver->LogicOpcode = NULL;
166 driver->PointParameterfv = NULL;
167 driver->PointSize = NULL;
168 driver->PolygonMode = NULL;
169 driver->PolygonOffset = NULL;
170 driver->PolygonStipple = NULL;
171 driver->ReadBuffer = NULL;
172 driver->RenderMode = NULL;
173 driver->Scissor = NULL;
174 driver->ShadeModel = NULL;
175 driver->StencilFuncSeparate = NULL;
176 driver->StencilOpSeparate = NULL;
177 driver->StencilMaskSeparate = NULL;
178 driver->TexGen = NULL;
179 driver->TexEnv = NULL;
180 driver->TexParameter = NULL;
181 driver->Viewport = NULL;
182
183 /* state queries */
184 driver->GetBooleanv = NULL;
185 driver->GetDoublev = NULL;
186 driver->GetFloatv = NULL;
187 driver->GetIntegerv = NULL;
188 driver->GetInteger64v = NULL;
189 driver->GetPointerv = NULL;
190
191 /* buffer objects */
192 _mesa_init_buffer_object_functions(driver);
193
194 /* query objects */
195 _mesa_init_query_object_functions(driver);
196
197 #if FEATURE_ARB_sync
198 _mesa_init_sync_object_functions(driver);
199 #endif
200
201 #if FEATURE_EXT_framebuffer_object
202 driver->NewFramebuffer = _mesa_new_framebuffer;
203 driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
204 driver->RenderTexture = _mesa_render_texture;
205 driver->FinishRenderTexture = _mesa_finish_render_texture;
206 driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
207 #endif
208
209 #if FEATURE_EXT_framebuffer_blit
210 driver->BlitFramebuffer = _swrast_BlitFramebuffer;
211 #endif
212
213 /* APPLE_vertex_array_object */
214 driver->NewArrayObject = _mesa_new_array_object;
215 driver->DeleteArrayObject = _mesa_delete_array_object;
216 driver->BindArrayObject = NULL;
217
218 /* T&L stuff */
219 driver->NeedValidate = GL_FALSE;
220 driver->ValidateTnlModule = NULL;
221 driver->CurrentExecPrimitive = 0;
222 driver->CurrentSavePrimitive = 0;
223 driver->NeedFlush = 0;
224 driver->SaveNeedFlush = 0;
225
226 driver->ProgramStringNotify = _tnl_program_string;
227 driver->FlushVertices = NULL;
228 driver->SaveFlushVertices = NULL;
229 driver->NotifySaveBegin = NULL;
230 driver->LightingSpaceChange = NULL;
231
232 /* display list */
233 driver->NewList = NULL;
234 driver->EndList = NULL;
235 driver->BeginCallList = NULL;
236 driver->EndCallList = NULL;
237
238
239 /* XXX temporary here */
240 _mesa_init_glsl_driver_functions(driver);
241 }
242
243
244 /**
245 * Call the ctx->Driver.* state functions with current values to initialize
246 * driver state.
247 * Only the Intel drivers use this so far.
248 */
249 void
250 _mesa_init_driver_state(GLcontext *ctx)
251 {
252 ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
253
254 ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
255
256 ctx->Driver.BlendEquationSeparate(ctx,
257 ctx->Color.BlendEquationRGB,
258 ctx->Color.BlendEquationA);
259
260 ctx->Driver.BlendFuncSeparate(ctx,
261 ctx->Color.BlendSrcRGB,
262 ctx->Color.BlendDstRGB,
263 ctx->Color.BlendSrcA, ctx->Color.BlendDstA);
264
265 if (ctx->Driver.ColorMaskIndexed) {
266 GLuint i;
267 for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
268 ctx->Driver.ColorMaskIndexed(ctx, i,
269 ctx->Color.ColorMask[0][RCOMP],
270 ctx->Color.ColorMask[0][GCOMP],
271 ctx->Color.ColorMask[0][BCOMP],
272 ctx->Color.ColorMask[0][ACOMP]);
273 }
274 }
275 else {
276 ctx->Driver.ColorMask(ctx,
277 ctx->Color.ColorMask[0][RCOMP],
278 ctx->Color.ColorMask[0][GCOMP],
279 ctx->Color.ColorMask[0][BCOMP],
280 ctx->Color.ColorMask[0][ACOMP]);
281 }
282
283 ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
284 ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
285 ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
286
287 ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
288 ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
289 ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
290 ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
291 ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
292 ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
293 ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
294 ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
295 ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
296 ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
297 ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
298 ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
299 ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil._Enabled);
300 ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
301 ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
302 ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
303 ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
304 ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
305
306 ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
307 ctx->Driver.Fogfv(ctx, GL_FOG_MODE, 0);
308 ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
309 ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
310 ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
311
312 ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
313
314 {
315 GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
316 ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
317 }
318
319 ctx->Driver.LineWidth(ctx, ctx->Line.Width);
320 ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
321 ctx->Driver.PointSize(ctx, ctx->Point.Size);
322 ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
323 ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
324 ctx->Scissor.Width, ctx->Scissor.Height);
325 ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
326 ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
327 ctx->Stencil.Function[0],
328 ctx->Stencil.Ref[0],
329 ctx->Stencil.ValueMask[0]);
330 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
331 ctx->Stencil.Function[1],
332 ctx->Stencil.Ref[1],
333 ctx->Stencil.ValueMask[1]);
334 ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
335 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
336 ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
337 ctx->Stencil.FailFunc[0],
338 ctx->Stencil.ZFailFunc[0],
339 ctx->Stencil.ZPassFunc[0]);
340 ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
341 ctx->Stencil.FailFunc[1],
342 ctx->Stencil.ZFailFunc[1],
343 ctx->Stencil.ZPassFunc[1]);
344
345
346 ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
347 }