i915_state.c 33.3 KB
Newer Older
1 2
/**************************************************************************
 * 
Jose Fonseca's avatar
Jose Fonseca committed
3
 * Copyright 2003 VMware, Inc.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
Jose Fonseca's avatar
Jose Fonseca committed
21
 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 23 24 25 26 27 28
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/


29 30 31 32
#include "main/glheader.h"
#include "main/context.h"
#include "main/macros.h"
#include "main/enums.h"
33
#include "main/fbobject.h"
34
#include "main/dd.h"
35
#include "main/state.h"
36
#include "main/stencil.h"
37
#include "main/viewport.h"
38 39 40
#include "tnl/tnl.h"
#include "tnl/t_context.h"

41 42
#include "drivers/common/driverfuncs.h"

43 44 45
#include "intel_fbo.h"
#include "intel_screen.h"
#include "intel_batchbuffer.h"
46
#include "intel_buffers.h"
47 48 49 50 51 52

#include "i915_context.h"
#include "i915_reg.h"

#define FILE_DEBUG_FLAG DEBUG_STATE

53
void
54
i915_update_stencil(struct gl_context * ctx)
55 56
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
57 58 59 60
   GLuint front_ref, front_writemask, front_mask;
   GLenum front_func, front_fail, front_pass_z_fail, front_pass_z_pass;
   GLuint back_ref, back_writemask, back_mask;
   GLenum back_func, back_fail, back_pass_z_fail, back_pass_z_pass;
61
   GLuint dirty = 0;
62

63 64 65 66 67
   /* The 915 considers CW to be "front" for two-sided stencil, so choose
    * appropriately.
    */
   /* _NEW_POLYGON | _NEW_STENCIL */
   if (ctx->Polygon.FrontFace == GL_CW) {
68
      front_ref = _mesa_get_stencil_ref(ctx, 0);
69 70 71 72 73 74
      front_mask = ctx->Stencil.ValueMask[0];
      front_writemask = ctx->Stencil.WriteMask[0];
      front_func = ctx->Stencil.Function[0];
      front_fail = ctx->Stencil.FailFunc[0];
      front_pass_z_fail = ctx->Stencil.ZFailFunc[0];
      front_pass_z_pass = ctx->Stencil.ZPassFunc[0];
75
      back_ref = _mesa_get_stencil_ref(ctx, ctx->Stencil._BackFace);
76 77 78 79 80 81 82
      back_mask = ctx->Stencil.ValueMask[ctx->Stencil._BackFace];
      back_writemask = ctx->Stencil.WriteMask[ctx->Stencil._BackFace];
      back_func = ctx->Stencil.Function[ctx->Stencil._BackFace];
      back_fail = ctx->Stencil.FailFunc[ctx->Stencil._BackFace];
      back_pass_z_fail = ctx->Stencil.ZFailFunc[ctx->Stencil._BackFace];
      back_pass_z_pass = ctx->Stencil.ZPassFunc[ctx->Stencil._BackFace];
   } else {
83
      front_ref = _mesa_get_stencil_ref(ctx, ctx->Stencil._BackFace);
84 85 86 87 88 89
      front_mask = ctx->Stencil.ValueMask[ctx->Stencil._BackFace];
      front_writemask = ctx->Stencil.WriteMask[ctx->Stencil._BackFace];
      front_func = ctx->Stencil.Function[ctx->Stencil._BackFace];
      front_fail = ctx->Stencil.FailFunc[ctx->Stencil._BackFace];
      front_pass_z_fail = ctx->Stencil.ZFailFunc[ctx->Stencil._BackFace];
      front_pass_z_pass = ctx->Stencil.ZPassFunc[ctx->Stencil._BackFace];
90
      back_ref = _mesa_get_stencil_ref(ctx, 0);
91 92 93 94 95 96 97
      back_mask = ctx->Stencil.ValueMask[0];
      back_writemask = ctx->Stencil.WriteMask[0];
      back_func = ctx->Stencil.Function[0];
      back_fail = ctx->Stencil.FailFunc[0];
      back_pass_z_fail = ctx->Stencil.ZFailFunc[0];
      back_pass_z_pass = ctx->Stencil.ZPassFunc[0];
   }
98 99 100 101 102
#define set_ctx_bits(reg, mask, set) do{ \
   GLuint dw = i915->state.Ctx[reg]; \
   dw &= ~(mask); \
   dw |= (set); \
   dirty |= dw != i915->state.Ctx[reg]; \
103
   i915->state.Ctx[reg] = dw; \
104
} while(0)
105

106
   /* Set front state. */
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
   set_ctx_bits(I915_CTXREG_STATE4,
                MODE4_ENABLE_STENCIL_TEST_MASK |
                MODE4_ENABLE_STENCIL_WRITE_MASK,
                ENABLE_STENCIL_TEST_MASK |
                ENABLE_STENCIL_WRITE_MASK |
                STENCIL_TEST_MASK(front_mask) |
                STENCIL_WRITE_MASK(front_writemask));

   set_ctx_bits(I915_CTXREG_LIS5,
                S5_STENCIL_REF_MASK |
                S5_STENCIL_TEST_FUNC_MASK |
                S5_STENCIL_FAIL_MASK |
                S5_STENCIL_PASS_Z_FAIL_MASK |
                S5_STENCIL_PASS_Z_PASS_MASK,
                (front_ref << S5_STENCIL_REF_SHIFT) |
                (intel_translate_compare_func(front_func) << S5_STENCIL_TEST_FUNC_SHIFT) |
                (intel_translate_stencil_op(front_fail) << S5_STENCIL_FAIL_SHIFT) |
                (intel_translate_stencil_op(front_pass_z_fail) <<
                 S5_STENCIL_PASS_Z_FAIL_SHIFT) |
                (intel_translate_stencil_op(front_pass_z_pass) <<
                 S5_STENCIL_PASS_Z_PASS_SHIFT));
