Merge git://proxy01.pd.intel.com:9419/git/mesa/mesa into crestline
[mesa.git] / src / mesa / drivers / dri / i965 / intel_state.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "glheader.h"
30 #include "context.h"
31 #include "macros.h"
32 #include "enums.h"
33 #include "colormac.h"
34 #include "dd.h"
35
36 #include "intel_screen.h"
37 #include "intel_context.h"
38 #include "intel_regions.h"
39 #include "swrast/swrast.h"
40
41 int intel_translate_compare_func( GLenum func )
42 {
43 switch(func) {
44 case GL_NEVER:
45 return COMPAREFUNC_NEVER;
46 case GL_LESS:
47 return COMPAREFUNC_LESS;
48 case GL_LEQUAL:
49 return COMPAREFUNC_LEQUAL;
50 case GL_GREATER:
51 return COMPAREFUNC_GREATER;
52 case GL_GEQUAL:
53 return COMPAREFUNC_GEQUAL;
54 case GL_NOTEQUAL:
55 return COMPAREFUNC_NOTEQUAL;
56 case GL_EQUAL:
57 return COMPAREFUNC_EQUAL;
58 case GL_ALWAYS:
59 return COMPAREFUNC_ALWAYS;
60 }
61
62 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, func);
63 return COMPAREFUNC_ALWAYS;
64 }
65
66 int intel_translate_stencil_op( GLenum op )
67 {
68 switch(op) {
69 case GL_KEEP:
70 return STENCILOP_KEEP;
71 case GL_ZERO:
72 return STENCILOP_ZERO;
73 case GL_REPLACE:
74 return STENCILOP_REPLACE;
75 case GL_INCR:
76 return STENCILOP_INCRSAT;
77 case GL_DECR:
78 return STENCILOP_DECRSAT;
79 case GL_INCR_WRAP:
80 return STENCILOP_INCR;
81 case GL_DECR_WRAP:
82 return STENCILOP_DECR;
83 case GL_INVERT:
84 return STENCILOP_INVERT;
85 default:
86 return STENCILOP_ZERO;
87 }
88 }
89
90 int intel_translate_blend_factor( GLenum factor )
91 {
92 switch(factor) {
93 case GL_ZERO:
94 return BLENDFACT_ZERO;
95 case GL_SRC_ALPHA:
96 return BLENDFACT_SRC_ALPHA;
97 case GL_ONE:
98 return BLENDFACT_ONE;
99 case GL_SRC_COLOR:
100 return BLENDFACT_SRC_COLR;
101 case GL_ONE_MINUS_SRC_COLOR:
102 return BLENDFACT_INV_SRC_COLR;
103 case GL_DST_COLOR:
104 return BLENDFACT_DST_COLR;
105 case GL_ONE_MINUS_DST_COLOR:
106 return BLENDFACT_INV_DST_COLR;
107 case GL_ONE_MINUS_SRC_ALPHA:
108 return BLENDFACT_INV_SRC_ALPHA;
109 case GL_DST_ALPHA:
110 return BLENDFACT_DST_ALPHA;
111 case GL_ONE_MINUS_DST_ALPHA:
112 return BLENDFACT_INV_DST_ALPHA;
113 case GL_SRC_ALPHA_SATURATE:
114 return BLENDFACT_SRC_ALPHA_SATURATE;
115 case GL_CONSTANT_COLOR:
116 return BLENDFACT_CONST_COLOR;
117 case GL_ONE_MINUS_CONSTANT_COLOR:
118 return BLENDFACT_INV_CONST_COLOR;
119 case GL_CONSTANT_ALPHA:
120 return BLENDFACT_CONST_ALPHA;
121 case GL_ONE_MINUS_CONSTANT_ALPHA:
122 return BLENDFACT_INV_CONST_ALPHA;
123 }
124
125 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, factor);
126 return BLENDFACT_ZERO;
127 }
128
129 int intel_translate_logic_op( GLenum opcode )
130 {
131 switch(opcode) {
132 case GL_CLEAR:
133 return LOGICOP_CLEAR;
134 case GL_AND:
135 return LOGICOP_AND;
136 case GL_AND_REVERSE:
137 return LOGICOP_AND_RVRSE;
138 case GL_COPY:
139 return LOGICOP_COPY;
140 case GL_COPY_INVERTED:
141 return LOGICOP_COPY_INV;
142 case GL_AND_INVERTED:
143 return LOGICOP_AND_INV;
144 case GL_NOOP:
145 return LOGICOP_NOOP;
146 case GL_XOR:
147 return LOGICOP_XOR;
148 case GL_OR:
149 return LOGICOP_OR;
150 case GL_OR_INVERTED:
151 return LOGICOP_OR_INV;
152 case GL_NOR:
153 return LOGICOP_NOR;
154 case GL_EQUIV:
155 return LOGICOP_EQUIV;
156 case GL_INVERT:
157 return LOGICOP_INV;
158 case GL_OR_REVERSE:
159 return LOGICOP_OR_RVRSE;
160 case GL_NAND:
161 return LOGICOP_NAND;
162 case GL_SET:
163 return LOGICOP_SET;
164 default:
165 return LOGICOP_SET;
166 }
167 }
168
169
170 static void intelClearColor(GLcontext *ctx, const GLfloat color[4])
171 {
172 struct intel_context *intel = intel_context(ctx);
173 intelScreenPrivate *screen = intel->intelScreen;
174
175 UNCLAMPED_FLOAT_TO_RGBA_CHAN(intel->clear_chan, color);
176
177 intel->ClearColor = INTEL_PACKCOLOR(screen->fbFormat,
178 intel->clear_chan[0],
179 intel->clear_chan[1],
180 intel->clear_chan[2],
181 intel->clear_chan[3]);
182 }
183
184
185
186 /* Fallback to swrast for select and feedback.
187 */
188 static void intelRenderMode( GLcontext *ctx, GLenum mode )
189 {
190 struct intel_context *intel = intel_context(ctx);
191 FALLBACK( intel, INTEL_FALLBACK_RENDERMODE, (mode != GL_RENDER) );
192 }
193
194
195 void intelInitStateFuncs( struct dd_function_table *functions )
196 {
197 functions->RenderMode = intelRenderMode;
198 functions->ClearColor = intelClearColor;
199 }
200
201
202
203
204 void intelInitState( GLcontext *ctx )
205 {
206 /* Mesa should do this for us:
207 */
208 ctx->Driver.AlphaFunc( ctx,
209 ctx->Color.AlphaFunc,
210 ctx->Color.AlphaRef);
211
212 ctx->Driver.BlendColor( ctx,
213 ctx->Color.BlendColor );
214
215 ctx->Driver.BlendEquationSeparate( ctx,
216 ctx->Color.BlendEquationRGB,
217 ctx->Color.BlendEquationA);
218
219 ctx->Driver.BlendFuncSeparate( ctx,
220 ctx->Color.BlendSrcRGB,
221 ctx->Color.BlendDstRGB,
222 ctx->Color.BlendSrcA,
223 ctx->Color.BlendDstA);
224
225 ctx->Driver.ColorMask( ctx,
226 ctx->Color.ColorMask[RCOMP],
227 ctx->Color.ColorMask[GCOMP],
228 ctx->Color.ColorMask[BCOMP],
229 ctx->Color.ColorMask[ACOMP]);
230
231 ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
232 ctx->Driver.DepthFunc( ctx, ctx->Depth.Func );
233 ctx->Driver.DepthMask( ctx, ctx->Depth.Mask );
234
235 ctx->Driver.Enable( ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled );
236 ctx->Driver.Enable( ctx, GL_BLEND, ctx->Color.BlendEnabled );
237 ctx->Driver.Enable( ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled );
238 ctx->Driver.Enable( ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled );
239 ctx->Driver.Enable( ctx, GL_CULL_FACE, ctx->Polygon.CullFlag );
240 ctx->Driver.Enable( ctx, GL_DEPTH_TEST, ctx->Depth.Test );
241 ctx->Driver.Enable( ctx, GL_DITHER, ctx->Color.DitherFlag );
242 ctx->Driver.Enable( ctx, GL_FOG, ctx->Fog.Enabled );
243 ctx->Driver.Enable( ctx, GL_LIGHTING, ctx->Light.Enabled );
244 ctx->Driver.Enable( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
245 ctx->Driver.Enable( ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag );
246 ctx->Driver.Enable( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
247 ctx->Driver.Enable( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
248 ctx->Driver.Enable( ctx, GL_TEXTURE_1D, GL_FALSE );
249 ctx->Driver.Enable( ctx, GL_TEXTURE_2D, GL_FALSE );
250 ctx->Driver.Enable( ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE );
251 ctx->Driver.Enable( ctx, GL_TEXTURE_3D, GL_FALSE );
252 ctx->Driver.Enable( ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE );
253
254 ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color );
255 ctx->Driver.Fogfv( ctx, GL_FOG_MODE, 0 );
256 ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
257 ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start );
258 ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End );
259
260 ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
261
262 {
263 GLfloat f = (GLfloat)ctx->Light.Model.ColorControl;
264 ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f );
265 }
266
267 ctx->Driver.LineWidth( ctx, ctx->Line.Width );
268 ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
269 ctx->Driver.PointSize( ctx, ctx->Point.Size );
270 ctx->Driver.PolygonStipple( ctx, (const GLubyte *)ctx->PolygonStipple );
271 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
272 ctx->Scissor.Width, ctx->Scissor.Height );
273 ctx->Driver.ShadeModel( ctx, ctx->Light.ShadeModel );
274 ctx->Driver.StencilFuncSeparate( ctx, GL_FRONT,
275 ctx->Stencil.Function[0],
276 ctx->Stencil.Ref[0],
277 ctx->Stencil.ValueMask[0] );
278 ctx->Driver.StencilFuncSeparate( ctx, GL_BACK,
279 ctx->Stencil.Function[1],
280 ctx->Stencil.Ref[1],
281 ctx->Stencil.ValueMask[1] );
282 ctx->Driver.StencilMaskSeparate( ctx, GL_FRONT, ctx->Stencil.WriteMask[0] );
283 ctx->Driver.StencilMaskSeparate( ctx, GL_BACK, ctx->Stencil.WriteMask[1] );
284 ctx->Driver.StencilOpSeparate( ctx, GL_FRONT,
285 ctx->Stencil.FailFunc[0],
286 ctx->Stencil.ZFailFunc[0],
287 ctx->Stencil.ZPassFunc[0]);
288 ctx->Driver.StencilOpSeparate( ctx, GL_BACK,
289 ctx->Stencil.FailFunc[1],
290 ctx->Stencil.ZFailFunc[1],
291 ctx->Stencil.ZPassFunc[1]);
292
293
294 ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] );
295 }