1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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 <keithw@vmware.com>
33 #include "main/macros.h"
34 #include "main/framebuffer.h"
35 #include "st_context.h"
38 #include "st_program.h"
39 #include "pipe/p_context.h"
40 #include "pipe/p_defines.h"
41 #include "cso_cache/cso_context.h"
44 static GLuint
translate_fill( GLenum mode
)
48 return PIPE_POLYGON_MODE_POINT
;
50 return PIPE_POLYGON_MODE_LINE
;
52 return PIPE_POLYGON_MODE_FILL
;
53 case GL_FILL_RECTANGLE_NV
:
54 return PIPE_POLYGON_MODE_FILL_RECTANGLE
;
63 void st_update_rasterizer( struct st_context
*st
)
65 struct gl_context
*ctx
= st
->ctx
;
66 struct pipe_rasterizer_state
*raster
= &st
->state
.rasterizer
;
67 const struct gl_program
*vertProg
= ctx
->VertexProgram
._Current
;
68 const struct gl_program
*fragProg
= ctx
->FragmentProgram
._Current
;
70 memset(raster
, 0, sizeof(*raster
));
72 /* _NEW_POLYGON, _NEW_BUFFERS
75 raster
->front_ccw
= (ctx
->Polygon
.FrontFace
== GL_CCW
);
78 if (ctx
->Transform
.ClipOrigin
== GL_UPPER_LEFT
) {
79 raster
->front_ccw
^= 1;
83 * Gallium's surfaces are Y=0=TOP orientation. OpenGL is the
84 * opposite. Window system surfaces are Y=0=TOP. Mesa's FBOs
85 * must match OpenGL conventions so FBOs use Y=0=BOTTOM. In that
86 * case, we must invert Y and flip the notion of front vs. back.
88 if (st_fb_orientation(ctx
->DrawBuffer
) == Y_0_BOTTOM
) {
89 /* Drawing to an FBO. The viewport will be inverted. */
90 raster
->front_ccw
^= 1;
96 raster
->flatshade
= ctx
->Light
.ShadeModel
== GL_FLAT
;
98 raster
->flatshade_first
= ctx
->Light
.ProvokingVertex
==
99 GL_FIRST_VERTEX_CONVENTION_EXT
;
101 /* _NEW_LIGHT | _NEW_PROGRAM */
102 raster
->light_twoside
= ctx
->VertexProgram
._TwoSideEnabled
;
104 /*_NEW_LIGHT | _NEW_BUFFERS */
105 raster
->clamp_vertex_color
= !st
->clamp_vert_color_in_shader
&&
106 ctx
->Light
._ClampVertexColor
;
110 if (ctx
->Polygon
.CullFlag
) {
111 switch (ctx
->Polygon
.CullFaceMode
) {
113 raster
->cull_face
= PIPE_FACE_FRONT
;
116 raster
->cull_face
= PIPE_FACE_BACK
;
118 case GL_FRONT_AND_BACK
:
119 raster
->cull_face
= PIPE_FACE_FRONT_AND_BACK
;
124 raster
->cull_face
= PIPE_FACE_NONE
;
130 if (ST_DEBUG
& DEBUG_WIREFRAME
) {
131 raster
->fill_front
= PIPE_POLYGON_MODE_LINE
;
132 raster
->fill_back
= PIPE_POLYGON_MODE_LINE
;
135 raster
->fill_front
= translate_fill( ctx
->Polygon
.FrontMode
);
136 raster
->fill_back
= translate_fill( ctx
->Polygon
.BackMode
);
139 /* Simplify when culling is active:
141 if (raster
->cull_face
& PIPE_FACE_FRONT
) {
142 raster
->fill_front
= raster
->fill_back
;
145 if (raster
->cull_face
& PIPE_FACE_BACK
) {
146 raster
->fill_back
= raster
->fill_front
;
152 if (ctx
->Polygon
.OffsetPoint
||
153 ctx
->Polygon
.OffsetLine
||
154 ctx
->Polygon
.OffsetFill
) {
155 raster
->offset_point
= ctx
->Polygon
.OffsetPoint
;
156 raster
->offset_line
= ctx
->Polygon
.OffsetLine
;
157 raster
->offset_tri
= ctx
->Polygon
.OffsetFill
;
158 raster
->offset_units
= ctx
->Polygon
.OffsetUnits
;
159 raster
->offset_scale
= ctx
->Polygon
.OffsetFactor
;
160 raster
->offset_clamp
= ctx
->Polygon
.OffsetClamp
;
163 raster
->poly_smooth
= ctx
->Polygon
.SmoothFlag
;
164 raster
->poly_stipple_enable
= ctx
->Polygon
.StippleFlag
;
168 raster
->point_size
= ctx
->Point
.Size
;
169 raster
->point_smooth
= !ctx
->Point
.PointSprite
&& ctx
->Point
.SmoothFlag
;
171 /* _NEW_POINT | _NEW_PROGRAM
173 if (ctx
->Point
.PointSprite
) {
175 if ((ctx
->Point
.SpriteOrigin
== GL_UPPER_LEFT
) ^
176 (st_fb_orientation(ctx
->DrawBuffer
) == Y_0_BOTTOM
))
177 raster
->sprite_coord_mode
= PIPE_SPRITE_COORD_UPPER_LEFT
;
179 raster
->sprite_coord_mode
= PIPE_SPRITE_COORD_LOWER_LEFT
;
181 /* Coord replacement flags. If bit 'k' is set that means
182 * that we need to replace GENERIC[k] attrib with an automatically
183 * computed texture coord.
185 raster
->sprite_coord_enable
= ctx
->Point
.CoordReplace
&
186 ((1u << MAX_TEXTURE_COORD_UNITS
) - 1);
187 if (!st
->needs_texcoord_semantic
&&
188 fragProg
->info
.inputs_read
& VARYING_BIT_PNTC
) {
189 raster
->sprite_coord_enable
|=
190 1 << st_get_generic_varying_index(st
, VARYING_SLOT_PNTC
);
193 raster
->point_quad_rasterization
= 1;
196 /* ST_NEW_VERTEX_PROGRAM
199 if (vertProg
->Id
== 0) {
200 if (vertProg
->info
.outputs_written
&
201 BITFIELD64_BIT(VARYING_SLOT_PSIZ
)) {
202 /* generated program which emits point size */
203 raster
->point_size_per_vertex
= TRUE
;
206 else if (ctx
->API
!= API_OPENGLES2
) {
207 /* PointSizeEnabled is always set in ES2 contexts */
208 raster
->point_size_per_vertex
= ctx
->VertexProgram
.PointSizeEnabled
;
211 /* ST_NEW_TESSEVAL_PROGRAM | ST_NEW_GEOMETRY_PROGRAM */
212 /* We have to check the last bound stage and see if it writes psize */
213 struct gl_program
*last
= NULL
;
214 if (ctx
->GeometryProgram
._Current
)
215 last
= ctx
->GeometryProgram
._Current
;
216 else if (ctx
->TessEvalProgram
._Current
)
217 last
= ctx
->TessEvalProgram
._Current
;
218 else if (ctx
->VertexProgram
._Current
)
219 last
= ctx
->VertexProgram
._Current
;
221 raster
->point_size_per_vertex
=
222 !!(last
->info
.outputs_written
&
223 BITFIELD64_BIT(VARYING_SLOT_PSIZ
));
226 if (!raster
->point_size_per_vertex
) {
228 raster
->point_size
= CLAMP(ctx
->Point
.Size
,
235 raster
->line_smooth
= ctx
->Line
.SmoothFlag
;
236 if (ctx
->Line
.SmoothFlag
) {
237 raster
->line_width
= CLAMP(ctx
->Line
.Width
,
238 ctx
->Const
.MinLineWidthAA
,
239 ctx
->Const
.MaxLineWidthAA
);
242 raster
->line_width
= CLAMP(ctx
->Line
.Width
,
243 ctx
->Const
.MinLineWidth
,
244 ctx
->Const
.MaxLineWidth
);
247 raster
->line_stipple_enable
= ctx
->Line
.StippleFlag
;
248 raster
->line_stipple_pattern
= ctx
->Line
.StipplePattern
;
249 /* GL stipple factor is in [1,256], remap to [0, 255] here */
250 raster
->line_stipple_factor
= ctx
->Line
.StippleFactor
- 1;
252 /* _NEW_MULTISAMPLE */
253 raster
->multisample
= _mesa_is_multisample_enabled(ctx
);
255 /* _NEW_MULTISAMPLE | _NEW_BUFFERS */
256 raster
->force_persample_interp
=
257 !st
->force_persample_in_shader
&&
258 raster
->multisample
&&
259 ctx
->Multisample
.SampleShading
&&
260 ctx
->Multisample
.MinSampleShadingValue
*
261 _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
264 raster
->scissor
= ctx
->Scissor
.EnableFlags
;
266 /* _NEW_FRAG_CLAMP */
267 raster
->clamp_fragment_color
= !st
->clamp_frag_color_in_shader
&&
268 ctx
->Color
._ClampFragmentColor
;
270 raster
->half_pixel_center
= 1;
271 if (st_fb_orientation(ctx
->DrawBuffer
) == Y_0_TOP
)
272 raster
->bottom_edge_rule
= 1;
274 if (ctx
->Transform
.ClipOrigin
== GL_UPPER_LEFT
)
275 raster
->bottom_edge_rule
^= 1;
277 /* ST_NEW_RASTERIZER */
278 raster
->rasterizer_discard
= ctx
->RasterDiscard
;
280 if (st
->edgeflag_culls_prims
) {
281 /* All edge flags are FALSE. Cull the affected faces. */
282 if (raster
->fill_front
!= PIPE_POLYGON_MODE_FILL
)
283 raster
->cull_face
|= PIPE_FACE_FRONT
;
284 if (raster
->fill_back
!= PIPE_POLYGON_MODE_FILL
)
285 raster
->cull_face
|= PIPE_FACE_BACK
;
289 raster
->depth_clip
= !ctx
->Transform
.DepthClamp
;
290 raster
->clip_plane_enable
= ctx
->Transform
.ClipPlanesEnabled
;
291 raster
->clip_halfz
= (ctx
->Transform
.ClipDepthMode
== GL_ZERO_TO_ONE
);
293 cso_set_rasterizer(st
->cso_context
, raster
);