Subversion Repositories Kolibri OS

Rev

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

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
  4.  * 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
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28.  /*
  29.   * Authors:
  30.   *   Keith Whitwell <keith@tungstengraphics.com>
  31.   */
  32.  
  33. #include "main/macros.h"
  34. #include "st_context.h"
  35. #include "st_atom.h"
  36. #include "pipe/p_context.h"
  37. #include "pipe/p_defines.h"
  38. #include "cso_cache/cso_context.h"
  39.  
  40.  
  41. static GLuint translate_fill( GLenum mode )
  42. {
  43.    switch (mode) {
  44.    case GL_POINT:
  45.       return PIPE_POLYGON_MODE_POINT;
  46.    case GL_LINE:
  47.       return PIPE_POLYGON_MODE_LINE;
  48.    case GL_FILL:
  49.       return PIPE_POLYGON_MODE_FILL;
  50.    default:
  51.       assert(0);
  52.       return 0;
  53.    }
  54. }
  55.  
  56.  
  57.  
  58. static void update_raster_state( struct st_context *st )
  59. {
  60.    struct gl_context *ctx = st->ctx;
  61.    struct pipe_rasterizer_state *raster = &st->state.rasterizer;
  62.    const struct gl_vertex_program *vertProg = ctx->VertexProgram._Current;
  63.    const struct gl_fragment_program *fragProg = ctx->FragmentProgram._Current;
  64.    uint i;
  65.  
  66.    memset(raster, 0, sizeof(*raster));
  67.  
  68.    /* _NEW_POLYGON, _NEW_BUFFERS
  69.     */
  70.    {
  71.       raster->front_ccw = (ctx->Polygon.FrontFace == GL_CCW);
  72.  
  73.       /* XXX
  74.        * I think the intention here is that user-created framebuffer objects
  75.        * use Y=0=TOP layout instead of OpenGL's normal Y=0=bottom layout.
  76.        * Flipping Y changes CW to CCW and vice-versa.
  77.        * But this is an implementation/driver-specific artifact - remove...
  78.        */
  79.       if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0)
  80.          raster->front_ccw ^= 1;
  81.    }
  82.  
  83.    /* _NEW_LIGHT
  84.     */
  85.    if (ctx->Light.ShadeModel == GL_FLAT)
  86.       raster->flatshade = 1;
  87.  
  88.    if (ctx->Light.ProvokingVertex == GL_FIRST_VERTEX_CONVENTION_EXT)
  89.       raster->flatshade_first = 1;
  90.  
  91.    /* _NEW_LIGHT | _NEW_PROGRAM
  92.     *
  93.     * Back-face colors can come from traditional lighting (when
  94.     * GL_LIGHT_MODEL_TWO_SIDE is set) or from vertex programs/shaders (when
  95.     * GL_VERTEX_PROGRAM_TWO_SIDE is set).  Note the logic here.
  96.     */
  97.    if (ctx->VertexProgram._Current) {
  98.       if (ctx->VertexProgram._Enabled ||
  99.           (ctx->Shader.CurrentVertexProgram &&
  100.            ctx->Shader.CurrentVertexProgram->LinkStatus)) {
  101.          /* user-defined vertex program or shader */
  102.          raster->light_twoside = ctx->VertexProgram.TwoSideEnabled;
  103.       }
  104.       else {
  105.          /* TNL-generated program */
  106.          raster->light_twoside = ctx->Light.Enabled && ctx->Light.Model.TwoSide;
  107.       }
  108.    }
  109.    else if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) {
  110.       raster->light_twoside = 1;
  111.    }
  112.  
  113.    /* _NEW_POLYGON
  114.     */
  115.    if (ctx->Polygon.CullFlag) {
  116.       switch (ctx->Polygon.CullFaceMode) {
  117.       case GL_FRONT:
  118.          raster->cull_face = PIPE_FACE_FRONT;
  119.          break;
  120.       case GL_BACK:
  121.          raster->cull_face = PIPE_FACE_BACK;
  122.          break;
  123.       case GL_FRONT_AND_BACK:
  124.          raster->cull_face = PIPE_FACE_FRONT_AND_BACK;
  125.          break;
  126.       }
  127.    }
  128.    else {
  129.       raster->cull_face = PIPE_FACE_NONE;
  130.    }
  131.  
  132.    /* _NEW_POLYGON
  133.     */
  134.    {
  135.       raster->fill_front = translate_fill( ctx->Polygon.FrontMode );
  136.       raster->fill_back = translate_fill( ctx->Polygon.BackMode );
  137.  
  138.       /* Simplify when culling is active:
  139.        */
  140.       if (raster->cull_face & PIPE_FACE_FRONT) {
  141.          raster->fill_front = raster->fill_back;
  142.       }
  143.      
  144.       if (raster->cull_face & PIPE_FACE_BACK) {
  145.          raster->fill_back = raster->fill_front;
  146.       }
  147.    }
  148.  
  149.    /* _NEW_POLYGON
  150.     */
  151.    if (ctx->Polygon.OffsetUnits != 0.0 ||
  152.        ctx->Polygon.OffsetFactor != 0.0) {
  153.       raster->offset_point = ctx->Polygon.OffsetPoint;
  154.       raster->offset_line = ctx->Polygon.OffsetLine;
  155.       raster->offset_tri = ctx->Polygon.OffsetFill;
  156.    }
  157.  
  158.    if (ctx->Polygon.OffsetPoint ||
  159.        ctx->Polygon.OffsetLine ||
  160.        ctx->Polygon.OffsetFill) {
  161.       raster->offset_units = ctx->Polygon.OffsetUnits;
  162.       raster->offset_scale = ctx->Polygon.OffsetFactor;
  163.    }
  164.  
  165.    if (ctx->Polygon.SmoothFlag)
  166.       raster->poly_smooth = 1;
  167.  
  168.    if (ctx->Polygon.StippleFlag)
  169.       raster->poly_stipple_enable = 1;
  170.  
  171.    /* _NEW_POINT
  172.     */
  173.    raster->point_size = ctx->Point.Size;
  174.  
  175.    if (!ctx->Point.PointSprite && ctx->Point.SmoothFlag)
  176.       raster->point_smooth = 1;
  177.  
  178.    /* _NEW_POINT | _NEW_PROGRAM
  179.     */
  180.    if (ctx->Point.PointSprite) {
  181.       /* origin */
  182.       if ((ctx->Point.SpriteOrigin == GL_UPPER_LEFT) ^
  183.           (st_fb_orientation(ctx->DrawBuffer) == Y_0_BOTTOM))
  184.          raster->sprite_coord_mode = PIPE_SPRITE_COORD_UPPER_LEFT;
  185.       else
  186.          raster->sprite_coord_mode = PIPE_SPRITE_COORD_LOWER_LEFT;
  187.  
  188.       /* Coord replacement flags.  If bit 'k' is set that means
  189.        * that we need to replace GENERIC[k] attrib with an automatically
  190.        * computed texture coord.
  191.        */
  192.       for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
  193.          if (ctx->Point.CoordReplace[i]) {
  194.             raster->sprite_coord_enable |= 1 << i;
  195.          }
  196.       }
  197.       if (fragProg->Base.InputsRead & FRAG_BIT_PNTC) {
  198.          raster->sprite_coord_enable |=
  199.             1 << (FRAG_ATTRIB_PNTC - FRAG_ATTRIB_TEX0);
  200.       }
  201.  
  202.       raster->point_quad_rasterization = 1;
  203.    }
  204.  
  205.    /* ST_NEW_VERTEX_PROGRAM
  206.     */
  207.    if (vertProg) {
  208.       if (vertProg->Base.Id == 0) {
  209.          if (vertProg->Base.OutputsWritten & BITFIELD64_BIT(VERT_RESULT_PSIZ)) {
  210.             /* generated program which emits point size */
  211.             raster->point_size_per_vertex = TRUE;
  212.          }
  213.       }
  214.       else if (ctx->VertexProgram.PointSizeEnabled) {
  215.          /* user-defined program and GL_VERTEX_PROGRAM_POINT_SIZE set */
  216.          raster->point_size_per_vertex = ctx->VertexProgram.PointSizeEnabled;
  217.       }
  218.    }
  219.    if (!raster->point_size_per_vertex) {
  220.       /* clamp size now */
  221.       raster->point_size = CLAMP(ctx->Point.Size,
  222.                                  ctx->Point.MinSize,
  223.                                  ctx->Point.MaxSize);
  224.    }
  225.  
  226.    /* _NEW_LINE
  227.     */
  228.    raster->line_smooth = ctx->Line.SmoothFlag;
  229.    if (ctx->Line.SmoothFlag) {
  230.       raster->line_width = CLAMP(ctx->Line.Width,
  231.                                 ctx->Const.MinLineWidthAA,
  232.                                 ctx->Const.MaxLineWidthAA);
  233.    }
  234.    else {
  235.       raster->line_width = CLAMP(ctx->Line.Width,
  236.                                 ctx->Const.MinLineWidth,
  237.                                 ctx->Const.MaxLineWidth);
  238.    }
  239.  
  240.    raster->line_stipple_enable = ctx->Line.StippleFlag;
  241.    raster->line_stipple_pattern = ctx->Line.StipplePattern;
  242.    /* GL stipple factor is in [1,256], remap to [0, 255] here */
  243.    raster->line_stipple_factor = ctx->Line.StippleFactor - 1;
  244.  
  245.    /* _NEW_MULTISAMPLE */
  246.    if (ctx->Multisample._Enabled || st->force_msaa)
  247.       raster->multisample = 1;
  248.  
  249.    /* _NEW_SCISSOR */
  250.    if (ctx->Scissor.Enabled)
  251.       raster->scissor = 1;
  252.  
  253.    raster->gl_rasterization_rules = 1;
  254.  
  255.    cso_set_rasterizer(st->cso_context, raster);
  256. }
  257.  
  258. const struct st_tracked_state st_update_rasterizer = {
  259.    "st_update_rasterizer",    /* name */
  260.    {
  261.       (_NEW_BUFFERS |
  262.        _NEW_LIGHT |
  263.        _NEW_LINE |
  264.        _NEW_MULTISAMPLE |
  265.        _NEW_POINT |
  266.        _NEW_POLYGON |
  267.        _NEW_PROGRAM |
  268.        _NEW_SCISSOR),      /* mesa state dependencies*/
  269.       ST_NEW_VERTEX_PROGRAM,  /* state tracker dependencies */
  270.    },
  271.    update_raster_state     /* update function */
  272. };
  273.