i830_state.c revision 46eb02b60920a920b782bacb15f01b44e18f888d
16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**************************************************************************
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved.
56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the
86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including
96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions:
136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the
156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software.
176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/
276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "glheader.h"
306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "context.h"
316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "macros.h"
326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "enums.h"
336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "dd.h"
346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "texmem.h"
366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
37a194bc3a8527ed41eead88632cc79ecabe4c81acBrian#include "drivers/common/driverfuncs.h"
38a194bc3a8527ed41eead88632cc79ecabe4c81acBrian
396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_screen.h"
406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_batchbuffer.h"
416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_fbo.h"
426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i830_context.h"
446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i830_reg.h"
456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define FILE_DEBUG_FLAG DEBUG_STATE
476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830StencilFuncSeparate(GLcontext * ctx, GLenum face, GLenum func, GLint ref,
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                        GLuint mask)
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int test = intel_translate_compare_func(func);
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   mask = mask & 0xff;
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s : func: %s, ref : 0x%x, mask: 0x%x\n", __FUNCTION__,
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(func), ref, mask);
596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_TEST_MASK;
636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE4] |= (ENABLE_STENCIL_TEST_MASK |
646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           STENCIL_TEST_MASK(mask));
656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STENCILTST] &= ~(STENCIL_REF_VALUE_MASK |
666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_STENCIL_TEST_FUNC_MASK);
676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STENCILTST] |= (ENABLE_STENCIL_REF_VALUE |
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               ENABLE_STENCIL_TEST_FUNC |
696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               STENCIL_REF_VALUE(ref) |
706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               STENCIL_TEST_FUNC(test));
716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830StencilMaskSeparate(GLcontext * ctx, GLenum face, GLuint mask)
756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s : mask 0x%x\n", __FUNCTION__, mask);
796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   mask = mask & 0xff;
816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE4] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK;
846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE4] |= (ENABLE_STENCIL_WRITE_MASK |
856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           STENCIL_WRITE_MASK(mask));
866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830StencilOpSeparate(GLcontext * ctx, GLenum face, GLenum fail, GLenum zfail,
906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                      GLenum zpass)
916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int fop, dfop, dpop;
946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s: fail : %s, zfail: %s, zpass : %s\n", __FUNCTION__,
966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(fail),
976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(zfail),
986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(zpass));
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   fop = 0;
1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   dfop = 0;
1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   dpop = 0;
1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (fail) {
1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_KEEP:
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fop = STENCILOP_KEEP;
1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_ZERO:
1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fop = STENCILOP_ZERO;
1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_REPLACE:
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fop = STENCILOP_REPLACE;
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INCR:
1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fop = STENCILOP_INCRSAT;
1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_DECR:
1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fop = STENCILOP_DECRSAT;
1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INCR_WRAP:
1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fop = STENCILOP_INCR;
1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_DECR_WRAP:
1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fop = STENCILOP_DECR;
1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INVERT:
1276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fop = STENCILOP_INVERT;
1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (zfail) {
1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_KEEP:
1346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dfop = STENCILOP_KEEP;
1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_ZERO:
1376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dfop = STENCILOP_ZERO;
1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_REPLACE:
1406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dfop = STENCILOP_REPLACE;
1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INCR:
1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dfop = STENCILOP_INCRSAT;
1446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_DECR:
1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dfop = STENCILOP_DECRSAT;
1476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INCR_WRAP:
1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dfop = STENCILOP_INCR;
1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_DECR_WRAP:
1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dfop = STENCILOP_DECR;
1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INVERT:
1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dfop = STENCILOP_INVERT;
1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
1586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (zpass) {
1616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_KEEP:
1626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dpop = STENCILOP_KEEP;
1636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_ZERO:
1656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dpop = STENCILOP_ZERO;
1666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_REPLACE:
1686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dpop = STENCILOP_REPLACE;
1696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INCR:
1716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dpop = STENCILOP_INCRSAT;
1726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_DECR:
1746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dpop = STENCILOP_DECRSAT;
1756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INCR_WRAP:
1776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dpop = STENCILOP_INCR;
1786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_DECR_WRAP:
1806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dpop = STENCILOP_DECR;
1816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_INVERT:
1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      dpop = STENCILOP_INVERT;
1846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
1916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STENCILTST] &= ~(STENCIL_OPS_MASK);
1926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STENCILTST] |= (ENABLE_STENCIL_PARMS |
1936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               STENCIL_FAIL_OP(fop) |
1946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               STENCIL_PASS_DEPTH_FAIL_OP
1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               (dfop) |
1966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               STENCIL_PASS_DEPTH_PASS_OP
1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               (dpop));
1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830AlphaFunc(GLcontext * ctx, GLenum func, GLfloat ref)
2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int test = intel_translate_compare_func(func);
2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLubyte refByte;
2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint refInt;
2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE(refByte, ref);
2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   refInt = (GLuint) refByte;
2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE2] &= ~ALPHA_TEST_REF_MASK;
2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE2] |= (ENABLE_ALPHA_TEST_FUNC |
2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           ENABLE_ALPHA_REF_VALUE |
2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           ALPHA_TEST_FUNC(test) |
2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           ALPHA_REF_VALUE(refInt));
2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**
2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Makes sure that the proper enables are set for LogicOp, Independant Alpha
2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Blend, and Blending.  It needs to be called from numerous places where we
2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * could change the LogicOp or Independant Alpha Blend without subsequent
2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * calls to glEnable.
2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
2256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * \todo
2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * This function is substantially different from the old i830-specific driver.
2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * I'm not sure which is correct.
2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830EvalLogicOpBlendState(GLcontext * ctx)
2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2367a9c7c1133d5cf17d032c8568e8f040a7c171a72Brian Paul   if (RGBA_LOGICOP_ENABLED(ctx)) {
2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~(ENABLE_COLOR_BLEND |
2386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                  ENABLE_LOGIC_OP_MASK);
2396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] |= (DISABLE_COLOR_BLEND |
2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                 ENABLE_LOGIC_OP);
2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else if (ctx->Color.BlendEnabled) {
2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~(ENABLE_COLOR_BLEND |
2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                  ENABLE_LOGIC_OP_MASK);
2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] |= (ENABLE_COLOR_BLEND |
2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                 DISABLE_LOGIC_OP);
2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else {
2496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~(ENABLE_COLOR_BLEND |
2506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                  ENABLE_LOGIC_OP_MASK);
2516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] |= (DISABLE_COLOR_BLEND |
2526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                 DISABLE_LOGIC_OP);
2536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
2556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
2576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830BlendColor(GLcontext * ctx, const GLfloat color[4])
2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
2596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
2606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLubyte r, g, b, a;
2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s\n", __FUNCTION__);
2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE(r, color[RCOMP]);
2656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE(g, color[GCOMP]);
2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE(b, color[BCOMP]);
2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE(a, color[ACOMP]);
2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_BLENDCOLOR1] =
2716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      (a << 24) | (r << 16) | (g << 8) | b;
2726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**
2756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Sets both the blend equation (called "function" in i830 docs) and the
2766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * blend function (called "factor" in i830 docs).  This is done in a single
2776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * change the interpretation of the blend function.
2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_set_blend_state(GLcontext * ctx)
2826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
2846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int funcA;
2856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int funcRGB;
2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int eqnA;
2876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int eqnRGB;
2886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int iab;
2896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int s1;
2906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   funcRGB =
2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      SRC_BLND_FACT(intel_translate_blend_factor(ctx->Color.BlendSrcRGB))
2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      | DST_BLND_FACT(intel_translate_blend_factor(ctx->Color.BlendDstRGB));
2956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (ctx->Color.BlendEquationRGB) {
2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_FUNC_ADD:
2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnRGB = BLENDFUNC_ADD;
2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_MIN:
3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnRGB = BLENDFUNC_MIN;
3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      funcRGB = SRC_BLND_FACT(BLENDFACT_ONE) | DST_BLND_FACT(BLENDFACT_ONE);
3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_MAX:
3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnRGB = BLENDFUNC_MAX;
3066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      funcRGB = SRC_BLND_FACT(BLENDFACT_ONE) | DST_BLND_FACT(BLENDFACT_ONE);
3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_FUNC_SUBTRACT:
3096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnRGB = BLENDFUNC_SUB;
3106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_FUNC_REVERSE_SUBTRACT:
3126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnRGB = BLENDFUNC_RVRSE_SUB;
3136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
3156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fprintf(stderr, "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
3166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              __FUNCTION__, __LINE__, ctx->Color.BlendEquationRGB);
3176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return;
3186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   funcA = SRC_ABLEND_FACT(intel_translate_blend_factor(ctx->Color.BlendSrcA))
3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      | DST_ABLEND_FACT(intel_translate_blend_factor(ctx->Color.BlendDstA));
3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (ctx->Color.BlendEquationA) {
3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_FUNC_ADD:
3266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnA = BLENDFUNC_ADD;
3276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_MIN:
3296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnA = BLENDFUNC_MIN;
3306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      funcA = SRC_BLND_FACT(BLENDFACT_ONE) | DST_BLND_FACT(BLENDFACT_ONE);
3316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_MAX:
3336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnA = BLENDFUNC_MAX;
3346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      funcA = SRC_BLND_FACT(BLENDFACT_ONE) | DST_BLND_FACT(BLENDFACT_ONE);
3356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_FUNC_SUBTRACT:
3376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnA = BLENDFUNC_SUB;
3386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_FUNC_REVERSE_SUBTRACT:
3406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      eqnA = BLENDFUNC_RVRSE_SUB;
3416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
3426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
3436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fprintf(stderr, "[%s:%u] Invalid alpha blend equation (0x%04x).\n",
3446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              __FUNCTION__, __LINE__, ctx->Color.BlendEquationA);
3456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return;
3466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   iab = eqnA | funcA
3496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      | _3DSTATE_INDPT_ALPHA_BLEND_CMD
3506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      | ENABLE_SRC_ABLEND_FACTOR | ENABLE_DST_ABLEND_FACTOR
3516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      | ENABLE_ALPHA_BLENDFUNC;
3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   s1 = eqnRGB | funcRGB
3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      | _3DSTATE_MODES_1_CMD
3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      | ENABLE_SRC_BLND_FACTOR | ENABLE_DST_BLND_FACTOR
3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      | ENABLE_COLR_BLND_FUNC;
3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if ((eqnA | funcA) != (eqnRGB | funcRGB))
3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      iab |= ENABLE_INDPT_ALPHA_BLEND;
3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else
3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      iab |= DISABLE_INDPT_ALPHA_BLEND;
3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (iab != i830->state.Ctx[I830_CTXREG_IALPHAB] ||
3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       s1 != i830->state.Ctx[I830_CTXREG_STATE1]) {
3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_IALPHAB] = iab;
3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_STATE1] = s1;
3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* This will catch a logicop blend equation.  It will also ensure
3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * independant alpha blend is really in the correct state (either enabled
3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * or disabled) if blending is already enabled.
3726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830EvalLogicOpBlendState(ctx);
3756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (0) {
3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fprintf(stderr,
3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              "[%s:%u] STATE1: 0x%08x IALPHAB: 0x%08x blend is %sabled\n",
3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              __FUNCTION__, __LINE__, i830->state.Ctx[I830_CTXREG_STATE1],
3806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              i830->state.Ctx[I830_CTXREG_IALPHAB],
3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              (ctx->Color.BlendEnabled) ? "en" : "dis");
3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
3876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830BlendEquationSeparate(GLcontext * ctx, GLenum modeRGB, GLenum modeA)
3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s -> %s, %s\n", __FUNCTION__,
3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(modeRGB),
3916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(modeA));
3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   (void) modeRGB;
3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   (void) modeA;
3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830_set_blend_state(ctx);
3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
4006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830BlendFuncSeparate(GLcontext * ctx, GLenum sfactorRGB,
4016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                      GLenum dfactorRGB, GLenum sfactorA, GLenum dfactorA)
4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s -> RGB(%s, %s) A(%s, %s)\n", __FUNCTION__,
4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(sfactorRGB),
4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(dfactorRGB),
4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(sfactorA),
4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       _mesa_lookup_enum_by_nr(dfactorA));
4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   (void) sfactorRGB;
4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   (void) dfactorRGB;
4116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   (void) sfactorA;
4126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   (void) dfactorA;
4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830_set_blend_state(ctx);
4146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
4196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830DepthFunc(GLcontext * ctx, GLenum func)
4206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
4216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
4226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int test = intel_translate_compare_func(func);
4236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s\n", __FUNCTION__);
4256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
4276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE3] &= ~DEPTH_TEST_FUNC_MASK;
4286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE3] |= (ENABLE_DEPTH_TEST_FUNC |
4296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           DEPTH_TEST_FUNC(test));
4306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
4336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830DepthMask(GLcontext * ctx, GLboolean flag)
4346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
4356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
4366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s flag (%d)\n", __FUNCTION__, flag);
4386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
4406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_ENABLES_2] &= ~ENABLE_DIS_DEPTH_WRITE_MASK;
4426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (flag && ctx->Depth.Test)
4446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_2] |= ENABLE_DEPTH_WRITE;
4456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else
4466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_2] |= DISABLE_DEPTH_WRITE;
4476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* =============================================================
4506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Polygon stipple
4516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
4526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The i830 supports a 4x4 stipple natively, GL wants 32x32.
4536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Fortunately stipple is usually a repeating pattern.
4546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
4556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
4566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830PolygonStipple(GLcontext * ctx, const GLubyte * mask)
4576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
4586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
4596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   const GLubyte *m = mask;
4606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLubyte p[4];
4616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int i, j, k;
4626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int active = (ctx->Polygon.StippleFlag &&
4636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                 i830->intel.reduced_primitive == GL_TRIANGLES);
4646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint newMask;
4656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (active) {
4676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_STIPPLE);
4686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Stipple[I830_STPREG_ST1] &= ~ST1_ENABLE;
4696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   p[0] = mask[12] & 0xf;
4726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   p[0] |= p[0] << 4;
4736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   p[1] = mask[8] & 0xf;
4746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   p[1] |= p[1] << 4;
4756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   p[2] = mask[4] & 0xf;
4766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   p[2] |= p[2] << 4;
4776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   p[3] = mask[0] & 0xf;
4786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   p[3] |= p[3] << 4;
4796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (k = 0; k < 8; k++)
4816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      for (j = 3; j >= 0; j--)
4826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         for (i = 0; i < 4; i++, m++)
4836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            if (*m != p[j]) {
4846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               i830->intel.hw_stipple = 0;
4856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               return;
4866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            }
4876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   newMask = (((p[0] & 0xf) << 0) |
4896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              ((p[1] & 0xf) << 4) |
4906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              ((p[2] & 0xf) << 8) | ((p[3] & 0xf) << 12));
4916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (newMask == 0xffff || newMask == 0x0) {
4946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* this is needed to make conform pass */
4956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->intel.hw_stipple = 0;
4966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return;
4976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Stipple[I830_STPREG_ST1] &= ~0xffff;
5006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Stipple[I830_STPREG_ST1] |= newMask;
5016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->intel.hw_stipple = 1;
5026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (active)
5046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Stipple[I830_STPREG_ST1] |= ST1_ENABLE;
5056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* =============================================================
5096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Hardware clipping
5106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
5116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
5126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830Scissor(GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h)
5136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
5146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
5156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int x1, y1, x2, y2;
5166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (!ctx->DrawBuffer)
5186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return;
5196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s %d,%d %dx%d\n", __FUNCTION__, x, y, w, h);
5216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (ctx->DrawBuffer->Name == 0) {
5236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      x1 = x;
5246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      y1 = ctx->DrawBuffer->Height - (y + h);
5256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      x2 = x + w - 1;
5266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      y2 = y1 + h - 1;
5276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      DBG("%s %d..%d,%d..%d (inverted)\n", __FUNCTION__, x1, x2, y1, y2);
5286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
5296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else {
5306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* FBO - not inverted
5316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
5326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      x1 = x;
5336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      y1 = y;
5346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      x2 = x + w - 1;
5356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      y2 = y + h - 1;
5366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      DBG("%s %d..%d,%d..%d (not inverted)\n", __FUNCTION__, x1, x2, y1, y2);
5376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
5386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   x1 = CLAMP(x1, 0, ctx->DrawBuffer->Width - 1);
5406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   y1 = CLAMP(y1, 0, ctx->DrawBuffer->Height - 1);
5416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   x2 = CLAMP(x2, 0, ctx->DrawBuffer->Width - 1);
5426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   y2 = CLAMP(y2, 0, ctx->DrawBuffer->Height - 1);
5436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s %d..%d,%d..%d (clamped)\n", __FUNCTION__, x1, x2, y1, y2);
5456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_BUFFERS);
5476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Buffer[I830_DESTREG_SR1] = (y1 << 16) | (x1 & 0xffff);
5486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Buffer[I830_DESTREG_SR2] = (y2 << 16) | (x2 & 0xffff);
5496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
5526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830LogicOp(GLcontext * ctx, GLenum opcode)
5536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
5546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
5556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int tmp = intel_translate_logic_op(opcode);
5566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s\n", __FUNCTION__);
5586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
5606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE4] &= ~LOGICOP_MASK;
5616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE4] |= LOGIC_OP_FUNC(tmp);
5626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
5676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830CullFaceFrontFace(GLcontext * ctx, GLenum unused)
5686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
5696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
5706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint mode;
5716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s\n", __FUNCTION__);
5736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (!ctx->Polygon.CullFlag) {
5756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      mode = CULLMODE_NONE;
5766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
5776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else if (ctx->Polygon.CullFaceMode != GL_FRONT_AND_BACK) {
5786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      mode = CULLMODE_CW;
5796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (ctx->Polygon.CullFaceMode == GL_FRONT)
5816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mode ^= (CULLMODE_CW ^ CULLMODE_CCW);
5826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (ctx->Polygon.FrontFace != GL_CCW)
5836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mode ^= (CULLMODE_CW ^ CULLMODE_CCW);
5846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
5856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else {
5866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      mode = CULLMODE_BOTH;
5876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
5886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
5906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE3] &= ~CULLMODE_MASK;
5916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE3] |= ENABLE_CULL_MODE | mode;
5926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
5956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830LineWidth(GLcontext * ctx, GLfloat widthf)
5966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
5976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
5986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int width;
5996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int state5;
6006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s\n", __FUNCTION__);
6026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   width = (int) (widthf * 2);
6046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   CLAMP_SELF(width, 1, 15);
6056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state5 = i830->state.Ctx[I830_CTXREG_STATE5] & ~FIXED_LINE_WIDTH_MASK;
6076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state5 |= (ENABLE_FIXED_LINE_WIDTH | FIXED_LINE_WIDTH(width));
6086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (state5 != i830->state.Ctx[I830_CTXREG_STATE5]) {
6106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
6116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_STATE5] = state5;
6126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
6136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
6146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
6166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830PointSize(GLcontext * ctx, GLfloat size)
6176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
6186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
6196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLint point_size = (int) size;
6206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s\n", __FUNCTION__);
6226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   CLAMP_SELF(point_size, 1, 256);
6246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
6256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE5] &= ~FIXED_POINT_WIDTH_MASK;
6266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE5] |= (ENABLE_FIXED_POINT_WIDTH |
6276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           FIXED_POINT_WIDTH(point_size));
6286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
6296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* =============================================================
6326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Color masks
6336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
6346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
6366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830ColorMask(GLcontext * ctx,
6376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell              GLboolean r, GLboolean g, GLboolean b, GLboolean a)
6386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
6396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
6406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint tmp = 0;
6416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__, r, g, b, a);
6436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tmp = ((i830->state.Ctx[I830_CTXREG_ENABLES_2] & ~WRITEMASK_MASK) |
6456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          ENABLE_COLOR_MASK |
6466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          ENABLE_COLOR_WRITE |
6476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          ((!r) << WRITEMASK_RED_SHIFT) |
6486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          ((!g) << WRITEMASK_GREEN_SHIFT) |
6496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          ((!b) << WRITEMASK_BLUE_SHIFT) | ((!a) << WRITEMASK_ALPHA_SHIFT));
6506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (tmp != i830->state.Ctx[I830_CTXREG_ENABLES_2]) {
6526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
6536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_2] = tmp;
6546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
6556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
6566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
6586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellupdate_specular(GLcontext * ctx)
6596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
6606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
6616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
6636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_SPEC_ADD_MASK;
6646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (NEED_SECONDARY_COLOR(ctx))
6666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_SPEC_ADD;
6676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else
6686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_SPEC_ADD;
6696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
6706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
6726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830LightModelfv(GLcontext * ctx, GLenum pname, const GLfloat * param)
6736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
6746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s\n", __FUNCTION__);
6756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) {
6776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      update_specular(ctx);
6786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
6796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
6806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* In Mesa 3.5 we can reliably do native flatshading.
6826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
6836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
6846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830ShadeModel(GLcontext * ctx, GLenum mode)
6856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
6866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
6876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I830_STATECHANGE(i830, I830_UPLOAD_CTX);
6886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define SHADE_MODE_MASK ((1<<10)|(1<<8)|(1<<6)|(1<<4))
6916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE3] &= ~SHADE_MODE_MASK;
6936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (mode == GL_FLAT) {
6956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_STATE3] |=
6966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         (ALPHA_SHADE_MODE(SHADE_MODE_FLAT) | FOG_SHADE_MODE(SHADE_MODE_FLAT)
6976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          | SPEC_SHADE_MODE(SHADE_MODE_FLAT) |
6986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          COLOR_SHADE_MODE(SHADE_MODE_FLAT));
6996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
7006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else {
7016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_STATE3] |=
7026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         (ALPHA_SHADE_MODE(SHADE_MODE_LINEAR) |
7036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          FOG_SHADE_MODE(SHADE_MODE_LINEAR) |
7046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          SPEC_SHADE_MODE(SHADE_MODE_LINEAR) |
7056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          COLOR_SHADE_MODE(SHADE_MODE_LINEAR));
7066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
7076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
7086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* =============================================================
7106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Fog
7116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
7126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
7136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830Fogfv(GLcontext * ctx, GLenum pname, const GLfloat * param)
7146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
7156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
7166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG("%s\n", __FUNCTION__);
7186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (pname == GL_FOG_COLOR) {
7206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLuint color = (((GLubyte) (ctx->Fog.Color[0] * 255.0F) << 16) |
7216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                      ((GLubyte) (ctx->Fog.Color[1] * 255.0F) << 8) |
7226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                      ((GLubyte) (ctx->Fog.Color[2] * 255.0F) << 0));
7236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
7256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_FOGCOLOR] =
7266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         (_3DSTATE_FOG_COLOR_CMD | color);
7276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
7286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
7296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* =============================================================
7316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
7326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
7346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830Enable(GLcontext * ctx, GLenum cap, GLboolean state)
7356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
7366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i830_context *i830 = i830_context(ctx);
7376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (cap) {
7396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_LIGHTING:
7406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_COLOR_SUM:
7416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      update_specular(ctx);
7426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
7436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_ALPHA_TEST:
7456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
7466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_DIS_ALPHA_TEST_MASK;
7476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (state)
7486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_ALPHA_TEST;
7496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else
7506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_ALPHA_TEST;
7516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
7536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_BLEND:
7556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830EvalLogicOpBlendState(ctx);
7566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
7576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_COLOR_LOGIC_OP:
7596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830EvalLogicOpBlendState(ctx);
7606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Logicop doesn't seem to work at 16bpp:
7626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
76346eb02b60920a920b782bacb15f01b44e18f888dKristian Høgsberg      if (i830->intel.ctx.Visual.rgbBits == 16)
7646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         FALLBACK(&i830->intel, I830_FALLBACK_LOGICOP, state);
7656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
7666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_DITHER:
7686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
7696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_2] &= ~ENABLE_DITHER;
7706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (state)
7726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_ENABLES_2] |= ENABLE_DITHER;
7736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else
7746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_ENABLES_2] |= DISABLE_DITHER;
7756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
7766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_DEPTH_TEST:
7786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
7796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_DIS_DEPTH_TEST_MASK;
7806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (state)
7826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_DEPTH_TEST;
7836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else
7846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_DEPTH_TEST;
7856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Also turn off depth writes when GL_DEPTH_TEST is disabled:
7876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
7886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830DepthMask(ctx, ctx->Depth.Mask);
7896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
7906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_SCISSOR_TEST:
7926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_BUFFERS);
7936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (state)
7956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Buffer[I830_DESTREG_SENABLE] =
7966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            (_3DSTATE_SCISSOR_ENABLE_CMD | ENABLE_SCISSOR_RECT);
7976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else
7986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Buffer[I830_DESTREG_SENABLE] =
7996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
8006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
8026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_LINE_SMOOTH:
8046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
8056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_AA] &= ~AA_LINE_ENABLE;
8076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (state)
8086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_AA] |= AA_LINE_ENABLE;
8096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else
8106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_AA] |= AA_LINE_DISABLE;
8116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
8126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_FOG:
8146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      I830_STATECHANGE(i830, I830_UPLOAD_CTX);
8156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_DIS_FOG_MASK;
8166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (state)
8176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_FOG;
8186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else
8196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_FOG;
8206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
8216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CULL_FACE:
8236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830CullFaceFrontFace(ctx, 0);
8246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
8256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_TEXTURE_2D:
8276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
8286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_STENCIL_TEST:
8306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      {
8316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         GLboolean hw_stencil = GL_FALSE;
8326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (ctx->DrawBuffer) {
8336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            struct intel_renderbuffer *irbStencil
8346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_STENCIL);
8356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            hw_stencil = (irbStencil && irbStencil->region);
8366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
8376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (hw_stencil) {
8386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            I830_STATECHANGE(i830, I830_UPLOAD_CTX);
8396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            if (state) {
8416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               i830->state.Ctx[I830_CTXREG_ENABLES_1] |= ENABLE_STENCIL_TEST;
8426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               i830->state.Ctx[I830_CTXREG_ENABLES_2] |= ENABLE_STENCIL_WRITE;
8436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            }
8446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            else {
8456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               i830->state.Ctx[I830_CTXREG_ENABLES_1] &= ~ENABLE_STENCIL_TEST;
8466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               i830->state.Ctx[I830_CTXREG_ENABLES_2] &=
8476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                  ~ENABLE_STENCIL_WRITE;
8486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               i830->state.Ctx[I830_CTXREG_ENABLES_1] |= DISABLE_STENCIL_TEST;
8496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               i830->state.Ctx[I830_CTXREG_ENABLES_2] |=
8506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                  DISABLE_STENCIL_WRITE;
8516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            }
8526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
8536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         else {
8546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            FALLBACK(&i830->intel, I830_FALLBACK_STENCIL, state);
8556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
8566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
8576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
8586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_POLYGON_STIPPLE:
8606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* The stipple command worked on my 855GM box, but not my 845G.
8616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * I'll do more testing later to find out exactly which hardware
8626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * supports it.  Disabled for now.
8636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
8646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (i830->intel.hw_stipple &&
8656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          i830->intel.reduced_primitive == GL_TRIANGLES) {
8666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         I830_STATECHANGE(i830, I830_UPLOAD_STIPPLE);
8676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         i830->state.Stipple[I830_STPREG_ST1] &= ~ST1_ENABLE;
8686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (state)
8696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            i830->state.Stipple[I830_STPREG_ST1] |= ST1_ENABLE;
8706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
8716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      break;
8726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
8746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      ;
8756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
8766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
8776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
8806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_init_packets(struct i830_context *i830)
8816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
8826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Zero all state */
8836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   memset(&i830->state, 0, sizeof(i830->state));
8846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Set default blend state */
8866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.TexBlend[0][0] = (_3DSTATE_MAP_BLEND_OP_CMD(0) |
8876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXPIPE_COLOR |
8886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 ENABLE_TEXOUTPUT_WRT_SEL |
8896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXOP_OUTPUT_CURRENT |
8906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 DISABLE_TEX_CNTRL_STAGE |
8916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXOP_SCALE_1X |
8926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXOP_MODIFY_PARMS |
8936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXOP_LAST_STAGE | TEXBLENDOP_ARG1);
8946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.TexBlend[0][1] = (_3DSTATE_MAP_BLEND_OP_CMD(0) |
8956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXPIPE_ALPHA |
8966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 ENABLE_TEXOUTPUT_WRT_SEL |
8976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXOP_OUTPUT_CURRENT |
8986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXOP_SCALE_1X |
8996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXOP_MODIFY_PARMS | TEXBLENDOP_ARG1);
9006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.TexBlend[0][2] = (_3DSTATE_MAP_BLEND_ARG_CMD(0) |
9016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXPIPE_COLOR |
9026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXBLEND_ARG1 |
9036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXBLENDARG_MODIFY_PARMS |
9046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXBLENDARG_DIFFUSE);
9056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.TexBlend[0][3] = (_3DSTATE_MAP_BLEND_ARG_CMD(0) |
9066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXPIPE_ALPHA |
9076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXBLEND_ARG1 |
9086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXBLENDARG_MODIFY_PARMS |
9096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 TEXBLENDARG_DIFFUSE);
9106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.TexBlendWordsUsed[0] = 4;
9126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_VF] = 0;
9156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_VF2] = 0;
9166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_AA] = (_3DSTATE_AA_CMD |
9186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                      AA_LINE_ECAAR_WIDTH_ENABLE |
9196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                      AA_LINE_ECAAR_WIDTH_1_0 |
9206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                      AA_LINE_REGION_WIDTH_ENABLE |
9216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                      AA_LINE_REGION_WIDTH_1_0 |
9226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                      AA_LINE_DISABLE);
9236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_ENABLES_1] = (_3DSTATE_ENABLES_1_CMD |
9256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                             DISABLE_LOGIC_OP |
9266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                             DISABLE_STENCIL_TEST |
9276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                             DISABLE_DEPTH_BIAS |
9286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                             DISABLE_SPEC_ADD |
9296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                             DISABLE_FOG |
9306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                             DISABLE_ALPHA_TEST |
9316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                             DISABLE_COLOR_BLEND |
9326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                             DISABLE_DEPTH_TEST);
9336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#if 000                         /* XXX all the stencil enable state is set in i830Enable(), right? */
9356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (i830->intel.hw_stencil) {
9366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_2] = (_3DSTATE_ENABLES_2_CMD |
9376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_STENCIL_WRITE |
9386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_TEX_CACHE |
9396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_DITHER |
9406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_COLOR_MASK |
9416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                /* set no color comps disabled */
9426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_COLOR_WRITE |
9436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_DEPTH_WRITE);
9446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
9456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else
9466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
9476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
9486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i830->state.Ctx[I830_CTXREG_ENABLES_2] = (_3DSTATE_ENABLES_2_CMD |
9496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                DISABLE_STENCIL_WRITE |
9506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_TEX_CACHE |
9516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_DITHER |
9526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_COLOR_MASK |
9536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                /* set no color comps disabled */
9546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_COLOR_WRITE |
9556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                                ENABLE_DEPTH_WRITE);
9566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
9576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE1] = (_3DSTATE_MODES_1_CMD |
9596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_COLR_BLND_FUNC |
9606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          BLENDFUNC_ADD |
9616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_SRC_BLND_FACTOR |
9626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          SRC_BLND_FACT(BLENDFACT_ONE) |
9636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_DST_BLND_FACTOR |
9646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          DST_BLND_FACT(BLENDFACT_ZERO));
9656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE2] = (_3DSTATE_MODES_2_CMD |
9676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_GLOBAL_DEPTH_BIAS |
9686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          GLOBAL_DEPTH_BIAS(0) |
9696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_ALPHA_TEST_FUNC |
9706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ALPHA_TEST_FUNC(COMPAREFUNC_ALWAYS)
9716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          | ALPHA_REF_VALUE(0));
9726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE3] = (_3DSTATE_MODES_3_CMD |
9746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_DEPTH_TEST_FUNC |
9756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          DEPTH_TEST_FUNC(COMPAREFUNC_LESS) |
9766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_ALPHA_SHADE_MODE |
9776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ALPHA_SHADE_MODE(SHADE_MODE_LINEAR)
9786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          | ENABLE_FOG_SHADE_MODE |
9796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          FOG_SHADE_MODE(SHADE_MODE_LINEAR) |
9806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_SPEC_SHADE_MODE |
9816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          SPEC_SHADE_MODE(SHADE_MODE_LINEAR) |
9826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_COLOR_SHADE_MODE |
9836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          COLOR_SHADE_MODE(SHADE_MODE_LINEAR)
9846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          | ENABLE_CULL_MODE | CULLMODE_NONE);
9856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE4] = (_3DSTATE_MODES_4_CMD |
9876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_LOGIC_OP_FUNC |
9886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          LOGIC_OP_FUNC(LOGICOP_COPY) |
9896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_STENCIL_TEST_MASK |
9906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          STENCIL_TEST_MASK(0xff) |
9916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_STENCIL_WRITE_MASK |
9926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          STENCIL_WRITE_MASK(0xff));
9936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STENCILTST] = (_3DSTATE_STENCIL_TEST_CMD |
9956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              ENABLE_STENCIL_PARMS |
9966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              STENCIL_FAIL_OP(STENCILOP_KEEP)
9976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              |
9986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              STENCIL_PASS_DEPTH_FAIL_OP
9996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              (STENCILOP_KEEP) |
10006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              STENCIL_PASS_DEPTH_PASS_OP
10016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              (STENCILOP_KEEP) |
10026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              ENABLE_STENCIL_TEST_FUNC |
10036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              STENCIL_TEST_FUNC
10046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              (COMPAREFUNC_ALWAYS) |
10056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              ENABLE_STENCIL_REF_VALUE |
10066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                              STENCIL_REF_VALUE(0));
10076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_STATE5] = (_3DSTATE_MODES_5_CMD | FLUSH_TEXTURE_CACHE | ENABLE_SPRITE_POINT_TEX | SPRITE_POINT_TEX_OFF | ENABLE_FIXED_LINE_WIDTH | FIXED_LINE_WIDTH(0x2) |       /* 1.0 */
10096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          ENABLE_FIXED_POINT_WIDTH |
10106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                          FIXED_POINT_WIDTH(1));
10116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_IALPHAB] = (_3DSTATE_INDPT_ALPHA_BLEND_CMD |
10136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           DISABLE_INDPT_ALPHA_BLEND |
10146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           ENABLE_ALPHA_BLENDFUNC |
10156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                           ABLENDFUNC_ADD);
10166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_FOGCOLOR] = (_3DSTATE_FOG_COLOR_CMD |
10186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                            FOG_COLOR_RED(0) |
10196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                            FOG_COLOR_GREEN(0) |
10206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                            FOG_COLOR_BLUE(0));
10216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_BLENDCOLOR0] = _3DSTATE_CONST_BLEND_COLOR_CMD;
10236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_BLENDCOLOR1] = 0;
10246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_MCSB0] = _3DSTATE_MAP_COORD_SETBIND_CMD;
10266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Ctx[I830_CTXREG_MCSB1] = (TEXBIND_SET3(TEXCOORDSRC_VTXSET_3) |
10276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                         TEXBIND_SET2(TEXCOORDSRC_VTXSET_2) |
10286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                         TEXBIND_SET1(TEXCOORDSRC_VTXSET_1) |
10296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                         TEXBIND_SET0(TEXCOORDSRC_VTXSET_0));
10306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Stipple[I830_STPREG_ST0] = _3DSTATE_STIPPLE;
10336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Buffer[I830_DESTREG_DV0] = _3DSTATE_DST_BUF_VARS_CMD;
10356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Buffer[I830_DESTREG_SENABLE] = (_3DSTATE_SCISSOR_ENABLE_CMD |
10366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               DISABLE_SCISSOR_RECT);
10376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Buffer[I830_DESTREG_SR0] = _3DSTATE_SCISSOR_RECT_0_CMD;
10386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Buffer[I830_DESTREG_SR1] = 0;
10396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.Buffer[I830_DESTREG_SR2] = 0;
10406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
10416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
10446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830InitStateFuncs(struct dd_function_table *functions)
10456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
10466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->AlphaFunc = i830AlphaFunc;
10476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->BlendColor = i830BlendColor;
10486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->BlendEquationSeparate = i830BlendEquationSeparate;
10496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->BlendFuncSeparate = i830BlendFuncSeparate;
10506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->ColorMask = i830ColorMask;
10516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->CullFace = i830CullFaceFrontFace;
10526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->DepthFunc = i830DepthFunc;
10536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->DepthMask = i830DepthMask;
10546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->Enable = i830Enable;
10556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->Fogfv = i830Fogfv;
10566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->FrontFace = i830CullFaceFrontFace;
10576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->LightModelfv = i830LightModelfv;
10586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->LineWidth = i830LineWidth;
10596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->LogicOpcode = i830LogicOp;
10606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->PointSize = i830PointSize;
10616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->PolygonStipple = i830PolygonStipple;
10626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->Scissor = i830Scissor;
10636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->ShadeModel = i830ShadeModel;
10646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->StencilFuncSeparate = i830StencilFuncSeparate;
10656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->StencilMaskSeparate = i830StencilMaskSeparate;
10666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   functions->StencilOpSeparate = i830StencilOpSeparate;
10676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
10686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
10706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830InitState(struct i830_context *i830)
10716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
10726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLcontext *ctx = &i830->intel.ctx;
10736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830_init_packets(i830);
10756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1076a194bc3a8527ed41eead88632cc79ecabe4c81acBrian   _mesa_init_driver_state(ctx);
10776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   memcpy(&i830->initial, &i830->state, sizeof(i830->state));
10796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->current = &i830->state;
10816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.emitted = 0;
10826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   i830->state.active = (I830_UPLOAD_INVARIENT |
10836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                         I830_UPLOAD_TEXBLEND(0) |
10846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                         I830_UPLOAD_STIPPLE |
10856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                         I830_UPLOAD_CTX | I830_UPLOAD_BUFFERS);
10866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1087