Major check-in of changes for GL_EXT_framebuffer_object extension.
[mesa.git] / src / mesa / drivers / dri / sis / sis_state.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
33 */
34
35 #include "sis_context.h"
36 #include "sis_state.h"
37 #include "sis_tris.h"
38 #include "sis_lock.h"
39 #include "sis_tex.h"
40
41 #include "context.h"
42 #include "buffers.h"
43 #include "enums.h"
44 #include "colormac.h"
45 #include "swrast/swrast.h"
46 #include "array_cache/acache.h"
47 #include "tnl/tnl.h"
48 #include "swrast_setup/swrast_setup.h"
49
50 #include "tnl/t_pipeline.h"
51
52 /* =============================================================
53 * Alpha blending
54 */
55
56 static void
57 sisDDAlphaFunc( GLcontext * ctx, GLenum func, GLfloat ref )
58 {
59 sisContextPtr smesa = SIS_CONTEXT(ctx);
60 GLubyte refbyte;
61
62 __GLSiSHardware *prev = &smesa->prev;
63 __GLSiSHardware *current = &smesa->current;
64
65 CLAMPED_FLOAT_TO_UBYTE(refbyte, ref);
66 current->hwAlpha = refbyte << 16;
67
68 /* Alpha Test function */
69 switch (func)
70 {
71 case GL_NEVER:
72 current->hwAlpha |= SiS_ALPHA_NEVER;
73 break;
74 case GL_LESS:
75 current->hwAlpha |= SiS_ALPHA_LESS;
76 break;
77 case GL_EQUAL:
78 current->hwAlpha |= SiS_ALPHA_EQUAL;
79 break;
80 case GL_LEQUAL:
81 current->hwAlpha |= SiS_ALPHA_LEQUAL;
82 break;
83 case GL_GREATER:
84 current->hwAlpha |= SiS_ALPHA_GREATER;
85 break;
86 case GL_NOTEQUAL:
87 current->hwAlpha |= SiS_ALPHA_NOTEQUAL;
88 break;
89 case GL_GEQUAL:
90 current->hwAlpha |= SiS_ALPHA_GEQUAL;
91 break;
92 case GL_ALWAYS:
93 current->hwAlpha |= SiS_ALPHA_ALWAYS;
94 break;
95 }
96
97 prev->hwAlpha = current->hwAlpha;
98 smesa->GlobalFlag |= GFLAG_ALPHASETTING;
99 }
100
101 static void
102 sisDDBlendFuncSeparate( GLcontext *ctx,
103 GLenum sfactorRGB, GLenum dfactorRGB,
104 GLenum sfactorA, GLenum dfactorA )
105 {
106 sisContextPtr smesa = SIS_CONTEXT(ctx);
107
108 __GLSiSHardware *prev = &smesa->prev;
109 __GLSiSHardware *current = &smesa->current;
110
111 current->hwDstSrcBlend = 0;
112
113 switch (dfactorRGB)
114 {
115 case GL_ZERO:
116 current->hwDstSrcBlend |= SiS_D_ZERO;
117 break;
118 case GL_ONE:
119 current->hwDstSrcBlend |= SiS_D_ONE;
120 break;
121 case GL_SRC_COLOR:
122 current->hwDstSrcBlend |= SiS_D_SRC_COLOR;
123 break;
124 case GL_ONE_MINUS_SRC_COLOR:
125 current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_COLOR;
126 break;
127 case GL_SRC_ALPHA:
128 current->hwDstSrcBlend |= SiS_D_SRC_ALPHA;
129 break;
130 case GL_ONE_MINUS_SRC_ALPHA:
131 current->hwDstSrcBlend |= SiS_D_ONE_MINUS_SRC_ALPHA;
132 break;
133 case GL_DST_COLOR:
134 current->hwDstSrcBlend |= SiS_D_DST_COLOR;
135 break;
136 case GL_ONE_MINUS_DST_COLOR:
137 current->hwDstSrcBlend |= SiS_D_ONE_MINUS_DST_COLOR;
138 break;
139 case GL_DST_ALPHA:
140 current->hwDstSrcBlend |= SiS_D_DST_ALPHA;
141 break;
142 case GL_ONE_MINUS_DST_ALPHA:
143 current->hwDstSrcBlend |= SiS_D_ONE_MINUS_DST_ALPHA;
144 break;
145 default:
146 fprintf(stderr, "Unknown dst blend function 0x%x\n", dfactorRGB);
147 break;
148 }
149
150 switch (sfactorRGB)
151 {
152 case GL_ZERO:
153 current->hwDstSrcBlend |= SiS_S_ZERO;
154 break;
155 case GL_ONE:
156 current->hwDstSrcBlend |= SiS_S_ONE;
157 break;
158 case GL_SRC_COLOR:
159 current->hwDstSrcBlend |= SiS_S_SRC_COLOR;
160 break;
161 case GL_ONE_MINUS_SRC_COLOR:
162 current->hwDstSrcBlend |= SiS_S_ONE_MINUS_SRC_COLOR;
163 break;
164 case GL_SRC_ALPHA:
165 current->hwDstSrcBlend |= SiS_S_SRC_ALPHA;
166 break;
167 case GL_ONE_MINUS_SRC_ALPHA:
168 current->hwDstSrcBlend |= SiS_S_ONE_MINUS_SRC_ALPHA;
169 break;
170 case GL_DST_COLOR:
171 current->hwDstSrcBlend |= SiS_S_DST_COLOR;
172 break;
173 case GL_ONE_MINUS_DST_COLOR:
174 current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_COLOR;
175 break;
176 case GL_DST_ALPHA:
177 current->hwDstSrcBlend |= SiS_S_DST_ALPHA;
178 break;
179 case GL_ONE_MINUS_DST_ALPHA:
180 current->hwDstSrcBlend |= SiS_S_ONE_MINUS_DST_ALPHA;
181 break;
182 case GL_SRC_ALPHA_SATURATE:
183 current->hwDstSrcBlend |= SiS_S_SRC_ALPHA_SATURATE;
184 break;
185 default:
186 fprintf(stderr, "Unknown src blend function 0x%x\n", sfactorRGB);
187 break;
188 }
189
190 if (current->hwDstSrcBlend != prev->hwDstSrcBlend) {
191 prev->hwDstSrcBlend = current->hwDstSrcBlend;
192 smesa->GlobalFlag |= GFLAG_DSTBLEND;
193 }
194 }
195
196 /* =============================================================
197 * Depth testing
198 */
199
200 static void
201 sisDDDepthFunc( GLcontext * ctx, GLenum func )
202 {
203 sisContextPtr smesa = SIS_CONTEXT(ctx);
204 __GLSiSHardware *prev = &smesa->prev;
205 __GLSiSHardware *current = &smesa->current;
206
207 current->hwZ &= ~MASK_ZTestMode;
208 switch (func)
209 {
210 case GL_LESS:
211 current->hwZ |= SiS_Z_COMP_S_LT_B;
212 break;
213 case GL_GEQUAL:
214 current->hwZ |= SiS_Z_COMP_S_GE_B;
215 break;
216 case GL_LEQUAL:
217 current->hwZ |= SiS_Z_COMP_S_LE_B;
218 break;
219 case GL_GREATER:
220 current->hwZ |= SiS_Z_COMP_S_GT_B;
221 break;
222 case GL_NOTEQUAL:
223 current->hwZ |= SiS_Z_COMP_S_NE_B;
224 break;
225 case GL_EQUAL:
226 current->hwZ |= SiS_Z_COMP_S_EQ_B;
227 break;
228 case GL_ALWAYS:
229 current->hwZ |= SiS_Z_COMP_ALWAYS;
230 break;
231 case GL_NEVER:
232 current->hwZ |= SiS_Z_COMP_NEVER;
233 break;
234 }
235
236 if (current->hwZ != prev->hwZ) {
237 prev->hwZ = current->hwZ;
238 smesa->GlobalFlag |= GFLAG_ZSETTING;
239 }
240 }
241
242 void
243 sisDDDepthMask( GLcontext * ctx, GLboolean flag )
244 {
245 sisContextPtr smesa = SIS_CONTEXT(ctx);
246 __GLSiSHardware *prev = &smesa->prev;
247 __GLSiSHardware *current = &smesa->current;
248
249 if (!ctx->Depth.Test)
250 flag = GL_FALSE;
251
252 if (ctx->Visual.stencilBits) {
253 if (flag || (ctx->Stencil.WriteMask[0] != 0)) {
254 current->hwCapEnable |= MASK_ZWriteEnable;
255 if (flag && (ctx->Stencil.WriteMask[0] == 0xff)) {
256 current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable;
257 } else {
258 current->hwCapEnable2 |= MASK_ZMaskWriteEnable;
259 current->hwZMask = (ctx->Stencil.WriteMask[0] << 24) |
260 ((flag) ? 0x00ffffff : 0);
261
262 if (current->hwZMask ^ prev->hwZMask) {
263 prev->hwZMask = current->hwZMask;
264 smesa->GlobalFlag |= GFLAG_ZSETTING;
265 }
266 }
267 } else {
268 current->hwCapEnable &= ~MASK_ZWriteEnable;
269 }
270 } else {
271 if (flag) {
272 current->hwCapEnable |= MASK_ZWriteEnable;
273 current->hwCapEnable2 &= ~MASK_ZMaskWriteEnable;
274 } else {
275 current->hwCapEnable &= ~MASK_ZWriteEnable;
276 }
277 }
278 }
279
280 /* =============================================================
281 * Clipping
282 */
283
284 void
285 sisUpdateClipping( GLcontext *ctx )
286 {
287 sisContextPtr smesa = SIS_CONTEXT(ctx);
288
289 __GLSiSHardware *prev = &smesa->prev;
290 __GLSiSHardware *current = &smesa->current;
291
292 GLint x1, y1, x2, y2;
293
294 x1 = 0;
295 y1 = 0;
296 x2 = smesa->width - 1;
297 y2 = smesa->height - 1;
298
299 if (ctx->Scissor.Enabled) {
300 if (ctx->Scissor.X > x1)
301 x1 = ctx->Scissor.X;
302 if (ctx->Scissor.Y > y1)
303 y1 = ctx->Scissor.Y;
304 if (ctx->Scissor.X + ctx->Scissor.Width - 1 < x2)
305 x2 = ctx->Scissor.X + ctx->Scissor.Width - 1;
306 if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < y2)
307 y2 = ctx->Scissor.Y + ctx->Scissor.Height - 1;
308 }
309
310 y1 = Y_FLIP(y1);
311 y2 = Y_FLIP(y2);
312
313 current->clipTopBottom = (y2 << 13) | y1;
314 current->clipLeftRight = (x1 << 13) | x2;
315
316 if ((current->clipTopBottom ^ prev->clipTopBottom) ||
317 (current->clipLeftRight ^ prev->clipLeftRight))
318 {
319 prev->clipTopBottom = current->clipTopBottom;
320 prev->clipLeftRight = current->clipLeftRight;
321 smesa->GlobalFlag |= GFLAG_CLIPPING;
322 }
323 }
324
325 static void
326 sisDDScissor( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h )
327 {
328 if (ctx->Scissor.Enabled)
329 sisUpdateClipping( ctx );
330 }
331
332 /* =============================================================
333 * Culling
334 */
335
336 static void
337 sisUpdateCull( GLcontext *ctx )
338 {
339 sisContextPtr smesa = SIS_CONTEXT(ctx);
340 GLint cullflag, frontface;
341
342 cullflag = ctx->Polygon.CullFaceMode;
343 frontface = ctx->Polygon.FrontFace;
344
345 smesa->AGPParseSet &= ~(MASK_PsCullDirection_CCW);
346 smesa->dwPrimitiveSet &= ~(MASK_CullDirection);
347
348 if((cullflag == GL_FRONT && frontface == GL_CCW) ||
349 (cullflag == GL_BACK && frontface == GL_CW))
350 {
351 smesa->AGPParseSet |= MASK_PsCullDirection_CCW;
352 smesa->dwPrimitiveSet |= OP_3D_CullDirection_CCW;
353 }
354 }
355
356
357 static void
358 sisDDCullFace( GLcontext *ctx, GLenum mode )
359 {
360 sisUpdateCull( ctx );
361 }
362
363 static void
364 sisDDFrontFace( GLcontext *ctx, GLenum mode )
365 {
366 sisUpdateCull( ctx );
367 }
368
369 /* =============================================================
370 * Masks
371 */
372
373 static void sisDDColorMask( GLcontext *ctx,
374 GLboolean r, GLboolean g,
375 GLboolean b, GLboolean a )
376 {
377 sisContextPtr smesa = SIS_CONTEXT(ctx);
378 __GLSiSHardware *prev = &smesa->prev;
379 __GLSiSHardware *current = &smesa->current;
380
381 if (r && g && b && ((ctx->Visual.alphaBits == 0) || a)) {
382 current->hwCapEnable2 &= ~(MASK_AlphaMaskWriteEnable |
383 MASK_ColorMaskWriteEnable);
384 } else {
385 current->hwCapEnable2 |= (MASK_AlphaMaskWriteEnable |
386 MASK_ColorMaskWriteEnable);
387
388 current->hwDstMask = (r) ? smesa->redMask : 0 |
389 (g) ? smesa->greenMask : 0 |
390 (b) ? smesa->blueMask : 0 |
391 (a) ? smesa->alphaMask : 0;
392 }
393
394 if (current->hwDstMask != prev->hwDstMask) {
395 prev->hwDstMask = current->hwDstMask;
396 smesa->GlobalFlag |= GFLAG_DESTSETTING;
397 }
398 }
399
400 /* =============================================================
401 * Rendering attributes
402 */
403
404 static void sisDDShadeModel( GLcontext *ctx, GLenum mode )
405 {
406 sisContextPtr smesa = SIS_CONTEXT(ctx);
407
408 /* Signal to sisRasterPrimitive to recalculate dwPrimitiveSet */
409 smesa->hw_primitive = -1;
410 }
411
412 /* =============================================================
413 * Window position
414 */
415
416 /* =============================================================
417 * Viewport
418 */
419
420 static void sisCalcViewport( GLcontext *ctx )
421 {
422 sisContextPtr smesa = SIS_CONTEXT(ctx);
423 const GLfloat *v = ctx->Viewport._WindowMap.m;
424 GLfloat *m = smesa->hw_viewport;
425
426 /* See also sis_translate_vertex.
427 */
428 m[MAT_SX] = v[MAT_SX];
429 m[MAT_TX] = v[MAT_TX] + SUBPIXEL_X;
430 m[MAT_SY] = - v[MAT_SY];
431 m[MAT_TY] = - v[MAT_TY] + smesa->driDrawable->h + SUBPIXEL_Y;
432 m[MAT_SZ] = v[MAT_SZ] * smesa->depth_scale;
433 m[MAT_TZ] = v[MAT_TZ] * smesa->depth_scale;
434 }
435
436 static void sisDDViewport( GLcontext *ctx,
437 GLint x, GLint y,
438 GLsizei width, GLsizei height )
439 {
440 /* update size of Mesa/software ancillary buffers */
441 _mesa_ResizeBuffersMESA();
442 sisCalcViewport( ctx );
443 }
444
445 static void sisDDDepthRange( GLcontext *ctx,
446 GLclampd nearval, GLclampd farval )
447 {
448 sisCalcViewport( ctx );
449 }
450
451 /* =============================================================
452 * Miscellaneous
453 */
454
455 static void
456 sisDDLogicOpCode( GLcontext *ctx, GLenum opcode )
457 {
458 sisContextPtr smesa = SIS_CONTEXT(ctx);
459
460 __GLSiSHardware *prev = &smesa->prev;
461 __GLSiSHardware *current = &smesa->current;
462
463 current->hwDstSet &= ~MASK_ROP2;
464 switch (opcode)
465 {
466 case GL_CLEAR:
467 current->hwDstSet |= LOP_CLEAR;
468 break;
469 case GL_SET:
470 current->hwDstSet |= LOP_SET;
471 break;
472 case GL_COPY:
473 current->hwDstSet |= LOP_COPY;
474 break;
475 case GL_COPY_INVERTED:
476 current->hwDstSet |= LOP_COPY_INVERTED;
477 break;
478 case GL_NOOP:
479 current->hwDstSet |= LOP_NOOP;
480 break;
481 case GL_INVERT:
482 current->hwDstSet |= LOP_INVERT;
483 break;
484 case GL_AND:
485 current->hwDstSet |= LOP_AND;
486 break;
487 case GL_NAND:
488 current->hwDstSet |= LOP_NAND;
489 break;
490 case GL_OR:
491 current->hwDstSet |= LOP_OR;
492 break;
493 case GL_NOR:
494 current->hwDstSet |= LOP_NOR;
495 break;
496 case GL_XOR:
497 current->hwDstSet |= LOP_XOR;
498 break;
499 case GL_EQUIV:
500 current->hwDstSet |= LOP_EQUIV;
501 break;
502 case GL_AND_REVERSE:
503 current->hwDstSet |= LOP_AND_REVERSE;
504 break;
505 case GL_AND_INVERTED:
506 current->hwDstSet |= LOP_AND_INVERTED;
507 break;
508 case GL_OR_REVERSE:
509 current->hwDstSet |= LOP_OR_REVERSE;
510 break;
511 case GL_OR_INVERTED:
512 current->hwDstSet |= LOP_OR_INVERTED;
513 break;
514 }
515
516 if (current->hwDstSet ^ prev->hwDstSet) {
517 prev->hwDstSet = current->hwDstSet;
518 smesa->GlobalFlag |= GFLAG_DESTSETTING;
519 }
520 }
521
522 void sisDDDrawBuffer( GLcontext *ctx, GLenum mode )
523 {
524 sisContextPtr smesa = SIS_CONTEXT(ctx);
525
526 __GLSiSHardware *prev = &smesa->prev;
527 __GLSiSHardware *current = &smesa->current;
528
529 /*
530 * _DrawDestMask is easier to cope with than <mode>.
531 */
532 switch ( ctx->DrawBuffer->_ColorDrawBufferMask[0] ) {
533 case BUFFER_BIT_FRONT_LEFT:
534 case BUFFER_BIT_BACK_LEFT:
535 FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_FALSE );
536 break;
537 default:
538 /* GL_NONE or GL_FRONT_AND_BACK or stereo left&right, etc */
539 FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_TRUE );
540 return;
541 }
542
543 /* We want to update the s/w rast state too so that sisDDSetBuffer()
544 * gets called.
545 */
546 _swrast_DrawBuffer(ctx, mode);
547
548 current->hwOffsetDest = (smesa->drawOffset) >> 1;
549 current->hwDstSet &= ~MASK_DstBufferPitch;
550 current->hwDstSet |= smesa->drawPitch >> 2;
551
552 if (current->hwDstSet != prev->hwDstSet) {
553 prev->hwDstSet = current->hwDstSet;
554 smesa->GlobalFlag |= GFLAG_DESTSETTING;
555 }
556
557 if (current->hwOffsetDest != prev->hwOffsetDest) {
558 prev->hwOffsetDest = current->hwOffsetDest;
559 smesa->GlobalFlag |= GFLAG_DESTSETTING;
560 }
561 }
562
563 /* =============================================================
564 * Polygon stipple
565 */
566
567 /* =============================================================
568 * Render mode
569 */
570
571 /* =============================================================
572 * State enable/disable
573 */
574
575 static void
576 sisDDEnable( GLcontext * ctx, GLenum cap, GLboolean state )
577 {
578 sisContextPtr smesa = SIS_CONTEXT(ctx);
579
580 __GLSiSHardware *current = &smesa->current;
581
582 switch (cap)
583 {
584 case GL_ALPHA_TEST:
585 if (state)
586 current->hwCapEnable |= MASK_AlphaTestEnable;
587 else
588 current->hwCapEnable &= ~MASK_AlphaTestEnable;
589 break;
590 case GL_BLEND:
591 /* TODO: */
592 if (state)
593 /* if (state & !ctx->Color.ColorLogicOpEnabled) */
594 current->hwCapEnable |= MASK_BlendEnable;
595 else
596 current->hwCapEnable &= ~MASK_BlendEnable;
597 break;
598 case GL_CULL_FACE:
599 if (state)
600 current->hwCapEnable |= MASK_CullEnable;
601 else
602 current->hwCapEnable &= ~MASK_CullEnable;
603 break;
604 case GL_DEPTH_TEST:
605 if (state && smesa->depthbuffer)
606 current->hwCapEnable |= MASK_ZTestEnable;
607 else
608 current->hwCapEnable &= ~MASK_ZTestEnable;
609 sisDDDepthMask( ctx, ctx->Depth.Mask );
610 break;
611 case GL_DITHER:
612 if (state)
613 current->hwCapEnable |= MASK_DitherEnable;
614 else
615 current->hwCapEnable &= ~MASK_DitherEnable;
616 break;
617 case GL_FOG:
618 if (state)
619 current->hwCapEnable |= MASK_FogEnable;
620 else
621 current->hwCapEnable &= ~MASK_FogEnable;
622 break;
623 case GL_COLOR_LOGIC_OP:
624 if (state)
625 sisDDLogicOpCode( ctx, ctx->Color.LogicOp );
626 else
627 sisDDLogicOpCode( ctx, GL_COPY );
628 break;
629 case GL_SCISSOR_TEST:
630 sisUpdateClipping( ctx );
631 break;
632 case GL_STENCIL_TEST:
633 if (state) {
634 if (smesa->zFormat != SiS_ZFORMAT_S8Z24)
635 FALLBACK(smesa, SIS_FALLBACK_STENCIL, 1);
636 else
637 current->hwCapEnable |= (MASK_StencilTestEnable |
638 MASK_StencilWriteEnable);
639 } else {
640 FALLBACK(smesa, SIS_FALLBACK_STENCIL, 0);
641 current->hwCapEnable &= ~(MASK_StencilTestEnable |
642 MASK_StencilWriteEnable);
643 }
644 break;
645 }
646 }
647
648
649 /* =============================================================
650 * State initialization, management
651 */
652
653 /* Called before beginning of rendering. */
654 void
655 sisUpdateHWState( GLcontext *ctx )
656 {
657 sisContextPtr smesa = SIS_CONTEXT(ctx);
658 __GLSiSHardware *prev = &smesa->prev;
659 __GLSiSHardware *current = &smesa->current;
660
661 /* enable setting 1 */
662 if (current->hwCapEnable ^ prev->hwCapEnable) {
663 prev->hwCapEnable = current->hwCapEnable;
664 smesa->GlobalFlag |= GFLAG_ENABLESETTING;
665 }
666
667 /* enable setting 2 */
668 if (current->hwCapEnable2 ^ prev->hwCapEnable2) {
669 prev->hwCapEnable2 = current->hwCapEnable2;
670 smesa->GlobalFlag |= GFLAG_ENABLESETTING2;
671 }
672
673 if (smesa->GlobalFlag & GFLAG_RENDER_STATES)
674 sis_update_render_state( smesa );
675
676 if (smesa->GlobalFlag & GFLAG_TEXTURE_STATES)
677 sis_update_texture_state( smesa );
678 }
679
680 static void
681 sisDDInvalidateState( GLcontext *ctx, GLuint new_state )
682 {
683 sisContextPtr smesa = SIS_CONTEXT(ctx);
684
685 _swrast_InvalidateState( ctx, new_state );
686 _swsetup_InvalidateState( ctx, new_state );
687 _ac_InvalidateState( ctx, new_state );
688 _tnl_InvalidateState( ctx, new_state );
689 smesa->NewGLState |= new_state;
690 }
691
692 /* Initialize the context's hardware state.
693 */
694 void sisDDInitState( sisContextPtr smesa )
695 {
696 __GLSiSHardware *current = &smesa->current;
697 __GLSiSHardware *prev = &(smesa->prev);
698 GLcontext *ctx = smesa->glCtx;
699
700 /* add Texture Perspective Enable */
701 prev->hwCapEnable = MASK_FogPerspectiveEnable | MASK_TextureCacheEnable |
702 MASK_TexturePerspectiveEnable | MASK_DitherEnable;
703 /*| MASK_SpecularEnable*/
704
705 /*
706 prev->hwCapEnable2 = 0x00aa0080;
707 */
708 /* if multi-texture enabled, disable Z pre-test */
709 prev->hwCapEnable2 = MASK_TextureMipmapBiasEnable;
710
711 /* Z test mode is LESS */
712 prev->hwZ = SiS_Z_COMP_S_LT_B;
713
714 /* Depth mask */
715 prev->hwZMask = 0xffffffff;
716
717 /* Alpha test mode is ALWAYS, alpha ref value is 0 */
718 prev->hwAlpha = SiS_ALPHA_ALWAYS;
719
720 /* ROP2 is COPYPEN */
721 prev->hwDstSet = LOP_COPY;
722
723 /* color mask */
724 prev->hwDstMask = 0xffffffff;
725
726 /* LinePattern is 0, Repeat Factor is 0 */
727 prev->hwLinePattern = 0x00008000;
728
729 /* Src blend is BLEND_ONE, Dst blend is D3DBLEND_ZERO */
730 prev->hwDstSrcBlend = SiS_S_ONE | SiS_D_ZERO;
731
732 /* Stenciling disabled, function ALWAYS, ref value zero, mask all ones */
733 prev->hwStSetting = STENCIL_FORMAT_8 | SiS_STENCIL_ALWAYS | 0xff;
734 /* Op is KEEP for all three operations */
735 prev->hwStSetting2 = SiS_SFAIL_KEEP | SiS_SPASS_ZFAIL_KEEP |
736 SiS_SPASS_ZPASS_KEEP;
737
738 /* Texture mapping mode is Tile */
739 #if 0
740 prev->texture[0].hwTextureSet = 0x00030000;
741 #endif
742 /* Magnified & minified texture filter is NEAREST */
743 #if 0
744 prev->texture[0].hwTextureMip = 0;
745 #endif
746
747 /* Texture Blending setting -- use fragment color/alpha*/
748 prev->hwTexBlendColor0 = STAGE0_C_CF;
749 prev->hwTexBlendColor1 = STAGE1_C_CF;
750 prev->hwTexBlendAlpha0 = STAGE0_A_AF;
751 prev->hwTexBlendAlpha1 = STAGE1_A_AF;
752
753 switch (smesa->bytesPerPixel)
754 {
755 case 2:
756 prev->hwDstSet |= DST_FORMAT_RGB_565;
757 break;
758 case 4:
759 prev->hwDstSet |= DST_FORMAT_ARGB_8888;
760 break;
761 }
762
763 switch (ctx->Visual.depthBits)
764 {
765 case 0:
766 prev->hwCapEnable &= ~MASK_ZWriteEnable;
767 case 16:
768 smesa->zFormat = SiS_ZFORMAT_Z16;
769 prev->hwCapEnable |= MASK_ZWriteEnable;
770 smesa->depth_scale = 1.0 / (GLfloat)0xffff;
771 break;
772 case 32:
773 smesa->zFormat = SiS_ZFORMAT_Z32;
774 prev->hwCapEnable |= MASK_ZWriteEnable;
775 smesa->depth_scale = 1.0 / (GLfloat)0xffffffff;
776 break;
777 case 24:
778 assert (ctx->Visual.stencilBits);
779 smesa->zFormat = SiS_ZFORMAT_S8Z24;
780 prev->hwCapEnable |= MASK_StencilBufferEnable;
781 prev->hwCapEnable |= MASK_ZWriteEnable;
782 smesa->depth_scale = 1.0 / (GLfloat)0xffffff;
783 break;
784 }
785
786 prev->hwZ |= smesa->zFormat;
787
788 /* TODO: need to clear cache? */
789 smesa->clearTexCache = GL_TRUE;
790
791 smesa->clearColorPattern = 0;
792
793 smesa->AGPParseSet = MASK_PsTexture1FromB | MASK_PsBumpTextureFromC;
794 smesa->dwPrimitiveSet = OP_3D_Texture1FromB | OP_3D_TextureBumpFromC;
795
796 sisUpdateZStencilPattern( smesa, 1.0, 0 );
797 sisUpdateCull( ctx );
798
799 memcpy( current, prev, sizeof (__GLSiSHardware) );
800
801 /* Set initial fog settings. Start and end are the same case. */
802 sisDDFogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
803 sisDDFogfv( ctx, GL_FOG_END, &ctx->Fog.End );
804 sisDDFogfv( ctx, GL_FOG_MODE, NULL );
805 }
806
807 /* Initialize the driver's state functions.
808 */
809 void sisDDInitStateFuncs( GLcontext *ctx )
810 {
811 ctx->Driver.UpdateState = sisDDInvalidateState;
812
813 ctx->Driver.Clear = sisDDClear;
814 ctx->Driver.ClearColor = sisDDClearColor;
815 ctx->Driver.ClearDepth = sisDDClearDepth;
816 ctx->Driver.ClearStencil = sisDDClearStencil;
817
818 ctx->Driver.AlphaFunc = sisDDAlphaFunc;
819 ctx->Driver.BlendFuncSeparate = sisDDBlendFuncSeparate;
820 ctx->Driver.ColorMask = sisDDColorMask;
821 ctx->Driver.CullFace = sisDDCullFace;
822 ctx->Driver.DepthMask = sisDDDepthMask;
823 ctx->Driver.DepthFunc = sisDDDepthFunc;
824 ctx->Driver.DepthRange = sisDDDepthRange;
825 ctx->Driver.DrawBuffer = sisDDDrawBuffer;
826 ctx->Driver.Enable = sisDDEnable;
827 ctx->Driver.FrontFace = sisDDFrontFace;
828 ctx->Driver.Fogfv = sisDDFogfv;
829 ctx->Driver.Hint = NULL;
830 ctx->Driver.Lightfv = NULL;
831 ctx->Driver.LogicOpcode = sisDDLogicOpCode;
832 ctx->Driver.PolygonMode = NULL;
833 ctx->Driver.PolygonStipple = NULL;
834 ctx->Driver.ReadBuffer = NULL;
835 ctx->Driver.RenderMode = NULL;
836 ctx->Driver.Scissor = sisDDScissor;
837 ctx->Driver.ShadeModel = sisDDShadeModel;
838 ctx->Driver.Viewport = sisDDViewport;
839
840 /* Pixel path fallbacks. */
841 ctx->Driver.Accum = _swrast_Accum;
842 ctx->Driver.Bitmap = _swrast_Bitmap;
843 ctx->Driver.CopyPixels = _swrast_CopyPixels;
844 ctx->Driver.DrawPixels = _swrast_DrawPixels;
845 ctx->Driver.ReadPixels = _swrast_ReadPixels;
846
847 /* Swrast hooks for imaging extensions:
848 */
849 ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
850 ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
851 ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
852 ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
853 }