Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / sis / sis6326_state.c
1 /*
2  * Copyright 2005 Eric Anholt
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  * Authors:
25  *    Eric Anholt <anholt@FreeBSD.org>
26  *
27  */
28
29 #include "sis_context.h"
30 #include "sis_state.h"
31 #include "sis_tris.h"
32 #include "sis_lock.h"
33 #include "sis_tex.h"
34 #include "sis_reg.h"
35
36 #include "main/context.h"
37 #include "main/colormac.h"
38 #include "main/state.h"
39 #include "swrast/swrast.h"
40 #include "vbo/vbo.h"
41 #include "tnl/tnl.h"
42 #include "swrast_setup/swrast_setup.h"
43
44
45 /* =============================================================
46  * Alpha blending
47  */
48
49 static void
50 sis6326DDAlphaFunc( struct gl_context *ctx, GLenum func, GLfloat ref )
51 {
52    sisContextPtr smesa = SIS_CONTEXT(ctx);
53    GLubyte refbyte;
54
55    __GLSiSHardware *prev = &smesa->prev;
56    __GLSiSHardware *current = &smesa->current;
57
58    CLAMPED_FLOAT_TO_UBYTE(refbyte, ref);
59    current->hwAlpha = refbyte << 16;
60
61    /* Alpha Test function */
62    switch (func)
63    {
64    case GL_NEVER:
65       current->hwAlpha |= S_ASET_PASS_NEVER;
66       break;
67    case GL_LESS:
68       current->hwAlpha |= S_ASET_PASS_LESS;
69       break;
70    case GL_EQUAL:
71       current->hwAlpha |= S_ASET_PASS_EQUAL;
72       break;
73    case GL_LEQUAL:
74       current->hwAlpha |= S_ASET_PASS_LEQUAL;
75       break;
76    case GL_GREATER:
77       current->hwAlpha |= S_ASET_PASS_GREATER;
78       break;
79    case GL_NOTEQUAL:
80       current->hwAlpha |= S_ASET_PASS_NOTEQUAL;
81       break;
82    case GL_GEQUAL:
83       current->hwAlpha |= S_ASET_PASS_GEQUAL;
84       break;
85    case GL_ALWAYS:
86       current->hwAlpha |= S_ASET_PASS_ALWAYS;
87       break;
88    }
89
90    prev->hwAlpha = current->hwAlpha;
91    smesa->GlobalFlag |= GFLAG_ALPHASETTING;
92 }
93
94 static void
95 sis6326DDBlendFuncSeparate( struct gl_context *ctx, 
96                             GLenum sfactorRGB, GLenum dfactorRGB,
97                             GLenum sfactorA,   GLenum dfactorA )
98 {
99    sisContextPtr smesa = SIS_CONTEXT(ctx);
100
101    __GLSiSHardware *prev = &smesa->prev;
102    __GLSiSHardware *current = &smesa->current;
103
104    current->hwDstSrcBlend = 0;
105
106    switch (dfactorRGB)
107    {
108    case GL_ZERO:
109       current->hwDstSrcBlend |= S_DBLEND_ZERO;
110       break;
111    case GL_ONE:
112       current->hwDstSrcBlend |= S_DBLEND_ONE;
113       break;
114    case GL_SRC_COLOR:
115       current->hwDstSrcBlend |= S_DBLEND_SRC_COLOR;
116       break;
117    case GL_ONE_MINUS_SRC_COLOR:
118       current->hwDstSrcBlend |= S_DBLEND_INV_SRC_COLOR;
119       break;
120    case GL_SRC_ALPHA:
121       current->hwDstSrcBlend |= S_DBLEND_SRC_ALPHA;
122       break;
123    case GL_ONE_MINUS_SRC_ALPHA:
124       current->hwDstSrcBlend |= S_DBLEND_INV_SRC_ALPHA;
125       break;
126    case GL_DST_ALPHA:
127       current->hwDstSrcBlend |= S_DBLEND_DST_ALPHA;
128       break;
129    case GL_ONE_MINUS_DST_ALPHA:
130       current->hwDstSrcBlend |= S_DBLEND_INV_DST_ALPHA;
131       break;
132    }
133
134    switch (sfactorRGB)
135    {
136    case GL_ZERO:
137       current->hwDstSrcBlend |= S_SBLEND_ZERO;
138       break;
139    case GL_ONE:
140       current->hwDstSrcBlend |= S_SBLEND_ONE;
141       break;
142    case GL_SRC_ALPHA:
143       current->hwDstSrcBlend |= S_SBLEND_SRC_ALPHA;
144       break;
145    case GL_ONE_MINUS_SRC_ALPHA:
146       current->hwDstSrcBlend |= S_SBLEND_INV_SRC_ALPHA;
147       break;
148    case GL_DST_ALPHA:
149       current->hwDstSrcBlend |= S_SBLEND_DST_ALPHA;
150       break;
151    case GL_ONE_MINUS_DST_ALPHA:
152       current->hwDstSrcBlend |= S_SBLEND_INV_DST_ALPHA;
153       break;
154    case GL_DST_COLOR:
155       current->hwDstSrcBlend |= S_SBLEND_DST_COLOR;
156       break;
157    case GL_ONE_MINUS_DST_COLOR:
158       current->hwDstSrcBlend |= S_SBLEND_INV_DST_COLOR;
159       break;
160    case GL_SRC_ALPHA_SATURATE:
161       current->hwDstSrcBlend |= S_SBLEND_SRC_ALPHA_SAT;
162       break;
163    }
164
165    if (current->hwDstSrcBlend != prev->hwDstSrcBlend) {
166       prev->hwDstSrcBlend = current->hwDstSrcBlend;
167       smesa->GlobalFlag |= GFLAG_DSTBLEND;
168    }
169 }
170
171 /* =============================================================
172  * Depth testing
173  */
174
175 static void
176 sis6326DDDepthFunc( struct gl_context *ctx, GLenum func )
177 {
178    sisContextPtr smesa = SIS_CONTEXT(ctx);
179    __GLSiSHardware *prev = &smesa->prev;
180    __GLSiSHardware *current = &smesa->current;
181
182    current->hwZ &= ~MASK_6326_ZTestMode;
183    switch (func)
184    {
185    case GL_LESS:
186       current->hwZ |= S_ZSET_PASS_LESS;
187       break;
188    case GL_GEQUAL:
189       current->hwZ |= S_ZSET_PASS_GEQUAL;
190       break;
191    case GL_LEQUAL:
192       current->hwZ |= S_ZSET_PASS_LEQUAL;
193       break;
194    case GL_GREATER:
195       current->hwZ |= S_ZSET_PASS_GREATER;
196       break;
197    case GL_NOTEQUAL:
198       current->hwZ |= S_ZSET_PASS_NOTEQUAL;
199       break;
200    case GL_EQUAL:
201       current->hwZ |= S_ZSET_PASS_EQUAL;
202       break;
203    case GL_ALWAYS:
204       current->hwZ |= S_ZSET_PASS_ALWAYS;
205       break;
206    case GL_NEVER:
207       current->hwZ |= S_ZSET_PASS_NEVER;
208       break;
209    }
210
211    if (current->hwZ != prev->hwZ) {
212       prev->hwZ = current->hwZ;
213       smesa->GlobalFlag |= GFLAG_ZSETTING;
214    }
215 }
216
217 static void
218 sis6326DDDepthMask( struct gl_context *ctx, GLboolean flag )
219 {
220    sisContextPtr smesa = SIS_CONTEXT(ctx);
221    __GLSiSHardware *current = &smesa->current;
222
223    if (ctx->Depth.Test)
224       current->hwCapEnable |= S_ENABLE_ZWrite;
225    else
226       current->hwCapEnable &= ~S_ENABLE_ZWrite;
227 }
228
229 /* =============================================================
230  * Fog
231  */
232
233 static void
234 sis6326DDFogfv( struct gl_context *ctx, GLenum pname, const GLfloat *params )
235 {
236    sisContextPtr smesa = SIS_CONTEXT(ctx);
237    __GLSiSHardware *current = &smesa->current;
238    __GLSiSHardware *prev = &smesa->prev;
239
240    GLint fogColor;
241
242    switch(pname)
243    {
244    case GL_FOG_COLOR:
245       fogColor  = FLOAT_TO_UBYTE( ctx->Fog.Color[0] ) << 16;
246       fogColor |= FLOAT_TO_UBYTE( ctx->Fog.Color[1] ) << 8;
247       fogColor |= FLOAT_TO_UBYTE( ctx->Fog.Color[2] );
248       current->hwFog = 0x01000000 | fogColor;
249       if (current->hwFog != prev->hwFog) {
250          prev->hwFog = current->hwFog;
251          smesa->GlobalFlag |= GFLAG_FOGSETTING;
252       }
253       break;
254    }
255 }
256
257 /* =============================================================
258  * Clipping
259  */
260
261 void
262 sis6326UpdateClipping(struct gl_context *ctx)
263 {
264    sisContextPtr smesa = SIS_CONTEXT(ctx);
265
266    __GLSiSHardware *prev = &smesa->prev;
267    __GLSiSHardware *current = &smesa->current;
268
269    GLint x1, y1, x2, y2;
270
271    x1 = 0;
272    y1 = 0;
273    x2 = smesa->width - 1;
274    y2 = smesa->height - 1;
275
276    if (ctx->Scissor.Enabled) {
277       if (ctx->Scissor.X > x1)
278          x1 = ctx->Scissor.X;
279       if (ctx->Scissor.Y > y1)
280          y1 = ctx->Scissor.Y;
281       if (ctx->Scissor.X + ctx->Scissor.Width - 1 < x2)
282          x2 = ctx->Scissor.X + ctx->Scissor.Width - 1;
283       if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < y2)
284          y2 = ctx->Scissor.Y + ctx->Scissor.Height - 1;
285    }
286
287    y1 = Y_FLIP(y1);
288    y2 = Y_FLIP(y2);
289
290    /*current->clipTopBottom = (y2 << 13) | y1;
291    current->clipLeftRight = (x1 << 13) | x2;*/ /* XXX */
292    current->clipTopBottom = (0 << 13) | smesa->height;
293    current->clipLeftRight = (0 << 13) | smesa->width;
294
295    if ((current->clipTopBottom != prev->clipTopBottom) ||
296        (current->clipLeftRight != prev->clipLeftRight)) {
297       prev->clipTopBottom = current->clipTopBottom;
298       prev->clipLeftRight = current->clipLeftRight;
299       smesa->GlobalFlag |= GFLAG_CLIPPING;
300    }
301 }
302
303 static void
304 sis6326DDScissor( struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h )
305 {
306    if (ctx->Scissor.Enabled)
307       sis6326UpdateClipping( ctx );
308 }
309
310 /* =============================================================
311  * Culling
312  */
313
314 static void
315 sis6326UpdateCull( struct gl_context *ctx )
316 {
317    /* XXX culling */
318 }
319
320
321 static void
322 sis6326DDCullFace( struct gl_context *ctx, GLenum mode )
323 {
324    sis6326UpdateCull( ctx );
325 }
326
327 static void
328 sis6326DDFrontFace( struct gl_context *ctx, GLenum mode )
329 {
330    sis6326UpdateCull( ctx );
331 }
332
333 /* =============================================================
334  * Masks
335  */
336
337 static void sis6326DDColorMask( struct gl_context *ctx,
338                                 GLboolean r, GLboolean g,
339                                 GLboolean b, GLboolean a )
340 {
341    sisContextPtr smesa = SIS_CONTEXT(ctx);
342         
343    if (r && g && b && ((ctx->Visual.alphaBits == 0) || a)) {
344       FALLBACK(smesa, SIS_FALLBACK_WRITEMASK, 0);
345    } else {
346       FALLBACK(smesa, SIS_FALLBACK_WRITEMASK, 1);
347    }
348 }
349
350 /* =============================================================
351  * Rendering attributes
352  */
353
354 static void sis6326UpdateSpecular(struct gl_context *ctx)
355 {
356    sisContextPtr smesa = SIS_CONTEXT(ctx);
357    __GLSiSHardware *current = &smesa->current;
358
359    if (_mesa_need_secondary_color(ctx))
360       current->hwCapEnable |= S_ENABLE_Specular;
361    else
362       current->hwCapEnable &= ~S_ENABLE_Specular;
363 }
364
365 static void sis6326DDLightModelfv(struct gl_context *ctx, GLenum pname,
366                               const GLfloat *param)
367 {
368    if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) {
369       sis6326UpdateSpecular(ctx);
370    }
371 }
372 static void sis6326DDShadeModel( struct gl_context *ctx, GLenum mode )
373 {
374    sisContextPtr smesa = SIS_CONTEXT(ctx);
375
376    /* Signal to sisRasterPrimitive to recalculate dwPrimitiveSet */
377    smesa->hw_primitive = -1;
378 }
379
380 /* =============================================================
381  * Window position
382  */
383
384 /* =============================================================
385  * Viewport
386  */
387
388 static void sis6326CalcViewport( struct gl_context *ctx )
389 {
390    sisContextPtr smesa = SIS_CONTEXT(ctx);
391    const GLfloat *v = ctx->Viewport._WindowMap.m;
392    GLfloat *m = smesa->hw_viewport;
393
394    /* See also sis_translate_vertex.
395     */
396    m[MAT_SX] =   v[MAT_SX];
397    m[MAT_TX] =   v[MAT_TX] + SUBPIXEL_X;
398    m[MAT_SY] = - v[MAT_SY];
399    m[MAT_TY] = - v[MAT_TY] + smesa->driDrawable->h + SUBPIXEL_Y;
400    m[MAT_SZ] =   v[MAT_SZ] * smesa->depth_scale;
401    m[MAT_TZ] =   v[MAT_TZ] * smesa->depth_scale;
402 }
403
404 static void sis6326DDViewport( struct gl_context *ctx,
405                            GLint x, GLint y,
406                            GLsizei width, GLsizei height )
407 {
408    sis6326CalcViewport( ctx );
409 }
410
411 static void sis6326DDDepthRange( struct gl_context *ctx,
412                              GLclampd nearval, GLclampd farval )
413 {
414    sis6326CalcViewport( ctx );
415 }
416
417 /* =============================================================
418  * Miscellaneous
419  */
420
421 static void
422 sis6326DDLogicOpCode( struct gl_context *ctx, GLenum opcode )
423 {
424    sisContextPtr smesa = SIS_CONTEXT(ctx);
425
426    __GLSiSHardware *prev = &smesa->prev;
427    __GLSiSHardware *current = &smesa->current;
428
429    if (!ctx->Color.ColorLogicOpEnabled)
430       return;
431
432    current->hwDstSet &= ~MASK_ROP2;
433    switch (opcode)
434    {
435    case GL_CLEAR:
436       current->hwDstSet |= LOP_CLEAR;
437       break;
438    case GL_SET:
439       current->hwDstSet |= LOP_SET;
440       break;
441    case GL_COPY:
442       current->hwDstSet |= LOP_COPY;
443       break;
444    case GL_COPY_INVERTED:
445       current->hwDstSet |= LOP_COPY_INVERTED;
446       break;
447    case GL_NOOP:
448       current->hwDstSet |= LOP_NOOP;
449       break;
450    case GL_INVERT:
451       current->hwDstSet |= LOP_INVERT;
452       break;
453    case GL_AND:
454       current->hwDstSet |= LOP_AND;
455       break;
456    case GL_NAND:
457       current->hwDstSet |= LOP_NAND;
458       break;
459    case GL_OR:
460       current->hwDstSet |= LOP_OR;
461       break;
462    case GL_NOR:
463       current->hwDstSet |= LOP_NOR;
464       break;
465    case GL_XOR:
466       current->hwDstSet |= LOP_XOR;
467       break;
468    case GL_EQUIV:
469       current->hwDstSet |= LOP_EQUIV;
470       break;
471    case GL_AND_REVERSE:
472       current->hwDstSet |= LOP_AND_REVERSE;
473       break;
474    case GL_AND_INVERTED:
475       current->hwDstSet |= LOP_AND_INVERTED;
476       break;
477    case GL_OR_REVERSE:
478       current->hwDstSet |= LOP_OR_REVERSE;
479       break;
480    case GL_OR_INVERTED:
481       current->hwDstSet |= LOP_OR_INVERTED;
482       break;
483    }
484
485    if (current->hwDstSet != prev->hwDstSet) {
486       prev->hwDstSet = current->hwDstSet;
487       smesa->GlobalFlag |= GFLAG_DESTSETTING;
488    }
489 }
490
491 void sis6326DDDrawBuffer( struct gl_context *ctx, GLenum mode )
492 {
493    sisContextPtr smesa = SIS_CONTEXT(ctx);
494
495    __GLSiSHardware *prev = &smesa->prev;
496    __GLSiSHardware *current = &smesa->current;
497
498    if(getenv("SIS_DRAW_FRONT"))
499       ctx->DrawBuffer->_ColorDrawBufferIndexes[0] = BUFFER_FRONT_LEFT;
500
501    if (ctx->DrawBuffer->_NumColorDrawBuffers > 1) {
502       FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_TRUE );
503       return;
504    }
505
506    current->hwDstSet &= ~MASK_DstBufferPitch;
507
508    switch ( ctx->DrawBuffer->_ColorDrawBufferIndexes[0] ) {
509    case BUFFER_FRONT_LEFT:
510       current->hwOffsetDest = smesa->front.offset;
511       current->hwDstSet |= smesa->front.pitch;
512       FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_FALSE );
513       break;
514    case BUFFER_BACK_LEFT:
515       current->hwOffsetDest = smesa->back.offset;
516       current->hwDstSet |= smesa->back.pitch;
517       FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_FALSE );
518       break;
519    default:
520       FALLBACK( smesa, SIS_FALLBACK_DRAW_BUFFER, GL_TRUE );
521       return;
522    }
523
524    if (current->hwDstSet != prev->hwDstSet) {
525       prev->hwDstSet = current->hwDstSet;
526       smesa->GlobalFlag |= GFLAG_DESTSETTING;
527    }
528
529    if (current->hwOffsetDest != prev->hwOffsetDest) {
530       prev->hwOffsetDest = current->hwOffsetDest;
531       smesa->GlobalFlag |= GFLAG_DESTSETTING;
532    }
533 }
534
535 /* =============================================================
536  * Polygon stipple
537  */
538
539 /* =============================================================
540  * Render mode
541  */
542
543 /* =============================================================
544  * State enable/disable
545  */
546
547 static void
548 sis6326DDEnable( struct gl_context *ctx, GLenum cap, GLboolean state )
549 {
550    sisContextPtr smesa = SIS_CONTEXT(ctx);
551
552    __GLSiSHardware *current = &smesa->current;
553
554    switch (cap)
555    {
556    case GL_ALPHA_TEST:
557       if (state)
558          current->hwCapEnable |= S_ENABLE_AlphaTest;
559       else
560          current->hwCapEnable &= ~S_ENABLE_AlphaTest;
561       break;
562    case GL_BLEND:
563       /* TODO: */
564       if (state)
565       /* if (state & !ctx->Color.ColorLogicOpEnabled) */
566          current->hwCapEnable |= S_ENABLE_Blend;
567       else
568          current->hwCapEnable &= ~S_ENABLE_Blend;
569       break;
570    case GL_CULL_FACE:
571       /* XXX culling */
572       break;
573    case GL_DEPTH_TEST:
574       if (state && smesa->depth.offset != 0)
575          current->hwCapEnable |= S_ENABLE_ZTest;
576       else
577          current->hwCapEnable &= ~S_ENABLE_ZTest;
578       sis6326DDDepthMask( ctx, ctx->Depth.Mask );
579       break;
580    case GL_DITHER:
581       if (state)
582          current->hwCapEnable |= S_ENABLE_Dither;
583       else
584          current->hwCapEnable &= ~S_ENABLE_Dither;
585       break;
586    case GL_FOG:
587       if (state)
588          current->hwCapEnable |= S_ENABLE_Fog;
589       else
590          current->hwCapEnable &= ~S_ENABLE_Fog;
591       break;
592    case GL_COLOR_LOGIC_OP:
593       if (state)
594          sis6326DDLogicOpCode( ctx, ctx->Color.LogicOp );
595       else
596          sis6326DDLogicOpCode( ctx, GL_COPY );
597       break;
598    case GL_SCISSOR_TEST:
599       sis6326UpdateClipping( ctx );
600       break;
601    case GL_STENCIL_TEST:
602       if (state) {
603          FALLBACK(smesa, SIS_FALLBACK_STENCIL, 1);
604       } else {
605          FALLBACK(smesa, SIS_FALLBACK_STENCIL, 0);
606       }
607       break;
608    case GL_LIGHTING:
609    case GL_COLOR_SUM_EXT:
610       sis6326UpdateSpecular(ctx);
611       break;
612     }
613 }
614
615 /* =============================================================
616  * State initialization, management
617  */
618
619 /* Called before beginning of rendering. */
620 void
621 sis6326UpdateHWState( struct gl_context *ctx )
622 {
623    sisContextPtr smesa = SIS_CONTEXT(ctx);
624    __GLSiSHardware *prev = &smesa->prev;
625    __GLSiSHardware *current = &smesa->current;
626
627    if (smesa->NewGLState & _NEW_TEXTURE)
628       sisUpdateTextureState( ctx );
629
630    if (current->hwCapEnable ^ prev->hwCapEnable) {
631       prev->hwCapEnable = current->hwCapEnable;
632       smesa->GlobalFlag |= GFLAG_ENABLESETTING;
633    }
634
635    if (smesa->GlobalFlag & GFLAG_RENDER_STATES)
636       sis_update_render_state( smesa );
637
638    if (smesa->GlobalFlag & GFLAG_TEXTURE_STATES)
639       sis_update_texture_state( smesa );
640 }
641
642 static void
643 sis6326DDInvalidateState( struct gl_context *ctx, GLuint new_state )
644 {
645         sisContextPtr smesa = SIS_CONTEXT(ctx);
646
647         _swrast_InvalidateState( ctx, new_state );
648         _swsetup_InvalidateState( ctx, new_state );
649         _vbo_InvalidateState( ctx, new_state );
650         _tnl_InvalidateState( ctx, new_state );
651         smesa->NewGLState |= new_state;
652 }
653
654 /* Initialize the context's hardware state.
655  */
656 void sis6326DDInitState( sisContextPtr smesa )
657 {
658    __GLSiSHardware *prev = &smesa->prev;
659    __GLSiSHardware *current = &smesa->current;
660    struct gl_context *ctx = smesa->glCtx;
661
662    /* add Texture Perspective Enable */
663    current->hwCapEnable = S_ENABLE_TextureCache |
664        S_ENABLE_TexturePerspective | S_ENABLE_Dither;
665
666    /* Z test mode is LESS */
667    current->hwZ = S_ZSET_PASS_LESS | S_ZSET_FORMAT_16;
668    if (ctx->Visual.depthBits > 0)
669       current->hwCapEnable |= S_ENABLE_ZWrite;
670
671    /* Alpha test mode is ALWAYS, alpha ref value is 0 */
672    current->hwAlpha = S_ASET_PASS_ALWAYS;
673
674    /* ROP2 is COPYPEN */
675    current->hwDstSet = LOP_COPY;
676
677    /* LinePattern is 0, Repeat Factor is 0 */
678    current->hwLinePattern = 0x00008000;
679
680    /* Src blend is BLEND_ONE, Dst blend is D3DBLEND_ZERO */
681    current->hwDstSrcBlend = S_SBLEND_ONE | S_DBLEND_ZERO;
682    
683    switch (smesa->bytesPerPixel)
684    {
685    case 2:
686       current->hwDstSet |= DST_FORMAT_RGB_565;
687       break;
688    case 4:
689       current->hwDstSet |= DST_FORMAT_ARGB_8888;
690       break;
691    }
692
693    smesa->depth_scale = 1.0 / (GLfloat)0xffff;
694
695    smesa->clearTexCache = GL_TRUE;
696
697    smesa->clearColorPattern = 0;
698
699    sis6326UpdateZPattern(smesa, 1.0);
700    sis6326UpdateCull(ctx);
701
702    /* Set initial fog settings. Start and end are the same case.  */
703    sis6326DDFogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
704    sis6326DDFogfv( ctx, GL_FOG_END, &ctx->Fog.End );
705    sis6326DDFogfv( ctx, GL_FOG_MODE, NULL );
706
707    memcpy(prev, current, sizeof(__GLSiSHardware));
708 }
709
710 /* Initialize the driver's state functions.
711  */
712 void sis6326DDInitStateFuncs( struct gl_context *ctx )
713 {
714    ctx->Driver.UpdateState              = sis6326DDInvalidateState;
715
716    ctx->Driver.Clear                    = sis6326DDClear;
717    ctx->Driver.ClearColor               = sis6326DDClearColor;
718    ctx->Driver.ClearDepth               = sis6326DDClearDepth;
719
720    ctx->Driver.AlphaFunc                = sis6326DDAlphaFunc;
721    ctx->Driver.BlendFuncSeparate        = sis6326DDBlendFuncSeparate;
722    ctx->Driver.ColorMask                = sis6326DDColorMask;
723    ctx->Driver.CullFace                 = sis6326DDCullFace;
724    ctx->Driver.DepthMask                = sis6326DDDepthMask;
725    ctx->Driver.DepthFunc                = sis6326DDDepthFunc;
726    ctx->Driver.DepthRange               = sis6326DDDepthRange;
727    ctx->Driver.DrawBuffer               = sis6326DDDrawBuffer;
728    ctx->Driver.Enable                   = sis6326DDEnable;
729    ctx->Driver.FrontFace                = sis6326DDFrontFace;
730    ctx->Driver.Fogfv                    = sis6326DDFogfv;
731    ctx->Driver.LogicOpcode              = sis6326DDLogicOpCode;
732    ctx->Driver.Scissor                  = sis6326DDScissor;
733    ctx->Driver.ShadeModel               = sis6326DDShadeModel;
734    ctx->Driver.LightModelfv             = sis6326DDLightModelfv;
735    ctx->Driver.Viewport                 = sis6326DDViewport;
736 }