Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Mesa 3-D graphics library
  3.  * Version:  7.2
  4.  *
  5.  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  6.  *
  7.  * Permission is hereby granted, free of charge, to any person obtaining a
  8.  * copy of this software and associated documentation files (the "Software"),
  9.  * to deal in the Software without restriction, including without limitation
  10.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11.  * and/or sell copies of the Software, and to permit persons to whom the
  12.  * Software is furnished to do so, subject to the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice shall be included
  15.  * in all copies or substantial portions of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  20.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Keith Whitwell <keith@tungstengraphics.com>
  26.  */
  27.  
  28.  
  29. #include "main/glheader.h"
  30. #include "main/imports.h"
  31. #include "main/context.h"
  32. #include "main/macros.h"
  33. #include "main/mtypes.h"
  34. #include "main/light.h"
  35. #include "math/m_translate.h"
  36. #include "math/m_xform.h"
  37.  
  38. #include "tnl.h"
  39. #include "t_context.h"
  40. #include "t_pipeline.h"
  41.  
  42. #include "vbo/vbo.h"
  43.  
  44. GLboolean
  45. _tnl_CreateContext( struct gl_context *ctx )
  46. {
  47.    TNLcontext *tnl;
  48.  
  49.    /* Create the TNLcontext structure
  50.     */
  51.    ctx->swtnl_context = tnl = (TNLcontext *) CALLOC( sizeof(TNLcontext) );
  52.  
  53.    if (!tnl) {
  54.       return GL_FALSE;
  55.    }
  56.  
  57.    /* Initialize the VB.
  58.     */
  59.    tnl->vb.Size = ctx->Const.MaxArrayLockSize + MAX_CLIPPED_VERTICES;
  60.  
  61.  
  62.    /* Initialize tnl state.
  63.     */
  64.    if (ctx->VertexProgram._MaintainTnlProgram) {
  65.       _tnl_install_pipeline( ctx, _tnl_vp_pipeline );
  66.    } else {
  67.       _tnl_install_pipeline( ctx, _tnl_default_pipeline );
  68.    }
  69.  
  70.    tnl->NeedNdcCoords = GL_TRUE;
  71.    tnl->AllowVertexFog = GL_TRUE;
  72.    tnl->AllowPixelFog = GL_TRUE;
  73.  
  74.    /* Set a few default values in the driver struct.
  75.     */
  76.    tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
  77.    tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
  78.    tnl->Driver.NotifyMaterialChange = _mesa_validate_all_lighting_tables;
  79.  
  80.    tnl->nr_blocks = 0;
  81.  
  82.    /* plug in the VBO drawing function */
  83.    vbo_set_draw_func(ctx, _tnl_vbo_draw_prims);
  84.  
  85.    _math_init_transformation();
  86.    _math_init_translate();
  87.  
  88.    return GL_TRUE;
  89. }
  90.  
  91.  
  92. void
  93. _tnl_DestroyContext( struct gl_context *ctx )
  94. {
  95.    TNLcontext *tnl = TNL_CONTEXT(ctx);
  96.  
  97.    _tnl_destroy_pipeline( ctx );
  98.  
  99.    FREE(tnl);
  100.    ctx->swtnl_context = NULL;
  101. }
  102.  
  103.  
  104. void
  105. _tnl_InvalidateState( struct gl_context *ctx, GLuint new_state )
  106. {
  107.    TNLcontext *tnl = TNL_CONTEXT(ctx);
  108.    const struct gl_vertex_program *vp = ctx->VertexProgram._Current;
  109.    const struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
  110.    GLuint i;
  111.  
  112.    if (new_state & (_NEW_HINT | _NEW_PROGRAM)) {
  113.       ASSERT(tnl->AllowVertexFog || tnl->AllowPixelFog);
  114.       tnl->_DoVertexFog = ((tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
  115.          || !tnl->AllowPixelFog) && !fp;
  116.    }
  117.  
  118.    tnl->pipeline.new_state |= new_state;
  119.  
  120.    /* Calculate tnl->render_inputs.  This bitmask indicates which vertex
  121.     * attributes need to be emitted to the rasterizer.
  122.     */
  123.    RENDERINPUTS_ZERO( tnl->render_inputs_bitset );
  124.    RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_POS );
  125.  
  126.    if (!fp || (fp->Base.InputsRead & FRAG_BIT_COL0)) {
  127.      RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR0 );
  128.    }
  129.  
  130.    if (NEED_SECONDARY_COLOR(ctx))
  131.      RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR1 );
  132.  
  133.    for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
  134.      if (ctx->Texture._EnabledCoordUnits & (1 << i) ||
  135.          (fp && fp->Base.InputsRead & FRAG_BIT_TEX(i))) {
  136.        RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_TEX(i) );
  137.      }
  138.    }
  139.  
  140.    if (ctx->Fog.Enabled) {
  141.       /* fixed-function fog */
  142.       RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_FOG );
  143.    }
  144.    else if (fp) {
  145.       if (fp->FogOption != GL_NONE || (fp->Base.InputsRead & FRAG_BIT_FOGC)) {
  146.          /* fragment program needs fog coord */
  147.          RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_FOG );
  148.       }
  149.    }
  150.  
  151.    if (ctx->Polygon.FrontMode != GL_FILL ||
  152.        ctx->Polygon.BackMode != GL_FILL)
  153.       RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_EDGEFLAG );
  154.  
  155.    if (ctx->RenderMode == GL_FEEDBACK)
  156.       RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_TEX0 );
  157.  
  158.    if (ctx->Point._Attenuated ||
  159.        (ctx->VertexProgram._Enabled && ctx->VertexProgram.PointSizeEnabled))
  160.       RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_POINTSIZE );
  161.  
  162.    /* check for varying vars which are written by the vertex program */
  163.    if (vp) {
  164.       GLuint i;
  165.       for (i = 0; i < MAX_VARYING; i++) {
  166.          if (vp->Base.OutputsWritten & BITFIELD64_BIT(VERT_RESULT_VAR0 + i)) {
  167.             RENDERINPUTS_SET(tnl->render_inputs_bitset,
  168.                              _TNL_ATTRIB_GENERIC(i));
  169.          }
  170.       }
  171.    }
  172. }
  173.  
  174.  
  175. void
  176. _tnl_wakeup( struct gl_context *ctx )
  177. {
  178.    /* Assume we haven't been getting state updates either:
  179.     */
  180.    _tnl_InvalidateState( ctx, ~0 );
  181.  
  182. #if 0
  183.    if (ctx->Light.ColorMaterialEnabled) {
  184.       _mesa_update_color_material( ctx,
  185.                                    ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
  186.    }
  187. #endif
  188. }
  189.  
  190.  
  191.  
  192.  
  193. /**
  194.  * Drivers call this function to tell the TCL module whether or not
  195.  * it wants Normalized Device Coords (NDC) computed.  I.e. whether
  196.  * we should "Divide-by-W".  Software renders will want that.
  197.  */
  198. void
  199. _tnl_need_projected_coords( struct gl_context *ctx, GLboolean mode )
  200. {
  201.    TNLcontext *tnl = TNL_CONTEXT(ctx);
  202.    tnl->NeedNdcCoords = mode;
  203. }
  204.  
  205. void
  206. _tnl_allow_vertex_fog( struct gl_context *ctx, GLboolean value )
  207. {
  208.    TNLcontext *tnl = TNL_CONTEXT(ctx);
  209.    tnl->AllowVertexFog = value;
  210.    tnl->_DoVertexFog = ((tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
  211.       || !tnl->AllowPixelFog) && !ctx->FragmentProgram._Current;
  212.  
  213. }
  214.  
  215. void
  216. _tnl_allow_pixel_fog( struct gl_context *ctx, GLboolean value )
  217. {
  218.    TNLcontext *tnl = TNL_CONTEXT(ctx);
  219.    tnl->AllowPixelFog = value;
  220.    tnl->_DoVertexFog = ((tnl->AllowVertexFog && (ctx->Hint.Fog != GL_NICEST))
  221.       || !tnl->AllowPixelFog) && !ctx->FragmentProgram._Current;
  222. }
  223.  
  224.