Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4358 Serge 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 
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
      /*
74
       * Gallium's surfaces are Y=0=TOP orientation.  OpenGL is the
75
       * opposite.  Window system surfaces are Y=0=TOP.  Mesa's FBOs
76
       * must match OpenGL conventions so FBOs use Y=0=BOTTOM.  In that
77
       * case, we must invert Y and flip the notion of front vs. back.
78
       */
79
      if (st_fb_orientation(ctx->DrawBuffer) == Y_0_BOTTOM) {
80
         /* Drawing to an FBO.  The viewport will be inverted. */
81
         raster->front_ccw ^= 1;
82
      }
83
   }
84
 
85
   /* _NEW_LIGHT
86
    */
87
   raster->flatshade = ctx->Light.ShadeModel == GL_FLAT;
88
 
89
   raster->flatshade_first = ctx->Light.ProvokingVertex ==
90
                             GL_FIRST_VERTEX_CONVENTION_EXT;
91
 
92
   /* _NEW_LIGHT | _NEW_PROGRAM */
93
   raster->light_twoside = ctx->VertexProgram._TwoSideEnabled;
94
 
95
   /*_NEW_LIGHT | _NEW_BUFFERS */
96
   raster->clamp_vertex_color = !st->clamp_vert_color_in_shader &&
97
                                ctx->Light._ClampVertexColor;
98
 
99
   /* _NEW_POLYGON
100
    */
101
   if (ctx->Polygon.CullFlag) {
102
      switch (ctx->Polygon.CullFaceMode) {
103
      case GL_FRONT:
104
	 raster->cull_face = PIPE_FACE_FRONT;
105
         break;
106
      case GL_BACK:
107
	 raster->cull_face = PIPE_FACE_BACK;
108
         break;
109
      case GL_FRONT_AND_BACK:
110
	 raster->cull_face = PIPE_FACE_FRONT_AND_BACK;
111
         break;
112
      }
113
   }
114
   else {
115
      raster->cull_face = PIPE_FACE_NONE;
116
   }
117
 
118
   /* _NEW_POLYGON
119
    */
120
   {
121
      raster->fill_front = translate_fill( ctx->Polygon.FrontMode );
122
      raster->fill_back = translate_fill( ctx->Polygon.BackMode );
123
 
124
      /* Simplify when culling is active:
125
       */
126
      if (raster->cull_face & PIPE_FACE_FRONT) {
127
	 raster->fill_front = raster->fill_back;
128
      }
129
 
130
      if (raster->cull_face & PIPE_FACE_BACK) {
131
	 raster->fill_back = raster->fill_front;
132
      }
133
   }
134
 
135
   /* _NEW_POLYGON
136
    */
137
   if (ctx->Polygon.OffsetPoint ||
138
       ctx->Polygon.OffsetLine ||
139
       ctx->Polygon.OffsetFill) {
140
      raster->offset_point = ctx->Polygon.OffsetPoint;
141
      raster->offset_line = ctx->Polygon.OffsetLine;
142
      raster->offset_tri = ctx->Polygon.OffsetFill;
143
      raster->offset_units = ctx->Polygon.OffsetUnits;
144
      raster->offset_scale = ctx->Polygon.OffsetFactor;
145
   }
146
 
147
   raster->poly_smooth = ctx->Polygon.SmoothFlag;
148
   raster->poly_stipple_enable = ctx->Polygon.StippleFlag;
149
 
150
   /* _NEW_POINT
151
    */
152
   raster->point_size = ctx->Point.Size;
153
   raster->point_smooth = !ctx->Point.PointSprite && ctx->Point.SmoothFlag;
154
 
155
   /* _NEW_POINT | _NEW_PROGRAM
156
    */
157
   if (ctx->Point.PointSprite) {
158
      /* origin */
159
      if ((ctx->Point.SpriteOrigin == GL_UPPER_LEFT) ^
160
          (st_fb_orientation(ctx->DrawBuffer) == Y_0_BOTTOM))
161
         raster->sprite_coord_mode = PIPE_SPRITE_COORD_UPPER_LEFT;
162
      else
163
         raster->sprite_coord_mode = PIPE_SPRITE_COORD_LOWER_LEFT;
164
 
165
      /* Coord replacement flags.  If bit 'k' is set that means
166
       * that we need to replace GENERIC[k] attrib with an automatically
167
       * computed texture coord.
168
       */
169
      for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
170
         if (ctx->Point.CoordReplace[i]) {
171
            raster->sprite_coord_enable |= 1 << i;
172
         }
173
      }
