1 /**************************************************************************
3 Copyright 2007 Stephane Marchesin
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
27 #include "nouveau_context.h"
28 #include "nouveau_object.h"
29 #include "nouveau_fifo.h"
30 #include "nouveau_reg.h"
31 #include "nouveau_msg.h"
33 #include "tnl/t_pipeline.h"
38 static uint32_t nv04_compare_func(GLcontext
*ctx
,GLuint f
)
40 switch ( ctx
->Color
.AlphaFunc
) {
41 case GL_NEVER
: return 1;
42 case GL_LESS
: return 2;
43 case GL_EQUAL
: return 3;
44 case GL_LEQUAL
: return 4;
45 case GL_GREATER
: return 5;
46 case GL_NOTEQUAL
: return 6;
47 case GL_GEQUAL
: return 7;
48 case GL_ALWAYS
: return 8;
50 WARN_ONCE("Unable to find the function\n");
54 static uint32_t nv04_blend_func(GLcontext
*ctx
,GLuint f
)
56 switch ( ctx
->Color
.AlphaFunc
) {
57 case GL_ZERO
: return 0x1;
58 case GL_ONE
: return 0x2;
59 case GL_SRC_COLOR
: return 0x3;
60 case GL_ONE_MINUS_SRC_COLOR
: return 0x4;
61 case GL_SRC_ALPHA
: return 0x5;
62 case GL_ONE_MINUS_SRC_ALPHA
: return 0x6;
63 case GL_DST_ALPHA
: return 0x7;
64 case GL_ONE_MINUS_DST_ALPHA
: return 0x8;
65 case GL_DST_COLOR
: return 0x9;
66 case GL_ONE_MINUS_DST_COLOR
: return 0xA;
67 case GL_SRC_ALPHA_SATURATE
: return 0xB;
69 WARN_ONCE("Unable to find the function\n");
73 static void nv04_emit_control(GLcontext
*ctx
)
75 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
76 uint32_t control
,cull
;
79 CLAMPED_FLOAT_TO_UBYTE(alpha_ref
, ctx
->Color
.AlphaRef
);
81 control
|=(nv04_compare_func(ctx
,ctx
->Color
.AlphaFunc
)<<8);
82 control
|=(ctx
->Color
.AlphaEnabled
<<12);
84 control
|=(ctx
->Depth
.Test
<<14);
85 control
|=(nv04_compare_func(ctx
,ctx
->Depth
.Func
)<<16);
86 if ((ctx
->Polygon
.CullFlag
)&&(ctx
->Polygon
.CullFaceMode
!=GL_FRONT_AND_BACK
))
88 if ((ctx
->Polygon
.FrontFace
==GL_CW
)&&(ctx
->Polygon
.CullFaceMode
==GL_FRONT
))
90 if ((ctx
->Polygon
.FrontFace
==GL_CW
)&&(ctx
->Polygon
.CullFaceMode
==GL_BACK
))
92 if ((ctx
->Polygon
.FrontFace
==GL_CCW
)&&(ctx
->Polygon
.CullFaceMode
==GL_FRONT
))
94 if ((ctx
->Polygon
.FrontFace
==GL_CCW
)&&(ctx
->Polygon
.CullFaceMode
==GL_BACK
))
98 if (ctx
->Polygon
.CullFaceMode
==GL_FRONT_AND_BACK
)
103 control
|=(ctx
->Color
.DitherFlag
<<22);
104 if ((ctx
->Depth
.Test
)&&(ctx
->Depth
.Mask
))
107 control
|=(1<<30); // integer zbuffer format
109 BEGIN_RING_CACHE(NvSub3D
, NV04_DX5_TEXTURED_TRIANGLE_CONTROL
, 1);
110 OUT_RING_CACHE(control
);
113 static void nv04_emit_blend(GLcontext
*ctx
)
115 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
118 blend
=0x4; // texture MODULATE_ALPHA
119 blend
|=0x20; // alpha is MSB
120 switch(ctx
->Light
.ShadeModel
) {
121 case GL_SMOOTH
:blend
|=(1<<6);break;
122 case GL_FLAT
: blend
|=(2<<6);break;
125 if (ctx
->Hint
.PerspectiveCorrection
!=GL_FASTEST
)
127 blend
|=(ctx
->Fog
.Enabled
<<16);
128 blend
|=(ctx
->Color
.BlendEnabled
<<20);
129 blend
|=(nv04_blend_func(ctx
,ctx
->Color
.BlendSrcRGB
)<<24);
130 blend
|=(nv04_blend_func(ctx
,ctx
->Color
.BlendDstRGB
)<<28);
132 BEGIN_RING_CACHE(NvSub3D
, NV04_DX5_TEXTURED_TRIANGLE_BLEND
, 1);
133 OUT_RING_CACHE(blend
);
136 static void nv04_emit_fog_color(GLcontext
*ctx
)
138 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
140 c
[0] = FLOAT_TO_UBYTE( ctx
->Fog
.Color
[0] );
141 c
[1] = FLOAT_TO_UBYTE( ctx
->Fog
.Color
[1] );
142 c
[2] = FLOAT_TO_UBYTE( ctx
->Fog
.Color
[2] );
143 c
[3] = FLOAT_TO_UBYTE( ctx
->Fog
.Color
[3] );
144 BEGIN_RING_CACHE(NvSub3D
, NV04_DX5_TEXTURED_TRIANGLE_FOG_COLOR
, 1);
145 OUT_RING_CACHE(PACK_COLOR_8888_REV(c
[0],c
[1],c
[2],c
[3]));
148 static void nv04AlphaFunc(GLcontext
*ctx
, GLenum func
, GLfloat ref
)
150 nv04_emit_control(ctx
);
153 static void nv04BlendColor(GLcontext
*ctx
, const GLfloat color
[4])
155 nv04_emit_blend(ctx
);
158 static void nv04BlendEquationSeparate(GLcontext
*ctx
, GLenum modeRGB
, GLenum modeA
)
160 nv04_emit_blend(ctx
);
164 static void nv04BlendFuncSeparate(GLcontext
*ctx
, GLenum sfactorRGB
, GLenum dfactorRGB
,
165 GLenum sfactorA
, GLenum dfactorA
)
167 nv04_emit_blend(ctx
);
170 static void nv04Clear(GLcontext
*ctx
, GLbitfield mask
)
175 static void nv04ClearColor(GLcontext
*ctx
, const GLfloat color
[4])
180 static void nv04ClearDepth(GLcontext
*ctx
, GLclampd d
)
185 static void nv04ClearStencil(GLcontext
*ctx
, GLint s
)
190 static void nv04ClipPlane(GLcontext
*ctx
, GLenum plane
, const GLfloat
*equation
)
195 static void nv04ColorMask(GLcontext
*ctx
, GLboolean rmask
, GLboolean gmask
,
196 GLboolean bmask
, GLboolean amask
)
201 static void nv04ColorMaterial(GLcontext
*ctx
, GLenum face
, GLenum mode
)
203 /* TODO I need love */
206 static void nv04CullFace(GLcontext
*ctx
, GLenum mode
)
208 nv04_emit_control(ctx
);
211 static void nv04FrontFace(GLcontext
*ctx
, GLenum mode
)
216 static void nv04DepthFunc(GLcontext
*ctx
, GLenum func
)
218 nv04_emit_control(ctx
);
221 static void nv04DepthMask(GLcontext
*ctx
, GLboolean flag
)
226 static void nv04DepthRange(GLcontext
*ctx
, GLclampd nearval
, GLclampd farval
)
231 /** Specify the current buffer for writing */
232 //void (*DrawBuffer)( GLcontext *ctx, GLenum buffer );
233 /** Specify the buffers for writing for fragment programs*/
234 //void (*DrawBuffers)( GLcontext *ctx, GLsizei n, const GLenum *buffers );
236 static void nv04Enable(GLcontext
*ctx
, GLenum cap
, GLboolean state
)
241 nv04_emit_control(ctx
);
243 // case GL_AUTO_NORMAL:
245 nv04_emit_blend(ctx
);
247 // case GL_CLIP_PLANE0:
248 // case GL_CLIP_PLANE1:
249 // case GL_CLIP_PLANE2:
250 // case GL_CLIP_PLANE3:
251 // case GL_CLIP_PLANE4:
252 // case GL_CLIP_PLANE5:
253 // case GL_COLOR_LOGIC_OP:
254 // case GL_COLOR_MATERIAL:
255 // case GL_COLOR_SUM_EXT:
256 // case GL_COLOR_TABLE:
257 // case GL_CONVOLUTION_1D:
258 // case GL_CONVOLUTION_2D:
260 nv04_emit_control(ctx
);
263 nv04_emit_control(ctx
);
266 nv04_emit_control(ctx
);
269 nv04_emit_blend(ctx
);
271 // case GL_HISTOGRAM:
272 // case GL_INDEX_LOGIC_OP:
282 // case GL_LINE_SMOOTH:
283 // case GL_LINE_STIPPLE:
284 // case GL_MAP1_COLOR_4:
285 // case GL_MAP1_INDEX:
286 // case GL_MAP1_NORMAL:
287 // case GL_MAP1_TEXTURE_COORD_1:
288 // case GL_MAP1_TEXTURE_COORD_2:
289 // case GL_MAP1_TEXTURE_COORD_3:
290 // case GL_MAP1_TEXTURE_COORD_4:
291 // case GL_MAP1_VERTEX_3:
292 // case GL_MAP1_VERTEX_4:
293 // case GL_MAP2_COLOR_4:
294 // case GL_MAP2_INDEX:
295 // case GL_MAP2_NORMAL:
296 // case GL_MAP2_TEXTURE_COORD_1:
297 // case GL_MAP2_TEXTURE_COORD_2:
298 // case GL_MAP2_TEXTURE_COORD_3:
299 // case GL_MAP2_TEXTURE_COORD_4:
300 // case GL_MAP2_VERTEX_3:
301 // case GL_MAP2_VERTEX_4:
303 // case GL_NORMALIZE:
304 // case GL_POINT_SMOOTH:
305 // case GL_POLYGON_OFFSET_POINT:
306 // case GL_POLYGON_OFFSET_LINE:
307 // case GL_POLYGON_OFFSET_FILL:
308 // case GL_POLYGON_SMOOTH:
309 // case GL_POLYGON_STIPPLE:
310 // case GL_POST_COLOR_MATRIX_COLOR_TABLE:
311 // case GL_POST_CONVOLUTION_COLOR_TABLE:
312 // case GL_RESCALE_NORMAL:
313 // case GL_SCISSOR_TEST:
314 // case GL_SEPARABLE_2D:
315 // case GL_STENCIL_TEST:
316 // case GL_TEXTURE_GEN_Q:
317 // case GL_TEXTURE_GEN_R:
318 // case GL_TEXTURE_GEN_S:
319 // case GL_TEXTURE_GEN_T:
320 // case GL_TEXTURE_1D:
321 // case GL_TEXTURE_2D:
322 // case GL_TEXTURE_3D:
326 static void nv04Fogfv(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
328 nv04_emit_blend(ctx
);
329 nv04_emit_fog_color(ctx
);
332 static void nv04Hint(GLcontext
*ctx
, GLenum target
, GLenum mode
)
336 case GL_PERSPECTIVE_CORRECTION_HINT
:nv04_emit_blend(ctx
);break;
341 static void nv04LineStipple(GLcontext
*ctx
, GLint factor
, GLushort pattern
)
343 /* TODO not even in your dreams */
346 static void nv04LineWidth(GLcontext
*ctx
, GLfloat width
)
351 static void nv04LogicOpcode(GLcontext
*ctx
, GLenum opcode
)
356 static void nv04PointParameterfv(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
)
361 static void nv04PointSize(GLcontext
*ctx
, GLfloat size
)
366 static void nv04PolygonMode(GLcontext
*ctx
, GLenum face
, GLenum mode
)
371 /** Set the scale and units used to calculate depth values */
372 static void nv04PolygonOffset(GLcontext
*ctx
, GLfloat factor
, GLfloat units
)
377 /** Set the polygon stippling pattern */
378 static void nv04PolygonStipple(GLcontext
*ctx
, const GLubyte
*mask
)
383 /* Specifies the current buffer for reading */
384 void (*ReadBuffer
)( GLcontext
*ctx
, GLenum buffer
);
385 /** Set rasterization mode */
386 void (*RenderMode
)(GLcontext
*ctx
, GLenum mode
);
388 /** Define the scissor box */
389 static void nv04Scissor(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
394 /** Select flat or smooth shading */
395 static void nv04ShadeModel(GLcontext
*ctx
, GLenum mode
)
397 nv04_emit_blend(ctx
);
400 /** OpenGL 2.0 two-sided StencilFunc */
401 static void nv04StencilFuncSeparate(GLcontext
*ctx
, GLenum face
, GLenum func
,
402 GLint ref
, GLuint mask
)
407 /** OpenGL 2.0 two-sided StencilMask */
408 static void nv04StencilMaskSeparate(GLcontext
*ctx
, GLenum face
, GLuint mask
)
413 /** OpenGL 2.0 two-sided StencilOp */
414 static void nv04StencilOpSeparate(GLcontext
*ctx
, GLenum face
, GLenum fail
,
415 GLenum zfail
, GLenum zpass
)
420 /** Control the generation of texture coordinates */
421 void (*TexGen
)(GLcontext
*ctx
, GLenum coord
, GLenum pname
,
422 const GLfloat
*params
);
423 /** Set texture environment parameters */
424 void (*TexEnv
)(GLcontext
*ctx
, GLenum target
, GLenum pname
,
425 const GLfloat
*param
);
426 /** Set texture parameters */
427 void (*TexParameter
)(GLcontext
*ctx
, GLenum target
,
428 struct gl_texture_object
*texObj
,
429 GLenum pname
, const GLfloat
*params
);
431 /* Update anything that depends on the window position/size */
432 static void nv04WindowMoved(nouveauContextPtr nmesa
)
436 /* Initialise any card-specific non-GL related state */
437 static GLboolean
nv04InitCard(nouveauContextPtr nmesa
)
442 /* Update buffer offset/pitch/format */
443 static GLboolean
nv04BindBuffers(nouveauContextPtr nmesa
, int num_color
,
444 nouveau_renderbuffer
**color
,
445 nouveau_renderbuffer
*depth
)
450 void nv04InitStateFuncs(GLcontext
*ctx
, struct dd_function_table
*func
)
452 nouveauContextPtr nmesa
= NOUVEAU_CONTEXT(ctx
);
454 func
->AlphaFunc
= nv04AlphaFunc
;
455 func
->BlendColor
= nv04BlendColor
;
456 func
->BlendEquationSeparate
= nv04BlendEquationSeparate
;
457 func
->BlendFuncSeparate
= nv04BlendFuncSeparate
;
458 func
->Clear
= nv04Clear
;
459 func
->ClearColor
= nv04ClearColor
;
460 func
->ClearDepth
= nv04ClearDepth
;
461 func
->ClearStencil
= nv04ClearStencil
;
462 func
->ClipPlane
= nv04ClipPlane
;
463 func
->ColorMask
= nv04ColorMask
;
464 func
->ColorMaterial
= nv04ColorMaterial
;
465 func
->CullFace
= nv04CullFace
;
466 func
->FrontFace
= nv04FrontFace
;
467 func
->DepthFunc
= nv04DepthFunc
;
468 func
->DepthMask
= nv04DepthMask
;
469 func
->DepthRange
= nv04DepthRange
;
470 func
->Enable
= nv04Enable
;
471 func
->Fogfv
= nv04Fogfv
;
472 func
->Hint
= nv04Hint
;
473 /* func->Lightfv = nv04Lightfv;*/
474 /* func->LightModelfv = nv04LightModelfv; */
475 func
->LineStipple
= nv04LineStipple
; /* Not for NV04 */
476 func
->LineWidth
= nv04LineWidth
;
477 func
->LogicOpcode
= nv04LogicOpcode
;
478 func
->PointParameterfv
= nv04PointParameterfv
;
479 func
->PointSize
= nv04PointSize
;
480 func
->PolygonMode
= nv04PolygonMode
;
481 func
->PolygonOffset
= nv04PolygonOffset
;
482 func
->PolygonStipple
= nv04PolygonStipple
; /* Not for NV04 */
483 /* func->ReadBuffer = nv04ReadBuffer;*/
484 /* func->RenderMode = nv04RenderMode;*/
485 func
->Scissor
= nv04Scissor
;
486 func
->ShadeModel
= nv04ShadeModel
;
487 func
->StencilFuncSeparate
= nv04StencilFuncSeparate
;
488 func
->StencilMaskSeparate
= nv04StencilMaskSeparate
;
489 func
->StencilOpSeparate
= nv04StencilOpSeparate
;
490 /* func->TexGen = nv04TexGen;*/
491 /* func->TexParameter = nv04TexParameter;*/
492 /* func->TextureMatrix = nv04TextureMatrix;*/
494 nmesa
->hw_func
.InitCard
= nv04InitCard
;
495 nmesa
->hw_func
.BindBuffers
= nv04BindBuffers
;
496 nmesa
->hw_func
.WindowMoved
= nv04WindowMoved
;