1 /* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_state.c,v 1.8 2002/12/16 16:18:58 dawes Exp $ */
2 /**************************************************************************
4 Copyright 2000, 2001 VA Linux Systems Inc., Fremont, California.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Gareth Hughes <gareth@valinux.com>
33 * Keith Whitwell <keith@tungstengraphics.com>
38 #include "api_arrayelt.h"
44 #include "swrast/swrast.h"
45 #include "array_cache/acache.h"
47 #include "tnl/t_pipeline.h"
48 #include "main/light.h"
49 #include "swrast_setup/swrast_setup.h"
51 #include "radeon_context.h"
52 #include "radeon_ioctl.h"
53 #include "radeon_state.h"
54 #include "radeon_tcl.h"
55 #include "radeon_tex.h"
56 #include "radeon_swtcl.h"
57 #include "radeon_vtxfmt.h"
59 /* =============================================================
63 static void radeonAlphaFunc( GLcontext
*ctx
, GLenum func
, GLfloat ref
)
65 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
66 int pp_misc
= rmesa
->hw
.ctx
.cmd
[CTX_PP_MISC
];
69 CLAMPED_FLOAT_TO_UBYTE(refByte
, ref
);
71 RADEON_STATECHANGE( rmesa
, ctx
);
73 pp_misc
&= ~(RADEON_ALPHA_TEST_OP_MASK
| RADEON_REF_ALPHA_MASK
);
74 pp_misc
|= (refByte
& RADEON_REF_ALPHA_MASK
);
78 pp_misc
|= RADEON_ALPHA_TEST_FAIL
;
81 pp_misc
|= RADEON_ALPHA_TEST_LESS
;
84 pp_misc
|= RADEON_ALPHA_TEST_EQUAL
;
87 pp_misc
|= RADEON_ALPHA_TEST_LEQUAL
;
90 pp_misc
|= RADEON_ALPHA_TEST_GREATER
;
93 pp_misc
|= RADEON_ALPHA_TEST_NEQUAL
;
96 pp_misc
|= RADEON_ALPHA_TEST_GEQUAL
;
99 pp_misc
|= RADEON_ALPHA_TEST_PASS
;
103 rmesa
->hw
.ctx
.cmd
[CTX_PP_MISC
] = pp_misc
;
106 static void radeonBlendEquationSeparate( GLcontext
*ctx
,
107 GLenum modeRGB
, GLenum modeA
)
109 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
110 GLuint b
= rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] & ~RADEON_COMB_FCN_MASK
;
111 GLboolean fallback
= GL_FALSE
;
113 assert( modeRGB
== modeA
);
118 b
|= RADEON_COMB_FCN_ADD_CLAMP
;
121 case GL_FUNC_SUBTRACT
:
122 b
|= RADEON_COMB_FCN_SUB_CLAMP
;
126 if (ctx
->Color
.BlendEnabled
)
129 b
|= RADEON_COMB_FCN_ADD_CLAMP
;
133 FALLBACK( rmesa
, RADEON_FALLBACK_BLEND_EQ
, fallback
);
135 RADEON_STATECHANGE( rmesa
, ctx
);
136 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = b
;
137 if ( ctx
->Color
._LogicOpEnabled
) {
138 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_ROP_ENABLE
;
140 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_ROP_ENABLE
;
145 static void radeonBlendFuncSeparate( GLcontext
*ctx
,
146 GLenum sfactorRGB
, GLenum dfactorRGB
,
147 GLenum sfactorA
, GLenum dfactorA
)
149 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
150 GLuint b
= rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] &
151 ~(RADEON_SRC_BLEND_MASK
| RADEON_DST_BLEND_MASK
);
152 GLboolean fallback
= GL_FALSE
;
154 switch ( ctx
->Color
.BlendSrcRGB
) {
156 b
|= RADEON_SRC_BLEND_GL_ZERO
;
159 b
|= RADEON_SRC_BLEND_GL_ONE
;
162 b
|= RADEON_SRC_BLEND_GL_DST_COLOR
;
164 case GL_ONE_MINUS_DST_COLOR
:
165 b
|= RADEON_SRC_BLEND_GL_ONE_MINUS_DST_COLOR
;
168 b
|= RADEON_SRC_BLEND_GL_SRC_COLOR
;
170 case GL_ONE_MINUS_SRC_COLOR
:
171 b
|= RADEON_SRC_BLEND_GL_ONE_MINUS_SRC_COLOR
;
174 b
|= RADEON_SRC_BLEND_GL_SRC_ALPHA
;
176 case GL_ONE_MINUS_SRC_ALPHA
:
177 b
|= RADEON_SRC_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
180 b
|= RADEON_SRC_BLEND_GL_DST_ALPHA
;
182 case GL_ONE_MINUS_DST_ALPHA
:
183 b
|= RADEON_SRC_BLEND_GL_ONE_MINUS_DST_ALPHA
;
185 case GL_SRC_ALPHA_SATURATE
:
186 b
|= RADEON_SRC_BLEND_GL_SRC_ALPHA_SATURATE
;
188 case GL_CONSTANT_COLOR
:
189 case GL_ONE_MINUS_CONSTANT_COLOR
:
190 case GL_CONSTANT_ALPHA
:
191 case GL_ONE_MINUS_CONSTANT_ALPHA
:
192 if (ctx
->Color
.BlendEnabled
)
195 b
|= RADEON_SRC_BLEND_GL_ONE
;
201 switch ( ctx
->Color
.BlendDstRGB
) {
203 b
|= RADEON_DST_BLEND_GL_ZERO
;
206 b
|= RADEON_DST_BLEND_GL_ONE
;
209 b
|= RADEON_DST_BLEND_GL_SRC_COLOR
;
211 case GL_ONE_MINUS_SRC_COLOR
:
212 b
|= RADEON_DST_BLEND_GL_ONE_MINUS_SRC_COLOR
;
215 b
|= RADEON_DST_BLEND_GL_SRC_ALPHA
;
217 case GL_ONE_MINUS_SRC_ALPHA
:
218 b
|= RADEON_DST_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
221 b
|= RADEON_DST_BLEND_GL_DST_COLOR
;
223 case GL_ONE_MINUS_DST_COLOR
:
224 b
|= RADEON_DST_BLEND_GL_ONE_MINUS_DST_COLOR
;
227 b
|= RADEON_DST_BLEND_GL_DST_ALPHA
;
229 case GL_ONE_MINUS_DST_ALPHA
:
230 b
|= RADEON_DST_BLEND_GL_ONE_MINUS_DST_ALPHA
;
232 case GL_CONSTANT_COLOR
:
233 case GL_ONE_MINUS_CONSTANT_COLOR
:
234 case GL_CONSTANT_ALPHA
:
235 case GL_ONE_MINUS_CONSTANT_ALPHA
:
236 if (ctx
->Color
.BlendEnabled
)
239 b
|= RADEON_DST_BLEND_GL_ZERO
;
245 FALLBACK( rmesa
, RADEON_FALLBACK_BLEND_FUNC
, fallback
);
247 RADEON_STATECHANGE( rmesa
, ctx
);
248 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = b
;
253 /* =============================================================
257 static void radeonDepthFunc( GLcontext
*ctx
, GLenum func
)
259 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
261 RADEON_STATECHANGE( rmesa
, ctx
);
262 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~RADEON_Z_TEST_MASK
;
264 switch ( ctx
->Depth
.Func
) {
266 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_NEVER
;
269 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_LESS
;
272 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_EQUAL
;
275 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_LEQUAL
;
278 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_GREATER
;
281 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_NEQUAL
;
284 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_GEQUAL
;
287 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_ALWAYS
;
293 static void radeonDepthMask( GLcontext
*ctx
, GLboolean flag
)
295 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
296 RADEON_STATECHANGE( rmesa
, ctx
);
298 if ( ctx
->Depth
.Mask
) {
299 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_WRITE_ENABLE
;
301 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~RADEON_Z_WRITE_ENABLE
;
305 static void radeonClearDepth( GLcontext
*ctx
, GLclampd d
)
307 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
308 GLuint format
= (rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &
309 RADEON_DEPTH_FORMAT_MASK
);
312 case RADEON_DEPTH_FORMAT_16BIT_INT_Z
:
313 rmesa
->state
.depth
.clear
= d
* 0x0000ffff;
315 case RADEON_DEPTH_FORMAT_24BIT_INT_Z
:
316 rmesa
->state
.depth
.clear
= d
* 0x00ffffff;
322 /* =============================================================
327 static void radeonFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
329 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
330 union { int i
; float f
; } c
, d
;
333 c
.i
= rmesa
->hw
.fog
.cmd
[FOG_C
];
334 d
.i
= rmesa
->hw
.fog
.cmd
[FOG_D
];
338 if (!ctx
->Fog
.Enabled
)
340 RADEON_STATECHANGE(rmesa
, tcl
);
341 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~RADEON_TCL_FOG_MASK
;
342 switch (ctx
->Fog
.Mode
) {
344 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_TCL_FOG_LINEAR
;
345 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
350 c
.f
= ctx
->Fog
.End
/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
351 d
.f
= 1.0/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
355 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_TCL_FOG_EXP
;
357 d
.f
= ctx
->Fog
.Density
;
360 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_TCL_FOG_EXP2
;
362 d
.f
= -(ctx
->Fog
.Density
* ctx
->Fog
.Density
);
369 switch (ctx
->Fog
.Mode
) {
372 d
.f
= ctx
->Fog
.Density
;
376 d
.f
= -(ctx
->Fog
.Density
* ctx
->Fog
.Density
);
384 if (ctx
->Fog
.Mode
== GL_LINEAR
) {
385 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
389 c
.f
= ctx
->Fog
.End
/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
390 d
.f
= 1.0/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
395 RADEON_STATECHANGE( rmesa
, ctx
);
396 UNCLAMPED_FLOAT_TO_RGB_CHAN( col
, ctx
->Fog
.Color
);
397 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] =
398 radeonPackColor( 4, col
[0], col
[1], col
[2], 0 );
400 case GL_FOG_COORDINATE_SOURCE_EXT
:
408 if (c
.i
!= rmesa
->hw
.fog
.cmd
[FOG_C
] || d
.i
!= rmesa
->hw
.fog
.cmd
[FOG_D
]) {
409 RADEON_STATECHANGE( rmesa
, fog
);
410 rmesa
->hw
.fog
.cmd
[FOG_C
] = c
.i
;
411 rmesa
->hw
.fog
.cmd
[FOG_D
] = d
.i
;
416 /* =============================================================
421 static GLboolean
intersect_rect( XF86DRIClipRectPtr out
,
422 XF86DRIClipRectPtr a
,
423 XF86DRIClipRectPtr b
)
426 if ( b
->x1
> out
->x1
) out
->x1
= b
->x1
;
427 if ( b
->y1
> out
->y1
) out
->y1
= b
->y1
;
428 if ( b
->x2
< out
->x2
) out
->x2
= b
->x2
;
429 if ( b
->y2
< out
->y2
) out
->y2
= b
->y2
;
430 if ( out
->x1
>= out
->x2
) return GL_FALSE
;
431 if ( out
->y1
>= out
->y2
) return GL_FALSE
;
436 void radeonRecalcScissorRects( radeonContextPtr rmesa
)
438 XF86DRIClipRectPtr out
;
441 /* Grow cliprect store?
443 if (rmesa
->state
.scissor
.numAllocedClipRects
< rmesa
->numClipRects
) {
444 while (rmesa
->state
.scissor
.numAllocedClipRects
< rmesa
->numClipRects
) {
445 rmesa
->state
.scissor
.numAllocedClipRects
+= 1; /* zero case */
446 rmesa
->state
.scissor
.numAllocedClipRects
*= 2;
449 if (rmesa
->state
.scissor
.pClipRects
)
450 FREE(rmesa
->state
.scissor
.pClipRects
);
452 rmesa
->state
.scissor
.pClipRects
=
453 MALLOC( rmesa
->state
.scissor
.numAllocedClipRects
*
454 sizeof(XF86DRIClipRectRec
) );
456 if ( rmesa
->state
.scissor
.pClipRects
== NULL
) {
457 rmesa
->state
.scissor
.numAllocedClipRects
= 0;
462 out
= rmesa
->state
.scissor
.pClipRects
;
463 rmesa
->state
.scissor
.numClipRects
= 0;
465 for ( i
= 0 ; i
< rmesa
->numClipRects
; i
++ ) {
466 if ( intersect_rect( out
,
467 &rmesa
->pClipRects
[i
],
468 &rmesa
->state
.scissor
.rect
) ) {
469 rmesa
->state
.scissor
.numClipRects
++;
476 static void radeonUpdateScissor( GLcontext
*ctx
)
478 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
480 if ( rmesa
->dri
.drawable
) {
481 __DRIdrawablePrivate
*dPriv
= rmesa
->dri
.drawable
;
483 int x
= ctx
->Scissor
.X
;
484 int y
= dPriv
->h
- ctx
->Scissor
.Y
- ctx
->Scissor
.Height
;
485 int w
= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
- 1;
486 int h
= dPriv
->h
- ctx
->Scissor
.Y
- 1;
488 rmesa
->state
.scissor
.rect
.x1
= x
+ dPriv
->x
;
489 rmesa
->state
.scissor
.rect
.y1
= y
+ dPriv
->y
;
490 rmesa
->state
.scissor
.rect
.x2
= w
+ dPriv
->x
+ 1;
491 rmesa
->state
.scissor
.rect
.y2
= h
+ dPriv
->y
+ 1;
493 radeonRecalcScissorRects( rmesa
);
498 static void radeonScissor( GLcontext
*ctx
,
499 GLint x
, GLint y
, GLsizei w
, GLsizei h
)
501 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
503 if ( ctx
->Scissor
.Enabled
) {
504 RADEON_FIREVERTICES( rmesa
); /* don't pipeline cliprect changes */
505 radeonUpdateScissor( ctx
);
511 /* =============================================================
515 static void radeonCullFace( GLcontext
*ctx
, GLenum unused
)
517 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
518 GLuint s
= rmesa
->hw
.set
.cmd
[SET_SE_CNTL
];
519 GLuint t
= rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
];
521 s
|= RADEON_FFACE_SOLID
| RADEON_BFACE_SOLID
;
522 t
&= ~(RADEON_CULL_FRONT
| RADEON_CULL_BACK
);
524 if ( ctx
->Polygon
.CullFlag
) {
525 switch ( ctx
->Polygon
.CullFaceMode
) {
527 s
&= ~RADEON_FFACE_SOLID
;
528 t
|= RADEON_CULL_FRONT
;
531 s
&= ~RADEON_BFACE_SOLID
;
532 t
|= RADEON_CULL_BACK
;
534 case GL_FRONT_AND_BACK
:
535 s
&= ~(RADEON_FFACE_SOLID
| RADEON_BFACE_SOLID
);
536 t
|= (RADEON_CULL_FRONT
| RADEON_CULL_BACK
);
541 if ( rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] != s
) {
542 RADEON_STATECHANGE(rmesa
, set
);
543 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] = s
;
546 if ( rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] != t
) {
547 RADEON_STATECHANGE(rmesa
, tcl
);
548 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] = t
;
552 static void radeonFrontFace( GLcontext
*ctx
, GLenum mode
)
554 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
556 RADEON_STATECHANGE( rmesa
, set
);
557 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_FFACE_CULL_DIR_MASK
;
559 RADEON_STATECHANGE( rmesa
, tcl
);
560 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~RADEON_CULL_FRONT_IS_CCW
;
564 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_FFACE_CULL_CW
;
567 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_FFACE_CULL_CCW
;
568 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_CULL_FRONT_IS_CCW
;
574 /* =============================================================
577 static void radeonLineWidth( GLcontext
*ctx
, GLfloat widthf
)
579 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
581 RADEON_STATECHANGE( rmesa
, lin
);
582 RADEON_STATECHANGE( rmesa
, set
);
584 /* Line width is stored in U6.4 format.
586 rmesa
->hw
.lin
.cmd
[LIN_SE_LINE_WIDTH
] = (GLuint
)(widthf
* 16.0);
587 if ( widthf
> 1.0 ) {
588 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_WIDELINE_ENABLE
;
590 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_WIDELINE_ENABLE
;
594 static void radeonLineStipple( GLcontext
*ctx
, GLint factor
, GLushort pattern
)
596 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
598 RADEON_STATECHANGE( rmesa
, lin
);
599 rmesa
->hw
.lin
.cmd
[LIN_RE_LINE_PATTERN
] =
600 ((((GLuint
)factor
& 0xff) << 16) | ((GLuint
)pattern
));
604 /* =============================================================
607 static void radeonColorMask( GLcontext
*ctx
,
608 GLboolean r
, GLboolean g
,
609 GLboolean b
, GLboolean a
)
611 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
612 GLuint mask
= radeonPackColor( rmesa
->radeonScreen
->cpp
,
613 ctx
->Color
.ColorMask
[RCOMP
],
614 ctx
->Color
.ColorMask
[GCOMP
],
615 ctx
->Color
.ColorMask
[BCOMP
],
616 ctx
->Color
.ColorMask
[ACOMP
] );
618 if ( rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
] != mask
) {
619 RADEON_STATECHANGE( rmesa
, msk
);
620 rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
] = mask
;
625 /* =============================================================
629 static void radeonPolygonOffset( GLcontext
*ctx
,
630 GLfloat factor
, GLfloat units
)
632 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
633 GLfloat constant
= units
* rmesa
->state
.depth
.scale
;
635 RADEON_STATECHANGE( rmesa
, zbs
);
636 rmesa
->hw
.zbs
.cmd
[ZBS_SE_ZBIAS_FACTOR
] = *(GLuint
*)&factor
;
637 rmesa
->hw
.zbs
.cmd
[ZBS_SE_ZBIAS_CONSTANT
] = *(GLuint
*)&constant
;
640 static void radeonPolygonStipple( GLcontext
*ctx
, const GLubyte
*mask
)
642 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
644 drmRadeonStipple stipple
;
646 /* Must flip pattern upside down.
648 for ( i
= 0 ; i
< 32 ; i
++ ) {
649 rmesa
->state
.stipple
.mask
[31 - i
] = ((GLuint
*) mask
)[i
];
652 /* TODO: push this into cmd mechanism
654 RADEON_FIREVERTICES( rmesa
);
655 LOCK_HARDWARE( rmesa
);
657 /* FIXME: Use window x,y offsets into stipple RAM.
659 stipple
.mask
= rmesa
->state
.stipple
.mask
;
660 drmCommandWrite( rmesa
->dri
.fd
, DRM_RADEON_STIPPLE
,
661 &stipple
, sizeof(drmRadeonStipple
) );
662 UNLOCK_HARDWARE( rmesa
);
665 static void radeonPolygonMode( GLcontext
*ctx
, GLenum face
, GLenum mode
)
667 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
668 GLboolean flag
= (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
) != 0;
670 /* Can't generally do unfilled via tcl, but some good special
673 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_UNFILLED
, flag
);
674 if (rmesa
->TclFallback
) {
675 radeonChooseRenderState( ctx
);
676 radeonChooseVertexState( ctx
);
681 /* =============================================================
682 * Rendering attributes
684 * We really don't want to recalculate all this every time we bind a
685 * texture. These things shouldn't change all that often, so it makes
686 * sense to break them out of the core texture state update routines.
689 /* Examine lighting and texture state to determine if separate specular
692 static void radeonUpdateSpecular( GLcontext
*ctx
)
694 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
695 CARD32 p
= rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
];
697 RADEON_STATECHANGE( rmesa
, tcl
);
699 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] &= ~RADEON_TCL_COMPUTE_SPECULAR
;
700 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] &= ~RADEON_TCL_COMPUTE_DIFFUSE
;
701 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] &= ~RADEON_TCL_VTX_PK_SPEC
;
702 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] &= ~RADEON_TCL_VTX_PK_DIFFUSE
;
703 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_LIGHTING_ENABLE
;
705 p
&= ~RADEON_SPECULAR_ENABLE
;
707 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_DIFFUSE_SPECULAR_COMBINE
;
710 if (ctx
->Light
.Enabled
&&
711 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
) {
712 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] |= RADEON_TCL_COMPUTE_SPECULAR
;
713 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] |= RADEON_TCL_COMPUTE_DIFFUSE
;
714 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_SPEC
;
715 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_DIFFUSE
;
716 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_LIGHTING_ENABLE
;
717 p
|= RADEON_SPECULAR_ENABLE
;
718 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &=
719 ~RADEON_DIFFUSE_SPECULAR_COMBINE
;
721 else if (ctx
->Light
.Enabled
) {
722 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] |= RADEON_TCL_COMPUTE_DIFFUSE
;
723 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_DIFFUSE
;
724 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_LIGHTING_ENABLE
;
725 } else if (ctx
->Fog
.ColorSumEnabled
) {
726 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_SPEC
;
727 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_DIFFUSE
;
728 p
|= RADEON_SPECULAR_ENABLE
;
730 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_DIFFUSE
;
733 if (ctx
->Fog
.Enabled
) {
734 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] |= RADEON_TCL_COMPUTE_SPECULAR
;
735 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_SPEC
;
737 /* Bizzare: have to leave lighting enabled to get fog.
739 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_LIGHTING_ENABLE
;
742 if (NEED_SECONDARY_COLOR(ctx
)) {
743 assert( (p
& RADEON_SPECULAR_ENABLE
) != 0 );
745 assert( (p
& RADEON_SPECULAR_ENABLE
) == 0 );
748 if ( rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] != p
) {
749 RADEON_STATECHANGE( rmesa
, ctx
);
750 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] = p
;
753 /* Update vertex/render formats
755 if (rmesa
->TclFallback
) {
756 radeonChooseRenderState( ctx
);
757 radeonChooseVertexState( ctx
);
762 /* =============================================================
767 /* Update on colormaterial, material emmissive/ambient,
768 * lightmodel.globalambient
770 static void update_global_ambient( GLcontext
*ctx
)
772 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
773 float *fcmd
= (float *)RADEON_DB_STATE( glt
);
775 /* Need to do more if both emmissive & ambient are PREMULT:
777 if ((rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &
778 ((3 << RADEON_EMISSIVE_SOURCE_SHIFT
) |
779 (3 << RADEON_AMBIENT_SOURCE_SHIFT
))) == 0)
781 COPY_3V( &fcmd
[GLT_RED
],
782 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_EMISSION
]);
783 ACC_SCALE_3V( &fcmd
[GLT_RED
],
784 ctx
->Light
.Model
.Ambient
,
785 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
]);
789 COPY_3V( &fcmd
[GLT_RED
], ctx
->Light
.Model
.Ambient
);
792 RADEON_DB_STATECHANGE(rmesa
, &rmesa
->hw
.glt
);
795 /* Update on change to
799 * - colormaterial enabled
800 * - colormaterial bitmask
802 static void update_light_colors( GLcontext
*ctx
, GLuint p
)
804 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
806 /* fprintf(stderr, "%s\n", __FUNCTION__); */
809 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
810 float *fcmd
= (float *)RADEON_DB_STATE( lit
[p
] );
811 GLuint bitmask
= ctx
->Light
.ColorMaterialBitmask
;
812 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
814 COPY_4V( &fcmd
[LIT_AMBIENT_RED
], l
->Ambient
);
815 COPY_4V( &fcmd
[LIT_DIFFUSE_RED
], l
->Diffuse
);
816 COPY_4V( &fcmd
[LIT_SPECULAR_RED
], l
->Specular
);
818 if (!ctx
->Light
.ColorMaterialEnabled
)
821 if ((bitmask
& MAT_BIT_FRONT_AMBIENT
) == 0)
822 SELF_SCALE_3V( &fcmd
[LIT_AMBIENT_RED
], mat
[MAT_ATTRIB_FRONT_AMBIENT
] );
824 if ((bitmask
& MAT_BIT_FRONT_DIFFUSE
) == 0)
825 SELF_SCALE_3V( &fcmd
[LIT_DIFFUSE_RED
], mat
[MAT_ATTRIB_FRONT_DIFFUSE
] );
827 if ((bitmask
& MAT_BIT_FRONT_SPECULAR
) == 0)
828 SELF_SCALE_3V( &fcmd
[LIT_SPECULAR_RED
], mat
[MAT_ATTRIB_FRONT_SPECULAR
] );
830 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.lit
[p
] );
834 /* Also fallback for asym colormaterial mode in twoside lighting...
836 static void check_twoside_fallback( GLcontext
*ctx
)
838 GLboolean fallback
= GL_FALSE
;
841 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
) {
842 if (ctx
->Light
.ColorMaterialEnabled
&&
843 (ctx
->Light
.ColorMaterialBitmask
& BACK_MATERIAL_BITS
) !=
844 ((ctx
->Light
.ColorMaterialBitmask
& FRONT_MATERIAL_BITS
)<<1))
847 for (i
= MAT_ATTRIB_FRONT_AMBIENT
; i
< MAT_ATTRIB_FRONT_INDEXES
; i
+=2)
848 if (memcmp( ctx
->Light
.Material
.Attrib
[i
],
849 ctx
->Light
.Material
.Attrib
[i
+1],
850 sizeof(GLfloat
)*4) != 0) {
857 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_LIGHT_TWOSIDE
, fallback
);
861 static void radeonColorMaterial( GLcontext
*ctx
, GLenum face
, GLenum mode
)
863 if (ctx
->Light
.ColorMaterialEnabled
) {
864 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
865 GLuint light_model_ctl1
= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
];
866 GLuint mask
= ctx
->Light
.ColorMaterialBitmask
;
868 /* Default to PREMULT:
870 light_model_ctl1
&= ~((3 << RADEON_EMISSIVE_SOURCE_SHIFT
) |
871 (3 << RADEON_AMBIENT_SOURCE_SHIFT
) |
872 (3 << RADEON_DIFFUSE_SOURCE_SHIFT
) |
873 (3 << RADEON_SPECULAR_SOURCE_SHIFT
));
875 if (mask
& MAT_BIT_FRONT_EMISSION
) {
876 light_model_ctl1
|= (RADEON_LM_SOURCE_VERTEX_DIFFUSE
<<
877 RADEON_EMISSIVE_SOURCE_SHIFT
);
880 if (mask
& MAT_BIT_FRONT_AMBIENT
) {
881 light_model_ctl1
|= (RADEON_LM_SOURCE_VERTEX_DIFFUSE
<<
882 RADEON_AMBIENT_SOURCE_SHIFT
);
885 if (mask
& MAT_BIT_FRONT_DIFFUSE
) {
886 light_model_ctl1
|= (RADEON_LM_SOURCE_VERTEX_DIFFUSE
<<
887 RADEON_DIFFUSE_SOURCE_SHIFT
);
890 if (mask
& MAT_BIT_FRONT_SPECULAR
) {
891 light_model_ctl1
|= (RADEON_LM_SOURCE_VERTEX_DIFFUSE
<<
892 RADEON_SPECULAR_SOURCE_SHIFT
);
895 if (light_model_ctl1
!= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
]) {
898 RADEON_STATECHANGE( rmesa
, tcl
);
899 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] = light_model_ctl1
;
901 for (p
= 0 ; p
< MAX_LIGHTS
; p
++)
902 update_light_colors( ctx
, p
);
903 update_global_ambient( ctx
);
907 check_twoside_fallback( ctx
);
910 void radeonUpdateMaterial( GLcontext
*ctx
)
912 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
913 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
914 GLfloat
*fcmd
= (GLfloat
*)RADEON_DB_STATE( mtl
);
918 if (ctx
->Light
.ColorMaterialEnabled
)
919 mask
&= ~ctx
->Light
.ColorMaterialBitmask
;
921 if (RADEON_DEBUG
& DEBUG_STATE
)
922 fprintf(stderr
, "%s\n", __FUNCTION__
);
925 if (mask
& MAT_BIT_FRONT_EMISSION
) {
926 fcmd
[MTL_EMMISSIVE_RED
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][0];
927 fcmd
[MTL_EMMISSIVE_GREEN
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][1];
928 fcmd
[MTL_EMMISSIVE_BLUE
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][2];
929 fcmd
[MTL_EMMISSIVE_ALPHA
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][3];
931 if (mask
& MAT_BIT_FRONT_AMBIENT
) {
932 fcmd
[MTL_AMBIENT_RED
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][0];
933 fcmd
[MTL_AMBIENT_GREEN
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][1];
934 fcmd
[MTL_AMBIENT_BLUE
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][2];
935 fcmd
[MTL_AMBIENT_ALPHA
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][3];
937 if (mask
& MAT_BIT_FRONT_DIFFUSE
) {
938 fcmd
[MTL_DIFFUSE_RED
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][0];
939 fcmd
[MTL_DIFFUSE_GREEN
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][1];
940 fcmd
[MTL_DIFFUSE_BLUE
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][2];
941 fcmd
[MTL_DIFFUSE_ALPHA
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][3];
943 if (mask
& MAT_BIT_FRONT_SPECULAR
) {
944 fcmd
[MTL_SPECULAR_RED
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][0];
945 fcmd
[MTL_SPECULAR_GREEN
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][1];
946 fcmd
[MTL_SPECULAR_BLUE
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][2];
947 fcmd
[MTL_SPECULAR_ALPHA
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][3];
949 if (mask
& MAT_BIT_FRONT_SHININESS
) {
950 fcmd
[MTL_SHININESS
] = mat
[MAT_ATTRIB_FRONT_SHININESS
][0];
953 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mtl
);
955 for (p
= 0 ; p
< MAX_LIGHTS
; p
++)
956 update_light_colors( ctx
, p
);
958 check_twoside_fallback( ctx
);
959 update_global_ambient( ctx
);
964 * _MESA_NEW_NEED_EYE_COORDS
966 * Uses derived state from mesa:
975 * which are calculated in light.c and are correct for the current
976 * lighting space (model or eye), hence dependencies on _NEW_MODELVIEW
977 * and _MESA_NEW_NEED_EYE_COORDS.
979 static void update_light( GLcontext
*ctx
)
981 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
983 /* Have to check these, or have an automatic shortcircuit mechanism
984 * to remove noop statechanges. (Or just do a better job on the
988 GLuint tmp
= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
];
990 if (ctx
->_NeedEyeCoords
)
991 tmp
&= ~RADEON_LIGHT_IN_MODELSPACE
;
993 tmp
|= RADEON_LIGHT_IN_MODELSPACE
;
996 /* Leave this test disabled: (unexplained q3 lockup) (even with
999 if (tmp
!= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
])
1001 RADEON_STATECHANGE( rmesa
, tcl
);
1002 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] = tmp
;
1007 GLfloat
*fcmd
= (GLfloat
*)RADEON_DB_STATE( eye
);
1008 fcmd
[EYE_X
] = ctx
->_EyeZDir
[0];
1009 fcmd
[EYE_Y
] = ctx
->_EyeZDir
[1];
1010 fcmd
[EYE_Z
] = - ctx
->_EyeZDir
[2];
1011 fcmd
[EYE_RESCALE_FACTOR
] = ctx
->_ModelViewInvScale
;
1012 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.eye
);
1017 if (ctx
->Light
.Enabled
) {
1019 for (p
= 0 ; p
< MAX_LIGHTS
; p
++) {
1020 if (ctx
->Light
.Light
[p
].Enabled
) {
1021 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
1022 GLfloat
*fcmd
= (GLfloat
*)RADEON_DB_STATE( lit
[p
] );
1024 if (l
->EyePosition
[3] == 0.0) {
1025 COPY_3FV( &fcmd
[LIT_POSITION_X
], l
->_VP_inf_norm
);
1026 COPY_3FV( &fcmd
[LIT_DIRECTION_X
], l
->_h_inf_norm
);
1027 fcmd
[LIT_POSITION_W
] = 0;
1028 fcmd
[LIT_DIRECTION_W
] = 0;
1030 COPY_4V( &fcmd
[LIT_POSITION_X
], l
->_Position
);
1031 fcmd
[LIT_DIRECTION_X
] = -l
->_NormDirection
[0];
1032 fcmd
[LIT_DIRECTION_Y
] = -l
->_NormDirection
[1];
1033 fcmd
[LIT_DIRECTION_Z
] = -l
->_NormDirection
[2];
1034 fcmd
[LIT_DIRECTION_W
] = 0;
1037 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.lit
[p
] );
1043 static void radeonLightfv( GLcontext
*ctx
, GLenum light
,
1044 GLenum pname
, const GLfloat
*params
)
1046 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1047 GLint p
= light
- GL_LIGHT0
;
1048 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
1049 GLfloat
*fcmd
= (GLfloat
*)rmesa
->hw
.lit
[p
].cmd
;
1056 update_light_colors( ctx
, p
);
1059 case GL_SPOT_DIRECTION
:
1060 /* picked up in update_light */
1064 /* positions picked up in update_light, but can do flag here */
1066 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1068 /* FIXME: Set RANGE_ATTEN only when needed */
1070 flag
= RADEON_LIGHT_1_IS_LOCAL
;
1072 flag
= RADEON_LIGHT_0_IS_LOCAL
;
1074 RADEON_STATECHANGE(rmesa
, tcl
);
1075 if (l
->EyePosition
[3] != 0.0F
)
1076 rmesa
->hw
.tcl
.cmd
[idx
] |= flag
;
1078 rmesa
->hw
.tcl
.cmd
[idx
] &= ~flag
;
1082 case GL_SPOT_EXPONENT
:
1083 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1084 fcmd
[LIT_SPOT_EXPONENT
] = params
[0];
1087 case GL_SPOT_CUTOFF
: {
1088 GLuint flag
= (p
&1) ? RADEON_LIGHT_1_IS_SPOT
: RADEON_LIGHT_0_IS_SPOT
;
1089 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1091 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1092 fcmd
[LIT_SPOT_CUTOFF
] = l
->_CosCutoff
;
1094 RADEON_STATECHANGE(rmesa
, tcl
);
1095 if (l
->SpotCutoff
!= 180.0F
)
1096 rmesa
->hw
.tcl
.cmd
[idx
] |= flag
;
1098 rmesa
->hw
.tcl
.cmd
[idx
] &= ~flag
;
1103 case GL_CONSTANT_ATTENUATION
:
1104 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1105 fcmd
[LIT_ATTEN_CONST
] = params
[0];
1106 if ( params
[0] == 0.0 )
1107 fcmd
[LIT_ATTEN_CONST_INV
] = FLT_MAX
;
1109 fcmd
[LIT_ATTEN_CONST_INV
] = 1.0 / params
[0];
1111 case GL_LINEAR_ATTENUATION
:
1112 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1113 fcmd
[LIT_ATTEN_LINEAR
] = params
[0];
1115 case GL_QUADRATIC_ATTENUATION
:
1116 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1117 fcmd
[LIT_ATTEN_QUADRATIC
] = params
[0];
1123 /* Set RANGE_ATTEN only when needed */
1126 case GL_CONSTANT_ATTENUATION
:
1127 case GL_LINEAR_ATTENUATION
:
1128 case GL_QUADRATIC_ATTENUATION
:
1130 GLuint
*icmd
= (GLuint
*)RADEON_DB_STATE( tcl
);
1131 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1132 GLuint atten_flag
= ( p
&1 ) ? RADEON_LIGHT_1_ENABLE_RANGE_ATTEN
1133 : RADEON_LIGHT_0_ENABLE_RANGE_ATTEN
;
1134 GLuint atten_const_flag
= ( p
&1 ) ? RADEON_LIGHT_1_CONSTANT_RANGE_ATTEN
1135 : RADEON_LIGHT_0_CONSTANT_RANGE_ATTEN
;
1137 if ( l
->EyePosition
[3] == 0.0F
||
1138 ( ( fcmd
[LIT_ATTEN_CONST
] == 0.0 || fcmd
[LIT_ATTEN_CONST
] == 1.0 ) &&
1139 fcmd
[LIT_ATTEN_QUADRATIC
] == 0.0 && fcmd
[LIT_ATTEN_LINEAR
] == 0.0 ) ) {
1140 /* Disable attenuation */
1141 icmd
[idx
] &= ~atten_flag
;
1143 if ( fcmd
[LIT_ATTEN_QUADRATIC
] == 0.0 && fcmd
[LIT_ATTEN_LINEAR
] == 0.0 ) {
1144 /* Enable only constant portion of attenuation calculation */
1145 icmd
[idx
] |= ( atten_flag
| atten_const_flag
);
1147 /* Enable full attenuation calculation */
1148 icmd
[idx
] &= ~atten_const_flag
;
1149 icmd
[idx
] |= atten_flag
;
1153 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.tcl
);
1164 static void radeonLightModelfv( GLcontext
*ctx
, GLenum pname
,
1165 const GLfloat
*param
)
1167 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1170 case GL_LIGHT_MODEL_AMBIENT
:
1171 update_global_ambient( ctx
);
1174 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
1175 RADEON_STATECHANGE( rmesa
, tcl
);
1176 if (ctx
->Light
.Model
.LocalViewer
)
1177 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_LOCAL_VIEWER
;
1179 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_LOCAL_VIEWER
;
1182 case GL_LIGHT_MODEL_TWO_SIDE
:
1183 RADEON_STATECHANGE( rmesa
, tcl
);
1184 if (ctx
->Light
.Model
.TwoSide
)
1185 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_LIGHT_TWOSIDE
;
1187 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~RADEON_LIGHT_TWOSIDE
;
1189 check_twoside_fallback( ctx
);
1191 if (rmesa
->TclFallback
) {
1192 radeonChooseRenderState( ctx
);
1193 radeonChooseVertexState( ctx
);
1197 case GL_LIGHT_MODEL_COLOR_CONTROL
:
1198 radeonUpdateSpecular(ctx
);
1206 static void radeonShadeModel( GLcontext
*ctx
, GLenum mode
)
1208 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1209 GLuint s
= rmesa
->hw
.set
.cmd
[SET_SE_CNTL
];
1211 s
&= ~(RADEON_DIFFUSE_SHADE_MASK
|
1212 RADEON_ALPHA_SHADE_MASK
|
1213 RADEON_SPECULAR_SHADE_MASK
|
1214 RADEON_FOG_SHADE_MASK
);
1218 s
|= (RADEON_DIFFUSE_SHADE_FLAT
|
1219 RADEON_ALPHA_SHADE_FLAT
|
1220 RADEON_SPECULAR_SHADE_FLAT
|
1221 RADEON_FOG_SHADE_FLAT
);
1224 s
|= (RADEON_DIFFUSE_SHADE_GOURAUD
|
1225 RADEON_ALPHA_SHADE_GOURAUD
|
1226 RADEON_SPECULAR_SHADE_GOURAUD
|
1227 RADEON_FOG_SHADE_GOURAUD
);
1233 if ( rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] != s
) {
1234 RADEON_STATECHANGE( rmesa
, set
);
1235 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] = s
;
1240 /* =============================================================
1244 static void radeonClipPlane( GLcontext
*ctx
, GLenum plane
, const GLfloat
*eq
)
1246 GLint p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
1247 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1248 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
1250 RADEON_STATECHANGE( rmesa
, ucp
[p
] );
1251 rmesa
->hw
.ucp
[p
].cmd
[UCP_X
] = ip
[0];
1252 rmesa
->hw
.ucp
[p
].cmd
[UCP_Y
] = ip
[1];
1253 rmesa
->hw
.ucp
[p
].cmd
[UCP_Z
] = ip
[2];
1254 rmesa
->hw
.ucp
[p
].cmd
[UCP_W
] = ip
[3];
1257 static void radeonUpdateClipPlanes( GLcontext
*ctx
)
1259 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1262 for (p
= 0; p
< ctx
->Const
.MaxClipPlanes
; p
++) {
1263 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
1264 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
1266 RADEON_STATECHANGE( rmesa
, ucp
[p
] );
1267 rmesa
->hw
.ucp
[p
].cmd
[UCP_X
] = ip
[0];
1268 rmesa
->hw
.ucp
[p
].cmd
[UCP_Y
] = ip
[1];
1269 rmesa
->hw
.ucp
[p
].cmd
[UCP_Z
] = ip
[2];
1270 rmesa
->hw
.ucp
[p
].cmd
[UCP_W
] = ip
[3];
1276 /* =============================================================
1280 static void radeonStencilFunc( GLcontext
*ctx
, GLenum func
,
1281 GLint ref
, GLuint mask
)
1283 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1284 GLuint refmask
= ((ctx
->Stencil
.Ref
[0] << RADEON_STENCIL_REF_SHIFT
) |
1285 (ctx
->Stencil
.ValueMask
[0] << RADEON_STENCIL_MASK_SHIFT
));
1287 RADEON_STATECHANGE( rmesa
, ctx
);
1288 RADEON_STATECHANGE( rmesa
, msk
);
1290 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~RADEON_STENCIL_TEST_MASK
;
1291 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] &= ~(RADEON_STENCIL_REF_MASK
|
1292 RADEON_STENCIL_VALUE_MASK
);
1294 switch ( ctx
->Stencil
.Function
[0] ) {
1296 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_NEVER
;
1299 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_LESS
;
1302 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_EQUAL
;
1305 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_LEQUAL
;
1308 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_GREATER
;
1311 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_NEQUAL
;
1314 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_GEQUAL
;
1317 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_ALWAYS
;
1321 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] |= refmask
;
1324 static void radeonStencilMask( GLcontext
*ctx
, GLuint mask
)
1326 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1328 RADEON_STATECHANGE( rmesa
, msk
);
1329 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] &= ~RADEON_STENCIL_WRITE_MASK
;
1330 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] |=
1331 (ctx
->Stencil
.WriteMask
[0] << RADEON_STENCIL_WRITEMASK_SHIFT
);
1334 static void radeonStencilOp( GLcontext
*ctx
, GLenum fail
,
1335 GLenum zfail
, GLenum zpass
)
1337 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1339 RADEON_STATECHANGE( rmesa
, ctx
);
1340 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~(RADEON_STENCIL_FAIL_MASK
|
1341 RADEON_STENCIL_ZFAIL_MASK
|
1342 RADEON_STENCIL_ZPASS_MASK
);
1344 switch ( ctx
->Stencil
.FailFunc
[0] ) {
1346 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_KEEP
;
1349 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_ZERO
;
1352 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_REPLACE
;
1355 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_INC
;
1358 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_DEC
;
1361 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_INVERT
;
1365 switch ( ctx
->Stencil
.ZFailFunc
[0] ) {
1367 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_KEEP
;
1370 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_ZERO
;
1373 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_REPLACE
;
1376 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_INC
;
1379 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_DEC
;
1382 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_INVERT
;
1386 switch ( ctx
->Stencil
.ZPassFunc
[0] ) {
1388 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_KEEP
;
1391 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_ZERO
;
1394 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_REPLACE
;
1397 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_INC
;
1400 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_DEC
;
1403 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_INVERT
;
1408 static void radeonClearStencil( GLcontext
*ctx
, GLint s
)
1410 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1412 rmesa
->state
.stencil
.clear
=
1413 ((GLuint
) ctx
->Stencil
.Clear
|
1414 (0xff << RADEON_STENCIL_MASK_SHIFT
) |
1415 (ctx
->Stencil
.WriteMask
[0] << RADEON_STENCIL_WRITEMASK_SHIFT
));
1419 /* =============================================================
1420 * Window position and viewport transformation
1424 * To correctly position primitives:
1426 #define SUBPIXEL_X 0.125
1427 #define SUBPIXEL_Y 0.125
1429 void radeonUpdateWindow( GLcontext
*ctx
)
1431 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1432 __DRIdrawablePrivate
*dPriv
= rmesa
->dri
.drawable
;
1433 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1434 GLfloat yoffset
= (GLfloat
)dPriv
->y
+ dPriv
->h
;
1435 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1437 GLfloat sx
= v
[MAT_SX
];
1438 GLfloat tx
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
1439 GLfloat sy
= - v
[MAT_SY
];
1440 GLfloat ty
= (- v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
1441 GLfloat sz
= v
[MAT_SZ
] * rmesa
->state
.depth
.scale
;
1442 GLfloat tz
= v
[MAT_TZ
] * rmesa
->state
.depth
.scale
;
1443 RADEON_FIREVERTICES( rmesa
);
1444 RADEON_STATECHANGE( rmesa
, vpt
);
1446 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XSCALE
] = *(GLuint
*)&sx
;
1447 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] = *(GLuint
*)&tx
;
1448 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YSCALE
] = *(GLuint
*)&sy
;
1449 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] = *(GLuint
*)&ty
;
1450 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_ZSCALE
] = *(GLuint
*)&sz
;
1451 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_ZOFFSET
] = *(GLuint
*)&tz
;
1456 static void radeonViewport( GLcontext
*ctx
, GLint x
, GLint y
,
1457 GLsizei width
, GLsizei height
)
1459 /* Don't pipeline viewport changes, conflict with window offset
1460 * setting below. Could apply deltas to rescue pipelined viewport
1461 * values, or keep the originals hanging around.
1463 RADEON_FIREVERTICES( RADEON_CONTEXT(ctx
) );
1464 radeonUpdateWindow( ctx
);
1467 static void radeonDepthRange( GLcontext
*ctx
, GLclampd nearval
,
1470 radeonUpdateWindow( ctx
);
1473 void radeonUpdateViewportOffset( GLcontext
*ctx
)
1475 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1476 __DRIdrawablePrivate
*dPriv
= rmesa
->dri
.drawable
;
1477 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1478 GLfloat yoffset
= (GLfloat
)dPriv
->y
+ dPriv
->h
;
1479 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1481 GLfloat tx
= v
[MAT_TX
] + xoffset
;
1482 GLfloat ty
= (- v
[MAT_TY
]) + yoffset
;
1484 if ( rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] != *(GLuint
*)&tx
||
1485 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] != *(GLuint
*)&ty
)
1487 /* Note: this should also modify whatever data the context reset
1490 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] = *(GLuint
*)&tx
;
1491 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] = *(GLuint
*)&ty
;
1493 /* update polygon stipple x/y screen offset */
1496 GLuint m
= rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
];
1498 m
&= ~(RADEON_STIPPLE_X_OFFSET_MASK
|
1499 RADEON_STIPPLE_Y_OFFSET_MASK
);
1501 /* add magic offsets, then invert */
1502 stx
= 31 - ((rmesa
->dri
.drawable
->x
- 1) & RADEON_STIPPLE_COORD_MASK
);
1503 sty
= 31 - ((rmesa
->dri
.drawable
->y
+ rmesa
->dri
.drawable
->h
- 1)
1504 & RADEON_STIPPLE_COORD_MASK
);
1506 m
|= ((stx
<< RADEON_STIPPLE_X_OFFSET_SHIFT
) |
1507 (sty
<< RADEON_STIPPLE_Y_OFFSET_SHIFT
));
1509 if ( rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
] != m
) {
1510 RADEON_STATECHANGE( rmesa
, msc
);
1511 rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
] = m
;
1516 radeonUpdateScissor( ctx
);
1521 /* =============================================================
1525 static void radeonClearColor( GLcontext
*ctx
, const GLfloat color
[4] )
1527 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1529 CLAMPED_FLOAT_TO_UBYTE(c
[0], color
[0]);
1530 CLAMPED_FLOAT_TO_UBYTE(c
[1], color
[1]);
1531 CLAMPED_FLOAT_TO_UBYTE(c
[2], color
[2]);
1532 CLAMPED_FLOAT_TO_UBYTE(c
[3], color
[3]);
1533 rmesa
->state
.color
.clear
= radeonPackColor( rmesa
->radeonScreen
->cpp
,
1534 c
[0], c
[1], c
[2], c
[3] );
1538 static void radeonRenderMode( GLcontext
*ctx
, GLenum mode
)
1540 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1541 FALLBACK( rmesa
, RADEON_FALLBACK_RENDER_MODE
, (mode
!= GL_RENDER
) );
1545 static GLuint radeon_rop_tab
[] = {
1548 RADEON_ROP_AND_REVERSE
,
1550 RADEON_ROP_AND_INVERTED
,
1557 RADEON_ROP_OR_REVERSE
,
1558 RADEON_ROP_COPY_INVERTED
,
1559 RADEON_ROP_OR_INVERTED
,
1564 static void radeonLogicOpCode( GLcontext
*ctx
, GLenum opcode
)
1566 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1567 GLuint rop
= (GLuint
)opcode
- GL_CLEAR
;
1571 RADEON_STATECHANGE( rmesa
, msk
);
1572 rmesa
->hw
.msk
.cmd
[MSK_RB3D_ROPCNTL
] = radeon_rop_tab
[rop
];
1576 void radeonSetCliprects( radeonContextPtr rmesa
, GLenum mode
)
1578 __DRIdrawablePrivate
*dPriv
= rmesa
->dri
.drawable
;
1582 rmesa
->numClipRects
= dPriv
->numClipRects
;
1583 rmesa
->pClipRects
= (XF86DRIClipRectPtr
)dPriv
->pClipRects
;
1586 /* Can't ignore 2d windows if we are page flipping.
1588 if ( dPriv
->numBackClipRects
== 0 || rmesa
->doPageFlip
) {
1589 rmesa
->numClipRects
= dPriv
->numClipRects
;
1590 rmesa
->pClipRects
= (XF86DRIClipRectPtr
)dPriv
->pClipRects
;
1593 rmesa
->numClipRects
= dPriv
->numBackClipRects
;
1594 rmesa
->pClipRects
= (XF86DRIClipRectPtr
)dPriv
->pBackClipRects
;
1598 fprintf(stderr
, "bad mode in radeonSetCliprects\n");
1602 if (rmesa
->state
.scissor
.enabled
)
1603 radeonRecalcScissorRects( rmesa
);
1607 static void radeonDrawBuffer( GLcontext
*ctx
, GLenum mode
)
1609 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1611 if (RADEON_DEBUG
& DEBUG_DRI
)
1612 fprintf(stderr
, "%s %s\n", __FUNCTION__
,
1613 _mesa_lookup_enum_by_nr( mode
));
1615 RADEON_FIREVERTICES(rmesa
); /* don't pipeline cliprect changes */
1618 * _DrawDestMask is easier to cope with than <mode>.
1620 switch ( ctx
->Color
._DrawDestMask
) {
1621 case FRONT_LEFT_BIT
:
1622 FALLBACK( rmesa
, RADEON_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
1623 radeonSetCliprects( rmesa
, GL_FRONT_LEFT
);
1626 FALLBACK( rmesa
, RADEON_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
1627 radeonSetCliprects( rmesa
, GL_BACK_LEFT
);
1630 /* GL_NONE or GL_FRONT_AND_BACK or stereo left&right, etc */
1631 FALLBACK( rmesa
, RADEON_FALLBACK_DRAW_BUFFER
, GL_TRUE
);
1635 /* We want to update the s/w rast state too so that r200SetBuffer()
1638 _swrast_DrawBuffer(ctx
, mode
);
1640 RADEON_STATECHANGE( rmesa
, ctx
);
1641 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLOROFFSET
] = ((rmesa
->state
.color
.drawOffset
+
1642 rmesa
->radeonScreen
->fbLocation
)
1643 & RADEON_COLOROFFSET_MASK
);
1644 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] = rmesa
->state
.color
.drawPitch
;
1647 static void radeonReadBuffer( GLcontext
*ctx
, GLenum mode
)
1649 /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
1653 /* =============================================================
1654 * State enable/disable
1657 static void radeonEnable( GLcontext
*ctx
, GLenum cap
, GLboolean state
)
1659 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1662 if ( RADEON_DEBUG
& DEBUG_STATE
)
1663 fprintf( stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1664 _mesa_lookup_enum_by_nr( cap
),
1665 state
? "GL_TRUE" : "GL_FALSE" );
1668 /* Fast track this one...
1676 RADEON_STATECHANGE( rmesa
, ctx
);
1678 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_ALPHA_TEST_ENABLE
;
1680 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_ALPHA_TEST_ENABLE
;
1685 RADEON_STATECHANGE( rmesa
, ctx
);
1687 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_ALPHA_BLEND_ENABLE
;
1689 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_ALPHA_BLEND_ENABLE
;
1691 if ( ctx
->Color
._LogicOpEnabled
) {
1692 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_ROP_ENABLE
;
1694 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_ROP_ENABLE
;
1697 /* Catch a possible fallback:
1700 ctx
->Driver
.BlendEquationSeparate( ctx
,
1701 ctx
->Color
.BlendEquationRGB
,
1702 ctx
->Color
.BlendEquationA
);
1703 ctx
->Driver
.BlendFuncSeparate( ctx
, ctx
->Color
.BlendSrcRGB
,
1704 ctx
->Color
.BlendDstRGB
,
1705 ctx
->Color
.BlendSrcA
,
1706 ctx
->Color
.BlendDstA
);
1709 FALLBACK( rmesa
, RADEON_FALLBACK_BLEND_FUNC
, GL_FALSE
);
1710 FALLBACK( rmesa
, RADEON_FALLBACK_BLEND_EQ
, GL_FALSE
);
1714 case GL_CLIP_PLANE0
:
1715 case GL_CLIP_PLANE1
:
1716 case GL_CLIP_PLANE2
:
1717 case GL_CLIP_PLANE3
:
1718 case GL_CLIP_PLANE4
:
1719 case GL_CLIP_PLANE5
:
1720 p
= cap
-GL_CLIP_PLANE0
;
1721 RADEON_STATECHANGE( rmesa
, tcl
);
1723 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= (RADEON_UCP_ENABLE_0
<<p
);
1724 radeonClipPlane( ctx
, cap
, NULL
);
1727 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~(RADEON_UCP_ENABLE_0
<<p
);
1731 case GL_COLOR_MATERIAL
:
1732 radeonColorMaterial( ctx
, 0, 0 );
1733 radeonUpdateMaterial( ctx
);
1737 radeonCullFace( ctx
, 0 );
1741 RADEON_STATECHANGE(rmesa
, ctx
);
1743 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_Z_ENABLE
;
1745 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_Z_ENABLE
;
1750 RADEON_STATECHANGE(rmesa
, ctx
);
1752 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_DITHER_ENABLE
;
1753 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~rmesa
->state
.color
.roundEnable
;
1755 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_DITHER_ENABLE
;
1756 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= rmesa
->state
.color
.roundEnable
;
1761 RADEON_STATECHANGE(rmesa
, ctx
);
1763 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_FOG_ENABLE
;
1764 radeonFogfv( ctx
, GL_FOG_MODE
, 0 );
1766 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_FOG_ENABLE
;
1767 RADEON_STATECHANGE(rmesa
, tcl
);
1768 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~RADEON_TCL_FOG_MASK
;
1770 radeonUpdateSpecular( ctx
); /* for PK_SPEC */
1771 if (rmesa
->TclFallback
)
1772 radeonChooseVertexState( ctx
);
1773 _mesa_allow_light_in_model( ctx
, !state
);
1784 RADEON_STATECHANGE(rmesa
, tcl
);
1785 p
= cap
- GL_LIGHT0
;
1787 flag
= (RADEON_LIGHT_1_ENABLE
|
1788 RADEON_LIGHT_1_ENABLE_AMBIENT
|
1789 RADEON_LIGHT_1_ENABLE_SPECULAR
);
1791 flag
= (RADEON_LIGHT_0_ENABLE
|
1792 RADEON_LIGHT_0_ENABLE_AMBIENT
|
1793 RADEON_LIGHT_0_ENABLE_SPECULAR
);
1796 rmesa
->hw
.tcl
.cmd
[p
/2 + TCL_PER_LIGHT_CTL_0
] |= flag
;
1798 rmesa
->hw
.tcl
.cmd
[p
/2 + TCL_PER_LIGHT_CTL_0
] &= ~flag
;
1802 update_light_colors( ctx
, p
);
1806 RADEON_STATECHANGE(rmesa
, tcl
);
1807 radeonUpdateSpecular(ctx
);
1808 check_twoside_fallback( ctx
);
1811 case GL_LINE_SMOOTH
:
1812 RADEON_STATECHANGE( rmesa
, ctx
);
1814 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_ANTI_ALIAS_LINE
;
1816 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_ANTI_ALIAS_LINE
;
1820 case GL_LINE_STIPPLE
:
1821 RADEON_STATECHANGE( rmesa
, ctx
);
1823 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_PATTERN_ENABLE
;
1825 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_PATTERN_ENABLE
;
1829 case GL_COLOR_LOGIC_OP
:
1830 RADEON_STATECHANGE( rmesa
, ctx
);
1831 if ( ctx
->Color
._LogicOpEnabled
) {
1832 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_ROP_ENABLE
;
1834 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_ROP_ENABLE
;
1839 RADEON_STATECHANGE( rmesa
, tcl
);
1841 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_NORMALIZE_NORMALS
;
1843 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_NORMALIZE_NORMALS
;
1847 case GL_POLYGON_OFFSET_POINT
:
1848 if (rmesa
->dri
.drmMinor
== 1) {
1849 radeonChooseRenderState( ctx
);
1852 RADEON_STATECHANGE( rmesa
, set
);
1854 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_ZBIAS_ENABLE_POINT
;
1856 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_ZBIAS_ENABLE_POINT
;
1861 case GL_POLYGON_OFFSET_LINE
:
1862 if (rmesa
->dri
.drmMinor
== 1) {
1863 radeonChooseRenderState( ctx
);
1866 RADEON_STATECHANGE( rmesa
, set
);
1868 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_ZBIAS_ENABLE_LINE
;
1870 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_ZBIAS_ENABLE_LINE
;
1875 case GL_POLYGON_OFFSET_FILL
:
1876 if (rmesa
->dri
.drmMinor
== 1) {
1877 radeonChooseRenderState( ctx
);
1880 RADEON_STATECHANGE( rmesa
, set
);
1882 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_ZBIAS_ENABLE_TRI
;
1884 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_ZBIAS_ENABLE_TRI
;
1889 case GL_POLYGON_SMOOTH
:
1890 RADEON_STATECHANGE( rmesa
, ctx
);
1892 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_ANTI_ALIAS_POLY
;
1894 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_ANTI_ALIAS_POLY
;
1898 case GL_POLYGON_STIPPLE
:
1899 RADEON_STATECHANGE(rmesa
, ctx
);
1901 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_STIPPLE_ENABLE
;
1903 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_STIPPLE_ENABLE
;
1907 case GL_RESCALE_NORMAL_EXT
: {
1908 GLboolean tmp
= ctx
->_NeedEyeCoords
? state
: !state
;
1909 RADEON_STATECHANGE( rmesa
, tcl
);
1911 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_RESCALE_NORMALS
;
1913 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_RESCALE_NORMALS
;
1918 case GL_SCISSOR_TEST
:
1919 RADEON_FIREVERTICES( rmesa
);
1920 rmesa
->state
.scissor
.enabled
= state
;
1921 radeonUpdateScissor( ctx
);
1924 case GL_STENCIL_TEST
:
1925 if ( rmesa
->state
.stencil
.hwBuffer
) {
1926 RADEON_STATECHANGE( rmesa
, ctx
);
1928 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_STENCIL_ENABLE
;
1930 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_STENCIL_ENABLE
;
1933 FALLBACK( rmesa
, RADEON_FALLBACK_STENCIL
, state
);
1937 case GL_TEXTURE_GEN_Q
:
1938 case GL_TEXTURE_GEN_R
:
1939 case GL_TEXTURE_GEN_S
:
1940 case GL_TEXTURE_GEN_T
:
1941 /* Picked up in radeonUpdateTextureState.
1943 rmesa
->recheck_texgen
[ctx
->Texture
.CurrentUnit
] = GL_TRUE
;
1946 case GL_COLOR_SUM_EXT
:
1947 radeonUpdateSpecular ( ctx
);
1956 static void radeonLightingSpaceChange( GLcontext
*ctx
)
1958 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1960 RADEON_STATECHANGE( rmesa
, tcl
);
1962 if (RADEON_DEBUG
& DEBUG_STATE
)
1963 fprintf(stderr
, "%s %d BEFORE %x\n", __FUNCTION__
, ctx
->_NeedEyeCoords
,
1964 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
]);
1966 if (ctx
->_NeedEyeCoords
)
1967 tmp
= ctx
->Transform
.RescaleNormals
;
1969 tmp
= !ctx
->Transform
.RescaleNormals
;
1972 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_RESCALE_NORMALS
;
1974 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_RESCALE_NORMALS
;
1977 if (RADEON_DEBUG
& DEBUG_STATE
)
1978 fprintf(stderr
, "%s %d AFTER %x\n", __FUNCTION__
, ctx
->_NeedEyeCoords
,
1979 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
]);
1982 /* =============================================================
1983 * Deferred state management - matrices, textures, other?
1989 static void upload_matrix( radeonContextPtr rmesa
, GLfloat
*src
, int idx
)
1991 float *dest
= ((float *)RADEON_DB_STATE( mat
[idx
] ))+MAT_ELT_0
;
1995 for (i
= 0 ; i
< 4 ; i
++) {
1999 *dest
++ = src
[i
+12];
2002 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mat
[idx
] );
2005 static void upload_matrix_t( radeonContextPtr rmesa
, GLfloat
*src
, int idx
)
2007 float *dest
= ((float *)RADEON_DB_STATE( mat
[idx
] ))+MAT_ELT_0
;
2008 memcpy(dest
, src
, 16*sizeof(float));
2009 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mat
[idx
] );
2013 static void update_texturematrix( GLcontext
*ctx
)
2015 radeonContextPtr rmesa
= RADEON_CONTEXT( ctx
);
2016 GLuint tpc
= rmesa
->hw
.tcl
.cmd
[TCL_TEXTURE_PROC_CTL
];
2017 GLuint vs
= rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
];
2020 rmesa
->TexMatEnabled
= 0;
2022 for (unit
= 0 ; unit
< 2; unit
++) {
2023 if (!ctx
->Texture
.Unit
[unit
]._ReallyEnabled
) {
2025 else if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
) {
2026 GLuint inputshift
= RADEON_TEXGEN_0_INPUT_SHIFT
+ unit
*4;
2028 rmesa
->TexMatEnabled
|= (RADEON_TEXGEN_TEXMAT_0_ENABLE
|
2029 RADEON_TEXMAT_0_ENABLE
) << unit
;
2031 if (rmesa
->TexGenEnabled
& (RADEON_TEXMAT_0_ENABLE
<< unit
)) {
2032 /* Need to preconcatenate any active texgen
2033 * obj/eyeplane matrices:
2035 _math_matrix_mul_matrix( &rmesa
->tmpmat
,
2036 &rmesa
->TexGenMatrix
[unit
],
2037 ctx
->TextureMatrixStack
[unit
].Top
);
2038 upload_matrix( rmesa
, rmesa
->tmpmat
.m
, TEXMAT_0
+unit
);
2041 rmesa
->TexMatEnabled
|=
2042 (RADEON_TEXGEN_INPUT_TEXCOORD_0
+unit
) << inputshift
;
2043 upload_matrix( rmesa
, ctx
->TextureMatrixStack
[unit
].Top
->m
,
2047 else if (rmesa
->TexGenEnabled
& (RADEON_TEXMAT_0_ENABLE
<< unit
)) {
2048 upload_matrix( rmesa
, rmesa
->TexGenMatrix
[unit
].m
,
2054 tpc
= (rmesa
->TexMatEnabled
| rmesa
->TexGenEnabled
);
2056 vs
&= ~((0xf << RADEON_TCL_TEX_0_OUTPUT_SHIFT
) |
2057 (0xf << RADEON_TCL_TEX_1_OUTPUT_SHIFT
));
2059 if (tpc
& RADEON_TEXGEN_TEXMAT_0_ENABLE
)
2060 vs
|= RADEON_TCL_TEX_COMPUTED_TEX_0
<< RADEON_TCL_TEX_0_OUTPUT_SHIFT
;
2062 vs
|= RADEON_TCL_TEX_INPUT_TEX_0
<< RADEON_TCL_TEX_0_OUTPUT_SHIFT
;
2064 if (tpc
& RADEON_TEXGEN_TEXMAT_1_ENABLE
)
2065 vs
|= RADEON_TCL_TEX_COMPUTED_TEX_1
<< RADEON_TCL_TEX_1_OUTPUT_SHIFT
;
2067 vs
|= RADEON_TCL_TEX_INPUT_TEX_1
<< RADEON_TCL_TEX_1_OUTPUT_SHIFT
;
2069 if (tpc
!= rmesa
->hw
.tcl
.cmd
[TCL_TEXTURE_PROC_CTL
] ||
2070 vs
!= rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
]) {
2072 RADEON_STATECHANGE(rmesa
, tcl
);
2073 rmesa
->hw
.tcl
.cmd
[TCL_TEXTURE_PROC_CTL
] = tpc
;
2074 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] = vs
;
2080 void radeonValidateState( GLcontext
*ctx
)
2082 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
2083 GLuint new_state
= rmesa
->NewGLState
;
2085 if (new_state
& _NEW_TEXTURE
) {
2086 radeonUpdateTextureState( ctx
);
2087 new_state
|= rmesa
->NewGLState
; /* may add TEXTURE_MATRIX */
2090 /* Need an event driven matrix update?
2092 if (new_state
& (_NEW_MODELVIEW
|_NEW_PROJECTION
))
2093 upload_matrix( rmesa
, ctx
->_ModelProjectMatrix
.m
, MODEL_PROJ
);
2095 /* Need these for lighting (shouldn't upload otherwise)
2097 if (new_state
& (_NEW_MODELVIEW
)) {
2098 upload_matrix( rmesa
, ctx
->ModelviewMatrixStack
.Top
->m
, MODEL
);
2099 upload_matrix_t( rmesa
, ctx
->ModelviewMatrixStack
.Top
->inv
, MODEL_IT
);
2102 /* Does this need to be triggered on eg. modelview for
2103 * texgen-derived objplane/eyeplane matrices?
2105 if (new_state
& _NEW_TEXTURE_MATRIX
) {
2106 update_texturematrix( ctx
);
2109 if (new_state
& (_NEW_LIGHT
|_NEW_MODELVIEW
|_MESA_NEW_NEED_EYE_COORDS
)) {
2110 update_light( ctx
);
2113 /* emit all active clip planes if projection matrix changes.
2115 if (new_state
& (_NEW_PROJECTION
)) {
2116 if (ctx
->Transform
.ClipPlanesEnabled
)
2117 radeonUpdateClipPlanes( ctx
);
2121 rmesa
->NewGLState
= 0;
2125 static void radeonInvalidateState( GLcontext
*ctx
, GLuint new_state
)
2127 _swrast_InvalidateState( ctx
, new_state
);
2128 _swsetup_InvalidateState( ctx
, new_state
);
2129 _ac_InvalidateState( ctx
, new_state
);
2130 _tnl_InvalidateState( ctx
, new_state
);
2131 _ae_invalidate_state( ctx
, new_state
);
2132 RADEON_CONTEXT(ctx
)->NewGLState
|= new_state
;
2133 radeonVtxfmtInvalidate( ctx
);
2137 /* A hack. Need a faster way to find this out.
2139 static GLboolean
check_material( GLcontext
*ctx
)
2141 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
2144 for (i
= _TNL_ATTRIB_MAT_FRONT_AMBIENT
;
2145 i
< _TNL_ATTRIB_MAT_BACK_INDEXES
;
2147 if (tnl
->vb
.AttribPtr
[i
] &&
2148 tnl
->vb
.AttribPtr
[i
]->stride
)
2155 static void radeonWrapRunPipeline( GLcontext
*ctx
)
2157 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
2158 GLboolean has_material
;
2161 fprintf(stderr
, "%s, newstate: %x\n", __FUNCTION__
, rmesa
->NewGLState
);
2165 if (rmesa
->NewGLState
)
2166 radeonValidateState( ctx
);
2168 has_material
= (ctx
->Light
.Enabled
&& check_material( ctx
));
2171 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_MATERIAL
, GL_TRUE
);
2174 /* Run the pipeline.
2176 _tnl_run_pipeline( ctx
);
2179 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_MATERIAL
, GL_FALSE
);
2184 /* Initialize the driver's state functions.
2186 void radeonInitStateFuncs( GLcontext
*ctx
)
2188 ctx
->Driver
.UpdateState
= radeonInvalidateState
;
2189 ctx
->Driver
.LightingSpaceChange
= radeonLightingSpaceChange
;
2191 ctx
->Driver
.DrawBuffer
= radeonDrawBuffer
;
2192 ctx
->Driver
.ReadBuffer
= radeonReadBuffer
;
2194 ctx
->Driver
.AlphaFunc
= radeonAlphaFunc
;
2195 ctx
->Driver
.BlendEquationSeparate
= radeonBlendEquationSeparate
;
2196 ctx
->Driver
.BlendFuncSeparate
= radeonBlendFuncSeparate
;
2197 ctx
->Driver
.ClearColor
= radeonClearColor
;
2198 ctx
->Driver
.ClearDepth
= radeonClearDepth
;
2199 ctx
->Driver
.ClearIndex
= NULL
;
2200 ctx
->Driver
.ClearStencil
= radeonClearStencil
;
2201 ctx
->Driver
.ClipPlane
= radeonClipPlane
;
2202 ctx
->Driver
.ColorMask
= radeonColorMask
;
2203 ctx
->Driver
.CullFace
= radeonCullFace
;
2204 ctx
->Driver
.DepthFunc
= radeonDepthFunc
;
2205 ctx
->Driver
.DepthMask
= radeonDepthMask
;
2206 ctx
->Driver
.DepthRange
= radeonDepthRange
;
2207 ctx
->Driver
.Enable
= radeonEnable
;
2208 ctx
->Driver
.Fogfv
= radeonFogfv
;
2209 ctx
->Driver
.FrontFace
= radeonFrontFace
;
2210 ctx
->Driver
.Hint
= NULL
;
2211 ctx
->Driver
.IndexMask
= NULL
;
2212 ctx
->Driver
.LightModelfv
= radeonLightModelfv
;
2213 ctx
->Driver
.Lightfv
= radeonLightfv
;
2214 ctx
->Driver
.LineStipple
= radeonLineStipple
;
2215 ctx
->Driver
.LineWidth
= radeonLineWidth
;
2216 ctx
->Driver
.LogicOpcode
= radeonLogicOpCode
;
2217 ctx
->Driver
.PolygonMode
= radeonPolygonMode
;
2219 if (RADEON_CONTEXT(ctx
)->dri
.drmMinor
> 1)
2220 ctx
->Driver
.PolygonOffset
= radeonPolygonOffset
;
2222 ctx
->Driver
.PolygonStipple
= radeonPolygonStipple
;
2223 ctx
->Driver
.RenderMode
= radeonRenderMode
;
2224 ctx
->Driver
.Scissor
= radeonScissor
;
2225 ctx
->Driver
.ShadeModel
= radeonShadeModel
;
2226 ctx
->Driver
.StencilFunc
= radeonStencilFunc
;
2227 ctx
->Driver
.StencilMask
= radeonStencilMask
;
2228 ctx
->Driver
.StencilOp
= radeonStencilOp
;
2229 ctx
->Driver
.Viewport
= radeonViewport
;
2231 /* Pixel path fallbacks
2233 ctx
->Driver
.Accum
= _swrast_Accum
;
2234 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
2235 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
2236 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
2237 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
2239 /* Swrast hooks for imaging extensions:
2241 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
2242 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
2243 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
2244 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
2246 TNL_CONTEXT(ctx
)->Driver
.NotifyMaterialChange
= radeonUpdateMaterial
;
2247 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= radeonWrapRunPipeline
;