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