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 **************************************************************************/
35 #include "tnl/t_context.h"
39 #include "intel_screen.h"
40 #include "intel_batchbuffer.h"
42 #include "i915_context.h"
48 i915StencilFuncSeparate(GLcontext
*ctx
, GLenum face
, GLenum func
, GLint ref
,
51 i915ContextPtr i915
= I915_CONTEXT(ctx
);
52 int test
= intel_translate_compare_func( func
);
56 if (INTEL_DEBUG
&DEBUG_DRI
)
57 fprintf(stderr
, "%s : func: %s, ref : 0x%x, mask: 0x%x\n", __FUNCTION__
,
58 _mesa_lookup_enum_by_nr(func
), ref
, mask
);
61 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
62 i915
->state
.Ctx
[I915_CTXREG_STATE4
] &= ~MODE4_ENABLE_STENCIL_TEST_MASK
;
63 i915
->state
.Ctx
[I915_CTXREG_STATE4
] |= (ENABLE_STENCIL_TEST_MASK
|
64 STENCIL_TEST_MASK(mask
));
66 i915
->state
.Ctx
[I915_CTXREG_LIS5
] &= ~(S5_STENCIL_REF_MASK
|
67 S5_STENCIL_TEST_FUNC_MASK
);
69 i915
->state
.Ctx
[I915_CTXREG_LIS5
] |= ((ref
<< S5_STENCIL_REF_SHIFT
) |
70 (test
<< S5_STENCIL_TEST_FUNC_SHIFT
));
74 i915StencilMaskSeparate(GLcontext
*ctx
, GLenum face
, GLuint mask
)
76 i915ContextPtr i915
= I915_CONTEXT(ctx
);
78 if (INTEL_DEBUG
&DEBUG_DRI
)
79 fprintf(stderr
, "%s : mask 0x%x\n", __FUNCTION__
, mask
);
83 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
84 i915
->state
.Ctx
[I915_CTXREG_STATE4
] &= ~MODE4_ENABLE_STENCIL_WRITE_MASK
;
85 i915
->state
.Ctx
[I915_CTXREG_STATE4
] |= (ENABLE_STENCIL_WRITE_MASK
|
86 STENCIL_WRITE_MASK(mask
));
91 i915StencilOpSeparate(GLcontext
*ctx
, GLenum face
, GLenum fail
, GLenum zfail
,
94 i915ContextPtr i915
= I915_CONTEXT(ctx
);
95 int fop
= intel_translate_stencil_op(fail
);
96 int dfop
= intel_translate_stencil_op(zfail
);
97 int dpop
= intel_translate_stencil_op(zpass
);
100 if (INTEL_DEBUG
&DEBUG_DRI
)
101 fprintf(stderr
, "%s: fail : %s, zfail: %s, zpass : %s\n", __FUNCTION__
,
102 _mesa_lookup_enum_by_nr(fail
),
103 _mesa_lookup_enum_by_nr(zfail
),
104 _mesa_lookup_enum_by_nr(zpass
));
106 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
108 i915
->state
.Ctx
[I915_CTXREG_LIS5
] &= ~(S5_STENCIL_FAIL_MASK
|
109 S5_STENCIL_PASS_Z_FAIL_MASK
|
110 S5_STENCIL_PASS_Z_PASS_MASK
);
112 i915
->state
.Ctx
[I915_CTXREG_LIS5
] |= ((fop
<< S5_STENCIL_FAIL_SHIFT
) |
113 (dfop
<< S5_STENCIL_PASS_Z_FAIL_SHIFT
) |
114 (dpop
<< S5_STENCIL_PASS_Z_PASS_SHIFT
));
117 static void i915AlphaFunc(GLcontext
*ctx
, GLenum func
, GLfloat ref
)
119 i915ContextPtr i915
= I915_CONTEXT(ctx
);
120 int test
= intel_translate_compare_func( func
);
123 UNCLAMPED_FLOAT_TO_UBYTE(refByte
, ref
);
125 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
126 i915
->state
.Ctx
[I915_CTXREG_LIS6
] &= ~(S6_ALPHA_TEST_FUNC_MASK
|
128 i915
->state
.Ctx
[I915_CTXREG_LIS6
] |= ((test
<< S6_ALPHA_TEST_FUNC_SHIFT
) |
129 (((GLuint
)refByte
) << S6_ALPHA_REF_SHIFT
));
132 /* This function makes sure that the proper enables are
133 * set for LogicOp, Independant Alpha Blend, and Blending.
134 * It needs to be called from numerous places where we
135 * could change the LogicOp or Independant Alpha Blend without subsequent
138 static void i915EvalLogicOpBlendState(GLcontext
*ctx
)
140 i915ContextPtr i915
= I915_CONTEXT(ctx
);
142 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
144 if (ctx
->Color
._LogicOpEnabled
) {
145 i915
->state
.Ctx
[I915_CTXREG_LIS5
] |= S5_LOGICOP_ENABLE
;
146 i915
->state
.Ctx
[I915_CTXREG_LIS6
] &= ~S6_CBUF_BLEND_ENABLE
;
148 i915
->state
.Ctx
[I915_CTXREG_LIS5
] &= ~S5_LOGICOP_ENABLE
;
150 if (ctx
->Color
.BlendEnabled
) {
151 i915
->state
.Ctx
[I915_CTXREG_LIS6
] |= S6_CBUF_BLEND_ENABLE
;
153 i915
->state
.Ctx
[I915_CTXREG_LIS6
] &= ~S6_CBUF_BLEND_ENABLE
;
158 static void i915BlendColor(GLcontext
*ctx
, const GLfloat color
[4])
160 i915ContextPtr i915
= I915_CONTEXT(ctx
);
163 if (INTEL_DEBUG
&DEBUG_DRI
)
164 fprintf(stderr
, "%s\n", __FUNCTION__
);
166 UNCLAMPED_FLOAT_TO_UBYTE(r
, color
[RCOMP
]);
167 UNCLAMPED_FLOAT_TO_UBYTE(g
, color
[GCOMP
]);
168 UNCLAMPED_FLOAT_TO_UBYTE(b
, color
[BCOMP
]);
169 UNCLAMPED_FLOAT_TO_UBYTE(a
, color
[ACOMP
]);
171 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
172 i915
->state
.Ctx
[I915_CTXREG_BLENDCOLOR1
] = (a
<<24) | (r
<<16) | (g
<<8) | b
;
176 #define DST_BLND_FACT(f) ((f)<<S6_CBUF_DST_BLEND_FACT_SHIFT)
177 #define SRC_BLND_FACT(f) ((f)<<S6_CBUF_SRC_BLEND_FACT_SHIFT)
178 #define DST_ABLND_FACT(f) ((f)<<IAB_DST_FACTOR_SHIFT)
179 #define SRC_ABLND_FACT(f) ((f)<<IAB_SRC_FACTOR_SHIFT)
183 static GLuint
translate_blend_equation( GLenum mode
)
186 case GL_FUNC_ADD
: return BLENDFUNC_ADD
;
187 case GL_MIN
: return BLENDFUNC_MIN
;
188 case GL_MAX
: return BLENDFUNC_MAX
;
189 case GL_FUNC_SUBTRACT
: return BLENDFUNC_SUBTRACT
;
190 case GL_FUNC_REVERSE_SUBTRACT
: return BLENDFUNC_REVERSE_SUBTRACT
;
195 static void i915UpdateBlendState( GLcontext
*ctx
)
197 i915ContextPtr i915
= I915_CONTEXT(ctx
);
198 GLuint iab
= (i915
->state
.Ctx
[I915_CTXREG_IAB
] &
199 ~(IAB_SRC_FACTOR_MASK
|
200 IAB_DST_FACTOR_MASK
|
201 (BLENDFUNC_MASK
<< IAB_FUNC_SHIFT
) |
204 GLuint lis6
= (i915
->state
.Ctx
[I915_CTXREG_LIS6
] &
205 ~(S6_CBUF_SRC_BLEND_FACT_MASK
|
206 S6_CBUF_DST_BLEND_FACT_MASK
|
207 S6_CBUF_BLEND_FUNC_MASK
));
209 GLuint eqRGB
= ctx
->Color
.BlendEquationRGB
;
210 GLuint eqA
= ctx
->Color
.BlendEquationA
;
211 GLuint srcRGB
= ctx
->Color
.BlendSrcRGB
;
212 GLuint dstRGB
= ctx
->Color
.BlendDstRGB
;
213 GLuint srcA
= ctx
->Color
.BlendSrcA
;
214 GLuint dstA
= ctx
->Color
.BlendDstA
;
216 if (eqRGB
== GL_MIN
|| eqRGB
== GL_MAX
) {
217 srcRGB
= dstRGB
= GL_ONE
;
220 if (eqA
== GL_MIN
|| eqA
== GL_MAX
) {
221 srcA
= dstA
= GL_ONE
;
224 lis6
|= SRC_BLND_FACT(intel_translate_blend_factor(srcRGB
));
225 lis6
|= DST_BLND_FACT(intel_translate_blend_factor(dstRGB
));
226 lis6
|= translate_blend_equation( eqRGB
) << S6_CBUF_BLEND_FUNC_SHIFT
;
228 iab
|= SRC_ABLND_FACT(intel_translate_blend_factor(srcA
));
229 iab
|= DST_ABLND_FACT(intel_translate_blend_factor(dstA
));
230 iab
|= translate_blend_equation( eqA
) << IAB_FUNC_SHIFT
;
232 if (srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
)
235 if (iab
!= i915
->state
.Ctx
[I915_CTXREG_IAB
] ||
236 lis6
!= i915
->state
.Ctx
[I915_CTXREG_LIS6
]) {
237 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
238 i915
->state
.Ctx
[I915_CTXREG_IAB
] = iab
;
239 i915
->state
.Ctx
[I915_CTXREG_LIS6
] = lis6
;
242 /* This will catch a logicop blend equation */
243 i915EvalLogicOpBlendState(ctx
);
247 static void i915BlendFuncSeparate(GLcontext
*ctx
, GLenum srcRGB
,
248 GLenum dstRGB
, GLenum srcA
,
251 i915UpdateBlendState( ctx
);
255 static void i915BlendEquationSeparate(GLcontext
*ctx
, GLenum eqRGB
,
258 i915UpdateBlendState( ctx
);
262 static void i915DepthFunc(GLcontext
*ctx
, GLenum func
)
264 i915ContextPtr i915
= I915_CONTEXT(ctx
);
265 int test
= intel_translate_compare_func( func
);
267 if (INTEL_DEBUG
&DEBUG_DRI
)
268 fprintf(stderr
, "%s\n", __FUNCTION__
);
270 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
271 i915
->state
.Ctx
[I915_CTXREG_LIS6
] &= ~S6_DEPTH_TEST_FUNC_MASK
;
272 i915
->state
.Ctx
[I915_CTXREG_LIS6
] |= test
<< S6_DEPTH_TEST_FUNC_SHIFT
;
275 static void i915DepthMask(GLcontext
*ctx
, GLboolean flag
)
277 i915ContextPtr i915
= I915_CONTEXT(ctx
);
279 if (INTEL_DEBUG
&DEBUG_DRI
)
280 fprintf(stderr
, "%s flag (%d)\n", __FUNCTION__
, flag
);
282 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
284 if (flag
&& ctx
->Depth
.Test
)
285 i915
->state
.Ctx
[I915_CTXREG_LIS6
] |= S6_DEPTH_WRITE_ENABLE
;
287 i915
->state
.Ctx
[I915_CTXREG_LIS6
] &= ~S6_DEPTH_WRITE_ENABLE
;
290 /* =============================================================
293 * The i915 supports a 4x4 stipple natively, GL wants 32x32.
294 * Fortunately stipple is usually a repeating pattern.
296 static void i915PolygonStipple( GLcontext
*ctx
, const GLubyte
*mask
)
298 i915ContextPtr i915
= I915_CONTEXT(ctx
);
299 const GLubyte
*m
= mask
;
302 int active
= (ctx
->Polygon
.StippleFlag
&&
303 i915
->intel
.reduced_primitive
== GL_TRIANGLES
);
307 I915_STATECHANGE(i915
, I915_UPLOAD_STIPPLE
);
308 i915
->state
.Stipple
[I915_STPREG_ST1
] &= ~ST1_ENABLE
;
311 p
[0] = mask
[12] & 0xf; p
[0] |= p
[0] << 4;
312 p
[1] = mask
[8] & 0xf; p
[1] |= p
[1] << 4;
313 p
[2] = mask
[4] & 0xf; p
[2] |= p
[2] << 4;
314 p
[3] = mask
[0] & 0xf; p
[3] |= p
[3] << 4;
316 for (k
= 0 ; k
< 8 ; k
++)
317 for (j
= 3 ; j
>= 0; j
--)
318 for (i
= 0 ; i
< 4 ; i
++, m
++)
320 i915
->intel
.hw_stipple
= 0;
324 newMask
= (((p
[0] & 0xf) << 0) |
325 ((p
[1] & 0xf) << 4) |
326 ((p
[2] & 0xf) << 8) |
327 ((p
[3] & 0xf) << 12));
330 if (newMask
== 0xffff || newMask
== 0x0) {
331 /* this is needed to make conform pass */
332 i915
->intel
.hw_stipple
= 0;
336 i915
->state
.Stipple
[I915_STPREG_ST1
] &= ~0xffff;
337 i915
->state
.Stipple
[I915_STPREG_ST1
] |= newMask
;
338 i915
->intel
.hw_stipple
= 1;
341 i915
->state
.Stipple
[I915_STPREG_ST1
] |= ST1_ENABLE
;
345 /* =============================================================
348 static void i915Scissor(GLcontext
*ctx
, GLint x
, GLint y
,
349 GLsizei w
, GLsizei h
)
351 i915ContextPtr i915
= I915_CONTEXT(ctx
);
352 intelScreenPrivate
*screen
= i915
->intel
.intelScreen
;
355 if (!i915
->intel
.driDrawable
)
359 y1
= i915
->intel
.driDrawable
->h
- (y
+ h
);
363 if (INTEL_DEBUG
&DEBUG_DRI
)
364 fprintf(stderr
, "[%s] x(%d) y(%d) w(%d) h(%d)\n", __FUNCTION__
,
372 if (x2
>= screen
->width
) x2
= screen
->width
-1;
373 if (y2
>= screen
->height
) y2
= screen
->height
-1;
374 if (x1
>= screen
->width
) x1
= screen
->width
-1;
375 if (y1
>= screen
->height
) y1
= screen
->height
-1;
378 I915_STATECHANGE(i915
, I915_UPLOAD_BUFFERS
);
379 i915
->state
.Buffer
[I915_DESTREG_SR1
] = (y1
<< 16) | (x1
& 0xffff);
380 i915
->state
.Buffer
[I915_DESTREG_SR2
] = (y2
<< 16) | (x2
& 0xffff);
383 static void i915LogicOp(GLcontext
*ctx
, GLenum opcode
)
385 i915ContextPtr i915
= I915_CONTEXT(ctx
);
386 int tmp
= intel_translate_logic_op(opcode
);
388 if (INTEL_DEBUG
&DEBUG_DRI
)
389 fprintf(stderr
, "%s\n", __FUNCTION__
);
391 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
392 i915
->state
.Ctx
[I915_CTXREG_STATE4
] &= ~LOGICOP_MASK
;
393 i915
->state
.Ctx
[I915_CTXREG_STATE4
] |= LOGIC_OP_FUNC(tmp
);
398 static void i915CullFaceFrontFace(GLcontext
*ctx
, GLenum unused
)
400 i915ContextPtr i915
= I915_CONTEXT(ctx
);
403 if (INTEL_DEBUG
&DEBUG_DRI
)
404 fprintf(stderr
, "%s\n", __FUNCTION__
);
406 if (!ctx
->Polygon
.CullFlag
) {
407 mode
= S4_CULLMODE_NONE
;
409 else if (ctx
->Polygon
.CullFaceMode
!= GL_FRONT_AND_BACK
) {
410 mode
= S4_CULLMODE_CW
;
412 if (ctx
->Polygon
.CullFaceMode
== GL_FRONT
)
413 mode
^= (S4_CULLMODE_CW
^ S4_CULLMODE_CCW
);
414 if (ctx
->Polygon
.FrontFace
!= GL_CCW
)
415 mode
^= (S4_CULLMODE_CW
^ S4_CULLMODE_CCW
);
418 mode
= S4_CULLMODE_BOTH
;
421 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
422 i915
->state
.Ctx
[I915_CTXREG_LIS4
] &= ~S4_CULLMODE_MASK
;
423 i915
->state
.Ctx
[I915_CTXREG_LIS4
] |= mode
;
426 static void i915LineWidth( GLcontext
*ctx
, GLfloat widthf
)
428 i915ContextPtr i915
= I915_CONTEXT( ctx
);
429 int lis4
= i915
->state
.Ctx
[I915_CTXREG_LIS4
] & ~S4_LINE_WIDTH_MASK
;
432 if (INTEL_DEBUG
&DEBUG_DRI
)
433 fprintf(stderr
, "%s\n", __FUNCTION__
);
435 width
= (int)(widthf
* 2);
436 CLAMP_SELF(width
, 1, 0xf);
437 lis4
|= width
<< S4_LINE_WIDTH_SHIFT
;
439 if (lis4
!= i915
->state
.Ctx
[I915_CTXREG_LIS4
]) {
440 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
441 i915
->state
.Ctx
[I915_CTXREG_LIS4
] = lis4
;
445 static void i915PointSize(GLcontext
*ctx
, GLfloat size
)
447 i915ContextPtr i915
= I915_CONTEXT(ctx
);
448 int lis4
= i915
->state
.Ctx
[I915_CTXREG_LIS4
] & ~S4_POINT_WIDTH_MASK
;
449 GLint point_size
= (int)size
;
451 if (INTEL_DEBUG
&DEBUG_DRI
)
452 fprintf(stderr
, "%s\n", __FUNCTION__
);
454 CLAMP_SELF(point_size
, 1, 255);
455 lis4
|= point_size
<< S4_POINT_WIDTH_SHIFT
;
457 if (lis4
!= i915
->state
.Ctx
[I915_CTXREG_LIS4
]) {
458 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
459 i915
->state
.Ctx
[I915_CTXREG_LIS4
] = lis4
;
464 /* =============================================================
468 static void i915ColorMask(GLcontext
*ctx
,
469 GLboolean r
, GLboolean g
,
470 GLboolean b
, GLboolean a
)
472 i915ContextPtr i915
= I915_CONTEXT( ctx
);
473 GLuint tmp
= i915
->state
.Ctx
[I915_CTXREG_LIS5
] & ~S5_WRITEDISABLE_MASK
;
475 if (INTEL_DEBUG
&DEBUG_DRI
)
476 fprintf(stderr
, "%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__
, r
, g
, b
, a
);
478 if (!r
) tmp
|= S5_WRITEDISABLE_RED
;
479 if (!g
) tmp
|= S5_WRITEDISABLE_GREEN
;
480 if (!b
) tmp
|= S5_WRITEDISABLE_BLUE
;
481 if (!a
) tmp
|= S5_WRITEDISABLE_ALPHA
;
483 if (tmp
!= i915
->state
.Ctx
[I915_CTXREG_LIS5
]) {
484 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
485 i915
->state
.Ctx
[I915_CTXREG_LIS5
] = tmp
;
489 static void update_specular( GLcontext
*ctx
)
491 /* A hack to trigger the rebuild of the fragment program.
493 INTEL_CONTEXT(ctx
)->NewGLState
|= _NEW_TEXTURE
;
494 I915_CONTEXT(ctx
)->tex_program
.translated
= 0;
497 static void i915LightModelfv(GLcontext
*ctx
, GLenum pname
,
498 const GLfloat
*param
)
500 if (INTEL_DEBUG
&DEBUG_DRI
)
501 fprintf(stderr
, "%s\n", __FUNCTION__
);
503 if (pname
== GL_LIGHT_MODEL_COLOR_CONTROL
) {
504 update_specular( ctx
);
508 static void i915ShadeModel(GLcontext
*ctx
, GLenum mode
)
510 i915ContextPtr i915
= I915_CONTEXT(ctx
);
511 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
513 if (mode
== GL_SMOOTH
) {
514 i915
->state
.Ctx
[I915_CTXREG_LIS4
] &= ~(S4_FLATSHADE_ALPHA
|
516 S4_FLATSHADE_SPECULAR
);
518 i915
->state
.Ctx
[I915_CTXREG_LIS4
] |= (S4_FLATSHADE_ALPHA
|
520 S4_FLATSHADE_SPECULAR
);
524 /* =============================================================
527 void i915_update_fog( GLcontext
*ctx
)
529 i915ContextPtr i915
= I915_CONTEXT(ctx
);
532 GLboolean try_pixel_fog
;
534 if (ctx
->FragmentProgram
._Active
) {
535 /* Pull in static fog state from program */
537 mode
= ctx
->FragmentProgram
._Current
->FogOption
;
538 enabled
= (mode
!= GL_NONE
);
542 enabled
= ctx
->Fog
.Enabled
;
543 mode
= ctx
->Fog
.Mode
;
545 try_pixel_fog
= (ctx
->Fog
.FogCoordinateSource
== GL_FRAGMENT_DEPTH_EXT
&&
546 ctx
->Hint
.Fog
== GL_NICEST
&&
547 0); /* XXX - DISABLE -- Need ortho fallback */
551 i915
->vertex_fog
= I915_FOG_NONE
;
553 else if (try_pixel_fog
) {
555 I915_STATECHANGE(i915
, I915_UPLOAD_FOG
);
556 i915
->state
.Fog
[I915_FOGREG_MODE1
] &= ~FMC1_FOGFUNC_MASK
;
557 i915
->vertex_fog
= I915_FOG_PIXEL
;
561 if (ctx
->Fog
.End
<= ctx
->Fog
.Start
) {
562 /* XXX - this won't work with fragment programs. Need to
563 * either fallback or append fog instructions to end of
564 * program in the case of linear fog.
566 i915
->state
.Fog
[I915_FOGREG_MODE1
] |= FMC1_FOGFUNC_VERTEX
;
567 i915
->vertex_fog
= I915_FOG_VERTEX
;
570 GLfloat c1
= ctx
->Fog
.End
/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
571 GLfloat c2
= 1.0/(ctx
->Fog
.End
-ctx
->Fog
.Start
);
573 i915
->state
.Fog
[I915_FOGREG_MODE1
] &= ~FMC1_C1_MASK
;
574 i915
->state
.Fog
[I915_FOGREG_MODE1
] |= FMC1_FOGFUNC_PIXEL_LINEAR
;
575 i915
->state
.Fog
[I915_FOGREG_MODE1
] |=
576 ((GLuint
)(c1
* FMC1_C1_ONE
)) & FMC1_C1_MASK
;
578 if (i915
->state
.Fog
[I915_FOGREG_MODE1
] & FMC1_FOGINDEX_Z
) {
579 i915
->state
.Fog
[I915_FOGREG_MODE2
] = (GLuint
)(c2
* FMC2_C2_ONE
);
582 union { float f
; int i
; } fi
;
584 i915
->state
.Fog
[I915_FOGREG_MODE2
] = fi
.i
;
589 i915
->state
.Fog
[I915_FOGREG_MODE1
] |= FMC1_FOGFUNC_PIXEL_EXP
;
592 i915
->state
.Fog
[I915_FOGREG_MODE1
] |= FMC1_FOGFUNC_PIXEL_EXP2
;
598 else /* if (i915->vertex_fog != I915_FOG_VERTEX) */ {
599 I915_STATECHANGE(i915
, I915_UPLOAD_FOG
);
600 i915
->state
.Fog
[I915_FOGREG_MODE1
] &= ~FMC1_FOGFUNC_MASK
;
601 i915
->state
.Fog
[I915_FOGREG_MODE1
] |= FMC1_FOGFUNC_VERTEX
;
602 i915
->vertex_fog
= I915_FOG_VERTEX
;
606 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
607 I915_ACTIVESTATE(i915
, I915_UPLOAD_FOG
, enabled
);
609 i915
->state
.Ctx
[I915_CTXREG_LIS5
] |= S5_FOG_ENABLE
;
611 i915
->state
.Ctx
[I915_CTXREG_LIS5
] &= ~S5_FOG_ENABLE
;
615 _tnl_allow_vertex_fog( ctx
, (i915
->vertex_fog
== I915_FOG_VERTEX
) );
616 _tnl_allow_pixel_fog( ctx
, (i915
->vertex_fog
!= I915_FOG_VERTEX
) );
620 static void i915Fogfv(GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
622 i915ContextPtr i915
= I915_CONTEXT(ctx
);
625 case GL_FOG_COORDINATE_SOURCE_EXT
:
632 I915_STATECHANGE(i915
, I915_UPLOAD_FOG
);
634 if (i915
->state
.Fog
[I915_FOGREG_MODE1
] & FMC1_FOGINDEX_Z
) {
635 i915
->state
.Fog
[I915_FOGREG_MODE3
] = (GLuint
)(ctx
->Fog
.Density
*
639 union { float f
; int i
; } fi
;
640 fi
.f
= ctx
->Fog
.Density
;
641 i915
->state
.Fog
[I915_FOGREG_MODE3
] = fi
.i
;
646 I915_STATECHANGE(i915
, I915_UPLOAD_FOG
);
647 i915
->state
.Fog
[I915_FOGREG_COLOR
] =
648 (_3DSTATE_FOG_COLOR_CMD
|
649 ((GLubyte
)(ctx
->Fog
.Color
[0]*255.0F
) << 16) |
650 ((GLubyte
)(ctx
->Fog
.Color
[1]*255.0F
) << 8) |
651 ((GLubyte
)(ctx
->Fog
.Color
[2]*255.0F
) << 0));
659 static void i915Hint(GLcontext
*ctx
, GLenum target
, GLenum state
)
669 /* =============================================================
672 static void i915Enable(GLcontext
*ctx
, GLenum cap
, GLboolean state
)
674 i915ContextPtr i915
= I915_CONTEXT(ctx
);
682 update_specular( ctx
);
686 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
688 i915
->state
.Ctx
[I915_CTXREG_LIS6
] |= S6_ALPHA_TEST_ENABLE
;
690 i915
->state
.Ctx
[I915_CTXREG_LIS6
] &= ~S6_ALPHA_TEST_ENABLE
;
694 i915EvalLogicOpBlendState(ctx
);
697 case GL_COLOR_LOGIC_OP
:
698 i915EvalLogicOpBlendState(ctx
);
700 /* Logicop doesn't seem to work at 16bpp:
702 if (i915
->intel
.intelScreen
->cpp
== 2)
703 FALLBACK( &i915
->intel
, I915_FALLBACK_LOGICOP
, state
);
706 case GL_FRAGMENT_PROGRAM_ARB
:
710 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
712 i915
->state
.Ctx
[I915_CTXREG_LIS5
] |= S5_COLOR_DITHER_ENABLE
;
714 i915
->state
.Ctx
[I915_CTXREG_LIS5
] &= ~S5_COLOR_DITHER_ENABLE
;
718 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
720 i915
->state
.Ctx
[I915_CTXREG_LIS6
] |= S6_DEPTH_TEST_ENABLE
;
722 i915
->state
.Ctx
[I915_CTXREG_LIS6
] &= ~S6_DEPTH_TEST_ENABLE
;
724 i915DepthMask( ctx
, ctx
->Depth
.Mask
);
727 case GL_SCISSOR_TEST
:
728 I915_STATECHANGE(i915
, I915_UPLOAD_BUFFERS
);
730 i915
->state
.Buffer
[I915_DESTREG_SENABLE
] = (_3DSTATE_SCISSOR_ENABLE_CMD
|
731 ENABLE_SCISSOR_RECT
);
733 i915
->state
.Buffer
[I915_DESTREG_SENABLE
] = (_3DSTATE_SCISSOR_ENABLE_CMD
|
734 DISABLE_SCISSOR_RECT
);
738 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
740 i915
->state
.Ctx
[I915_CTXREG_LIS4
] |= S4_LINE_ANTIALIAS_ENABLE
;
742 i915
->state
.Ctx
[I915_CTXREG_LIS4
] &= ~S4_LINE_ANTIALIAS_ENABLE
;
749 i915CullFaceFrontFace(ctx
, 0);
752 case GL_STENCIL_TEST
:
753 if (i915
->intel
.hw_stencil
) {
754 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
756 i915
->state
.Ctx
[I915_CTXREG_LIS5
] |= (S5_STENCIL_TEST_ENABLE
|
757 S5_STENCIL_WRITE_ENABLE
);
759 i915
->state
.Ctx
[I915_CTXREG_LIS5
] &= ~(S5_STENCIL_TEST_ENABLE
|
760 S5_STENCIL_WRITE_ENABLE
);
762 FALLBACK( &i915
->intel
, I915_FALLBACK_STENCIL
, state
);
766 case GL_POLYGON_STIPPLE
:
767 /* The stipple command worked on my 855GM box, but not my 845G.
768 * I'll do more testing later to find out exactly which hardware
769 * supports it. Disabled for now.
771 if (i915
->intel
.hw_stipple
&&
772 i915
->intel
.reduced_primitive
== GL_TRIANGLES
)
774 I915_STATECHANGE(i915
, I915_UPLOAD_STIPPLE
);
776 i915
->state
.Stipple
[I915_STPREG_ST1
] |= ST1_ENABLE
;
778 i915
->state
.Stipple
[I915_STPREG_ST1
] &= ~ST1_ENABLE
;
788 static void i915_init_packets( i915ContextPtr i915
)
790 intelScreenPrivate
*screen
= i915
->intel
.intelScreen
;
793 memset(&i915
->state
, 0, sizeof(i915
->state
));
797 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
798 /* Probably don't want to upload all this stuff every time one
801 i915
->state
.Ctx
[I915_CTXREG_LI
] = (_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
807 i915
->state
.Ctx
[I915_CTXREG_LIS2
] = 0;
808 i915
->state
.Ctx
[I915_CTXREG_LIS4
] = 0;
809 i915
->state
.Ctx
[I915_CTXREG_LIS5
] = 0;
811 if (screen
->cpp
== 2)
812 i915
->state
.Ctx
[I915_CTXREG_LIS5
] |= S5_COLOR_DITHER_ENABLE
;
815 i915
->state
.Ctx
[I915_CTXREG_LIS6
] = (S6_COLOR_WRITE_ENABLE
|
816 (2 << S6_TRISTRIP_PV_SHIFT
));
818 i915
->state
.Ctx
[I915_CTXREG_STATE4
] = (_3DSTATE_MODES_4_CMD
|
819 ENABLE_LOGIC_OP_FUNC
|
820 LOGIC_OP_FUNC(LOGICOP_COPY
) |
821 ENABLE_STENCIL_TEST_MASK
|
822 STENCIL_TEST_MASK(0xff) |
823 ENABLE_STENCIL_WRITE_MASK
|
824 STENCIL_WRITE_MASK(0xff));
827 i915
->state
.Ctx
[I915_CTXREG_IAB
] = (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD
|
830 IAB_MODIFY_SRC_FACTOR
|
831 IAB_MODIFY_DST_FACTOR
);
833 i915
->state
.Ctx
[I915_CTXREG_BLENDCOLOR0
] = _3DSTATE_CONST_BLEND_COLOR_CMD
;
834 i915
->state
.Ctx
[I915_CTXREG_BLENDCOLOR1
] = 0;
839 I915_STATECHANGE(i915
, I915_UPLOAD_STIPPLE
);
840 i915
->state
.Stipple
[I915_STPREG_ST0
] = _3DSTATE_STIPPLE
;
845 I915_STATECHANGE(i915
, I915_UPLOAD_FOG
);
846 i915
->state
.Fog
[I915_FOGREG_MODE0
] = _3DSTATE_FOG_MODE_CMD
;
847 i915
->state
.Fog
[I915_FOGREG_MODE1
] = (FMC1_FOGFUNC_MODIFY_ENABLE
|
848 FMC1_FOGFUNC_VERTEX
|
849 FMC1_FOGINDEX_MODIFY_ENABLE
|
851 FMC1_C1_C2_MODIFY_ENABLE
|
852 FMC1_DENSITY_MODIFY_ENABLE
);
853 i915
->state
.Fog
[I915_FOGREG_COLOR
] = _3DSTATE_FOG_COLOR_CMD
;
858 I915_STATECHANGE(i915
, I915_UPLOAD_BUFFERS
);
859 i915
->state
.Buffer
[I915_DESTREG_CBUFADDR0
] = _3DSTATE_BUF_INFO_CMD
;
860 i915
->state
.Buffer
[I915_DESTREG_CBUFADDR1
] =
861 (BUF_3D_ID_COLOR_BACK
|
862 BUF_3D_PITCH(screen
->front
.pitch
* screen
->cpp
) |
866 i915
->state
.Buffer
[I915_DESTREG_DBUFADDR0
] = _3DSTATE_BUF_INFO_CMD
;
867 i915
->state
.Buffer
[I915_DESTREG_DBUFADDR1
] =
869 BUF_3D_PITCH(screen
->depth
.pitch
* screen
->cpp
) |
871 i915
->state
.Buffer
[I915_DESTREG_DBUFADDR2
] = screen
->depth
.offset
;
874 i915
->state
.Buffer
[I915_DESTREG_DV0
] = _3DSTATE_DST_BUF_VARS_CMD
;
876 switch (screen
->fbFormat
) {
879 i915
->state
.Buffer
[I915_DESTREG_DV1
] = (DSTORG_HORT_BIAS(0x8) | /* .5 */
880 DSTORG_VERT_BIAS(0x8) | /* .5 */
882 TEX_DEFAULT_COLOR_OGL
|
885 DEPTH_FRMT_16_FIXED
);
888 i915
->state
.Buffer
[I915_DESTREG_DV1
] = (DSTORG_HORT_BIAS(0x8) | /* .5 */
889 DSTORG_VERT_BIAS(0x8) | /* .5 */
891 TEX_DEFAULT_COLOR_OGL
|
893 DEPTH_FRMT_24_FIXED_8_OTHER
);
896 i915
->state
.Buffer
[I915_DESTREG_SENABLE
] = (_3DSTATE_SCISSOR_ENABLE_CMD
|
897 DISABLE_SCISSOR_RECT
);
898 i915
->state
.Buffer
[I915_DESTREG_SR0
] = _3DSTATE_SCISSOR_RECT_0_CMD
;
899 i915
->state
.Buffer
[I915_DESTREG_SR1
] = 0;
900 i915
->state
.Buffer
[I915_DESTREG_SR2
] = 0;
904 /* These will be emitted every at the head of every buffer, unless
905 * we get hardware contexts working.
907 i915
->state
.active
= (I915_UPLOAD_PROGRAM
|
908 I915_UPLOAD_STIPPLE
|
910 I915_UPLOAD_BUFFERS
);
913 void i915InitStateFunctions( struct dd_function_table
*functions
)
915 functions
->AlphaFunc
= i915AlphaFunc
;
916 functions
->BlendColor
= i915BlendColor
;
917 functions
->BlendEquationSeparate
= i915BlendEquationSeparate
;
918 functions
->BlendFuncSeparate
= i915BlendFuncSeparate
;
919 functions
->ColorMask
= i915ColorMask
;
920 functions
->CullFace
= i915CullFaceFrontFace
;
921 functions
->DepthFunc
= i915DepthFunc
;
922 functions
->DepthMask
= i915DepthMask
;
923 functions
->Enable
= i915Enable
;
924 functions
->Fogfv
= i915Fogfv
;
925 functions
->FrontFace
= i915CullFaceFrontFace
;
926 functions
->Hint
= i915Hint
;
927 functions
->LightModelfv
= i915LightModelfv
;
928 functions
->LineWidth
= i915LineWidth
;
929 functions
->LogicOpcode
= i915LogicOp
;
930 functions
->PointSize
= i915PointSize
;
931 functions
->PolygonStipple
= i915PolygonStipple
;
932 functions
->Scissor
= i915Scissor
;
933 functions
->ShadeModel
= i915ShadeModel
;
934 functions
->StencilFuncSeparate
= i915StencilFuncSeparate
;
935 functions
->StencilMaskSeparate
= i915StencilMaskSeparate
;
936 functions
->StencilOpSeparate
= i915StencilOpSeparate
;
940 void i915InitState( i915ContextPtr i915
)
942 GLcontext
*ctx
= &i915
->intel
.ctx
;
944 i915_init_packets( i915
);
946 intelInitState( ctx
);
948 memcpy( &i915
->initial
, &i915
->state
, sizeof(i915
->state
) );
949 i915
->current
= &i915
->state
;