128 129

   /* Set back state if different from front. */
130
   if (_mesa_stencil_is_two_sided(ctx)) {
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
      set_ctx_bits(I915_CTXREG_BF_STENCIL_OPS,
                   BFO_STENCIL_REF_MASK |
                   BFO_STENCIL_TEST_MASK |
                   BFO_STENCIL_FAIL_MASK |
                   BFO_STENCIL_PASS_Z_FAIL_MASK |
                   BFO_STENCIL_PASS_Z_PASS_MASK,
                   BFO_STENCIL_TWO_SIDE |
                   (back_ref << BFO_STENCIL_REF_SHIFT) |
                   (intel_translate_compare_func(back_func) << BFO_STENCIL_TEST_SHIFT) |
                   (intel_translate_stencil_op(back_fail) << BFO_STENCIL_FAIL_SHIFT) |
                   (intel_translate_stencil_op(back_pass_z_fail) <<
                    BFO_STENCIL_PASS_Z_FAIL_SHIFT) |
                   (intel_translate_stencil_op(back_pass_z_pass) <<
                    BFO_STENCIL_PASS_Z_PASS_SHIFT));

      set_ctx_bits(I915_CTXREG_BF_STENCIL_MASKS,
                   BFM_STENCIL_TEST_MASK_MASK |
                   BFM_STENCIL_WRITE_MASK_MASK,
                   BFM_STENCIL_TEST_MASK(back_mask) |
                   BFM_STENCIL_WRITE_MASK(back_writemask));
151
   } else {
152 153
      set_ctx_bits(I915_CTXREG_BF_STENCIL_OPS,
                   BFO_STENCIL_TWO_SIDE, 0);
154
   }
155 156 157 158 159

#undef set_ctx_bits

   if (dirty)
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
160
}
161

162
static void
163
i915StencilFuncSeparate(struct gl_context * ctx, GLenum face, GLenum func, GLint ref,
164 165
                        GLuint mask)
{
166 167 168
}

static void
169
i915StencilMaskSeparate(struct gl_context * ctx, GLenum face, GLuint mask)
170 171 172 173
{
}

static void
174
i915StencilOpSeparate(struct gl_context * ctx, GLenum face, GLenum fail, GLenum zfail,
175 176 177 178 179
                      GLenum zpass)
{
}

static void
180
i915AlphaFunc(struct gl_context * ctx, GLenum func, GLfloat ref)
181 182 183 184
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   int test = intel_translate_compare_func(func);
   GLubyte refByte;
185
   GLuint dw;
186 187 188

   UNCLAMPED_FLOAT_TO_UBYTE(refByte, ref);

189 190 191 192 193 194 195 196
   dw = i915->state.Ctx[I915_CTXREG_LIS6];
   dw &= ~(S6_ALPHA_TEST_FUNC_MASK | S6_ALPHA_REF_MASK);
   dw |= ((test << S6_ALPHA_TEST_FUNC_SHIFT) |
	  (((GLuint) refByte) << S6_ALPHA_REF_SHIFT));
   if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
      i915->state.Ctx[I915_CTXREG_LIS6] = dw;
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
   }
197 198 199
}

/* This function makes sure that the proper enables are
Zoë Blade's avatar
Zoë Blade committed
200
 * set for LogicOp, Independent Alpha Blend, and Blending.
201
 * It needs to be called from numerous places where we
Zoë Blade's avatar
Zoë Blade committed
202
 * could change the LogicOp or Independent Alpha Blend without subsequent
203 204 205
 * calls to glEnable.
 */
static void
206
i915EvalLogicOpBlendState(struct gl_context * ctx)
207 208
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
209
   GLuint dw0, dw1;
210

211 212
   dw0 = i915->state.Ctx[I915_CTXREG_LIS5];
   dw1 = i915->state.Ctx[I915_CTXREG_LIS6];
213

214
   if (ctx->Color.ColorLogicOpEnabled) {
215 216
      dw0 |= S5_LOGICOP_ENABLE;
      dw1 &= ~S6_CBUF_BLEND_ENABLE;
217 218
   }
   else {
219
      dw0 &= ~S5_LOGICOP_ENABLE;
220 221

      if (ctx->Color.BlendEnabled) {
222
         dw1 |= S6_CBUF_BLEND_ENABLE;
223 224
      }
      else {
225
         dw1 &= ~S6_CBUF_BLEND_ENABLE;
226 227
      }
   }
228 229 230 231 232 233 234
   if (dw0 != i915->state.Ctx[I915_CTXREG_LIS5] ||
       dw1 != i915->state.Ctx[I915_CTXREG_LIS6]) {
      i915->state.Ctx[I915_CTXREG_LIS5] = dw0;
      i915->state.Ctx[I915_CTXREG_LIS6] = dw1;

      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
   }
235 236 237
}

static void
238
i915BlendColor(struct gl_context * ctx, const GLfloat color[4])
239 240 241
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   GLubyte r, g, b, a;
242
   GLuint dw;
243

244
   DBG("%s\n", __func__);
245 246 247 248 249 250
   
   UNCLAMPED_FLOAT_TO_UBYTE(r, color[RCOMP]);
   UNCLAMPED_FLOAT_TO_UBYTE(g, color[GCOMP]);
   UNCLAMPED_FLOAT_TO_UBYTE(b, color[BCOMP]);
   UNCLAMPED_FLOAT_TO_UBYTE(a, color[ACOMP]);

251
   dw = (a << 24) | (r << 16) | (g << 8) | b;
