1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/macros.h"
32 #include "main/enums.h"
37 #include "drivers/common/driverfuncs.h"
39 #include "intel_screen.h"
40 #include "intel_batchbuffer.h"
41 #include "intel_fbo.h"
42 #include "intel_buffers.h"
44 #include "i830_context.h"
47 #define FILE_DEBUG_FLAG DEBUG_STATE
50 i830StencilFuncSeparate(struct gl_context
* ctx
, GLenum face
, GLenum func
, GLint ref
,
53 struct i830_context
*i830
= i830_context(ctx
);
54 int test
= intel_translate_compare_func(func
);
58 DBG("%s : func: %s, ref : 0x%x, mask: 0x%x\n", __FUNCTION__
,
59 _mesa_lookup_enum_by_nr(func
), ref
, mask
);
62 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
63 i830
->state
.Ctx
[I830_CTXREG_STATE4
] &= ~MODE4_ENABLE_STENCIL_TEST_MASK
;
64 i830
->state
.Ctx
[I830_CTXREG_STATE4
] |= (ENABLE_STENCIL_TEST_MASK
|
65 STENCIL_TEST_MASK(mask
));
66 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] &= ~(STENCIL_REF_VALUE_MASK
|
67 ENABLE_STENCIL_TEST_FUNC_MASK
);
68 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] |= (ENABLE_STENCIL_REF_VALUE
|
69 ENABLE_STENCIL_TEST_FUNC
|
70 STENCIL_REF_VALUE(ref
) |
71 STENCIL_TEST_FUNC(test
));
75 i830StencilMaskSeparate(struct gl_context
* ctx
, GLenum face
, GLuint mask
)
77 struct i830_context
*i830
= i830_context(ctx
);
79 DBG("%s : mask 0x%x\n", __FUNCTION__
, mask
);
83 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
84 i830
->state
.Ctx
[I830_CTXREG_STATE4
] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK
;
85 i830
->state
.Ctx
[I830_CTXREG_STATE4
] |= (ENABLE_STENCIL_WRITE_MASK
|
86 STENCIL_WRITE_MASK(mask
));
90 i830StencilOpSeparate(struct gl_context
* ctx
, GLenum face
, GLenum fail
, GLenum zfail
,
93 struct i830_context
*i830
= i830_context(ctx
);
96 DBG("%s: fail : %s, zfail: %s, zpass : %s\n", __FUNCTION__
,
97 _mesa_lookup_enum_by_nr(fail
),
98 _mesa_lookup_enum_by_nr(zfail
),
99 _mesa_lookup_enum_by_nr(zpass
));
107 fop
= STENCILOP_KEEP
;
110 fop
= STENCILOP_ZERO
;
113 fop
= STENCILOP_REPLACE
;
116 fop
= STENCILOP_INCRSAT
;
119 fop
= STENCILOP_DECRSAT
;
122 fop
= STENCILOP_INCR
;
125 fop
= STENCILOP_DECR
;
128 fop
= STENCILOP_INVERT
;
135 dfop
= STENCILOP_KEEP
;
138 dfop
= STENCILOP_ZERO
;
141 dfop
= STENCILOP_REPLACE
;
144 dfop
= STENCILOP_INCRSAT
;
147 dfop
= STENCILOP_DECRSAT
;
150 dfop
= STENCILOP_INCR
;
153 dfop
= STENCILOP_DECR
;
156 dfop
= STENCILOP_INVERT
;
163 dpop
= STENCILOP_KEEP
;
166 dpop
= STENCILOP_ZERO
;
169 dpop
= STENCILOP_REPLACE
;
172 dpop
= STENCILOP_INCRSAT
;
175 dpop
= STENCILOP_DECRSAT
;
178 dpop
= STENCILOP_INCR
;
181 dpop
= STENCILOP_DECR
;
184 dpop
= STENCILOP_INVERT
;
191 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
192 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] &= ~(STENCIL_OPS_MASK
);
193 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] |= (ENABLE_STENCIL_PARMS
|
194 STENCIL_FAIL_OP(fop
) |
195 STENCIL_PASS_DEPTH_FAIL_OP
197 STENCIL_PASS_DEPTH_PASS_OP
202 i830AlphaFunc(struct gl_context
* ctx
, GLenum func
, GLfloat ref
)
204 struct i830_context
*i830
= i830_context(ctx
);
205 int test
= intel_translate_compare_func(func
);
209 UNCLAMPED_FLOAT_TO_UBYTE(refByte
, ref
);
210 refInt
= (GLuint
) refByte
;
212 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
213 i830
->state
.Ctx
[I830_CTXREG_STATE2
] &= ~ALPHA_TEST_REF_MASK
;
214 i830
->state
.Ctx
[I830_CTXREG_STATE2
] |= (ENABLE_ALPHA_TEST_FUNC
|
215 ENABLE_ALPHA_REF_VALUE
|
216 ALPHA_TEST_FUNC(test
) |
217 ALPHA_REF_VALUE(refInt
));
221 * Makes sure that the proper enables are set for LogicOp, Independant Alpha
222 * Blend, and Blending. It needs to be called from numerous places where we
223 * could change the LogicOp or Independant Alpha Blend without subsequent
227 * This function is substantially different from the old i830-specific driver.
228 * I'm not sure which is correct.
231 i830EvalLogicOpBlendState(struct gl_context
* ctx
)
233 struct i830_context
*i830
= i830_context(ctx
);
235 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
237 if (RGBA_LOGICOP_ENABLED(ctx
)) {
238 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~(ENABLE_COLOR_BLEND
|
239 ENABLE_LOGIC_OP_MASK
);
240 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= (DISABLE_COLOR_BLEND
|
243 else if (ctx
->Color
.BlendEnabled
) {
244 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~(ENABLE_COLOR_BLEND
|
245 ENABLE_LOGIC_OP_MASK
);
246 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= (ENABLE_COLOR_BLEND
|
250 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~(ENABLE_COLOR_BLEND
|
251 ENABLE_LOGIC_OP_MASK
);
252 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= (DISABLE_COLOR_BLEND
|
258 i830BlendColor(struct gl_context
* ctx
, const GLfloat color
[4])
260 struct i830_context
*i830
= i830_context(ctx
);
263 DBG("%s\n", __FUNCTION__
);
265 UNCLAMPED_FLOAT_TO_UBYTE(r
, color
[RCOMP
]);
266 UNCLAMPED_FLOAT_TO_UBYTE(g
, color
[GCOMP
]);
267 UNCLAMPED_FLOAT_TO_UBYTE(b
, color
[BCOMP
]);
268 UNCLAMPED_FLOAT_TO_UBYTE(a
, color
[ACOMP
]);
270 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
271 i830
->state
.Ctx
[I830_CTXREG_BLENDCOLOR1
] =
272 (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
276 * Sets both the blend equation (called "function" in i830 docs) and the
277 * blend function (called "factor" in i830 docs). This is done in a single
278 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
279 * change the interpretation of the blend function.
282 i830_set_blend_state(struct gl_context
* ctx
)
284 struct i830_context
*i830
= i830_context(ctx
);
294 SRC_BLND_FACT(intel_translate_blend_factor(ctx
->Color
.BlendSrcRGB
))
295 | DST_BLND_FACT(intel_translate_blend_factor(ctx
->Color
.BlendDstRGB
));
297 switch (ctx
->Color
.BlendEquationRGB
) {
299 eqnRGB
= BLENDFUNC_ADD
;
302 eqnRGB
= BLENDFUNC_MIN
;
303 funcRGB
= SRC_BLND_FACT(BLENDFACT_ONE
) | DST_BLND_FACT(BLENDFACT_ONE
);
306 eqnRGB
= BLENDFUNC_MAX
;
307 funcRGB
= SRC_BLND_FACT(BLENDFACT_ONE
) | DST_BLND_FACT(BLENDFACT_ONE
);
309 case GL_FUNC_SUBTRACT
:
310 eqnRGB
= BLENDFUNC_SUB
;
312 case GL_FUNC_REVERSE_SUBTRACT
:
313 eqnRGB
= BLENDFUNC_RVRSE_SUB
;
316 fprintf(stderr
, "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
317 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationRGB
);
322 funcA
= SRC_ABLEND_FACT(intel_translate_blend_factor(ctx
->Color
.BlendSrcA
))
323 | DST_ABLEND_FACT(intel_translate_blend_factor(ctx
->Color
.BlendDstA
));
325 switch (ctx
->Color
.BlendEquationA
) {
327 eqnA
= BLENDFUNC_ADD
;
330 eqnA
= BLENDFUNC_MIN
;
331 funcA
= SRC_BLND_FACT(BLENDFACT_ONE
) | DST_BLND_FACT(BLENDFACT_ONE
);
334 eqnA
= BLENDFUNC_MAX
;
335 funcA
= SRC_BLND_FACT(BLENDFACT_ONE
) | DST_BLND_FACT(BLENDFACT_ONE
);
337 case GL_FUNC_SUBTRACT
:
338 eqnA
= BLENDFUNC_SUB
;
340 case GL_FUNC_REVERSE_SUBTRACT
:
341 eqnA
= BLENDFUNC_RVRSE_SUB
;
344 fprintf(stderr
, "[%s:%u] Invalid alpha blend equation (0x%04x).\n",
345 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationA
);
350 | _3DSTATE_INDPT_ALPHA_BLEND_CMD
351 | ENABLE_SRC_ABLEND_FACTOR
| ENABLE_DST_ABLEND_FACTOR
352 | ENABLE_ALPHA_BLENDFUNC
;
353 s1
= eqnRGB
| funcRGB
354 | _3DSTATE_MODES_1_CMD
355 | ENABLE_SRC_BLND_FACTOR
| ENABLE_DST_BLND_FACTOR
356 | ENABLE_COLR_BLND_FUNC
;
358 if ((eqnA
| funcA
) != (eqnRGB
| funcRGB
))
359 iab
|= ENABLE_INDPT_ALPHA_BLEND
;
361 iab
|= DISABLE_INDPT_ALPHA_BLEND
;
363 if (iab
!= i830
->state
.Ctx
[I830_CTXREG_IALPHAB
] ||
364 s1
!= i830
->state
.Ctx
[I830_CTXREG_STATE1
]) {
365 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
366 i830
->state
.Ctx
[I830_CTXREG_IALPHAB
] = iab
;
367 i830
->state
.Ctx
[I830_CTXREG_STATE1
] = s1
;
370 /* This will catch a logicop blend equation. It will also ensure
371 * independant alpha blend is really in the correct state (either enabled
372 * or disabled) if blending is already enabled.
375 i830EvalLogicOpBlendState(ctx
);
379 "[%s:%u] STATE1: 0x%08x IALPHAB: 0x%08x blend is %sabled\n",
380 __FUNCTION__
, __LINE__
, i830
->state
.Ctx
[I830_CTXREG_STATE1
],
381 i830
->state
.Ctx
[I830_CTXREG_IALPHAB
],
382 (ctx
->Color
.BlendEnabled
) ? "en" : "dis");
388 i830BlendEquationSeparate(struct gl_context
* ctx
, GLenum modeRGB
, GLenum modeA
)
390 DBG("%s -> %s, %s\n", __FUNCTION__
,
391 _mesa_lookup_enum_by_nr(modeRGB
),
392 _mesa_lookup_enum_by_nr(modeA
));
396 i830_set_blend_state(ctx
);
401 i830BlendFuncSeparate(struct gl_context
* ctx
, GLenum sfactorRGB
,
402 GLenum dfactorRGB
, GLenum sfactorA
, GLenum dfactorA
)
404 DBG("%s -> RGB(%s, %s) A(%s, %s)\n", __FUNCTION__
,
405 _mesa_lookup_enum_by_nr(sfactorRGB
),
406 _mesa_lookup_enum_by_nr(dfactorRGB
),
407 _mesa_lookup_enum_by_nr(sfactorA
),
408 _mesa_lookup_enum_by_nr(dfactorA
));
414 i830_set_blend_state(ctx
);
420 i830DepthFunc(struct gl_context
* ctx
, GLenum func
)
422 struct i830_context
*i830
= i830_context(ctx
);
423 int test
= intel_translate_compare_func(func
);
425 DBG("%s\n", __FUNCTION__
);
427 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
428 i830
->state
.Ctx
[I830_CTXREG_STATE3
] &= ~DEPTH_TEST_FUNC_MASK
;
429 i830
->state
.Ctx
[I830_CTXREG_STATE3
] |= (ENABLE_DEPTH_TEST_FUNC
|
430 DEPTH_TEST_FUNC(test
));
434 i830DepthMask(struct gl_context
* ctx
, GLboolean flag
)
436 struct i830_context
*i830
= i830_context(ctx
);
438 DBG("%s flag (%d)\n", __FUNCTION__
, flag
);
440 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
442 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] &= ~ENABLE_DIS_DEPTH_WRITE_MASK
;
444 if (flag
&& ctx
->Depth
.Test
)
445 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= ENABLE_DEPTH_WRITE
;
447 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= DISABLE_DEPTH_WRITE
;
450 /** Called from ctx->Driver.Viewport() */
452 i830Viewport(struct gl_context
* ctx
,
453 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
455 intelCalcViewport(ctx
);
459 /** Called from ctx->Driver.DepthRange() */
461 i830DepthRange(struct gl_context
* ctx
, GLclampd nearval
, GLclampd farval
)
463 intelCalcViewport(ctx
);
466 /* =============================================================
469 * The i830 supports a 4x4 stipple natively, GL wants 32x32.
470 * Fortunately stipple is usually a repeating pattern.
473 i830PolygonStipple(struct gl_context
* ctx
, const GLubyte
* mask
)
475 struct i830_context
*i830
= i830_context(ctx
);
476 const GLubyte
*m
= mask
;
479 int active
= (ctx
->Polygon
.StippleFlag
&&
480 i830
->intel
.reduced_primitive
== GL_TRIANGLES
);
484 I830_STATECHANGE(i830
, I830_UPLOAD_STIPPLE
);
485 i830
->state
.Stipple
[I830_STPREG_ST1
] &= ~ST1_ENABLE
;
488 p
[0] = mask
[12] & 0xf;
490 p
[1] = mask
[8] & 0xf;
492 p
[2] = mask
[4] & 0xf;
494 p
[3] = mask
[0] & 0xf;
497 for (k
= 0; k
< 8; k
++)
498 for (j
= 3; j
>= 0; j
--)
499 for (i
= 0; i
< 4; i
++, m
++)
501 i830
->intel
.hw_stipple
= 0;
505 newMask
= (((p
[0] & 0xf) << 0) |
506 ((p
[1] & 0xf) << 4) |
507 ((p
[2] & 0xf) << 8) | ((p
[3] & 0xf) << 12));
510 if (newMask
== 0xffff || newMask
== 0x0) {
511 /* this is needed to make conform pass */
512 i830
->intel
.hw_stipple
= 0;
516 i830
->state
.Stipple
[I830_STPREG_ST1
] &= ~0xffff;
517 i830
->state
.Stipple
[I830_STPREG_ST1
] |= newMask
;
518 i830
->intel
.hw_stipple
= 1;
521 i830
->state
.Stipple
[I830_STPREG_ST1
] |= ST1_ENABLE
;
525 /* =============================================================
529 i830Scissor(struct gl_context
* ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
531 struct i830_context
*i830
= i830_context(ctx
);
534 if (!ctx
->DrawBuffer
)
537 DBG("%s %d,%d %dx%d\n", __FUNCTION__
, x
, y
, w
, h
);
539 if (ctx
->DrawBuffer
->Name
== 0) {
541 y1
= ctx
->DrawBuffer
->Height
- (y
+ h
);
544 DBG("%s %d..%d,%d..%d (inverted)\n", __FUNCTION__
, x1
, x2
, y1
, y2
);
547 /* FBO - not inverted
553 DBG("%s %d..%d,%d..%d (not inverted)\n", __FUNCTION__
, x1
, x2
, y1
, y2
);
556 x1
= CLAMP(x1
, 0, ctx
->DrawBuffer
->Width
- 1);
557 y1
= CLAMP(y1
, 0, ctx
->DrawBuffer
->Height
- 1);
558 x2
= CLAMP(x2
, 0, ctx
->DrawBuffer
->Width
- 1);
559 y2
= CLAMP(y2
, 0, ctx
->DrawBuffer
->Height
- 1);
561 DBG("%s %d..%d,%d..%d (clamped)\n", __FUNCTION__
, x1
, x2
, y1
, y2
);
563 I830_STATECHANGE(i830
, I830_UPLOAD_BUFFERS
);
564 i830
->state
.Buffer
[I830_DESTREG_SR1
] = (y1
<< 16) | (x1
& 0xffff);
565 i830
->state
.Buffer
[I830_DESTREG_SR2
] = (y2
<< 16) | (x2
& 0xffff);
569 i830LogicOp(struct gl_context
* ctx
, GLenum opcode
)
571 struct i830_context
*i830
= i830_context(ctx
);
572 int tmp
= intel_translate_logic_op(opcode
);
574 DBG("%s\n", __FUNCTION__
);
576 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
577 i830
->state
.Ctx
[I830_CTXREG_STATE4
] &= ~LOGICOP_MASK
;
578 i830
->state
.Ctx
[I830_CTXREG_STATE4
] |= LOGIC_OP_FUNC(tmp
);
584 i830CullFaceFrontFace(struct gl_context
* ctx
, GLenum unused
)
586 struct i830_context
*i830
= i830_context(ctx
);
589 DBG("%s\n", __FUNCTION__
);
591 if (!ctx
->Polygon
.CullFlag
) {
592 mode
= CULLMODE_NONE
;
594 else if (ctx
->Polygon
.CullFaceMode
!= GL_FRONT_AND_BACK
) {
597 if (ctx
->Polygon
.CullFaceMode
== GL_FRONT
)
598 mode
^= (CULLMODE_CW
^ CULLMODE_CCW
);
599 if (ctx
->Polygon
.FrontFace
!= GL_CCW
)
600 mode
^= (CULLMODE_CW
^ CULLMODE_CCW
);
603 mode
= CULLMODE_BOTH
;
606 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
607 i830
->state
.Ctx
[I830_CTXREG_STATE3
] &= ~CULLMODE_MASK
;
608 i830
->state
.Ctx
[I830_CTXREG_STATE3
] |= ENABLE_CULL_MODE
| mode
;
612 i830LineWidth(struct gl_context
* ctx
, GLfloat widthf
)
614 struct i830_context
*i830
= i830_context(ctx
);
618 DBG("%s\n", __FUNCTION__
);
620 width
= (int) (widthf
* 2);
621 width
= CLAMP(width
, 1, 15);
623 state5
= i830
->state
.Ctx
[I830_CTXREG_STATE5
] & ~FIXED_LINE_WIDTH_MASK
;
624 state5
|= (ENABLE_FIXED_LINE_WIDTH
| FIXED_LINE_WIDTH(width
));
626 if (state5
!= i830
->state
.Ctx
[I830_CTXREG_STATE5
]) {
627 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
628 i830
->state
.Ctx
[I830_CTXREG_STATE5
] = state5
;
633 i830PointSize(struct gl_context
* ctx
, GLfloat size
)
635 struct i830_context
*i830
= i830_context(ctx
);
636 GLint point_size
= (int) size
;
638 DBG("%s\n", __FUNCTION__
);
640 point_size
= CLAMP(point_size
, 1, 256);
641 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
642 i830
->state
.Ctx
[I830_CTXREG_STATE5
] &= ~FIXED_POINT_WIDTH_MASK
;
643 i830
->state
.Ctx
[I830_CTXREG_STATE5
] |= (ENABLE_FIXED_POINT_WIDTH
|
644 FIXED_POINT_WIDTH(point_size
));
648 /* =============================================================
653 i830ColorMask(struct gl_context
* ctx
,
654 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
656 struct i830_context
*i830
= i830_context(ctx
);
659 DBG("%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__
, r
, g
, b
, a
);
661 tmp
= ((i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] & ~WRITEMASK_MASK
) |
664 ((!r
) << WRITEMASK_RED_SHIFT
) |
665 ((!g
) << WRITEMASK_GREEN_SHIFT
) |
666 ((!b
) << WRITEMASK_BLUE_SHIFT
) | ((!a
) << WRITEMASK_ALPHA_SHIFT
));
668 if (tmp
!= i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
]) {
669 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
670 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] = tmp
;
675 update_specular(struct gl_context
* ctx
)
677 struct i830_context
*i830
= i830_context(ctx
);
679 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
680 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_SPEC_ADD_MASK
;
682 if (NEED_SECONDARY_COLOR(ctx
))
683 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_SPEC_ADD
;
685 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_SPEC_ADD
;
689 i830LightModelfv(struct gl_context
* ctx
, GLenum pname
, const GLfloat
* param
)
691 DBG("%s\n", __FUNCTION__
);
693 if (pname
== GL_LIGHT_MODEL_COLOR_CONTROL
) {
694 update_specular(ctx
);
698 /* In Mesa 3.5 we can reliably do native flatshading.
701 i830ShadeModel(struct gl_context
* ctx
, GLenum mode
)
703 struct i830_context
*i830
= i830_context(ctx
);
704 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
707 #define SHADE_MODE_MASK ((1<<10)|(1<<8)|(1<<6)|(1<<4))
709 i830
->state
.Ctx
[I830_CTXREG_STATE3
] &= ~SHADE_MODE_MASK
;
711 if (mode
== GL_FLAT
) {
712 i830
->state
.Ctx
[I830_CTXREG_STATE3
] |=
713 (ALPHA_SHADE_MODE(SHADE_MODE_FLAT
) | FOG_SHADE_MODE(SHADE_MODE_FLAT
)
714 | SPEC_SHADE_MODE(SHADE_MODE_FLAT
) |
715 COLOR_SHADE_MODE(SHADE_MODE_FLAT
));
718 i830
->state
.Ctx
[I830_CTXREG_STATE3
] |=
719 (ALPHA_SHADE_MODE(SHADE_MODE_LINEAR
) |
720 FOG_SHADE_MODE(SHADE_MODE_LINEAR
) |
721 SPEC_SHADE_MODE(SHADE_MODE_LINEAR
) |
722 COLOR_SHADE_MODE(SHADE_MODE_LINEAR
));
726 /* =============================================================
730 i830Fogfv(struct gl_context
* ctx
, GLenum pname
, const GLfloat
* param
)
732 struct i830_context
*i830
= i830_context(ctx
);
734 DBG("%s\n", __FUNCTION__
);
736 if (pname
== GL_FOG_COLOR
) {
737 GLuint color
= (((GLubyte
) (ctx
->Fog
.Color
[0] * 255.0F
) << 16) |
738 ((GLubyte
) (ctx
->Fog
.Color
[1] * 255.0F
) << 8) |
739 ((GLubyte
) (ctx
->Fog
.Color
[2] * 255.0F
) << 0));
741 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
742 i830
->state
.Ctx
[I830_CTXREG_FOGCOLOR
] =
743 (_3DSTATE_FOG_COLOR_CMD
| color
);
747 /* =============================================================
751 i830Enable(struct gl_context
* ctx
, GLenum cap
, GLboolean state
)
753 struct i830_context
*i830
= i830_context(ctx
);
758 update_specular(ctx
);
762 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
763 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_DIS_ALPHA_TEST_MASK
;
765 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_ALPHA_TEST
;
767 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_ALPHA_TEST
;
772 i830EvalLogicOpBlendState(ctx
);
775 case GL_COLOR_LOGIC_OP
:
776 i830EvalLogicOpBlendState(ctx
);
778 /* Logicop doesn't seem to work at 16bpp:
780 if (i830
->intel
.ctx
.Visual
.rgbBits
== 16)
781 FALLBACK(&i830
->intel
, I830_FALLBACK_LOGICOP
, state
);
785 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
786 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] &= ~ENABLE_DITHER
;
789 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= ENABLE_DITHER
;
791 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= DISABLE_DITHER
;
795 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
796 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_DIS_DEPTH_TEST_MASK
;
799 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_DEPTH_TEST
;
801 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_DEPTH_TEST
;
803 /* Also turn off depth writes when GL_DEPTH_TEST is disabled:
805 i830DepthMask(ctx
, ctx
->Depth
.Mask
);
808 case GL_SCISSOR_TEST
:
809 I830_STATECHANGE(i830
, I830_UPLOAD_BUFFERS
);
812 i830
->state
.Buffer
[I830_DESTREG_SENABLE
] =
813 (_3DSTATE_SCISSOR_ENABLE_CMD
| ENABLE_SCISSOR_RECT
);
815 i830
->state
.Buffer
[I830_DESTREG_SENABLE
] =
816 (_3DSTATE_SCISSOR_ENABLE_CMD
| DISABLE_SCISSOR_RECT
);
821 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
823 i830
->state
.Ctx
[I830_CTXREG_AA
] &= ~AA_LINE_ENABLE
;
825 i830
->state
.Ctx
[I830_CTXREG_AA
] |= AA_LINE_ENABLE
;
827 i830
->state
.Ctx
[I830_CTXREG_AA
] |= AA_LINE_DISABLE
;
831 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
832 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_DIS_FOG_MASK
;
834 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_FOG
;
836 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_FOG
;
840 i830CullFaceFrontFace(ctx
, 0);
846 case GL_STENCIL_TEST
:
848 GLboolean hw_stencil
= GL_FALSE
;
849 if (ctx
->DrawBuffer
) {
850 struct intel_renderbuffer
*irbStencil
851 = intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_STENCIL
);
852 hw_stencil
= (irbStencil
&& irbStencil
->region
);
855 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
858 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_STENCIL_TEST
;
859 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= ENABLE_STENCIL_WRITE
;
862 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_STENCIL_TEST
;
863 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] &=
864 ~ENABLE_STENCIL_WRITE
;
865 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_STENCIL_TEST
;
866 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |=
867 DISABLE_STENCIL_WRITE
;
871 FALLBACK(&i830
->intel
, I830_FALLBACK_STENCIL
, state
);
876 case GL_POLYGON_STIPPLE
:
877 /* The stipple command worked on my 855GM box, but not my 845G.
878 * I'll do more testing later to find out exactly which hardware
879 * supports it. Disabled for now.
881 if (i830
->intel
.hw_stipple
&&
882 i830
->intel
.reduced_primitive
== GL_TRIANGLES
) {
883 I830_STATECHANGE(i830
, I830_UPLOAD_STIPPLE
);
884 i830
->state
.Stipple
[I830_STPREG_ST1
] &= ~ST1_ENABLE
;
886 i830
->state
.Stipple
[I830_STPREG_ST1
] |= ST1_ENABLE
;
897 i830_init_packets(struct i830_context
*i830
)
900 memset(&i830
->state
, 0, sizeof(i830
->state
));
902 /* Set default blend state */
903 i830
->state
.TexBlend
[0][0] = (_3DSTATE_MAP_BLEND_OP_CMD(0) |
905 ENABLE_TEXOUTPUT_WRT_SEL
|
906 TEXOP_OUTPUT_CURRENT
|
907 DISABLE_TEX_CNTRL_STAGE
|
910 TEXOP_LAST_STAGE
| TEXBLENDOP_ARG1
);
911 i830
->state
.TexBlend
[0][1] = (_3DSTATE_MAP_BLEND_OP_CMD(0) |
913 ENABLE_TEXOUTPUT_WRT_SEL
|
914 TEXOP_OUTPUT_CURRENT
|
916 TEXOP_MODIFY_PARMS
| TEXBLENDOP_ARG1
);
917 i830
->state
.TexBlend
[0][2] = (_3DSTATE_MAP_BLEND_ARG_CMD(0) |
920 TEXBLENDARG_MODIFY_PARMS
|
921 TEXBLENDARG_DIFFUSE
);
922 i830
->state
.TexBlend
[0][3] = (_3DSTATE_MAP_BLEND_ARG_CMD(0) |
925 TEXBLENDARG_MODIFY_PARMS
|
926 TEXBLENDARG_DIFFUSE
);
928 i830
->state
.TexBlendWordsUsed
[0] = 4;
931 i830
->state
.Ctx
[I830_CTXREG_VF
] = 0;
932 i830
->state
.Ctx
[I830_CTXREG_VF2
] = 0;
934 i830
->state
.Ctx
[I830_CTXREG_AA
] = (_3DSTATE_AA_CMD
|
935 AA_LINE_ECAAR_WIDTH_ENABLE
|
936 AA_LINE_ECAAR_WIDTH_1_0
|
937 AA_LINE_REGION_WIDTH_ENABLE
|
938 AA_LINE_REGION_WIDTH_1_0
|
941 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] = (_3DSTATE_ENABLES_1_CMD
|
943 DISABLE_STENCIL_TEST
|
948 DISABLE_COLOR_BLEND
|
951 #if 000 /* XXX all the stencil enable state is set in i830Enable(), right? */
952 if (i830
->intel
.hw_stencil
) {
953 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] = (_3DSTATE_ENABLES_2_CMD
|
954 ENABLE_STENCIL_WRITE
|
958 /* set no color comps disabled */
965 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] = (_3DSTATE_ENABLES_2_CMD
|
966 DISABLE_STENCIL_WRITE
|
970 /* set no color comps disabled */
975 i830
->state
.Ctx
[I830_CTXREG_STATE1
] = (_3DSTATE_MODES_1_CMD
|
976 ENABLE_COLR_BLND_FUNC
|
978 ENABLE_SRC_BLND_FACTOR
|
979 SRC_BLND_FACT(BLENDFACT_ONE
) |
980 ENABLE_DST_BLND_FACTOR
|
981 DST_BLND_FACT(BLENDFACT_ZERO
));
983 i830
->state
.Ctx
[I830_CTXREG_STATE2
] = (_3DSTATE_MODES_2_CMD
|
984 ENABLE_GLOBAL_DEPTH_BIAS
|
985 GLOBAL_DEPTH_BIAS(0) |
986 ENABLE_ALPHA_TEST_FUNC
|
987 ALPHA_TEST_FUNC(COMPAREFUNC_ALWAYS
)
988 | ALPHA_REF_VALUE(0));
990 i830
->state
.Ctx
[I830_CTXREG_STATE3
] = (_3DSTATE_MODES_3_CMD
|
991 ENABLE_DEPTH_TEST_FUNC
|
992 DEPTH_TEST_FUNC(COMPAREFUNC_LESS
) |
993 ENABLE_ALPHA_SHADE_MODE
|
994 ALPHA_SHADE_MODE(SHADE_MODE_LINEAR
)
995 | ENABLE_FOG_SHADE_MODE
|
996 FOG_SHADE_MODE(SHADE_MODE_LINEAR
) |
997 ENABLE_SPEC_SHADE_MODE
|
998 SPEC_SHADE_MODE(SHADE_MODE_LINEAR
) |
999 ENABLE_COLOR_SHADE_MODE
|
1000 COLOR_SHADE_MODE(SHADE_MODE_LINEAR
)
1001 | ENABLE_CULL_MODE
| CULLMODE_NONE
);
1003 i830
->state
.Ctx
[I830_CTXREG_STATE4
] = (_3DSTATE_MODES_4_CMD
|
1004 ENABLE_LOGIC_OP_FUNC
|
1005 LOGIC_OP_FUNC(LOGICOP_COPY
) |
1006 ENABLE_STENCIL_TEST_MASK
|
1007 STENCIL_TEST_MASK(0xff) |
1008 ENABLE_STENCIL_WRITE_MASK
|
1009 STENCIL_WRITE_MASK(0xff));
1011 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] = (_3DSTATE_STENCIL_TEST_CMD
|
1012 ENABLE_STENCIL_PARMS
|
1013 STENCIL_FAIL_OP(STENCILOP_KEEP
)
1015 STENCIL_PASS_DEPTH_FAIL_OP
1017 STENCIL_PASS_DEPTH_PASS_OP
1019 ENABLE_STENCIL_TEST_FUNC
|
1021 (COMPAREFUNC_ALWAYS
) |
1022 ENABLE_STENCIL_REF_VALUE
|
1023 STENCIL_REF_VALUE(0));
1025 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 */
1026 ENABLE_FIXED_POINT_WIDTH
|
1027 FIXED_POINT_WIDTH(1));
1029 i830
->state
.Ctx
[I830_CTXREG_IALPHAB
] = (_3DSTATE_INDPT_ALPHA_BLEND_CMD
|
1030 DISABLE_INDPT_ALPHA_BLEND
|
1031 ENABLE_ALPHA_BLENDFUNC
|
1034 i830
->state
.Ctx
[I830_CTXREG_FOGCOLOR
] = (_3DSTATE_FOG_COLOR_CMD
|
1036 FOG_COLOR_GREEN(0) |
1039 i830
->state
.Ctx
[I830_CTXREG_BLENDCOLOR0
] = _3DSTATE_CONST_BLEND_COLOR_CMD
;
1040 i830
->state
.Ctx
[I830_CTXREG_BLENDCOLOR1
] = 0;
1042 i830
->state
.Ctx
[I830_CTXREG_MCSB0
] = _3DSTATE_MAP_COORD_SETBIND_CMD
;
1043 i830
->state
.Ctx
[I830_CTXREG_MCSB1
] = (TEXBIND_SET3(TEXCOORDSRC_VTXSET_3
) |
1044 TEXBIND_SET2(TEXCOORDSRC_VTXSET_2
) |
1045 TEXBIND_SET1(TEXCOORDSRC_VTXSET_1
) |
1046 TEXBIND_SET0(TEXCOORDSRC_VTXSET_0
));
1048 i830
->state
.RasterRules
[I830_RASTER_RULES
] = (_3DSTATE_RASTER_RULES_CMD
|
1049 ENABLE_POINT_RASTER_RULE
|
1050 OGL_POINT_RASTER_RULE
|
1051 ENABLE_LINE_STRIP_PROVOKE_VRTX
|
1052 ENABLE_TRI_FAN_PROVOKE_VRTX
|
1053 ENABLE_TRI_STRIP_PROVOKE_VRTX
|
1054 LINE_STRIP_PROVOKE_VRTX(1) |
1055 TRI_FAN_PROVOKE_VRTX(2) |
1056 TRI_STRIP_PROVOKE_VRTX(2));
1059 i830
->state
.Stipple
[I830_STPREG_ST0
] = _3DSTATE_STIPPLE
;
1061 i830
->state
.Buffer
[I830_DESTREG_DV0
] = _3DSTATE_DST_BUF_VARS_CMD
;
1062 i830
->state
.Buffer
[I830_DESTREG_SENABLE
] = (_3DSTATE_SCISSOR_ENABLE_CMD
|
1063 DISABLE_SCISSOR_RECT
);
1064 i830
->state
.Buffer
[I830_DESTREG_SR0
] = _3DSTATE_SCISSOR_RECT_0_CMD
;
1065 i830
->state
.Buffer
[I830_DESTREG_SR1
] = 0;
1066 i830
->state
.Buffer
[I830_DESTREG_SR2
] = 0;
1070 i830_update_provoking_vertex(struct gl_context
* ctx
)
1072 struct i830_context
*i830
= i830_context(ctx
);
1074 I830_STATECHANGE(i830
, I830_UPLOAD_RASTER_RULES
);
1075 i830
->state
.RasterRules
[I830_RASTER_RULES
] &= ~(LINE_STRIP_PROVOKE_VRTX_MASK
|
1076 TRI_FAN_PROVOKE_VRTX_MASK
|
1077 TRI_STRIP_PROVOKE_VRTX_MASK
);
1080 if (ctx
->Light
.ProvokingVertex
== GL_LAST_VERTEX_CONVENTION
) {
1081 i830
->state
.RasterRules
[I830_RASTER_RULES
] |= (LINE_STRIP_PROVOKE_VRTX(1) |
1082 TRI_FAN_PROVOKE_VRTX(2) |
1083 TRI_STRIP_PROVOKE_VRTX(2));
1085 i830
->state
.RasterRules
[I830_RASTER_RULES
] |= (LINE_STRIP_PROVOKE_VRTX(0) |
1086 TRI_FAN_PROVOKE_VRTX(1) |
1087 TRI_STRIP_PROVOKE_VRTX(0));
1092 i830InitStateFuncs(struct dd_function_table
*functions
)
1094 functions
->AlphaFunc
= i830AlphaFunc
;
1095 functions
->BlendColor
= i830BlendColor
;
1096 functions
->BlendEquationSeparate
= i830BlendEquationSeparate
;
1097 functions
->BlendFuncSeparate
= i830BlendFuncSeparate
;
1098 functions
->ColorMask
= i830ColorMask
;
1099 functions
->CullFace
= i830CullFaceFrontFace
;
1100 functions
->DepthFunc
= i830DepthFunc
;
1101 functions
->DepthMask
= i830DepthMask
;
1102 functions
->Enable
= i830Enable
;
1103 functions
->Fogfv
= i830Fogfv
;
1104 functions
->FrontFace
= i830CullFaceFrontFace
;
1105 functions
->LightModelfv
= i830LightModelfv
;
1106 functions
->LineWidth
= i830LineWidth
;
1107 functions
->LogicOpcode
= i830LogicOp
;
1108 functions
->PointSize
= i830PointSize
;
1109 functions
->PolygonStipple
= i830PolygonStipple
;
1110 functions
->Scissor
= i830Scissor
;
1111 functions
->ShadeModel
= i830ShadeModel
;
1112 functions
->StencilFuncSeparate
= i830StencilFuncSeparate
;
1113 functions
->StencilMaskSeparate
= i830StencilMaskSeparate
;
1114 functions
->StencilOpSeparate
= i830StencilOpSeparate
;
1115 functions
->DepthRange
= i830DepthRange
;
1116 functions
->Viewport
= i830Viewport
;
1120 i830InitState(struct i830_context
*i830
)
1122 struct gl_context
*ctx
= &i830
->intel
.ctx
;
1124 i830_init_packets(i830
);
1126 _mesa_init_driver_state(ctx
);
1128 i830
->state
.emitted
= 0;
1129 i830
->state
.active
= (I830_UPLOAD_INVARIENT
|
1130 I830_UPLOAD_RASTER_RULES
|
1131 I830_UPLOAD_TEXBLEND(0) |
1132 I830_UPLOAD_STIPPLE
|
1133 I830_UPLOAD_CTX
| I830_UPLOAD_BUFFERS
);