1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "main/macros.h"
34 #include "st_context.h"
36 #include "pipe/p_context.h"
37 #include "pipe/p_defines.h"
38 #include "cso_cache/cso_context.h"
41 static GLuint
translate_fill( GLenum mode
)
45 return PIPE_POLYGON_MODE_POINT
;
47 return PIPE_POLYGON_MODE_LINE
;
49 return PIPE_POLYGON_MODE_FILL
;
56 static GLboolean
get_offset_flag( GLuint fill_mode
,
57 const struct gl_polygon_attrib
*p
)
60 case PIPE_POLYGON_MODE_POINT
:
61 return p
->OffsetPoint
;
62 case PIPE_POLYGON_MODE_LINE
:
64 case PIPE_POLYGON_MODE_FILL
:
73 static void update_raster_state( struct st_context
*st
)
75 GLcontext
*ctx
= st
->ctx
;
76 struct pipe_rasterizer_state
*raster
= &st
->state
.rasterizer
;
77 const struct gl_vertex_program
*vertProg
= ctx
->VertexProgram
._Current
;
80 memset(raster
, 0, sizeof(*raster
));
82 /* _NEW_POLYGON, _NEW_BUFFERS
85 if (ctx
->Polygon
.FrontFace
== GL_CCW
)
86 raster
->front_winding
= PIPE_WINDING_CCW
;
88 raster
->front_winding
= PIPE_WINDING_CW
;
91 * I think the intention here is that user-created framebuffer objects
92 * use Y=0=TOP layout instead of OpenGL's normal Y=0=bottom layout.
93 * Flipping Y changes CW to CCW and vice-versa.
94 * But this is an implementation/driver-specific artifact - remove...
96 if (ctx
->DrawBuffer
&& ctx
->DrawBuffer
->Name
!= 0)
97 raster
->front_winding
^= PIPE_WINDING_BOTH
;
102 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
103 raster
->flatshade
= 1;
105 /* _NEW_LIGHT | _NEW_PROGRAM
107 * Back-face colors can come from traditional lighting (when
108 * GL_LIGHT_MODEL_TWO_SIDE is set) or from vertex programs/shaders (when
109 * GL_VERTEX_PROGRAM_TWO_SIDE is set). Note the logic here.
111 if (ctx
->VertexProgram
._Current
) {
112 if (ctx
->VertexProgram
._Enabled
||
113 (ctx
->Shader
.CurrentProgram
&&
114 ctx
->Shader
.CurrentProgram
->VertexProgram
&&
115 ctx
->Shader
.CurrentProgram
->LinkStatus
)) {
116 /* user-defined vertex program or shader */
117 raster
->light_twoside
= ctx
->VertexProgram
.TwoSideEnabled
;
120 /* TNL-generated program */
121 raster
->light_twoside
= ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
;
124 else if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
) {
125 raster
->light_twoside
= 1;
130 if (ctx
->Polygon
.CullFlag
) {
131 if (ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
) {
132 raster
->cull_mode
= PIPE_WINDING_BOTH
;
134 else if (ctx
->Polygon
.CullFaceMode
== GL_FRONT
) {
135 raster
->cull_mode
= raster
->front_winding
;
138 raster
->cull_mode
= raster
->front_winding
^ PIPE_WINDING_BOTH
;
145 GLuint fill_front
= translate_fill( ctx
->Polygon
.FrontMode
);
146 GLuint fill_back
= translate_fill( ctx
->Polygon
.BackMode
);
148 if (raster
->front_winding
== PIPE_WINDING_CW
) {
149 raster
->fill_cw
= fill_front
;
150 raster
->fill_ccw
= fill_back
;
153 raster
->fill_cw
= fill_back
;
154 raster
->fill_ccw
= fill_front
;
157 /* Simplify when culling is active:
159 if (raster
->cull_mode
& PIPE_WINDING_CW
) {
160 raster
->fill_cw
= raster
->fill_ccw
;
163 if (raster
->cull_mode
& PIPE_WINDING_CCW
) {
164 raster
->fill_ccw
= raster
->fill_cw
;
170 if (ctx
->Polygon
.OffsetUnits
!= 0.0 ||
171 ctx
->Polygon
.OffsetFactor
!= 0.0) {
172 raster
->offset_cw
= get_offset_flag( raster
->fill_cw
, &ctx
->Polygon
);
173 raster
->offset_ccw
= get_offset_flag( raster
->fill_ccw
, &ctx
->Polygon
);
174 raster
->offset_units
= ctx
->Polygon
.OffsetUnits
;
175 raster
->offset_scale
= ctx
->Polygon
.OffsetFactor
;
178 if (ctx
->Polygon
.SmoothFlag
)
179 raster
->poly_smooth
= 1;
181 if (ctx
->Polygon
.StippleFlag
)
182 raster
->poly_stipple_enable
= 1;
186 raster
->point_size
= ctx
->Point
.Size
;
188 raster
->point_size_min
= 0; /* temporary, will go away */
189 raster
->point_size_max
= 1000; /* temporary, will go away */
191 raster
->point_smooth
= ctx
->Point
.SmoothFlag
;
192 raster
->point_sprite
= ctx
->Point
.PointSprite
;
193 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++) {
194 if (ctx
->Point
.CoordReplace
[i
]) {
195 if (ctx
->Point
.SpriteOrigin
== GL_UPPER_LEFT
)
196 raster
->sprite_coord_mode
[i
] = PIPE_SPRITE_COORD_UPPER_LEFT
;
198 raster
->sprite_coord_mode
[i
] = PIPE_SPRITE_COORD_LOWER_LEFT
;
201 raster
->sprite_coord_mode
[i
] = PIPE_SPRITE_COORD_NONE
;
205 /* ST_NEW_VERTEX_PROGRAM
208 if (vertProg
->Base
.Id
== 0) {
209 if (vertProg
->Base
.OutputsWritten
& (1 << VERT_RESULT_PSIZ
)) {
210 /* generated program which emits point size */
211 raster
->point_size_per_vertex
= TRUE
;
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
;
219 if (!raster
->point_size_per_vertex
) {
221 raster
->point_size
= CLAMP(ctx
->Point
.Size
,
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
);
235 raster
->line_width
= CLAMP(ctx
->Line
.Width
,
236 ctx
->Const
.MinLineWidth
,
237 ctx
->Const
.MaxLineWidth
);
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;
245 /* _NEW_MULTISAMPLE */
246 if (ctx
->Multisample
._Enabled
|| st
->force_msaa
)
247 raster
->multisample
= 1;
250 if (ctx
->Scissor
.Enabled
)
253 raster
->gl_rasterization_rules
= 1;
255 cso_set_rasterizer(st
->cso_context
, raster
);
258 const struct st_tracked_state st_update_rasterizer
= {
259 "st_update_rasterizer", /* name */
268 _NEW_SCISSOR
), /* mesa state dependencies*/
269 ST_NEW_VERTEX_PROGRAM
, /* state tracker dependencies */
271 update_raster_state
/* update function */