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"
43 #include "framebuffer.h"
45 #include "array_cache/acache.h"
47 #include "tnl/t_pipeline.h"
48 #include "swrast_setup/swrast_setup.h"
50 #include "radeon_context.h"
51 #include "radeon_ioctl.h"
52 #include "radeon_state.h"
53 #include "radeon_tcl.h"
54 #include "radeon_tex.h"
55 #include "radeon_swtcl.h"
56 #include "radeon_vtxfmt.h"
57 #include "drirenderbuffer.h"
59 static void radeonUpdateSpecular( GLcontext
*ctx
);
61 /* =============================================================
65 static void radeonAlphaFunc( GLcontext
*ctx
, GLenum func
, GLfloat ref
)
67 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
68 int pp_misc
= rmesa
->hw
.ctx
.cmd
[CTX_PP_MISC
];
71 CLAMPED_FLOAT_TO_UBYTE(refByte
, ref
);
73 RADEON_STATECHANGE( rmesa
, ctx
);
75 pp_misc
&= ~(RADEON_ALPHA_TEST_OP_MASK
| RADEON_REF_ALPHA_MASK
);
76 pp_misc
|= (refByte
& RADEON_REF_ALPHA_MASK
);
80 pp_misc
|= RADEON_ALPHA_TEST_FAIL
;
83 pp_misc
|= RADEON_ALPHA_TEST_LESS
;
86 pp_misc
|= RADEON_ALPHA_TEST_EQUAL
;
89 pp_misc
|= RADEON_ALPHA_TEST_LEQUAL
;
92 pp_misc
|= RADEON_ALPHA_TEST_GREATER
;
95 pp_misc
|= RADEON_ALPHA_TEST_NEQUAL
;
98 pp_misc
|= RADEON_ALPHA_TEST_GEQUAL
;
101 pp_misc
|= RADEON_ALPHA_TEST_PASS
;
105 rmesa
->hw
.ctx
.cmd
[CTX_PP_MISC
] = pp_misc
;
108 static void radeonBlendEquationSeparate( GLcontext
*ctx
,
109 GLenum modeRGB
, GLenum modeA
)
111 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
112 GLuint b
= rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] & ~RADEON_COMB_FCN_MASK
;
113 GLboolean fallback
= GL_FALSE
;
115 assert( modeRGB
== modeA
);
120 b
|= RADEON_COMB_FCN_ADD_CLAMP
;
123 case GL_FUNC_SUBTRACT
:
124 b
|= RADEON_COMB_FCN_SUB_CLAMP
;
128 if (ctx
->Color
.BlendEnabled
)
131 b
|= RADEON_COMB_FCN_ADD_CLAMP
;
135 FALLBACK( rmesa
, RADEON_FALLBACK_BLEND_EQ
, fallback
);
137 RADEON_STATECHANGE( rmesa
, ctx
);
138 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = b
;
139 if ( (ctx
->Color
.ColorLogicOpEnabled
|| (ctx
->Color
.BlendEnabled
140 && ctx
->Color
.BlendEquationRGB
== GL_LOGIC_OP
)) ) {
141 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_ROP_ENABLE
;
143 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_ROP_ENABLE
;
148 static void radeonBlendFuncSeparate( GLcontext
*ctx
,
149 GLenum sfactorRGB
, GLenum dfactorRGB
,
150 GLenum sfactorA
, GLenum dfactorA
)
152 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
153 GLuint b
= rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] &
154 ~(RADEON_SRC_BLEND_MASK
| RADEON_DST_BLEND_MASK
);
155 GLboolean fallback
= GL_FALSE
;
157 switch ( ctx
->Color
.BlendSrcRGB
) {
159 b
|= RADEON_SRC_BLEND_GL_ZERO
;
162 b
|= RADEON_SRC_BLEND_GL_ONE
;
165 b
|= RADEON_SRC_BLEND_GL_DST_COLOR
;
167 case GL_ONE_MINUS_DST_COLOR
:
168 b
|= RADEON_SRC_BLEND_GL_ONE_MINUS_DST_COLOR
;
171 b
|= RADEON_SRC_BLEND_GL_SRC_COLOR
;
173 case GL_ONE_MINUS_SRC_COLOR
:
174 b
|= RADEON_SRC_BLEND_GL_ONE_MINUS_SRC_COLOR
;
177 b
|= RADEON_SRC_BLEND_GL_SRC_ALPHA
;
179 case GL_ONE_MINUS_SRC_ALPHA
:
180 b
|= RADEON_SRC_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
183 b
|= RADEON_SRC_BLEND_GL_DST_ALPHA
;
185 case GL_ONE_MINUS_DST_ALPHA
:
186 b
|= RADEON_SRC_BLEND_GL_ONE_MINUS_DST_ALPHA
;
188 case GL_SRC_ALPHA_SATURATE
:
189 b
|= RADEON_SRC_BLEND_GL_SRC_ALPHA_SATURATE
;
191 case GL_CONSTANT_COLOR
:
192 case GL_ONE_MINUS_CONSTANT_COLOR
:
193 case GL_CONSTANT_ALPHA
:
194 case GL_ONE_MINUS_CONSTANT_ALPHA
:
195 if (ctx
->Color
.BlendEnabled
)
198 b
|= RADEON_SRC_BLEND_GL_ONE
;
204 switch ( ctx
->Color
.BlendDstRGB
) {
206 b
|= RADEON_DST_BLEND_GL_ZERO
;
209 b
|= RADEON_DST_BLEND_GL_ONE
;
212 b
|= RADEON_DST_BLEND_GL_SRC_COLOR
;
214 case GL_ONE_MINUS_SRC_COLOR
:
215 b
|= RADEON_DST_BLEND_GL_ONE_MINUS_SRC_COLOR
;
218 b
|= RADEON_DST_BLEND_GL_SRC_ALPHA
;
220 case GL_ONE_MINUS_SRC_ALPHA
:
221 b
|= RADEON_DST_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
224 b
|= RADEON_DST_BLEND_GL_DST_COLOR
;
226 case GL_ONE_MINUS_DST_COLOR
:
227 b
|= RADEON_DST_BLEND_GL_ONE_MINUS_DST_COLOR
;
230 b
|= RADEON_DST_BLEND_GL_DST_ALPHA
;
232 case GL_ONE_MINUS_DST_ALPHA
:
233 b
|= RADEON_DST_BLEND_GL_ONE_MINUS_DST_ALPHA
;
235 case GL_CONSTANT_COLOR
:
236 case GL_ONE_MINUS_CONSTANT_COLOR
:
237 case GL_CONSTANT_ALPHA
:
238 case GL_ONE_MINUS_CONSTANT_ALPHA
:
239 if (ctx
->Color
.BlendEnabled
)
242 b
|= RADEON_DST_BLEND_GL_ZERO
;
248 FALLBACK( rmesa
, RADEON_FALLBACK_BLEND_FUNC
, fallback
);
250 RADEON_STATECHANGE( rmesa
, ctx
);
251 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = b
;
256 /* =============================================================
260 static void radeonDepthFunc( GLcontext
*ctx
, GLenum func
)
262 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
264 RADEON_STATECHANGE( rmesa
, ctx
);
265 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~RADEON_Z_TEST_MASK
;
267 switch ( ctx
->Depth
.Func
) {
269 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_NEVER
;
272 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_LESS
;
275 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_EQUAL
;
278 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_LEQUAL
;
281 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_GREATER
;
284 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_NEQUAL
;
287 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_GEQUAL
;
290 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_TEST_ALWAYS
;
296 static void radeonDepthMask( GLcontext
*ctx
, GLboolean flag
)
298 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
299 RADEON_STATECHANGE( rmesa
, ctx
);
301 if ( ctx
->Depth
.Mask
) {
302 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_Z_WRITE_ENABLE
;
304 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~RADEON_Z_WRITE_ENABLE
;
308 static void radeonClearDepth( GLcontext
*ctx
, GLclampd d
)
310 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
311 GLuint format
= (rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &
312 RADEON_DEPTH_FORMAT_MASK
);
315 case RADEON_DEPTH_FORMAT_16BIT_INT_Z
:
316 rmesa
->state
.depth
.clear
= d
* 0x0000ffff;
318 case RADEON_DEPTH_FORMAT_24BIT_INT_Z
:
319 rmesa
->state
.depth
.clear
= d
* 0x00ffffff;
325 /* =============================================================
330 static void radeonFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
332 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
333 union { int i
; float f
; } c
, 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
;
347 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_TCL_FOG_EXP
;
350 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_TCL_FOG_EXP2
;
359 if (!ctx
->Fog
.Enabled
)
361 c
.i
= rmesa
->hw
.fog
.cmd
[FOG_C
];
362 d
.i
= rmesa
->hw
.fog
.cmd
[FOG_D
];
363 switch (ctx
->Fog
.Mode
) {
366 /* While this is the opposite sign from the DDK, it makes the fog test
367 * pass, and matches r200.
369 d
.f
= -ctx
->Fog
.Density
;
373 d
.f
= -(ctx
->Fog
.Density
* ctx
->Fog
.Density
);
376 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
380 c
.f
= ctx
->Fog
.End
/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
381 /* While this is the opposite sign from the DDK, it makes the fog
382 * test pass, and matches r200.
384 d
.f
= -1.0/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
390 if (c
.i
!= rmesa
->hw
.fog
.cmd
[FOG_C
] || d
.i
!= rmesa
->hw
.fog
.cmd
[FOG_D
]) {
391 RADEON_STATECHANGE( rmesa
, fog
);
392 rmesa
->hw
.fog
.cmd
[FOG_C
] = c
.i
;
393 rmesa
->hw
.fog
.cmd
[FOG_D
] = d
.i
;
397 RADEON_STATECHANGE( rmesa
, ctx
);
398 UNCLAMPED_FLOAT_TO_RGB_CHAN( col
, ctx
->Fog
.Color
);
399 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] &= ~RADEON_FOG_COLOR_MASK
;
400 rmesa
->hw
.ctx
.cmd
[CTX_PP_FOG_COLOR
] |=
401 radeonPackColor( 4, col
[0], col
[1], col
[2], 0 );
403 case GL_FOG_COORD_SRC
:
404 radeonUpdateSpecular( ctx
);
412 /* =============================================================
417 static GLboolean
intersect_rect( drm_clip_rect_t
*out
,
422 if ( b
->x1
> out
->x1
) out
->x1
= b
->x1
;
423 if ( b
->y1
> out
->y1
) out
->y1
= b
->y1
;
424 if ( b
->x2
< out
->x2
) out
->x2
= b
->x2
;
425 if ( b
->y2
< out
->y2
) out
->y2
= b
->y2
;
426 if ( out
->x1
>= out
->x2
) return GL_FALSE
;
427 if ( out
->y1
>= out
->y2
) return GL_FALSE
;
432 void radeonRecalcScissorRects( radeonContextPtr rmesa
)
434 drm_clip_rect_t
*out
;
437 /* Grow cliprect store?
439 if (rmesa
->state
.scissor
.numAllocedClipRects
< rmesa
->numClipRects
) {
440 while (rmesa
->state
.scissor
.numAllocedClipRects
< rmesa
->numClipRects
) {
441 rmesa
->state
.scissor
.numAllocedClipRects
+= 1; /* zero case */
442 rmesa
->state
.scissor
.numAllocedClipRects
*= 2;
445 if (rmesa
->state
.scissor
.pClipRects
)
446 FREE(rmesa
->state
.scissor
.pClipRects
);
448 rmesa
->state
.scissor
.pClipRects
=
449 MALLOC( rmesa
->state
.scissor
.numAllocedClipRects
*
450 sizeof(drm_clip_rect_t
) );
452 if ( rmesa
->state
.scissor
.pClipRects
== NULL
) {
453 rmesa
->state
.scissor
.numAllocedClipRects
= 0;
458 out
= rmesa
->state
.scissor
.pClipRects
;
459 rmesa
->state
.scissor
.numClipRects
= 0;
461 for ( i
= 0 ; i
< rmesa
->numClipRects
; i
++ ) {
462 if ( intersect_rect( out
,
463 &rmesa
->pClipRects
[i
],
464 &rmesa
->state
.scissor
.rect
) ) {
465 rmesa
->state
.scissor
.numClipRects
++;
472 static void radeonUpdateScissor( GLcontext
*ctx
)
474 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
476 if ( rmesa
->dri
.drawable
) {
477 __DRIdrawablePrivate
*dPriv
= rmesa
->dri
.drawable
;
479 int x
= ctx
->Scissor
.X
;
480 int y
= dPriv
->h
- ctx
->Scissor
.Y
- ctx
->Scissor
.Height
;
481 int w
= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
- 1;
482 int h
= dPriv
->h
- ctx
->Scissor
.Y
- 1;
484 rmesa
->state
.scissor
.rect
.x1
= x
+ dPriv
->x
;
485 rmesa
->state
.scissor
.rect
.y1
= y
+ dPriv
->y
;
486 rmesa
->state
.scissor
.rect
.x2
= w
+ dPriv
->x
+ 1;
487 rmesa
->state
.scissor
.rect
.y2
= h
+ dPriv
->y
+ 1;
489 radeonRecalcScissorRects( rmesa
);
494 static void radeonScissor( GLcontext
*ctx
,
495 GLint x
, GLint y
, GLsizei w
, GLsizei h
)
497 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
499 if ( ctx
->Scissor
.Enabled
) {
500 RADEON_FIREVERTICES( rmesa
); /* don't pipeline cliprect changes */
501 radeonUpdateScissor( ctx
);
507 /* =============================================================
511 static void radeonCullFace( GLcontext
*ctx
, GLenum unused
)
513 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
514 GLuint s
= rmesa
->hw
.set
.cmd
[SET_SE_CNTL
];
515 GLuint t
= rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
];
517 s
|= RADEON_FFACE_SOLID
| RADEON_BFACE_SOLID
;
518 t
&= ~(RADEON_CULL_FRONT
| RADEON_CULL_BACK
);
520 if ( ctx
->Polygon
.CullFlag
) {
521 switch ( ctx
->Polygon
.CullFaceMode
) {
523 s
&= ~RADEON_FFACE_SOLID
;
524 t
|= RADEON_CULL_FRONT
;
527 s
&= ~RADEON_BFACE_SOLID
;
528 t
|= RADEON_CULL_BACK
;
530 case GL_FRONT_AND_BACK
:
531 s
&= ~(RADEON_FFACE_SOLID
| RADEON_BFACE_SOLID
);
532 t
|= (RADEON_CULL_FRONT
| RADEON_CULL_BACK
);
537 if ( rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] != s
) {
538 RADEON_STATECHANGE(rmesa
, set
);
539 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] = s
;
542 if ( rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] != t
) {
543 RADEON_STATECHANGE(rmesa
, tcl
);
544 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] = t
;
548 static void radeonFrontFace( GLcontext
*ctx
, GLenum mode
)
550 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
552 RADEON_STATECHANGE( rmesa
, set
);
553 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_FFACE_CULL_DIR_MASK
;
555 RADEON_STATECHANGE( rmesa
, tcl
);
556 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~RADEON_CULL_FRONT_IS_CCW
;
560 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_FFACE_CULL_CW
;
563 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_FFACE_CULL_CCW
;
564 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_CULL_FRONT_IS_CCW
;
570 /* =============================================================
573 static void radeonLineWidth( GLcontext
*ctx
, GLfloat widthf
)
575 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
577 RADEON_STATECHANGE( rmesa
, lin
);
578 RADEON_STATECHANGE( rmesa
, set
);
580 /* Line width is stored in U6.4 format.
582 rmesa
->hw
.lin
.cmd
[LIN_SE_LINE_WIDTH
] = (GLuint
)(widthf
* 16.0);
583 if ( widthf
> 1.0 ) {
584 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_WIDELINE_ENABLE
;
586 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_WIDELINE_ENABLE
;
590 static void radeonLineStipple( GLcontext
*ctx
, GLint factor
, GLushort pattern
)
592 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
594 RADEON_STATECHANGE( rmesa
, lin
);
595 rmesa
->hw
.lin
.cmd
[LIN_RE_LINE_PATTERN
] =
596 ((((GLuint
)factor
& 0xff) << 16) | ((GLuint
)pattern
));
600 /* =============================================================
603 static void radeonColorMask( GLcontext
*ctx
,
604 GLboolean r
, GLboolean g
,
605 GLboolean b
, GLboolean a
)
607 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
608 GLuint mask
= radeonPackColor( rmesa
->radeonScreen
->cpp
,
609 ctx
->Color
.ColorMask
[RCOMP
],
610 ctx
->Color
.ColorMask
[GCOMP
],
611 ctx
->Color
.ColorMask
[BCOMP
],
612 ctx
->Color
.ColorMask
[ACOMP
] );
614 if ( rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
] != mask
) {
615 RADEON_STATECHANGE( rmesa
, msk
);
616 rmesa
->hw
.msk
.cmd
[MSK_RB3D_PLANEMASK
] = mask
;
621 /* =============================================================
625 static void radeonPolygonOffset( GLcontext
*ctx
,
626 GLfloat factor
, GLfloat units
)
628 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
629 float_ui32_type constant
= { units
* rmesa
->state
.depth
.scale
};
630 float_ui32_type factoru
= { factor
};
632 RADEON_STATECHANGE( rmesa
, zbs
);
633 rmesa
->hw
.zbs
.cmd
[ZBS_SE_ZBIAS_FACTOR
] = factoru
.ui32
;
634 rmesa
->hw
.zbs
.cmd
[ZBS_SE_ZBIAS_CONSTANT
] = constant
.ui32
;
637 static void radeonPolygonStipple( GLcontext
*ctx
, const GLubyte
*mask
)
639 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
641 drm_radeon_stipple_t stipple
;
643 /* Must flip pattern upside down.
645 for ( i
= 0 ; i
< 32 ; i
++ ) {
646 rmesa
->state
.stipple
.mask
[31 - i
] = ((GLuint
*) mask
)[i
];
649 /* TODO: push this into cmd mechanism
651 RADEON_FIREVERTICES( rmesa
);
652 LOCK_HARDWARE( rmesa
);
654 /* FIXME: Use window x,y offsets into stipple RAM.
656 stipple
.mask
= rmesa
->state
.stipple
.mask
;
657 drmCommandWrite( rmesa
->dri
.fd
, DRM_RADEON_STIPPLE
,
658 &stipple
, sizeof(drm_radeon_stipple_t
) );
659 UNLOCK_HARDWARE( rmesa
);
662 static void radeonPolygonMode( GLcontext
*ctx
, GLenum face
, GLenum mode
)
664 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
665 GLboolean flag
= (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
) != 0;
667 /* Can't generally do unfilled via tcl, but some good special
670 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_UNFILLED
, flag
);
671 if (rmesa
->TclFallback
) {
672 radeonChooseRenderState( ctx
);
673 radeonChooseVertexState( ctx
);
678 /* =============================================================
679 * Rendering attributes
681 * We really don't want to recalculate all this every time we bind a
682 * texture. These things shouldn't change all that often, so it makes
683 * sense to break them out of the core texture state update routines.
686 /* Examine lighting and texture state to determine if separate specular
689 static void radeonUpdateSpecular( GLcontext
*ctx
)
691 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
692 u_int32_t p
= rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
];
695 RADEON_STATECHANGE( rmesa
, tcl
);
697 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] &= ~RADEON_TCL_COMPUTE_SPECULAR
;
698 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] &= ~RADEON_TCL_COMPUTE_DIFFUSE
;
699 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] &= ~RADEON_TCL_VTX_PK_SPEC
;
700 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] &= ~RADEON_TCL_VTX_PK_DIFFUSE
;
701 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_LIGHTING_ENABLE
;
703 p
&= ~RADEON_SPECULAR_ENABLE
;
705 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_DIFFUSE_SPECULAR_COMBINE
;
708 if (ctx
->Light
.Enabled
&&
709 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
) {
710 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] |= RADEON_TCL_COMPUTE_SPECULAR
;
711 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] |= RADEON_TCL_COMPUTE_DIFFUSE
;
712 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_SPEC
;
713 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_DIFFUSE
;
714 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_LIGHTING_ENABLE
;
715 p
|= RADEON_SPECULAR_ENABLE
;
716 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &=
717 ~RADEON_DIFFUSE_SPECULAR_COMBINE
;
719 else if (ctx
->Light
.Enabled
) {
720 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] |= RADEON_TCL_COMPUTE_DIFFUSE
;
721 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_DIFFUSE
;
722 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_LIGHTING_ENABLE
;
723 } else if (ctx
->Fog
.ColorSumEnabled
) {
724 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_SPEC
;
725 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_DIFFUSE
;
726 p
|= RADEON_SPECULAR_ENABLE
;
728 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_DIFFUSE
;
731 if (ctx
->Fog
.Enabled
) {
732 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] |= RADEON_TCL_VTX_PK_SPEC
;
733 if (ctx
->Fog
.FogCoordinateSource
== GL_FRAGMENT_DEPTH
) {
734 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] |= RADEON_TCL_COMPUTE_SPECULAR
;
735 /* Bizzare: have to leave lighting enabled to get fog. */
736 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_LIGHTING_ENABLE
;
739 /* cannot do tcl fog factor calculation with fog coord source
740 * (send precomputed factors). Cannot use precomputed fog
741 * factors together with tcl spec light (need tcl fallback) */
742 flag
= (rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] &
743 RADEON_TCL_COMPUTE_SPECULAR
) != 0;
747 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_FOGCOORDSPEC
, flag
);
749 if (NEED_SECONDARY_COLOR(ctx
)) {
750 assert( (p
& RADEON_SPECULAR_ENABLE
) != 0 );
752 assert( (p
& RADEON_SPECULAR_ENABLE
) == 0 );
755 if ( rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] != p
) {
756 RADEON_STATECHANGE( rmesa
, ctx
);
757 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] = p
;
760 /* Update vertex/render formats
762 if (rmesa
->TclFallback
) {
763 radeonChooseRenderState( ctx
);
764 radeonChooseVertexState( ctx
);
769 /* =============================================================
774 /* Update on colormaterial, material emmissive/ambient,
775 * lightmodel.globalambient
777 static void update_global_ambient( GLcontext
*ctx
)
779 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
780 float *fcmd
= (float *)RADEON_DB_STATE( glt
);
782 /* Need to do more if both emmissive & ambient are PREMULT:
783 * Hope this is not needed for MULT
785 if ((rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &
786 ((3 << RADEON_EMISSIVE_SOURCE_SHIFT
) |
787 (3 << RADEON_AMBIENT_SOURCE_SHIFT
))) == 0)
789 COPY_3V( &fcmd
[GLT_RED
],
790 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_EMISSION
]);
791 ACC_SCALE_3V( &fcmd
[GLT_RED
],
792 ctx
->Light
.Model
.Ambient
,
793 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
]);
797 COPY_3V( &fcmd
[GLT_RED
], ctx
->Light
.Model
.Ambient
);
800 RADEON_DB_STATECHANGE(rmesa
, &rmesa
->hw
.glt
);
803 /* Update on change to
807 static void update_light_colors( GLcontext
*ctx
, GLuint p
)
809 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
811 /* fprintf(stderr, "%s\n", __FUNCTION__); */
814 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
815 float *fcmd
= (float *)RADEON_DB_STATE( lit
[p
] );
817 COPY_4V( &fcmd
[LIT_AMBIENT_RED
], l
->Ambient
);
818 COPY_4V( &fcmd
[LIT_DIFFUSE_RED
], l
->Diffuse
);
819 COPY_4V( &fcmd
[LIT_SPECULAR_RED
], l
->Specular
);
821 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.lit
[p
] );
825 /* Also fallback for asym colormaterial mode in twoside lighting...
827 static void check_twoside_fallback( GLcontext
*ctx
)
829 GLboolean fallback
= GL_FALSE
;
832 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
) {
833 if (ctx
->Light
.ColorMaterialEnabled
&&
834 (ctx
->Light
.ColorMaterialBitmask
& BACK_MATERIAL_BITS
) !=
835 ((ctx
->Light
.ColorMaterialBitmask
& FRONT_MATERIAL_BITS
)<<1))
838 for (i
= MAT_ATTRIB_FRONT_AMBIENT
; i
< MAT_ATTRIB_FRONT_INDEXES
; i
+=2)
839 if (memcmp( ctx
->Light
.Material
.Attrib
[i
],
840 ctx
->Light
.Material
.Attrib
[i
+1],
841 sizeof(GLfloat
)*4) != 0) {
848 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_LIGHT_TWOSIDE
, fallback
);
852 static void radeonColorMaterial( GLcontext
*ctx
, GLenum face
, GLenum mode
)
854 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
855 GLuint light_model_ctl1
= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
];
857 light_model_ctl1
&= ~((3 << RADEON_EMISSIVE_SOURCE_SHIFT
) |
858 (3 << RADEON_AMBIENT_SOURCE_SHIFT
) |
859 (3 << RADEON_DIFFUSE_SOURCE_SHIFT
) |
860 (3 << RADEON_SPECULAR_SOURCE_SHIFT
));
862 if (ctx
->Light
.ColorMaterialEnabled
) {
863 GLuint mask
= ctx
->Light
.ColorMaterialBitmask
;
865 if (mask
& MAT_BIT_FRONT_EMISSION
) {
866 light_model_ctl1
|= (RADEON_LM_SOURCE_VERTEX_DIFFUSE
<<
867 RADEON_EMISSIVE_SOURCE_SHIFT
);
870 light_model_ctl1
|= (RADEON_LM_SOURCE_STATE_MULT
<<
871 RADEON_EMISSIVE_SOURCE_SHIFT
);
874 if (mask
& MAT_BIT_FRONT_AMBIENT
) {
875 light_model_ctl1
|= (RADEON_LM_SOURCE_VERTEX_DIFFUSE
<<
876 RADEON_AMBIENT_SOURCE_SHIFT
);
879 light_model_ctl1
|= (RADEON_LM_SOURCE_STATE_MULT
<<
880 RADEON_AMBIENT_SOURCE_SHIFT
);
883 if (mask
& MAT_BIT_FRONT_DIFFUSE
) {
884 light_model_ctl1
|= (RADEON_LM_SOURCE_VERTEX_DIFFUSE
<<
885 RADEON_DIFFUSE_SOURCE_SHIFT
);
888 light_model_ctl1
|= (RADEON_LM_SOURCE_STATE_MULT
<<
889 RADEON_DIFFUSE_SOURCE_SHIFT
);
892 if (mask
& MAT_BIT_FRONT_SPECULAR
) {
893 light_model_ctl1
|= (RADEON_LM_SOURCE_VERTEX_DIFFUSE
<<
894 RADEON_SPECULAR_SOURCE_SHIFT
);
897 light_model_ctl1
|= (RADEON_LM_SOURCE_STATE_MULT
<<
898 RADEON_SPECULAR_SOURCE_SHIFT
);
904 light_model_ctl1
|= (RADEON_LM_SOURCE_STATE_MULT
<< RADEON_EMISSIVE_SOURCE_SHIFT
) |
905 (RADEON_LM_SOURCE_STATE_MULT
<< RADEON_AMBIENT_SOURCE_SHIFT
) |
906 (RADEON_LM_SOURCE_STATE_MULT
<< RADEON_DIFFUSE_SOURCE_SHIFT
) |
907 (RADEON_LM_SOURCE_STATE_MULT
<< RADEON_SPECULAR_SOURCE_SHIFT
);
910 if (light_model_ctl1
!= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
]) {
911 RADEON_STATECHANGE( rmesa
, tcl
);
912 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] = light_model_ctl1
;
916 void radeonUpdateMaterial( GLcontext
*ctx
)
918 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
919 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
920 GLfloat
*fcmd
= (GLfloat
*)RADEON_DB_STATE( mtl
);
923 if (ctx
->Light
.ColorMaterialEnabled
)
924 mask
&= ~ctx
->Light
.ColorMaterialBitmask
;
926 if (RADEON_DEBUG
& DEBUG_STATE
)
927 fprintf(stderr
, "%s\n", __FUNCTION__
);
930 if (mask
& MAT_BIT_FRONT_EMISSION
) {
931 fcmd
[MTL_EMMISSIVE_RED
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][0];
932 fcmd
[MTL_EMMISSIVE_GREEN
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][1];
933 fcmd
[MTL_EMMISSIVE_BLUE
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][2];
934 fcmd
[MTL_EMMISSIVE_ALPHA
] = mat
[MAT_ATTRIB_FRONT_EMISSION
][3];
936 if (mask
& MAT_BIT_FRONT_AMBIENT
) {
937 fcmd
[MTL_AMBIENT_RED
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][0];
938 fcmd
[MTL_AMBIENT_GREEN
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][1];
939 fcmd
[MTL_AMBIENT_BLUE
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][2];
940 fcmd
[MTL_AMBIENT_ALPHA
] = mat
[MAT_ATTRIB_FRONT_AMBIENT
][3];
942 if (mask
& MAT_BIT_FRONT_DIFFUSE
) {
943 fcmd
[MTL_DIFFUSE_RED
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][0];
944 fcmd
[MTL_DIFFUSE_GREEN
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][1];
945 fcmd
[MTL_DIFFUSE_BLUE
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][2];
946 fcmd
[MTL_DIFFUSE_ALPHA
] = mat
[MAT_ATTRIB_FRONT_DIFFUSE
][3];
948 if (mask
& MAT_BIT_FRONT_SPECULAR
) {
949 fcmd
[MTL_SPECULAR_RED
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][0];
950 fcmd
[MTL_SPECULAR_GREEN
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][1];
951 fcmd
[MTL_SPECULAR_BLUE
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][2];
952 fcmd
[MTL_SPECULAR_ALPHA
] = mat
[MAT_ATTRIB_FRONT_SPECULAR
][3];
954 if (mask
& MAT_BIT_FRONT_SHININESS
) {
955 fcmd
[MTL_SHININESS
] = mat
[MAT_ATTRIB_FRONT_SHININESS
][0];
958 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mtl
);
960 check_twoside_fallback( ctx
);
961 /* update_global_ambient( ctx );*/
966 * _MESA_NEW_NEED_EYE_COORDS
968 * Uses derived state from mesa:
977 * which are calculated in light.c and are correct for the current
978 * lighting space (model or eye), hence dependencies on _NEW_MODELVIEW
979 * and _MESA_NEW_NEED_EYE_COORDS.
981 static void update_light( GLcontext
*ctx
)
983 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
985 /* Have to check these, or have an automatic shortcircuit mechanism
986 * to remove noop statechanges. (Or just do a better job on the
990 GLuint tmp
= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
];
992 if (ctx
->_NeedEyeCoords
)
993 tmp
&= ~RADEON_LIGHT_IN_MODELSPACE
;
995 tmp
|= RADEON_LIGHT_IN_MODELSPACE
;
998 /* Leave this test disabled: (unexplained q3 lockup) (even with
1001 if (tmp
!= rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
])
1003 RADEON_STATECHANGE( rmesa
, tcl
);
1004 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] = tmp
;
1009 GLfloat
*fcmd
= (GLfloat
*)RADEON_DB_STATE( eye
);
1010 fcmd
[EYE_X
] = ctx
->_EyeZDir
[0];
1011 fcmd
[EYE_Y
] = ctx
->_EyeZDir
[1];
1012 fcmd
[EYE_Z
] = - ctx
->_EyeZDir
[2];
1013 fcmd
[EYE_RESCALE_FACTOR
] = ctx
->_ModelViewInvScale
;
1014 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.eye
);
1019 if (ctx
->Light
.Enabled
) {
1021 for (p
= 0 ; p
< MAX_LIGHTS
; p
++) {
1022 if (ctx
->Light
.Light
[p
].Enabled
) {
1023 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
1024 GLfloat
*fcmd
= (GLfloat
*)RADEON_DB_STATE( lit
[p
] );
1026 if (l
->EyePosition
[3] == 0.0) {
1027 COPY_3FV( &fcmd
[LIT_POSITION_X
], l
->_VP_inf_norm
);
1028 COPY_3FV( &fcmd
[LIT_DIRECTION_X
], l
->_h_inf_norm
);
1029 fcmd
[LIT_POSITION_W
] = 0;
1030 fcmd
[LIT_DIRECTION_W
] = 0;
1032 COPY_4V( &fcmd
[LIT_POSITION_X
], l
->_Position
);
1033 fcmd
[LIT_DIRECTION_X
] = -l
->_NormDirection
[0];
1034 fcmd
[LIT_DIRECTION_Y
] = -l
->_NormDirection
[1];
1035 fcmd
[LIT_DIRECTION_Z
] = -l
->_NormDirection
[2];
1036 fcmd
[LIT_DIRECTION_W
] = 0;
1039 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.lit
[p
] );
1045 static void radeonLightfv( GLcontext
*ctx
, GLenum light
,
1046 GLenum pname
, const GLfloat
*params
)
1048 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1049 GLint p
= light
- GL_LIGHT0
;
1050 struct gl_light
*l
= &ctx
->Light
.Light
[p
];
1051 GLfloat
*fcmd
= (GLfloat
*)rmesa
->hw
.lit
[p
].cmd
;
1058 update_light_colors( ctx
, p
);
1061 case GL_SPOT_DIRECTION
:
1062 /* picked up in update_light */
1066 /* positions picked up in update_light, but can do flag here */
1068 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1070 /* FIXME: Set RANGE_ATTEN only when needed */
1072 flag
= RADEON_LIGHT_1_IS_LOCAL
;
1074 flag
= RADEON_LIGHT_0_IS_LOCAL
;
1076 RADEON_STATECHANGE(rmesa
, tcl
);
1077 if (l
->EyePosition
[3] != 0.0F
)
1078 rmesa
->hw
.tcl
.cmd
[idx
] |= flag
;
1080 rmesa
->hw
.tcl
.cmd
[idx
] &= ~flag
;
1084 case GL_SPOT_EXPONENT
:
1085 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1086 fcmd
[LIT_SPOT_EXPONENT
] = params
[0];
1089 case GL_SPOT_CUTOFF
: {
1090 GLuint flag
= (p
&1) ? RADEON_LIGHT_1_IS_SPOT
: RADEON_LIGHT_0_IS_SPOT
;
1091 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1093 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1094 fcmd
[LIT_SPOT_CUTOFF
] = l
->_CosCutoff
;
1096 RADEON_STATECHANGE(rmesa
, tcl
);
1097 if (l
->SpotCutoff
!= 180.0F
)
1098 rmesa
->hw
.tcl
.cmd
[idx
] |= flag
;
1100 rmesa
->hw
.tcl
.cmd
[idx
] &= ~flag
;
1105 case GL_CONSTANT_ATTENUATION
:
1106 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1107 fcmd
[LIT_ATTEN_CONST
] = params
[0];
1108 if ( params
[0] == 0.0 )
1109 fcmd
[LIT_ATTEN_CONST_INV
] = FLT_MAX
;
1111 fcmd
[LIT_ATTEN_CONST_INV
] = 1.0 / params
[0];
1113 case GL_LINEAR_ATTENUATION
:
1114 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1115 fcmd
[LIT_ATTEN_LINEAR
] = params
[0];
1117 case GL_QUADRATIC_ATTENUATION
:
1118 RADEON_STATECHANGE(rmesa
, lit
[p
]);
1119 fcmd
[LIT_ATTEN_QUADRATIC
] = params
[0];
1125 /* Set RANGE_ATTEN only when needed */
1128 case GL_CONSTANT_ATTENUATION
:
1129 case GL_LINEAR_ATTENUATION
:
1130 case GL_QUADRATIC_ATTENUATION
:
1132 GLuint
*icmd
= (GLuint
*)RADEON_DB_STATE( tcl
);
1133 GLuint idx
= TCL_PER_LIGHT_CTL_0
+ p
/2;
1134 GLuint atten_flag
= ( p
&1 ) ? RADEON_LIGHT_1_ENABLE_RANGE_ATTEN
1135 : RADEON_LIGHT_0_ENABLE_RANGE_ATTEN
;
1136 GLuint atten_const_flag
= ( p
&1 ) ? RADEON_LIGHT_1_CONSTANT_RANGE_ATTEN
1137 : RADEON_LIGHT_0_CONSTANT_RANGE_ATTEN
;
1139 if ( l
->EyePosition
[3] == 0.0F
||
1140 ( ( fcmd
[LIT_ATTEN_CONST
] == 0.0 || fcmd
[LIT_ATTEN_CONST
] == 1.0 ) &&
1141 fcmd
[LIT_ATTEN_QUADRATIC
] == 0.0 && fcmd
[LIT_ATTEN_LINEAR
] == 0.0 ) ) {
1142 /* Disable attenuation */
1143 icmd
[idx
] &= ~atten_flag
;
1145 if ( fcmd
[LIT_ATTEN_QUADRATIC
] == 0.0 && fcmd
[LIT_ATTEN_LINEAR
] == 0.0 ) {
1146 /* Enable only constant portion of attenuation calculation */
1147 icmd
[idx
] |= ( atten_flag
| atten_const_flag
);
1149 /* Enable full attenuation calculation */
1150 icmd
[idx
] &= ~atten_const_flag
;
1151 icmd
[idx
] |= atten_flag
;
1155 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.tcl
);
1166 static void radeonLightModelfv( GLcontext
*ctx
, GLenum pname
,
1167 const GLfloat
*param
)
1169 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1172 case GL_LIGHT_MODEL_AMBIENT
:
1173 update_global_ambient( ctx
);
1176 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
1177 RADEON_STATECHANGE( rmesa
, tcl
);
1178 if (ctx
->Light
.Model
.LocalViewer
)
1179 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_LOCAL_VIEWER
;
1181 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_LOCAL_VIEWER
;
1184 case GL_LIGHT_MODEL_TWO_SIDE
:
1185 RADEON_STATECHANGE( rmesa
, tcl
);
1186 if (ctx
->Light
.Model
.TwoSide
)
1187 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= RADEON_LIGHT_TWOSIDE
;
1189 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~RADEON_LIGHT_TWOSIDE
;
1191 check_twoside_fallback( ctx
);
1193 if (rmesa
->TclFallback
) {
1194 radeonChooseRenderState( ctx
);
1195 radeonChooseVertexState( ctx
);
1199 case GL_LIGHT_MODEL_COLOR_CONTROL
:
1200 radeonUpdateSpecular(ctx
);
1208 static void radeonShadeModel( GLcontext
*ctx
, GLenum mode
)
1210 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1211 GLuint s
= rmesa
->hw
.set
.cmd
[SET_SE_CNTL
];
1213 s
&= ~(RADEON_DIFFUSE_SHADE_MASK
|
1214 RADEON_ALPHA_SHADE_MASK
|
1215 RADEON_SPECULAR_SHADE_MASK
|
1216 RADEON_FOG_SHADE_MASK
);
1220 s
|= (RADEON_DIFFUSE_SHADE_FLAT
|
1221 RADEON_ALPHA_SHADE_FLAT
|
1222 RADEON_SPECULAR_SHADE_FLAT
|
1223 RADEON_FOG_SHADE_FLAT
);
1226 s
|= (RADEON_DIFFUSE_SHADE_GOURAUD
|
1227 RADEON_ALPHA_SHADE_GOURAUD
|
1228 RADEON_SPECULAR_SHADE_GOURAUD
|
1229 RADEON_FOG_SHADE_GOURAUD
);
1235 if ( rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] != s
) {
1236 RADEON_STATECHANGE( rmesa
, set
);
1237 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] = s
;
1242 /* =============================================================
1246 static void radeonClipPlane( GLcontext
*ctx
, GLenum plane
, const GLfloat
*eq
)
1248 GLint p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
1249 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1250 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
1252 RADEON_STATECHANGE( rmesa
, ucp
[p
] );
1253 rmesa
->hw
.ucp
[p
].cmd
[UCP_X
] = ip
[0];
1254 rmesa
->hw
.ucp
[p
].cmd
[UCP_Y
] = ip
[1];
1255 rmesa
->hw
.ucp
[p
].cmd
[UCP_Z
] = ip
[2];
1256 rmesa
->hw
.ucp
[p
].cmd
[UCP_W
] = ip
[3];
1259 static void radeonUpdateClipPlanes( GLcontext
*ctx
)
1261 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1264 for (p
= 0; p
< ctx
->Const
.MaxClipPlanes
; p
++) {
1265 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
1266 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
1268 RADEON_STATECHANGE( rmesa
, ucp
[p
] );
1269 rmesa
->hw
.ucp
[p
].cmd
[UCP_X
] = ip
[0];
1270 rmesa
->hw
.ucp
[p
].cmd
[UCP_Y
] = ip
[1];
1271 rmesa
->hw
.ucp
[p
].cmd
[UCP_Z
] = ip
[2];
1272 rmesa
->hw
.ucp
[p
].cmd
[UCP_W
] = ip
[3];
1278 /* =============================================================
1283 radeonStencilFuncSeparate( GLcontext
*ctx
, GLenum face
, GLenum func
,
1284 GLint ref
, GLuint mask
)
1286 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1287 GLuint refmask
= (((ctx
->Stencil
.Ref
[0] & 0xff) << RADEON_STENCIL_REF_SHIFT
) |
1288 ((ctx
->Stencil
.ValueMask
[0] & 0xff) << RADEON_STENCIL_MASK_SHIFT
));
1290 RADEON_STATECHANGE( rmesa
, ctx
);
1291 RADEON_STATECHANGE( rmesa
, msk
);
1293 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~RADEON_STENCIL_TEST_MASK
;
1294 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] &= ~(RADEON_STENCIL_REF_MASK
|
1295 RADEON_STENCIL_VALUE_MASK
);
1297 switch ( ctx
->Stencil
.Function
[0] ) {
1299 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_NEVER
;
1302 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_LESS
;
1305 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_EQUAL
;
1308 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_LEQUAL
;
1311 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_GREATER
;
1314 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_NEQUAL
;
1317 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_GEQUAL
;
1320 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_TEST_ALWAYS
;
1324 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] |= refmask
;
1328 radeonStencilMaskSeparate( GLcontext
*ctx
, GLenum face
, GLuint mask
)
1330 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1332 RADEON_STATECHANGE( rmesa
, msk
);
1333 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] &= ~RADEON_STENCIL_WRITE_MASK
;
1334 rmesa
->hw
.msk
.cmd
[MSK_RB3D_STENCILREFMASK
] |=
1335 ((ctx
->Stencil
.WriteMask
[0] & 0xff) << RADEON_STENCIL_WRITEMASK_SHIFT
);
1338 static void radeonStencilOpSeparate( GLcontext
*ctx
, GLenum face
, GLenum fail
,
1339 GLenum zfail
, GLenum zpass
)
1341 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1343 /* radeon 7200 have stencil bug, DEC and INC_WRAP will actually both do DEC_WRAP,
1344 and DEC_WRAP (and INVERT) will do INVERT. No way to get correct INC_WRAP and DEC,
1345 but DEC_WRAP can be fixed by using DEC and INC_WRAP at least use INC. */
1347 GLuint tempRADEON_STENCIL_FAIL_DEC_WRAP
;
1348 GLuint tempRADEON_STENCIL_FAIL_INC_WRAP
;
1349 GLuint tempRADEON_STENCIL_ZFAIL_DEC_WRAP
;
1350 GLuint tempRADEON_STENCIL_ZFAIL_INC_WRAP
;
1351 GLuint tempRADEON_STENCIL_ZPASS_DEC_WRAP
;
1352 GLuint tempRADEON_STENCIL_ZPASS_INC_WRAP
;
1354 if (rmesa
->radeonScreen
->chip_flags
& RADEON_CHIPSET_BROKEN_STENCIL
) {
1355 tempRADEON_STENCIL_FAIL_DEC_WRAP
= RADEON_STENCIL_FAIL_DEC
;
1356 tempRADEON_STENCIL_FAIL_INC_WRAP
= RADEON_STENCIL_FAIL_INC
;
1357 tempRADEON_STENCIL_ZFAIL_DEC_WRAP
= RADEON_STENCIL_ZFAIL_DEC
;
1358 tempRADEON_STENCIL_ZFAIL_INC_WRAP
= RADEON_STENCIL_ZFAIL_INC
;
1359 tempRADEON_STENCIL_ZPASS_DEC_WRAP
= RADEON_STENCIL_ZPASS_DEC
;
1360 tempRADEON_STENCIL_ZPASS_INC_WRAP
= RADEON_STENCIL_ZPASS_INC
;
1363 tempRADEON_STENCIL_FAIL_DEC_WRAP
= RADEON_STENCIL_FAIL_DEC_WRAP
;
1364 tempRADEON_STENCIL_FAIL_INC_WRAP
= RADEON_STENCIL_FAIL_INC_WRAP
;
1365 tempRADEON_STENCIL_ZFAIL_DEC_WRAP
= RADEON_STENCIL_ZFAIL_DEC_WRAP
;
1366 tempRADEON_STENCIL_ZFAIL_INC_WRAP
= RADEON_STENCIL_ZFAIL_INC_WRAP
;
1367 tempRADEON_STENCIL_ZPASS_DEC_WRAP
= RADEON_STENCIL_ZPASS_DEC_WRAP
;
1368 tempRADEON_STENCIL_ZPASS_INC_WRAP
= RADEON_STENCIL_ZPASS_INC_WRAP
;
1371 RADEON_STATECHANGE( rmesa
, ctx
);
1372 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] &= ~(RADEON_STENCIL_FAIL_MASK
|
1373 RADEON_STENCIL_ZFAIL_MASK
|
1374 RADEON_STENCIL_ZPASS_MASK
);
1376 switch ( ctx
->Stencil
.FailFunc
[0] ) {
1378 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_KEEP
;
1381 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_ZERO
;
1384 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_REPLACE
;
1387 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_INC
;
1390 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_DEC
;
1393 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= tempRADEON_STENCIL_FAIL_INC_WRAP
;
1396 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= tempRADEON_STENCIL_FAIL_DEC_WRAP
;
1399 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_FAIL_INVERT
;
1403 switch ( ctx
->Stencil
.ZFailFunc
[0] ) {
1405 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_KEEP
;
1408 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_ZERO
;
1411 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_REPLACE
;
1414 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_INC
;
1417 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_DEC
;
1420 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= tempRADEON_STENCIL_ZFAIL_INC_WRAP
;
1423 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= tempRADEON_STENCIL_ZFAIL_DEC_WRAP
;
1426 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZFAIL_INVERT
;
1430 switch ( ctx
->Stencil
.ZPassFunc
[0] ) {
1432 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_KEEP
;
1435 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_ZERO
;
1438 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_REPLACE
;
1441 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_INC
;
1444 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_DEC
;
1447 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= tempRADEON_STENCIL_ZPASS_INC_WRAP
;
1450 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= tempRADEON_STENCIL_ZPASS_DEC_WRAP
;
1453 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_ZSTENCILCNTL
] |= RADEON_STENCIL_ZPASS_INVERT
;
1458 static void radeonClearStencil( GLcontext
*ctx
, GLint s
)
1460 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1462 rmesa
->state
.stencil
.clear
=
1463 ((GLuint
) (ctx
->Stencil
.Clear
& 0xff) |
1464 (0xff << RADEON_STENCIL_MASK_SHIFT
) |
1465 ((ctx
->Stencil
.WriteMask
[0] & 0xff) << RADEON_STENCIL_WRITEMASK_SHIFT
));
1469 /* =============================================================
1470 * Window position and viewport transformation
1474 * To correctly position primitives:
1476 #define SUBPIXEL_X 0.125
1477 #define SUBPIXEL_Y 0.125
1481 * Called when window size or position changes or viewport or depth range
1482 * state is changed. We update the hardware viewport state here.
1484 void radeonUpdateWindow( GLcontext
*ctx
)
1486 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1487 __DRIdrawablePrivate
*dPriv
= rmesa
->dri
.drawable
;
1488 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1489 GLfloat yoffset
= (GLfloat
)dPriv
->y
+ dPriv
->h
;
1490 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1492 float_ui32_type sx
= { v
[MAT_SX
] };
1493 float_ui32_type tx
= { v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
};
1494 float_ui32_type sy
= { - v
[MAT_SY
] };
1495 float_ui32_type ty
= { (- v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
};
1496 float_ui32_type sz
= { v
[MAT_SZ
] * rmesa
->state
.depth
.scale
};
1497 float_ui32_type tz
= { v
[MAT_TZ
] * rmesa
->state
.depth
.scale
};
1499 RADEON_FIREVERTICES( rmesa
);
1500 RADEON_STATECHANGE( rmesa
, vpt
);
1502 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XSCALE
] = sx
.ui32
;
1503 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] = tx
.ui32
;
1504 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YSCALE
] = sy
.ui32
;
1505 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] = ty
.ui32
;
1506 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_ZSCALE
] = sz
.ui32
;
1507 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_ZOFFSET
] = tz
.ui32
;
1511 static void radeonViewport( GLcontext
*ctx
, GLint x
, GLint y
,
1512 GLsizei width
, GLsizei height
)
1514 /* Don't pipeline viewport changes, conflict with window offset
1515 * setting below. Could apply deltas to rescue pipelined viewport
1516 * values, or keep the originals hanging around.
1518 radeonUpdateWindow( ctx
);
1521 static void radeonDepthRange( GLcontext
*ctx
, GLclampd nearval
,
1524 radeonUpdateWindow( ctx
);
1527 void radeonUpdateViewportOffset( GLcontext
*ctx
)
1529 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1530 __DRIdrawablePrivate
*dPriv
= rmesa
->dri
.drawable
;
1531 GLfloat xoffset
= (GLfloat
)dPriv
->x
;
1532 GLfloat yoffset
= (GLfloat
)dPriv
->y
+ dPriv
->h
;
1533 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1538 tx
.f
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
1539 ty
.f
= (- v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
1541 if ( rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] != tx
.ui32
||
1542 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] != ty
.ui32
)
1544 /* Note: this should also modify whatever data the context reset
1547 RADEON_STATECHANGE( rmesa
, vpt
);
1548 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_XOFFSET
] = tx
.ui32
;
1549 rmesa
->hw
.vpt
.cmd
[VPT_SE_VPORT_YOFFSET
] = ty
.ui32
;
1551 /* update polygon stipple x/y screen offset */
1554 GLuint m
= rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
];
1556 m
&= ~(RADEON_STIPPLE_X_OFFSET_MASK
|
1557 RADEON_STIPPLE_Y_OFFSET_MASK
);
1559 /* add magic offsets, then invert */
1560 stx
= 31 - ((rmesa
->dri
.drawable
->x
- 1) & RADEON_STIPPLE_COORD_MASK
);
1561 sty
= 31 - ((rmesa
->dri
.drawable
->y
+ rmesa
->dri
.drawable
->h
- 1)
1562 & RADEON_STIPPLE_COORD_MASK
);
1564 m
|= ((stx
<< RADEON_STIPPLE_X_OFFSET_SHIFT
) |
1565 (sty
<< RADEON_STIPPLE_Y_OFFSET_SHIFT
));
1567 if ( rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
] != m
) {
1568 RADEON_STATECHANGE( rmesa
, msc
);
1569 rmesa
->hw
.msc
.cmd
[MSC_RE_MISC
] = m
;
1574 radeonUpdateScissor( ctx
);
1579 /* =============================================================
1583 static void radeonClearColor( GLcontext
*ctx
, const GLfloat color
[4] )
1585 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1587 CLAMPED_FLOAT_TO_UBYTE(c
[0], color
[0]);
1588 CLAMPED_FLOAT_TO_UBYTE(c
[1], color
[1]);
1589 CLAMPED_FLOAT_TO_UBYTE(c
[2], color
[2]);
1590 CLAMPED_FLOAT_TO_UBYTE(c
[3], color
[3]);
1591 rmesa
->state
.color
.clear
= radeonPackColor( rmesa
->radeonScreen
->cpp
,
1592 c
[0], c
[1], c
[2], c
[3] );
1596 static void radeonRenderMode( GLcontext
*ctx
, GLenum mode
)
1598 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1599 FALLBACK( rmesa
, RADEON_FALLBACK_RENDER_MODE
, (mode
!= GL_RENDER
) );
1603 static GLuint radeon_rop_tab
[] = {
1606 RADEON_ROP_AND_REVERSE
,
1608 RADEON_ROP_AND_INVERTED
,
1615 RADEON_ROP_OR_REVERSE
,
1616 RADEON_ROP_COPY_INVERTED
,
1617 RADEON_ROP_OR_INVERTED
,
1622 static void radeonLogicOpCode( GLcontext
*ctx
, GLenum opcode
)
1624 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1625 GLuint rop
= (GLuint
)opcode
- GL_CLEAR
;
1629 RADEON_STATECHANGE( rmesa
, msk
);
1630 rmesa
->hw
.msk
.cmd
[MSK_RB3D_ROPCNTL
] = radeon_rop_tab
[rop
];
1635 * Set up the cliprects for either front or back-buffer drawing.
1637 void radeonSetCliprects( radeonContextPtr rmesa
)
1639 __DRIdrawablePrivate
*const drawable
= rmesa
->dri
.drawable
;
1640 __DRIdrawablePrivate
*const readable
= rmesa
->dri
.readable
;
1641 GLframebuffer
*const draw_fb
= (GLframebuffer
*) drawable
->driverPrivate
;
1642 GLframebuffer
*const read_fb
= (GLframebuffer
*) readable
->driverPrivate
;
1644 if (draw_fb
->_ColorDrawBufferMask
[0]
1645 == BUFFER_BIT_BACK_LEFT
) {
1646 /* Can't ignore 2d windows if we are page flipping.
1648 if ( drawable
->numBackClipRects
== 0 || rmesa
->doPageFlip
) {
1649 rmesa
->numClipRects
= drawable
->numClipRects
;
1650 rmesa
->pClipRects
= drawable
->pClipRects
;
1653 rmesa
->numClipRects
= drawable
->numBackClipRects
;
1654 rmesa
->pClipRects
= drawable
->pBackClipRects
;
1658 /* front buffer (or none, or multiple buffers */
1659 rmesa
->numClipRects
= drawable
->numClipRects
;
1660 rmesa
->pClipRects
= drawable
->pClipRects
;
1663 if ((draw_fb
->Width
!= drawable
->w
) || (draw_fb
->Height
!= drawable
->h
)) {
1664 _mesa_resize_framebuffer(rmesa
->glCtx
, draw_fb
,
1665 drawable
->w
, drawable
->h
);
1666 draw_fb
->Initialized
= GL_TRUE
;
1669 if (drawable
!= readable
) {
1670 if ((read_fb
->Width
!= readable
->w
) || (read_fb
->Height
!= readable
->h
)) {
1671 _mesa_resize_framebuffer(rmesa
->glCtx
, read_fb
,
1672 readable
->w
, readable
->h
);
1673 read_fb
->Initialized
= GL_TRUE
;
1677 if (rmesa
->state
.scissor
.enabled
)
1678 radeonRecalcScissorRects( rmesa
);
1683 * Called via glDrawBuffer.
1685 static void radeonDrawBuffer( GLcontext
*ctx
, GLenum mode
)
1687 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1689 if (RADEON_DEBUG
& DEBUG_DRI
)
1690 fprintf(stderr
, "%s %s\n", __FUNCTION__
,
1691 _mesa_lookup_enum_by_nr( mode
));
1693 RADEON_FIREVERTICES(rmesa
); /* don't pipeline cliprect changes */
1696 * _ColorDrawBufferMask is easier to cope with than <mode>.
1697 * Check for software fallback, update cliprects.
1699 switch ( ctx
->DrawBuffer
->_ColorDrawBufferMask
[0] ) {
1700 case BUFFER_BIT_FRONT_LEFT
:
1701 case BUFFER_BIT_BACK_LEFT
:
1702 FALLBACK( rmesa
, RADEON_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
1705 /* 0 (GL_NONE) buffers or multiple color drawing buffers */
1706 FALLBACK( rmesa
, RADEON_FALLBACK_DRAW_BUFFER
, GL_TRUE
);
1710 radeonSetCliprects( rmesa
);
1712 /* We'll set the drawing engine's offset/pitch parameters later
1713 * when we update other state.
1717 static void radeonReadBuffer( GLcontext
*ctx
, GLenum mode
)
1719 /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
1723 /* =============================================================
1724 * State enable/disable
1727 static void radeonEnable( GLcontext
*ctx
, GLenum cap
, GLboolean state
)
1729 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
1732 if ( RADEON_DEBUG
& DEBUG_STATE
)
1733 fprintf( stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1734 _mesa_lookup_enum_by_nr( cap
),
1735 state
? "GL_TRUE" : "GL_FALSE" );
1738 /* Fast track this one...
1746 RADEON_STATECHANGE( rmesa
, ctx
);
1748 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_ALPHA_TEST_ENABLE
;
1750 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_ALPHA_TEST_ENABLE
;
1755 RADEON_STATECHANGE( rmesa
, ctx
);
1757 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_ALPHA_BLEND_ENABLE
;
1759 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_ALPHA_BLEND_ENABLE
;
1761 if ( (ctx
->Color
.ColorLogicOpEnabled
|| (ctx
->Color
.BlendEnabled
1762 && ctx
->Color
.BlendEquationRGB
== GL_LOGIC_OP
)) ) {
1763 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_ROP_ENABLE
;
1765 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_ROP_ENABLE
;
1768 /* Catch a possible fallback:
1771 ctx
->Driver
.BlendEquationSeparate( ctx
,
1772 ctx
->Color
.BlendEquationRGB
,
1773 ctx
->Color
.BlendEquationA
);
1774 ctx
->Driver
.BlendFuncSeparate( ctx
, ctx
->Color
.BlendSrcRGB
,
1775 ctx
->Color
.BlendDstRGB
,
1776 ctx
->Color
.BlendSrcA
,
1777 ctx
->Color
.BlendDstA
);
1780 FALLBACK( rmesa
, RADEON_FALLBACK_BLEND_FUNC
, GL_FALSE
);
1781 FALLBACK( rmesa
, RADEON_FALLBACK_BLEND_EQ
, GL_FALSE
);
1785 case GL_CLIP_PLANE0
:
1786 case GL_CLIP_PLANE1
:
1787 case GL_CLIP_PLANE2
:
1788 case GL_CLIP_PLANE3
:
1789 case GL_CLIP_PLANE4
:
1790 case GL_CLIP_PLANE5
:
1791 p
= cap
-GL_CLIP_PLANE0
;
1792 RADEON_STATECHANGE( rmesa
, tcl
);
1794 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] |= (RADEON_UCP_ENABLE_0
<<p
);
1795 radeonClipPlane( ctx
, cap
, NULL
);
1798 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~(RADEON_UCP_ENABLE_0
<<p
);
1802 case GL_COLOR_MATERIAL
:
1803 radeonColorMaterial( ctx
, 0, 0 );
1804 radeonUpdateMaterial( ctx
);
1808 radeonCullFace( ctx
, 0 );
1812 RADEON_STATECHANGE(rmesa
, ctx
);
1814 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_Z_ENABLE
;
1816 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_Z_ENABLE
;
1821 RADEON_STATECHANGE(rmesa
, ctx
);
1823 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_DITHER_ENABLE
;
1824 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~rmesa
->state
.color
.roundEnable
;
1826 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_DITHER_ENABLE
;
1827 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= rmesa
->state
.color
.roundEnable
;
1832 RADEON_STATECHANGE(rmesa
, ctx
);
1834 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_FOG_ENABLE
;
1835 radeonFogfv( ctx
, GL_FOG_MODE
, NULL
);
1837 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_FOG_ENABLE
;
1838 RADEON_STATECHANGE(rmesa
, tcl
);
1839 rmesa
->hw
.tcl
.cmd
[TCL_UCP_VERT_BLEND_CTL
] &= ~RADEON_TCL_FOG_MASK
;
1841 radeonUpdateSpecular( ctx
); /* for PK_SPEC */
1842 _mesa_allow_light_in_model( ctx
, !state
);
1853 RADEON_STATECHANGE(rmesa
, tcl
);
1854 p
= cap
- GL_LIGHT0
;
1856 flag
= (RADEON_LIGHT_1_ENABLE
|
1857 RADEON_LIGHT_1_ENABLE_AMBIENT
|
1858 RADEON_LIGHT_1_ENABLE_SPECULAR
);
1860 flag
= (RADEON_LIGHT_0_ENABLE
|
1861 RADEON_LIGHT_0_ENABLE_AMBIENT
|
1862 RADEON_LIGHT_0_ENABLE_SPECULAR
);
1865 rmesa
->hw
.tcl
.cmd
[p
/2 + TCL_PER_LIGHT_CTL_0
] |= flag
;
1867 rmesa
->hw
.tcl
.cmd
[p
/2 + TCL_PER_LIGHT_CTL_0
] &= ~flag
;
1871 update_light_colors( ctx
, p
);
1875 RADEON_STATECHANGE(rmesa
, tcl
);
1876 radeonUpdateSpecular(ctx
);
1877 check_twoside_fallback( ctx
);
1880 case GL_LINE_SMOOTH
:
1881 RADEON_STATECHANGE( rmesa
, ctx
);
1883 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_ANTI_ALIAS_LINE
;
1885 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_ANTI_ALIAS_LINE
;
1889 case GL_LINE_STIPPLE
:
1890 RADEON_STATECHANGE( rmesa
, ctx
);
1892 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_PATTERN_ENABLE
;
1894 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_PATTERN_ENABLE
;
1898 case GL_COLOR_LOGIC_OP
:
1899 RADEON_STATECHANGE( rmesa
, ctx
);
1900 if ( (ctx
->Color
.ColorLogicOpEnabled
|| (ctx
->Color
.BlendEnabled
1901 && ctx
->Color
.BlendEquationRGB
== GL_LOGIC_OP
)) ) {
1902 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_ROP_ENABLE
;
1904 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_ROP_ENABLE
;
1909 RADEON_STATECHANGE( rmesa
, tcl
);
1911 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_NORMALIZE_NORMALS
;
1913 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_NORMALIZE_NORMALS
;
1917 case GL_POLYGON_OFFSET_POINT
:
1918 RADEON_STATECHANGE( rmesa
, set
);
1920 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_ZBIAS_ENABLE_POINT
;
1922 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_ZBIAS_ENABLE_POINT
;
1926 case GL_POLYGON_OFFSET_LINE
:
1927 RADEON_STATECHANGE( rmesa
, set
);
1929 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_ZBIAS_ENABLE_LINE
;
1931 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_ZBIAS_ENABLE_LINE
;
1935 case GL_POLYGON_OFFSET_FILL
:
1936 RADEON_STATECHANGE( rmesa
, set
);
1938 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] |= RADEON_ZBIAS_ENABLE_TRI
;
1940 rmesa
->hw
.set
.cmd
[SET_SE_CNTL
] &= ~RADEON_ZBIAS_ENABLE_TRI
;
1944 case GL_POLYGON_SMOOTH
:
1945 RADEON_STATECHANGE( rmesa
, ctx
);
1947 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_ANTI_ALIAS_POLY
;
1949 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_ANTI_ALIAS_POLY
;
1953 case GL_POLYGON_STIPPLE
:
1954 RADEON_STATECHANGE(rmesa
, ctx
);
1956 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= RADEON_STIPPLE_ENABLE
;
1958 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~RADEON_STIPPLE_ENABLE
;
1962 case GL_RESCALE_NORMAL_EXT
: {
1963 GLboolean tmp
= ctx
->_NeedEyeCoords
? state
: !state
;
1964 RADEON_STATECHANGE( rmesa
, tcl
);
1966 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_RESCALE_NORMALS
;
1968 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_RESCALE_NORMALS
;
1973 case GL_SCISSOR_TEST
:
1974 RADEON_FIREVERTICES( rmesa
);
1975 rmesa
->state
.scissor
.enabled
= state
;
1976 radeonUpdateScissor( ctx
);
1979 case GL_STENCIL_TEST
:
1980 if ( rmesa
->state
.stencil
.hwBuffer
) {
1981 RADEON_STATECHANGE( rmesa
, ctx
);
1983 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] |= RADEON_STENCIL_ENABLE
;
1985 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &= ~RADEON_STENCIL_ENABLE
;
1988 FALLBACK( rmesa
, RADEON_FALLBACK_STENCIL
, state
);
1992 case GL_TEXTURE_GEN_Q
:
1993 case GL_TEXTURE_GEN_R
:
1994 case GL_TEXTURE_GEN_S
:
1995 case GL_TEXTURE_GEN_T
:
1996 /* Picked up in radeonUpdateTextureState.
1998 rmesa
->recheck_texgen
[ctx
->Texture
.CurrentUnit
] = GL_TRUE
;
2001 case GL_COLOR_SUM_EXT
:
2002 radeonUpdateSpecular ( ctx
);
2011 static void radeonLightingSpaceChange( GLcontext
*ctx
)
2013 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
2015 RADEON_STATECHANGE( rmesa
, tcl
);
2017 if (RADEON_DEBUG
& DEBUG_STATE
)
2018 fprintf(stderr
, "%s %d BEFORE %x\n", __FUNCTION__
, ctx
->_NeedEyeCoords
,
2019 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
]);
2021 if (ctx
->_NeedEyeCoords
)
2022 tmp
= ctx
->Transform
.RescaleNormals
;
2024 tmp
= !ctx
->Transform
.RescaleNormals
;
2027 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] |= RADEON_RESCALE_NORMALS
;
2029 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
] &= ~RADEON_RESCALE_NORMALS
;
2032 if (RADEON_DEBUG
& DEBUG_STATE
)
2033 fprintf(stderr
, "%s %d AFTER %x\n", __FUNCTION__
, ctx
->_NeedEyeCoords
,
2034 rmesa
->hw
.tcl
.cmd
[TCL_LIGHT_MODEL_CTL
]);
2037 /* =============================================================
2038 * Deferred state management - matrices, textures, other?
2042 void radeonUploadTexMatrix( radeonContextPtr rmesa
,
2043 int unit
, GLboolean swapcols
)
2045 /* Here's how this works: on r100, only 3 tex coords can be submitted, so the
2046 vector looks like this probably: (s t r|q 0) (not sure if the last coord
2047 is hardwired to 0, could be 1 too). Interestingly, it actually looks like
2048 texgen generates all 4 coords, at least tests with projtex indicated that.
2049 So: if we need the q coord in the end (solely determined by the texture
2050 target, i.e. 2d / 1d / texrect targets) we swap the third and 4th row.
2051 Additionally, if we don't have texgen but 4 tex coords submitted, we swap
2052 column 3 and 4 (for the 2d / 1d / texrect targets) since the the q coord
2053 will get submitted in the "wrong", i.e. 3rd, slot.
2054 If an app submits 3 coords for 2d targets, we assume it is saving on vertex
2055 size and using the texture matrix to swap the r and q coords around (ut2k3
2056 does exactly that), so we don't need the 3rd / 4th column swap - still need
2057 the 3rd / 4th row swap of course. This will potentially break for apps which
2058 use TexCoord3x just for fun. Additionally, it will never work if an app uses
2059 an "advanced" texture matrix and relies on all 4 texcoord inputs to generate
2060 the maximum needed 3. This seems impossible to do with hw tcl on r100, and
2061 incredibly hard to detect so we can't just fallback in such a case. Assume
2062 it never happens... - rs
2065 int idx
= TEXMAT_0
+ unit
;
2066 float *dest
= ((float *)RADEON_DB_STATE( mat
[idx
] )) + MAT_ELT_0
;
2068 struct gl_texture_unit tUnit
= rmesa
->glCtx
->Texture
.Unit
[unit
];
2069 GLfloat
*src
= rmesa
->tmpmat
[unit
].m
;
2071 rmesa
->TexMatColSwap
&= ~(1 << unit
);
2072 if ((tUnit
._ReallyEnabled
& (TEXTURE_3D_BIT
| TEXTURE_CUBE_BIT
)) == 0) {
2074 rmesa
->TexMatColSwap
|= 1 << unit
;
2075 /* attention some elems are swapped 2 times! */
2088 /* those last 4 are probably never used */
2095 for (i
= 0; i
< 2; i
++) {
2099 *dest
++ = src
[i
+12];
2101 for (i
= 3; i
>= 2; i
--) {
2105 *dest
++ = src
[i
+12];
2110 for (i
= 0 ; i
< 4 ; i
++) {
2114 *dest
++ = src
[i
+12];
2118 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mat
[idx
] );
2122 static void upload_matrix( radeonContextPtr rmesa
, GLfloat
*src
, int idx
)
2124 float *dest
= ((float *)RADEON_DB_STATE( mat
[idx
] ))+MAT_ELT_0
;
2128 for (i
= 0 ; i
< 4 ; i
++) {
2132 *dest
++ = src
[i
+12];
2135 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mat
[idx
] );
2138 static void upload_matrix_t( radeonContextPtr rmesa
, GLfloat
*src
, int idx
)
2140 float *dest
= ((float *)RADEON_DB_STATE( mat
[idx
] ))+MAT_ELT_0
;
2141 memcpy(dest
, src
, 16*sizeof(float));
2142 RADEON_DB_STATECHANGE( rmesa
, &rmesa
->hw
.mat
[idx
] );
2146 static void update_texturematrix( GLcontext
*ctx
)
2148 radeonContextPtr rmesa
= RADEON_CONTEXT( ctx
);
2149 GLuint tpc
= rmesa
->hw
.tcl
.cmd
[TCL_TEXTURE_PROC_CTL
];
2150 GLuint vs
= rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
];
2152 GLuint texMatEnabled
= 0;
2153 rmesa
->NeedTexMatrix
= 0;
2154 rmesa
->TexMatColSwap
= 0;
2156 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
2157 if (ctx
->Texture
.Unit
[unit
]._ReallyEnabled
) {
2158 GLboolean needMatrix
= GL_FALSE
;
2159 if (ctx
->TextureMatrixStack
[unit
].Top
->type
!= MATRIX_IDENTITY
) {
2160 needMatrix
= GL_TRUE
;
2161 texMatEnabled
|= (RADEON_TEXGEN_TEXMAT_0_ENABLE
|
2162 RADEON_TEXMAT_0_ENABLE
) << unit
;
2164 if (rmesa
->TexGenEnabled
& (RADEON_TEXMAT_0_ENABLE
<< unit
)) {
2165 /* Need to preconcatenate any active texgen
2166 * obj/eyeplane matrices:
2168 _math_matrix_mul_matrix( &rmesa
->tmpmat
[unit
],
2169 ctx
->TextureMatrixStack
[unit
].Top
,
2170 &rmesa
->TexGenMatrix
[unit
] );
2173 _math_matrix_copy( &rmesa
->tmpmat
[unit
],
2174 ctx
->TextureMatrixStack
[unit
].Top
);
2177 else if (rmesa
->TexGenEnabled
& (RADEON_TEXMAT_0_ENABLE
<< unit
)) {
2178 _math_matrix_copy( &rmesa
->tmpmat
[unit
], &rmesa
->TexGenMatrix
[unit
] );
2179 needMatrix
= GL_TRUE
;
2182 rmesa
->NeedTexMatrix
|= 1 << unit
;
2183 radeonUploadTexMatrix( rmesa
, unit
,
2184 !ctx
->Texture
.Unit
[unit
].TexGenEnabled
);
2189 tpc
= (texMatEnabled
| rmesa
->TexGenEnabled
);
2191 /* TCL_TEX_COMPUTED_x is TCL_TEX_INPUT_x | 0x8 */
2192 vs
&= ~((RADEON_TCL_TEX_COMPUTED_TEX_0
<< RADEON_TCL_TEX_0_OUTPUT_SHIFT
) |
2193 (RADEON_TCL_TEX_COMPUTED_TEX_0
<< RADEON_TCL_TEX_1_OUTPUT_SHIFT
) |
2194 (RADEON_TCL_TEX_COMPUTED_TEX_0
<< RADEON_TCL_TEX_2_OUTPUT_SHIFT
));
2196 vs
|= (((tpc
& RADEON_TEXGEN_TEXMAT_0_ENABLE
) <<
2197 (RADEON_TCL_TEX_0_OUTPUT_SHIFT
+ 3)) |
2198 ((tpc
& RADEON_TEXGEN_TEXMAT_1_ENABLE
) <<
2199 (RADEON_TCL_TEX_1_OUTPUT_SHIFT
+ 2)) |
2200 ((tpc
& RADEON_TEXGEN_TEXMAT_2_ENABLE
) <<
2201 (RADEON_TCL_TEX_2_OUTPUT_SHIFT
+ 1)));
2203 if (tpc
!= rmesa
->hw
.tcl
.cmd
[TCL_TEXTURE_PROC_CTL
] ||
2204 vs
!= rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
]) {
2206 RADEON_STATECHANGE(rmesa
, tcl
);
2207 rmesa
->hw
.tcl
.cmd
[TCL_TEXTURE_PROC_CTL
] = tpc
;
2208 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXSEL
] = vs
;
2214 * Tell the card where to render (offset, pitch).
2215 * Effected by glDrawBuffer, etc
2218 radeonUpdateDrawBuffer(GLcontext
*ctx
)
2220 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
2221 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
2222 driRenderbuffer
*drb
;
2224 if (fb
->_ColorDrawBufferMask
[0] == BUFFER_BIT_FRONT_LEFT
) {
2226 drb
= (driRenderbuffer
*) fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
2228 else if (fb
->_ColorDrawBufferMask
[0] == BUFFER_BIT_BACK_LEFT
) {
2230 drb
= (driRenderbuffer
*) fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
2233 /* drawing to multiple buffers, or none */
2238 assert(drb
->flippedPitch
);
2240 RADEON_STATECHANGE( rmesa
, ctx
);
2242 /* Note: we used the (possibly) page-flipped values */
2243 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLOROFFSET
]
2244 = ((drb
->flippedOffset
+ rmesa
->radeonScreen
->fbLocation
)
2245 & RADEON_COLOROFFSET_MASK
);
2246 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] = drb
->flippedPitch
;
2247 if (rmesa
->sarea
->tiling_enabled
) {
2248 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] |= RADEON_COLOR_TILE_ENABLE
;
2253 void radeonValidateState( GLcontext
*ctx
)
2255 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
2256 GLuint new_state
= rmesa
->NewGLState
;
2258 if (new_state
& (_NEW_BUFFERS
| _NEW_COLOR
| _NEW_PIXEL
)) {
2259 radeonUpdateDrawBuffer(ctx
);
2262 if (new_state
& _NEW_TEXTURE
) {
2263 radeonUpdateTextureState( ctx
);
2264 new_state
|= rmesa
->NewGLState
; /* may add TEXTURE_MATRIX */
2267 /* Need an event driven matrix update?
2269 if (new_state
& (_NEW_MODELVIEW
|_NEW_PROJECTION
))
2270 upload_matrix( rmesa
, ctx
->_ModelProjectMatrix
.m
, MODEL_PROJ
);
2272 /* Need these for lighting (shouldn't upload otherwise)
2274 if (new_state
& (_NEW_MODELVIEW
)) {
2275 upload_matrix( rmesa
, ctx
->ModelviewMatrixStack
.Top
->m
, MODEL
);
2276 upload_matrix_t( rmesa
, ctx
->ModelviewMatrixStack
.Top
->inv
, MODEL_IT
);
2279 /* Does this need to be triggered on eg. modelview for
2280 * texgen-derived objplane/eyeplane matrices?
2282 if (new_state
& _NEW_TEXTURE_MATRIX
) {
2283 update_texturematrix( ctx
);
2286 if (new_state
& (_NEW_LIGHT
|_NEW_MODELVIEW
|_MESA_NEW_NEED_EYE_COORDS
)) {
2287 update_light( ctx
);
2290 /* emit all active clip planes if projection matrix changes.
2292 if (new_state
& (_NEW_PROJECTION
)) {
2293 if (ctx
->Transform
.ClipPlanesEnabled
)
2294 radeonUpdateClipPlanes( ctx
);
2298 rmesa
->NewGLState
= 0;
2302 static void radeonInvalidateState( GLcontext
*ctx
, GLuint new_state
)
2304 _swrast_InvalidateState( ctx
, new_state
);
2305 _swsetup_InvalidateState( ctx
, new_state
);
2306 _ac_InvalidateState( ctx
, new_state
);
2307 _tnl_InvalidateState( ctx
, new_state
);
2308 _ae_invalidate_state( ctx
, new_state
);
2309 RADEON_CONTEXT(ctx
)->NewGLState
|= new_state
;
2310 radeonVtxfmtInvalidate( ctx
);
2314 /* A hack. Need a faster way to find this out.
2316 static GLboolean
check_material( GLcontext
*ctx
)
2318 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
2321 for (i
= _TNL_ATTRIB_MAT_FRONT_AMBIENT
;
2322 i
< _TNL_ATTRIB_MAT_BACK_INDEXES
;
2324 if (tnl
->vb
.AttribPtr
[i
] &&
2325 tnl
->vb
.AttribPtr
[i
]->stride
)
2332 static void radeonWrapRunPipeline( GLcontext
*ctx
)
2334 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
2335 GLboolean has_material
;
2338 fprintf(stderr
, "%s, newstate: %x\n", __FUNCTION__
, rmesa
->NewGLState
);
2342 if (rmesa
->NewGLState
)
2343 radeonValidateState( ctx
);
2345 has_material
= (ctx
->Light
.Enabled
&& check_material( ctx
));
2348 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_MATERIAL
, GL_TRUE
);
2351 /* Run the pipeline.
2353 _tnl_run_pipeline( ctx
);
2356 TCL_FALLBACK( ctx
, RADEON_TCL_FALLBACK_MATERIAL
, GL_FALSE
);
2361 /* Initialize the driver's state functions.
2362 * Many of the ctx->Driver functions might have been initialized to
2363 * software defaults in the earlier _mesa_init_driver_functions() call.
2365 void radeonInitStateFuncs( GLcontext
*ctx
)
2367 ctx
->Driver
.UpdateState
= radeonInvalidateState
;
2368 ctx
->Driver
.LightingSpaceChange
= radeonLightingSpaceChange
;
2370 ctx
->Driver
.DrawBuffer
= radeonDrawBuffer
;
2371 ctx
->Driver
.ReadBuffer
= radeonReadBuffer
;
2373 ctx
->Driver
.AlphaFunc
= radeonAlphaFunc
;
2374 ctx
->Driver
.BlendEquationSeparate
= radeonBlendEquationSeparate
;
2375 ctx
->Driver
.BlendFuncSeparate
= radeonBlendFuncSeparate
;
2376 ctx
->Driver
.ClearColor
= radeonClearColor
;
2377 ctx
->Driver
.ClearDepth
= radeonClearDepth
;
2378 ctx
->Driver
.ClearIndex
= NULL
;
2379 ctx
->Driver
.ClearStencil
= radeonClearStencil
;
2380 ctx
->Driver
.ClipPlane
= radeonClipPlane
;
2381 ctx
->Driver
.ColorMask
= radeonColorMask
;
2382 ctx
->Driver
.CullFace
= radeonCullFace
;
2383 ctx
->Driver
.DepthFunc
= radeonDepthFunc
;
2384 ctx
->Driver
.DepthMask
= radeonDepthMask
;
2385 ctx
->Driver
.DepthRange
= radeonDepthRange
;
2386 ctx
->Driver
.Enable
= radeonEnable
;
2387 ctx
->Driver
.Fogfv
= radeonFogfv
;
2388 ctx
->Driver
.FrontFace
= radeonFrontFace
;
2389 ctx
->Driver
.Hint
= NULL
;
2390 ctx
->Driver
.IndexMask
= NULL
;
2391 ctx
->Driver
.LightModelfv
= radeonLightModelfv
;
2392 ctx
->Driver
.Lightfv
= radeonLightfv
;
2393 ctx
->Driver
.LineStipple
= radeonLineStipple
;
2394 ctx
->Driver
.LineWidth
= radeonLineWidth
;
2395 ctx
->Driver
.LogicOpcode
= radeonLogicOpCode
;
2396 ctx
->Driver
.PolygonMode
= radeonPolygonMode
;
2397 ctx
->Driver
.PolygonOffset
= radeonPolygonOffset
;
2398 ctx
->Driver
.PolygonStipple
= radeonPolygonStipple
;
2399 ctx
->Driver
.RenderMode
= radeonRenderMode
;
2400 ctx
->Driver
.Scissor
= radeonScissor
;
2401 ctx
->Driver
.ShadeModel
= radeonShadeModel
;
2402 ctx
->Driver
.StencilFuncSeparate
= radeonStencilFuncSeparate
;
2403 ctx
->Driver
.StencilMaskSeparate
= radeonStencilMaskSeparate
;
2404 ctx
->Driver
.StencilOpSeparate
= radeonStencilOpSeparate
;
2405 ctx
->Driver
.Viewport
= radeonViewport
;
2407 TNL_CONTEXT(ctx
)->Driver
.NotifyMaterialChange
= radeonUpdateMaterial
;
2408 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= radeonWrapRunPipeline
;