17117f1b4Smrg/* 27117f1b4Smrg * Mesa 3-D graphics library 37117f1b4Smrg * 47117f1b4Smrg * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 57117f1b4Smrg * 67117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 77117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 87117f1b4Smrg * to deal in the Software without restriction, including without limitation 97117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 107117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 117117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 127117f1b4Smrg * 137117f1b4Smrg * The above copyright notice and this permission notice shall be included 147117f1b4Smrg * in all copies or substantial portions of the Software. 157117f1b4Smrg * 167117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 177117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 187117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 237117f1b4Smrg */ 247117f1b4Smrg 257117f1b4Smrg 26c1f859d4Smrg#include "main/glheader.h" 27af69d88dSmrg#include "main/accum.h" 28c1f859d4Smrg#include "main/arrayobj.h" 29c1f859d4Smrg#include "main/context.h" 3001e04c3fSmrg#include "main/draw.h" 31af69d88dSmrg#include "main/formatquery.h" 32c1f859d4Smrg#include "main/framebuffer.h" 33c1f859d4Smrg#include "main/mipmap.h" 34c1f859d4Smrg#include "main/queryobj.h" 35af69d88dSmrg#include "main/readpix.h" 3601e04c3fSmrg#include "main/rastpos.h" 37c1f859d4Smrg#include "main/renderbuffer.h" 383464ebd5Sriastradh#include "main/shaderobj.h" 39c1f859d4Smrg#include "main/texcompress.h" 40c1f859d4Smrg#include "main/texformat.h" 414a49301eSmrg#include "main/texgetimage.h" 42c1f859d4Smrg#include "main/teximage.h" 43c1f859d4Smrg#include "main/texobj.h" 44af69d88dSmrg#include "main/texstorage.h" 45c1f859d4Smrg#include "main/texstore.h" 46c1f859d4Smrg#include "main/bufferobj.h" 47c1f859d4Smrg#include "main/fbobject.h" 483464ebd5Sriastradh#include "main/samplerobj.h" 494a49301eSmrg#include "main/syncobj.h" 5001e04c3fSmrg#include "main/barrier.h" 513464ebd5Sriastradh#include "main/transformfeedback.h" 5201e04c3fSmrg#include "main/externalobjects.h" 537117f1b4Smrg 543464ebd5Sriastradh#include "program/program.h" 557117f1b4Smrg#include "tnl/tnl.h" 567117f1b4Smrg#include "swrast/swrast.h" 57af69d88dSmrg#include "swrast/s_renderbuffer.h" 587117f1b4Smrg 59c1f859d4Smrg#include "driverfuncs.h" 604a49301eSmrg#include "meta.h" 61c1f859d4Smrg 627117f1b4Smrg 637117f1b4Smrg 647117f1b4Smrg/** 657117f1b4Smrg * Plug in default functions for all pointers in the dd_function_table 667117f1b4Smrg * structure. 677117f1b4Smrg * Device drivers should call this function and then plug in any 687117f1b4Smrg * functions which it wants to override. 697117f1b4Smrg * Some functions (pointers) MUST be implemented by all drivers (REQUIRED). 707117f1b4Smrg * 717117f1b4Smrg * \param table the dd_function_table to initialize 727117f1b4Smrg */ 737117f1b4Smrgvoid 747117f1b4Smrg_mesa_init_driver_functions(struct dd_function_table *driver) 757117f1b4Smrg{ 76cdc920a0Smrg memset(driver, 0, sizeof(*driver)); 777117f1b4Smrg 787117f1b4Smrg driver->GetString = NULL; /* REQUIRED! */ 797117f1b4Smrg driver->UpdateState = NULL; /* REQUIRED! */ 807117f1b4Smrg 817117f1b4Smrg driver->Finish = NULL; 827117f1b4Smrg driver->Flush = NULL; 837117f1b4Smrg 847117f1b4Smrg /* framebuffer/image functions */ 857117f1b4Smrg driver->Clear = _swrast_Clear; 8601e04c3fSmrg driver->RasterPos = _mesa_RasterPos; 877117f1b4Smrg driver->DrawPixels = _swrast_DrawPixels; 88af69d88dSmrg driver->ReadPixels = _mesa_readpixels; 897117f1b4Smrg driver->CopyPixels = _swrast_CopyPixels; 907117f1b4Smrg driver->Bitmap = _swrast_Bitmap; 917117f1b4Smrg 927117f1b4Smrg /* Texture functions */ 937117f1b4Smrg driver->ChooseTextureFormat = _mesa_choose_tex_format; 9401e04c3fSmrg driver->QueryInternalFormat = _mesa_query_internal_format_default; 95af69d88dSmrg driver->TexImage = _mesa_store_teximage; 96af69d88dSmrg driver->TexSubImage = _mesa_store_texsubimage; 9701e04c3fSmrg driver->GetTexSubImage = _mesa_meta_GetTexSubImage; 98af69d88dSmrg driver->ClearTexSubImage = _mesa_meta_ClearTexSubImage; 99af69d88dSmrg driver->CopyTexSubImage = _mesa_meta_CopyTexSubImage; 1004a49301eSmrg driver->GenerateMipmap = _mesa_meta_GenerateMipmap; 1017117f1b4Smrg driver->TestProxyTexImage = _mesa_test_proxy_teximage; 102af69d88dSmrg driver->CompressedTexImage = _mesa_store_compressed_teximage; 103af69d88dSmrg driver->CompressedTexSubImage = _mesa_store_compressed_texsubimage; 1047117f1b4Smrg driver->BindTexture = NULL; 1057117f1b4Smrg driver->NewTextureObject = _mesa_new_texture_object; 1067117f1b4Smrg driver->DeleteTexture = _mesa_delete_texture_object; 107af69d88dSmrg driver->NewTextureImage = _swrast_new_texture_image; 108af69d88dSmrg driver->DeleteTextureImage = _swrast_delete_texture_image; 109af69d88dSmrg driver->AllocTextureImageBuffer = _swrast_alloc_texture_image_buffer; 110af69d88dSmrg driver->FreeTextureImageBuffer = _swrast_free_texture_image_buffer; 111af69d88dSmrg driver->MapTextureImage = _swrast_map_teximage; 112af69d88dSmrg driver->UnmapTextureImage = _swrast_unmap_teximage; 113af69d88dSmrg driver->DrawTex = _mesa_meta_DrawTex; 1147117f1b4Smrg 1157117f1b4Smrg /* Vertex/fragment programs */ 1167117f1b4Smrg driver->NewProgram = _mesa_new_program; 1177117f1b4Smrg driver->DeleteProgram = _mesa_delete_program; 1187117f1b4Smrg 11901e04c3fSmrg /* ATI_fragment_shader */ 12001e04c3fSmrg driver->NewATIfs = NULL; 12101e04c3fSmrg 12201e04c3fSmrg /* Draw functions */ 12301e04c3fSmrg driver->Draw = NULL; 1247ec681f3Smrg driver->DrawGallium = _mesa_draw_gallium_fallback; 1257ec681f3Smrg driver->DrawGalliumMultiMode = _mesa_draw_gallium_multimode_fallback; 1267ec681f3Smrg driver->DrawIndirect = NULL; 1277ec681f3Smrg driver->DrawTransformFeedback = NULL; 12801e04c3fSmrg 1297117f1b4Smrg /* simple state commands */ 1307117f1b4Smrg driver->AlphaFunc = NULL; 1317117f1b4Smrg driver->BlendColor = NULL; 1327117f1b4Smrg driver->BlendEquationSeparate = NULL; 1337117f1b4Smrg driver->BlendFuncSeparate = NULL; 1347117f1b4Smrg driver->ClipPlane = NULL; 1357117f1b4Smrg driver->ColorMask = NULL; 1367117f1b4Smrg driver->ColorMaterial = NULL; 1377117f1b4Smrg driver->CullFace = NULL; 1387117f1b4Smrg driver->DrawBuffer = NULL; 1397117f1b4Smrg driver->FrontFace = NULL; 1407117f1b4Smrg driver->DepthFunc = NULL; 1417117f1b4Smrg driver->DepthMask = NULL; 1427117f1b4Smrg driver->DepthRange = NULL; 1437117f1b4Smrg driver->Enable = NULL; 1447117f1b4Smrg driver->Fogfv = NULL; 1457117f1b4Smrg driver->Lightfv = NULL; 1467117f1b4Smrg driver->LightModelfv = NULL; 1477117f1b4Smrg driver->LineStipple = NULL; 1487117f1b4Smrg driver->LineWidth = NULL; 1497117f1b4Smrg driver->LogicOpcode = NULL; 1507117f1b4Smrg driver->PointParameterfv = NULL; 1517117f1b4Smrg driver->PointSize = NULL; 1527117f1b4Smrg driver->PolygonMode = NULL; 1537117f1b4Smrg driver->PolygonOffset = NULL; 1547117f1b4Smrg driver->PolygonStipple = NULL; 1557117f1b4Smrg driver->ReadBuffer = NULL; 1567117f1b4Smrg driver->RenderMode = NULL; 1577117f1b4Smrg driver->Scissor = NULL; 1587117f1b4Smrg driver->ShadeModel = NULL; 1597117f1b4Smrg driver->StencilFuncSeparate = NULL; 1607117f1b4Smrg driver->StencilOpSeparate = NULL; 1617117f1b4Smrg driver->StencilMaskSeparate = NULL; 1627117f1b4Smrg driver->TexGen = NULL; 1637117f1b4Smrg driver->TexEnv = NULL; 1647117f1b4Smrg driver->TexParameter = NULL; 1657117f1b4Smrg driver->Viewport = NULL; 1667117f1b4Smrg 1674a49301eSmrg /* buffer objects */ 1684a49301eSmrg _mesa_init_buffer_object_functions(driver); 1694a49301eSmrg 1704a49301eSmrg /* query objects */ 1714a49301eSmrg _mesa_init_query_object_functions(driver); 1724a49301eSmrg 1734a49301eSmrg _mesa_init_sync_object_functions(driver); 1747117f1b4Smrg 17501e04c3fSmrg /* memory objects */ 17601e04c3fSmrg _mesa_init_memory_object_functions(driver); 17701e04c3fSmrg 1787117f1b4Smrg driver->NewFramebuffer = _mesa_new_framebuffer; 179af69d88dSmrg driver->NewRenderbuffer = _swrast_new_soft_renderbuffer; 180af69d88dSmrg driver->MapRenderbuffer = _swrast_map_soft_renderbuffer; 181af69d88dSmrg driver->UnmapRenderbuffer = _swrast_unmap_soft_renderbuffer; 1823464ebd5Sriastradh driver->RenderTexture = _swrast_render_texture; 1833464ebd5Sriastradh driver->FinishRenderTexture = _swrast_finish_render_texture; 18401e04c3fSmrg driver->FramebufferRenderbuffer = _mesa_FramebufferRenderbuffer_sw; 1853464ebd5Sriastradh driver->ValidateFramebuffer = _mesa_validate_framebuffer; 1867117f1b4Smrg 1877117f1b4Smrg driver->BlitFramebuffer = _swrast_BlitFramebuffer; 188af69d88dSmrg driver->DiscardFramebuffer = NULL; 1893464ebd5Sriastradh 19001e04c3fSmrg _mesa_init_barrier_functions(driver); 1913464ebd5Sriastradh _mesa_init_shader_object_functions(driver); 1923464ebd5Sriastradh _mesa_init_transform_feedback_functions(driver); 1933464ebd5Sriastradh _mesa_init_sampler_object_functions(driver); 1943464ebd5Sriastradh 1957117f1b4Smrg /* T&L stuff */ 1967117f1b4Smrg driver->CurrentExecPrimitive = 0; 1977117f1b4Smrg driver->CurrentSavePrimitive = 0; 1987117f1b4Smrg driver->NeedFlush = 0; 1997117f1b4Smrg driver->SaveNeedFlush = 0; 2007117f1b4Smrg 2017117f1b4Smrg driver->ProgramStringNotify = _tnl_program_string; 2027117f1b4Smrg driver->LightingSpaceChange = NULL; 2037117f1b4Smrg 204af69d88dSmrg /* GL_ARB_texture_storage */ 20501e04c3fSmrg driver->AllocTextureStorage = _mesa_AllocTextureStorage_sw; 206af69d88dSmrg 207af69d88dSmrg /* GL_ARB_texture_view */ 208af69d88dSmrg driver->TextureView = NULL; 209af69d88dSmrg 210af69d88dSmrg /* GL_ARB_texture_multisample */ 211af69d88dSmrg driver->GetSamplePosition = NULL; 21201e04c3fSmrg 21301e04c3fSmrg /* Multithreading */ 21401e04c3fSmrg driver->SetBackgroundContext = NULL; 2157117f1b4Smrg} 2167117f1b4Smrg 2177117f1b4Smrg 2187117f1b4Smrg/** 219c1f859d4Smrg * Call the ctx->Driver.* state functions with current values to initialize 220c1f859d4Smrg * driver state. 221c1f859d4Smrg * Only the Intel drivers use this so far. 2227117f1b4Smrg */ 2237117f1b4Smrgvoid 2243464ebd5Sriastradh_mesa_init_driver_state(struct gl_context *ctx) 2257117f1b4Smrg{ 226c1f859d4Smrg ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef); 227c1f859d4Smrg 228c1f859d4Smrg ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor); 229c1f859d4Smrg 230c1f859d4Smrg ctx->Driver.BlendEquationSeparate(ctx, 2313464ebd5Sriastradh ctx->Color.Blend[0].EquationRGB, 2323464ebd5Sriastradh ctx->Color.Blend[0].EquationA); 233c1f859d4Smrg 234c1f859d4Smrg ctx->Driver.BlendFuncSeparate(ctx, 2353464ebd5Sriastradh ctx->Color.Blend[0].SrcRGB, 2363464ebd5Sriastradh ctx->Color.Blend[0].DstRGB, 2373464ebd5Sriastradh ctx->Color.Blend[0].SrcA, 2383464ebd5Sriastradh ctx->Color.Blend[0].DstA); 239c1f859d4Smrg 24001e04c3fSmrg ctx->Driver.ColorMask(ctx, 24101e04c3fSmrg GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0), 24201e04c3fSmrg GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1), 24301e04c3fSmrg GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2), 24401e04c3fSmrg GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3)); 245c1f859d4Smrg 246c1f859d4Smrg ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode); 247c1f859d4Smrg ctx->Driver.DepthFunc(ctx, ctx->Depth.Func); 248c1f859d4Smrg ctx->Driver.DepthMask(ctx, ctx->Depth.Mask); 249c1f859d4Smrg 250c1f859d4Smrg ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled); 251c1f859d4Smrg ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled); 252c1f859d4Smrg ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled); 253c1f859d4Smrg ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled); 254c1f859d4Smrg ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag); 255c1f859d4Smrg ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test); 256c1f859d4Smrg ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag); 257c1f859d4Smrg ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled); 258c1f859d4Smrg ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled); 259c1f859d4Smrg ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag); 260c1f859d4Smrg ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag); 261af69d88dSmrg ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.EnableFlags); 26201e04c3fSmrg ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled); 263c1f859d4Smrg ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE); 264c1f859d4Smrg ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE); 265c1f859d4Smrg ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE); 266c1f859d4Smrg ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE); 267c1f859d4Smrg ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE); 268c1f859d4Smrg 269c1f859d4Smrg ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color); 270af69d88dSmrg { 271af69d88dSmrg GLfloat mode = (GLfloat) ctx->Fog.Mode; 272af69d88dSmrg ctx->Driver.Fogfv(ctx, GL_FOG_MODE, &mode); 273af69d88dSmrg } 274c1f859d4Smrg ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density); 275c1f859d4Smrg ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start); 276c1f859d4Smrg ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End); 277c1f859d4Smrg 278c1f859d4Smrg ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace); 279c1f859d4Smrg 280c1f859d4Smrg { 281c1f859d4Smrg GLfloat f = (GLfloat) ctx->Light.Model.ColorControl; 282c1f859d4Smrg ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f); 283c1f859d4Smrg } 284c1f859d4Smrg 285c1f859d4Smrg ctx->Driver.LineWidth(ctx, ctx->Line.Width); 28601e04c3fSmrg ctx->Driver.LogicOpcode(ctx, ctx->Color._LogicOp); 287c1f859d4Smrg ctx->Driver.PointSize(ctx, ctx->Point.Size); 288c1f859d4Smrg ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple); 289af69d88dSmrg ctx->Driver.Scissor(ctx); 290c1f859d4Smrg ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel); 291c1f859d4Smrg ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT, 292c1f859d4Smrg ctx->Stencil.Function[0], 293c1f859d4Smrg ctx->Stencil.Ref[0], 294c1f859d4Smrg ctx->Stencil.ValueMask[0]); 295c1f859d4Smrg ctx->Driver.StencilFuncSeparate(ctx, GL_BACK, 296c1f859d4Smrg ctx->Stencil.Function[1], 297c1f859d4Smrg ctx->Stencil.Ref[1], 298c1f859d4Smrg ctx->Stencil.ValueMask[1]); 299c1f859d4Smrg ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]); 300c1f859d4Smrg ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]); 301c1f859d4Smrg ctx->Driver.StencilOpSeparate(ctx, GL_FRONT, 302c1f859d4Smrg ctx->Stencil.FailFunc[0], 303c1f859d4Smrg ctx->Stencil.ZFailFunc[0], 304c1f859d4Smrg ctx->Stencil.ZPassFunc[0]); 305c1f859d4Smrg ctx->Driver.StencilOpSeparate(ctx, GL_BACK, 306c1f859d4Smrg ctx->Stencil.FailFunc[1], 307c1f859d4Smrg ctx->Stencil.ZFailFunc[1], 308c1f859d4Smrg ctx->Stencil.ZPassFunc[1]); 309c1f859d4Smrg 310c1f859d4Smrg 31101e04c3fSmrg ctx->Driver.DrawBuffer(ctx); 3127117f1b4Smrg} 313