blob: 03fbab69e3982dfd0794b229c379b27ccd963028 [file] [log] [blame]
Brian Paul988a8862004-01-20 02:36:44 +00001/*
2 * Mesa 3-D graphics library
Briana99114a2007-05-22 16:54:25 -06003 * Version: 7.1
Brian Paul988a8862004-01-20 02:36:44 +00004 *
Brian0bf5dbe2006-12-19 18:02:41 -07005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Brian Paul988a8862004-01-20 02:36:44 +00006 *
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"
root99441742007-09-11 15:24:43 -060028#include "arrayobj.h"
Brian Paul988a8862004-01-20 02:36:44 +000029#include "buffers.h"
30#include "context.h"
Brian Paule4b23562005-05-04 20:11:35 +000031#include "framebuffer.h"
Brianb1502582007-04-21 12:54:23 -060032#include "queryobj.h"
Brian Paule4b23562005-05-04 20:11:35 +000033#include "renderbuffer.h"
Brian Paul8f04c122004-04-27 13:39:20 +000034#include "texcompress.h"
Brian Paul988a8862004-01-20 02:36:44 +000035#include "texformat.h"
36#include "teximage.h"
37#include "texobj.h"
38#include "texstore.h"
Brian Paul2c6f9112005-02-24 05:47:06 +000039#if FEATURE_ARB_vertex_buffer_object
Brian Paul988a8862004-01-20 02:36:44 +000040#include "bufferobj.h"
Brian Paul2c6f9112005-02-24 05:47:06 +000041#endif
42#if FEATURE_EXT_framebuffer_object
43#include "fbobject.h"
Brian Paule4b23562005-05-04 20:11:35 +000044#include "texrender.h"
Brian Paul2c6f9112005-02-24 05:47:06 +000045#endif
Brian Paul988a8862004-01-20 02:36:44 +000046
root99441742007-09-11 15:24:43 -060047#include "shader/program.h"
48#include "shader/prog_execute.h"
49#include "shader/shader_api.h"
Brian Paul988a8862004-01-20 02:36:44 +000050#include "driverfuncs.h"
Brian Paulb5ee3682005-10-28 14:32:49 +000051#include "tnl/tnl.h"
Brian Paul988a8862004-01-20 02:36:44 +000052#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 */
65void
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! */
Brian Paule4b23562005-05-04 20:11:35 +000073 driver->ResizeBuffers = _mesa_resize_framebuffer;
Brian Paul988a8862004-01-20 02:36:44 +000074 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->DrawPixels = _swrast_DrawPixels;
83 driver->ReadPixels = _swrast_ReadPixels;
84 driver->CopyPixels = _swrast_CopyPixels;
85 driver->Bitmap = _swrast_Bitmap;
86
87 /* Texture functions */
88 driver->ChooseTextureFormat = _mesa_choose_tex_format;
89 driver->TexImage1D = _mesa_store_teximage1d;
90 driver->TexImage2D = _mesa_store_teximage2d;
91 driver->TexImage3D = _mesa_store_teximage3d;
92 driver->TexSubImage1D = _mesa_store_texsubimage1d;
93 driver->TexSubImage2D = _mesa_store_texsubimage2d;
94 driver->TexSubImage3D = _mesa_store_texsubimage3d;
Brian Paul68d293b2004-12-12 19:03:16 +000095 driver->GetTexImage = _mesa_get_teximage;
Brian Paul988a8862004-01-20 02:36:44 +000096 driver->CopyTexImage1D = _swrast_copy_teximage1d;
97 driver->CopyTexImage2D = _swrast_copy_teximage2d;
98 driver->CopyTexSubImage1D = _swrast_copy_texsubimage1d;
99 driver->CopyTexSubImage2D = _swrast_copy_texsubimage2d;
100 driver->CopyTexSubImage3D = _swrast_copy_texsubimage3d;
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;
Brian Paul68d293b2004-12-12 19:03:16 +0000108 driver->GetCompressedTexImage = _mesa_get_compressed_teximage;
Brian Paul8f04c122004-04-27 13:39:20 +0000109 driver->CompressedTextureSize = _mesa_compressed_texture_size;
Brian Paul988a8862004-01-20 02:36:44 +0000110 driver->BindTexture = NULL;
111 driver->NewTextureObject = _mesa_new_texture_object;
112 driver->DeleteTexture = _mesa_delete_texture_object;
113 driver->NewTextureImage = _mesa_new_texture_image;
Keith Whitwell3e62d3a2005-03-22 14:27:10 +0000114 driver->FreeTexImageData = _mesa_free_texture_image_data;
Brian61fbc812007-11-29 08:12:33 -0700115 driver->MapTexture = NULL;
116 driver->UnmapTexture = NULL;
Keith Whitwell17bcf9f2005-05-23 12:17:27 +0000117 driver->TextureMemCpy = _mesa_memcpy;
Brian Paul988a8862004-01-20 02:36:44 +0000118 driver->IsTextureResident = NULL;
119 driver->PrioritizeTexture = NULL;
120 driver->ActiveTexture = NULL;
121 driver->UpdateTexturePalette = NULL;
122
123 /* imaging */
124 driver->CopyColorTable = _swrast_CopyColorTable;
125 driver->CopyColorSubTable = _swrast_CopyColorSubTable;
126 driver->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
127 driver->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
128
Brian Paul4d859f72004-01-23 18:57:05 +0000129 /* Vertex/fragment programs */
130 driver->BindProgram = NULL;
131 driver->NewProgram = _mesa_new_program;
132 driver->DeleteProgram = _mesa_delete_program;
Brian Paul39c4daa2006-10-10 21:43:31 +0000133#if FEATURE_MESA_program_debug
Brian21bcb2e2007-02-25 18:35:47 -0700134 driver->GetProgramRegister = _mesa_get_program_register;
Brian Paul39c4daa2006-10-10 21:43:31 +0000135#endif /* FEATURE_MESA_program_debug */
Brian Paul4d859f72004-01-23 18:57:05 +0000136
Brian Paul988a8862004-01-20 02:36:44 +0000137 /* simple state commands */
138 driver->AlphaFunc = NULL;
139 driver->BlendColor = NULL;
Ian Romanickc93105e2004-01-27 18:52:40 +0000140 driver->BlendEquationSeparate = NULL;
Brian Paul988a8862004-01-20 02:36:44 +0000141 driver->BlendFuncSeparate = NULL;
142 driver->ClearColor = NULL;
143 driver->ClearDepth = NULL;
144 driver->ClearIndex = NULL;
145 driver->ClearStencil = NULL;
146 driver->ClipPlane = NULL;
147 driver->ColorMask = NULL;
148 driver->ColorMaterial = NULL;
149 driver->CullFace = NULL;
Brian Paulacafeeb2005-09-03 16:57:58 +0000150 driver->DrawBuffer = NULL;
151 driver->DrawBuffers = NULL;
Brian Paul988a8862004-01-20 02:36:44 +0000152 driver->FrontFace = NULL;
153 driver->DepthFunc = NULL;
154 driver->DepthMask = NULL;
155 driver->DepthRange = NULL;
156 driver->Enable = NULL;
157 driver->Fogfv = NULL;
158 driver->Hint = NULL;
159 driver->IndexMask = NULL;
160 driver->Lightfv = NULL;
161 driver->LightModelfv = NULL;
162 driver->LineStipple = NULL;
163 driver->LineWidth = NULL;
164 driver->LogicOpcode = NULL;
165 driver->PointParameterfv = NULL;
166 driver->PointSize = NULL;
167 driver->PolygonMode = NULL;
168 driver->PolygonOffset = NULL;
169 driver->PolygonStipple = NULL;
170 driver->ReadBuffer = NULL;
171 driver->RenderMode = NULL;
172 driver->Scissor = NULL;
173 driver->ShadeModel = NULL;
Brian Paul878c3712005-09-13 04:42:09 +0000174 driver->StencilFuncSeparate = NULL;
Brian Paul5179f672005-09-13 01:17:01 +0000175 driver->StencilOpSeparate = NULL;
Brian Paul878c3712005-09-13 04:42:09 +0000176 driver->StencilMaskSeparate = NULL;
Brian Paul988a8862004-01-20 02:36:44 +0000177 driver->TexGen = NULL;
178 driver->TexEnv = NULL;
179 driver->TexParameter = NULL;
180 driver->TextureMatrix = NULL;
181 driver->Viewport = NULL;
182
183 /* vertex arrays */
184 driver->VertexPointer = NULL;
185 driver->NormalPointer = NULL;
186 driver->ColorPointer = NULL;
187 driver->FogCoordPointer = NULL;
188 driver->IndexPointer = NULL;
189 driver->SecondaryColorPointer = NULL;
190 driver->TexCoordPointer = NULL;
191 driver->EdgeFlagPointer = NULL;
192 driver->VertexAttribPointer = NULL;
193 driver->LockArraysEXT = NULL;
194 driver->UnlockArraysEXT = NULL;
195
196 /* state queries */
197 driver->GetBooleanv = NULL;
198 driver->GetDoublev = NULL;
199 driver->GetFloatv = NULL;
200 driver->GetIntegerv = NULL;
201 driver->GetPointerv = NULL;
202
203#if FEATURE_ARB_vertex_buffer_object
204 driver->NewBufferObject = _mesa_new_buffer_object;
205 driver->DeleteBuffer = _mesa_delete_buffer_object;
206 driver->BindBuffer = NULL;
207 driver->BufferData = _mesa_buffer_data;
208 driver->BufferSubData = _mesa_buffer_subdata;
209 driver->GetBufferSubData = _mesa_buffer_get_subdata;
210 driver->MapBuffer = _mesa_buffer_map;
Brian Paul7eab3372004-10-31 15:23:42 +0000211 driver->UnmapBuffer = _mesa_buffer_unmap;
Brian Paul988a8862004-01-20 02:36:44 +0000212#endif
213
Brian Paul2c6f9112005-02-24 05:47:06 +0000214#if FEATURE_EXT_framebuffer_object
215 driver->NewFramebuffer = _mesa_new_framebuffer;
Brian Paule4b23562005-05-04 20:11:35 +0000216 driver->NewRenderbuffer = _mesa_new_soft_renderbuffer;
Brian Paulea4fe662006-03-26 05:22:17 +0000217 driver->RenderTexture = _mesa_render_texture;
218 driver->FinishRenderTexture = _mesa_finish_render_texture;
Brian Paule4b23562005-05-04 20:11:35 +0000219 driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
Brian Paul2c6f9112005-02-24 05:47:06 +0000220#endif
221
Brian Paulafa1df52006-03-02 03:45:28 +0000222#if FEATURE_EXT_framebuffer_blit
223 driver->BlitFramebuffer = _swrast_BlitFramebuffer;
224#endif
225
Brian Paul23ffc3a2005-08-27 13:56:08 +0000226 /* query objects */
Brian Paul4fb99502005-09-02 13:42:49 +0000227 driver->NewQueryObject = _mesa_new_query_object;
Brian Paul23ffc3a2005-08-27 13:56:08 +0000228 driver->BeginQuery = NULL;
229 driver->EndQuery = NULL;
230
Ian Romanickee34e6e2006-06-12 16:26:29 +0000231 /* APPLE_vertex_array_object */
232 driver->NewArrayObject = _mesa_new_array_object;
233 driver->DeleteArrayObject = _mesa_delete_array_object;
234 driver->BindArrayObject = NULL;
235
Brian Paul988a8862004-01-20 02:36:44 +0000236 /* T&L stuff */
237 driver->NeedValidate = GL_FALSE;
238 driver->ValidateTnlModule = NULL;
239 driver->CurrentExecPrimitive = 0;
240 driver->CurrentSavePrimitive = 0;
241 driver->NeedFlush = 0;
242 driver->SaveNeedFlush = 0;
243
Brian Paulb5ee3682005-10-28 14:32:49 +0000244 driver->ProgramStringNotify = _tnl_program_string;
Brian Paul988a8862004-01-20 02:36:44 +0000245 driver->FlushVertices = NULL;
246 driver->SaveFlushVertices = NULL;
247 driver->NotifySaveBegin = NULL;
248 driver->LightingSpaceChange = NULL;
Brian Paul988a8862004-01-20 02:36:44 +0000249
250 /* display list */
251 driver->NewList = NULL;
252 driver->EndList = NULL;
253 driver->BeginCallList = NULL;
254 driver->EndCallList = NULL;
Brian0bf5dbe2006-12-19 18:02:41 -0700255
256
257 /* XXX temporary here */
258 _mesa_init_glsl_driver_functions(driver);
259}
260
261
262/**
263 * Plug in Mesa's GLSL functions.
264 */
265void
266_mesa_init_glsl_driver_functions(struct dd_function_table *driver)
267{
268 driver->AttachShader = _mesa_attach_shader;
269 driver->BindAttribLocation = _mesa_bind_attrib_location;
270 driver->CompileShader = _mesa_compile_shader;
271 driver->CreateProgram = _mesa_create_program;
272 driver->CreateShader = _mesa_create_shader;
273 driver->DeleteProgram2 = _mesa_delete_program2;
274 driver->DeleteShader = _mesa_delete_shader;
275 driver->DetachShader = _mesa_detach_shader;
276 driver->GetActiveAttrib = _mesa_get_active_attrib;
277 driver->GetActiveUniform = _mesa_get_active_uniform;
278 driver->GetAttachedShaders = _mesa_get_attached_shaders;
279 driver->GetAttribLocation = _mesa_get_attrib_location;
280 driver->GetHandle = _mesa_get_handle;
281 driver->GetProgramiv = _mesa_get_programiv;
282 driver->GetProgramInfoLog = _mesa_get_program_info_log;
283 driver->GetShaderiv = _mesa_get_shaderiv;
284 driver->GetShaderInfoLog = _mesa_get_shader_info_log;
285 driver->GetShaderSource = _mesa_get_shader_source;
286 driver->GetUniformfv = _mesa_get_uniformfv;
287 driver->GetUniformLocation = _mesa_get_uniform_location;
288 driver->IsProgram = _mesa_is_program;
289 driver->IsShader = _mesa_is_shader;
290 driver->LinkProgram = _mesa_link_program;
291 driver->ShaderSource = _mesa_shader_source;
292 driver->Uniform = _mesa_uniform;
293 driver->UniformMatrix = _mesa_uniform_matrix;
294 driver->UseProgram = _mesa_use_program;
295 driver->ValidateProgram = _mesa_validate_program;
Brian Paul988a8862004-01-20 02:36:44 +0000296}
Briana99114a2007-05-22 16:54:25 -0600297
298
299/**
300 * Call the ctx->Driver.* state functions with current values to initialize
301 * driver state.
302 * Only the Intel drivers use this so far.
303 */
304void
305_mesa_init_driver_state(GLcontext *ctx)
306{
307 ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
308
309 ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
310
311 ctx->Driver.BlendEquationSeparate(ctx,
312 ctx->Color.BlendEquationRGB,
313 ctx->Color.BlendEquationA);
314
315 ctx->Driver.BlendFuncSeparate(ctx,
316 ctx->Color.BlendSrcRGB,
317 ctx->Color.BlendDstRGB,
318 ctx->Color.BlendSrcA, ctx->Color.BlendDstA);
319
320 ctx->Driver.ColorMask(ctx,
321 ctx->Color.ColorMask[RCOMP],
322 ctx->Color.ColorMask[GCOMP],
323 ctx->Color.ColorMask[BCOMP],
324 ctx->Color.ColorMask[ACOMP]);
325
326 ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
327 ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
328 ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
329
330 ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
331 ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
332 ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
333 ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
334 ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
335 ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
336 ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
337 ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
338 ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
339 ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
340 ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
341 ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
342 ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled);
343 ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
344 ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
345 ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
346 ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
347 ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
348
349 ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
350 ctx->Driver.Fogfv(ctx, GL_FOG_MODE, 0);
351 ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
352 ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
353 ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
354
355 ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
356
357 {
358 GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
359 ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
360 }
361
362 ctx->Driver.LineWidth(ctx, ctx->Line.Width);
363 ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
364 ctx->Driver.PointSize(ctx, ctx->Point.Size);
365 ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
366 ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
367 ctx->Scissor.Width, ctx->Scissor.Height);
368 ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
369 ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
370 ctx->Stencil.Function[0],
371 ctx->Stencil.Ref[0],
372 ctx->Stencil.ValueMask[0]);
373 ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
374 ctx->Stencil.Function[1],
375 ctx->Stencil.Ref[1],
376 ctx->Stencil.ValueMask[1]);
377 ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
378 ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
379 ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
380 ctx->Stencil.FailFunc[0],
381 ctx->Stencil.ZFailFunc[0],
382 ctx->Stencil.ZPassFunc[0]);
383 ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
384 ctx->Stencil.FailFunc[1],
385 ctx->Stencil.ZFailFunc[1],
386 ctx->Stencil.ZPassFunc[1]);
387
388
389 ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
390}