252 253 254
   if (dw != i915->state.Blend[I915_BLENDREG_BLENDCOLOR1]) {
      i915->state.Blend[I915_BLENDREG_BLENDCOLOR1] = dw;
      I915_STATECHANGE(i915, I915_UPLOAD_BLEND);
255
   }
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
}


#define DST_BLND_FACT(f) ((f)<<S6_CBUF_DST_BLEND_FACT_SHIFT)
#define SRC_BLND_FACT(f) ((f)<<S6_CBUF_SRC_BLEND_FACT_SHIFT)
#define DST_ABLND_FACT(f) ((f)<<IAB_DST_FACTOR_SHIFT)
#define SRC_ABLND_FACT(f) ((f)<<IAB_SRC_FACTOR_SHIFT)



static GLuint
translate_blend_equation(GLenum mode)
{
   switch (mode) {
   case GL_FUNC_ADD:
      return BLENDFUNC_ADD;
   case GL_MIN:
      return BLENDFUNC_MIN;
   case GL_MAX:
      return BLENDFUNC_MAX;
   case GL_FUNC_SUBTRACT:
      return BLENDFUNC_SUBTRACT;
   case GL_FUNC_REVERSE_SUBTRACT:
      return BLENDFUNC_REVERSE_SUBTRACT;
   default:
      return 0;
   }
}

static void
286
i915UpdateBlendState(struct gl_context * ctx)
287 288
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
289
   GLuint iab = (i915->state.Blend[I915_BLENDREG_IAB] &
290 291 292 293 294 295 296 297
                 ~(IAB_SRC_FACTOR_MASK |
                   IAB_DST_FACTOR_MASK |
                   (BLENDFUNC_MASK << IAB_FUNC_SHIFT) | IAB_ENABLE));

   GLuint lis6 = (i915->state.Ctx[I915_CTXREG_LIS6] &
                  ~(S6_CBUF_SRC_BLEND_FACT_MASK |
                    S6_CBUF_DST_BLEND_FACT_MASK | S6_CBUF_BLEND_FUNC_MASK));

298 299 300 301 302 303
   GLuint eqRGB = ctx->Color.Blend[0].EquationRGB;
   GLuint eqA = ctx->Color.Blend[0].EquationA;
   GLuint srcRGB = ctx->Color.Blend[0].SrcRGB;
   GLuint dstRGB = ctx->Color.Blend[0].DstRGB;
   GLuint srcA = ctx->Color.Blend[0].SrcA;
   GLuint dstA = ctx->Color.Blend[0].DstA;
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323

   if (eqRGB == GL_MIN || eqRGB == GL_MAX) {
      srcRGB = dstRGB = GL_ONE;
   }

   if (eqA == GL_MIN || eqA == GL_MAX) {
      srcA = dstA = GL_ONE;
   }

   lis6 |= SRC_BLND_FACT(intel_translate_blend_factor(srcRGB));
   lis6 |= DST_BLND_FACT(intel_translate_blend_factor(dstRGB));
   lis6 |= translate_blend_equation(eqRGB) << S6_CBUF_BLEND_FUNC_SHIFT;

   iab |= SRC_ABLND_FACT(intel_translate_blend_factor(srcA));
   iab |= DST_ABLND_FACT(intel_translate_blend_factor(dstA));
   iab |= translate_blend_equation(eqA) << IAB_FUNC_SHIFT;

   if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB)
      iab |= IAB_ENABLE;

324 325 326 327 328
   if (iab != i915->state.Blend[I915_BLENDREG_IAB]) {
      i915->state.Blend[I915_BLENDREG_IAB] = iab;
      I915_STATECHANGE(i915, I915_UPLOAD_BLEND);
   }
   if (lis6 != i915->state.Ctx[I915_CTXREG_LIS6]) {
329
      i915->state.Ctx[I915_CTXREG_LIS6] = lis6;
330
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
331 332 333 334 335 336 337 338
   }

   /* This will catch a logicop blend equation */
   i915EvalLogicOpBlendState(ctx);
}


static void
339
i915BlendFuncSeparate(struct gl_context * ctx, GLenum srcRGB,
340 341 342 343 344 345 346
                      GLenum dstRGB, GLenum srcA, GLenum dstA)
{
   i915UpdateBlendState(ctx);
}


static void
347
i915BlendEquationSeparate(struct gl_context * ctx, GLenum eqRGB, GLenum eqA)
348 349 350 351 352 353
{
   i915UpdateBlendState(ctx);
}


static void
354
i915DepthFunc(struct gl_context * ctx, GLenum func)
355 356 357
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   int test = intel_translate_compare_func(func);
358
   GLuint dw;
359

360
   DBG("%s\n", __func__);
361
   
362 363 364 365 366 367 368
   dw = i915->state.Ctx[I915_CTXREG_LIS6];
   dw &= ~S6_DEPTH_TEST_FUNC_MASK;
   dw |= test << S6_DEPTH_TEST_FUNC_SHIFT;
   if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      i915->state.Ctx[I915_CTXREG_LIS6] = dw;
   }
369 370 371
}

static void
372
i915DepthMask(struct gl_context * ctx, GLboolean flag)
373 374
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
375
   GLuint dw;
376

377
   DBG("%s flag (%d)\n", __func__, flag);
378

379 380 381
   if (!ctx->DrawBuffer || !ctx->DrawBuffer->Visual.depthBits)
      flag = false;

382
   dw = i915->state.Ctx[I915_CTXREG_LIS6];
383
   if (flag && ctx->Depth.Test)
384
      dw |= S6_DEPTH_WRITE_ENABLE;
385
   else
386 387 388 389 390
      dw &= ~S6_DEPTH_WRITE_ENABLE;
   if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      i915->state.Ctx[I915_CTXREG_LIS6] = dw;
   }
