1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 
26 #include "main/glheader.h"
27 #include "main/accum.h"
28 #include "main/arrayobj.h"
29 #include "main/context.h"
30 #include "main/draw.h"
31 #include "main/formatquery.h"
32 #include "main/framebuffer.h"
33 #include "main/mipmap.h"
34 #include "main/queryobj.h"
35 #include "main/readpix.h"
36 #include "main/rastpos.h"
37 #include "main/renderbuffer.h"
38 #include "main/shaderobj.h"
39 #include "main/texcompress.h"
40 #include "main/texformat.h"
41 #include "main/texgetimage.h"
42 #include "main/teximage.h"
43 #include "main/texobj.h"
44 #include "main/texstorage.h"
45 #include "main/texstore.h"
46 #include "main/bufferobj.h"
47 #include "main/fbobject.h"
48 #include "main/samplerobj.h"
49 #include "main/syncobj.h"
50 #include "main/barrier.h"
51 #include "main/transformfeedback.h"
52 #include "main/externalobjects.h"
53 
54 #include "program/program.h"
55 #include "tnl/tnl.h"
56 #include "swrast/swrast.h"
57 #include "swrast/s_renderbuffer.h"
58 
59 #include "driverfuncs.h"
60 #include "meta.h"
61 
62 
63 
64 /**
65  * Plug in default functions for all pointers in the dd_function_table
66  * structure.
67  * Device drivers should call this function and then plug in any
68  * functions which it wants to override.
69  * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
70  *
71  * \param table the dd_function_table to initialize
72  */
73 void
_mesa_init_driver_functions(struct dd_function_table * driver)74 _mesa_init_driver_functions(struct dd_function_table *driver)
75 {
76    memset(driver, 0, sizeof(*driver));
77 
78    driver->GetString = NULL;  /* REQUIRED! */
79    driver->UpdateState = NULL;  /* REQUIRED! */
80 
81    driver->Finish = NULL;
82    driver->Flush = NULL;
83 
84    /* framebuffer/image functions */
85    driver->Clear = _swrast_Clear;
86    driver->RasterPos = _mesa_RasterPos;
87    driver->DrawPixels = _swrast_DrawPixels;
88    driver->ReadPixels = _mesa_readpixels;
89    driver->CopyPixels = _swrast_CopyPixels;
90    driver->Bitmap = _swrast_Bitmap;
91 
92    /* Texture functions */
93    driver->ChooseTextureFormat = _mesa_choose_tex_format;
94    driver->QueryInternalFormat = _mesa_query_internal_format_default;
95    driver->TexImage = _mesa_store_teximage;
96    driver->TexSubImage = _mesa_store_texsubimage;
97    driver->GetTexSubImage = _mesa_meta_GetTexSubImage;
98    driver->ClearTexSubImage = _mesa_meta_ClearTexSubImage;
99    driver->CopyTexSubImage = _mesa_meta_CopyTexSubImage;
100    driver->GenerateMipmap = _mesa_meta_GenerateMipmap;
101    driver->TestProxyTexImage = _mesa_test_proxy_teximage;
102    driver->CompressedTexImage = _mesa_store_compressed_teximage;
103    driver->CompressedTexSubImage = _mesa_store_compressed_texsubimage;
104    driver->BindTexture = NULL;
105    driver->NewTextureObject = _mesa_new_texture_object;
106    driver->DeleteTexture = _mesa_delete_texture_object;
107    driver->NewTextureImage = _swrast_new_texture_image;
108    driver->DeleteTextureImage = _swrast_delete_texture_image;
109    driver->AllocTextureImageBuffer = _swrast_alloc_texture_image_buffer;
110    driver->FreeTextureImageBuffer = _swrast_free_texture_image_buffer;
111    driver->MapTextureImage = _swrast_map_teximage;
112    driver->UnmapTextureImage = _swrast_unmap_teximage;
113    driver->DrawTex = _mesa_meta_DrawTex;
114 
115    /* Vertex/fragment programs */
116    driver->NewProgram = _mesa_new_program;
117    driver->DeleteProgram = _mesa_delete_program;
118 
119    /* ATI_fragment_shader */
120    driver->NewATIfs = NULL;
121 
122    /* Draw functions */
123    driver->Draw = NULL;
124    driver->DrawGallium = _mesa_draw_gallium_fallback;
125    driver->DrawGalliumMultiMode = _mesa_draw_gallium_multimode_fallback;
126    driver->DrawIndirect = NULL;
127    driver->DrawTransformFeedback = NULL;
128 
129    /* simple state commands */
130    driver->AlphaFunc = NULL;
131    driver->BlendColor = NULL;
132    driver->BlendEquationSeparate = NULL;
133    driver->BlendFuncSeparate = NULL;
134    driver->ClipPlane = NULL;
135    driver->ColorMask = NULL;
136    driver->ColorMaterial = NULL;
137    driver->CullFace = NULL;
138    driver->DrawBuffer = NULL;
139    driver->FrontFace = NULL;
140    driver->DepthFunc = NULL;
141    driver->DepthMask = NULL;
142    driver->DepthRange = NULL;
143    driver->Enable = NULL;
144    driver->Fogfv = NULL;
145    driver->Lightfv = NULL;
146    driver->LightModelfv = NULL;
147    driver->LineStipple = NULL;
148    driver->LineWidth = NULL;
149    driver->LogicOpcode = NULL;
150    driver->PointParameterfv = NULL;
151    driver->PointSize = NULL;
152    driver->PolygonMode = NULL;
153    driver->PolygonOffset = NULL;
154    driver->PolygonStipple = NULL;
155    driver->ReadBuffer = NULL;
156    driver->RenderMode = NULL;
157    driver->Scissor = NULL;
158    driver->ShadeModel = NULL;
159    driver->StencilFuncSeparate = NULL;
160    driver->StencilOpSeparate = NULL;
161    driver->StencilMaskSeparate = NULL;
162    driver->TexGen = NULL;
163    driver->TexEnv = NULL;
164    driver->TexParameter = NULL;
165    driver->Viewport = NULL;
166 
167    /* buffer objects */
168    _mesa_init_buffer_object_functions(driver);
169 
170    /* query objects */
171    _mesa_init_query_object_functions(driver);
172 
173    _mesa_init_sync_object_functions(driver);
174 
175    /* memory objects */
176    _mesa_init_memory_object_functions(driver);
177 
178    driver->NewFramebuffer = _mesa_new_framebuffer;
179    driver->NewRenderbuffer = _swrast_new_soft_renderbuffer;
180    driver->MapRenderbuffer = _swrast_map_soft_renderbuffer;
181    driver->UnmapRenderbuffer = _swrast_unmap_soft_renderbuffer;
182    driver->RenderTexture = _swrast_render_texture;
183    driver->FinishRenderTexture = _swrast_finish_render_texture;
184    driver->FramebufferRenderbuffer = _mesa_FramebufferRenderbuffer_sw;
185    driver->ValidateFramebuffer = _mesa_validate_framebuffer;
186 
187    driver->BlitFramebuffer = _swrast_BlitFramebuffer;
188    driver->DiscardFramebuffer = NULL;
189 
190    _mesa_init_barrier_functions(driver);
191    _mesa_init_shader_object_functions(driver);
192    _mesa_init_transform_feedback_functions(driver);
193    _mesa_init_sampler_object_functions(driver);
194 
195    /* T&L stuff */
196    driver->CurrentExecPrimitive = 0;
197    driver->CurrentSavePrimitive = 0;
198    driver->NeedFlush = 0;
199    driver->SaveNeedFlush = 0;
200 
201    driver->ProgramStringNotify = _tnl_program_string;
202    driver->LightingSpaceChange = NULL;
203 
204    /* GL_ARB_texture_storage */
205    driver->AllocTextureStorage = _mesa_AllocTextureStorage_sw;
206 
207    /* GL_ARB_texture_view */
208    driver->TextureView = NULL;
209 
210    /* GL_ARB_texture_multisample */
211    driver->GetSamplePosition = NULL;
212 
213    /* Multithreading */
214    driver->SetBackgroundContext = NULL;
215 }
216 
217 
218 /**
219  * Call the ctx->Driver.* state functions with current values to initialize
220  * driver state.
221  * Only the Intel drivers use this so far.
222  */
223 void
_mesa_init_driver_state(struct gl_context * ctx)224 _mesa_init_driver_state(struct gl_context *ctx)
225 {
226    ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
227 
228    ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
229 
230    ctx->Driver.BlendEquationSeparate(ctx,
231                                      ctx->Color.Blend[0].EquationRGB,
232                                      ctx->Color.Blend[0].EquationA);
233 
234    ctx->Driver.BlendFuncSeparate(ctx,
235                                  ctx->Color.Blend[0].SrcRGB,
236                                  ctx->Color.Blend[0].DstRGB,
237                                  ctx->Color.Blend[0].SrcA,
238                                  ctx->Color.Blend[0].DstA);
239 
240    ctx->Driver.ColorMask(ctx,
241                          GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0),
242                          GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1),
243                          GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2),
244                          GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3));
245 
246    ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
247    ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
248    ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
249 
250    ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
251    ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
252    ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
253    ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
254    ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
255    ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
256    ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
257    ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
258    ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
259    ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
260    ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
261    ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.EnableFlags);
262    ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled);
263    ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
264    ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
265    ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
266    ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
267    ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
268 
269    ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
270    {
271       GLfloat mode = (GLfloat) ctx->Fog.Mode;
272       ctx->Driver.Fogfv(ctx, GL_FOG_MODE, &mode);
273    }
274    ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
275    ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
276    ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
277 
278    ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
279 
280    {
281       GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
282       ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
283    }
284 
285    ctx->Driver.LineWidth(ctx, ctx->Line.Width);
286    ctx->Driver.LogicOpcode(ctx, ctx->Color._LogicOp);
287    ctx->Driver.PointSize(ctx, ctx->Point.Size);
288    ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
289    ctx->Driver.Scissor(ctx);
290    ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
291    ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
292                                    ctx->Stencil.Function[0],
293                                    ctx->Stencil.Ref[0],
294                                    ctx->Stencil.ValueMask[0]);
295    ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
296                                    ctx->Stencil.Function[1],
297                                    ctx->Stencil.Ref[1],
298                                    ctx->Stencil.ValueMask[1]);
299    ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
300    ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
301    ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
302                                  ctx->Stencil.FailFunc[0],
303                                  ctx->Stencil.ZFailFunc[0],
304                                  ctx->Stencil.ZPassFunc[0]);
305    ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
306                                  ctx->Stencil.FailFunc[1],
307                                  ctx->Stencil.ZFailFunc[1],
308                                  ctx->Stencil.ZPassFunc[1]);
309 
310 
311    ctx->Driver.DrawBuffer(ctx);
312 }
313