Move guts of glRasterPos down into T&L module.
[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 "glheader.h"
27 #include "imports.h"
28 #include "buffers.h"
29 #include "context.h"
30 #include "framebuffer.h"
31 #include "program.h"
32 #include "prog_execute.h"
33 #include "queryobj.h"
34 #include "renderbuffer.h"
35 #include "texcompress.h"
36 #include "texformat.h"
37 #include "teximage.h"
38 #include "texobj.h"
39 #include "texstore.h"
40 #if FEATURE_ARB_vertex_buffer_object
41 #include "bufferobj.h"
42 #endif
43 #if FEATURE_EXT_framebuffer_object
44 #include "fbobject.h"
45 #include "texrender.h"
46 #endif
47 #include "shader_api.h"
48 #include "arrayobj.h"
49
50 #include "driverfuncs.h"
51 #include "tnl/tnl.h"
52 #include "swrast/swrast.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 _mesa_bzero(driver, 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 = _swrast_Accum;
82 driver->RasterPos = _tnl_RasterPos;
83 driver->DrawPixels = _swrast_DrawPixels;
84 driver->ReadPixels = _swrast_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_get_teximage;
97 driver->CopyTexImage1D = _swrast_copy_teximage1d;
98 driver->CopyTexImage2D = _swrast_copy_teximage2d;
99 driver->CopyTexSubImage1D = _swrast_copy_texsubimage1d;
100 driver->CopyTexSubImage2D = _swrast_copy_texsubimage2d;
101 driver->CopyTexSubImage3D = _swrast_copy_texsubimage3d;
102 driver->TestProxyTexImage = _mesa_test_proxy_teximage;
103 driver->CompressedTexImage1D = _mesa_store_compressed_teximage1d;
104 driver->CompressedTexImage2D = _mesa_store_compressed_teximage2d;
105 driver->CompressedTexImage3D = _mesa_store_compressed_teximage3d;
106 driver->CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
107 driver->CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
108 driver->CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
109 driver->GetCompressedTexImage = _mesa_get_compressed_teximage;
110 driver->CompressedTextureSize = _mesa_compressed_texture_size;
111 driver->BindTexture = NULL;
112 driver->NewTextureObject = _mesa_new_texture_object;
113 driver->DeleteTexture = _mesa_delete_texture_object;
114 driver->NewTextureImage = _mesa_new_texture_image;
115 driver->FreeTexImageData = _mesa_free_texture_image_data;
116 driver->TextureMemCpy = _mesa_memcpy;
117 driver->IsTextureResident = NULL;
118 driver->PrioritizeTexture = NULL;
119 driver->ActiveTexture = NULL;
120 driver->UpdateTexturePalette = NULL;
121
122 /* imaging */
123 driver->CopyColorTable = _swrast_CopyColorTable;
124 driver->CopyColorSubTable = _swrast_CopyColorSubTable;
125 driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
126 driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
127
128 /* Vertex/fragment programs */
129 driver->BindProgram = NULL;
130 driver->NewProgram = _mesa_new_program;
131 driver->DeleteProgram = _mesa_delete_program;
132 #if FEATURE_MESA_program_debug
133 driver->GetProgramRegister = _mesa_get_program_register;
134 #endif /* FEATURE_MESA_program_debug */
135
136 /* simple state commands */
137 driver->AlphaFunc = NULL;
138 driver->BlendColor = NULL;
139 driver->BlendEquationSeparate = NULL;
140 driver->BlendFuncSeparate = NULL;
141 driver->ClearColor = NULL;
142 driver->ClearDepth = NULL;
143 driver->ClearIndex = NULL;
144 driver->ClearStencil = NULL;
145 driver->ClipPlane = NULL;
146 driver->ColorMask = NULL;
147 driver->ColorMaterial = NULL;
148 driver->CullFace = NULL;
149 driver->DrawBuffer = NULL;
150 driver->DrawBuffers = NULL;
151 driver->FrontFace = NULL;
152 driver->DepthFunc = NULL;
153 driver->DepthMask = NULL;
154 driver->DepthRange = NULL;
155 driver->Enable = NULL;
156 driver->Fogfv = NULL;
157 driver->Hint = NULL;
158 driver->IndexMask = NULL;
159 driver->Lightfv = NULL;
160 driver->LightModelfv = NULL;
161 driver->LineStipple = NULL;
162 driver->LineWidth = NULL;
163 driver->LogicOpcode = NULL;
164 driver->PointParameterfv = NULL;
165 driver->PointSize = NULL;
166 driver->PolygonMode = NULL;
167 driver->PolygonOffset = NULL;
168 driver->PolygonStipple = NULL;
169 driver->ReadBuffer = NULL;
170 driver->RenderMode = NULL;
171 driver->Scissor = NULL;
172 driver->ShadeModel = NULL;
173 driver->StencilFuncSeparate = NULL;
174 driver->StencilOpSeparate = NULL;
175 driver->StencilMaskSeparate = NULL;
176 driver->TexGen = NULL;
177 driver->TexEnv = NULL;
178 driver->TexParameter = NULL;
179 driver->TextureMatrix = NULL;
180 driver->Viewport = NULL;
181
182 /* vertex arrays */
183 driver->VertexPointer = NULL;
184 driver->NormalPointer = NULL;
185 driver->ColorPointer = NULL;
186 driver->FogCoordPointer = NULL;
187 driver->IndexPointer = NULL;
188 driver->SecondaryColorPointer = NULL;
189 driver->TexCoordPointer = NULL;
190 driver->EdgeFlagPointer = NULL;
191 driver->VertexAttribPointer = NULL;
192 driver->LockArraysEXT = NULL;
193 driver->UnlockArraysEXT = NULL;
194
195 /* state queries */
196 driver->GetBooleanv = NULL;
197 driver->GetDoublev = NULL;
198 driver->GetFloatv = NULL;
199 driver->GetIntegerv = NULL;
200 driver->GetPointerv = NULL;
201
202 #if FEATURE_ARB_vertex_buffer_object
203 driver->NewBufferObject = _mesa_new_buffer_object;
204 driver->DeleteBuffer = _mesa_delete_buffer_object;
205 driver->BindBuffer = NULL;
206 driver->BufferData = _mesa_buffer_data;
207 driver->BufferSubData = _mesa_buffer_subdata;
208 driver->GetBufferSubData = _mesa_buffer_get_subdata;
209 driver->MapBuffer = _mesa_buffer_map;
210 driver->UnmapBuffer = _mesa_buffer_unmap;
211 #endif
212
213 #if FEATURE_EXT_framebuffer_object
214 driver->NewFramebuffer = _mesa_new_framebuffer;
215 driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
216 driver->RenderTexture = _mesa_render_texture;
217 driver->FinishRenderTexture = _mesa_finish_render_texture;
218 driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
219 #endif
220
221 #if FEATURE_EXT_framebuffer_blit
222 driver->BlitFramebuffer = _swrast_BlitFramebuffer;
223 #endif
224
225 /* query objects */
226 driver->NewQueryObject = _mesa_new_query_object;
227 driver->BeginQuery = NULL;
228 driver->EndQuery = NULL;
229
230 /* APPLE_vertex_array_object */
231 driver->NewArrayObject = _mesa_new_array_object;
232 driver->DeleteArrayObject = _mesa_delete_array_object;
233 driver->BindArrayObject = NULL;
234
235 /* T&L stuff */
236 driver->NeedValidate = GL_FALSE;
237 driver->ValidateTnlModule = NULL;
238 driver->CurrentExecPrimitive = 0;
239 driver->CurrentSavePrimitive = 0;
240 driver->NeedFlush = 0;
241 driver->SaveNeedFlush = 0;
242
243 driver->ProgramStringNotify = _tnl_program_string;
244 driver->FlushVertices = NULL;
245 driver->SaveFlushVertices = NULL;
246 driver->NotifySaveBegin = NULL;
247 driver->LightingSpaceChange = NULL;
248
249 /* display list */
250 driver->NewList = NULL;
251 driver->EndList = NULL;
252 driver->BeginCallList = NULL;
253 driver->EndCallList = NULL;
254
255
256 /* XXX temporary here */
257 _mesa_init_glsl_driver_functions(driver);
258 }
259
260
261 /**
262 * Plug in Mesa's GLSL functions.
263 */
264 void
265 _mesa_init_glsl_driver_functions(struct dd_function_table *driver)
266 {
267 driver->AttachShader = _mesa_attach_shader;
268 driver->BindAttribLocation = _mesa_bind_attrib_location;
269 driver->CompileShader = _mesa_compile_shader;
270 driver->CreateProgram = _mesa_create_program;
271 driver->CreateShader = _mesa_create_shader;
272 driver->DeleteProgram2 = _mesa_delete_program2;
273 driver->DeleteShader = _mesa_delete_shader;
274 driver->DetachShader = _mesa_detach_shader;
275 driver->GetActiveAttrib = _mesa_get_active_attrib;
276 driver->GetActiveUniform = _mesa_get_active_uniform;
277 driver->GetAttachedShaders = _mesa_get_attached_shaders;
278 driver->GetAttribLocation = _mesa_get_attrib_location;
279 driver->GetHandle = _mesa_get_handle;
280 driver->GetProgramiv = _mesa_get_programiv;
281 driver->GetProgramInfoLog = _mesa_get_program_info_log;
282 driver->GetShaderiv = _mesa_get_shaderiv;
283 driver->GetShaderInfoLog = _mesa_get_shader_info_log;
284 driver->GetShaderSource = _mesa_get_shader_source;
285 driver->GetUniformfv = _mesa_get_uniformfv;
286 driver->GetUniformLocation = _mesa_get_uniform_location;
287 driver->IsProgram = _mesa_is_program;
288 driver->IsShader = _mesa_is_shader;
289 driver->LinkProgram = _mesa_link_program;
290 driver->ShaderSource = _mesa_shader_source;
291 driver->Uniform = _mesa_uniform;
292 driver->UniformMatrix = _mesa_uniform_matrix;
293 driver->UseProgram = _mesa_use_program;
294 driver->ValidateProgram = _mesa_validate_program;
295 }
296
297
298 /**
299 * Call the ctx->Driver.* state functions with current values to initialize
300 * driver state.
301 * Only the Intel drivers use this so far.
302 */
303 void
304 _mesa_init_driver_state(GLcontext *ctx)
305 {
306 ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
307
308 ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
309
310 ctx->Driver.BlendEquationSeparate(ctx,
311 ctx->Color.BlendEquationRGB,
312 ctx->Color.BlendEquationA);
313
314 ctx->Driver.BlendFuncSeparate(ctx,
315 ctx->Color.BlendSrcRGB,
316 ctx->Color.BlendDstRGB,
317 ctx->Color.BlendSrcA, ctx->Color.BlendDstA);
318
319 ctx->Driver.ColorMask(ctx,
320 ctx->Color.ColorMask[RCOMP],
321 ctx->Color.ColorMask[GCOMP],
322 ctx->Color.ColorMask[BCOMP],
323 ctx->Color.ColorMask[ACOMP]);
324
325 ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
326 ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
327 ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
328
329 ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
330 ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
331 ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
332 ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
333 ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
334 ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
335 ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
336 ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
337 ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
338 ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
339 ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
340 ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
341 ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled);
342 ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
343 ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
344 ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
345 ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
346 ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
347
348 ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
349 ctx->Driver.Fogfv(ctx, GL_FOG_MODE, 0);
350 ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
351 ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
352 ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
353
354 ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
355
356 {
357 GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
358 ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
359 }
360
361 ctx->Driver.LineWidth(ctx, ctx->Line.Width);
362 ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
363 ctx->Driver.PointSize(ctx, ctx->Point.Size);
364 ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
365 ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
366 ctx->Scissor.Width, ctx->Scissor.Height);
367 ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
368 ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
369 ctx->Stencil.Function[0],
370 ctx->Stencil.Ref[0],
371 ctx->Stencil.ValueMask[0]);
372 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
373 ctx->Stencil.Function[1],
374 ctx->Stencil.Ref[1],
375 ctx->Stencil.ValueMask[1]);
376 ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
377 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
378 ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
379 ctx->Stencil.FailFunc[0],
380 ctx->Stencil.ZFailFunc[0],
381 ctx->Stencil.ZPassFunc[0]);
382 ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
383 ctx->Stencil.FailFunc[1],
384 ctx->Stencil.ZFailFunc[1],
385 ctx->Stencil.ZPassFunc[1]);
386
387
388 ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
389 }