391 392
}

393 394 395 396 397 398 399 400


/**
 * Update the viewport transformation matrix.  Depends on:
 *  - viewport pos/size
 *  - depthrange
 *  - window pos/size or FBO size
 */
401
void
402
intelCalcViewport(struct gl_context * ctx)
403 404
{
   struct intel_context *intel = intel_context(ctx);
405
   float scale[3], translate[3];
406 407

   _mesa_get_viewport_xform(ctx, 0, scale, translate);
408

409
   if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
410 411
      scale[1] = -scale[1];
      translate[1] = ctx->DrawBuffer->Height - translate[1];
412
   }
413 414 415

   _math_matrix_viewport(&intel->ViewportMatrix,
                         scale, translate, 1.0);
416 417 418 419 420
}


/** Called from ctx->Driver.DepthRange() */
static void
421
i915DepthRange(struct gl_context *ctx)
422 423 424 425 426
{
   intelCalcViewport(ctx);
}


427 428 429 430 431 432 433
/* =============================================================
 * Polygon stipple
 *
 * The i915 supports a 4x4 stipple natively, GL wants 32x32.
 * Fortunately stipple is usually a repeating pattern.
 */
static void
434
i915PolygonStipple(struct gl_context * ctx, const GLubyte * mask)
435 436
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
437
   const GLubyte *m;
438 439 440 441 442 443 444 445 446 447 448
   GLubyte p[4];
   int i, j, k;
   int active = (ctx->Polygon.StippleFlag &&
                 i915->intel.reduced_primitive == GL_TRIANGLES);
   GLuint newMask;

   if (active) {
      I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE);
      i915->state.Stipple[I915_STPREG_ST1] &= ~ST1_ENABLE;
   }

449 450 451 452 453 454
   /* Use the already unpacked stipple data from the context rather than the
    * uninterpreted mask passed in.
    */
   mask = (const GLubyte *)ctx->PolygonStipple;
   m = mask;

455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
   p[0] = mask[12] & 0xf;
   p[0] |= p[0] << 4;
   p[1] = mask[8] & 0xf;
   p[1] |= p[1] << 4;
   p[2] = mask[4] & 0xf;
   p[2] |= p[2] << 4;
   p[3] = mask[0] & 0xf;
   p[3] |= p[3] << 4;

   for (k = 0; k < 8; k++)
      for (j = 3; j >= 0; j--)
         for (i = 0; i < 4; i++, m++)
            if (*m != p[j]) {
               i915->intel.hw_stipple = 0;
               return;
            }

   newMask = (((p[0] & 0xf) << 0) |
              ((p[1] & 0xf) << 4) |
              ((p[2] & 0xf) << 8) | ((p[3] & 0xf) << 12));


   if (newMask == 0xffff || newMask == 0x0) {
      /* this is needed to make conform pass */
      i915->intel.hw_stipple = 0;
      return;
   }

   i915->state.Stipple[I915_STPREG_ST1] &= ~0xffff;
   i915->state.Stipple[I915_STPREG_ST1] |= newMask;
   i915->intel.hw_stipple = 1;

   if (active)
      i915->state.Stipple[I915_STPREG_ST1] |= ST1_ENABLE;
}


/* =============================================================
 * Hardware clipping
 */
static void
496
i915Scissor(struct gl_context * ctx)
497 498 499 500 501 502 503
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   int x1, y1, x2, y2;

   if (!ctx->DrawBuffer)
      return;

504
   DBG("%s %d,%d %dx%d\n", __func__,
505 506
       ctx->Scissor.ScissorArray[0].X,     ctx->Scissor.ScissorArray[0].Y,
       ctx->Scissor.ScissorArray[0].Width, ctx->Scissor.ScissorArray[0].Height);
507

508
   if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
509 510 511 512 513 514
      x1 = ctx->Scissor.ScissorArray[0].X;
      y1 = ctx->DrawBuffer->Height - (ctx->Scissor.ScissorArray[0].Y
                                      + ctx->Scissor.ScissorArray[0].Height);
      x2 = ctx->Scissor.ScissorArray[0].X
         + ctx->Scissor.ScissorArray[0].Width - 1;
      y2 = y1 + ctx->Scissor.ScissorArray[0].Height - 1;
515
      DBG("%s %d..%d,%d..%d (inverted)\n", __func__, x1, x2, y1, y2);
516 517 518 519
   }
   else {
      /* FBO - not inverted
       */
520 521 522 523 524 525
      x1 = ctx->Scissor.ScissorArray[0].X;
      y1 = ctx->Scissor.ScissorArray[0].Y;
      x2 = ctx->Scissor.ScissorArray[0].X
         + ctx->Scissor.ScissorArray[0].Width - 1;
      y2 = ctx->Scissor.ScissorArray[0].Y
         + ctx->Scissor.ScissorArray[0].Height - 1;
526
      DBG("%s %d..%d,%d..%d (not inverted)\n", __func__, x1, x2, y1, y2);
527 528 529 530 531 532 533
   }
   
   x1 = CLAMP(x1, 0, ctx->DrawBuffer->Width - 1);
   y1 = CLAMP(y1, 0, ctx->DrawBuffer->Height - 1);
   x2 = CLAMP(x2, 0, ctx->DrawBuffer->Width - 1);
   y2 = CLAMP(y2, 0, ctx->DrawBuffer->Height - 1);
   
534
   DBG("%s %d..%d,%d..%d (clamped)\n", __func__, x1, x2, y1, y2);
535 536 537 538 539 540 541

   I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS);
   i915->state.Buffer[I915_DESTREG_SR1] = (y1 << 16) | (x1 & 0xffff);
   i915->state.Buffer[I915_DESTREG_SR2] = (y2 << 16) | (x2 & 0xffff);
}

