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"
36 nouveau_alpha_func(GLcontext
*ctx
, GLenum func
, GLfloat ref
)
38 context_dirty(ctx
, ALPHA_FUNC
);
42 nouveau_blend_color(GLcontext
*ctx
, const GLfloat color
[4])
44 context_dirty(ctx
, BLEND_COLOR
);
48 nouveau_blend_equation_separate(GLcontext
*ctx
, GLenum modeRGB
, GLenum modeA
)
50 context_dirty(ctx
, BLEND_EQUATION
);
54 nouveau_blend_func_separate(GLcontext
*ctx
, GLenum sfactorRGB
,
55 GLenum dfactorRGB
, GLenum sfactorA
, GLenum dfactorA
)
57 context_dirty(ctx
, BLEND_FUNC
);
61 nouveau_clip_plane(GLcontext
*ctx
, GLenum plane
, const GLfloat
*equation
)
63 context_dirty_i(ctx
, CLIP_PLANE
, plane
- GL_CLIP_PLANE0
);
67 nouveau_color_mask(GLcontext
*ctx
, GLboolean rmask
, GLboolean gmask
,
68 GLboolean bmask
, GLboolean amask
)
70 context_dirty(ctx
, COLOR_MASK
);
74 nouveau_color_material(GLcontext
*ctx
, GLenum face
, GLenum mode
)
76 context_dirty(ctx
, COLOR_MATERIAL
);
77 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
78 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
79 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
80 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
81 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
82 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
86 nouveau_cull_face(GLcontext
*ctx
, GLenum mode
)
88 context_dirty(ctx
, CULL_FACE
);
92 nouveau_front_face(GLcontext
*ctx
, GLenum mode
)
94 context_dirty(ctx
, FRONT_FACE
);
98 nouveau_depth_func(GLcontext
*ctx
, GLenum func
)
100 context_dirty(ctx
, DEPTH
);
104 nouveau_depth_mask(GLcontext
*ctx
, GLboolean flag
)
106 context_dirty(ctx
, DEPTH
);
110 nouveau_depth_range(GLcontext
*ctx
, GLclampd nearval
, GLclampd farval
)
112 context_dirty(ctx
, VIEWPORT
);
116 nouveau_draw_buffer(GLcontext
*ctx
, GLenum buffer
)
118 context_dirty(ctx
, FRAMEBUFFER
);
122 nouveau_draw_buffers(GLcontext
*ctx
, GLsizei n
, const GLenum
*buffers
)
124 context_dirty(ctx
, FRAMEBUFFER
);
128 nouveau_enable(GLcontext
*ctx
, GLenum cap
, GLboolean state
)
134 context_dirty(ctx
, ALPHA_FUNC
);
137 context_dirty(ctx
, BLEND_EQUATION
);
139 case GL_COLOR_LOGIC_OP
:
140 context_dirty(ctx
, LOGIC_OPCODE
);
142 case GL_COLOR_MATERIAL
:
143 context_dirty(ctx
, COLOR_MATERIAL
);
144 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
145 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
146 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
147 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
148 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
149 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
151 case GL_COLOR_SUM_EXT
:
152 context_dirty(ctx
, FRAG
);
153 context_dirty(ctx
, LIGHT_MODEL
);
156 context_dirty(ctx
, CULL_FACE
);
159 context_dirty(ctx
, DEPTH
);
162 context_dirty(ctx
, DITHER
);
165 context_dirty(ctx
, FOG
);
166 context_dirty(ctx
, FRAG
);
167 context_dirty(ctx
, MODELVIEW
);
177 context_dirty(ctx
, MODELVIEW
);
178 context_dirty(ctx
, LIGHT_ENABLE
);
179 context_dirty_i(ctx
, LIGHT_SOURCE
, cap
- GL_LIGHT0
);
180 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
181 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
182 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
183 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
184 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
185 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
186 context_dirty(ctx
, MATERIAL_FRONT_SHININESS
);
187 context_dirty(ctx
, MATERIAL_BACK_SHININESS
);
190 context_dirty(ctx
, FRAG
);
191 context_dirty(ctx
, MODELVIEW
);
192 context_dirty(ctx
, LIGHT_ENABLE
);
194 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
195 if (ctx
->Light
.Light
[i
].Enabled
)
196 context_dirty_i(ctx
, LIGHT_SOURCE
, i
);
199 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
200 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
201 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
202 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
203 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
204 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
205 context_dirty(ctx
, MATERIAL_FRONT_SHININESS
);
206 context_dirty(ctx
, MATERIAL_BACK_SHININESS
);
209 context_dirty(ctx
, LINE_MODE
);
212 context_dirty(ctx
, LIGHT_ENABLE
);
214 case GL_POINT_SMOOTH
:
215 context_dirty(ctx
, POINT_MODE
);
217 case GL_POLYGON_OFFSET_POINT
:
218 case GL_POLYGON_OFFSET_LINE
:
219 case GL_POLYGON_OFFSET_FILL
:
220 context_dirty(ctx
, POLYGON_OFFSET
);
222 case GL_POLYGON_SMOOTH
:
223 context_dirty(ctx
, POLYGON_MODE
);
225 case GL_SCISSOR_TEST
:
226 context_dirty(ctx
, SCISSOR
);
228 case GL_STENCIL_TEST
:
229 context_dirty(ctx
, STENCIL_FUNC
);
234 context_dirty_i(ctx
, TEX_ENV
, ctx
->Texture
.CurrentUnit
);
235 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
241 nouveau_fog(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
243 context_dirty(ctx
, FOG
);
247 nouveau_light(GLcontext
*ctx
, GLenum light
, GLenum pname
, const GLfloat
*params
)
251 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
252 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
255 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
256 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
259 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
260 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
264 context_dirty(ctx
, MODELVIEW
);
265 context_dirty(ctx
, LIGHT_ENABLE
);
266 context_dirty_i(ctx
, LIGHT_SOURCE
, light
- GL_LIGHT0
);
269 context_dirty_i(ctx
, LIGHT_SOURCE
, light
- GL_LIGHT0
);
275 nouveau_light_model(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
277 context_dirty(ctx
, LIGHT_MODEL
);
278 context_dirty(ctx
, MODELVIEW
);
282 nouveau_line_stipple(GLcontext
*ctx
, GLint factor
, GLushort pattern
)
284 context_dirty(ctx
, LINE_STIPPLE
);
288 nouveau_line_width(GLcontext
*ctx
, GLfloat width
)
290 context_dirty(ctx
, LINE_MODE
);
294 nouveau_logic_opcode(GLcontext
*ctx
, GLenum opcode
)
296 context_dirty(ctx
, LOGIC_OPCODE
);
300 nouveau_point_parameter(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
302 context_dirty(ctx
, POINT_PARAMETER
);
306 nouveau_point_size(GLcontext
*ctx
, GLfloat size
)
308 context_dirty(ctx
, POINT_MODE
);
312 nouveau_polygon_mode(GLcontext
*ctx
, GLenum face
, GLenum mode
)
314 context_dirty(ctx
, POLYGON_MODE
);
318 nouveau_polygon_offset(GLcontext
*ctx
, GLfloat factor
, GLfloat units
)
320 context_dirty(ctx
, POLYGON_OFFSET
);
324 nouveau_polygon_stipple(GLcontext
*ctx
, const GLubyte
*mask
)
326 context_dirty(ctx
, POLYGON_STIPPLE
);
330 nouveau_render_mode(GLcontext
*ctx
, GLenum mode
)
332 context_dirty(ctx
, RENDER_MODE
);
336 nouveau_scissor(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
338 context_dirty(ctx
, SCISSOR
);
342 nouveau_shade_model(GLcontext
*ctx
, GLenum mode
)
344 context_dirty(ctx
, SHADE_MODEL
);
348 nouveau_stencil_func_separate(GLcontext
*ctx
, GLenum face
, GLenum func
,
349 GLint ref
, GLuint mask
)
351 context_dirty(ctx
, STENCIL_FUNC
);
355 nouveau_stencil_mask_separate(GLcontext
*ctx
, GLenum face
, GLuint mask
)
357 context_dirty(ctx
, STENCIL_MASK
);
361 nouveau_stencil_op_separate(GLcontext
*ctx
, GLenum face
, GLenum fail
,
362 GLenum zfail
, GLenum zpass
)
364 context_dirty(ctx
, STENCIL_OP
);
368 nouveau_tex_gen(GLcontext
*ctx
, GLenum coord
, GLenum pname
,
369 const GLfloat
*params
)
371 context_dirty_i(ctx
, TEX_GEN
, ctx
->Texture
.CurrentUnit
);
375 nouveau_tex_env(GLcontext
*ctx
, GLenum target
, GLenum pname
,
376 const GLfloat
*param
)
379 case GL_TEXTURE_FILTER_CONTROL_EXT
:
380 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
383 context_dirty_i(ctx
, TEX_ENV
, ctx
->Texture
.CurrentUnit
);
389 nouveau_tex_parameter(GLcontext
*ctx
, GLenum target
,
390 struct gl_texture_object
*t
, GLenum pname
,
391 const GLfloat
*params
)
394 case GL_TEXTURE_MAG_FILTER
:
395 case GL_TEXTURE_WRAP_S
:
396 case GL_TEXTURE_WRAP_T
:
397 case GL_TEXTURE_WRAP_R
:
398 case GL_TEXTURE_MIN_LOD
:
399 case GL_TEXTURE_MAX_LOD
:
400 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
401 case GL_TEXTURE_LOD_BIAS
:
402 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
405 case GL_TEXTURE_MIN_FILTER
:
406 case GL_TEXTURE_BASE_LEVEL
:
407 case GL_TEXTURE_MAX_LEVEL
:
408 nouveau_texture_reallocate(ctx
, t
);
409 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
415 nouveau_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
417 context_dirty(ctx
, VIEWPORT
);
421 nouveau_emit_nothing(GLcontext
*ctx
, int emit
)
426 nouveau_next_dirty_state(GLcontext
*ctx
)
428 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
429 int i
= BITSET_FFS(nctx
->dirty
) - 1;
431 if (i
< 0 || i
>= context_drv(ctx
)->num_emit
)
438 nouveau_state_emit(GLcontext
*ctx
)
440 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
441 const struct nouveau_driver
*drv
= context_drv(ctx
);
444 while ((i
= nouveau_next_dirty_state(ctx
)) >= 0) {
445 BITSET_CLEAR(nctx
->dirty
, i
);
446 drv
->emit
[i
](ctx
, i
);
449 BITSET_ZERO(nctx
->dirty
);
451 nouveau_bo_state_emit(ctx
);
455 nouveau_update_state(GLcontext
*ctx
, GLbitfield new_state
)
457 if (new_state
& (_NEW_PROJECTION
| _NEW_MODELVIEW
))
458 context_dirty(ctx
, PROJECTION
);
460 if (new_state
& _NEW_MODELVIEW
)
461 context_dirty(ctx
, MODELVIEW
);
463 if (new_state
& _NEW_CURRENT_ATTRIB
&&
464 new_state
& _NEW_LIGHT
) {
465 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
466 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
467 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
468 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
469 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
470 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
471 context_dirty(ctx
, MATERIAL_FRONT_SHININESS
);
472 context_dirty(ctx
, MATERIAL_BACK_SHININESS
);
475 _swrast_InvalidateState(ctx
, new_state
);
476 _tnl_InvalidateState(ctx
, new_state
);
478 nouveau_state_emit(ctx
);
482 nouveau_state_init(GLcontext
*ctx
)
484 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
486 ctx
->Driver
.AlphaFunc
= nouveau_alpha_func
;
487 ctx
->Driver
.BlendColor
= nouveau_blend_color
;
488 ctx
->Driver
.BlendEquationSeparate
= nouveau_blend_equation_separate
;
489 ctx
->Driver
.BlendFuncSeparate
= nouveau_blend_func_separate
;
490 ctx
->Driver
.ClipPlane
= nouveau_clip_plane
;
491 ctx
->Driver
.ColorMask
= nouveau_color_mask
;
492 ctx
->Driver
.ColorMaterial
= nouveau_color_material
;
493 ctx
->Driver
.CullFace
= nouveau_cull_face
;
494 ctx
->Driver
.FrontFace
= nouveau_front_face
;
495 ctx
->Driver
.DepthFunc
= nouveau_depth_func
;
496 ctx
->Driver
.DepthMask
= nouveau_depth_mask
;
497 ctx
->Driver
.DepthRange
= nouveau_depth_range
;
498 ctx
->Driver
.DrawBuffer
= nouveau_draw_buffer
;
499 ctx
->Driver
.DrawBuffers
= nouveau_draw_buffers
;
500 ctx
->Driver
.Enable
= nouveau_enable
;
501 ctx
->Driver
.Fogfv
= nouveau_fog
;
502 ctx
->Driver
.Lightfv
= nouveau_light
;
503 ctx
->Driver
.LightModelfv
= nouveau_light_model
;
504 ctx
->Driver
.LineStipple
= nouveau_line_stipple
;
505 ctx
->Driver
.LineWidth
= nouveau_line_width
;
506 ctx
->Driver
.LogicOpcode
= nouveau_logic_opcode
;
507 ctx
->Driver
.PointParameterfv
= nouveau_point_parameter
;
508 ctx
->Driver
.PointSize
= nouveau_point_size
;
509 ctx
->Driver
.PolygonMode
= nouveau_polygon_mode
;
510 ctx
->Driver
.PolygonOffset
= nouveau_polygon_offset
;
511 ctx
->Driver
.PolygonStipple
= nouveau_polygon_stipple
;
512 ctx
->Driver
.RenderMode
= nouveau_render_mode
;
513 ctx
->Driver
.Scissor
= nouveau_scissor
;
514 ctx
->Driver
.ShadeModel
= nouveau_shade_model
;
515 ctx
->Driver
.StencilFuncSeparate
= nouveau_stencil_func_separate
;
516 ctx
->Driver
.StencilMaskSeparate
= nouveau_stencil_mask_separate
;
517 ctx
->Driver
.StencilOpSeparate
= nouveau_stencil_op_separate
;
518 ctx
->Driver
.TexGen
= nouveau_tex_gen
;
519 ctx
->Driver
.TexEnv
= nouveau_tex_env
;
520 ctx
->Driver
.TexParameter
= nouveau_tex_parameter
;
521 ctx
->Driver
.Viewport
= nouveau_viewport
;
523 ctx
->Driver
.UpdateState
= nouveau_update_state
;
525 BITSET_ONES(nctx
->dirty
);