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 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
127 int cull
= ctx
->Polygon
.CullFaceMode
;
128 int front
= ctx
->Polygon
.FrontFace
;
130 nv04
->ctrl
[0] = NV04_TEXTURED_TRIANGLE_CONTROL_Z_FORMAT_FIXED
|
131 NV04_TEXTURED_TRIANGLE_CONTROL_ORIGIN_CORNER
;
136 if (ctx
->Color
.DitherFlag
)
137 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_DITHER_ENABLE
;
140 if (!ctx
->Polygon
.CullFlag
)
141 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_NONE
;
142 else if (cull
== GL_FRONT_AND_BACK
)
143 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_BOTH
;
145 nv04
->ctrl
[0] |= (cull
== GL_FRONT
) ^ (front
== GL_CCW
) ?
146 NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_CW
:
147 NV04_TEXTURED_TRIANGLE_CONTROL_CULL_MODE_CCW
;
150 if (ctx
->Depth
.Test
&& fb
->Visual
.depthBits
> 0)
151 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_ENABLE
;
152 if (ctx
->Depth
.Mask
&& fb
->Visual
.depthBits
> 0)
153 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_Z_WRITE
;
155 nv04
->ctrl
[0] |= get_comparison_op(ctx
->Depth
.Func
) << 16;
158 if (ctx
->Color
.AlphaEnabled
)
159 nv04
->ctrl
[0] |= NV04_TEXTURED_TRIANGLE_CONTROL_ALPHA_ENABLE
;
161 nv04
->ctrl
[0] |= get_comparison_op(ctx
->Color
.AlphaFunc
) << 8 |
162 FLOAT_TO_UBYTE(ctx
->Color
.AlphaRef
);
165 if (ctx
->Color
.ColorMask
[0][RCOMP
])
166 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_RED_WRITE
;
167 if (ctx
->Color
.ColorMask
[0][GCOMP
])
168 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_GREEN_WRITE
;
169 if (ctx
->Color
.ColorMask
[0][BCOMP
])
170 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_BLUE_WRITE
;
171 if (ctx
->Color
.ColorMask
[0][ACOMP
])
172 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_ALPHA_WRITE
;
175 if (ctx
->Stencil
.WriteMask
[0])
176 nv04
->ctrl
[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_STENCIL_WRITE
;
178 if (ctx
->Stencil
._Enabled
)
179 nv04
->ctrl
[1] |= NV04_MULTITEX_TRIANGLE_CONTROL1_STENCIL_ENABLE
;
181 nv04
->ctrl
[1] |= get_comparison_op(ctx
->Stencil
.Function
[0]) << 4 |
182 _mesa_get_stencil_ref(ctx
, 0) << 8 |
183 ctx
->Stencil
.ValueMask
[0] << 16 |
184 ctx
->Stencil
.WriteMask
[0] << 24;
186 nv04
->ctrl
[2] |= get_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) << 8 |
187 get_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) << 4 |
188 get_stencil_op(ctx
->Stencil
.FailFunc
[0]);
192 nv04_defer_blend(struct gl_context
*ctx
, int emit
)
194 context_dirty(ctx
, BLEND
);
198 nv04_emit_blend(struct gl_context
*ctx
, int emit
)
200 struct nv04_context
*nv04
= to_nv04_context(ctx
);
202 nv04
->blend
&= NV04_TEXTURED_TRIANGLE_BLEND_TEXTURE_MAP__MASK
;
203 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_MASK_BIT_MSB
|
204 NV04_TEXTURED_TRIANGLE_BLEND_TEXTURE_PERSPECTIVE_ENABLE
;
206 /* Alpha blending. */
207 nv04
->blend
|= get_blend_func(ctx
->Color
.Blend
[0].DstRGB
) << 28 |
208 get_blend_func(ctx
->Color
.Blend
[0].SrcRGB
) << 24;
210 if (ctx
->Color
.BlendEnabled
)
211 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_BLEND_ENABLE
;
214 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
)
215 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_GOURAUD
;
217 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SHADE_MODE_FLAT
;
219 /* Secondary color */
220 if (_mesa_need_secondary_color(ctx
))
221 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_SPECULAR_ENABLE
;
224 if (ctx
->Fog
.Enabled
) {
225 nv04
->blend
|= NV04_TEXTURED_TRIANGLE_BLEND_FOG_ENABLE
;
226 nv04
->fog
= pack_rgba_f(MESA_FORMAT_B8G8R8A8_UNORM
, ctx
->Fog
.Color
);