static void
542
i915LogicOp(struct gl_context * ctx, GLenum opcode)
543 544 545 546
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   int tmp = intel_translate_logic_op(opcode);

547
   DBG("%s\n", __func__);
548 549 550 551 552 553 554 555 556
   
   I915_STATECHANGE(i915, I915_UPLOAD_CTX);
   i915->state.Ctx[I915_CTXREG_STATE4] &= ~LOGICOP_MASK;
   i915->state.Ctx[I915_CTXREG_STATE4] |= LOGIC_OP_FUNC(tmp);
}



static void
557
i915CullFaceFrontFace(struct gl_context * ctx, GLenum unused)
558 559
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
560
   GLuint mode, dw;
561

562
   DBG("%s %d\n", __func__,
563 564 565 566 567 568 569 570
       ctx->DrawBuffer ? ctx->DrawBuffer->Name : 0);

   if (!ctx->Polygon.CullFlag) {
      mode = S4_CULLMODE_NONE;
   }
   else if (ctx->Polygon.CullFaceMode != GL_FRONT_AND_BACK) {
      mode = S4_CULLMODE_CW;

571
      if (ctx->DrawBuffer && _mesa_is_user_fbo(ctx->DrawBuffer))
572 573 574 575 576 577 578 579 580 581
         mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW);
      if (ctx->Polygon.CullFaceMode == GL_FRONT)
         mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW);
      if (ctx->Polygon.FrontFace != GL_CCW)
         mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW);
   }
   else {
      mode = S4_CULLMODE_BOTH;
   }

582 583 584 585 586 587 588
   dw = i915->state.Ctx[I915_CTXREG_LIS4];
   dw &= ~S4_CULLMODE_MASK;
   dw |= mode;
   if (dw != i915->state.Ctx[I915_CTXREG_LIS4]) {
      i915->state.Ctx[I915_CTXREG_LIS4] = dw;
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
   }
589 590 591
}

static void
592
i915LineWidth(struct gl_context * ctx, GLfloat widthf)
593 594 595 596 597
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   int lis4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_LINE_WIDTH_MASK;
   int width;

598
   DBG("%s\n", __func__);
599 600
   
   width = (int) (widthf * 2);
601
   width = CLAMP(width, 1, 0xf);
602 603 604 605 606 607 608 609 610
   lis4 |= width << S4_LINE_WIDTH_SHIFT;

   if (lis4 != i915->state.Ctx[I915_CTXREG_LIS4]) {
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      i915->state.Ctx[I915_CTXREG_LIS4] = lis4;
   }
}

static void
611
i915PointSize(struct gl_context * ctx, GLfloat size)
612 613 614
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   int lis4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_POINT_WIDTH_MASK;
615
   GLint point_size = (int) round(size);
616

617
   DBG("%s\n", __func__);
618
   
619
   point_size = CLAMP(point_size, 1, 255);
620 621 622 623 624 625 626 627 628
   lis4 |= point_size << S4_POINT_WIDTH_SHIFT;

   if (lis4 != i915->state.Ctx[I915_CTXREG_LIS4]) {
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      i915->state.Ctx[I915_CTXREG_LIS4] = lis4;
   }
}


629
static void
630
i915PointParameterfv(struct gl_context * ctx, GLenum pname, const GLfloat *params)
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
{
   struct i915_context *i915 = I915_CONTEXT(ctx);

   switch (pname) {
   case GL_POINT_SPRITE_COORD_ORIGIN:
      /* This could be supported, but it would require modifying the fragment
       * program to invert the y component of the texture coordinate by
       * inserting a 'SUB tc.y, {1.0}.xxxx, tc' instruction.
       */
      FALLBACK(&i915->intel, I915_FALLBACK_POINT_SPRITE_COORD_ORIGIN,
	       (params[0] != GL_UPPER_LEFT));
      break;
   }
}

646 647 648 649 650 651 652
void
i915_update_sprite_point_enable(struct gl_context *ctx)
{
   struct intel_context *intel = intel_context(ctx);
   /* _NEW_PROGRAM */
   struct i915_fragment_program *p =
      (struct i915_fragment_program *) ctx->FragmentProgram._Current;
653
   const GLbitfield64 inputsRead = p->FragProg.info.inputs_read;
654 655 656
   struct i915_context *i915 = i915_context(ctx);
   GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK;
   GLuint coord_replace_bits = 0x0;
657 658 659

   /* _NEW_POINT */
   if (ctx->Point.PointSprite)
660
      coord_replace_bits = ctx->Point.CoordReplace;
661 662 663

   GLuint tex_coord_unit_bits =
      (GLuint)((inputsRead & VARYING_BITS_TEX_ANY) >> VARYING_SLOT_TEX0);
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684

   /*
    * Here we can't enable the SPRITE_POINT_ENABLE bit when the mis-match
    * of tex_coord_unit_bits and coord_replace_bits, or this will make all
    * the other non-point-sprite coords(like varying inputs, as we now use
    * tex coord to implement varying inputs) be replaced to value (0, 0)-(1, 1).
    *
    * Thus, do fallback when needed.
    */
   FALLBACK(intel, I915_FALLBACK_COORD_REPLACE,
            coord_replace_bits && coord_replace_bits != tex_coord_unit_bits);

   s4 &= ~S4_SPRITE_POINT_ENABLE;
   s4 |= (coord_replace_bits && coord_replace_bits == tex_coord_unit_bits) ?
         S4_SPRITE_POINT_ENABLE : 0;
   if (s4 != i915->state.Ctx[I915_CTXREG_LIS4]) {
      i915->state.Ctx[I915_CTXREG_LIS4] = s4;
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
   }
}

