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