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"
33 #include "main/stencil.h"
36 get_comparison_op(unsigned op
)
61 get_stencil_op(unsigned op
)
86 get_blend_func(unsigned func
)
95 case GL_ONE_MINUS_SRC_COLOR
:
99 case GL_ONE_MINUS_SRC_ALPHA
:
103 case GL_ONE_MINUS_DST_ALPHA
:
107 case GL_ONE_MINUS_DST_COLOR
:
109 case GL_SRC_ALPHA_SATURATE
:
117 nv04_defer_control(struct gl_context
*ctx
, int emit
)
119 context_dirty(ctx
, CONTROL
);
123 nv04_emit_control(struct gl_context
*ctx
, int emit
)
125 struct nv04_context
*nv04
= to_nv04_context(ctx
);
126 int cull
= ctx
->Polygon
.CullFaceMode
;
127 int front
= ctx
->Polygon
.FrontFace
;
129 nv04
->ctrl
[0] = NV04_TEXTURED_TRIANGLE_CONTROL_Z_FORMAT_FIXED
|
130 NV04_TEXTURED_TRIANGLE_CONTROL_ORIGIN_CORNER
;
135 if (ctx
->Color
.DitherFlag
)
136 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_DITHER_ENABLE
;
139 if (!ctx
->Polygon
.CullFlag
)
140 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_NONE
;
141 else if (cull
== GL_FRONT_AND_BACK
)
142 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_BOTH
;
144 nv04
->ctrl
[0] |= (cull
== GL_FRONT
) ^ (front
== GL_CCW
) ?
145 NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_CW
:
146 NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_CCW
;
150 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_ENABLE
;
152 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_WRITE
;
154 nv04
->ctrl
[0] |= get_comparison_op(ctx
->Depth
.Func
) << 16;
157 if (ctx
->Color
.AlphaEnabled
)
158 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_ALPHA_ENABLE
;
160 nv04
->ctrl
[0] |= get_comparison_op(ctx
->Color
.AlphaFunc
) << 8 |
161 FLOAT_TO_UBYTE(ctx
->Color
.AlphaRef
);
164 if (ctx
->Color
.ColorMask
[0][RCOMP
])
165 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_RED_WRITE
;
166 if (ctx
->Color
.ColorMask
[0][GCOMP
])
167 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_GREEN_WRITE
;
168 if (ctx
->Color
.ColorMask
[0][BCOMP
])
169 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_BLUE_WRITE
;
170 if (ctx
->Color
.ColorMask
[0][ACOMP
])
171 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_ALPHA_WRITE
;
174 if (ctx
->Stencil
.WriteMask
[0])
175 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_STENCIL_WRITE
;
177 if (ctx
->Stencil
.Enabled
)
178 nv04
->ctrl
[1] |= NV04_MULTITEX_TRIANGLE_CONTROL1_STENCIL_ENABLE
;
180 nv04
->ctrl
[1] |= get_comparison_op(ctx
->Stencil
.Function
[0]) << 4 |
181 _mesa_get_stencil_ref(ctx
, 0) << 8 |
182 ctx
->Stencil
.ValueMask
[0] << 16 |
183 ctx
->Stencil
.WriteMask
[0] << 24;
185 nv04
->ctrl
[2] |= get_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) << 8 |
186 get_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) << 4 |
187 get_stencil_op(ctx
->Stencil
.FailFunc
[0]);
191 nv04_defer_blend(struct gl_context
*ctx
, int emit
)
193 context_dirty(ctx
, BLEND
);
197 nv04_emit_blend(struct gl_context
*ctx
, int emit
)
199 struct nv04_context
*nv04
= to_nv04_context(ctx
);
201 nv04
->blend
&= NV04_TEXTURED_TRIANGLE_BLEND_TEXTURE_MAP__MASK
;
202 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_MASK_BIT_MSB
|
203 NV04_TEXTURED_TRIANGLE_BLEND_TEXTURE_PERSPECTIVE_ENABLE
;
205 /* Alpha blending. */
206 nv04
->blend
|= get_blend_func(ctx
->Color
.Blend
[0].DstRGB
) << 28 |
207 get_blend_func(ctx
->Color
.Blend
[0].SrcRGB
) << 24;
209 if (ctx
->Color
.BlendEnabled
)
210 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_BLEND_ENABLE
;
213 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
)
214 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_GOURAUD
;
216 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_FLAT
;
218 /* Secondary color */
219 if (_mesa_need_secondary_color(ctx
))
220 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SPECULAR_ENABLE
;
223 if (ctx
->Fog
.Enabled
) {
224 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_FOG_ENABLE
;
225 nv04
->fog
= pack_rgba_f(MESA_FORMAT_B8G8R8A8_UNORM
, ctx
->Fog
.Color
);