685

686 687 688 689 690
/* =============================================================
 * Color masks
 */

static void
691
i915ColorMask(struct gl_context * ctx,
692 693 694 695 696
              GLboolean r, GLboolean g, GLboolean b, GLboolean a)
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   GLuint tmp = i915->state.Ctx[I915_CTXREG_LIS5] & ~S5_WRITEDISABLE_MASK;

697
   DBG("%s r(%d) g(%d) b(%d) a(%d)\n", __func__, r, g, b,
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
       a);

   if (!r)
      tmp |= S5_WRITEDISABLE_RED;
   if (!g)
      tmp |= S5_WRITEDISABLE_GREEN;
   if (!b)
      tmp |= S5_WRITEDISABLE_BLUE;
   if (!a)
      tmp |= S5_WRITEDISABLE_ALPHA;

   if (tmp != i915->state.Ctx[I915_CTXREG_LIS5]) {
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      i915->state.Ctx[I915_CTXREG_LIS5] = tmp;
   }
}

static void
716
update_specular(struct gl_context * ctx)
717 718 719 720 721 722 723
{
   /* A hack to trigger the rebuild of the fragment program.
    */
   intel_context(ctx)->NewGLState |= _NEW_TEXTURE;
}

static void
724
i915LightModelfv(struct gl_context * ctx, GLenum pname, const GLfloat * param)
725
{
726
   DBG("%s\n", __func__);
727 728 729 730 731 732 733
   
   if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) {
      update_specular(ctx);
   }
}

static void
734
i915ShadeModel(struct gl_context * ctx, GLenum mode)
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
   I915_STATECHANGE(i915, I915_UPLOAD_CTX);

   if (mode == GL_SMOOTH) {
      i915->state.Ctx[I915_CTXREG_LIS4] &= ~(S4_FLATSHADE_ALPHA |
                                             S4_FLATSHADE_COLOR |
                                             S4_FLATSHADE_SPECULAR);
   }
   else {
      i915->state.Ctx[I915_CTXREG_LIS4] |= (S4_FLATSHADE_ALPHA |
                                            S4_FLATSHADE_COLOR |
                                            S4_FLATSHADE_SPECULAR);
   }
}

/* =============================================================
 * Fog
753 754 755 756
 *
 * This empty function remains because _mesa_init_driver_state calls
 * dd_function_table::Fogfv unconditionally.  We have to have some function
 * there so that it doesn't try to call a NULL pointer.
757 758
 */
static void
759
i915Fogfv(struct gl_context * ctx, GLenum pname, const GLfloat * param)
760
{
761 762 763
   (void) ctx;
   (void) pname;
   (void) param;
764 765 766 767 768 769
}

/* =============================================================
 */

static void
770
i915Enable(struct gl_context * ctx, GLenum cap, GLboolean state)
771 772
{
   struct i915_context *i915 = I915_CONTEXT(ctx);
773
   GLuint dw;
774 775 776 777 778 779 780 781 782 783 784

   switch (cap) {
   case GL_TEXTURE_2D:
      break;

   case GL_LIGHTING:
   case GL_COLOR_SUM:
      update_specular(ctx);
      break;

   case GL_ALPHA_TEST:
785
      dw = i915->state.Ctx[I915_CTXREG_LIS6];
786
      if (state)
787
         dw |= S6_ALPHA_TEST_ENABLE;
788
      else
789 790 791 792 793
         dw &= ~S6_ALPHA_TEST_ENABLE;
      if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
	 i915->state.Ctx[I915_CTXREG_LIS6] = dw;
	 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      }
794 795 796 797 798 799 800 801 802 803 804
      break;

   case GL_BLEND:
      i915EvalLogicOpBlendState(ctx);
      break;

   case GL_COLOR_LOGIC_OP:
      i915EvalLogicOpBlendState(ctx);

      /* Logicop doesn't seem to work at 16bpp:
       */
805
      if (ctx->Visual.rgbBits == 16)
806 807 808 809 810 811 812
         FALLBACK(&i915->intel, I915_FALLBACK_LOGICOP, state);
      break;

   case GL_FRAGMENT_PROGRAM_ARB:
      break;

   case GL_DITHER:
813
      dw = i915->state.Ctx[I915_CTXREG_LIS5];
814
      if (state)
815
         dw |= S5_COLOR_DITHER_ENABLE;
816
      else
817 818 819 820 821
         dw &= ~S5_COLOR_DITHER_ENABLE;
      if (dw != i915->state.Ctx[I915_CTXREG_LIS5]) {
	 i915->state.Ctx[I915_CTXREG_LIS5] = dw;
	 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      }
822 823 824
      break;

   case GL_DEPTH_TEST:
825
      dw = i915->state.Ctx[I915_CTXREG_LIS6];
826 827 828 829

      if (!ctx->DrawBuffer || !ctx->DrawBuffer->Visual.depthBits)
	 state = false;

830
      if (state)
831
         dw |= S6_DEPTH_TEST_ENABLE;
832
      else
833 834 835 836 837
         dw &= ~S6_DEPTH_TEST_ENABLE;
      if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
	 i915->state.Ctx[I915_CTXREG_LIS6] = dw;
	 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      }
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852

      i915DepthMask(ctx, ctx->Depth.Mask);
      break;

   case GL_SCISSOR_TEST:
      I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS);
      if (state)
         i915->state.Buffer[I915_DESTREG_SENABLE] =
            (_3DSTATE_SCISSOR_ENABLE_CMD | ENABLE_SCISSOR_RECT);
      else
         i915->state.Buffer[I915_DESTREG_SENABLE] =
            (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
      break;

   case GL_LINE_SMOOTH:
853
      dw = i915->state.Ctx[I915_CTXREG_LIS4];
854
      if (state)
855
         dw |= S4_LINE_ANTIALIAS_ENABLE;
856
      else
857 858 859 860 861
         dw &= ~S4_LINE_ANTIALIAS_ENABLE;
      if (dw != i915->state.Ctx[I915_CTXREG_LIS4]) {
	 i915->state.Ctx[I915_CTXREG_LIS4] = dw;
	 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
      }
862 863 864 865 866 867 868
      break;

   case GL_CULL_FACE:
      i915CullFaceFrontFace(ctx, 0);
      break;

   case GL_STENCIL_TEST:
869 870 871 872 873 874 875 876 877 878 879
      if (!ctx->DrawBuffer || !ctx->DrawBuffer->Visual.stencilBits)
	 state = false;

      dw = i915->state.Ctx[I915_CTXREG_LIS5];
      if (state)
	 dw |= (S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE);
      else
	 dw &= ~(S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE);
      if (dw != i915->state.Ctx[I915_CTXREG_LIS5]) {
	 i915->state.Ctx[I915_CTXREG_LIS5] = dw;
	 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
      }
      break;

   case GL_POLYGON_STIPPLE:
      /* The stipple command worked on my 855GM box, but not my 845G.
       * I'll do more testing later to find out exactly which hardware
       * supports it.  Disabled for now.
       */
      if (i915->intel.hw_stipple &&
          i915->intel.reduced_primitive == GL_TRIANGLES) {
         I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE);
         if (state)
            i915->state.Stipple[I915_STPREG_ST1] |= ST1_ENABLE;
         else
            i915->state.Stipple[I915_STPREG_ST1] &= ~ST1_ENABLE;
      }
      break;

   case GL_POLYGON_SMOOTH:
      break;

