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"
33 #include "main/fbobject.h"
35 #include "main/state.h"
37 #include "drivers/common/driverfuncs.h"
39 #include "intel_screen.h"
40 #include "intel_batchbuffer.h"
41 #include "intel_mipmap_tree.h"
42 #include "intel_fbo.h"
43 #include "intel_buffers.h"
45 #include "i830_context.h"
48 #define FILE_DEBUG_FLAG DEBUG_STATE
51 i830StencilFuncSeparate(struct gl_context
* ctx
, GLenum face
, GLenum func
, GLint ref
,
54 struct i830_context
*i830
= i830_context(ctx
);
55 int test
= intel_translate_compare_func(func
);
59 DBG("%s : func: %s, ref : 0x%x, mask: 0x%x\n", __FUNCTION__
,
60 _mesa_lookup_enum_by_nr(func
), ref
, mask
);
63 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
64 i830
->state
.Ctx
[I830_CTXREG_STATE4
] &= ~MODE4_ENABLE_STENCIL_TEST_MASK
;
65 i830
->state
.Ctx
[I830_CTXREG_STATE4
] |= (ENABLE_STENCIL_TEST_MASK
|
66 STENCIL_TEST_MASK(mask
));
67 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] &= ~(STENCIL_REF_VALUE_MASK
|
68 ENABLE_STENCIL_TEST_FUNC_MASK
);
69 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] |= (ENABLE_STENCIL_REF_VALUE
|
70 ENABLE_STENCIL_TEST_FUNC
|
71 STENCIL_REF_VALUE(ref
) |
72 STENCIL_TEST_FUNC(test
));
76 i830StencilMaskSeparate(struct gl_context
* ctx
, GLenum face
, GLuint mask
)
78 struct i830_context
*i830
= i830_context(ctx
);
80 DBG("%s : mask 0x%x\n", __FUNCTION__
, mask
);
84 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
85 i830
->state
.Ctx
[I830_CTXREG_STATE4
] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK
;
86 i830
->state
.Ctx
[I830_CTXREG_STATE4
] |= (ENABLE_STENCIL_WRITE_MASK
|
87 STENCIL_WRITE_MASK(mask
));
91 i830StencilOpSeparate(struct gl_context
* ctx
, GLenum face
, GLenum fail
, GLenum zfail
,
94 struct i830_context
*i830
= i830_context(ctx
);
97 DBG("%s: fail : %s, zfail: %s, zpass : %s\n", __FUNCTION__
,
98 _mesa_lookup_enum_by_nr(fail
),
99 _mesa_lookup_enum_by_nr(zfail
),
100 _mesa_lookup_enum_by_nr(zpass
));
108 fop
= STENCILOP_KEEP
;
111 fop
= STENCILOP_ZERO
;
114 fop
= STENCILOP_REPLACE
;
117 fop
= STENCILOP_INCRSAT
;
120 fop
= STENCILOP_DECRSAT
;
123 fop
= STENCILOP_INCR
;
126 fop
= STENCILOP_DECR
;
129 fop
= STENCILOP_INVERT
;
136 dfop
= STENCILOP_KEEP
;
139 dfop
= STENCILOP_ZERO
;
142 dfop
= STENCILOP_REPLACE
;
145 dfop
= STENCILOP_INCRSAT
;
148 dfop
= STENCILOP_DECRSAT
;
151 dfop
= STENCILOP_INCR
;
154 dfop
= STENCILOP_DECR
;
157 dfop
= STENCILOP_INVERT
;
164 dpop
= STENCILOP_KEEP
;
167 dpop
= STENCILOP_ZERO
;
170 dpop
= STENCILOP_REPLACE
;
173 dpop
= STENCILOP_INCRSAT
;
176 dpop
= STENCILOP_DECRSAT
;
179 dpop
= STENCILOP_INCR
;
182 dpop
= STENCILOP_DECR
;
185 dpop
= STENCILOP_INVERT
;
192 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
193 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] &= ~(STENCIL_OPS_MASK
);
194 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] |= (ENABLE_STENCIL_PARMS
|
195 STENCIL_FAIL_OP(fop
) |
196 STENCIL_PASS_DEPTH_FAIL_OP
198 STENCIL_PASS_DEPTH_PASS_OP
203 i830AlphaFunc(struct gl_context
* ctx
, GLenum func
, GLfloat ref
)
205 struct i830_context
*i830
= i830_context(ctx
);
206 int test
= intel_translate_compare_func(func
);
210 UNCLAMPED_FLOAT_TO_UBYTE(refByte
, ref
);
211 refInt
= (GLuint
) refByte
;
213 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
214 i830
->state
.Ctx
[I830_CTXREG_STATE2
] &= ~ALPHA_TEST_REF_MASK
;
215 i830
->state
.Ctx
[I830_CTXREG_STATE2
] |= (ENABLE_ALPHA_TEST_FUNC
|
216 ENABLE_ALPHA_REF_VALUE
|
217 ALPHA_TEST_FUNC(test
) |
218 ALPHA_REF_VALUE(refInt
));
222 * Makes sure that the proper enables are set for LogicOp, Independant Alpha
223 * Blend, and Blending. It needs to be called from numerous places where we
224 * could change the LogicOp or Independant Alpha Blend without subsequent
228 * This function is substantially different from the old i830-specific driver.
229 * I'm not sure which is correct.
232 i830EvalLogicOpBlendState(struct gl_context
* ctx
)
234 struct i830_context
*i830
= i830_context(ctx
);
236 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
238 if (ctx
->Color
.ColorLogicOpEnabled
) {
239 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~(ENABLE_COLOR_BLEND
|
240 ENABLE_LOGIC_OP_MASK
);
241 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= (DISABLE_COLOR_BLEND
|
244 else if (ctx
->Color
.BlendEnabled
) {
245 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~(ENABLE_COLOR_BLEND
|
246 ENABLE_LOGIC_OP_MASK
);
247 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= (ENABLE_COLOR_BLEND
|
251 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~(ENABLE_COLOR_BLEND
|
252 ENABLE_LOGIC_OP_MASK
);
253 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= (DISABLE_COLOR_BLEND
|
259 i830BlendColor(struct gl_context
* ctx
, const GLfloat color
[4])
261 struct i830_context
*i830
= i830_context(ctx
);
264 DBG("%s\n", __FUNCTION__
);
266 UNCLAMPED_FLOAT_TO_UBYTE(r
, color
[RCOMP
]);
267 UNCLAMPED_FLOAT_TO_UBYTE(g
, color
[GCOMP
]);
268 UNCLAMPED_FLOAT_TO_UBYTE(b
, color
[BCOMP
]);
269 UNCLAMPED_FLOAT_TO_UBYTE(a
, color
[ACOMP
]);
271 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
272 i830
->state
.Ctx
[I830_CTXREG_BLENDCOLOR1
] =
273 (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
277 * Sets both the blend equation (called "function" in i830 docs) and the
278 * blend function (called "factor" in i830 docs). This is done in a single
279 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
280 * change the interpretation of the blend function.
283 i830_set_blend_state(struct gl_context
* ctx
)
285 struct i830_context
*i830
= i830_context(ctx
);
295 SRC_BLND_FACT(intel_translate_blend_factor(ctx
->Color
.Blend
[0].SrcRGB
))
296 | DST_BLND_FACT(intel_translate_blend_factor(ctx
->Color
.Blend
[0].DstRGB
));
298 switch (ctx
->Color
.Blend
[0].EquationRGB
) {
300 eqnRGB
= BLENDFUNC_ADD
;
303 eqnRGB
= BLENDFUNC_MIN
;
304 funcRGB
= SRC_BLND_FACT(BLENDFACT_ONE
) | DST_BLND_FACT(BLENDFACT_ONE
);
307 eqnRGB
= BLENDFUNC_MAX
;
308 funcRGB
= SRC_BLND_FACT(BLENDFACT_ONE
) | DST_BLND_FACT(BLENDFACT_ONE
);
310 case GL_FUNC_SUBTRACT
:
311 eqnRGB
= BLENDFUNC_SUB
;
313 case GL_FUNC_REVERSE_SUBTRACT
:
314 eqnRGB
= BLENDFUNC_RVRSE_SUB
;
317 fprintf(stderr
, "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
318 __FUNCTION__
, __LINE__
, ctx
->Color
.Blend
[0].EquationRGB
);
323 funcA
= SRC_ABLEND_FACT(intel_translate_blend_factor(ctx
->Color
.Blend
[0].SrcA
))
324 | DST_ABLEND_FACT(intel_translate_blend_factor(ctx
->Color
.Blend
[0].DstA
));
326 switch (ctx
->Color
.Blend
[0].EquationA
) {
328 eqnA
= BLENDFUNC_ADD
;
331 eqnA
= BLENDFUNC_MIN
;
332 funcA
= SRC_BLND_FACT(BLENDFACT_ONE
) | DST_BLND_FACT(BLENDFACT_ONE
);
335 eqnA
= BLENDFUNC_MAX
;
336 funcA
= SRC_BLND_FACT(BLENDFACT_ONE
) | DST_BLND_FACT(BLENDFACT_ONE
);
338 case GL_FUNC_SUBTRACT
:
339 eqnA
= BLENDFUNC_SUB
;
341 case GL_FUNC_REVERSE_SUBTRACT
:
342 eqnA
= BLENDFUNC_RVRSE_SUB
;
345 fprintf(stderr
, "[%s:%u] Invalid alpha blend equation (0x%04x).\n",
346 __FUNCTION__
, __LINE__
, ctx
->Color
.Blend
[0].EquationA
);
351 | _3DSTATE_INDPT_ALPHA_BLEND_CMD
352 | ENABLE_SRC_ABLEND_FACTOR
| ENABLE_DST_ABLEND_FACTOR
353 | ENABLE_ALPHA_BLENDFUNC
;
354 s1
= eqnRGB
| funcRGB
355 | _3DSTATE_MODES_1_CMD
356 | ENABLE_SRC_BLND_FACTOR
| ENABLE_DST_BLND_FACTOR
357 | ENABLE_COLR_BLND_FUNC
;
359 if ((eqnA
| funcA
) != (eqnRGB
| funcRGB
))
360 iab
|= ENABLE_INDPT_ALPHA_BLEND
;
362 iab
|= DISABLE_INDPT_ALPHA_BLEND
;
364 if (iab
!= i830
->state
.Ctx
[I830_CTXREG_IALPHAB
] ||
365 s1
!= i830
->state
.Ctx
[I830_CTXREG_STATE1
]) {
366 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
367 i830
->state
.Ctx
[I830_CTXREG_IALPHAB
] = iab
;
368 i830
->state
.Ctx
[I830_CTXREG_STATE1
] = s1
;
371 /* This will catch a logicop blend equation. It will also ensure
372 * independant alpha blend is really in the correct state (either enabled
373 * or disabled) if blending is already enabled.
376 i830EvalLogicOpBlendState(ctx
);
380 "[%s:%u] STATE1: 0x%08x IALPHAB: 0x%08x blend is %sabled\n",
381 __FUNCTION__
, __LINE__
, i830
->state
.Ctx
[I830_CTXREG_STATE1
],
382 i830
->state
.Ctx
[I830_CTXREG_IALPHAB
],
383 (ctx
->Color
.BlendEnabled
) ? "en" : "dis");
389 i830BlendEquationSeparate(struct gl_context
* ctx
, GLenum modeRGB
, GLenum modeA
)
391 DBG("%s -> %s, %s\n", __FUNCTION__
,
392 _mesa_lookup_enum_by_nr(modeRGB
),
393 _mesa_lookup_enum_by_nr(modeA
));
397 i830_set_blend_state(ctx
);
402 i830BlendFuncSeparate(struct gl_context
* ctx
, GLenum sfactorRGB
,
403 GLenum dfactorRGB
, GLenum sfactorA
, GLenum dfactorA
)
405 DBG("%s -> RGB(%s, %s) A(%s, %s)\n", __FUNCTION__
,
406 _mesa_lookup_enum_by_nr(sfactorRGB
),
407 _mesa_lookup_enum_by_nr(dfactorRGB
),
408 _mesa_lookup_enum_by_nr(sfactorA
),
409 _mesa_lookup_enum_by_nr(dfactorA
));
415 i830_set_blend_state(ctx
);
421 i830DepthFunc(struct gl_context
* ctx
, GLenum func
)
423 struct i830_context
*i830
= i830_context(ctx
);
424 int test
= intel_translate_compare_func(func
);
426 DBG("%s\n", __FUNCTION__
);
428 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
429 i830
->state
.Ctx
[I830_CTXREG_STATE3
] &= ~DEPTH_TEST_FUNC_MASK
;
430 i830
->state
.Ctx
[I830_CTXREG_STATE3
] |= (ENABLE_DEPTH_TEST_FUNC
|
431 DEPTH_TEST_FUNC(test
));
435 i830DepthMask(struct gl_context
* ctx
, GLboolean flag
)
437 struct i830_context
*i830
= i830_context(ctx
);
439 DBG("%s flag (%d)\n", __FUNCTION__
, flag
);
441 if (!ctx
->DrawBuffer
|| !ctx
->DrawBuffer
->Visual
.depthBits
)
444 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
446 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] &= ~ENABLE_DIS_DEPTH_WRITE_MASK
;
448 if (flag
&& ctx
->Depth
.Test
)
449 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= ENABLE_DEPTH_WRITE
;
451 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= DISABLE_DEPTH_WRITE
;
454 /** Called from ctx->Driver.Viewport() */
456 i830Viewport(struct gl_context
* ctx
,
457 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
459 intelCalcViewport(ctx
);
463 /** Called from ctx->Driver.DepthRange() */
465 i830DepthRange(struct gl_context
* ctx
, GLclampd nearval
, GLclampd farval
)
467 intelCalcViewport(ctx
);
470 /* =============================================================
473 * The i830 supports a 4x4 stipple natively, GL wants 32x32.
474 * Fortunately stipple is usually a repeating pattern.
477 i830PolygonStipple(struct gl_context
* ctx
, const GLubyte
* mask
)
479 struct i830_context
*i830
= i830_context(ctx
);
483 int active
= (ctx
->Polygon
.StippleFlag
&&
484 i830
->intel
.reduced_primitive
== GL_TRIANGLES
);
488 I830_STATECHANGE(i830
, I830_UPLOAD_STIPPLE
);
489 i830
->state
.Stipple
[I830_STPREG_ST1
] &= ~ST1_ENABLE
;
492 /* Use the already unpacked stipple data from the context rather than the
493 * uninterpreted mask passed in.
495 mask
= (const GLubyte
*)ctx
->PolygonStipple
;
498 p
[0] = mask
[12] & 0xf;
500 p
[1] = mask
[8] & 0xf;
502 p
[2] = mask
[4] & 0xf;
504 p
[3] = mask
[0] & 0xf;
507 for (k
= 0; k
< 8; k
++)
508 for (j
= 3; j
>= 0; j
--)
509 for (i
= 0; i
< 4; i
++, m
++)
511 i830
->intel
.hw_stipple
= 0;
515 newMask
= (((p
[0] & 0xf) << 0) |
516 ((p
[1] & 0xf) << 4) |
517 ((p
[2] & 0xf) << 8) | ((p
[3] & 0xf) << 12));
520 if (newMask
== 0xffff || newMask
== 0x0) {
521 /* this is needed to make conform pass */
522 i830
->intel
.hw_stipple
= 0;
526 i830
->state
.Stipple
[I830_STPREG_ST1
] &= ~0xffff;
527 i830
->state
.Stipple
[I830_STPREG_ST1
] |= newMask
;
528 i830
->intel
.hw_stipple
= 1;
531 i830
->state
.Stipple
[I830_STPREG_ST1
] |= ST1_ENABLE
;
535 /* =============================================================
539 i830Scissor(struct gl_context
* ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
541 struct i830_context
*i830
= i830_context(ctx
);
544 if (!ctx
->DrawBuffer
)
547 DBG("%s %d,%d %dx%d\n", __FUNCTION__
, x
, y
, w
, h
);
549 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
551 y1
= ctx
->DrawBuffer
->Height
- (y
+ h
);
554 DBG("%s %d..%d,%d..%d (inverted)\n", __FUNCTION__
, x1
, x2
, y1
, y2
);
557 /* FBO - not inverted
563 DBG("%s %d..%d,%d..%d (not inverted)\n", __FUNCTION__
, x1
, x2
, y1
, y2
);
566 x1
= CLAMP(x1
, 0, ctx
->DrawBuffer
->Width
- 1);
567 y1
= CLAMP(y1
, 0, ctx
->DrawBuffer
->Height
- 1);
568 x2
= CLAMP(x2
, 0, ctx
->DrawBuffer
->Width
- 1);
569 y2
= CLAMP(y2
, 0, ctx
->DrawBuffer
->Height
- 1);
571 DBG("%s %d..%d,%d..%d (clamped)\n", __FUNCTION__
, x1
, x2
, y1
, y2
);
573 I830_STATECHANGE(i830
, I830_UPLOAD_BUFFERS
);
574 i830
->state
.Buffer
[I830_DESTREG_SR1
] = (y1
<< 16) | (x1
& 0xffff);
575 i830
->state
.Buffer
[I830_DESTREG_SR2
] = (y2
<< 16) | (x2
& 0xffff);
579 i830LogicOp(struct gl_context
* ctx
, GLenum opcode
)
581 struct i830_context
*i830
= i830_context(ctx
);
582 int tmp
= intel_translate_logic_op(opcode
);
584 DBG("%s\n", __FUNCTION__
);
586 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
587 i830
->state
.Ctx
[I830_CTXREG_STATE4
] &= ~LOGICOP_MASK
;
588 i830
->state
.Ctx
[I830_CTXREG_STATE4
] |= LOGIC_OP_FUNC(tmp
);
594 i830CullFaceFrontFace(struct gl_context
* ctx
, GLenum unused
)
596 struct i830_context
*i830
= i830_context(ctx
);
599 DBG("%s\n", __FUNCTION__
);
601 if (!ctx
->Polygon
.CullFlag
) {
602 mode
= CULLMODE_NONE
;
604 else if (ctx
->Polygon
.CullFaceMode
!= GL_FRONT_AND_BACK
) {
607 if (ctx
->Polygon
.CullFaceMode
== GL_FRONT
)
608 mode
^= (CULLMODE_CW
^ CULLMODE_CCW
);
609 if (ctx
->Polygon
.FrontFace
!= GL_CCW
)
610 mode
^= (CULLMODE_CW
^ CULLMODE_CCW
);
613 mode
= CULLMODE_BOTH
;
616 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
617 i830
->state
.Ctx
[I830_CTXREG_STATE3
] &= ~CULLMODE_MASK
;
618 i830
->state
.Ctx
[I830_CTXREG_STATE3
] |= ENABLE_CULL_MODE
| mode
;
622 i830LineWidth(struct gl_context
* ctx
, GLfloat widthf
)
624 struct i830_context
*i830
= i830_context(ctx
);
628 DBG("%s\n", __FUNCTION__
);
630 width
= (int) (widthf
* 2);
631 width
= CLAMP(width
, 1, 15);
633 state5
= i830
->state
.Ctx
[I830_CTXREG_STATE5
] & ~FIXED_LINE_WIDTH_MASK
;
634 state5
|= (ENABLE_FIXED_LINE_WIDTH
| FIXED_LINE_WIDTH(width
));
636 if (state5
!= i830
->state
.Ctx
[I830_CTXREG_STATE5
]) {
637 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
638 i830
->state
.Ctx
[I830_CTXREG_STATE5
] = state5
;
643 i830PointSize(struct gl_context
* ctx
, GLfloat size
)
645 struct i830_context
*i830
= i830_context(ctx
);
646 GLint point_size
= (int) size
;
648 DBG("%s\n", __FUNCTION__
);
650 point_size
= CLAMP(point_size
, 1, 256);
651 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
652 i830
->state
.Ctx
[I830_CTXREG_STATE5
] &= ~FIXED_POINT_WIDTH_MASK
;
653 i830
->state
.Ctx
[I830_CTXREG_STATE5
] |= (ENABLE_FIXED_POINT_WIDTH
|
654 FIXED_POINT_WIDTH(point_size
));
658 /* =============================================================
663 i830ColorMask(struct gl_context
* ctx
,
664 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
666 struct i830_context
*i830
= i830_context(ctx
);
669 DBG("%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__
, r
, g
, b
, a
);
671 tmp
= ((i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] & ~WRITEMASK_MASK
) |
674 ((!r
) << WRITEMASK_RED_SHIFT
) |
675 ((!g
) << WRITEMASK_GREEN_SHIFT
) |
676 ((!b
) << WRITEMASK_BLUE_SHIFT
) | ((!a
) << WRITEMASK_ALPHA_SHIFT
));
678 if (tmp
!= i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
]) {
679 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
680 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] = tmp
;
685 update_specular(struct gl_context
* ctx
)
687 struct i830_context
*i830
= i830_context(ctx
);
689 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
690 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_SPEC_ADD_MASK
;
692 if (_mesa_need_secondary_color(ctx
))
693 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_SPEC_ADD
;
695 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_SPEC_ADD
;
699 i830LightModelfv(struct gl_context
* ctx
, GLenum pname
, const GLfloat
* param
)
701 DBG("%s\n", __FUNCTION__
);
703 if (pname
== GL_LIGHT_MODEL_COLOR_CONTROL
) {
704 update_specular(ctx
);
708 /* In Mesa 3.5 we can reliably do native flatshading.
711 i830ShadeModel(struct gl_context
* ctx
, GLenum mode
)
713 struct i830_context
*i830
= i830_context(ctx
);
714 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
717 #define SHADE_MODE_MASK ((1<<10)|(1<<8)|(1<<6)|(1<<4))
719 i830
->state
.Ctx
[I830_CTXREG_STATE3
] &= ~SHADE_MODE_MASK
;
721 if (mode
== GL_FLAT
) {
722 i830
->state
.Ctx
[I830_CTXREG_STATE3
] |=
723 (ALPHA_SHADE_MODE(SHADE_MODE_FLAT
) | FOG_SHADE_MODE(SHADE_MODE_FLAT
)
724 | SPEC_SHADE_MODE(SHADE_MODE_FLAT
) |
725 COLOR_SHADE_MODE(SHADE_MODE_FLAT
));
728 i830
->state
.Ctx
[I830_CTXREG_STATE3
] |=
729 (ALPHA_SHADE_MODE(SHADE_MODE_LINEAR
) |
730 FOG_SHADE_MODE(SHADE_MODE_LINEAR
) |
731 SPEC_SHADE_MODE(SHADE_MODE_LINEAR
) |
732 COLOR_SHADE_MODE(SHADE_MODE_LINEAR
));
736 /* =============================================================
740 i830Fogfv(struct gl_context
* ctx
, GLenum pname
, const GLfloat
* param
)
742 struct i830_context
*i830
= i830_context(ctx
);
744 DBG("%s\n", __FUNCTION__
);
746 if (pname
== GL_FOG_COLOR
) {
747 GLuint color
= (((GLubyte
) (ctx
->Fog
.Color
[0] * 255.0F
) << 16) |
748 ((GLubyte
) (ctx
->Fog
.Color
[1] * 255.0F
) << 8) |
749 ((GLubyte
) (ctx
->Fog
.Color
[2] * 255.0F
) << 0));
751 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
752 i830
->state
.Ctx
[I830_CTXREG_FOGCOLOR
] =
753 (_3DSTATE_FOG_COLOR_CMD
| color
);
757 /* =============================================================
761 i830Enable(struct gl_context
* ctx
, GLenum cap
, GLboolean state
)
763 struct i830_context
*i830
= i830_context(ctx
);
768 update_specular(ctx
);
772 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
773 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_DIS_ALPHA_TEST_MASK
;
775 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_ALPHA_TEST
;
777 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_ALPHA_TEST
;
782 i830EvalLogicOpBlendState(ctx
);
785 case GL_COLOR_LOGIC_OP
:
786 i830EvalLogicOpBlendState(ctx
);
788 /* Logicop doesn't seem to work at 16bpp:
790 if (i830
->intel
.ctx
.Visual
.rgbBits
== 16)
791 FALLBACK(&i830
->intel
, I830_FALLBACK_LOGICOP
, state
);
795 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
796 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] &= ~ENABLE_DITHER
;
799 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= ENABLE_DITHER
;
801 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= DISABLE_DITHER
;
805 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
806 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_DIS_DEPTH_TEST_MASK
;
808 if (!ctx
->DrawBuffer
|| !ctx
->DrawBuffer
->Visual
.depthBits
)
812 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_DEPTH_TEST
;
814 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_DEPTH_TEST
;
816 /* Also turn off depth writes when GL_DEPTH_TEST is disabled:
818 i830DepthMask(ctx
, ctx
->Depth
.Mask
);
821 case GL_SCISSOR_TEST
:
822 I830_STATECHANGE(i830
, I830_UPLOAD_BUFFERS
);
825 i830
->state
.Buffer
[I830_DESTREG_SENABLE
] =
826 (_3DSTATE_SCISSOR_ENABLE_CMD
| ENABLE_SCISSOR_RECT
);
828 i830
->state
.Buffer
[I830_DESTREG_SENABLE
] =
829 (_3DSTATE_SCISSOR_ENABLE_CMD
| DISABLE_SCISSOR_RECT
);
834 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
836 i830
->state
.Ctx
[I830_CTXREG_AA
] &= ~AA_LINE_ENABLE
;
838 i830
->state
.Ctx
[I830_CTXREG_AA
] |= AA_LINE_ENABLE
;
840 i830
->state
.Ctx
[I830_CTXREG_AA
] |= AA_LINE_DISABLE
;
844 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
845 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_DIS_FOG_MASK
;
847 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_FOG
;
849 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_FOG
;
853 i830CullFaceFrontFace(ctx
, 0);
859 case GL_STENCIL_TEST
:
861 bool hw_stencil
= false;
862 if (ctx
->DrawBuffer
) {
863 struct intel_renderbuffer
*irbStencil
864 = intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_STENCIL
);
865 hw_stencil
= (irbStencil
&& irbStencil
->mt
);
868 I830_STATECHANGE(i830
, I830_UPLOAD_CTX
);
871 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= ENABLE_STENCIL_TEST
;
872 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |= ENABLE_STENCIL_WRITE
;
875 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] &= ~ENABLE_STENCIL_TEST
;
876 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] &=
877 ~ENABLE_STENCIL_WRITE
;
878 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] |= DISABLE_STENCIL_TEST
;
879 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] |=
880 DISABLE_STENCIL_WRITE
;
884 FALLBACK(&i830
->intel
, I830_FALLBACK_STENCIL
, state
);
889 case GL_POLYGON_STIPPLE
:
890 /* The stipple command worked on my 855GM box, but not my 845G.
891 * I'll do more testing later to find out exactly which hardware
892 * supports it. Disabled for now.
894 if (i830
->intel
.hw_stipple
&&
895 i830
->intel
.reduced_primitive
== GL_TRIANGLES
) {
896 I830_STATECHANGE(i830
, I830_UPLOAD_STIPPLE
);
897 i830
->state
.Stipple
[I830_STPREG_ST1
] &= ~ST1_ENABLE
;
899 i830
->state
.Stipple
[I830_STPREG_ST1
] |= ST1_ENABLE
;
910 i830_init_packets(struct i830_context
*i830
)
913 memset(&i830
->state
, 0, sizeof(i830
->state
));
915 /* Set default blend state */
916 i830
->state
.TexBlend
[0][0] = (_3DSTATE_MAP_BLEND_OP_CMD(0) |
918 ENABLE_TEXOUTPUT_WRT_SEL
|
919 TEXOP_OUTPUT_CURRENT
|
920 DISABLE_TEX_CNTRL_STAGE
|
923 TEXOP_LAST_STAGE
| TEXBLENDOP_ARG1
);
924 i830
->state
.TexBlend
[0][1] = (_3DSTATE_MAP_BLEND_OP_CMD(0) |
926 ENABLE_TEXOUTPUT_WRT_SEL
|
927 TEXOP_OUTPUT_CURRENT
|
929 TEXOP_MODIFY_PARMS
| TEXBLENDOP_ARG1
);
930 i830
->state
.TexBlend
[0][2] = (_3DSTATE_MAP_BLEND_ARG_CMD(0) |
933 TEXBLENDARG_MODIFY_PARMS
|
934 TEXBLENDARG_DIFFUSE
);
935 i830
->state
.TexBlend
[0][3] = (_3DSTATE_MAP_BLEND_ARG_CMD(0) |
938 TEXBLENDARG_MODIFY_PARMS
|
939 TEXBLENDARG_DIFFUSE
);
941 i830
->state
.TexBlendWordsUsed
[0] = 4;
944 i830
->state
.Ctx
[I830_CTXREG_VF
] = 0;
945 i830
->state
.Ctx
[I830_CTXREG_VF2
] = 0;
947 i830
->state
.Ctx
[I830_CTXREG_AA
] = (_3DSTATE_AA_CMD
|
948 AA_LINE_ECAAR_WIDTH_ENABLE
|
949 AA_LINE_ECAAR_WIDTH_1_0
|
950 AA_LINE_REGION_WIDTH_ENABLE
|
951 AA_LINE_REGION_WIDTH_1_0
|
954 i830
->state
.Ctx
[I830_CTXREG_ENABLES_1
] = (_3DSTATE_ENABLES_1_CMD
|
956 DISABLE_STENCIL_TEST
|
961 DISABLE_COLOR_BLEND
|
964 #if 000 /* XXX all the stencil enable state is set in i830Enable(), right? */
965 if (i830
->intel
.hw_stencil
) {
966 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] = (_3DSTATE_ENABLES_2_CMD
|
967 ENABLE_STENCIL_WRITE
|
971 /* set no color comps disabled */
978 i830
->state
.Ctx
[I830_CTXREG_ENABLES_2
] = (_3DSTATE_ENABLES_2_CMD
|
979 DISABLE_STENCIL_WRITE
|
983 /* set no color comps disabled */
988 i830
->state
.Ctx
[I830_CTXREG_STATE1
] = (_3DSTATE_MODES_1_CMD
|
989 ENABLE_COLR_BLND_FUNC
|
991 ENABLE_SRC_BLND_FACTOR
|
992 SRC_BLND_FACT(BLENDFACT_ONE
) |
993 ENABLE_DST_BLND_FACTOR
|
994 DST_BLND_FACT(BLENDFACT_ZERO
));
996 i830
->state
.Ctx
[I830_CTXREG_STATE2
] = (_3DSTATE_MODES_2_CMD
|
997 ENABLE_GLOBAL_DEPTH_BIAS
|
998 GLOBAL_DEPTH_BIAS(0) |
999 ENABLE_ALPHA_TEST_FUNC
|
1000 ALPHA_TEST_FUNC(COMPAREFUNC_ALWAYS
)
1001 | ALPHA_REF_VALUE(0));
1003 i830
->state
.Ctx
[I830_CTXREG_STATE3
] = (_3DSTATE_MODES_3_CMD
|
1004 ENABLE_DEPTH_TEST_FUNC
|
1005 DEPTH_TEST_FUNC(COMPAREFUNC_LESS
) |
1006 ENABLE_ALPHA_SHADE_MODE
|
1007 ALPHA_SHADE_MODE(SHADE_MODE_LINEAR
)
1008 | ENABLE_FOG_SHADE_MODE
|
1009 FOG_SHADE_MODE(SHADE_MODE_LINEAR
) |
1010 ENABLE_SPEC_SHADE_MODE
|
1011 SPEC_SHADE_MODE(SHADE_MODE_LINEAR
) |
1012 ENABLE_COLOR_SHADE_MODE
|
1013 COLOR_SHADE_MODE(SHADE_MODE_LINEAR
)
1014 | ENABLE_CULL_MODE
| CULLMODE_NONE
);
1016 i830
->state
.Ctx
[I830_CTXREG_STATE4
] = (_3DSTATE_MODES_4_CMD
|
1017 ENABLE_LOGIC_OP_FUNC
|
1018 LOGIC_OP_FUNC(LOGICOP_COPY
) |
1019 ENABLE_STENCIL_TEST_MASK
|
1020 STENCIL_TEST_MASK(0xff) |
1021 ENABLE_STENCIL_WRITE_MASK
|
1022 STENCIL_WRITE_MASK(0xff));
1024 i830
->state
.Ctx
[I830_CTXREG_STENCILTST
] = (_3DSTATE_STENCIL_TEST_CMD
|
1025 ENABLE_STENCIL_PARMS
|
1026 STENCIL_FAIL_OP(STENCILOP_KEEP
)
1028 STENCIL_PASS_DEPTH_FAIL_OP
1030 STENCIL_PASS_DEPTH_PASS_OP
1032 ENABLE_STENCIL_TEST_FUNC
|
1034 (COMPAREFUNC_ALWAYS
) |
1035 ENABLE_STENCIL_REF_VALUE
|
1036 STENCIL_REF_VALUE(0));
1038 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 */
1039 ENABLE_FIXED_POINT_WIDTH
|
1040 FIXED_POINT_WIDTH(1));
1042 i830
->state
.Ctx
[I830_CTXREG_IALPHAB
] = (_3DSTATE_INDPT_ALPHA_BLEND_CMD
|
1043 DISABLE_INDPT_ALPHA_BLEND
|
1044 ENABLE_ALPHA_BLENDFUNC
|
1047 i830
->state
.Ctx
[I830_CTXREG_FOGCOLOR
] = (_3DSTATE_FOG_COLOR_CMD
|
1049 FOG_COLOR_GREEN(0) |
1052 i830
->state
.Ctx
[I830_CTXREG_BLENDCOLOR0
] = _3DSTATE_CONST_BLEND_COLOR_CMD
;
1053 i830
->state
.Ctx
[I830_CTXREG_BLENDCOLOR1
] = 0;
1055 i830
->state
.Ctx
[I830_CTXREG_MCSB0
] = _3DSTATE_MAP_COORD_SETBIND_CMD
;
1056 i830
->state
.Ctx
[I830_CTXREG_MCSB1
] = (TEXBIND_SET3(TEXCOORDSRC_VTXSET_3
) |
1057 TEXBIND_SET2(TEXCOORDSRC_VTXSET_2
) |
1058 TEXBIND_SET1(TEXCOORDSRC_VTXSET_1
) |
1059 TEXBIND_SET0(TEXCOORDSRC_VTXSET_0
));
1061 i830
->state
.RasterRules
[I830_RASTER_RULES
] = (_3DSTATE_RASTER_RULES_CMD
|
1062 ENABLE_POINT_RASTER_RULE
|
1063 OGL_POINT_RASTER_RULE
|
1064 ENABLE_LINE_STRIP_PROVOKE_VRTX
|
1065 ENABLE_TRI_FAN_PROVOKE_VRTX
|
1066 ENABLE_TRI_STRIP_PROVOKE_VRTX
|
1067 LINE_STRIP_PROVOKE_VRTX(1) |
1068 TRI_FAN_PROVOKE_VRTX(2) |
1069 TRI_STRIP_PROVOKE_VRTX(2));
1072 i830
->state
.Stipple
[I830_STPREG_ST0
] = _3DSTATE_STIPPLE
;
1074 i830
->state
.Buffer
[I830_DESTREG_DV0
] = _3DSTATE_DST_BUF_VARS_CMD
;
1075 i830
->state
.Buffer
[I830_DESTREG_SENABLE
] = (_3DSTATE_SCISSOR_ENABLE_CMD
|
1076 DISABLE_SCISSOR_RECT
);
1077 i830
->state
.Buffer
[I830_DESTREG_SR0
] = _3DSTATE_SCISSOR_RECT_0_CMD
;
1078 i830
->state
.Buffer
[I830_DESTREG_SR1
] = 0;
1079 i830
->state
.Buffer
[I830_DESTREG_SR2
] = 0;
1083 i830_update_provoking_vertex(struct gl_context
* ctx
)
1085 struct i830_context
*i830
= i830_context(ctx
);
1087 I830_STATECHANGE(i830
, I830_UPLOAD_RASTER_RULES
);
1088 i830
->state
.RasterRules
[I830_RASTER_RULES
] &= ~(LINE_STRIP_PROVOKE_VRTX_MASK
|
1089 TRI_FAN_PROVOKE_VRTX_MASK
|
1090 TRI_STRIP_PROVOKE_VRTX_MASK
);
1093 if (ctx
->Light
.ProvokingVertex
== GL_LAST_VERTEX_CONVENTION
) {
1094 i830
->state
.RasterRules
[I830_RASTER_RULES
] |= (LINE_STRIP_PROVOKE_VRTX(1) |
1095 TRI_FAN_PROVOKE_VRTX(2) |
1096 TRI_STRIP_PROVOKE_VRTX(2));
1098 i830
->state
.RasterRules
[I830_RASTER_RULES
] |= (LINE_STRIP_PROVOKE_VRTX(0) |
1099 TRI_FAN_PROVOKE_VRTX(1) |
1100 TRI_STRIP_PROVOKE_VRTX(0));
1104 /* Fallback to swrast for select and feedback.
1107 i830RenderMode(struct gl_context
*ctx
, GLenum mode
)
1109 struct intel_context
*intel
= intel_context(ctx
);
1110 FALLBACK(intel
, INTEL_FALLBACK_RENDERMODE
, (mode
!= GL_RENDER
));
1114 i830InitStateFuncs(struct dd_function_table
*functions
)
1116 functions
->AlphaFunc
= i830AlphaFunc
;
1117 functions
->BlendColor
= i830BlendColor
;
1118 functions
->BlendEquationSeparate
= i830BlendEquationSeparate
;
1119 functions
->BlendFuncSeparate
= i830BlendFuncSeparate
;
1120 functions
->ColorMask
= i830ColorMask
;
1121 functions
->CullFace
= i830CullFaceFrontFace
;
1122 functions
->DepthFunc
= i830DepthFunc
;
1123 functions
->DepthMask
= i830DepthMask
;
1124 functions
->Enable
= i830Enable
;
1125 functions
->Fogfv
= i830Fogfv
;
1126 functions
->FrontFace
= i830CullFaceFrontFace
;
1127 functions
->LightModelfv
= i830LightModelfv
;
1128 functions
->LineWidth
= i830LineWidth
;
1129 functions
->LogicOpcode
= i830LogicOp
;
1130 functions
->PointSize
= i830PointSize
;
1131 functions
->PolygonStipple
= i830PolygonStipple
;
1132 functions
->RenderMode
= i830RenderMode
;
1133 functions
->Scissor
= i830Scissor
;
1134 functions
->ShadeModel
= i830ShadeModel
;
1135 functions
->StencilFuncSeparate
= i830StencilFuncSeparate
;
1136 functions
->StencilMaskSeparate
= i830StencilMaskSeparate
;
1137 functions
->StencilOpSeparate
= i830StencilOpSeparate
;
1138 functions
->DepthRange
= i830DepthRange
;
1139 functions
->Viewport
= i830Viewport
;
1143 i830InitState(struct i830_context
*i830
)
1145 struct gl_context
*ctx
= &i830
->intel
.ctx
;
1147 i830_init_packets(i830
);
1149 _mesa_init_driver_state(ctx
);
1151 i830
->state
.emitted
= 0;
1152 i830
->state
.active
= (I830_UPLOAD_INVARIENT
|
1153 I830_UPLOAD_RASTER_RULES
|
1154 I830_UPLOAD_TEXBLEND(0) |
1155 I830_UPLOAD_STIPPLE
|
1156 I830_UPLOAD_CTX
| I830_UPLOAD_BUFFERS
);