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 "main/state.h"
36 #include "st_context.h"
39 #include "st_program.h"
41 #include "pipe/p_context.h"
42 #include "pipe/p_defines.h"
43 #include "cso_cache/cso_context.h"
47 translate_fill(GLenum mode
)
51 return PIPE_POLYGON_MODE_POINT
;
53 return PIPE_POLYGON_MODE_LINE
;
55 return PIPE_POLYGON_MODE_FILL
;
56 case GL_FILL_RECTANGLE_NV
:
57 return PIPE_POLYGON_MODE_FILL_RECTANGLE
;
65 st_update_rasterizer(struct st_context
*st
)
67 struct gl_context
*ctx
= st
->ctx
;
68 struct pipe_rasterizer_state
*raster
= &st
->state
.rasterizer
;
69 const struct gl_program
*fragProg
= ctx
->FragmentProgram
._Current
;
71 memset(raster
, 0, sizeof(*raster
));
73 /* _NEW_POLYGON, _NEW_BUFFERS
76 raster
->front_ccw
= (ctx
->Polygon
.FrontFace
== GL_CCW
);
79 if (ctx
->Transform
.ClipOrigin
== GL_UPPER_LEFT
) {
80 raster
->front_ccw
^= 1;
84 * Gallium's surfaces are Y=0=TOP orientation. OpenGL is the
85 * opposite. Window system surfaces are Y=0=TOP. Mesa's FBOs
86 * must match OpenGL conventions so FBOs use Y=0=BOTTOM. In that
87 * case, we must invert Y and flip the notion of front vs. back.
89 if (st
->state
.fb_orientation
== Y_0_BOTTOM
) {
90 /* Drawing to an FBO. The viewport will be inverted. */
91 raster
->front_ccw
^= 1;
97 raster
->flatshade
= !st
->lower_flatshade
&&
98 ctx
->Light
.ShadeModel
== GL_FLAT
;
100 raster
->flatshade_first
= ctx
->Light
.ProvokingVertex
==
101 GL_FIRST_VERTEX_CONVENTION_EXT
;
103 /* _NEW_LIGHT | _NEW_PROGRAM */
104 if (!st
->lower_two_sided_color
)
105 raster
->light_twoside
= _mesa_vertex_program_two_side_enabled(ctx
);
107 /*_NEW_LIGHT | _NEW_BUFFERS */
108 raster
->clamp_vertex_color
= !st
->clamp_vert_color_in_shader
&&
109 ctx
->Light
._ClampVertexColor
;
113 if (ctx
->Polygon
.CullFlag
) {
114 switch (ctx
->Polygon
.CullFaceMode
) {
116 raster
->cull_face
= PIPE_FACE_FRONT
;
119 raster
->cull_face
= PIPE_FACE_BACK
;
121 case GL_FRONT_AND_BACK
:
122 raster
->cull_face
= PIPE_FACE_FRONT_AND_BACK
;
127 raster
->cull_face
= PIPE_FACE_NONE
;
133 if (ST_DEBUG
& DEBUG_WIREFRAME
) {
134 raster
->fill_front
= PIPE_POLYGON_MODE_LINE
;
135 raster
->fill_back
= PIPE_POLYGON_MODE_LINE
;
138 raster
->fill_front
= translate_fill(ctx
->Polygon
.FrontMode
);
139 raster
->fill_back
= translate_fill(ctx
->Polygon
.BackMode
);
142 /* Simplify when culling is active:
144 if (raster
->cull_face
& PIPE_FACE_FRONT
) {
145 raster
->fill_front
= raster
->fill_back
;
148 if (raster
->cull_face
& PIPE_FACE_BACK
) {
149 raster
->fill_back
= raster
->fill_front
;
155 if (ctx
->Polygon
.OffsetPoint
||
156 ctx
->Polygon
.OffsetLine
||
157 ctx
->Polygon
.OffsetFill
) {
158 raster
->offset_point
= ctx
->Polygon
.OffsetPoint
;
159 raster
->offset_line
= ctx
->Polygon
.OffsetLine
;
160 raster
->offset_tri
= ctx
->Polygon
.OffsetFill
;
161 raster
->offset_units
= ctx
->Polygon
.OffsetUnits
;
162 raster
->offset_scale
= ctx
->Polygon
.OffsetFactor
;
163 raster
->offset_clamp
= ctx
->Polygon
.OffsetClamp
;
166 raster
->poly_smooth
= ctx
->Polygon
.SmoothFlag
;
167 raster
->poly_stipple_enable
= ctx
->Polygon
.StippleFlag
;
171 raster
->point_size
= ctx
->Point
.Size
;
172 raster
->point_smooth
= !ctx
->Point
.PointSprite
&& ctx
->Point
.SmoothFlag
;
174 /* _NEW_POINT | _NEW_PROGRAM
176 if (ctx
->Point
.PointSprite
) {
178 if ((ctx
->Point
.SpriteOrigin
== GL_UPPER_LEFT
) ^
179 (st
->state
.fb_orientation
== Y_0_BOTTOM
))
180 raster
->sprite_coord_mode
= PIPE_SPRITE_COORD_UPPER_LEFT
;
182 raster
->sprite_coord_mode
= PIPE_SPRITE_COORD_LOWER_LEFT
;
184 /* Coord replacement flags. If bit 'k' is set that means
185 * that we need to replace GENERIC[k] attrib with an automatically
186 * computed texture coord.
188 raster
->sprite_coord_enable
= ctx
->Point
.CoordReplace
&
189 ((1u << MAX_TEXTURE_COORD_UNITS
) - 1);
190 if (!st
->needs_texcoord_semantic
&&
191 fragProg
->info
.inputs_read
& VARYING_BIT_PNTC
) {
192 raster
->sprite_coord_enable
|=
193 1 << st_get_generic_varying_index(st
, VARYING_SLOT_PNTC
);
196 raster
->point_quad_rasterization
= 1;
199 /* ST_NEW_VERTEX_PROGRAM
201 raster
->point_size_per_vertex
= st_point_size_per_vertex(ctx
);
202 if (!raster
->point_size_per_vertex
) {
204 raster
->point_size
= CLAMP(ctx
->Point
.Size
,
211 raster
->line_smooth
= ctx
->Line
.SmoothFlag
;
212 if (ctx
->Line
.SmoothFlag
) {
213 raster
->line_width
= CLAMP(ctx
->Line
.Width
,
214 ctx
->Const
.MinLineWidthAA
,
215 ctx
->Const
.MaxLineWidthAA
);
218 raster
->line_width
= CLAMP(ctx
->Line
.Width
,
219 ctx
->Const
.MinLineWidth
,
220 ctx
->Const
.MaxLineWidth
);
223 raster
->line_stipple_enable
= ctx
->Line
.StippleFlag
;
224 raster
->line_stipple_pattern
= ctx
->Line
.StipplePattern
;
225 /* GL stipple factor is in [1,256], remap to [0, 255] here */
226 raster
->line_stipple_factor
= ctx
->Line
.StippleFactor
- 1;
228 /* _NEW_MULTISAMPLE */
229 raster
->multisample
= _mesa_is_multisample_enabled(ctx
);
231 /* _NEW_MULTISAMPLE | _NEW_BUFFERS */
232 raster
->force_persample_interp
=
233 !st
->force_persample_in_shader
&&
234 raster
->multisample
&&
235 ctx
->Multisample
.SampleShading
&&
236 ctx
->Multisample
.MinSampleShadingValue
*
237 _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
240 raster
->scissor
= !!ctx
->Scissor
.EnableFlags
;
242 /* gl_driver_flags::NewFragClamp */
243 raster
->clamp_fragment_color
= !st
->clamp_frag_color_in_shader
&&
244 ctx
->Color
._ClampFragmentColor
;
246 raster
->half_pixel_center
= 1;
247 if (st
->state
.fb_orientation
== Y_0_TOP
)
248 raster
->bottom_edge_rule
= 1;
251 if (ctx
->Transform
.ClipOrigin
== GL_UPPER_LEFT
)
252 raster
->bottom_edge_rule
^= 1;
254 /* ST_NEW_RASTERIZER */
255 raster
->rasterizer_discard
= ctx
->RasterDiscard
;
256 if (ctx
->TileRasterOrderFixed
) {
257 raster
->tile_raster_order_fixed
= true;
258 raster
->tile_raster_order_increasing_x
= ctx
->TileRasterOrderIncreasingX
;
259 raster
->tile_raster_order_increasing_y
= ctx
->TileRasterOrderIncreasingY
;
262 if (st
->edgeflag_culls_prims
) {
263 /* All edge flags are FALSE. Cull the affected faces. */
264 if (raster
->fill_front
!= PIPE_POLYGON_MODE_FILL
)
265 raster
->cull_face
|= PIPE_FACE_FRONT
;
266 if (raster
->fill_back
!= PIPE_POLYGON_MODE_FILL
)
267 raster
->cull_face
|= PIPE_FACE_BACK
;
271 raster
->depth_clip_near
= st
->clamp_frag_depth_in_shader
||
272 !ctx
->Transform
.DepthClampNear
;
273 raster
->depth_clip_far
= st
->clamp_frag_depth_in_shader
||
274 !ctx
->Transform
.DepthClampFar
;
275 raster
->clip_plane_enable
= ctx
->Transform
.ClipPlanesEnabled
;
276 raster
->clip_halfz
= (ctx
->Transform
.ClipDepthMode
== GL_ZERO_TO_ONE
);
278 /* ST_NEW_RASTERIZER */
279 if (ctx
->ConservativeRasterization
) {
280 if (ctx
->ConservativeRasterMode
== GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV
)
281 raster
->conservative_raster_mode
= PIPE_CONSERVATIVE_RASTER_POST_SNAP
;
283 raster
->conservative_raster_mode
= PIPE_CONSERVATIVE_RASTER_PRE_SNAP
;
284 } else if (ctx
->IntelConservativeRasterization
) {
285 raster
->conservative_raster_mode
= PIPE_CONSERVATIVE_RASTER_POST_SNAP
;
287 raster
->conservative_raster_mode
= PIPE_CONSERVATIVE_RASTER_OFF
;
290 raster
->conservative_raster_dilate
= ctx
->ConservativeRasterDilate
;
292 raster
->subpixel_precision_x
= ctx
->SubpixelPrecisionBias
[0];
293 raster
->subpixel_precision_y
= ctx
->SubpixelPrecisionBias
[1];
295 cso_set_rasterizer(st
->cso_context
, raster
);