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