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_util.h"
30 #include "nv_object.xml.h"
31 #include "nv04_3d.xml.h"
32 #include "nv04_driver.h"
35 get_comparison_op(unsigned op
)
60 get_stencil_op(unsigned op
)
85 get_blend_func(unsigned func
)
94 case GL_ONE_MINUS_SRC_COLOR
:
98 case GL_ONE_MINUS_SRC_ALPHA
:
102 case GL_ONE_MINUS_DST_ALPHA
:
106 case GL_ONE_MINUS_DST_COLOR
:
108 case GL_SRC_ALPHA_SATURATE
:
116 nv04_defer_control(struct gl_context
*ctx
, int emit
)
118 context_dirty(ctx
, CONTROL
);
122 nv04_emit_control(struct gl_context
*ctx
, int emit
)
124 struct nv04_context
*nv04
= to_nv04_context(ctx
);
125 int cull
= ctx
->Polygon
.CullFaceMode
;
126 int front
= ctx
->Polygon
.FrontFace
;
128 nv04
->ctrl
[0] = NV04_TEXTURED_TRIANGLE_CONTROL_Z_FORMAT_FIXED
|
129 NV04_TEXTURED_TRIANGLE_CONTROL_ORIGIN_CORNER
;
134 if (ctx
->Color
.DitherFlag
)
135 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_DITHER_ENABLE
;
138 if (!ctx
->Polygon
.CullFlag
)
139 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_NONE
;
140 else if (cull
== GL_FRONT_AND_BACK
)
141 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_BOTH
;
143 nv04
->ctrl
[0] |= (cull
== GL_FRONT
) ^ (front
== GL_CCW
) ?
144 NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_CW
:
145 NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_CCW
;
149 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_ENABLE
;
151 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_WRITE
;
153 nv04
->ctrl
[0] |= get_comparison_op(ctx
->Depth
.Func
) << 16;
156 if (ctx
->Color
.AlphaEnabled
)
157 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_ALPHA_ENABLE
;
159 nv04
->ctrl
[0] |= get_comparison_op(ctx
->Color
.AlphaFunc
) << 8 |
160 FLOAT_TO_UBYTE(ctx
->Color
.AlphaRef
);
163 if (ctx
->Color
.ColorMask
[0][RCOMP
])
164 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_RED_WRITE
;
165 if (ctx
->Color
.ColorMask
[0][GCOMP
])
166 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_GREEN_WRITE
;
167 if (ctx
->Color
.ColorMask
[0][BCOMP
])
168 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_BLUE_WRITE
;
169 if (ctx
->Color
.ColorMask
[0][ACOMP
])
170 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_ALPHA_WRITE
;
173 if (ctx
->Stencil
.WriteMask
[0])
174 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_STENCIL_WRITE
;
176 if (ctx
->Stencil
.Enabled
)
177 nv04
->ctrl
[1] |= NV04_MULTITEX_TRIANGLE_CONTROL1_STENCIL_ENABLE
;
179 nv04
->ctrl
[1] |= get_comparison_op(ctx
->Stencil
.Function
[0]) << 4 |
180 ctx
->Stencil
.Ref
[0] << 8 |
181 ctx
->Stencil
.ValueMask
[0] << 16 |
182 ctx
->Stencil
.WriteMask
[0] << 24;
184 nv04
->ctrl
[2] |= get_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) << 8 |
185 get_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) << 4 |
186 get_stencil_op(ctx
->Stencil
.FailFunc
[0]);
190 nv04_defer_blend(struct gl_context
*ctx
, int emit
)
192 context_dirty(ctx
, BLEND
);
196 nv04_emit_blend(struct gl_context
*ctx
, int emit
)
198 struct nv04_context
*nv04
= to_nv04_context(ctx
);
200 nv04
->blend
&= NV04_TEXTURED_TRIANGLE_BLEND_TEXTURE_MAP__MASK
;
201 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_MASK_BIT_MSB
|
202 NV04_TEXTURED_TRIANGLE_BLEND_TEXTURE_PERSPECTIVE_ENABLE
;
204 /* Alpha blending. */
205 nv04
->blend
|= get_blend_func(ctx
->Color
.Blend
[0].DstRGB
) << 28 |
206 get_blend_func(ctx
->Color
.Blend
[0].SrcRGB
) << 24;
208 if (ctx
->Color
.BlendEnabled
)
209 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_BLEND_ENABLE
;
212 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
)
213 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_GOURAUD
;
215 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_FLAT
;
217 /* Secondary color */
218 if (_mesa_need_secondary_color(ctx
))
219 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SPECULAR_ENABLE
;
222 if (ctx
->Fog
.Enabled
) {
223 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_FOG_ENABLE
;
224 nv04
->fog
= pack_rgba_f(MESA_FORMAT_ARGB8888
, ctx
->Fog
.Color
);