2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_texture.h"
30 #include "nouveau_util.h"
32 #include "swrast/swrast.h"
34 #include "util/bitscan.h"
35 #include "main/framebuffer.h"
38 nouveau_alpha_func(struct gl_context
*ctx
, GLenum func
, GLfloat ref
)
40 context_dirty(ctx
, ALPHA_FUNC
);
44 nouveau_blend_color(struct gl_context
*ctx
, const GLfloat color
[4])
46 context_dirty(ctx
, BLEND_COLOR
);
50 nouveau_blend_equation_separate(struct gl_context
*ctx
, GLenum modeRGB
, GLenum modeA
)
52 context_dirty(ctx
, BLEND_EQUATION
);
56 nouveau_blend_func_separate(struct gl_context
*ctx
, GLenum sfactorRGB
,
57 GLenum dfactorRGB
, GLenum sfactorA
, GLenum dfactorA
)
59 context_dirty(ctx
, BLEND_FUNC
);
63 nouveau_clip_plane(struct gl_context
*ctx
, GLenum plane
, const GLfloat
*equation
)
65 context_dirty_i(ctx
, CLIP_PLANE
, plane
- GL_CLIP_PLANE0
);
69 nouveau_color_mask(struct gl_context
*ctx
, GLboolean rmask
, GLboolean gmask
,
70 GLboolean bmask
, GLboolean amask
)
72 context_dirty(ctx
, COLOR_MASK
);
76 nouveau_color_material(struct gl_context
*ctx
, GLenum face
, GLenum mode
)
78 context_dirty(ctx
, COLOR_MATERIAL
);
79 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
80 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
81 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
82 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
83 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
84 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
88 nouveau_cull_face(struct gl_context
*ctx
, GLenum mode
)
90 context_dirty(ctx
, CULL_FACE
);
94 nouveau_front_face(struct gl_context
*ctx
, GLenum mode
)
96 context_dirty(ctx
, FRONT_FACE
);
100 nouveau_depth_func(struct gl_context
*ctx
, GLenum func
)
102 context_dirty(ctx
, DEPTH
);
106 nouveau_depth_mask(struct gl_context
*ctx
, GLboolean flag
)
108 context_dirty(ctx
, DEPTH
);
112 nouveau_read_buffer(struct gl_context
*ctx
, GLenum buffer
)
114 nouveau_validate_framebuffer(ctx
);
118 nouveau_draw_buffers(struct gl_context
*ctx
, GLsizei n
, const GLenum
*buffers
)
120 nouveau_validate_framebuffer(ctx
);
121 context_dirty(ctx
, FRAMEBUFFER
);
125 nouveau_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
131 context_dirty(ctx
, ALPHA_FUNC
);
134 context_dirty(ctx
, BLEND_EQUATION
);
136 case GL_COLOR_LOGIC_OP
:
137 context_dirty(ctx
, LOGIC_OPCODE
);
139 case GL_COLOR_MATERIAL
:
140 context_dirty(ctx
, COLOR_MATERIAL
);
141 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
142 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
143 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
144 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
145 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
146 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
148 case GL_COLOR_SUM_EXT
:
149 context_dirty(ctx
, FRAG
);
150 context_dirty(ctx
, LIGHT_MODEL
);
153 context_dirty(ctx
, CULL_FACE
);
156 context_dirty(ctx
, DEPTH
);
159 context_dirty(ctx
, DITHER
);
162 context_dirty(ctx
, FOG
);
163 context_dirty(ctx
, FRAG
);
164 context_dirty(ctx
, MODELVIEW
);
174 context_dirty(ctx
, MODELVIEW
);
175 context_dirty(ctx
, LIGHT_ENABLE
);
176 context_dirty_i(ctx
, LIGHT_SOURCE
, cap
- GL_LIGHT0
);
177 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
178 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
179 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
180 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
181 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
182 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
183 context_dirty(ctx
, MATERIAL_FRONT_SHININESS
);
184 context_dirty(ctx
, MATERIAL_BACK_SHININESS
);
187 context_dirty(ctx
, FRAG
);
188 context_dirty(ctx
, MODELVIEW
);
189 context_dirty(ctx
, LIGHT_MODEL
);
190 context_dirty(ctx
, LIGHT_ENABLE
);
192 mask
= ctx
->Light
._EnabledLights
;
194 const int i
= u_bit_scan(&mask
);
195 context_dirty_i(ctx
, LIGHT_SOURCE
, i
);
198 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
199 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
200 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
201 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
202 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
203 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
204 context_dirty(ctx
, MATERIAL_FRONT_SHININESS
);
205 context_dirty(ctx
, MATERIAL_BACK_SHININESS
);
208 context_dirty(ctx
, LINE_MODE
);
211 context_dirty(ctx
, LIGHT_ENABLE
);
213 case GL_POINT_SMOOTH
:
214 context_dirty(ctx
, POINT_MODE
);
216 case GL_POLYGON_OFFSET_POINT
:
217 case GL_POLYGON_OFFSET_LINE
:
218 case GL_POLYGON_OFFSET_FILL
:
219 context_dirty(ctx
, POLYGON_OFFSET
);
221 case GL_POLYGON_SMOOTH
:
222 context_dirty(ctx
, POLYGON_MODE
);
224 case GL_SCISSOR_TEST
:
225 context_dirty(ctx
, SCISSOR
);
227 case GL_STENCIL_TEST
:
228 context_dirty(ctx
, STENCIL_FUNC
);
233 case GL_TEXTURE_RECTANGLE
:
234 context_dirty_i(ctx
, TEX_ENV
, ctx
->Texture
.CurrentUnit
);
235 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
237 case GL_TEXTURE_GEN_S
:
238 case GL_TEXTURE_GEN_T
:
239 case GL_TEXTURE_GEN_R
:
240 case GL_TEXTURE_GEN_Q
:
241 context_dirty_i(ctx
, TEX_GEN
, ctx
->Texture
.CurrentUnit
);
242 context_dirty(ctx
, MODELVIEW
);
248 nouveau_fog(struct gl_context
*ctx
, GLenum pname
, const GLfloat
*params
)
250 context_dirty(ctx
, FOG
);
254 nouveau_light(struct gl_context
*ctx
, GLenum light
, GLenum pname
, const GLfloat
*params
)
258 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
259 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
262 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
263 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
266 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
267 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
271 context_dirty(ctx
, MODELVIEW
);
272 context_dirty(ctx
, LIGHT_ENABLE
);
273 context_dirty_i(ctx
, LIGHT_SOURCE
, light
- GL_LIGHT0
);
276 context_dirty_i(ctx
, LIGHT_SOURCE
, light
- GL_LIGHT0
);
282 nouveau_light_model(struct gl_context
*ctx
, GLenum pname
, const GLfloat
*params
)
284 context_dirty(ctx
, LIGHT_MODEL
);
285 context_dirty(ctx
, MODELVIEW
);
289 nouveau_line_stipple(struct gl_context
*ctx
, GLint factor
, GLushort pattern
)
291 context_dirty(ctx
, LINE_STIPPLE
);
295 nouveau_line_width(struct gl_context
*ctx
, GLfloat width
)
297 context_dirty(ctx
, LINE_MODE
);
301 nouveau_logic_opcode(struct gl_context
*ctx
, GLenum opcode
)
303 context_dirty(ctx
, LOGIC_OPCODE
);
307 nouveau_point_parameter(struct gl_context
*ctx
, GLenum pname
, const GLfloat
*params
)
309 context_dirty(ctx
, POINT_PARAMETER
);
313 nouveau_point_size(struct gl_context
*ctx
, GLfloat size
)
315 context_dirty(ctx
, POINT_MODE
);
319 nouveau_polygon_mode(struct gl_context
*ctx
, GLenum face
, GLenum mode
)
321 context_dirty(ctx
, POLYGON_MODE
);
325 nouveau_polygon_offset(struct gl_context
*ctx
, GLfloat factor
, GLfloat units
, GLfloat clamp
)
327 context_dirty(ctx
, POLYGON_OFFSET
);
331 nouveau_polygon_stipple(struct gl_context
*ctx
, const GLubyte
*mask
)
333 context_dirty(ctx
, POLYGON_STIPPLE
);
337 nouveau_render_mode(struct gl_context
*ctx
, GLenum mode
)
339 context_dirty(ctx
, RENDER_MODE
);
343 nouveau_shade_model(struct gl_context
*ctx
, GLenum mode
)
345 context_dirty(ctx
, SHADE_MODEL
);
349 nouveau_stencil_func_separate(struct gl_context
*ctx
, GLenum face
, GLenum func
,
350 GLint ref
, GLuint mask
)
352 context_dirty(ctx
, STENCIL_FUNC
);
356 nouveau_stencil_mask_separate(struct gl_context
*ctx
, GLenum face
, GLuint mask
)
358 context_dirty(ctx
, STENCIL_MASK
);
362 nouveau_stencil_op_separate(struct gl_context
*ctx
, GLenum face
, GLenum fail
,
363 GLenum zfail
, GLenum zpass
)
365 context_dirty(ctx
, STENCIL_OP
);
369 nouveau_tex_gen(struct gl_context
*ctx
, GLenum coord
, GLenum pname
,
370 const GLfloat
*params
)
373 case GL_TEXTURE_GEN_MODE
:
374 context_dirty_i(ctx
, TEX_GEN
, ctx
->Texture
.CurrentUnit
);
375 context_dirty(ctx
, MODELVIEW
);
378 context_dirty_i(ctx
, TEX_GEN
, ctx
->Texture
.CurrentUnit
);
384 nouveau_tex_env(struct gl_context
*ctx
, GLenum target
, GLenum pname
,
385 const GLfloat
*param
)
388 case GL_TEXTURE_FILTER_CONTROL_EXT
:
389 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
392 context_dirty_i(ctx
, TEX_ENV
, ctx
->Texture
.CurrentUnit
);
398 nouveau_tex_parameter(struct gl_context
*ctx
,
399 struct gl_texture_object
*t
, GLenum pname
)
402 case GL_TEXTURE_MAG_FILTER
:
403 case GL_TEXTURE_WRAP_S
:
404 case GL_TEXTURE_WRAP_T
:
405 case GL_TEXTURE_WRAP_R
:
406 case GL_TEXTURE_MIN_LOD
:
407 case GL_TEXTURE_MAX_LOD
:
408 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
409 case GL_TEXTURE_LOD_BIAS
:
410 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
413 case GL_TEXTURE_MIN_FILTER
:
414 case GL_TEXTURE_BASE_LEVEL
:
415 case GL_TEXTURE_MAX_LEVEL
:
416 nouveau_texture_reallocate(ctx
, t
);
417 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
423 nouveau_emit_nothing(struct gl_context
*ctx
, int emit
)
428 nouveau_next_dirty_state(struct gl_context
*ctx
)
430 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
431 int i
= BITSET_FFS(nctx
->dirty
) - 1;
433 if (i
< 0 || i
>= context_drv(ctx
)->num_emit
)
440 nouveau_state_emit(struct gl_context
*ctx
)
442 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
443 const struct nouveau_driver
*drv
= context_drv(ctx
);
446 while ((i
= nouveau_next_dirty_state(ctx
)) >= 0) {
447 BITSET_CLEAR(nctx
->dirty
, i
);
448 drv
->emit
[i
](ctx
, i
);
451 BITSET_ZERO(nctx
->dirty
);
455 nouveau_update_state(struct gl_context
*ctx
)
457 GLbitfield new_state
= ctx
->NewState
;
460 if (new_state
& (_NEW_SCISSOR
| _NEW_BUFFERS
| _NEW_VIEWPORT
))
461 _mesa_update_draw_buffer_bounds(ctx
, ctx
->DrawBuffer
);
463 if (new_state
& (_NEW_PROJECTION
| _NEW_MODELVIEW
))
464 context_dirty(ctx
, PROJECTION
);
466 if (new_state
& _NEW_MODELVIEW
)
467 context_dirty(ctx
, MODELVIEW
);
469 if (new_state
& _NEW_TEXTURE_MATRIX
) {
470 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
471 context_dirty_i(ctx
, TEX_MAT
, i
);
474 if (new_state
& _NEW_SCISSOR
)
475 context_dirty(ctx
, SCISSOR
);
477 if (new_state
& _NEW_VIEWPORT
)
478 context_dirty(ctx
, VIEWPORT
);
480 if (new_state
& _NEW_CURRENT_ATTRIB
&&
481 new_state
& _NEW_LIGHT
) {
482 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
483 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
484 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
485 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
486 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
487 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
488 context_dirty(ctx
, MATERIAL_FRONT_SHININESS
);
489 context_dirty(ctx
, MATERIAL_BACK_SHININESS
);
492 if (new_state
& _NEW_TEXTURE
) {
493 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
494 if (ctx
->Texture
.Unit
[i
].Sampler
)
495 context_dirty_i(ctx
, TEX_OBJ
, i
);
499 _swrast_InvalidateState(ctx
, new_state
);
500 _tnl_InvalidateState(ctx
, new_state
);
502 nouveau_state_emit(ctx
);
506 nouveau_state_init(struct gl_context
*ctx
)
508 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
510 ctx
->Driver
.AlphaFunc
= nouveau_alpha_func
;
511 ctx
->Driver
.BlendColor
= nouveau_blend_color
;
512 ctx
->Driver
.BlendEquationSeparate
= nouveau_blend_equation_separate
;
513 ctx
->Driver
.BlendFuncSeparate
= nouveau_blend_func_separate
;
514 ctx
->Driver
.ClipPlane
= nouveau_clip_plane
;
515 ctx
->Driver
.ColorMask
= nouveau_color_mask
;
516 ctx
->Driver
.ColorMaterial
= nouveau_color_material
;
517 ctx
->Driver
.CullFace
= nouveau_cull_face
;
518 ctx
->Driver
.FrontFace
= nouveau_front_face
;
519 ctx
->Driver
.DepthFunc
= nouveau_depth_func
;
520 ctx
->Driver
.DepthMask
= nouveau_depth_mask
;
521 ctx
->Driver
.ReadBuffer
= nouveau_read_buffer
;
522 ctx
->Driver
.DrawBuffers
= nouveau_draw_buffers
;
523 ctx
->Driver
.Enable
= nouveau_enable
;
524 ctx
->Driver
.Fogfv
= nouveau_fog
;
525 ctx
->Driver
.Lightfv
= nouveau_light
;
526 ctx
->Driver
.LightModelfv
= nouveau_light_model
;
527 ctx
->Driver
.LineStipple
= nouveau_line_stipple
;
528 ctx
->Driver
.LineWidth
= nouveau_line_width
;
529 ctx
->Driver
.LogicOpcode
= nouveau_logic_opcode
;
530 ctx
->Driver
.PointParameterfv
= nouveau_point_parameter
;
531 ctx
->Driver
.PointSize
= nouveau_point_size
;
532 ctx
->Driver
.PolygonMode
= nouveau_polygon_mode
;
533 ctx
->Driver
.PolygonOffset
= nouveau_polygon_offset
;
534 ctx
->Driver
.PolygonStipple
= nouveau_polygon_stipple
;
535 ctx
->Driver
.RenderMode
= nouveau_render_mode
;
536 ctx
->Driver
.ShadeModel
= nouveau_shade_model
;
537 ctx
->Driver
.StencilFuncSeparate
= nouveau_stencil_func_separate
;
538 ctx
->Driver
.StencilMaskSeparate
= nouveau_stencil_mask_separate
;
539 ctx
->Driver
.StencilOpSeparate
= nouveau_stencil_op_separate
;
540 ctx
->Driver
.TexGen
= nouveau_tex_gen
;
541 ctx
->Driver
.TexEnv
= nouveau_tex_env
;
542 ctx
->Driver
.TexParameter
= nouveau_tex_parameter
;
544 ctx
->Driver
.UpdateState
= nouveau_update_state
;
546 BITSET_ONES(nctx
->dirty
);