174
      if (fragProg->Base.InputsRead & VARYING_BIT_PNTC) {
175
         raster->sprite_coord_enable |=
176
            1 << (VARYING_SLOT_PNTC - VARYING_SLOT_TEX0);
177
      }
178
 
179
      raster->point_quad_rasterization = 1;
180
   }
181
 
182
   /* ST_NEW_VERTEX_PROGRAM
183
    */
184
   if (vertProg) {
185
      if (vertProg->Base.Id == 0) {
186
         if (vertProg->Base.OutputsWritten & BITFIELD64_BIT(VARYING_SLOT_PSIZ)) {
187
            /* generated program which emits point size */
188
            raster->point_size_per_vertex = TRUE;
189
         }
190
      }
191
      else if (ctx->VertexProgram.PointSizeEnabled) {
192
         /* user-defined program and GL_VERTEX_PROGRAM_POINT_SIZE set */
193
         raster->point_size_per_vertex = ctx->VertexProgram.PointSizeEnabled;
194
      }
195
   }
196
   if (!raster->point_size_per_vertex) {
197
      /* clamp size now */
198
      raster->point_size = CLAMP(ctx->Point.Size,
199
                                 ctx->Point.MinSize,
200
                                 ctx->Point.MaxSize);
201
   }
202
 
203
   /* _NEW_LINE
204
    */
205
   raster->line_smooth = ctx->Line.SmoothFlag;
206
   if (ctx->Line.SmoothFlag) {
207
      raster->line_width = CLAMP(ctx->Line.Width,
208
                                ctx->Const.MinLineWidthAA,
209
                                ctx->Const.MaxLineWidthAA);
210
   }
211
   else {
212
      raster->line_width = CLAMP(ctx->Line.Width,
213
                                ctx->Const.MinLineWidth,
214
                                ctx->Const.MaxLineWidth);
215
   }
216
 
217
   raster->line_stipple_enable = ctx->Line.StippleFlag;
218
   raster->line_stipple_pattern = ctx->Line.StipplePattern;
219
   /* GL stipple factor is in [1,256], remap to [0, 255] here */
220
   raster->line_stipple_factor = ctx->Line.StippleFactor - 1;
221
 
222
   /* _NEW_MULTISAMPLE */
223
   raster->multisample = ctx->Multisample._Enabled;
224
 
225
   /* _NEW_SCISSOR */
226
   raster->scissor = ctx->Scissor.Enabled;
227
 
228
   /* _NEW_FRAG_CLAMP */
229
   raster->clamp_fragment_color = !st->clamp_frag_color_in_shader &&
230
                                  ctx->Color._ClampFragmentColor;
231
 
232
   raster->half_pixel_center = 1;
233
   if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP)
234
      raster->bottom_edge_rule = 1;
235
 
236
   /* ST_NEW_RASTERIZER */
237
   raster->rasterizer_discard = ctx->RasterDiscard;
238
 
239
   /* _NEW_TRANSFORM */
240
   raster->depth_clip = ctx->Transform.DepthClamp == GL_FALSE;
241
   raster->clip_plane_enable = ctx->Transform.ClipPlanesEnabled;
242
 
243
   cso_set_rasterizer(st->cso_context, raster);
244
}
245
 
246
const struct st_tracked_state st_update_rasterizer = {
247
   "st_update_rasterizer",    /* name */
248
   {
249
      (_NEW_BUFFERS |
250
       _NEW_LIGHT |
251
       _NEW_LINE |
252
       _NEW_MULTISAMPLE |
253
       _NEW_POINT |
254
       _NEW_POLYGON |
255
       _NEW_PROGRAM |
256
       _NEW_SCISSOR |
257
       _NEW_FRAG_CLAMP |
258
       _NEW_TRANSFORM),      /* mesa state dependencies*/
259
      (ST_NEW_VERTEX_PROGRAM |
260
       ST_NEW_RASTERIZER),  /* state tracker dependencies */
261
   },
262
   update_raster_state     /* update function */
263
};