Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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/renderbuffer.h"
  37. #include "main/shaderobj.h"
  38. #include "main/texcompress.h"
  39. #include "main/texformat.h"
  40. #include "main/texgetimage.h"
  41. #include "main/teximage.h"
  42. #include "main/texobj.h"
  43. #include "main/texstorage.h"
  44. #include "main/texstore.h"
  45. #include "main/bufferobj.h"
  46. #include "main/fbobject.h"
  47. #include "main/samplerobj.h"
  48. #include "main/syncobj.h"
  49. #include "main/texturebarrier.h"
  50. #include "main/transformfeedback.h"
  51.  
  52. #include "program/program.h"
  53. #include "tnl/tnl.h"
  54. #include "swrast/swrast.h"
  55. #include "swrast/s_renderbuffer.h"
  56.  
  57. #include "driverfuncs.h"
  58. #include "meta.h"
  59.  
  60.  
  61.  
  62. /**
  63.  * Plug in default functions for all pointers in the dd_function_table
  64.  * structure.
  65.  * Device drivers should call this function and then plug in any
  66.  * functions which it wants to override.
  67.  * Some functions (pointers) MUST be implemented by all drivers (REQUIRED).
  68.  *
  69.  * \param table the dd_function_table to initialize
  70.  */
  71. void
  72. _mesa_init_driver_functions(struct dd_function_table *driver)
  73. {
  74.    memset(driver, 0, sizeof(*driver));
  75.  
  76.    driver->GetString = NULL;  /* REQUIRED! */
  77.    driver->UpdateState = NULL;  /* REQUIRED! */
  78.    driver->ResizeBuffers = _mesa_resize_framebuffer;
  79.  
  80.    driver->Finish = NULL;
  81.    driver->Flush = NULL;
  82.  
  83.    /* framebuffer/image functions */
  84.    driver->Clear = _swrast_Clear;
  85.    driver->Accum = _mesa_accum;
  86.    driver->RasterPos = _tnl_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->QuerySamplesForFormat = _mesa_query_samples_for_format;
  95.    driver->TexImage = _mesa_store_teximage;
  96.    driver->TexSubImage = _mesa_store_texsubimage;
  97.    driver->GetTexImage = _mesa_meta_GetTexImage;
  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->GetCompressedTexImage = _mesa_get_compressed_teximage;
  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.    /* simple state commands */
  121.    driver->AlphaFunc = NULL;
  122.    driver->BlendColor = NULL;
  123.    driver->BlendEquationSeparate = NULL;
  124.    driver->BlendFuncSeparate = NULL;
  125.    driver->ClipPlane = NULL;
  126.    driver->ColorMask = NULL;
  127.    driver->ColorMaterial = NULL;
  128.    driver->CullFace = NULL;
  129.    driver->DrawBuffer = NULL;
  130.    driver->DrawBuffers = NULL;
  131.    driver->FrontFace = NULL;
  132.    driver->DepthFunc = NULL;
  133.    driver->DepthMask = NULL;
  134.    driver->DepthRange = NULL;
  135.    driver->Enable = NULL;
  136.    driver->Fogfv = NULL;
  137.    driver->Hint = NULL;
  138.    driver->Lightfv = NULL;
  139.    driver->LightModelfv = NULL;
  140.    driver->LineStipple = NULL;
  141.    driver->LineWidth = NULL;
  142.    driver->LogicOpcode = NULL;
  143.    driver->PointParameterfv = NULL;
  144.    driver->PointSize = NULL;
  145.    driver->PolygonMode = NULL;
  146.    driver->PolygonOffset = NULL;
  147.    driver->PolygonStipple = NULL;
  148.    driver->ReadBuffer = NULL;
  149.    driver->RenderMode = NULL;
  150.    driver->Scissor = NULL;
  151.    driver->ShadeModel = NULL;
  152.    driver->StencilFuncSeparate = NULL;
  153.    driver->StencilOpSeparate = NULL;
  154.    driver->StencilMaskSeparate = NULL;
  155.    driver->TexGen = NULL;
  156.    driver->TexEnv = NULL;
  157.    driver->TexParameter = NULL;
  158.    driver->Viewport = NULL;
  159.  
  160.    /* buffer objects */
  161.    _mesa_init_buffer_object_functions(driver);
  162.  
  163.    /* query objects */
  164.    _mesa_init_query_object_functions(driver);
  165.  
  166.    _mesa_init_sync_object_functions(driver);
  167.  
  168.    driver->NewFramebuffer = _mesa_new_framebuffer;
  169.    driver->NewRenderbuffer = _swrast_new_soft_renderbuffer;
  170.    driver->MapRenderbuffer = _swrast_map_soft_renderbuffer;
  171.    driver->UnmapRenderbuffer = _swrast_unmap_soft_renderbuffer;
  172.    driver->RenderTexture = _swrast_render_texture;
  173.    driver->FinishRenderTexture = _swrast_finish_render_texture;
  174.    driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer;
  175.    driver->ValidateFramebuffer = _mesa_validate_framebuffer;
  176.  
  177.    driver->BlitFramebuffer = _swrast_BlitFramebuffer;
  178.    driver->DiscardFramebuffer = NULL;
  179.  
  180.    _mesa_init_texture_barrier_functions(driver);
  181.  
  182.    /* APPLE_vertex_array_object */
  183.    driver->NewArrayObject = _mesa_new_array_object;
  184.    driver->DeleteArrayObject = _mesa_delete_array_object;
  185.    driver->BindArrayObject = NULL;
  186.  
  187.    _mesa_init_shader_object_functions(driver);
  188.  
  189.    _mesa_init_transform_feedback_functions(driver);
  190.  
  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->FlushVertices = NULL;
  201.    driver->SaveFlushVertices = NULL;
  202.    driver->NotifySaveBegin = NULL;
  203.    driver->LightingSpaceChange = NULL;
  204.  
  205.    /* display list */
  206.    driver->NewList = NULL;
  207.    driver->EndList = NULL;
  208.    driver->BeginCallList = NULL;
  209.    driver->EndCallList = NULL;
  210.  
  211.    /* GL_ARB_texture_storage */
  212.    driver->AllocTextureStorage = _mesa_alloc_texture_storage;
  213.  
  214.    /* GL_ARB_texture_multisample */
  215.    driver->GetSamplePosition = NULL;
  216. }
  217.  
  218.  
  219. /**
  220.  * Call the ctx->Driver.* state functions with current values to initialize
  221.  * driver state.
  222.  * Only the Intel drivers use this so far.
  223.  */
  224. void
  225. _mesa_init_driver_state(struct gl_context *ctx)
  226. {
  227.    ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
  228.  
  229.    ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor);
  230.  
  231.    ctx->Driver.BlendEquationSeparate(ctx,
  232.                                      ctx->Color.Blend[0].EquationRGB,
  233.                                      ctx->Color.Blend[0].EquationA);
  234.  
  235.    ctx->Driver.BlendFuncSeparate(ctx,
  236.                                  ctx->Color.Blend[0].SrcRGB,
  237.                                  ctx->Color.Blend[0].DstRGB,
  238.                                  ctx->Color.Blend[0].SrcA,
  239.                                  ctx->Color.Blend[0].DstA);
  240.  
  241.    if (ctx->Driver.ColorMaskIndexed) {
  242.       GLuint i;
  243.       for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
  244.          ctx->Driver.ColorMaskIndexed(ctx, i,
  245.                                       ctx->Color.ColorMask[i][RCOMP],
  246.                                       ctx->Color.ColorMask[i][GCOMP],
  247.                                       ctx->Color.ColorMask[i][BCOMP],
  248.                                       ctx->Color.ColorMask[i][ACOMP]);
  249.       }
  250.    }
  251.    else {
  252.       ctx->Driver.ColorMask(ctx,
  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.    ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
  260.    ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
  261.    ctx->Driver.DepthMask(ctx, ctx->Depth.Mask);
  262.  
  263.    ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled);
  264.    ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled);
  265.    ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled);
  266.    ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled);
  267.    ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag);
  268.    ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test);
  269.    ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag);
  270.    ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled);
  271.    ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled);
  272.    ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag);
  273.    ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag);
  274.    ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);
  275.    ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil._Enabled);
  276.    ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE);
  277.    ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE);
  278.    ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE);
  279.    ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE);
  280.    ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE);
  281.  
  282.    ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color);
  283.    {
  284.       GLfloat mode = (GLfloat) ctx->Fog.Mode;
  285.       ctx->Driver.Fogfv(ctx, GL_FOG_MODE, &mode);
  286.    }
  287.    ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density);
  288.    ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start);
  289.    ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End);
  290.  
  291.    ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
  292.  
  293.    {
  294.       GLfloat f = (GLfloat) ctx->Light.Model.ColorControl;
  295.       ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f);
  296.    }
  297.  
  298.    ctx->Driver.LineWidth(ctx, ctx->Line.Width);
  299.    ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp);
  300.    ctx->Driver.PointSize(ctx, ctx->Point.Size);
  301.    ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple);
  302.    ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y,
  303.                        ctx->Scissor.Width, ctx->Scissor.Height);
  304.    ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel);
  305.    ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT,
  306.                                    ctx->Stencil.Function[0],
  307.                                    ctx->Stencil.Ref[0],
  308.                                    ctx->Stencil.ValueMask[0]);
  309.    ctx->Driver.StencilFuncSeparate(ctx, GL_BACK,
  310.                                    ctx->Stencil.Function[1],
  311.                                    ctx->Stencil.Ref[1],
  312.                                    ctx->Stencil.ValueMask[1]);
  313.    ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]);
  314.    ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]);
  315.    ctx->Driver.StencilOpSeparate(ctx, GL_FRONT,
  316.                                  ctx->Stencil.FailFunc[0],
  317.                                  ctx->Stencil.ZFailFunc[0],
  318.                                  ctx->Stencil.ZPassFunc[0]);
  319.    ctx->Driver.StencilOpSeparate(ctx, GL_BACK,
  320.                                  ctx->Stencil.FailFunc[1],
  321.                                  ctx->Stencil.ZFailFunc[1],
  322.                                  ctx->Stencil.ZPassFunc[1]);
  323.  
  324.  
  325.    ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]);
  326. }
  327.