901
   case GL_POINT_SPRITE:
902
      /* Handle it at i915_update_sprite_point_enable () */
903 904
      break;

905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
   case GL_POINT_SMOOTH:
      break;

   default:
      ;
   }
}


static void
i915_init_packets(struct i915_context *i915)
{
   /* Zero all state */
   memset(&i915->state, 0, sizeof(i915->state));


   {
      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
923
      I915_STATECHANGE(i915, I915_UPLOAD_BLEND);
924 925 926 927
      /* Probably don't want to upload all this stuff every time one 
       * piece changes.
       */
      i915->state.Ctx[I915_CTXREG_LI] = (_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
928 929 930
                                         I1_LOAD_S(2) | I1_LOAD_S(3) |
                                         I1_LOAD_S(4) | I1_LOAD_S(5) |
                                         I1_LOAD_S(6) | (4));
931 932
      i915->state.Ctx[I915_CTXREG_LIS2] = 0;
      i915->state.Ctx[I915_CTXREG_LIS4] = 0;
933
      i915->state.Ctx[I915_CTXREG_LIS3] = 0;
934 935
      i915->state.Ctx[I915_CTXREG_LIS5] = 0;

936
      if (i915->intel.ctx.Visual.rgbBits == 16)
937 938 939 940 941 942 943 944 945 946 947 948 949 950
         i915->state.Ctx[I915_CTXREG_LIS5] |= S5_COLOR_DITHER_ENABLE;


      i915->state.Ctx[I915_CTXREG_LIS6] = (S6_COLOR_WRITE_ENABLE |
                                           (2 << S6_TRISTRIP_PV_SHIFT));

      i915->state.Ctx[I915_CTXREG_STATE4] = (_3DSTATE_MODES_4_CMD |
                                             ENABLE_LOGIC_OP_FUNC |
                                             LOGIC_OP_FUNC(LOGICOP_COPY) |
                                             ENABLE_STENCIL_TEST_MASK |
                                             STENCIL_TEST_MASK(0xff) |
                                             ENABLE_STENCIL_WRITE_MASK |
                                             STENCIL_WRITE_MASK(0xff));

951
      i915->state.Blend[I915_BLENDREG_IAB] =
952 953 954
         (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD | IAB_MODIFY_ENABLE |
          IAB_MODIFY_FUNC | IAB_MODIFY_SRC_FACTOR | IAB_MODIFY_DST_FACTOR);

955
      i915->state.Blend[I915_BLENDREG_BLENDCOLOR0] =
956
         _3DSTATE_CONST_BLEND_COLOR_CMD;
957
      i915->state.Blend[I915_BLENDREG_BLENDCOLOR1] = 0;
958

959 960 961 962 963 964 965 966 967 968 969
      i915->state.Ctx[I915_CTXREG_BF_STENCIL_MASKS] =
	 _3DSTATE_BACKFACE_STENCIL_MASKS |
	 BFM_ENABLE_STENCIL_TEST_MASK |
	 BFM_ENABLE_STENCIL_WRITE_MASK |
	 (0xff << BFM_STENCIL_WRITE_MASK_SHIFT) |
	 (0xff << BFM_STENCIL_TEST_MASK_SHIFT);
      i915->state.Ctx[I915_CTXREG_BF_STENCIL_OPS] =
	 _3DSTATE_BACKFACE_STENCIL_OPS |
	 BFO_ENABLE_STENCIL_REF |
	 BFO_ENABLE_STENCIL_FUNCS |
	 BFO_ENABLE_STENCIL_TWO_SIDE;
970 971 972 973 974 975 976 977 978 979 980 981 982 983
   }

   {
      I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE);
      i915->state.Stipple[I915_STPREG_ST0] = _3DSTATE_STIPPLE;
   }

   {
      i915->state.Buffer[I915_DESTREG_DV0] = _3DSTATE_DST_BUF_VARS_CMD;

      /* scissor */
      i915->state.Buffer[I915_DESTREG_SR0] = _3DSTATE_SCISSOR_RECT_0_CMD;
      i915->state.Buffer[I915_DESTREG_SR1] = 0;
      i915->state.Buffer[I915_DESTREG_SR2] = 0;
984 985
      i915->state.Buffer[I915_DESTREG_SENABLE] =
         (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
986 987
   }

988 989 990 991 992 993 994
   i915->state.RasterRules[I915_RASTER_RULES] = _3DSTATE_RASTER_RULES_CMD |
      ENABLE_POINT_RASTER_RULE |
      OGL_POINT_RASTER_RULE |
      ENABLE_LINE_STRIP_PROVOKE_VRTX |
      ENABLE_TRI_FAN_PROVOKE_VRTX |
      LINE_STRIP_PROVOKE_VRTX(1) |
      TRI_FAN_PROVOKE_VRTX(2) | ENABLE_TEXKILL_3D_4D | TEXKILL_4D;
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014

#if 0
   {
      I915_STATECHANGE(i915, I915_UPLOAD_DEFAULTS);
      i915->state.Default[I915_DEFREG_C0] = _3DSTATE_DEFAULT_DIFFUSE;
      i915->state.Default[I915_DEFREG_C1] = 0;
      i915->state.Default[I915_DEFREG_S0] = _3DSTATE_DEFAULT_SPECULAR;
      i915->state.Default[I915_DEFREG_S1] = 0;
      i915->state.Default[I915_DEFREG_Z0] = _3DSTATE_DEFAULT_Z;
      i915->state.Default[I915_DEFREG_Z1] = 0;
   }
#endif


   /* These will be emitted every at the head of every buffer, unless
    * we get hardware contexts working.
    */
   i915->state.active = (I915_UPLOAD_PROGRAM |
                         I915_UPLOAD_STIPPLE |
                         I915_UPLOAD_CTX |
1015
                         I915_UPLOAD_BLEND |
1016 1017 1018 1019 1020 1021
                         I915_UPLOAD_BUFFERS |
			 I915_UPLOAD_INVARIENT |
			 I915_UPLOAD_RASTER_RULES);
}

