OSDN Git Service

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