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