void
1022
i915_update_provoking_vertex(struct gl_context * ctx)
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
{
   struct i915_context *i915 = I915_CONTEXT(ctx);

   I915_STATECHANGE(i915, I915_UPLOAD_CTX);
   i915->state.Ctx[I915_CTXREG_LIS6] &= ~(S6_TRISTRIP_PV_MASK);

   I915_STATECHANGE(i915, I915_UPLOAD_RASTER_RULES);
   i915->state.RasterRules[I915_RASTER_RULES] &= ~(LINE_STRIP_PROVOKE_VRTX_MASK |
						   TRI_FAN_PROVOKE_VRTX_MASK);

   /* _NEW_LIGHT */
   if (ctx->Light.ProvokingVertex == GL_LAST_VERTEX_CONVENTION) {
      i915->state.RasterRules[I915_RASTER_RULES] |= (LINE_STRIP_PROVOKE_VRTX(1) |
						     TRI_FAN_PROVOKE_VRTX(2));
      i915->state.Ctx[I915_CTXREG_LIS6] |= (2 << S6_TRISTRIP_PV_SHIFT);
   } else {
      i915->state.RasterRules[I915_RASTER_RULES] |= (LINE_STRIP_PROVOKE_VRTX(0) |
						     TRI_FAN_PROVOKE_VRTX(1));
      i915->state.Ctx[I915_CTXREG_LIS6] |= (0 << S6_TRISTRIP_PV_SHIFT);
    }
1043 1044
}

1045 1046 1047 1048 1049 1050 1051 1052 1053
/* Fallback to swrast for select and feedback.
 */
static void
i915RenderMode(struct gl_context *ctx, GLenum mode)
{
   struct intel_context *intel = intel_context(ctx);
   FALLBACK(intel, INTEL_FALLBACK_RENDERMODE, (mode != GL_RENDER));
}

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
void
i915InitStateFunctions(struct dd_function_table *functions)
{
   functions->AlphaFunc = i915AlphaFunc;
   functions->BlendColor = i915BlendColor;
   functions->BlendEquationSeparate = i915BlendEquationSeparate;
   functions->BlendFuncSeparate = i915BlendFuncSeparate;
   functions->ColorMask = i915ColorMask;
   functions->CullFace = i915CullFaceFrontFace;
   functions->DepthFunc = i915DepthFunc;
   functions->DepthMask = i915DepthMask;
   functions->Enable = i915Enable;
   functions->Fogfv = i915Fogfv;
   functions->FrontFace = i915CullFaceFrontFace;
   functions->LightModelfv = i915LightModelfv;
   functions->LineWidth = i915LineWidth;
   functions->LogicOpcode = i915LogicOp;
   functions->PointSize = i915PointSize;
1072
   functions->PointParameterfv = i915PointParameterfv;
1073
   functions->PolygonStipple = i915PolygonStipple;
1074
   functions->RenderMode = i915RenderMode;
1075 1076 1077 1078 1079
   functions->Scissor = i915Scissor;
   functions->ShadeModel = i915ShadeModel;
   functions->StencilFuncSeparate = i915StencilFuncSeparate;
   functions->StencilMaskSeparate = i915StencilMaskSeparate;
   functions->StencilOpSeparate = i915StencilOpSeparate;
Brian Paul's avatar
Brian Paul committed
1080
   functions->DepthRange = i915DepthRange;
1081 1082 1083 1084 1085 1086
}


void
i915InitState(struct i915_context *i915)
{
1087
   struct gl_context *ctx = &i915->intel.ctx;
1088 1089 1090

   i915_init_packets(i915);

1091
   _mesa_init_driver_state(ctx);
1092
}