1 /**************************************************************************
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 * Keith Whitwell <keith@tungstengraphics.com>
36 #include "main/glheader.h"
37 #include "main/imports.h"
38 #include "main/api_arrayelt.h"
39 #include "main/enums.h"
40 #include "main/colormac.h"
41 #include "main/light.h"
42 #include "main/framebuffer.h"
44 #include "swrast/swrast.h"
47 #include "tnl/t_pipeline.h"
48 #include "swrast_setup/swrast_setup.h"
50 #include "radeon_common.h"
51 #include "radeon_mipmap_tree.h"
52 #include "r200_context.h"
53 #include "r200_ioctl.h"
54 #include "r200_state.h"
57 #include "r200_swtcl.h"
58 #include "r200_vertprog.h"
61 /* =============================================================
65 static void r200AlphaFunc( GLcontext
*ctx
, GLenum func
, GLfloat ref
)
67 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
68 int pp_misc
= rmesa
->hw
.ctx
.cmd
[CTX_PP_MISC
];
71 CLAMPED_FLOAT_TO_UBYTE(refByte
, ref
);
73 R200_STATECHANGE( rmesa
, ctx
);
75 pp_misc
&= ~(R200_ALPHA_TEST_OP_MASK
| R200_REF_ALPHA_MASK
);
76 pp_misc
|= (refByte
& R200_REF_ALPHA_MASK
);
80 pp_misc
|= R200_ALPHA_TEST_FAIL
;
83 pp_misc
|= R200_ALPHA_TEST_LESS
;
86 pp_misc
|= R200_ALPHA_TEST_EQUAL
;
89 pp_misc
|= R200_ALPHA_TEST_LEQUAL
;
92 pp_misc
|= R200_ALPHA_TEST_GREATER
;
95 pp_misc
|= R200_ALPHA_TEST_NEQUAL
;
98 pp_misc
|= R200_ALPHA_TEST_GEQUAL
;
101 pp_misc
|= R200_ALPHA_TEST_PASS
;
105 rmesa
->hw
.ctx
.cmd
[CTX_PP_MISC
] = pp_misc
;
108 static void r200BlendColor( GLcontext
*ctx
, const GLfloat cf
[4] )
111 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
112 R200_STATECHANGE( rmesa
, ctx
);
113 CLAMPED_FLOAT_TO_UBYTE(color
[0], cf
[0]);
114 CLAMPED_FLOAT_TO_UBYTE(color
[1], cf
[1]);
115 CLAMPED_FLOAT_TO_UBYTE(color
[2], cf
[2]);
116 CLAMPED_FLOAT_TO_UBYTE(color
[3], cf
[3]);
117 if (rmesa
->radeon
.radeonScreen
->drmSupportsBlendColor
)
118 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCOLOR
] = radeonPackColor( 4, color
[0], color
[1], color
[2], color
[3] );
122 * Calculate the hardware blend factor setting. This same function is used
123 * for source and destination of both alpha and RGB.
126 * The hardware register value for the specified blend factor. This value
127 * will need to be shifted into the correct position for either source or
128 * destination factor.
131 * Since the two cases where source and destination are handled differently
132 * are essentially error cases, they should never happen. Determine if these
133 * cases can be removed.
135 static int blend_factor( GLenum factor
, GLboolean is_src
)
141 func
= R200_BLEND_GL_ZERO
;
144 func
= R200_BLEND_GL_ONE
;
147 func
= R200_BLEND_GL_DST_COLOR
;
149 case GL_ONE_MINUS_DST_COLOR
:
150 func
= R200_BLEND_GL_ONE_MINUS_DST_COLOR
;
153 func
= R200_BLEND_GL_SRC_COLOR
;
155 case GL_ONE_MINUS_SRC_COLOR
:
156 func
= R200_BLEND_GL_ONE_MINUS_SRC_COLOR
;
159 func
= R200_BLEND_GL_SRC_ALPHA
;
161 case GL_ONE_MINUS_SRC_ALPHA
:
162 func
= R200_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
165 func
= R200_BLEND_GL_DST_ALPHA
;
167 case GL_ONE_MINUS_DST_ALPHA
:
168 func
= R200_BLEND_GL_ONE_MINUS_DST_ALPHA
;
170 case GL_SRC_ALPHA_SATURATE
:
171 func
= (is_src
) ? R200_BLEND_GL_SRC_ALPHA_SATURATE
: R200_BLEND_GL_ZERO
;
173 case GL_CONSTANT_COLOR
:
174 func
= R200_BLEND_GL_CONST_COLOR
;
176 case GL_ONE_MINUS_CONSTANT_COLOR
:
177 func
= R200_BLEND_GL_ONE_MINUS_CONST_COLOR
;
179 case GL_CONSTANT_ALPHA
:
180 func
= R200_BLEND_GL_CONST_ALPHA
;
182 case GL_ONE_MINUS_CONSTANT_ALPHA
:
183 func
= R200_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
186 func
= (is_src
) ? R200_BLEND_GL_ONE
: R200_BLEND_GL_ZERO
;
192 * Sets both the blend equation and the blend function.
193 * This is done in a single
194 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
195 * change the interpretation of the blend function.
196 * Also, make sure that blend function and blend equation are set to their default
197 * value if color blending is not enabled, since at least blend equations GL_MIN
198 * and GL_FUNC_REVERSE_SUBTRACT will cause wrong results otherwise for
201 static void r200_set_blend_state( GLcontext
* ctx
)
203 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
204 GLuint cntl
= rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &
205 ~(R200_ROP_ENABLE
| R200_ALPHA_BLEND_ENABLE
| R200_SEPARATE_ALPHA_ENABLE
);
207 int func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
208 (R200_BLEND_GL_ZERO
<< R200_DST_BLEND_SHIFT
);
209 int eqn
= R200_COMB_FCN_ADD_CLAMP
;
210 int funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
211 (R200_BLEND_GL_ZERO
<< R200_DST_BLEND_SHIFT
);
212 int eqnA
= R200_COMB_FCN_ADD_CLAMP
;
214 R200_STATECHANGE( rmesa
, ctx
);
216 if (rmesa
->radeon
.radeonScreen
->drmSupportsBlendColor
) {
217 if (ctx
->Color
.ColorLogicOpEnabled
) {
218 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = cntl
| R200_ROP_ENABLE
;
219 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ABLENDCNTL
] = eqn
| func
;
220 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CBLENDCNTL
] = eqn
| func
;
222 } else if (ctx
->Color
.BlendEnabled
) {
223 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = cntl
| R200_ALPHA_BLEND_ENABLE
| R200_SEPARATE_ALPHA_ENABLE
;
226 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = cntl
;
227 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ABLENDCNTL
] = eqn
| func
;
228 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CBLENDCNTL
] = eqn
| func
;
233 if (ctx
->Color
.ColorLogicOpEnabled
) {
234 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = cntl
| R200_ROP_ENABLE
;
235 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = eqn
| func
;
237 } else if (ctx
->Color
.BlendEnabled
) {
238 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = cntl
| R200_ALPHA_BLEND_ENABLE
;
241 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = cntl
;
242 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = eqn
| func
;
247 func
= (blend_factor( ctx
->Color
.BlendSrcRGB
, GL_TRUE
) << R200_SRC_BLEND_SHIFT
) |
248 (blend_factor( ctx
->Color
.BlendDstRGB
, GL_FALSE
) << R200_DST_BLEND_SHIFT
);
250 switch(ctx
->Color
.BlendEquationRGB
) {
252 eqn
= R200_COMB_FCN_ADD_CLAMP
;
255 case GL_FUNC_SUBTRACT
:
256 eqn
= R200_COMB_FCN_SUB_CLAMP
;
259 case GL_FUNC_REVERSE_SUBTRACT
:
260 eqn
= R200_COMB_FCN_RSUB_CLAMP
;
264 eqn
= R200_COMB_FCN_MIN
;
265 func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
266 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
270 eqn
= R200_COMB_FCN_MAX
;
271 func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
272 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
276 fprintf( stderr
, "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
277 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationRGB
);
281 if (!rmesa
->radeon
.radeonScreen
->drmSupportsBlendColor
) {
282 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = eqn
| func
;
286 funcA
= (blend_factor( ctx
->Color
.BlendSrcA
, GL_TRUE
) << R200_SRC_BLEND_SHIFT
) |
287 (blend_factor( ctx
->Color
.BlendDstA
, GL_FALSE
) << R200_DST_BLEND_SHIFT
);
289 switch(ctx
->Color
.BlendEquationA
) {
291 eqnA
= R200_COMB_FCN_ADD_CLAMP
;
294 case GL_FUNC_SUBTRACT
:
295 eqnA
= R200_COMB_FCN_SUB_CLAMP
;
298 case GL_FUNC_REVERSE_SUBTRACT
:
299 eqnA
= R200_COMB_FCN_RSUB_CLAMP
;
303 eqnA
= R200_COMB_FCN_MIN
;
304 funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
305 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
309 eqnA
= R200_COMB_FCN_MAX
;
310 funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
311 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
315 fprintf( stderr
, "[%s:%u] Invalid A blend equation (0x%04x).\n",
316 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationA
);
320 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ABLENDCNTL
] = eqnA
| funcA
;
321 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CBLENDCNTL
] = eqn
| func
;
325 static void r200BlendEquationSeparate( GLcontext
*ctx
,
326 GLenum modeRGB
, GLenum modeA
)
328 r200_set_blend_state( ctx
);
331 static void r200BlendFuncSeparate( GLcontext
*ctx
,
332 GLenum sfactorRGB
, GLenum dfactorRGB
,
333 GLenum sfactorA
, GLenum dfactorA
)
335 r200_set_blend_state( ctx
);
339 /* =============================================================
343 static void r200DepthFunc( GLcontext
*ctx
, GLenum func
)
345 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
347 R200_STATECHANGE( rmesa
, ctx
);
348 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~R200_Z_TEST_MASK
;
350 switch ( ctx
->Depth
.Func
) {
352 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_TEST_NEVER
;
355 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_TEST_LESS
;
358 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_TEST_EQUAL
;
361 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_TEST_LEQUAL
;
364 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_TEST_GREATER
;
367 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_TEST_NEQUAL
;
370 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_TEST_GEQUAL
;
373 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_TEST_ALWAYS
;
378 static void r200ClearDepth( GLcontext
*ctx
, GLclampd d
)
380 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
381 GLuint format
= (rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &
382 R200_DEPTH_FORMAT_MASK
);
385 case R200_DEPTH_FORMAT_16BIT_INT_Z
:
386 rmesa
->radeon
.state
.depth
.clear
= d
* 0x0000ffff;
388 case R200_DEPTH_FORMAT_24BIT_INT_Z
:
389 rmesa
->radeon
.state
.depth
.clear
= d
* 0x00ffffff;
394 static void r200DepthMask( GLcontext
*ctx
, GLboolean flag
)
396 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
397 R200_STATECHANGE( rmesa
, ctx
);
399 if ( ctx
->Depth
.Mask
) {
400 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_Z_WRITE_ENABLE
;
402 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~R200_Z_WRITE_ENABLE
;
407 /* =============================================================
412 static void r200Fogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
414 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
415 union { int i
; float f
; } c
, d
;
419 c
.i
= rmesa
->hw
.fog
.cmd
[FOG_C
];
420 d
.i
= rmesa
->hw
.fog
.cmd
[FOG_D
];
424 if (!ctx
->Fog
.Enabled
)
426 R200_STATECHANGE(rmesa
, tcl
);
427 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~R200_TCL_FOG_MASK
;
428 switch (ctx
->Fog
.Mode
) {
430 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= R200_TCL_FOG_LINEAR
;
431 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
436 c
.f
= ctx
->Fog
.End
/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
437 d
.f
= -1.0/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
441 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= R200_TCL_FOG_EXP
;
443 d
.f
= -ctx
->Fog
.Density
;
446 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= R200_TCL_FOG_EXP2
;
448 d
.f
= -(ctx
->Fog
.Density
* ctx
->Fog
.Density
);
455 switch (ctx
->Fog
.Mode
) {
458 d
.f
= -ctx
->Fog
.Density
;
462 d
.f
= -(ctx
->Fog
.Density
* ctx
->Fog
.Density
);
470 if (ctx
->Fog
.Mode
== GL_LINEAR
) {
471 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
475 c
.f
= ctx
->Fog
.End
/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
476 d
.f
= -1.0/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
481 R200_STATECHANGE( rmesa
, ctx
);
482 UNCLAMPED_FLOAT_TO_RGB_CHAN( col
, ctx
->Fog
.Color
);
483 i
= radeonPackColor( 4, col
[0], col
[1], col
[2], 0 );
484 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] &= ~R200_FOG_COLOR_MASK
;
485 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] |= i
;
487 case GL_FOG_COORD_SRC
: {
488 GLuint out_0
= rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
];
489 GLuint fog
= rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
];
491 fog
&= ~R200_FOG_USE_MASK
;
492 if ( ctx
->Fog
.FogCoordinateSource
== GL_FOG_COORD
|| ctx
->VertexProgram
.Enabled
) {
493 fog
|= R200_FOG_USE_VTX_FOG
;
494 out_0
|= R200_VTX_DISCRETE_FOG
;
497 fog
|= R200_FOG_USE_SPEC_ALPHA
;
498 out_0
&= ~R200_VTX_DISCRETE_FOG
;
501 if ( fog
!= rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] ) {
502 R200_STATECHANGE( rmesa
, ctx
);
503 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] = fog
;
506 if (out_0
!= rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
]) {
507 R200_STATECHANGE( rmesa
, vtx
);
508 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] = out_0
;
517 if (c
.i
!= rmesa
->hw
.fog
.cmd
[FOG_C
] || d
.i
!= rmesa
->hw
.fog
.cmd
[FOG_D
]) {
518 R200_STATECHANGE( rmesa
, fog
);
519 rmesa
->hw
.fog
.cmd
[FOG_C
] = c
.i
;
520 rmesa
->hw
.fog
.cmd
[FOG_D
] = d
.i
;
524 /* =============================================================
528 static void r200CullFace( GLcontext
*ctx
, GLenum unused
)
530 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
531 GLuint s
= rmesa
->hw
.set
.cmd
[SET_SE_CNTL
];
532 GLuint t
= rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
];
534 s
|= R200_FFACE_SOLID
| R200_BFACE_SOLID
;
535 t
&= ~(R200_CULL_FRONT
| R200_CULL_BACK
);
537 if ( ctx
->Polygon
.CullFlag
) {
538 switch ( ctx
->Polygon
.CullFaceMode
) {
540 s
&= ~R200_FFACE_SOLID
;
541 t
|= R200_CULL_FRONT
;
544 s
&= ~R200_BFACE_SOLID
;
547 case GL_FRONT_AND_BACK
:
548 s
&= ~(R200_FFACE_SOLID
| R200_BFACE_SOLID
);
549 t
|= (R200_CULL_FRONT
| R200_CULL_BACK
);
554 if ( rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] != s
) {
555 R200_STATECHANGE(rmesa
, set
);
556 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] = s
;
559 if ( rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] != t
) {
560 R200_STATECHANGE(rmesa
, tcl
);
561 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] = t
;
565 static void r200FrontFace( GLcontext
*ctx
, GLenum mode
)
567 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
569 R200_STATECHANGE( rmesa
, set
);
570 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~R200_FFACE_CULL_DIR_MASK
;
572 R200_STATECHANGE( rmesa
, tcl
);
573 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~R200_CULL_FRONT_IS_CCW
;
575 /* Winding is inverted when rendering to FBO */
576 if (ctx
->DrawBuffer
&& ctx
->DrawBuffer
->Name
)
577 mode
= (mode
== GL_CW
) ? GL_CCW
: GL_CW
;
581 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= R200_FFACE_CULL_CW
;
584 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= R200_FFACE_CULL_CCW
;
585 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= R200_CULL_FRONT_IS_CCW
;
590 /* =============================================================
593 static void r200PointSize( GLcontext
*ctx
, GLfloat size
)
595 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
596 GLfloat
*fcmd
= (GLfloat
*)rmesa
->hw
.ptp
.cmd
;
598 radeon_print(RADEON_STATE
, RADEON_TRACE
,
599 "%s(%p) size: %f, fixed point result: %d.%d (%d/16)\n",
601 ((GLuint
)(ctx
->Point
.Size
* 16.0))/16,
602 (((GLuint
)(ctx
->Point
.Size
* 16.0))&15)*100/16,
603 ((GLuint
)(ctx
->Point
.Size
* 16.0))&15);
605 R200_STATECHANGE( rmesa
, cst
);
606 R200_STATECHANGE( rmesa
, ptp
);
607 rmesa
->hw
.cst
.cmd
[CST_RE_POINTSIZE
] &= ~0xffff;
608 rmesa
->hw
.cst
.cmd
[CST_RE_POINTSIZE
] |= ((GLuint
)(ctx
->Point
.Size
* 16.0));
609 /* this is the size param of the point size calculation (point size reg value
610 is not used when calculation is active). */
611 fcmd
[PTP_VPORT_SCALE_PTSIZE
] = ctx
->Point
.Size
;
614 static void r200PointParameter( GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
616 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
617 GLfloat
*fcmd
= (GLfloat
*)rmesa
->hw
.ptp
.cmd
;
620 case GL_POINT_SIZE_MIN
:
621 /* Can clamp both in tcl and setup - just set both (as does fglrx) */
622 R200_STATECHANGE( rmesa
, lin
);
623 R200_STATECHANGE( rmesa
, ptp
);
624 rmesa
->hw
.lin
.cmd
[LIN_SE_LINE_WIDTH
] &= 0xffff;
625 rmesa
->hw
.lin
.cmd
[LIN_SE_LINE_WIDTH
] |= (GLuint
)(ctx
->Point
.MinSize
* 16.0) << 16;
626 fcmd
[PTP_CLAMP_MIN
] = ctx
->Point
.MinSize
;
628 case GL_POINT_SIZE_MAX
:
629 R200_STATECHANGE( rmesa
, cst
);
630 R200_STATECHANGE( rmesa
, ptp
);
631 rmesa
->hw
.cst
.cmd
[CST_RE_POINTSIZE
] &= 0xffff;
632 rmesa
->hw
.cst
.cmd
[CST_RE_POINTSIZE
] |= (GLuint
)(ctx
->Point
.MaxSize
* 16.0) << 16;
633 fcmd
[PTP_CLAMP_MAX
] = ctx
->Point
.MaxSize
;
635 case GL_POINT_DISTANCE_ATTENUATION
:
636 R200_STATECHANGE( rmesa
, vtx
);
637 R200_STATECHANGE( rmesa
, spr
);
638 R200_STATECHANGE( rmesa
, ptp
);
639 GLfloat
*fcmd
= (GLfloat
*)rmesa
->hw
.ptp
.cmd
;
640 rmesa
->hw
.spr
.cmd
[SPR_POINT_SPRITE_CNTL
] &=
641 ~(R200_PS_MULT_MASK
| R200_PS_LIN_ATT_ZERO
| R200_PS_SE_SEL_STATE
);
642 /* can't rely on ctx->Point._Attenuated here and test for NEW_POINT in
643 r200ValidateState looks like overkill */
644 if (ctx
->Point
.Params
[0] != 1.0 ||
645 ctx
->Point
.Params
[1] != 0.0 ||
646 ctx
->Point
.Params
[2] != 0.0 ||
647 (ctx
->VertexProgram
.Enabled
&& ctx
->VertexProgram
.PointSizeEnabled
)) {
648 /* all we care for vp would be the ps_se_sel_state setting */
649 fcmd
[PTP_ATT_CONST_QUAD
] = ctx
->Point
.Params
[2];
650 fcmd
[PTP_ATT_CONST_LIN
] = ctx
->Point
.Params
[1];
651 fcmd
[PTP_ATT_CONST_CON
] = ctx
->Point
.Params
[0];
652 rmesa
->hw
.spr
.cmd
[SPR_POINT_SPRITE_CNTL
] |= R200_PS_MULT_ATTENCONST
;
653 if (ctx
->Point
.Params
[1] == 0.0)
654 rmesa
->hw
.spr
.cmd
[SPR_POINT_SPRITE_CNTL
] |= R200_PS_LIN_ATT_ZERO
;
655 /* FIXME: setting this here doesn't look quite ok - we only want to do
656 that if we're actually drawing points probably */
657 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] |= R200_OUTPUT_PT_SIZE
;
658 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] |= R200_VTX_POINT_SIZE
;
661 rmesa
->hw
.spr
.cmd
[SPR_POINT_SPRITE_CNTL
] |=
662 R200_PS_SE_SEL_STATE
| R200_PS_MULT_CONST
;
663 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] &= ~R200_OUTPUT_PT_SIZE
;
664 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] &= ~R200_VTX_POINT_SIZE
;
667 case GL_POINT_FADE_THRESHOLD_SIZE
:
668 /* don't support multisampling, so doesn't matter. */
670 /* can't do these but don't need them.
671 case GL_POINT_SPRITE_R_MODE_NV:
672 case GL_POINT_SPRITE_COORD_ORIGIN: */
674 fprintf(stderr
, "bad pname parameter in r200PointParameter\n");
679 /* =============================================================
682 static void r200LineWidth( GLcontext
*ctx
, GLfloat widthf
)
684 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
686 R200_STATECHANGE( rmesa
, lin
);
687 R200_STATECHANGE( rmesa
, set
);
689 /* Line width is stored in U6.4 format.
690 * Same min/max limits for AA, non-AA lines.
692 rmesa
->hw
.lin
.cmd
[LIN_SE_LINE_WIDTH
] &= ~0xffff;
693 rmesa
->hw
.lin
.cmd
[LIN_SE_LINE_WIDTH
] |= (GLuint
)
694 (CLAMP(widthf
, ctx
->Const
.MinLineWidth
, ctx
->Const
.MaxLineWidth
) * 16.0);
696 if ( widthf
> 1.0 ) {
697 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= R200_WIDELINE_ENABLE
;
699 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~R200_WIDELINE_ENABLE
;
703 static void r200LineStipple( GLcontext
*ctx
, GLint factor
, GLushort pattern
)
705 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
707 R200_STATECHANGE( rmesa
, lin
);
708 rmesa
->hw
.lin
.cmd
[LIN_RE_LINE_PATTERN
] =
709 ((((GLuint
)factor
& 0xff) << 16) | ((GLuint
)pattern
));
713 /* =============================================================
716 static void r200ColorMask( GLcontext
*ctx
,
717 GLboolean r
, GLboolean g
,
718 GLboolean b
, GLboolean a
)
720 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
722 struct radeon_renderbuffer
*rrb
;
723 GLuint flag
= rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] & ~R200_PLANE_MASK_ENABLE
;
725 rrb
= radeon_get_colorbuffer(&rmesa
->radeon
);
728 mask
= radeonPackColor( rrb
->cpp
,
729 ctx
->Color
.ColorMask
[0][RCOMP
],
730 ctx
->Color
.ColorMask
[0][GCOMP
],
731 ctx
->Color
.ColorMask
[0][BCOMP
],
732 ctx
->Color
.ColorMask
[0][ACOMP
] );
735 if (!(r
&& g
&& b
&& a
))
736 flag
|= R200_PLANE_MASK_ENABLE
;
738 if ( rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] != flag
) {
739 R200_STATECHANGE( rmesa
, ctx
);
740 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = flag
;
743 if ( rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
] != mask
) {
744 R200_STATECHANGE( rmesa
, msk
);
745 rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
] = mask
;
750 /* =============================================================
754 static void r200PolygonOffset( GLcontext
*ctx
,
755 GLfloat factor
, GLfloat units
)
757 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
758 const GLfloat depthScale
= 1.0F
/ ctx
->DrawBuffer
->_DepthMaxF
;
759 float_ui32_type constant
= { units
* depthScale
};
760 float_ui32_type factoru
= { factor
};
765 /* fprintf(stderr, "%s f:%f u:%f\n", __FUNCTION__, factor, constant); */
767 R200_STATECHANGE( rmesa
, zbs
);
768 rmesa
->hw
.zbs
.cmd
[ZBS_SE_ZBIAS_FACTOR
] = factoru
.ui32
;
769 rmesa
->hw
.zbs
.cmd
[ZBS_SE_ZBIAS_CONSTANT
] = constant
.ui32
;
772 static void r200PolygonMode( GLcontext
*ctx
, GLenum face
, GLenum mode
)
774 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
775 GLboolean flag
= (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
) != 0;
777 /* Can't generally do unfilled via tcl, but some good special
780 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_UNFILLED
, flag
);
781 if (rmesa
->radeon
.TclFallback
) {
782 r200ChooseRenderState( ctx
);
783 r200ChooseVertexState( ctx
);
788 /* =============================================================
789 * Rendering attributes
791 * We really don't want to recalculate all this every time we bind a
792 * texture. These things shouldn't change all that often, so it makes
793 * sense to break them out of the core texture state update routines.
796 /* Examine lighting and texture state to determine if separate specular
799 static void r200UpdateSpecular( GLcontext
*ctx
)
801 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
802 uint32_t p
= rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
];
804 R200_STATECHANGE( rmesa
, tcl
);
805 R200_STATECHANGE( rmesa
, vtx
);
807 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] &= ~(3<<R200_VTX_COLOR_0_SHIFT
);
808 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] &= ~(3<<R200_VTX_COLOR_1_SHIFT
);
809 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] &= ~R200_OUTPUT_COLOR_0
;
810 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] &= ~R200_OUTPUT_COLOR_1
;
811 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] &= ~R200_LIGHTING_ENABLE
;
813 p
&= ~R200_SPECULAR_ENABLE
;
815 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] |= R200_DIFFUSE_SPECULAR_COMBINE
;
818 if (ctx
->Light
.Enabled
&&
819 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
) {
820 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] |=
821 ((R200_VTX_FP_RGBA
<< R200_VTX_COLOR_0_SHIFT
) |
822 (R200_VTX_FP_RGBA
<< R200_VTX_COLOR_1_SHIFT
));
823 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] |= R200_OUTPUT_COLOR_0
;
824 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] |= R200_OUTPUT_COLOR_1
;
825 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] |= R200_LIGHTING_ENABLE
;
826 p
|= R200_SPECULAR_ENABLE
;
827 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] &=
828 ~R200_DIFFUSE_SPECULAR_COMBINE
;
830 else if (ctx
->Light
.Enabled
) {
831 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] |=
832 ((R200_VTX_FP_RGBA
<< R200_VTX_COLOR_0_SHIFT
));
833 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] |= R200_OUTPUT_COLOR_0
;
834 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] |= R200_LIGHTING_ENABLE
;
835 } else if (ctx
->Fog
.ColorSumEnabled
) {
836 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] |=
837 ((R200_VTX_FP_RGBA
<< R200_VTX_COLOR_0_SHIFT
) |
838 (R200_VTX_FP_RGBA
<< R200_VTX_COLOR_1_SHIFT
));
839 p
|= R200_SPECULAR_ENABLE
;
841 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] |=
842 ((R200_VTX_FP_RGBA
<< R200_VTX_COLOR_0_SHIFT
));
845 if (ctx
->Fog
.Enabled
) {
846 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_0
] |=
847 ((R200_VTX_FP_RGBA
<< R200_VTX_COLOR_1_SHIFT
));
848 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] |= R200_OUTPUT_COLOR_1
;
851 if ( rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] != p
) {
852 R200_STATECHANGE( rmesa
, ctx
);
853 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] = p
;
856 /* Update vertex/render formats
858 if (rmesa
->radeon
.TclFallback
) {
859 r200ChooseRenderState( ctx
);
860 r200ChooseVertexState( ctx
);
865 /* =============================================================
870 /* Update on colormaterial, material emmissive/ambient,
871 * lightmodel.globalambient
873 static void update_global_ambient( GLcontext
*ctx
)
875 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
876 float *fcmd
= (float *)R200_DB_STATE( glt
);
878 /* Need to do more if both emmissive & ambient are PREMULT:
879 * I believe this is not nessary when using source_material. This condition thus
880 * will never happen currently, and the function has no dependencies on materials now
882 if ((rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_1
] &
883 ((3 << R200_FRONT_EMISSIVE_SOURCE_SHIFT
) |
884 (3 << R200_FRONT_AMBIENT_SOURCE_SHIFT
))) == 0)
886 COPY_3V( &fcmd
[GLT_RED
],
887 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_EMISSION
]);
888 ACC_SCALE_3V( &fcmd
[GLT_RED
],
889 ctx
->Light
.Model
.Ambient
,
890 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
]);
894 COPY_3V( &fcmd
[GLT_RED
], ctx
->Light
.Model
.Ambient
);
897 R200_DB_STATECHANGE(rmesa
, &rmesa
->hw
.glt
);
900 /* Update on change to
904 static void update_light_colors( GLcontext
*ctx
, GLuint p
)
906 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
908 /* fprintf(stderr, "%s\n", __FUNCTION__); */
911 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
912 float *fcmd
= (float *)R200_DB_STATE( lit
[p
] );
914 COPY_4V( &fcmd
[LIT_AMBIENT_RED
], l
->Ambient
);
915 COPY_4V( &fcmd
[LIT_DIFFUSE_RED
], l
->Diffuse
);
916 COPY_4V( &fcmd
[LIT_SPECULAR_RED
], l
->Specular
);
918 R200_DB_STATECHANGE( rmesa
, &rmesa
->hw
.lit
[p
] );
922 static void r200ColorMaterial( GLcontext
*ctx
, GLenum face
, GLenum mode
)
924 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
925 GLuint light_model_ctl1
= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_1
];
926 light_model_ctl1
&= ~((0xf << R200_FRONT_EMISSIVE_SOURCE_SHIFT
) |
927 (0xf << R200_FRONT_AMBIENT_SOURCE_SHIFT
) |
928 (0xf << R200_FRONT_DIFFUSE_SOURCE_SHIFT
) |
929 (0xf << R200_FRONT_SPECULAR_SOURCE_SHIFT
) |
930 (0xf << R200_BACK_EMISSIVE_SOURCE_SHIFT
) |
931 (0xf << R200_BACK_AMBIENT_SOURCE_SHIFT
) |
932 (0xf << R200_BACK_DIFFUSE_SOURCE_SHIFT
) |
933 (0xf << R200_BACK_SPECULAR_SOURCE_SHIFT
));
935 if (ctx
->Light
.ColorMaterialEnabled
) {
936 GLuint mask
= ctx
->Light
.ColorMaterialBitmask
;
938 if (mask
& MAT_BIT_FRONT_EMISSION
) {
939 light_model_ctl1
|= (R200_LM1_SOURCE_VERTEX_COLOR_0
<<
940 R200_FRONT_EMISSIVE_SOURCE_SHIFT
);
943 light_model_ctl1
|= (R200_LM1_SOURCE_MATERIAL_0
<<
944 R200_FRONT_EMISSIVE_SOURCE_SHIFT
);
946 if (mask
& MAT_BIT_FRONT_AMBIENT
) {
947 light_model_ctl1
|= (R200_LM1_SOURCE_VERTEX_COLOR_0
<<
948 R200_FRONT_AMBIENT_SOURCE_SHIFT
);
951 light_model_ctl1
|= (R200_LM1_SOURCE_MATERIAL_0
<<
952 R200_FRONT_AMBIENT_SOURCE_SHIFT
);
954 if (mask
& MAT_BIT_FRONT_DIFFUSE
) {
955 light_model_ctl1
|= (R200_LM1_SOURCE_VERTEX_COLOR_0
<<
956 R200_FRONT_DIFFUSE_SOURCE_SHIFT
);
959 light_model_ctl1
|= (R200_LM1_SOURCE_MATERIAL_0
<<
960 R200_FRONT_DIFFUSE_SOURCE_SHIFT
);
962 if (mask
& MAT_BIT_FRONT_SPECULAR
) {
963 light_model_ctl1
|= (R200_LM1_SOURCE_VERTEX_COLOR_0
<<
964 R200_FRONT_SPECULAR_SOURCE_SHIFT
);
967 light_model_ctl1
|= (R200_LM1_SOURCE_MATERIAL_0
<<
968 R200_FRONT_SPECULAR_SOURCE_SHIFT
);
971 if (mask
& MAT_BIT_BACK_EMISSION
) {
972 light_model_ctl1
|= (R200_LM1_SOURCE_VERTEX_COLOR_0
<<
973 R200_BACK_EMISSIVE_SOURCE_SHIFT
);
976 else light_model_ctl1
|= (R200_LM1_SOURCE_MATERIAL_1
<<
977 R200_BACK_EMISSIVE_SOURCE_SHIFT
);
979 if (mask
& MAT_BIT_BACK_AMBIENT
) {
980 light_model_ctl1
|= (R200_LM1_SOURCE_VERTEX_COLOR_0
<<
981 R200_BACK_AMBIENT_SOURCE_SHIFT
);
983 else light_model_ctl1
|= (R200_LM1_SOURCE_MATERIAL_1
<<
984 R200_BACK_AMBIENT_SOURCE_SHIFT
);
986 if (mask
& MAT_BIT_BACK_DIFFUSE
) {
987 light_model_ctl1
|= (R200_LM1_SOURCE_VERTEX_COLOR_0
<<
988 R200_BACK_DIFFUSE_SOURCE_SHIFT
);
990 else light_model_ctl1
|= (R200_LM1_SOURCE_MATERIAL_1
<<
991 R200_BACK_DIFFUSE_SOURCE_SHIFT
);
993 if (mask
& MAT_BIT_BACK_SPECULAR
) {
994 light_model_ctl1
|= (R200_LM1_SOURCE_VERTEX_COLOR_0
<<
995 R200_BACK_SPECULAR_SOURCE_SHIFT
);
998 light_model_ctl1
|= (R200_LM1_SOURCE_MATERIAL_1
<<
999 R200_BACK_SPECULAR_SOURCE_SHIFT
);
1003 /* Default to SOURCE_MATERIAL:
1006 (R200_LM1_SOURCE_MATERIAL_0
<< R200_FRONT_EMISSIVE_SOURCE_SHIFT
) |
1007 (R200_LM1_SOURCE_MATERIAL_0
<< R200_FRONT_AMBIENT_SOURCE_SHIFT
) |
1008 (R200_LM1_SOURCE_MATERIAL_0
<< R200_FRONT_DIFFUSE_SOURCE_SHIFT
) |
1009 (R200_LM1_SOURCE_MATERIAL_0
<< R200_FRONT_SPECULAR_SOURCE_SHIFT
) |
1010 (R200_LM1_SOURCE_MATERIAL_1
<< R200_BACK_EMISSIVE_SOURCE_SHIFT
) |
1011 (R200_LM1_SOURCE_MATERIAL_1
<< R200_BACK_AMBIENT_SOURCE_SHIFT
) |
1012 (R200_LM1_SOURCE_MATERIAL_1
<< R200_BACK_DIFFUSE_SOURCE_SHIFT
) |
1013 (R200_LM1_SOURCE_MATERIAL_1
<< R200_BACK_SPECULAR_SOURCE_SHIFT
);
1016 if (light_model_ctl1
!= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_1
]) {
1017 R200_STATECHANGE( rmesa
, tcl
);
1018 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_1
] = light_model_ctl1
;
1024 void r200UpdateMaterial( GLcontext
*ctx
)
1026 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1027 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
1028 GLfloat
*fcmd
= (GLfloat
*)R200_DB_STATE( mtl
[0] );
1029 GLfloat
*fcmd2
= (GLfloat
*)R200_DB_STATE( mtl
[1] );
1032 /* Might be possible and faster to update everything unconditionally? */
1033 if (ctx
->Light
.ColorMaterialEnabled
)
1034 mask
&= ~ctx
->Light
.ColorMaterialBitmask
;
1036 if (R200_DEBUG
& RADEON_STATE
)
1037 fprintf(stderr
, "%s\n", __FUNCTION__
);
1039 if (mask
& MAT_BIT_FRONT_EMISSION
) {
1040 fcmd
[MTL_EMMISSIVE_RED
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][0];
1041 fcmd
[MTL_EMMISSIVE_GREEN
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][1];
1042 fcmd
[MTL_EMMISSIVE_BLUE
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][2];
1043 fcmd
[MTL_EMMISSIVE_ALPHA
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][3];
1045 if (mask
& MAT_BIT_FRONT_AMBIENT
) {
1046 fcmd
[MTL_AMBIENT_RED
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][0];
1047 fcmd
[MTL_AMBIENT_GREEN
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][1];
1048 fcmd
[MTL_AMBIENT_BLUE
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][2];
1049 fcmd
[MTL_AMBIENT_ALPHA
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][3];
1051 if (mask
& MAT_BIT_FRONT_DIFFUSE
) {
1052 fcmd
[MTL_DIFFUSE_RED
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][0];
1053 fcmd
[MTL_DIFFUSE_GREEN
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][1];
1054 fcmd
[MTL_DIFFUSE_BLUE
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][2];
1055 fcmd
[MTL_DIFFUSE_ALPHA
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][3];
1057 if (mask
& MAT_BIT_FRONT_SPECULAR
) {
1058 fcmd
[MTL_SPECULAR_RED
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][0];
1059 fcmd
[MTL_SPECULAR_GREEN
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][1];
1060 fcmd
[MTL_SPECULAR_BLUE
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][2];
1061 fcmd
[MTL_SPECULAR_ALPHA
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][3];
1063 if (mask
& MAT_BIT_FRONT_SHININESS
) {
1064 fcmd
[MTL_SHININESS
] = mat
[MAT_ATTRIB_FRONT_SHININESS
][0];
1067 if (mask
& MAT_BIT_BACK_EMISSION
) {
1068 fcmd2
[MTL_EMMISSIVE_RED
] = mat
[MAT_ATTRIB_BACK_EMISSION
][0];
1069 fcmd2
[MTL_EMMISSIVE_GREEN
] = mat
[MAT_ATTRIB_BACK_EMISSION
][1];
1070 fcmd2
[MTL_EMMISSIVE_BLUE
] = mat
[MAT_ATTRIB_BACK_EMISSION
][2];
1071 fcmd2
[MTL_EMMISSIVE_ALPHA
] = mat
[MAT_ATTRIB_BACK_EMISSION
][3];
1073 if (mask
& MAT_BIT_BACK_AMBIENT
) {
1074 fcmd2
[MTL_AMBIENT_RED
] = mat
[MAT_ATTRIB_BACK_AMBIENT
][0];
1075 fcmd2
[MTL_AMBIENT_GREEN
] = mat
[MAT_ATTRIB_BACK_AMBIENT
][1];
1076 fcmd2
[MTL_AMBIENT_BLUE
] = mat
[MAT_ATTRIB_BACK_AMBIENT
][2];
1077 fcmd2
[MTL_AMBIENT_ALPHA
] = mat
[MAT_ATTRIB_BACK_AMBIENT
][3];
1079 if (mask
& MAT_BIT_BACK_DIFFUSE
) {
1080 fcmd2
[MTL_DIFFUSE_RED
] = mat
[MAT_ATTRIB_BACK_DIFFUSE
][0];
1081 fcmd2
[MTL_DIFFUSE_GREEN
] = mat
[MAT_ATTRIB_BACK_DIFFUSE
][1];
1082 fcmd2
[MTL_DIFFUSE_BLUE
] = mat
[MAT_ATTRIB_BACK_DIFFUSE
][2];
1083 fcmd2
[MTL_DIFFUSE_ALPHA
] = mat
[MAT_ATTRIB_BACK_DIFFUSE
][3];
1085 if (mask
& MAT_BIT_BACK_SPECULAR
) {
1086 fcmd2
[MTL_SPECULAR_RED
] = mat
[MAT_ATTRIB_BACK_SPECULAR
][0];
1087 fcmd2
[MTL_SPECULAR_GREEN
] = mat
[MAT_ATTRIB_BACK_SPECULAR
][1];
1088 fcmd2
[MTL_SPECULAR_BLUE
] = mat
[MAT_ATTRIB_BACK_SPECULAR
][2];
1089 fcmd2
[MTL_SPECULAR_ALPHA
] = mat
[MAT_ATTRIB_BACK_SPECULAR
][3];
1091 if (mask
& MAT_BIT_BACK_SHININESS
) {
1092 fcmd2
[MTL_SHININESS
] = mat
[MAT_ATTRIB_BACK_SHININESS
][0];
1095 R200_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mtl
[0] );
1096 R200_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mtl
[1] );
1098 /* currently material changes cannot trigger a global ambient change, I believe this is correct
1099 update_global_ambient( ctx ); */
1104 * _MESA_NEW_NEED_EYE_COORDS
1106 * Uses derived state from mesa:
1110 * _NormSpotDirection
1111 * _ModelViewInvScale
1115 * which are calculated in light.c and are correct for the current
1116 * lighting space (model or eye), hence dependencies on _NEW_MODELVIEW
1117 * and _MESA_NEW_NEED_EYE_COORDS.
1119 static void update_light( GLcontext
*ctx
)
1121 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1123 /* Have to check these, or have an automatic shortcircuit mechanism
1124 * to remove noop statechanges. (Or just do a better job on the
1128 GLuint tmp
= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
];
1130 if (ctx
->_NeedEyeCoords
)
1131 tmp
&= ~R200_LIGHT_IN_MODELSPACE
;
1133 tmp
|= R200_LIGHT_IN_MODELSPACE
;
1135 if (tmp
!= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
])
1137 R200_STATECHANGE( rmesa
, tcl
);
1138 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] = tmp
;
1143 GLfloat
*fcmd
= (GLfloat
*)R200_DB_STATE( eye
);
1144 fcmd
[EYE_X
] = ctx
->_EyeZDir
[0];
1145 fcmd
[EYE_Y
] = ctx
->_EyeZDir
[1];
1146 fcmd
[EYE_Z
] = - ctx
->_EyeZDir
[2];
1147 fcmd
[EYE_RESCALE_FACTOR
] = ctx
->_ModelViewInvScale
;
1148 R200_DB_STATECHANGE( rmesa
, &rmesa
->hw
.eye
);
1153 if (ctx
->Light
.Enabled
) {
1155 for (p
= 0 ; p
< MAX_LIGHTS
; p
++) {
1156 if (ctx
->Light
.Light
[p
].Enabled
) {
1157 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
1158 GLfloat
*fcmd
= (GLfloat
*)R200_DB_STATE( lit
[p
] );
1160 if (l
->EyePosition
[3] == 0.0) {
1161 COPY_3FV( &fcmd
[LIT_POSITION_X
], l
->_VP_inf_norm
);
1162 COPY_3FV( &fcmd
[LIT_DIRECTION_X
], l
->_h_inf_norm
);
1163 fcmd
[LIT_POSITION_W
] = 0;
1164 fcmd
[LIT_DIRECTION_W
] = 0;
1166 COPY_4V( &fcmd
[LIT_POSITION_X
], l
->_Position
);
1167 fcmd
[LIT_DIRECTION_X
] = -l
->_NormSpotDirection
[0];
1168 fcmd
[LIT_DIRECTION_Y
] = -l
->_NormSpotDirection
[1];
1169 fcmd
[LIT_DIRECTION_Z
] = -l
->_NormSpotDirection
[2];
1170 fcmd
[LIT_DIRECTION_W
] = 0;
1173 R200_DB_STATECHANGE( rmesa
, &rmesa
->hw
.lit
[p
] );
1179 static void r200Lightfv( GLcontext
*ctx
, GLenum light
,
1180 GLenum pname
, const GLfloat
*params
)
1182 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1183 GLint p
= light
- GL_LIGHT0
;
1184 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
1185 GLfloat
*fcmd
= (GLfloat
*)rmesa
->hw
.lit
[p
].cmd
;
1192 update_light_colors( ctx
, p
);
1195 case GL_SPOT_DIRECTION
:
1196 /* picked up in update_light */
1200 /* positions picked up in update_light, but can do flag here */
1201 GLuint flag
= (p
&1)? R200_LIGHT_1_IS_LOCAL
: R200_LIGHT_0_IS_LOCAL
;
1202 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1204 R200_STATECHANGE(rmesa
, tcl
);
1205 if (l
->EyePosition
[3] != 0.0F
)
1206 rmesa
->hw
.tcl
.cmd
[idx
] |= flag
;
1208 rmesa
->hw
.tcl
.cmd
[idx
] &= ~flag
;
1212 case GL_SPOT_EXPONENT
:
1213 R200_STATECHANGE(rmesa
, lit
[p
]);
1214 fcmd
[LIT_SPOT_EXPONENT
] = params
[0];
1217 case GL_SPOT_CUTOFF
: {
1218 GLuint flag
= (p
&1) ? R200_LIGHT_1_IS_SPOT
: R200_LIGHT_0_IS_SPOT
;
1219 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1221 R200_STATECHANGE(rmesa
, lit
[p
]);
1222 fcmd
[LIT_SPOT_CUTOFF
] = l
->_CosCutoff
;
1224 R200_STATECHANGE(rmesa
, tcl
);
1225 if (l
->SpotCutoff
!= 180.0F
)
1226 rmesa
->hw
.tcl
.cmd
[idx
] |= flag
;
1228 rmesa
->hw
.tcl
.cmd
[idx
] &= ~flag
;
1233 case GL_CONSTANT_ATTENUATION
:
1234 R200_STATECHANGE(rmesa
, lit
[p
]);
1235 fcmd
[LIT_ATTEN_CONST
] = params
[0];
1236 if ( params
[0] == 0.0 )
1237 fcmd
[LIT_ATTEN_CONST_INV
] = FLT_MAX
;
1239 fcmd
[LIT_ATTEN_CONST_INV
] = 1.0 / params
[0];
1241 case GL_LINEAR_ATTENUATION
:
1242 R200_STATECHANGE(rmesa
, lit
[p
]);
1243 fcmd
[LIT_ATTEN_LINEAR
] = params
[0];
1245 case GL_QUADRATIC_ATTENUATION
:
1246 R200_STATECHANGE(rmesa
, lit
[p
]);
1247 fcmd
[LIT_ATTEN_QUADRATIC
] = params
[0];
1253 /* Set RANGE_ATTEN only when needed */
1256 case GL_CONSTANT_ATTENUATION
:
1257 case GL_LINEAR_ATTENUATION
:
1258 case GL_QUADRATIC_ATTENUATION
: {
1259 GLuint
*icmd
= (GLuint
*)R200_DB_STATE( tcl
);
1260 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1261 GLuint atten_flag
= ( p
&1 ) ? R200_LIGHT_1_ENABLE_RANGE_ATTEN
1262 : R200_LIGHT_0_ENABLE_RANGE_ATTEN
;
1263 GLuint atten_const_flag
= ( p
&1 ) ? R200_LIGHT_1_CONSTANT_RANGE_ATTEN
1264 : R200_LIGHT_0_CONSTANT_RANGE_ATTEN
;
1266 if ( l
->EyePosition
[3] == 0.0F
||
1267 ( ( fcmd
[LIT_ATTEN_CONST
] == 0.0 || fcmd
[LIT_ATTEN_CONST
] == 1.0 ) &&
1268 fcmd
[LIT_ATTEN_QUADRATIC
] == 0.0 && fcmd
[LIT_ATTEN_LINEAR
] == 0.0 ) ) {
1269 /* Disable attenuation */
1270 icmd
[idx
] &= ~atten_flag
;
1272 if ( fcmd
[LIT_ATTEN_QUADRATIC
] == 0.0 && fcmd
[LIT_ATTEN_LINEAR
] == 0.0 ) {
1273 /* Enable only constant portion of attenuation calculation */
1274 icmd
[idx
] |= ( atten_flag
| atten_const_flag
);
1276 /* Enable full attenuation calculation */
1277 icmd
[idx
] &= ~atten_const_flag
;
1278 icmd
[idx
] |= atten_flag
;
1282 R200_DB_STATECHANGE( rmesa
, &rmesa
->hw
.tcl
);
1290 static void r200UpdateLocalViewer ( GLcontext
*ctx
)
1292 /* It looks like for the texgen modes GL_SPHERE_MAP, GL_NORMAL_MAP and
1293 GL_REFLECTION_MAP we need R200_LOCAL_VIEWER set (fglrx does exactly that
1294 for these and only these modes). This means specular highlights may turn out
1295 wrong in some cases when lighting is enabled but GL_LIGHT_MODEL_LOCAL_VIEWER
1296 is not set, though it seems to happen rarely and the effect seems quite
1297 subtle. May need TCL fallback to fix it completely, though I'm not sure
1298 how you'd identify the cases where the specular highlights indeed will
1299 be wrong. Don't know if fglrx does something special in that case.
1301 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1302 R200_STATECHANGE( rmesa
, tcl
);
1303 if (ctx
->Light
.Model
.LocalViewer
||
1304 ctx
->Texture
._GenFlags
& TEXGEN_NEED_NORMALS
)
1305 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] |= R200_LOCAL_VIEWER
;
1307 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] &= ~R200_LOCAL_VIEWER
;
1310 static void r200LightModelfv( GLcontext
*ctx
, GLenum pname
,
1311 const GLfloat
*param
)
1313 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1316 case GL_LIGHT_MODEL_AMBIENT
:
1317 update_global_ambient( ctx
);
1320 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
1321 r200UpdateLocalViewer( ctx
);
1324 case GL_LIGHT_MODEL_TWO_SIDE
:
1325 R200_STATECHANGE( rmesa
, tcl
);
1326 if (ctx
->Light
.Model
.TwoSide
)
1327 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] |= R200_LIGHT_TWOSIDE
;
1329 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] &= ~(R200_LIGHT_TWOSIDE
);
1330 if (rmesa
->radeon
.TclFallback
) {
1331 r200ChooseRenderState( ctx
);
1332 r200ChooseVertexState( ctx
);
1336 case GL_LIGHT_MODEL_COLOR_CONTROL
:
1337 r200UpdateSpecular(ctx
);
1345 static void r200ShadeModel( GLcontext
*ctx
, GLenum mode
)
1347 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1348 GLuint s
= rmesa
->hw
.set
.cmd
[SET_SE_CNTL
];
1350 s
&= ~(R200_DIFFUSE_SHADE_MASK
|
1351 R200_ALPHA_SHADE_MASK
|
1352 R200_SPECULAR_SHADE_MASK
|
1353 R200_FOG_SHADE_MASK
|
1354 R200_DISC_FOG_SHADE_MASK
);
1358 s
|= (R200_DIFFUSE_SHADE_FLAT
|
1359 R200_ALPHA_SHADE_FLAT
|
1360 R200_SPECULAR_SHADE_FLAT
|
1361 R200_FOG_SHADE_FLAT
|
1362 R200_DISC_FOG_SHADE_FLAT
);
1365 s
|= (R200_DIFFUSE_SHADE_GOURAUD
|
1366 R200_ALPHA_SHADE_GOURAUD
|
1367 R200_SPECULAR_SHADE_GOURAUD
|
1368 R200_FOG_SHADE_GOURAUD
|
1369 R200_DISC_FOG_SHADE_GOURAUD
);
1375 if ( rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] != s
) {
1376 R200_STATECHANGE( rmesa
, set
);
1377 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] = s
;
1382 /* =============================================================
1386 static void r200ClipPlane( GLcontext
*ctx
, GLenum plane
, const GLfloat
*eq
)
1388 GLint p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
1389 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1390 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
1392 R200_STATECHANGE( rmesa
, ucp
[p
] );
1393 rmesa
->hw
.ucp
[p
].cmd
[UCP_X
] = ip
[0];
1394 rmesa
->hw
.ucp
[p
].cmd
[UCP_Y
] = ip
[1];
1395 rmesa
->hw
.ucp
[p
].cmd
[UCP_Z
] = ip
[2];
1396 rmesa
->hw
.ucp
[p
].cmd
[UCP_W
] = ip
[3];
1399 static void r200UpdateClipPlanes( GLcontext
*ctx
)
1401 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1404 for (p
= 0; p
< ctx
->Const
.MaxClipPlanes
; p
++) {
1405 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
1406 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
1408 R200_STATECHANGE( rmesa
, ucp
[p
] );
1409 rmesa
->hw
.ucp
[p
].cmd
[UCP_X
] = ip
[0];
1410 rmesa
->hw
.ucp
[p
].cmd
[UCP_Y
] = ip
[1];
1411 rmesa
->hw
.ucp
[p
].cmd
[UCP_Z
] = ip
[2];
1412 rmesa
->hw
.ucp
[p
].cmd
[UCP_W
] = ip
[3];
1418 /* =============================================================
1423 r200StencilFuncSeparate( GLcontext
*ctx
, GLenum face
, GLenum func
,
1424 GLint ref
, GLuint mask
)
1426 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1427 GLuint refmask
= (((ctx
->Stencil
.Ref
[0] & 0xff) << R200_STENCIL_REF_SHIFT
) |
1428 ((ctx
->Stencil
.ValueMask
[0] & 0xff) << R200_STENCIL_MASK_SHIFT
));
1430 R200_STATECHANGE( rmesa
, ctx
);
1431 R200_STATECHANGE( rmesa
, msk
);
1433 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~R200_STENCIL_TEST_MASK
;
1434 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] &= ~(R200_STENCIL_REF_MASK
|
1435 R200_STENCIL_VALUE_MASK
);
1437 switch ( ctx
->Stencil
.Function
[0] ) {
1439 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_TEST_NEVER
;
1442 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_TEST_LESS
;
1445 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_TEST_EQUAL
;
1448 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_TEST_LEQUAL
;
1451 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_TEST_GREATER
;
1454 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_TEST_NEQUAL
;
1457 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_TEST_GEQUAL
;
1460 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_TEST_ALWAYS
;
1464 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] |= refmask
;
1468 r200StencilMaskSeparate( GLcontext
*ctx
, GLenum face
, GLuint mask
)
1470 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1472 R200_STATECHANGE( rmesa
, msk
);
1473 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] &= ~R200_STENCIL_WRITE_MASK
;
1474 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] |=
1475 ((ctx
->Stencil
.WriteMask
[0] & 0xff) << R200_STENCIL_WRITEMASK_SHIFT
);
1479 r200StencilOpSeparate( GLcontext
*ctx
, GLenum face
, GLenum fail
,
1480 GLenum zfail
, GLenum zpass
)
1482 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1484 R200_STATECHANGE( rmesa
, ctx
);
1485 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~(R200_STENCIL_FAIL_MASK
|
1486 R200_STENCIL_ZFAIL_MASK
|
1487 R200_STENCIL_ZPASS_MASK
);
1489 switch ( ctx
->Stencil
.FailFunc
[0] ) {
1491 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_FAIL_KEEP
;
1494 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_FAIL_ZERO
;
1497 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_FAIL_REPLACE
;
1500 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_FAIL_INC
;
1503 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_FAIL_DEC
;
1505 case GL_INCR_WRAP_EXT
:
1506 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_FAIL_INC_WRAP
;
1508 case GL_DECR_WRAP_EXT
:
1509 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_FAIL_DEC_WRAP
;
1512 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_FAIL_INVERT
;
1516 switch ( ctx
->Stencil
.ZFailFunc
[0] ) {
1518 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZFAIL_KEEP
;
1521 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZFAIL_ZERO
;
1524 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZFAIL_REPLACE
;
1527 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZFAIL_INC
;
1530 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZFAIL_DEC
;
1532 case GL_INCR_WRAP_EXT
:
1533 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZFAIL_INC_WRAP
;
1535 case GL_DECR_WRAP_EXT
:
1536 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZFAIL_DEC_WRAP
;
1539 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZFAIL_INVERT
;
1543 switch ( ctx
->Stencil
.ZPassFunc
[0] ) {
1545 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZPASS_KEEP
;
1548 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZPASS_ZERO
;
1551 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZPASS_REPLACE
;
1554 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZPASS_INC
;
1557 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZPASS_DEC
;
1559 case GL_INCR_WRAP_EXT
:
1560 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZPASS_INC_WRAP
;
1562 case GL_DECR_WRAP_EXT
:
1563 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZPASS_DEC_WRAP
;
1566 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= R200_STENCIL_ZPASS_INVERT
;
1571 static void r200ClearStencil( GLcontext
*ctx
, GLint s
)
1573 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1575 rmesa
->radeon
.state
.stencil
.clear
=
1576 ((GLuint
) (ctx
->Stencil
.Clear
& 0xff) |
1577 (0xff << R200_STENCIL_MASK_SHIFT
) |
1578 ((ctx
->Stencil
.WriteMask
[0] & 0xff) << R200_STENCIL_WRITEMASK_SHIFT
));
1582 /* =============================================================
1583 * Window position and viewport transformation
1587 * Called when window size or position changes or viewport or depth range
1588 * state is changed. We update the hardware viewport state here.
1590 void r200UpdateWindow( GLcontext
*ctx
)
1592 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1593 __DRIdrawable
*dPriv
= radeon_get_drawable(&rmesa
->radeon
);
1594 GLfloat xoffset
= dPriv
? (GLfloat
) dPriv
->x
: 0;
1595 GLfloat yoffset
= dPriv
? (GLfloat
) dPriv
->y
+ dPriv
->h
: 0;
1596 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1597 const GLboolean render_to_fbo
= (ctx
->DrawBuffer
? (ctx
->DrawBuffer
->Name
!= 0) : 0);
1598 const GLfloat depthScale
= 1.0F
/ ctx
->DrawBuffer
->_DepthMaxF
;
1599 GLfloat y_scale
, y_bias
;
1601 if (render_to_fbo
) {
1609 float_ui32_type sx
= { v
[MAT_SX
] };
1610 float_ui32_type tx
= { v
[MAT_TX
] + xoffset
};
1611 float_ui32_type sy
= { v
[MAT_SY
] * y_scale
};
1612 float_ui32_type ty
= { (v
[MAT_TY
] * y_scale
) + y_bias
};
1613 float_ui32_type sz
= { v
[MAT_SZ
] * depthScale
};
1614 float_ui32_type tz
= { v
[MAT_TZ
] * depthScale
};
1616 R200_STATECHANGE( rmesa
, vpt
);
1618 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XSCALE
] = sx
.ui32
;
1619 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] = tx
.ui32
;
1620 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YSCALE
] = sy
.ui32
;
1621 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] = ty
.ui32
;
1622 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_ZSCALE
] = sz
.ui32
;
1623 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_ZOFFSET
] = tz
.ui32
;
1626 void r200_vtbl_update_scissor( GLcontext
*ctx
)
1628 r200ContextPtr r200
= R200_CONTEXT(ctx
);
1629 unsigned x1
, y1
, x2
, y2
;
1630 struct radeon_renderbuffer
*rrb
;
1632 R200_SET_STATE(r200
, set
, SET_RE_CNTL
, R200_SCISSOR_ENABLE
| r200
->hw
.set
.cmd
[SET_RE_CNTL
]);
1634 if (r200
->radeon
.state
.scissor
.enabled
) {
1635 x1
= r200
->radeon
.state
.scissor
.rect
.x1
;
1636 y1
= r200
->radeon
.state
.scissor
.rect
.y1
;
1637 x2
= r200
->radeon
.state
.scissor
.rect
.x2
;
1638 y2
= r200
->radeon
.state
.scissor
.rect
.y2
;
1640 rrb
= radeon_get_colorbuffer(&r200
->radeon
);
1643 x2
= rrb
->base
.Width
- 1;
1644 y2
= rrb
->base
.Height
- 1;
1647 R200_SET_STATE(r200
, sci
, SCI_XY_1
, x1
| (y1
<< 16));
1648 R200_SET_STATE(r200
, sci
, SCI_XY_2
, x2
| (y2
<< 16));
1652 static void r200Viewport( GLcontext
*ctx
, GLint x
, GLint y
,
1653 GLsizei width
, GLsizei height
)
1655 /* Don't pipeline viewport changes, conflict with window offset
1656 * setting below. Could apply deltas to rescue pipelined viewport
1657 * values, or keep the originals hanging around.
1659 r200UpdateWindow( ctx
);
1661 radeon_viewport(ctx
, x
, y
, width
, height
);
1664 static void r200DepthRange( GLcontext
*ctx
, GLclampd nearval
,
1667 r200UpdateWindow( ctx
);
1670 void r200UpdateViewportOffset( GLcontext
*ctx
)
1672 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1673 __DRIdrawable
*dPriv
= radeon_get_drawable(&rmesa
->radeon
);
1674 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1675 GLfloat yoffset
= (GLfloat
)dPriv
->y
+ dPriv
->h
;
1676 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1681 tx
.f
= v
[MAT_TX
] + xoffset
;
1682 ty
.f
= (- v
[MAT_TY
]) + yoffset
;
1684 if ( rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] != tx
.ui32
||
1685 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] != ty
.ui32
)
1687 /* Note: this should also modify whatever data the context reset
1690 R200_STATECHANGE( rmesa
, vpt
);
1691 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] = tx
.ui32
;
1692 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] = ty
.ui32
;
1694 /* update polygon stipple x/y screen offset */
1697 GLuint m
= rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
];
1699 m
&= ~(R200_STIPPLE_X_OFFSET_MASK
|
1700 R200_STIPPLE_Y_OFFSET_MASK
);
1702 /* add magic offsets, then invert */
1703 stx
= 31 - ((dPriv
->x
- 1) & R200_STIPPLE_COORD_MASK
);
1704 sty
= 31 - ((dPriv
->y
+ dPriv
->h
- 1)
1705 & R200_STIPPLE_COORD_MASK
);
1707 m
|= ((stx
<< R200_STIPPLE_X_OFFSET_SHIFT
) |
1708 (sty
<< R200_STIPPLE_Y_OFFSET_SHIFT
));
1710 if ( rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
] != m
) {
1711 R200_STATECHANGE( rmesa
, msc
);
1712 rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
] = m
;
1717 radeonUpdateScissor( ctx
);
1722 /* =============================================================
1726 static void r200ClearColor( GLcontext
*ctx
, const GLfloat c
[4] )
1728 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1730 struct radeon_renderbuffer
*rrb
;
1732 rrb
= radeon_get_colorbuffer(&rmesa
->radeon
);
1735 CLAMPED_FLOAT_TO_UBYTE(color
[0], c
[0]);
1736 CLAMPED_FLOAT_TO_UBYTE(color
[1], c
[1]);
1737 CLAMPED_FLOAT_TO_UBYTE(color
[2], c
[2]);
1738 CLAMPED_FLOAT_TO_UBYTE(color
[3], c
[3]);
1739 rmesa
->radeon
.state
.color
.clear
= radeonPackColor( rrb
->cpp
,
1741 color
[2], color
[3] );
1745 static void r200RenderMode( GLcontext
*ctx
, GLenum mode
)
1747 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1748 FALLBACK( rmesa
, R200_FALLBACK_RENDER_MODE
, (mode
!= GL_RENDER
) );
1752 static GLuint r200_rop_tab
[] = {
1755 R200_ROP_AND_REVERSE
,
1757 R200_ROP_AND_INVERTED
,
1764 R200_ROP_OR_REVERSE
,
1765 R200_ROP_COPY_INVERTED
,
1766 R200_ROP_OR_INVERTED
,
1771 static void r200LogicOpCode( GLcontext
*ctx
, GLenum opcode
)
1773 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1774 GLuint rop
= (GLuint
)opcode
- GL_CLEAR
;
1778 R200_STATECHANGE( rmesa
, msk
);
1779 rmesa
->hw
.msk
.cmd
[MSK_RB3D_ROPCNTL
] = r200_rop_tab
[rop
];
1782 /* =============================================================
1783 * State enable/disable
1786 static void r200Enable( GLcontext
*ctx
, GLenum cap
, GLboolean state
)
1788 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1791 if ( R200_DEBUG
& RADEON_STATE
)
1792 fprintf( stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1793 _mesa_lookup_enum_by_nr( cap
),
1794 state
? "GL_TRUE" : "GL_FALSE" );
1797 /* Fast track this one...
1805 R200_STATECHANGE( rmesa
, ctx
);
1807 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= R200_ALPHA_TEST_ENABLE
;
1809 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~R200_ALPHA_TEST_ENABLE
;
1814 case GL_COLOR_LOGIC_OP
:
1815 r200_set_blend_state( ctx
);
1818 case GL_CLIP_PLANE0
:
1819 case GL_CLIP_PLANE1
:
1820 case GL_CLIP_PLANE2
:
1821 case GL_CLIP_PLANE3
:
1822 case GL_CLIP_PLANE4
:
1823 case GL_CLIP_PLANE5
:
1824 p
= cap
-GL_CLIP_PLANE0
;
1825 R200_STATECHANGE( rmesa
, tcl
);
1827 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= (R200_UCP_ENABLE_0
<<p
);
1828 r200ClipPlane( ctx
, cap
, NULL
);
1831 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~(R200_UCP_ENABLE_0
<<p
);
1835 case GL_COLOR_MATERIAL
:
1836 r200ColorMaterial( ctx
, 0, 0 );
1837 r200UpdateMaterial( ctx
);
1841 r200CullFace( ctx
, 0 );
1845 R200_STATECHANGE(rmesa
, ctx
);
1847 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= R200_Z_ENABLE
;
1849 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~R200_Z_ENABLE
;
1854 R200_STATECHANGE(rmesa
, ctx
);
1856 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= R200_DITHER_ENABLE
;
1857 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~rmesa
->radeon
.state
.color
.roundEnable
;
1859 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~R200_DITHER_ENABLE
;
1860 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= rmesa
->radeon
.state
.color
.roundEnable
;
1865 R200_STATECHANGE(rmesa
, ctx
);
1867 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= R200_FOG_ENABLE
;
1868 r200Fogfv( ctx
, GL_FOG_MODE
, NULL
);
1870 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~R200_FOG_ENABLE
;
1871 R200_STATECHANGE(rmesa
, tcl
);
1872 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~R200_TCL_FOG_MASK
;
1874 r200UpdateSpecular( ctx
); /* for PK_SPEC */
1875 if (rmesa
->radeon
.TclFallback
)
1876 r200ChooseVertexState( ctx
);
1877 _mesa_allow_light_in_model( ctx
, !state
);
1888 R200_STATECHANGE(rmesa
, tcl
);
1889 p
= cap
- GL_LIGHT0
;
1891 flag
= (R200_LIGHT_1_ENABLE
|
1892 R200_LIGHT_1_ENABLE_AMBIENT
|
1893 R200_LIGHT_1_ENABLE_SPECULAR
);
1895 flag
= (R200_LIGHT_0_ENABLE
|
1896 R200_LIGHT_0_ENABLE_AMBIENT
|
1897 R200_LIGHT_0_ENABLE_SPECULAR
);
1900 rmesa
->hw
.tcl
.cmd
[p
/2 + TCL_PER_LIGHT_CTL_0
] |= flag
;
1902 rmesa
->hw
.tcl
.cmd
[p
/2 + TCL_PER_LIGHT_CTL_0
] &= ~flag
;
1906 update_light_colors( ctx
, p
);
1910 r200UpdateSpecular(ctx
);
1911 /* for reflection map fixup - might set recheck_texgen for all units too */
1912 rmesa
->radeon
.NewGLState
|= _NEW_TEXTURE
;
1915 case GL_LINE_SMOOTH
:
1916 R200_STATECHANGE( rmesa
, ctx
);
1918 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= R200_ANTI_ALIAS_LINE
;
1920 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~R200_ANTI_ALIAS_LINE
;
1924 case GL_LINE_STIPPLE
:
1925 R200_STATECHANGE( rmesa
, set
);
1927 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] |= R200_PATTERN_ENABLE
;
1929 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] &= ~R200_PATTERN_ENABLE
;
1934 R200_STATECHANGE( rmesa
, tcl
);
1936 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] |= R200_NORMALIZE_NORMALS
;
1938 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] &= ~R200_NORMALIZE_NORMALS
;
1942 /* Pointsize registers on r200 only work for point sprites, and point smooth
1943 * doesn't work for point sprites (and isn't needed for 1.0 sized aa points).
1944 * In any case, setting pointmin == pointsizemax == 1.0 for aa points
1945 * is enough to satisfy conform.
1947 case GL_POINT_SMOOTH
:
1950 /* These don't really do anything, as we don't use the 3vtx
1954 case GL_POLYGON_OFFSET_POINT
:
1955 R200_STATECHANGE( rmesa
, set
);
1957 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= R200_ZBIAS_ENABLE_POINT
;
1959 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~R200_ZBIAS_ENABLE_POINT
;
1963 case GL_POLYGON_OFFSET_LINE
:
1964 R200_STATECHANGE( rmesa
, set
);
1966 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= R200_ZBIAS_ENABLE_LINE
;
1968 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~R200_ZBIAS_ENABLE_LINE
;
1973 case GL_POINT_SPRITE_ARB
:
1974 R200_STATECHANGE( rmesa
, spr
);
1977 for (i
= 0; i
< 6; i
++) {
1978 rmesa
->hw
.spr
.cmd
[SPR_POINT_SPRITE_CNTL
] |=
1979 ctx
->Point
.CoordReplace
[i
] << (R200_PS_GEN_TEX_0_SHIFT
+ i
);
1982 rmesa
->hw
.spr
.cmd
[SPR_POINT_SPRITE_CNTL
] &= ~R200_PS_GEN_TEX_MASK
;
1986 case GL_POLYGON_OFFSET_FILL
:
1987 R200_STATECHANGE( rmesa
, set
);
1989 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= R200_ZBIAS_ENABLE_TRI
;
1991 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~R200_ZBIAS_ENABLE_TRI
;
1995 case GL_POLYGON_SMOOTH
:
1996 R200_STATECHANGE( rmesa
, ctx
);
1998 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= R200_ANTI_ALIAS_POLY
;
2000 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~R200_ANTI_ALIAS_POLY
;
2004 case GL_POLYGON_STIPPLE
:
2005 R200_STATECHANGE(rmesa
, set
);
2007 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] |= R200_STIPPLE_ENABLE
;
2009 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] &= ~R200_STIPPLE_ENABLE
;
2013 case GL_RESCALE_NORMAL_EXT
: {
2014 GLboolean tmp
= ctx
->_NeedEyeCoords
? state
: !state
;
2015 R200_STATECHANGE( rmesa
, tcl
);
2017 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] |= R200_RESCALE_NORMALS
;
2019 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] &= ~R200_RESCALE_NORMALS
;
2024 case GL_SCISSOR_TEST
:
2025 radeon_firevertices(&rmesa
->radeon
);
2026 rmesa
->radeon
.state
.scissor
.enabled
= state
;
2027 radeonUpdateScissor( ctx
);
2030 case GL_STENCIL_TEST
:
2032 GLboolean hw_stencil
= GL_FALSE
;
2033 if (ctx
->DrawBuffer
) {
2034 struct radeon_renderbuffer
*rrbStencil
2035 = radeon_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_STENCIL
);
2036 hw_stencil
= (rrbStencil
&& rrbStencil
->bo
);
2040 R200_STATECHANGE( rmesa
, ctx
);
2042 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= R200_STENCIL_ENABLE
;
2044 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~R200_STENCIL_ENABLE
;
2047 FALLBACK( rmesa
, R200_FALLBACK_STENCIL
, state
);
2052 case GL_TEXTURE_GEN_Q
:
2053 case GL_TEXTURE_GEN_R
:
2054 case GL_TEXTURE_GEN_S
:
2055 case GL_TEXTURE_GEN_T
:
2056 /* Picked up in r200UpdateTextureState.
2058 rmesa
->recheck_texgen
[ctx
->Texture
.CurrentUnit
] = GL_TRUE
;
2061 case GL_COLOR_SUM_EXT
:
2062 r200UpdateSpecular ( ctx
);
2065 case GL_VERTEX_PROGRAM_ARB
:
2068 rmesa
->curr_vp_hw
= NULL
;
2069 R200_STATECHANGE( rmesa
, vap
);
2070 rmesa
->hw
.vap
.cmd
[VAP_SE_VAP_CNTL
] &= ~R200_VAP_PROG_VTX_SHADER_ENABLE
;
2071 /* mark all tcl atoms (tcl vector state got overwritten) dirty
2072 not sure about tcl scalar state - we need at least grd
2073 with vert progs too.
2074 ucp looks like it doesn't get overwritten (may even work
2075 with vp for pos-invariant progs if we're lucky) */
2076 R200_STATECHANGE( rmesa
, mtl
[0] );
2077 R200_STATECHANGE( rmesa
, mtl
[1] );
2078 R200_STATECHANGE( rmesa
, fog
);
2079 R200_STATECHANGE( rmesa
, glt
);
2080 R200_STATECHANGE( rmesa
, eye
);
2081 for (i
= R200_MTX_MV
; i
<= R200_MTX_TEX5
; i
++) {
2082 R200_STATECHANGE( rmesa
, mat
[i
] );
2084 for (i
= 0 ; i
< 8; i
++) {
2085 R200_STATECHANGE( rmesa
, lit
[i
] );
2087 R200_STATECHANGE( rmesa
, tcl
);
2088 for (i
= 0; i
<= ctx
->Const
.MaxClipPlanes
; i
++) {
2089 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << i
)) {
2090 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= (R200_UCP_ENABLE_0
<< i
);
2093 rmesa->hw.tcl.cmd[TCL_UCP_VERT_BLEND_CTL] &= ~(R200_UCP_ENABLE_0 << i);
2096 /* ugly. Need to call everything which might change compsel. */
2097 r200UpdateSpecular( ctx
);
2099 /* shouldn't be necessary, as it's picked up anyway in r200ValidateState (_NEW_PROGRAM),
2100 but without it doom3 locks up at always the same places. Why? */
2101 /* FIXME: This can (and should) be replaced by a call to the TCL_STATE_FLUSH reg before
2102 accessing VAP_SE_VAP_CNTL. Requires drm changes (done). Remove after some time... */
2103 r200UpdateTextureState( ctx
);
2104 /* if we call r200UpdateTextureState we need the code below because we are calling it with
2105 non-current derived enabled values which may revert the state atoms for frag progs even when
2106 they already got disabled... ugh
2107 Should really figure out why we need to call r200UpdateTextureState in the first place */
2109 for (unit
= 0; unit
< R200_MAX_TEXTURE_UNITS
; unit
++) {
2110 R200_STATECHANGE( rmesa
, pix
[unit
] );
2111 R200_STATECHANGE( rmesa
, tex
[unit
] );
2112 rmesa
->hw
.tex
[unit
].cmd
[TEX_PP_TXFORMAT
] &=
2113 ~(R200_TXFORMAT_ST_ROUTE_MASK
| R200_TXFORMAT_LOOKUP_DISABLE
);
2114 rmesa
->hw
.tex
[unit
].cmd
[TEX_PP_TXFORMAT
] |= unit
<< R200_TXFORMAT_ST_ROUTE_SHIFT
;
2115 /* need to guard this with drmSupportsFragmentShader? Should never get here if
2116 we don't announce ATI_fs, right? */
2117 rmesa
->hw
.tex
[unit
].cmd
[TEX_PP_TXMULTI_CTL
] = 0;
2119 R200_STATECHANGE( rmesa
, cst
);
2120 R200_STATECHANGE( rmesa
, tf
);
2121 rmesa
->hw
.cst
.cmd
[CST_PP_CNTL_X
] = 0;
2125 /* picked up later */
2127 /* call functions which change hw state based on ARB_vp enabled or not. */
2128 r200PointParameter( ctx
, GL_POINT_DISTANCE_ATTENUATION
, NULL
);
2129 r200Fogfv( ctx
, GL_FOG_COORD_SRC
, NULL
);
2132 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
2133 r200PointParameter( ctx
, GL_POINT_DISTANCE_ATTENUATION
, NULL
);
2136 case GL_FRAGMENT_SHADER_ATI
:
2138 /* restore normal tex env colors and make sure tex env combine will get updated
2139 mark env atoms dirty (as their data was overwritten by afs even
2140 if they didn't change) and restore tex coord routing */
2142 for (unit
= 0; unit
< R200_MAX_TEXTURE_UNITS
; unit
++) {
2143 R200_STATECHANGE( rmesa
, pix
[unit
] );
2144 R200_STATECHANGE( rmesa
, tex
[unit
] );
2145 rmesa
->hw
.tex
[unit
].cmd
[TEX_PP_TXFORMAT
] &=
2146 ~(R200_TXFORMAT_ST_ROUTE_MASK
| R200_TXFORMAT_LOOKUP_DISABLE
);
2147 rmesa
->hw
.tex
[unit
].cmd
[TEX_PP_TXFORMAT
] |= unit
<< R200_TXFORMAT_ST_ROUTE_SHIFT
;
2148 /* need to guard this with drmSupportsFragmentShader? Should never get here if
2149 we don't announce ATI_fs, right? */
2150 rmesa
->hw
.tex
[unit
].cmd
[TEX_PP_TXMULTI_CTL
] = 0;
2152 R200_STATECHANGE( rmesa
, cst
);
2153 R200_STATECHANGE( rmesa
, tf
);
2154 rmesa
->hw
.cst
.cmd
[CST_PP_CNTL_X
] = 0;
2157 /* need to mark this dirty as pix/tf atoms have overwritten the data
2158 even if the data in the atoms didn't change */
2159 R200_STATECHANGE( rmesa
, atf
);
2160 R200_STATECHANGE( rmesa
, afs
[1] );
2161 /* everything else picked up in r200UpdateTextureState hopefully */
2170 void r200LightingSpaceChange( GLcontext
*ctx
)
2172 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
2175 if (R200_DEBUG
& RADEON_STATE
)
2176 fprintf(stderr
, "%s %d BEFORE %x\n", __FUNCTION__
, ctx
->_NeedEyeCoords
,
2177 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
]);
2179 if (ctx
->_NeedEyeCoords
)
2180 tmp
= ctx
->Transform
.RescaleNormals
;
2182 tmp
= !ctx
->Transform
.RescaleNormals
;
2184 R200_STATECHANGE( rmesa
, tcl
);
2186 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] |= R200_RESCALE_NORMALS
;
2188 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
] &= ~R200_RESCALE_NORMALS
;
2191 if (R200_DEBUG
& RADEON_STATE
)
2192 fprintf(stderr
, "%s %d AFTER %x\n", __FUNCTION__
, ctx
->_NeedEyeCoords
,
2193 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL_0
]);
2196 /* =============================================================
2197 * Deferred state management - matrices, textures, other?
2203 static void upload_matrix( r200ContextPtr rmesa
, GLfloat
*src
, int idx
)
2205 float *dest
= ((float *)R200_DB_STATE( mat
[idx
] ))+MAT_ELT_0
;
2209 for (i
= 0 ; i
< 4 ; i
++) {
2213 *dest
++ = src
[i
+12];
2216 R200_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mat
[idx
] );
2219 static void upload_matrix_t( r200ContextPtr rmesa
, const GLfloat
*src
, int idx
)
2221 float *dest
= ((float *)R200_DB_STATE( mat
[idx
] ))+MAT_ELT_0
;
2222 memcpy(dest
, src
, 16*sizeof(float));
2223 R200_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mat
[idx
] );
2227 static void update_texturematrix( GLcontext
*ctx
)
2229 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
2230 GLuint tpc
= rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_0
];
2231 GLuint compsel
= rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
];
2234 if (R200_DEBUG
& RADEON_STATE
)
2235 fprintf(stderr
, "%s before COMPSEL: %x\n", __FUNCTION__
,
2236 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
]);
2238 rmesa
->TexMatEnabled
= 0;
2239 rmesa
->TexMatCompSel
= 0;
2241 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2242 if (!ctx
->Texture
.Unit
[unit
]._ReallyEnabled
)
2245 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
) {
2246 rmesa
->TexMatEnabled
|= (R200_TEXGEN_TEXMAT_0_ENABLE
|
2247 R200_TEXMAT_0_ENABLE
) << unit
;
2249 rmesa
->TexMatCompSel
|= R200_OUTPUT_TEX_0
<< unit
;
2251 if (rmesa
->TexGenEnabled
& (R200_TEXMAT_0_ENABLE
<< unit
)) {
2252 /* Need to preconcatenate any active texgen
2253 * obj/eyeplane matrices:
2255 _math_matrix_mul_matrix( &rmesa
->tmpmat
,
2256 ctx
->TextureMatrixStack
[unit
].Top
,
2257 &rmesa
->TexGenMatrix
[unit
] );
2258 upload_matrix( rmesa
, rmesa
->tmpmat
.m
, R200_MTX_TEX0
+unit
);
2261 upload_matrix( rmesa
, ctx
->TextureMatrixStack
[unit
].Top
->m
,
2262 R200_MTX_TEX0
+unit
);
2265 else if (rmesa
->TexGenEnabled
& (R200_TEXMAT_0_ENABLE
<< unit
)) {
2266 upload_matrix( rmesa
, rmesa
->TexGenMatrix
[unit
].m
,
2267 R200_MTX_TEX0
+unit
);
2271 tpc
= (rmesa
->TexMatEnabled
| rmesa
->TexGenEnabled
);
2272 if (tpc
!= rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_0
]) {
2273 R200_STATECHANGE(rmesa
, tcg
);
2274 rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_0
] = tpc
;
2277 compsel
&= ~R200_OUTPUT_TEX_MASK
;
2278 compsel
|= rmesa
->TexMatCompSel
| rmesa
->TexGenCompSel
;
2279 if (compsel
!= rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
]) {
2280 R200_STATECHANGE(rmesa
, vtx
);
2281 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_COMPSEL
] = compsel
;
2285 static GLboolean
r200ValidateBuffers(GLcontext
*ctx
)
2287 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
2288 struct radeon_renderbuffer
*rrb
;
2289 struct radeon_dma_bo
*dma_bo
;
2292 if (RADEON_DEBUG
& RADEON_IOCTL
)
2293 fprintf(stderr
, "%s\n", __FUNCTION__
);
2294 radeon_cs_space_reset_bos(rmesa
->radeon
.cmdbuf
.cs
);
2296 rrb
= radeon_get_colorbuffer(&rmesa
->radeon
);
2298 if (rrb
&& rrb
->bo
) {
2299 radeon_cs_space_add_persistent_bo(rmesa
->radeon
.cmdbuf
.cs
, rrb
->bo
,
2300 0, RADEON_GEM_DOMAIN_VRAM
);
2304 rrb
= radeon_get_depthbuffer(&rmesa
->radeon
);
2306 if (rrb
&& rrb
->bo
) {
2307 radeon_cs_space_add_persistent_bo(rmesa
->radeon
.cmdbuf
.cs
, rrb
->bo
,
2308 0, RADEON_GEM_DOMAIN_VRAM
);
2311 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; ++i
) {
2314 if (!ctx
->Texture
.Unit
[i
]._ReallyEnabled
)
2317 t
= radeon_tex_obj(ctx
->Texture
.Unit
[i
]._Current
);
2318 if (t
->image_override
&& t
->bo
)
2319 radeon_cs_space_add_persistent_bo(rmesa
->radeon
.cmdbuf
.cs
, t
->bo
,
2320 RADEON_GEM_DOMAIN_GTT
| RADEON_GEM_DOMAIN_VRAM
, 0);
2322 radeon_cs_space_add_persistent_bo(rmesa
->radeon
.cmdbuf
.cs
, t
->mt
->bo
,
2323 RADEON_GEM_DOMAIN_GTT
| RADEON_GEM_DOMAIN_VRAM
, 0);
2326 dma_bo
= first_elem(&rmesa
->radeon
.dma
.reserved
);
2328 ret
= radeon_cs_space_check_with_bo(rmesa
->radeon
.cmdbuf
.cs
, dma_bo
->bo
, RADEON_GEM_DOMAIN_GTT
, 0);
2335 GLboolean
r200ValidateState( GLcontext
*ctx
)
2337 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
2338 GLuint new_state
= rmesa
->radeon
.NewGLState
;
2340 if (new_state
& _NEW_BUFFERS
) {
2341 _mesa_update_framebuffer(ctx
);
2342 /* this updates the DrawBuffer's Width/Height if it's a FBO */
2343 _mesa_update_draw_buffer_bounds(ctx
);
2345 R200_STATECHANGE(rmesa
, ctx
);
2348 if (new_state
& (_NEW_TEXTURE
| _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
)) {
2349 r200UpdateTextureState( ctx
);
2350 new_state
|= rmesa
->radeon
.NewGLState
; /* may add TEXTURE_MATRIX */
2351 r200UpdateLocalViewer( ctx
);
2354 /* we need to do a space check here */
2355 if (!r200ValidateBuffers(ctx
))
2358 /* FIXME: don't really need most of these when vertex progs are enabled */
2360 /* Need an event driven matrix update?
2362 if (new_state
& (_NEW_MODELVIEW
|_NEW_PROJECTION
))
2363 upload_matrix( rmesa
, ctx
->_ModelProjectMatrix
.m
, R200_MTX_MVP
);
2365 /* Need these for lighting (shouldn't upload otherwise)
2367 if (new_state
& (_NEW_MODELVIEW
)) {
2368 upload_matrix( rmesa
, ctx
->ModelviewMatrixStack
.Top
->m
, R200_MTX_MV
);
2369 upload_matrix_t( rmesa
, ctx
->ModelviewMatrixStack
.Top
->inv
, R200_MTX_IMV
);
2372 /* Does this need to be triggered on eg. modelview for
2373 * texgen-derived objplane/eyeplane matrices?
2375 if (new_state
& (_NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
)) {
2376 update_texturematrix( ctx
);
2379 if (new_state
& (_NEW_LIGHT
|_NEW_MODELVIEW
|_MESA_NEW_NEED_EYE_COORDS
)) {
2380 update_light( ctx
);
2383 /* emit all active clip planes if projection matrix changes.
2385 if (new_state
& (_NEW_PROJECTION
)) {
2386 if (ctx
->Transform
.ClipPlanesEnabled
)
2387 r200UpdateClipPlanes( ctx
);
2390 if (new_state
& (_NEW_PROGRAM
|
2391 _NEW_PROGRAM_CONSTANTS
|
2392 /* need to test for pretty much anything due to possible parameter bindings */
2393 _NEW_MODELVIEW
|_NEW_PROJECTION
|_NEW_TRANSFORM
|
2394 _NEW_LIGHT
|_NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
|
2395 _NEW_FOG
|_NEW_POINT
|_NEW_TRACK_MATRIX
)) {
2396 if (ctx
->VertexProgram
._Enabled
) {
2397 r200SetupVertexProg( ctx
);
2399 else TCL_FALLBACK(ctx
, R200_TCL_FALLBACK_VERTEX_PROGRAM
, 0);
2402 rmesa
->radeon
.NewGLState
= 0;
2407 static void r200InvalidateState( GLcontext
*ctx
, GLuint new_state
)
2409 _swrast_InvalidateState( ctx
, new_state
);
2410 _swsetup_InvalidateState( ctx
, new_state
);
2411 _vbo_InvalidateState( ctx
, new_state
);
2412 _tnl_InvalidateState( ctx
, new_state
);
2413 _ae_invalidate_state( ctx
, new_state
);
2414 R200_CONTEXT(ctx
)->radeon
.NewGLState
|= new_state
;
2417 /* A hack. The r200 can actually cope just fine with materials
2418 * between begin/ends, so fix this.
2419 * Should map to inputs just like the generic vertex arrays for vertex progs.
2420 * In theory there could still be too many and we'd still need a fallback.
2422 static GLboolean
check_material( GLcontext
*ctx
)
2424 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
2427 for (i
= _TNL_ATTRIB_MAT_FRONT_AMBIENT
;
2428 i
< _TNL_ATTRIB_MAT_BACK_INDEXES
;
2430 if (tnl
->vb
.AttribPtr
[i
] &&
2431 tnl
->vb
.AttribPtr
[i
]->stride
)
2437 static void r200WrapRunPipeline( GLcontext
*ctx
)
2439 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
2440 GLboolean has_material
;
2443 fprintf(stderr
, "%s, newstate: %x\n", __FUNCTION__
, rmesa
->radeon
.NewGLState
);
2447 if (rmesa
->radeon
.NewGLState
)
2448 if (!r200ValidateState( ctx
))
2449 FALLBACK(rmesa
, RADEON_FALLBACK_TEXTURE
, GL_TRUE
);
2451 has_material
= !ctx
->VertexProgram
._Enabled
&& ctx
->Light
.Enabled
&& check_material( ctx
);
2454 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_MATERIAL
, GL_TRUE
);
2457 /* Run the pipeline.
2459 _tnl_run_pipeline( ctx
);
2462 TCL_FALLBACK( ctx
, R200_TCL_FALLBACK_MATERIAL
, GL_FALSE
);
2467 static void r200PolygonStipple( GLcontext
*ctx
, const GLubyte
*mask
)
2469 r200ContextPtr r200
= R200_CONTEXT(ctx
);
2472 radeon_firevertices(&r200
->radeon
);
2474 radeon_print(RADEON_STATE
, RADEON_TRACE
,
2475 "%s(%p) first 32 bits are %x.\n",
2480 R200_STATECHANGE(r200
, stp
);
2482 /* Must flip pattern upside down.
2484 for ( i
= 31 ; i
>= 0; i
--) {
2485 r200
->hw
.stp
.cmd
[3 + i
] = ((GLuint
*) mask
)[i
];
2488 /* Initialize the driver's state functions.
2490 void r200InitStateFuncs( struct dd_function_table
*functions
)
2492 functions
->UpdateState
= r200InvalidateState
;
2493 functions
->LightingSpaceChange
= r200LightingSpaceChange
;
2495 functions
->DrawBuffer
= radeonDrawBuffer
;
2496 functions
->ReadBuffer
= radeonReadBuffer
;
2498 functions
->AlphaFunc
= r200AlphaFunc
;
2499 functions
->BlendColor
= r200BlendColor
;
2500 functions
->BlendEquationSeparate
= r200BlendEquationSeparate
;
2501 functions
->BlendFuncSeparate
= r200BlendFuncSeparate
;
2502 functions
->ClearColor
= r200ClearColor
;
2503 functions
->ClearDepth
= r200ClearDepth
;
2504 functions
->ClearIndex
= NULL
;
2505 functions
->ClearStencil
= r200ClearStencil
;
2506 functions
->ClipPlane
= r200ClipPlane
;
2507 functions
->ColorMask
= r200ColorMask
;
2508 functions
->CullFace
= r200CullFace
;
2509 functions
->DepthFunc
= r200DepthFunc
;
2510 functions
->DepthMask
= r200DepthMask
;
2511 functions
->DepthRange
= r200DepthRange
;
2512 functions
->Enable
= r200Enable
;
2513 functions
->Fogfv
= r200Fogfv
;
2514 functions
->FrontFace
= r200FrontFace
;
2515 functions
->Hint
= NULL
;
2516 functions
->IndexMask
= NULL
;
2517 functions
->LightModelfv
= r200LightModelfv
;
2518 functions
->Lightfv
= r200Lightfv
;
2519 functions
->LineStipple
= r200LineStipple
;
2520 functions
->LineWidth
= r200LineWidth
;
2521 functions
->LogicOpcode
= r200LogicOpCode
;
2522 functions
->PolygonMode
= r200PolygonMode
;
2523 functions
->PolygonOffset
= r200PolygonOffset
;
2524 functions
->PolygonStipple
= r200PolygonStipple
;
2525 functions
->PointParameterfv
= r200PointParameter
;
2526 functions
->PointSize
= r200PointSize
;
2527 functions
->RenderMode
= r200RenderMode
;
2528 functions
->Scissor
= radeonScissor
;
2529 functions
->ShadeModel
= r200ShadeModel
;
2530 functions
->StencilFuncSeparate
= r200StencilFuncSeparate
;
2531 functions
->StencilMaskSeparate
= r200StencilMaskSeparate
;
2532 functions
->StencilOpSeparate
= r200StencilOpSeparate
;
2533 functions
->Viewport
= r200Viewport
;
2537 void r200InitTnlFuncs( GLcontext
*ctx
)
2539 TNL_CONTEXT(ctx
)->Driver
.NotifyMaterialChange
= r200UpdateMaterial
;
2540 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= r200WrapRunPipeline
;