Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5563 | serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
||
4 | * All Rights Reserved. |
||
5 | * |
||
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: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice (including the |
||
15 | * next paragraph) shall be included in all copies or substantial portions |
||
16 | * of the Software. |
||
17 | * |
||
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. |
||
25 | * |
||
26 | **************************************************************************/ |
||
27 | |||
28 | |||
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" |
||
34 | #include "main/dd.h" |
||
35 | #include "main/state.h" |
||
36 | #include "main/stencil.h" |
||
37 | #include "tnl/tnl.h" |
||
38 | #include "tnl/t_context.h" |
||
39 | |||
40 | #include "drivers/common/driverfuncs.h" |
||
41 | |||
42 | #include "intel_fbo.h" |
||
43 | #include "intel_screen.h" |
||
44 | #include "intel_batchbuffer.h" |
||
45 | #include "intel_buffers.h" |
||
46 | |||
47 | #include "i915_context.h" |
||
48 | #include "i915_reg.h" |
||
49 | |||
50 | #define FILE_DEBUG_FLAG DEBUG_STATE |
||
51 | |||
52 | void |
||
53 | i915_update_stencil(struct gl_context * ctx) |
||
54 | { |
||
55 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
56 | GLuint front_ref, front_writemask, front_mask; |
||
57 | GLenum front_func, front_fail, front_pass_z_fail, front_pass_z_pass; |
||
58 | GLuint back_ref, back_writemask, back_mask; |
||
59 | GLenum back_func, back_fail, back_pass_z_fail, back_pass_z_pass; |
||
60 | GLuint dirty = 0; |
||
61 | |||
62 | /* The 915 considers CW to be "front" for two-sided stencil, so choose |
||
63 | * appropriately. |
||
64 | */ |
||
65 | /* _NEW_POLYGON | _NEW_STENCIL */ |
||
66 | if (ctx->Polygon.FrontFace == GL_CW) { |
||
67 | front_ref = _mesa_get_stencil_ref(ctx, 0); |
||
68 | front_mask = ctx->Stencil.ValueMask[0]; |
||
69 | front_writemask = ctx->Stencil.WriteMask[0]; |
||
70 | front_func = ctx->Stencil.Function[0]; |
||
71 | front_fail = ctx->Stencil.FailFunc[0]; |
||
72 | front_pass_z_fail = ctx->Stencil.ZFailFunc[0]; |
||
73 | front_pass_z_pass = ctx->Stencil.ZPassFunc[0]; |
||
74 | back_ref = _mesa_get_stencil_ref(ctx, ctx->Stencil._BackFace); |
||
75 | back_mask = ctx->Stencil.ValueMask[ctx->Stencil._BackFace]; |
||
76 | back_writemask = ctx->Stencil.WriteMask[ctx->Stencil._BackFace]; |
||
77 | back_func = ctx->Stencil.Function[ctx->Stencil._BackFace]; |
||
78 | back_fail = ctx->Stencil.FailFunc[ctx->Stencil._BackFace]; |
||
79 | back_pass_z_fail = ctx->Stencil.ZFailFunc[ctx->Stencil._BackFace]; |
||
80 | back_pass_z_pass = ctx->Stencil.ZPassFunc[ctx->Stencil._BackFace]; |
||
81 | } else { |
||
82 | front_ref = _mesa_get_stencil_ref(ctx, ctx->Stencil._BackFace); |
||
83 | front_mask = ctx->Stencil.ValueMask[ctx->Stencil._BackFace]; |
||
84 | front_writemask = ctx->Stencil.WriteMask[ctx->Stencil._BackFace]; |
||
85 | front_func = ctx->Stencil.Function[ctx->Stencil._BackFace]; |
||
86 | front_fail = ctx->Stencil.FailFunc[ctx->Stencil._BackFace]; |
||
87 | front_pass_z_fail = ctx->Stencil.ZFailFunc[ctx->Stencil._BackFace]; |
||
88 | front_pass_z_pass = ctx->Stencil.ZPassFunc[ctx->Stencil._BackFace]; |
||
89 | back_ref = _mesa_get_stencil_ref(ctx, 0); |
||
90 | back_mask = ctx->Stencil.ValueMask[0]; |
||
91 | back_writemask = ctx->Stencil.WriteMask[0]; |
||
92 | back_func = ctx->Stencil.Function[0]; |
||
93 | back_fail = ctx->Stencil.FailFunc[0]; |
||
94 | back_pass_z_fail = ctx->Stencil.ZFailFunc[0]; |
||
95 | back_pass_z_pass = ctx->Stencil.ZPassFunc[0]; |
||
96 | } |
||
97 | #define set_ctx_bits(reg, mask, set) do{ \ |
||
98 | GLuint dw = i915->state.Ctx[reg]; \ |
||
99 | dw &= ~(mask); \ |
||
100 | dw |= (set); \ |
||
101 | dirty |= dw != i915->state.Ctx[reg]; \ |
||
102 | i915->state.Ctx[reg] = dw; \ |
||
103 | } while(0) |
||
104 | |||
105 | /* Set front state. */ |
||
106 | set_ctx_bits(I915_CTXREG_STATE4, |
||
107 | MODE4_ENABLE_STENCIL_TEST_MASK | |
||
108 | MODE4_ENABLE_STENCIL_WRITE_MASK, |
||
109 | ENABLE_STENCIL_TEST_MASK | |
||
110 | ENABLE_STENCIL_WRITE_MASK | |
||
111 | STENCIL_TEST_MASK(front_mask) | |
||
112 | STENCIL_WRITE_MASK(front_writemask)); |
||
113 | |||
114 | set_ctx_bits(I915_CTXREG_LIS5, |
||
115 | S5_STENCIL_REF_MASK | |
||
116 | S5_STENCIL_TEST_FUNC_MASK | |
||
117 | S5_STENCIL_FAIL_MASK | |
||
118 | S5_STENCIL_PASS_Z_FAIL_MASK | |
||
119 | S5_STENCIL_PASS_Z_PASS_MASK, |
||
120 | (front_ref << S5_STENCIL_REF_SHIFT) | |
||
121 | (intel_translate_compare_func(front_func) << S5_STENCIL_TEST_FUNC_SHIFT) | |
||
122 | (intel_translate_stencil_op(front_fail) << S5_STENCIL_FAIL_SHIFT) | |
||
123 | (intel_translate_stencil_op(front_pass_z_fail) << |
||
124 | S5_STENCIL_PASS_Z_FAIL_SHIFT) | |
||
125 | (intel_translate_stencil_op(front_pass_z_pass) << |
||
126 | S5_STENCIL_PASS_Z_PASS_SHIFT)); |
||
127 | |||
128 | /* Set back state if different from front. */ |
||
129 | if (ctx->Stencil._TestTwoSide) { |
||
130 | set_ctx_bits(I915_CTXREG_BF_STENCIL_OPS, |
||
131 | BFO_STENCIL_REF_MASK | |
||
132 | BFO_STENCIL_TEST_MASK | |
||
133 | BFO_STENCIL_FAIL_MASK | |
||
134 | BFO_STENCIL_PASS_Z_FAIL_MASK | |
||
135 | BFO_STENCIL_PASS_Z_PASS_MASK, |
||
136 | BFO_STENCIL_TWO_SIDE | |
||
137 | (back_ref << BFO_STENCIL_REF_SHIFT) | |
||
138 | (intel_translate_compare_func(back_func) << BFO_STENCIL_TEST_SHIFT) | |
||
139 | (intel_translate_stencil_op(back_fail) << BFO_STENCIL_FAIL_SHIFT) | |
||
140 | (intel_translate_stencil_op(back_pass_z_fail) << |
||
141 | BFO_STENCIL_PASS_Z_FAIL_SHIFT) | |
||
142 | (intel_translate_stencil_op(back_pass_z_pass) << |
||
143 | BFO_STENCIL_PASS_Z_PASS_SHIFT)); |
||
144 | |||
145 | set_ctx_bits(I915_CTXREG_BF_STENCIL_MASKS, |
||
146 | BFM_STENCIL_TEST_MASK_MASK | |
||
147 | BFM_STENCIL_WRITE_MASK_MASK, |
||
148 | BFM_STENCIL_TEST_MASK(back_mask) | |
||
149 | BFM_STENCIL_WRITE_MASK(back_writemask)); |
||
150 | } else { |
||
151 | set_ctx_bits(I915_CTXREG_BF_STENCIL_OPS, |
||
152 | BFO_STENCIL_TWO_SIDE, 0); |
||
153 | } |
||
154 | |||
155 | #undef set_ctx_bits |
||
156 | |||
157 | if (dirty) |
||
158 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
159 | } |
||
160 | |||
161 | static void |
||
162 | i915StencilFuncSeparate(struct gl_context * ctx, GLenum face, GLenum func, GLint ref, |
||
163 | GLuint mask) |
||
164 | { |
||
165 | } |
||
166 | |||
167 | static void |
||
168 | i915StencilMaskSeparate(struct gl_context * ctx, GLenum face, GLuint mask) |
||
169 | { |
||
170 | } |
||
171 | |||
172 | static void |
||
173 | i915StencilOpSeparate(struct gl_context * ctx, GLenum face, GLenum fail, GLenum zfail, |
||
174 | GLenum zpass) |
||
175 | { |
||
176 | } |
||
177 | |||
178 | static void |
||
179 | i915AlphaFunc(struct gl_context * ctx, GLenum func, GLfloat ref) |
||
180 | { |
||
181 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
182 | int test = intel_translate_compare_func(func); |
||
183 | GLubyte refByte; |
||
184 | GLuint dw; |
||
185 | |||
186 | UNCLAMPED_FLOAT_TO_UBYTE(refByte, ref); |
||
187 | |||
188 | dw = i915->state.Ctx[I915_CTXREG_LIS6]; |
||
189 | dw &= ~(S6_ALPHA_TEST_FUNC_MASK | S6_ALPHA_REF_MASK); |
||
190 | dw |= ((test << S6_ALPHA_TEST_FUNC_SHIFT) | |
||
191 | (((GLuint) refByte) << S6_ALPHA_REF_SHIFT)); |
||
192 | if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) { |
||
193 | i915->state.Ctx[I915_CTXREG_LIS6] = dw; |
||
194 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
195 | } |
||
196 | } |
||
197 | |||
198 | /* This function makes sure that the proper enables are |
||
199 | * set for LogicOp, Independant Alpha Blend, and Blending. |
||
200 | * It needs to be called from numerous places where we |
||
201 | * could change the LogicOp or Independant Alpha Blend without subsequent |
||
202 | * calls to glEnable. |
||
203 | */ |
||
204 | static void |
||
205 | i915EvalLogicOpBlendState(struct gl_context * ctx) |
||
206 | { |
||
207 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
208 | GLuint dw0, dw1; |
||
209 | |||
210 | dw0 = i915->state.Ctx[I915_CTXREG_LIS5]; |
||
211 | dw1 = i915->state.Ctx[I915_CTXREG_LIS6]; |
||
212 | |||
213 | if (ctx->Color.ColorLogicOpEnabled) { |
||
214 | dw0 |= S5_LOGICOP_ENABLE; |
||
215 | dw1 &= ~S6_CBUF_BLEND_ENABLE; |
||
216 | } |
||
217 | else { |
||
218 | dw0 &= ~S5_LOGICOP_ENABLE; |
||
219 | |||
220 | if (ctx->Color.BlendEnabled) { |
||
221 | dw1 |= S6_CBUF_BLEND_ENABLE; |
||
222 | } |
||
223 | else { |
||
224 | dw1 &= ~S6_CBUF_BLEND_ENABLE; |
||
225 | } |
||
226 | } |
||
227 | if (dw0 != i915->state.Ctx[I915_CTXREG_LIS5] || |
||
228 | dw1 != i915->state.Ctx[I915_CTXREG_LIS6]) { |
||
229 | i915->state.Ctx[I915_CTXREG_LIS5] = dw0; |
||
230 | i915->state.Ctx[I915_CTXREG_LIS6] = dw1; |
||
231 | |||
232 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
233 | } |
||
234 | } |
||
235 | |||
236 | static void |
||
237 | i915BlendColor(struct gl_context * ctx, const GLfloat color[4]) |
||
238 | { |
||
239 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
240 | GLubyte r, g, b, a; |
||
241 | GLuint dw; |
||
242 | |||
243 | DBG("%s\n", __FUNCTION__); |
||
244 | |||
245 | UNCLAMPED_FLOAT_TO_UBYTE(r, color[RCOMP]); |
||
246 | UNCLAMPED_FLOAT_TO_UBYTE(g, color[GCOMP]); |
||
247 | UNCLAMPED_FLOAT_TO_UBYTE(b, color[BCOMP]); |
||
248 | UNCLAMPED_FLOAT_TO_UBYTE(a, color[ACOMP]); |
||
249 | |||
250 | dw = (a << 24) | (r << 16) | (g << 8) | b; |
||
251 | if (dw != i915->state.Blend[I915_BLENDREG_BLENDCOLOR1]) { |
||
252 | i915->state.Blend[I915_BLENDREG_BLENDCOLOR1] = dw; |
||
253 | I915_STATECHANGE(i915, I915_UPLOAD_BLEND); |
||
254 | } |
||
255 | } |
||
256 | |||
257 | |||
258 | #define DST_BLND_FACT(f) ((f)< |
||
259 | #define SRC_BLND_FACT(f) ((f)< |
||
260 | #define DST_ABLND_FACT(f) ((f)< |
||
261 | #define SRC_ABLND_FACT(f) ((f)< |
||
262 | |||
263 | |||
264 | |||
265 | static GLuint |
||
266 | translate_blend_equation(GLenum mode) |
||
267 | { |
||
268 | switch (mode) { |
||
269 | case GL_FUNC_ADD: |
||
270 | return BLENDFUNC_ADD; |
||
271 | case GL_MIN: |
||
272 | return BLENDFUNC_MIN; |
||
273 | case GL_MAX: |
||
274 | return BLENDFUNC_MAX; |
||
275 | case GL_FUNC_SUBTRACT: |
||
276 | return BLENDFUNC_SUBTRACT; |
||
277 | case GL_FUNC_REVERSE_SUBTRACT: |
||
278 | return BLENDFUNC_REVERSE_SUBTRACT; |
||
279 | default: |
||
280 | return 0; |
||
281 | } |
||
282 | } |
||
283 | |||
284 | static void |
||
285 | i915UpdateBlendState(struct gl_context * ctx) |
||
286 | { |
||
287 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
288 | GLuint iab = (i915->state.Blend[I915_BLENDREG_IAB] & |
||
289 | ~(IAB_SRC_FACTOR_MASK | |
||
290 | IAB_DST_FACTOR_MASK | |
||
291 | (BLENDFUNC_MASK << IAB_FUNC_SHIFT) | IAB_ENABLE)); |
||
292 | |||
293 | GLuint lis6 = (i915->state.Ctx[I915_CTXREG_LIS6] & |
||
294 | ~(S6_CBUF_SRC_BLEND_FACT_MASK | |
||
295 | S6_CBUF_DST_BLEND_FACT_MASK | S6_CBUF_BLEND_FUNC_MASK)); |
||
296 | |||
297 | GLuint eqRGB = ctx->Color.Blend[0].EquationRGB; |
||
298 | GLuint eqA = ctx->Color.Blend[0].EquationA; |
||
299 | GLuint srcRGB = ctx->Color.Blend[0].SrcRGB; |
||
300 | GLuint dstRGB = ctx->Color.Blend[0].DstRGB; |
||
301 | GLuint srcA = ctx->Color.Blend[0].SrcA; |
||
302 | GLuint dstA = ctx->Color.Blend[0].DstA; |
||
303 | |||
304 | if (eqRGB == GL_MIN || eqRGB == GL_MAX) { |
||
305 | srcRGB = dstRGB = GL_ONE; |
||
306 | } |
||
307 | |||
308 | if (eqA == GL_MIN || eqA == GL_MAX) { |
||
309 | srcA = dstA = GL_ONE; |
||
310 | } |
||
311 | |||
312 | lis6 |= SRC_BLND_FACT(intel_translate_blend_factor(srcRGB)); |
||
313 | lis6 |= DST_BLND_FACT(intel_translate_blend_factor(dstRGB)); |
||
314 | lis6 |= translate_blend_equation(eqRGB) << S6_CBUF_BLEND_FUNC_SHIFT; |
||
315 | |||
316 | iab |= SRC_ABLND_FACT(intel_translate_blend_factor(srcA)); |
||
317 | iab |= DST_ABLND_FACT(intel_translate_blend_factor(dstA)); |
||
318 | iab |= translate_blend_equation(eqA) << IAB_FUNC_SHIFT; |
||
319 | |||
320 | if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) |
||
321 | iab |= IAB_ENABLE; |
||
322 | |||
323 | if (iab != i915->state.Blend[I915_BLENDREG_IAB]) { |
||
324 | i915->state.Blend[I915_BLENDREG_IAB] = iab; |
||
325 | I915_STATECHANGE(i915, I915_UPLOAD_BLEND); |
||
326 | } |
||
327 | if (lis6 != i915->state.Ctx[I915_CTXREG_LIS6]) { |
||
328 | i915->state.Ctx[I915_CTXREG_LIS6] = lis6; |
||
329 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
330 | } |
||
331 | |||
332 | /* This will catch a logicop blend equation */ |
||
333 | i915EvalLogicOpBlendState(ctx); |
||
334 | } |
||
335 | |||
336 | |||
337 | static void |
||
338 | i915BlendFuncSeparate(struct gl_context * ctx, GLenum srcRGB, |
||
339 | GLenum dstRGB, GLenum srcA, GLenum dstA) |
||
340 | { |
||
341 | i915UpdateBlendState(ctx); |
||
342 | } |
||
343 | |||
344 | |||
345 | static void |
||
346 | i915BlendEquationSeparate(struct gl_context * ctx, GLenum eqRGB, GLenum eqA) |
||
347 | { |
||
348 | i915UpdateBlendState(ctx); |
||
349 | } |
||
350 | |||
351 | |||
352 | static void |
||
353 | i915DepthFunc(struct gl_context * ctx, GLenum func) |
||
354 | { |
||
355 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
356 | int test = intel_translate_compare_func(func); |
||
357 | GLuint dw; |
||
358 | |||
359 | DBG("%s\n", __FUNCTION__); |
||
360 | |||
361 | dw = i915->state.Ctx[I915_CTXREG_LIS6]; |
||
362 | dw &= ~S6_DEPTH_TEST_FUNC_MASK; |
||
363 | dw |= test << S6_DEPTH_TEST_FUNC_SHIFT; |
||
364 | if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) { |
||
365 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
366 | i915->state.Ctx[I915_CTXREG_LIS6] = dw; |
||
367 | } |
||
368 | } |
||
369 | |||
370 | static void |
||
371 | i915DepthMask(struct gl_context * ctx, GLboolean flag) |
||
372 | { |
||
373 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
374 | GLuint dw; |
||
375 | |||
376 | DBG("%s flag (%d)\n", __FUNCTION__, flag); |
||
377 | |||
378 | if (!ctx->DrawBuffer || !ctx->DrawBuffer->Visual.depthBits) |
||
379 | flag = false; |
||
380 | |||
381 | dw = i915->state.Ctx[I915_CTXREG_LIS6]; |
||
382 | if (flag && ctx->Depth.Test) |
||
383 | dw |= S6_DEPTH_WRITE_ENABLE; |
||
384 | else |
||
385 | dw &= ~S6_DEPTH_WRITE_ENABLE; |
||
386 | if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) { |
||
387 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
388 | i915->state.Ctx[I915_CTXREG_LIS6] = dw; |
||
389 | } |
||
390 | } |
||
391 | |||
392 | |||
393 | |||
394 | /** |
||
395 | * Update the viewport transformation matrix. Depends on: |
||
396 | * - viewport pos/size |
||
397 | * - depthrange |
||
398 | * - window pos/size or FBO size |
||
399 | */ |
||
400 | void |
||
401 | intelCalcViewport(struct gl_context * ctx) |
||
402 | { |
||
403 | struct intel_context *intel = intel_context(ctx); |
||
404 | |||
405 | if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) { |
||
406 | _math_matrix_viewport(&intel->ViewportMatrix, |
||
407 | ctx->Viewport.X, |
||
408 | ctx->DrawBuffer->Height - ctx->Viewport.Y, |
||
409 | ctx->Viewport.Width, |
||
410 | -ctx->Viewport.Height, |
||
411 | ctx->Viewport.Near, |
||
412 | ctx->Viewport.Far, |
||
413 | 1.0); |
||
414 | } else { |
||
415 | _math_matrix_viewport(&intel->ViewportMatrix, |
||
416 | ctx->Viewport.X, |
||
417 | ctx->Viewport.Y, |
||
418 | ctx->Viewport.Width, |
||
419 | ctx->Viewport.Height, |
||
420 | ctx->Viewport.Near, |
||
421 | ctx->Viewport.Far, |
||
422 | 1.0); |
||
423 | } |
||
424 | } |
||
425 | |||
426 | |||
427 | /** Called from ctx->Driver.Viewport() */ |
||
428 | static void |
||
429 | i915Viewport(struct gl_context * ctx, |
||
430 | GLint x, GLint y, GLsizei width, GLsizei height) |
||
431 | { |
||
432 | intelCalcViewport(ctx); |
||
433 | } |
||
434 | |||
435 | |||
436 | /** Called from ctx->Driver.DepthRange() */ |
||
437 | static void |
||
438 | i915DepthRange(struct gl_context * ctx, GLclampd nearval, GLclampd farval) |
||
439 | { |
||
440 | intelCalcViewport(ctx); |
||
441 | } |
||
442 | |||
443 | |||
444 | /* ============================================================= |
||
445 | * Polygon stipple |
||
446 | * |
||
447 | * The i915 supports a 4x4 stipple natively, GL wants 32x32. |
||
448 | * Fortunately stipple is usually a repeating pattern. |
||
449 | */ |
||
450 | static void |
||
451 | i915PolygonStipple(struct gl_context * ctx, const GLubyte * mask) |
||
452 | { |
||
453 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
454 | const GLubyte *m; |
||
455 | GLubyte p[4]; |
||
456 | int i, j, k; |
||
457 | int active = (ctx->Polygon.StippleFlag && |
||
458 | i915->intel.reduced_primitive == GL_TRIANGLES); |
||
459 | GLuint newMask; |
||
460 | |||
461 | if (active) { |
||
462 | I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE); |
||
463 | i915->state.Stipple[I915_STPREG_ST1] &= ~ST1_ENABLE; |
||
464 | } |
||
465 | |||
466 | /* Use the already unpacked stipple data from the context rather than the |
||
467 | * uninterpreted mask passed in. |
||
468 | */ |
||
469 | mask = (const GLubyte *)ctx->PolygonStipple; |
||
470 | m = mask; |
||
471 | |||
472 | p[0] = mask[12] & 0xf; |
||
473 | p[0] |= p[0] << 4; |
||
474 | p[1] = mask[8] & 0xf; |
||
475 | p[1] |= p[1] << 4; |
||
476 | p[2] = mask[4] & 0xf; |
||
477 | p[2] |= p[2] << 4; |
||
478 | p[3] = mask[0] & 0xf; |
||
479 | p[3] |= p[3] << 4; |
||
480 | |||
481 | for (k = 0; k < 8; k++) |
||
482 | for (j = 3; j >= 0; j--) |
||
483 | for (i = 0; i < 4; i++, m++) |
||
484 | if (*m != p[j]) { |
||
485 | i915->intel.hw_stipple = 0; |
||
486 | return; |
||
487 | } |
||
488 | |||
489 | newMask = (((p[0] & 0xf) << 0) | |
||
490 | ((p[1] & 0xf) << 4) | |
||
491 | ((p[2] & 0xf) << 8) | ((p[3] & 0xf) << 12)); |
||
492 | |||
493 | |||
494 | if (newMask == 0xffff || newMask == 0x0) { |
||
495 | /* this is needed to make conform pass */ |
||
496 | i915->intel.hw_stipple = 0; |
||
497 | return; |
||
498 | } |
||
499 | |||
500 | i915->state.Stipple[I915_STPREG_ST1] &= ~0xffff; |
||
501 | i915->state.Stipple[I915_STPREG_ST1] |= newMask; |
||
502 | i915->intel.hw_stipple = 1; |
||
503 | |||
504 | if (active) |
||
505 | i915->state.Stipple[I915_STPREG_ST1] |= ST1_ENABLE; |
||
506 | } |
||
507 | |||
508 | |||
509 | /* ============================================================= |
||
510 | * Hardware clipping |
||
511 | */ |
||
512 | static void |
||
513 | i915Scissor(struct gl_context * ctx, GLint x, GLint y, GLsizei w, GLsizei h) |
||
514 | { |
||
515 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
516 | int x1, y1, x2, y2; |
||
517 | |||
518 | if (!ctx->DrawBuffer) |
||
519 | return; |
||
520 | |||
521 | DBG("%s %d,%d %dx%d\n", __FUNCTION__, x, y, w, h); |
||
522 | |||
523 | if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) { |
||
524 | x1 = x; |
||
525 | y1 = ctx->DrawBuffer->Height - (y + h); |
||
526 | x2 = x + w - 1; |
||
527 | y2 = y1 + h - 1; |
||
528 | DBG("%s %d..%d,%d..%d (inverted)\n", __FUNCTION__, x1, x2, y1, y2); |
||
529 | } |
||
530 | else { |
||
531 | /* FBO - not inverted |
||
532 | */ |
||
533 | x1 = x; |
||
534 | y1 = y; |
||
535 | x2 = x + w - 1; |
||
536 | y2 = y + h - 1; |
||
537 | DBG("%s %d..%d,%d..%d (not inverted)\n", __FUNCTION__, x1, x2, y1, y2); |
||
538 | } |
||
539 | |||
540 | x1 = CLAMP(x1, 0, ctx->DrawBuffer->Width - 1); |
||
541 | y1 = CLAMP(y1, 0, ctx->DrawBuffer->Height - 1); |
||
542 | x2 = CLAMP(x2, 0, ctx->DrawBuffer->Width - 1); |
||
543 | y2 = CLAMP(y2, 0, ctx->DrawBuffer->Height - 1); |
||
544 | |||
545 | DBG("%s %d..%d,%d..%d (clamped)\n", __FUNCTION__, x1, x2, y1, y2); |
||
546 | |||
547 | I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS); |
||
548 | i915->state.Buffer[I915_DESTREG_SR1] = (y1 << 16) | (x1 & 0xffff); |
||
549 | i915->state.Buffer[I915_DESTREG_SR2] = (y2 << 16) | (x2 & 0xffff); |
||
550 | } |
||
551 | |||
552 | static void |
||
553 | i915LogicOp(struct gl_context * ctx, GLenum opcode) |
||
554 | { |
||
555 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
556 | int tmp = intel_translate_logic_op(opcode); |
||
557 | |||
558 | DBG("%s\n", __FUNCTION__); |
||
559 | |||
560 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
561 | i915->state.Ctx[I915_CTXREG_STATE4] &= ~LOGICOP_MASK; |
||
562 | i915->state.Ctx[I915_CTXREG_STATE4] |= LOGIC_OP_FUNC(tmp); |
||
563 | } |
||
564 | |||
565 | |||
566 | |||
567 | static void |
||
568 | i915CullFaceFrontFace(struct gl_context * ctx, GLenum unused) |
||
569 | { |
||
570 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
571 | GLuint mode, dw; |
||
572 | |||
573 | DBG("%s %d\n", __FUNCTION__, |
||
574 | ctx->DrawBuffer ? ctx->DrawBuffer->Name : 0); |
||
575 | |||
576 | if (!ctx->Polygon.CullFlag) { |
||
577 | mode = S4_CULLMODE_NONE; |
||
578 | } |
||
579 | else if (ctx->Polygon.CullFaceMode != GL_FRONT_AND_BACK) { |
||
580 | mode = S4_CULLMODE_CW; |
||
581 | |||
582 | if (ctx->DrawBuffer && _mesa_is_user_fbo(ctx->DrawBuffer)) |
||
583 | mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW); |
||
584 | if (ctx->Polygon.CullFaceMode == GL_FRONT) |
||
585 | mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW); |
||
586 | if (ctx->Polygon.FrontFace != GL_CCW) |
||
587 | mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW); |
||
588 | } |
||
589 | else { |
||
590 | mode = S4_CULLMODE_BOTH; |
||
591 | } |
||
592 | |||
593 | dw = i915->state.Ctx[I915_CTXREG_LIS4]; |
||
594 | dw &= ~S4_CULLMODE_MASK; |
||
595 | dw |= mode; |
||
596 | if (dw != i915->state.Ctx[I915_CTXREG_LIS4]) { |
||
597 | i915->state.Ctx[I915_CTXREG_LIS4] = dw; |
||
598 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
599 | } |
||
600 | } |
||
601 | |||
602 | static void |
||
603 | i915LineWidth(struct gl_context * ctx, GLfloat widthf) |
||
604 | { |
||
605 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
606 | int lis4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_LINE_WIDTH_MASK; |
||
607 | int width; |
||
608 | |||
609 | DBG("%s\n", __FUNCTION__); |
||
610 | |||
611 | width = (int) (widthf * 2); |
||
612 | width = CLAMP(width, 1, 0xf); |
||
613 | lis4 |= width << S4_LINE_WIDTH_SHIFT; |
||
614 | |||
615 | if (lis4 != i915->state.Ctx[I915_CTXREG_LIS4]) { |
||
616 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
617 | i915->state.Ctx[I915_CTXREG_LIS4] = lis4; |
||
618 | } |
||
619 | } |
||
620 | |||
621 | static void |
||
622 | i915PointSize(struct gl_context * ctx, GLfloat size) |
||
623 | { |
||
624 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
625 | int lis4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_POINT_WIDTH_MASK; |
||
626 | GLint point_size = (int) round(size); |
||
627 | |||
628 | DBG("%s\n", __FUNCTION__); |
||
629 | |||
630 | point_size = CLAMP(point_size, 1, 255); |
||
631 | lis4 |= point_size << S4_POINT_WIDTH_SHIFT; |
||
632 | |||
633 | if (lis4 != i915->state.Ctx[I915_CTXREG_LIS4]) { |
||
634 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
635 | i915->state.Ctx[I915_CTXREG_LIS4] = lis4; |
||
636 | } |
||
637 | } |
||
638 | |||
639 | |||
640 | static void |
||
641 | i915PointParameterfv(struct gl_context * ctx, GLenum pname, const GLfloat *params) |
||
642 | { |
||
643 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
644 | |||
645 | switch (pname) { |
||
646 | case GL_POINT_SPRITE_COORD_ORIGIN: |
||
647 | /* This could be supported, but it would require modifying the fragment |
||
648 | * program to invert the y component of the texture coordinate by |
||
649 | * inserting a 'SUB tc.y, {1.0}.xxxx, tc' instruction. |
||
650 | */ |
||
651 | FALLBACK(&i915->intel, I915_FALLBACK_POINT_SPRITE_COORD_ORIGIN, |
||
652 | (params[0] != GL_UPPER_LEFT)); |
||
653 | break; |
||
654 | } |
||
655 | } |
||
656 | |||
657 | void |
||
658 | i915_update_sprite_point_enable(struct gl_context *ctx) |
||
659 | { |
||
660 | struct intel_context *intel = intel_context(ctx); |
||
661 | /* _NEW_PROGRAM */ |
||
662 | struct i915_fragment_program *p = |
||
663 | (struct i915_fragment_program *) ctx->FragmentProgram._Current; |
||
664 | const GLbitfield64 inputsRead = p->FragProg.Base.InputsRead; |
||
665 | struct i915_context *i915 = i915_context(ctx); |
||
666 | GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK; |
||
667 | int i; |
||
668 | GLuint coord_replace_bits = 0x0; |
||
669 | GLuint tex_coord_unit_bits = 0x0; |
||
670 | |||
671 | for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { |
||
672 | /* _NEW_POINT */ |
||
673 | if (ctx->Point.CoordReplace[i] && ctx->Point.PointSprite) |
||
674 | coord_replace_bits |= (1 << i); |
||
675 | if (inputsRead & VARYING_BIT_TEX(i)) |
||
676 | tex_coord_unit_bits |= (1 << i); |
||
677 | } |
||
678 | |||
679 | /* |
||
680 | * Here we can't enable the SPRITE_POINT_ENABLE bit when the mis-match |
||
681 | * of tex_coord_unit_bits and coord_replace_bits, or this will make all |
||
682 | * the other non-point-sprite coords(like varying inputs, as we now use |
||
683 | * tex coord to implement varying inputs) be replaced to value (0, 0)-(1, 1). |
||
684 | * |
||
685 | * Thus, do fallback when needed. |
||
686 | */ |
||
687 | FALLBACK(intel, I915_FALLBACK_COORD_REPLACE, |
||
688 | coord_replace_bits && coord_replace_bits != tex_coord_unit_bits); |
||
689 | |||
690 | s4 &= ~S4_SPRITE_POINT_ENABLE; |
||
691 | s4 |= (coord_replace_bits && coord_replace_bits == tex_coord_unit_bits) ? |
||
692 | S4_SPRITE_POINT_ENABLE : 0; |
||
693 | if (s4 != i915->state.Ctx[I915_CTXREG_LIS4]) { |
||
694 | i915->state.Ctx[I915_CTXREG_LIS4] = s4; |
||
695 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
696 | } |
||
697 | } |
||
698 | |||
699 | |||
700 | /* ============================================================= |
||
701 | * Color masks |
||
702 | */ |
||
703 | |||
704 | static void |
||
705 | i915ColorMask(struct gl_context * ctx, |
||
706 | GLboolean r, GLboolean g, GLboolean b, GLboolean a) |
||
707 | { |
||
708 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
709 | GLuint tmp = i915->state.Ctx[I915_CTXREG_LIS5] & ~S5_WRITEDISABLE_MASK; |
||
710 | |||
711 | DBG("%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__, r, g, b, |
||
712 | a); |
||
713 | |||
714 | if (!r) |
||
715 | tmp |= S5_WRITEDISABLE_RED; |
||
716 | if (!g) |
||
717 | tmp |= S5_WRITEDISABLE_GREEN; |
||
718 | if (!b) |
||
719 | tmp |= S5_WRITEDISABLE_BLUE; |
||
720 | if (!a) |
||
721 | tmp |= S5_WRITEDISABLE_ALPHA; |
||
722 | |||
723 | if (tmp != i915->state.Ctx[I915_CTXREG_LIS5]) { |
||
724 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
725 | i915->state.Ctx[I915_CTXREG_LIS5] = tmp; |
||
726 | } |
||
727 | } |
||
728 | |||
729 | static void |
||
730 | update_specular(struct gl_context * ctx) |
||
731 | { |
||
732 | /* A hack to trigger the rebuild of the fragment program. |
||
733 | */ |
||
734 | intel_context(ctx)->NewGLState |= _NEW_TEXTURE; |
||
735 | } |
||
736 | |||
737 | static void |
||
738 | i915LightModelfv(struct gl_context * ctx, GLenum pname, const GLfloat * param) |
||
739 | { |
||
740 | DBG("%s\n", __FUNCTION__); |
||
741 | |||
742 | if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) { |
||
743 | update_specular(ctx); |
||
744 | } |
||
745 | } |
||
746 | |||
747 | static void |
||
748 | i915ShadeModel(struct gl_context * ctx, GLenum mode) |
||
749 | { |
||
750 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
751 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
752 | |||
753 | if (mode == GL_SMOOTH) { |
||
754 | i915->state.Ctx[I915_CTXREG_LIS4] &= ~(S4_FLATSHADE_ALPHA | |
||
755 | S4_FLATSHADE_COLOR | |
||
756 | S4_FLATSHADE_SPECULAR); |
||
757 | } |
||
758 | else { |
||
759 | i915->state.Ctx[I915_CTXREG_LIS4] |= (S4_FLATSHADE_ALPHA | |
||
760 | S4_FLATSHADE_COLOR | |
||
761 | S4_FLATSHADE_SPECULAR); |
||
762 | } |
||
763 | } |
||
764 | |||
765 | /* ============================================================= |
||
766 | * Fog |
||
767 | * |
||
768 | * This empty function remains because _mesa_init_driver_state calls |
||
769 | * dd_function_table::Fogfv unconditionally. We have to have some function |
||
770 | * there so that it doesn't try to call a NULL pointer. |
||
771 | */ |
||
772 | static void |
||
773 | i915Fogfv(struct gl_context * ctx, GLenum pname, const GLfloat * param) |
||
774 | { |
||
775 | (void) ctx; |
||
776 | (void) pname; |
||
777 | (void) param; |
||
778 | } |
||
779 | |||
780 | /* ============================================================= |
||
781 | */ |
||
782 | |||
783 | static void |
||
784 | i915Enable(struct gl_context * ctx, GLenum cap, GLboolean state) |
||
785 | { |
||
786 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
787 | GLuint dw; |
||
788 | |||
789 | switch (cap) { |
||
790 | case GL_TEXTURE_2D: |
||
791 | break; |
||
792 | |||
793 | case GL_LIGHTING: |
||
794 | case GL_COLOR_SUM: |
||
795 | update_specular(ctx); |
||
796 | break; |
||
797 | |||
798 | case GL_ALPHA_TEST: |
||
799 | dw = i915->state.Ctx[I915_CTXREG_LIS6]; |
||
800 | if (state) |
||
801 | dw |= S6_ALPHA_TEST_ENABLE; |
||
802 | else |
||
803 | dw &= ~S6_ALPHA_TEST_ENABLE; |
||
804 | if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) { |
||
805 | i915->state.Ctx[I915_CTXREG_LIS6] = dw; |
||
806 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
807 | } |
||
808 | break; |
||
809 | |||
810 | case GL_BLEND: |
||
811 | i915EvalLogicOpBlendState(ctx); |
||
812 | break; |
||
813 | |||
814 | case GL_COLOR_LOGIC_OP: |
||
815 | i915EvalLogicOpBlendState(ctx); |
||
816 | |||
817 | /* Logicop doesn't seem to work at 16bpp: |
||
818 | */ |
||
819 | if (ctx->Visual.rgbBits == 16) |
||
820 | FALLBACK(&i915->intel, I915_FALLBACK_LOGICOP, state); |
||
821 | break; |
||
822 | |||
823 | case GL_FRAGMENT_PROGRAM_ARB: |
||
824 | break; |
||
825 | |||
826 | case GL_DITHER: |
||
827 | dw = i915->state.Ctx[I915_CTXREG_LIS5]; |
||
828 | if (state) |
||
829 | dw |= S5_COLOR_DITHER_ENABLE; |
||
830 | else |
||
831 | dw &= ~S5_COLOR_DITHER_ENABLE; |
||
832 | if (dw != i915->state.Ctx[I915_CTXREG_LIS5]) { |
||
833 | i915->state.Ctx[I915_CTXREG_LIS5] = dw; |
||
834 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
835 | } |
||
836 | break; |
||
837 | |||
838 | case GL_DEPTH_TEST: |
||
839 | dw = i915->state.Ctx[I915_CTXREG_LIS6]; |
||
840 | |||
841 | if (!ctx->DrawBuffer || !ctx->DrawBuffer->Visual.depthBits) |
||
842 | state = false; |
||
843 | |||
844 | if (state) |
||
845 | dw |= S6_DEPTH_TEST_ENABLE; |
||
846 | else |
||
847 | dw &= ~S6_DEPTH_TEST_ENABLE; |
||
848 | if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) { |
||
849 | i915->state.Ctx[I915_CTXREG_LIS6] = dw; |
||
850 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
851 | } |
||
852 | |||
853 | i915DepthMask(ctx, ctx->Depth.Mask); |
||
854 | break; |
||
855 | |||
856 | case GL_SCISSOR_TEST: |
||
857 | I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS); |
||
858 | if (state) |
||
859 | i915->state.Buffer[I915_DESTREG_SENABLE] = |
||
860 | (_3DSTATE_SCISSOR_ENABLE_CMD | ENABLE_SCISSOR_RECT); |
||
861 | else |
||
862 | i915->state.Buffer[I915_DESTREG_SENABLE] = |
||
863 | (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT); |
||
864 | break; |
||
865 | |||
866 | case GL_LINE_SMOOTH: |
||
867 | dw = i915->state.Ctx[I915_CTXREG_LIS4]; |
||
868 | if (state) |
||
869 | dw |= S4_LINE_ANTIALIAS_ENABLE; |
||
870 | else |
||
871 | dw &= ~S4_LINE_ANTIALIAS_ENABLE; |
||
872 | if (dw != i915->state.Ctx[I915_CTXREG_LIS4]) { |
||
873 | i915->state.Ctx[I915_CTXREG_LIS4] = dw; |
||
874 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
875 | } |
||
876 | break; |
||
877 | |||
878 | case GL_CULL_FACE: |
||
879 | i915CullFaceFrontFace(ctx, 0); |
||
880 | break; |
||
881 | |||
882 | case GL_STENCIL_TEST: |
||
883 | if (!ctx->DrawBuffer || !ctx->DrawBuffer->Visual.stencilBits) |
||
884 | state = false; |
||
885 | |||
886 | dw = i915->state.Ctx[I915_CTXREG_LIS5]; |
||
887 | if (state) |
||
888 | dw |= (S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE); |
||
889 | else |
||
890 | dw &= ~(S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE); |
||
891 | if (dw != i915->state.Ctx[I915_CTXREG_LIS5]) { |
||
892 | i915->state.Ctx[I915_CTXREG_LIS5] = dw; |
||
893 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
894 | } |
||
895 | break; |
||
896 | |||
897 | case GL_POLYGON_STIPPLE: |
||
898 | /* The stipple command worked on my 855GM box, but not my 845G. |
||
899 | * I'll do more testing later to find out exactly which hardware |
||
900 | * supports it. Disabled for now. |
||
901 | */ |
||
902 | if (i915->intel.hw_stipple && |
||
903 | i915->intel.reduced_primitive == GL_TRIANGLES) { |
||
904 | I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE); |
||
905 | if (state) |
||
906 | i915->state.Stipple[I915_STPREG_ST1] |= ST1_ENABLE; |
||
907 | else |
||
908 | i915->state.Stipple[I915_STPREG_ST1] &= ~ST1_ENABLE; |
||
909 | } |
||
910 | break; |
||
911 | |||
912 | case GL_POLYGON_SMOOTH: |
||
913 | break; |
||
914 | |||
915 | case GL_POINT_SPRITE: |
||
916 | /* Handle it at i915_update_sprite_point_enable () */ |
||
917 | break; |
||
918 | |||
919 | case GL_POINT_SMOOTH: |
||
920 | break; |
||
921 | |||
922 | default: |
||
923 | ; |
||
924 | } |
||
925 | } |
||
926 | |||
927 | |||
928 | static void |
||
929 | i915_init_packets(struct i915_context *i915) |
||
930 | { |
||
931 | /* Zero all state */ |
||
932 | memset(&i915->state, 0, sizeof(i915->state)); |
||
933 | |||
934 | |||
935 | { |
||
936 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
937 | I915_STATECHANGE(i915, I915_UPLOAD_BLEND); |
||
938 | /* Probably don't want to upload all this stuff every time one |
||
939 | * piece changes. |
||
940 | */ |
||
941 | i915->state.Ctx[I915_CTXREG_LI] = (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | |
||
942 | I1_LOAD_S(2) | |
||
943 | I1_LOAD_S(4) | |
||
944 | I1_LOAD_S(5) | I1_LOAD_S(6) | (3)); |
||
945 | i915->state.Ctx[I915_CTXREG_LIS2] = 0; |
||
946 | i915->state.Ctx[I915_CTXREG_LIS4] = 0; |
||
947 | i915->state.Ctx[I915_CTXREG_LIS5] = 0; |
||
948 | |||
949 | if (i915->intel.ctx.Visual.rgbBits == 16) |
||
950 | i915->state.Ctx[I915_CTXREG_LIS5] |= S5_COLOR_DITHER_ENABLE; |
||
951 | |||
952 | |||
953 | i915->state.Ctx[I915_CTXREG_LIS6] = (S6_COLOR_WRITE_ENABLE | |
||
954 | (2 << S6_TRISTRIP_PV_SHIFT)); |
||
955 | |||
956 | i915->state.Ctx[I915_CTXREG_STATE4] = (_3DSTATE_MODES_4_CMD | |
||
957 | ENABLE_LOGIC_OP_FUNC | |
||
958 | LOGIC_OP_FUNC(LOGICOP_COPY) | |
||
959 | ENABLE_STENCIL_TEST_MASK | |
||
960 | STENCIL_TEST_MASK(0xff) | |
||
961 | ENABLE_STENCIL_WRITE_MASK | |
||
962 | STENCIL_WRITE_MASK(0xff)); |
||
963 | |||
964 | i915->state.Blend[I915_BLENDREG_IAB] = |
||
965 | (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD | IAB_MODIFY_ENABLE | |
||
966 | IAB_MODIFY_FUNC | IAB_MODIFY_SRC_FACTOR | IAB_MODIFY_DST_FACTOR); |
||
967 | |||
968 | i915->state.Blend[I915_BLENDREG_BLENDCOLOR0] = |
||
969 | _3DSTATE_CONST_BLEND_COLOR_CMD; |
||
970 | i915->state.Blend[I915_BLENDREG_BLENDCOLOR1] = 0; |
||
971 | |||
972 | i915->state.Ctx[I915_CTXREG_BF_STENCIL_MASKS] = |
||
973 | _3DSTATE_BACKFACE_STENCIL_MASKS | |
||
974 | BFM_ENABLE_STENCIL_TEST_MASK | |
||
975 | BFM_ENABLE_STENCIL_WRITE_MASK | |
||
976 | (0xff << BFM_STENCIL_WRITE_MASK_SHIFT) | |
||
977 | (0xff << BFM_STENCIL_TEST_MASK_SHIFT); |
||
978 | i915->state.Ctx[I915_CTXREG_BF_STENCIL_OPS] = |
||
979 | _3DSTATE_BACKFACE_STENCIL_OPS | |
||
980 | BFO_ENABLE_STENCIL_REF | |
||
981 | BFO_ENABLE_STENCIL_FUNCS | |
||
982 | BFO_ENABLE_STENCIL_TWO_SIDE; |
||
983 | } |
||
984 | |||
985 | { |
||
986 | I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE); |
||
987 | i915->state.Stipple[I915_STPREG_ST0] = _3DSTATE_STIPPLE; |
||
988 | } |
||
989 | |||
990 | { |
||
991 | i915->state.Buffer[I915_DESTREG_DV0] = _3DSTATE_DST_BUF_VARS_CMD; |
||
992 | |||
993 | /* scissor */ |
||
994 | i915->state.Buffer[I915_DESTREG_SENABLE] = |
||
995 | (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT); |
||
996 | i915->state.Buffer[I915_DESTREG_SR0] = _3DSTATE_SCISSOR_RECT_0_CMD; |
||
997 | i915->state.Buffer[I915_DESTREG_SR1] = 0; |
||
998 | i915->state.Buffer[I915_DESTREG_SR2] = 0; |
||
999 | } |
||
1000 | |||
1001 | i915->state.RasterRules[I915_RASTER_RULES] = _3DSTATE_RASTER_RULES_CMD | |
||
1002 | ENABLE_POINT_RASTER_RULE | |
||
1003 | OGL_POINT_RASTER_RULE | |
||
1004 | ENABLE_LINE_STRIP_PROVOKE_VRTX | |
||
1005 | ENABLE_TRI_FAN_PROVOKE_VRTX | |
||
1006 | LINE_STRIP_PROVOKE_VRTX(1) | |
||
1007 | TRI_FAN_PROVOKE_VRTX(2) | ENABLE_TEXKILL_3D_4D | TEXKILL_4D; |
||
1008 | |||
1009 | #if 0 |
||
1010 | { |
||
1011 | I915_STATECHANGE(i915, I915_UPLOAD_DEFAULTS); |
||
1012 | i915->state.Default[I915_DEFREG_C0] = _3DSTATE_DEFAULT_DIFFUSE; |
||
1013 | i915->state.Default[I915_DEFREG_C1] = 0; |
||
1014 | i915->state.Default[I915_DEFREG_S0] = _3DSTATE_DEFAULT_SPECULAR; |
||
1015 | i915->state.Default[I915_DEFREG_S1] = 0; |
||
1016 | i915->state.Default[I915_DEFREG_Z0] = _3DSTATE_DEFAULT_Z; |
||
1017 | i915->state.Default[I915_DEFREG_Z1] = 0; |
||
1018 | } |
||
1019 | #endif |
||
1020 | |||
1021 | |||
1022 | /* These will be emitted every at the head of every buffer, unless |
||
1023 | * we get hardware contexts working. |
||
1024 | */ |
||
1025 | i915->state.active = (I915_UPLOAD_PROGRAM | |
||
1026 | I915_UPLOAD_STIPPLE | |
||
1027 | I915_UPLOAD_CTX | |
||
1028 | I915_UPLOAD_BLEND | |
||
1029 | I915_UPLOAD_BUFFERS | |
||
1030 | I915_UPLOAD_INVARIENT | |
||
1031 | I915_UPLOAD_RASTER_RULES); |
||
1032 | } |
||
1033 | |||
1034 | void |
||
1035 | i915_update_provoking_vertex(struct gl_context * ctx) |
||
1036 | { |
||
1037 | struct i915_context *i915 = I915_CONTEXT(ctx); |
||
1038 | |||
1039 | I915_STATECHANGE(i915, I915_UPLOAD_CTX); |
||
1040 | i915->state.Ctx[I915_CTXREG_LIS6] &= ~(S6_TRISTRIP_PV_MASK); |
||
1041 | |||
1042 | I915_STATECHANGE(i915, I915_UPLOAD_RASTER_RULES); |
||
1043 | i915->state.RasterRules[I915_RASTER_RULES] &= ~(LINE_STRIP_PROVOKE_VRTX_MASK | |
||
1044 | TRI_FAN_PROVOKE_VRTX_MASK); |
||
1045 | |||
1046 | /* _NEW_LIGHT */ |
||
1047 | if (ctx->Light.ProvokingVertex == GL_LAST_VERTEX_CONVENTION) { |
||
1048 | i915->state.RasterRules[I915_RASTER_RULES] |= (LINE_STRIP_PROVOKE_VRTX(1) | |
||
1049 | TRI_FAN_PROVOKE_VRTX(2)); |
||
1050 | i915->state.Ctx[I915_CTXREG_LIS6] |= (2 << S6_TRISTRIP_PV_SHIFT); |
||
1051 | } else { |
||
1052 | i915->state.RasterRules[I915_RASTER_RULES] |= (LINE_STRIP_PROVOKE_VRTX(0) | |
||
1053 | TRI_FAN_PROVOKE_VRTX(1)); |
||
1054 | i915->state.Ctx[I915_CTXREG_LIS6] |= (0 << S6_TRISTRIP_PV_SHIFT); |
||
1055 | } |
||
1056 | } |
||
1057 | |||
1058 | /* Fallback to swrast for select and feedback. |
||
1059 | */ |
||
1060 | static void |
||
1061 | i915RenderMode(struct gl_context *ctx, GLenum mode) |
||
1062 | { |
||
1063 | struct intel_context *intel = intel_context(ctx); |
||
1064 | FALLBACK(intel, INTEL_FALLBACK_RENDERMODE, (mode != GL_RENDER)); |
||
1065 | } |
||
1066 | |||
1067 | void |
||
1068 | i915InitStateFunctions(struct dd_function_table *functions) |
||
1069 | { |
||
1070 | functions->AlphaFunc = i915AlphaFunc; |
||
1071 | functions->BlendColor = i915BlendColor; |
||
1072 | functions->BlendEquationSeparate = i915BlendEquationSeparate; |
||
1073 | functions->BlendFuncSeparate = i915BlendFuncSeparate; |
||
1074 | functions->ColorMask = i915ColorMask; |
||
1075 | functions->CullFace = i915CullFaceFrontFace; |
||
1076 | functions->DepthFunc = i915DepthFunc; |
||
1077 | functions->DepthMask = i915DepthMask; |
||
1078 | functions->Enable = i915Enable; |
||
1079 | functions->Fogfv = i915Fogfv; |
||
1080 | functions->FrontFace = i915CullFaceFrontFace; |
||
1081 | functions->LightModelfv = i915LightModelfv; |
||
1082 | functions->LineWidth = i915LineWidth; |
||
1083 | functions->LogicOpcode = i915LogicOp; |
||
1084 | functions->PointSize = i915PointSize; |
||
1085 | functions->PointParameterfv = i915PointParameterfv; |
||
1086 | functions->PolygonStipple = i915PolygonStipple; |
||
1087 | functions->RenderMode = i915RenderMode; |
||
1088 | functions->Scissor = i915Scissor; |
||
1089 | functions->ShadeModel = i915ShadeModel; |
||
1090 | functions->StencilFuncSeparate = i915StencilFuncSeparate; |
||
1091 | functions->StencilMaskSeparate = i915StencilMaskSeparate; |
||
1092 | functions->StencilOpSeparate = i915StencilOpSeparate; |
||
1093 | functions->DepthRange = i915DepthRange; |
||
1094 | functions->Viewport = i915Viewport; |
||
1095 | } |
||
1096 | |||
1097 | |||
1098 | void |
||
1099 | i915InitState(struct i915_context *i915) |
||
1100 | { |
||
1101 | struct gl_context *ctx = &i915->intel.ctx; |
||
1102 | |||
1103 | i915_init_packets(i915); |
||
1104 | |||
1105 | _mesa_init_driver_state(ctx); |
||
1106 | }><>><>><>><>><>><>><>>><>><>><>><>><>><>><>><>>>><>><>><>><>><>><>><>><> |