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
);
155 context_dirty(ctx
, CULL_FACE
);
158 context_dirty(ctx
, DEPTH
);
161 context_dirty(ctx
, DITHER
);
164 context_dirty(ctx
, FOG
);
165 context_dirty(ctx
, FRAG
);
166 context_dirty(ctx
, MODELVIEW
);
176 context_dirty(ctx
, MODELVIEW
);
177 context_dirty(ctx
, LIGHT_ENABLE
);
178 context_dirty_i(ctx
, LIGHT_SOURCE
, cap
- GL_LIGHT0
);
179 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
180 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
181 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
182 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
183 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
184 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
185 context_dirty(ctx
, MATERIAL_FRONT_SHININESS
);
186 context_dirty(ctx
, MATERIAL_BACK_SHININESS
);
189 context_dirty(ctx
, FRAG
);
190 context_dirty(ctx
, MODELVIEW
);
191 context_dirty(ctx
, LIGHT_ENABLE
);
193 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
194 if (ctx
->Light
.Light
[i
].Enabled
)
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 context_dirty_i(ctx
, TEX_ENV
, ctx
->Texture
.CurrentUnit
);
234 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
240 nouveau_fog(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
242 context_dirty(ctx
, FOG
);
246 nouveau_light(GLcontext
*ctx
, GLenum light
, GLenum pname
, const GLfloat
*params
)
250 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
251 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
254 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
255 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
258 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
259 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
263 context_dirty(ctx
, MODELVIEW
);
264 context_dirty(ctx
, LIGHT_ENABLE
);
265 context_dirty_i(ctx
, LIGHT_SOURCE
, light
- GL_LIGHT0
);
268 context_dirty_i(ctx
, LIGHT_SOURCE
, light
- GL_LIGHT0
);
274 nouveau_light_model(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
276 context_dirty(ctx
, LIGHT_MODEL
);
277 context_dirty(ctx
, MODELVIEW
);
281 nouveau_line_stipple(GLcontext
*ctx
, GLint factor
, GLushort pattern
)
283 context_dirty(ctx
, LINE_STIPPLE
);
287 nouveau_line_width(GLcontext
*ctx
, GLfloat width
)
289 context_dirty(ctx
, LINE_MODE
);
293 nouveau_logic_opcode(GLcontext
*ctx
, GLenum opcode
)
295 context_dirty(ctx
, LOGIC_OPCODE
);
299 nouveau_point_parameter(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
301 context_dirty(ctx
, POINT_PARAMETER
);
305 nouveau_point_size(GLcontext
*ctx
, GLfloat size
)
307 context_dirty(ctx
, POINT_MODE
);
311 nouveau_polygon_mode(GLcontext
*ctx
, GLenum face
, GLenum mode
)
313 context_dirty(ctx
, POLYGON_MODE
);
317 nouveau_polygon_offset(GLcontext
*ctx
, GLfloat factor
, GLfloat units
)
319 context_dirty(ctx
, POLYGON_OFFSET
);
323 nouveau_polygon_stipple(GLcontext
*ctx
, const GLubyte
*mask
)
325 context_dirty(ctx
, POLYGON_STIPPLE
);
329 nouveau_render_mode(GLcontext
*ctx
, GLenum mode
)
331 context_dirty(ctx
, RENDER_MODE
);
335 nouveau_scissor(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
337 context_dirty(ctx
, SCISSOR
);
341 nouveau_shade_model(GLcontext
*ctx
, GLenum mode
)
343 context_dirty(ctx
, SHADE_MODEL
);
347 nouveau_stencil_func_separate(GLcontext
*ctx
, GLenum face
, GLenum func
,
348 GLint ref
, GLuint mask
)
350 context_dirty(ctx
, STENCIL_FUNC
);
354 nouveau_stencil_mask_separate(GLcontext
*ctx
, GLenum face
, GLuint mask
)
356 context_dirty(ctx
, STENCIL_MASK
);
360 nouveau_stencil_op_separate(GLcontext
*ctx
, GLenum face
, GLenum fail
,
361 GLenum zfail
, GLenum zpass
)
363 context_dirty(ctx
, STENCIL_OP
);
367 nouveau_tex_gen(GLcontext
*ctx
, GLenum coord
, GLenum pname
,
368 const GLfloat
*params
)
370 context_dirty_i(ctx
, TEX_GEN
, ctx
->Texture
.CurrentUnit
);
374 nouveau_tex_env(GLcontext
*ctx
, GLenum target
, GLenum pname
,
375 const GLfloat
*param
)
378 case GL_TEXTURE_FILTER_CONTROL_EXT
:
379 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
382 context_dirty_i(ctx
, TEX_ENV
, ctx
->Texture
.CurrentUnit
);
388 nouveau_tex_parameter(GLcontext
*ctx
, GLenum target
,
389 struct gl_texture_object
*t
, GLenum pname
,
390 const GLfloat
*params
)
393 case GL_TEXTURE_MAG_FILTER
:
394 case GL_TEXTURE_WRAP_S
:
395 case GL_TEXTURE_WRAP_T
:
396 case GL_TEXTURE_WRAP_R
:
397 case GL_TEXTURE_MIN_LOD
:
398 case GL_TEXTURE_MAX_LOD
:
399 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
400 case GL_TEXTURE_LOD_BIAS
:
401 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
404 case GL_TEXTURE_MIN_FILTER
:
405 case GL_TEXTURE_BASE_LEVEL
:
406 case GL_TEXTURE_MAX_LEVEL
:
407 nouveau_texture_reallocate(ctx
, t
);
408 context_dirty_i(ctx
, TEX_OBJ
, ctx
->Texture
.CurrentUnit
);
414 nouveau_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
416 context_dirty(ctx
, VIEWPORT
);
420 nouveau_emit_nothing(GLcontext
*ctx
, int emit
)
425 nouveau_next_dirty_state(GLcontext
*ctx
)
427 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
428 int i
= BITSET_FFS(nctx
->dirty
) - 1;
430 if (i
< 0 || i
>= context_drv(ctx
)->num_emit
)
437 nouveau_state_emit(GLcontext
*ctx
)
439 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
440 const struct nouveau_driver
*drv
= context_drv(ctx
);
443 while ((i
= nouveau_next_dirty_state(ctx
)) >= 0) {
444 BITSET_CLEAR(nctx
->dirty
, i
);
445 drv
->emit
[i
](ctx
, i
);
448 BITSET_ZERO(nctx
->dirty
);
450 nouveau_bo_state_emit(ctx
);
454 nouveau_update_state(GLcontext
*ctx
, GLbitfield new_state
)
456 if (new_state
& (_NEW_PROJECTION
| _NEW_MODELVIEW
))
457 context_dirty(ctx
, PROJECTION
);
459 if (new_state
& _NEW_MODELVIEW
)
460 context_dirty(ctx
, MODELVIEW
);
462 if (new_state
& _NEW_CURRENT_ATTRIB
&&
463 new_state
& _NEW_LIGHT
) {
464 context_dirty(ctx
, MATERIAL_FRONT_AMBIENT
);
465 context_dirty(ctx
, MATERIAL_BACK_AMBIENT
);
466 context_dirty(ctx
, MATERIAL_FRONT_DIFFUSE
);
467 context_dirty(ctx
, MATERIAL_BACK_DIFFUSE
);
468 context_dirty(ctx
, MATERIAL_FRONT_SPECULAR
);
469 context_dirty(ctx
, MATERIAL_BACK_SPECULAR
);
470 context_dirty(ctx
, MATERIAL_FRONT_SHININESS
);
471 context_dirty(ctx
, MATERIAL_BACK_SHININESS
);
474 _swrast_InvalidateState(ctx
, new_state
);
475 _tnl_InvalidateState(ctx
, new_state
);
477 nouveau_state_emit(ctx
);
481 nouveau_state_init(GLcontext
*ctx
)
483 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
485 ctx
->Driver
.AlphaFunc
= nouveau_alpha_func
;
486 ctx
->Driver
.BlendColor
= nouveau_blend_color
;
487 ctx
->Driver
.BlendEquationSeparate
= nouveau_blend_equation_separate
;
488 ctx
->Driver
.BlendFuncSeparate
= nouveau_blend_func_separate
;
489 ctx
->Driver
.ClipPlane
= nouveau_clip_plane
;
490 ctx
->Driver
.ColorMask
= nouveau_color_mask
;
491 ctx
->Driver
.ColorMaterial
= nouveau_color_material
;
492 ctx
->Driver
.CullFace
= nouveau_cull_face
;
493 ctx
->Driver
.FrontFace
= nouveau_front_face
;
494 ctx
->Driver
.DepthFunc
= nouveau_depth_func
;
495 ctx
->Driver
.DepthMask
= nouveau_depth_mask
;
496 ctx
->Driver
.DepthRange
= nouveau_depth_range
;
497 ctx
->Driver
.DrawBuffer
= nouveau_draw_buffer
;
498 ctx
->Driver
.DrawBuffers
= nouveau_draw_buffers
;
499 ctx
->Driver
.Enable
= nouveau_enable
;
500 ctx
->Driver
.Fogfv
= nouveau_fog
;
501 ctx
->Driver
.Lightfv
= nouveau_light
;
502 ctx
->Driver
.LightModelfv
= nouveau_light_model
;
503 ctx
->Driver
.LineStipple
= nouveau_line_stipple
;
504 ctx
->Driver
.LineWidth
= nouveau_line_width
;
505 ctx
->Driver
.LogicOpcode
= nouveau_logic_opcode
;
506 ctx
->Driver
.PointParameterfv
= nouveau_point_parameter
;
507 ctx
->Driver
.PointSize
= nouveau_point_size
;
508 ctx
->Driver
.PolygonMode
= nouveau_polygon_mode
;
509 ctx
->Driver
.PolygonOffset
= nouveau_polygon_offset
;
510 ctx
->Driver
.PolygonStipple
= nouveau_polygon_stipple
;
511 ctx
->Driver
.RenderMode
= nouveau_render_mode
;
512 ctx
->Driver
.Scissor
= nouveau_scissor
;
513 ctx
->Driver
.ShadeModel
= nouveau_shade_model
;
514 ctx
->Driver
.StencilFuncSeparate
= nouveau_stencil_func_separate
;
515 ctx
->Driver
.StencilMaskSeparate
= nouveau_stencil_mask_separate
;
516 ctx
->Driver
.StencilOpSeparate
= nouveau_stencil_op_separate
;
517 ctx
->Driver
.TexGen
= nouveau_tex_gen
;
518 ctx
->Driver
.TexEnv
= nouveau_tex_env
;
519 ctx
->Driver
.TexParameter
= nouveau_tex_parameter
;
520 ctx
->Driver
.Viewport
= nouveau_viewport
;
522 ctx
->Driver
.UpdateState
= nouveau_update_state
;
524 BITSET_ONES(nctx
->dirty
);