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 "st_context.h"
36 #include "st_program.h"
37 #include "pipe/p_context.h"
38 #include "pipe/p_defines.h"
39 #include "cso_cache/cso_context.h"
42 static GLuint
translate_fill( GLenum mode
)
46 return PIPE_POLYGON_MODE_POINT
;
48 return PIPE_POLYGON_MODE_LINE
;
50 return PIPE_POLYGON_MODE_FILL
;
59 static void update_raster_state( struct st_context
*st
)
61 struct gl_context
*ctx
= st
->ctx
;
62 struct pipe_rasterizer_state
*raster
= &st
->state
.rasterizer
;
63 const struct gl_vertex_program
*vertProg
= ctx
->VertexProgram
._Current
;
64 const struct gl_fragment_program
*fragProg
= ctx
->FragmentProgram
._Current
;
67 memset(raster
, 0, sizeof(*raster
));
69 /* _NEW_POLYGON, _NEW_BUFFERS
72 raster
->front_ccw
= (ctx
->Polygon
.FrontFace
== GL_CCW
);
75 * Gallium's surfaces are Y=0=TOP orientation. OpenGL is the
76 * opposite. Window system surfaces are Y=0=TOP. Mesa's FBOs
77 * must match OpenGL conventions so FBOs use Y=0=BOTTOM. In that
78 * case, we must invert Y and flip the notion of front vs. back.
80 if (st_fb_orientation(ctx
->DrawBuffer
) == Y_0_BOTTOM
) {
81 /* Drawing to an FBO. The viewport will be inverted. */
82 raster
->front_ccw
^= 1;
88 raster
->flatshade
= ctx
->Light
.ShadeModel
== GL_FLAT
;
90 raster
->flatshade_first
= ctx
->Light
.ProvokingVertex
==
91 GL_FIRST_VERTEX_CONVENTION_EXT
;
93 /* _NEW_LIGHT | _NEW_PROGRAM */
94 raster
->light_twoside
= ctx
->VertexProgram
._TwoSideEnabled
;
96 /*_NEW_LIGHT | _NEW_BUFFERS */
97 raster
->clamp_vertex_color
= !st
->clamp_vert_color_in_shader
&&
98 ctx
->Light
._ClampVertexColor
;
102 if (ctx
->Polygon
.CullFlag
) {
103 switch (ctx
->Polygon
.CullFaceMode
) {
105 raster
->cull_face
= PIPE_FACE_FRONT
;
108 raster
->cull_face
= PIPE_FACE_BACK
;
110 case GL_FRONT_AND_BACK
:
111 raster
->cull_face
= PIPE_FACE_FRONT_AND_BACK
;
116 raster
->cull_face
= PIPE_FACE_NONE
;
122 raster
->fill_front
= translate_fill( ctx
->Polygon
.FrontMode
);
123 raster
->fill_back
= translate_fill( ctx
->Polygon
.BackMode
);
125 /* Simplify when culling is active:
127 if (raster
->cull_face
& PIPE_FACE_FRONT
) {
128 raster
->fill_front
= raster
->fill_back
;
131 if (raster
->cull_face
& PIPE_FACE_BACK
) {
132 raster
->fill_back
= raster
->fill_front
;
138 if (ctx
->Polygon
.OffsetPoint
||
139 ctx
->Polygon
.OffsetLine
||
140 ctx
->Polygon
.OffsetFill
) {
141 raster
->offset_point
= ctx
->Polygon
.OffsetPoint
;
142 raster
->offset_line
= ctx
->Polygon
.OffsetLine
;
143 raster
->offset_tri
= ctx
->Polygon
.OffsetFill
;
144 raster
->offset_units
= ctx
->Polygon
.OffsetUnits
;
145 raster
->offset_scale
= ctx
->Polygon
.OffsetFactor
;
148 raster
->poly_smooth
= ctx
->Polygon
.SmoothFlag
;
149 raster
->poly_stipple_enable
= ctx
->Polygon
.StippleFlag
;
153 raster
->point_size
= ctx
->Point
.Size
;
154 raster
->point_smooth
= !ctx
->Point
.PointSprite
&& ctx
->Point
.SmoothFlag
;
156 /* _NEW_POINT | _NEW_PROGRAM
158 if (ctx
->Point
.PointSprite
) {
160 if ((ctx
->Point
.SpriteOrigin
== GL_UPPER_LEFT
) ^
161 (st_fb_orientation(ctx
->DrawBuffer
) == Y_0_BOTTOM
))
162 raster
->sprite_coord_mode
= PIPE_SPRITE_COORD_UPPER_LEFT
;
164 raster
->sprite_coord_mode
= PIPE_SPRITE_COORD_LOWER_LEFT
;
166 /* Coord replacement flags. If bit 'k' is set that means
167 * that we need to replace GENERIC[k] attrib with an automatically
168 * computed texture coord.
170 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++) {
171 if (ctx
->Point
.CoordReplace
[i
]) {
172 raster
->sprite_coord_enable
|= 1 << i
;
175 if (!st
->needs_texcoord_semantic
&&
176 fragProg
->Base
.InputsRead
& VARYING_BIT_PNTC
) {
177 raster
->sprite_coord_enable
|=
178 1 << st_get_generic_varying_index(st
, VARYING_SLOT_PNTC
);
181 raster
->point_quad_rasterization
= 1;
184 /* ST_NEW_VERTEX_PROGRAM
187 if (vertProg
->Base
.Id
== 0) {
188 if (vertProg
->Base
.OutputsWritten
& BITFIELD64_BIT(VARYING_SLOT_PSIZ
)) {
189 /* generated program which emits point size */
190 raster
->point_size_per_vertex
= TRUE
;
193 else if (ctx
->VertexProgram
.PointSizeEnabled
) {
194 /* user-defined program and GL_VERTEX_PROGRAM_POINT_SIZE set */
195 raster
->point_size_per_vertex
= ctx
->VertexProgram
.PointSizeEnabled
;
198 if (!raster
->point_size_per_vertex
) {
200 raster
->point_size
= CLAMP(ctx
->Point
.Size
,
207 raster
->line_smooth
= ctx
->Line
.SmoothFlag
;
208 if (ctx
->Line
.SmoothFlag
) {
209 raster
->line_width
= CLAMP(ctx
->Line
.Width
,
210 ctx
->Const
.MinLineWidthAA
,
211 ctx
->Const
.MaxLineWidthAA
);
214 raster
->line_width
= CLAMP(ctx
->Line
.Width
,
215 ctx
->Const
.MinLineWidth
,
216 ctx
->Const
.MaxLineWidth
);
219 raster
->line_stipple_enable
= ctx
->Line
.StippleFlag
;
220 raster
->line_stipple_pattern
= ctx
->Line
.StipplePattern
;
221 /* GL stipple factor is in [1,256], remap to [0, 255] here */
222 raster
->line_stipple_factor
= ctx
->Line
.StippleFactor
- 1;
224 /* _NEW_MULTISAMPLE */
225 raster
->multisample
= ctx
->Multisample
._Enabled
;
228 raster
->scissor
= ctx
->Scissor
.EnableFlags
;
230 /* _NEW_FRAG_CLAMP */
231 raster
->clamp_fragment_color
= !st
->clamp_frag_color_in_shader
&&
232 ctx
->Color
._ClampFragmentColor
;
234 raster
->half_pixel_center
= 1;
235 if (st_fb_orientation(ctx
->DrawBuffer
) == Y_0_TOP
)
236 raster
->bottom_edge_rule
= 1;
238 /* ST_NEW_RASTERIZER */
239 raster
->rasterizer_discard
= ctx
->RasterDiscard
;
241 if (st
->edgeflag_culls_prims
) {
242 /* All edge flags are FALSE. Cull the affected faces. */
243 if (raster
->fill_front
!= PIPE_POLYGON_MODE_FILL
)
244 raster
->cull_face
|= PIPE_FACE_FRONT
;
245 if (raster
->fill_back
!= PIPE_POLYGON_MODE_FILL
)
246 raster
->cull_face
|= PIPE_FACE_BACK
;
250 raster
->depth_clip
= !ctx
->Transform
.DepthClamp
;
251 raster
->clip_plane_enable
= ctx
->Transform
.ClipPlanesEnabled
;
253 cso_set_rasterizer(st
->cso_context
, raster
);
256 const struct st_tracked_state st_update_rasterizer
= {
257 "st_update_rasterizer", /* name */
268 _NEW_TRANSFORM
), /* mesa state dependencies*/
269 (ST_NEW_VERTEX_PROGRAM
|
270 ST_NEW_RASTERIZER
), /* state tracker dependencies */
272 update_raster_state
/* update function */