1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
36 #include "intel_screen.h"
37 #include "intel_context.h"
38 #include "intel_regions.h"
39 #include "swrast/swrast.h"
41 int intel_translate_compare_func( GLenum func
)
45 return COMPAREFUNC_NEVER
;
47 return COMPAREFUNC_LESS
;
49 return COMPAREFUNC_LEQUAL
;
51 return COMPAREFUNC_GREATER
;
53 return COMPAREFUNC_GEQUAL
;
55 return COMPAREFUNC_NOTEQUAL
;
57 return COMPAREFUNC_EQUAL
;
59 return COMPAREFUNC_ALWAYS
;
62 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, func
);
63 return COMPAREFUNC_ALWAYS
;
66 int intel_translate_stencil_op( GLenum op
)
70 return STENCILOP_KEEP
;
72 return STENCILOP_ZERO
;
74 return STENCILOP_REPLACE
;
76 return STENCILOP_INCRSAT
;
78 return STENCILOP_DECRSAT
;
80 return STENCILOP_INCR
;
82 return STENCILOP_DECR
;
84 return STENCILOP_INVERT
;
86 return STENCILOP_ZERO
;
90 int intel_translate_blend_factor( GLenum factor
)
94 return BLENDFACT_ZERO
;
96 return BLENDFACT_SRC_ALPHA
;
100 return BLENDFACT_SRC_COLR
;
101 case GL_ONE_MINUS_SRC_COLOR
:
102 return BLENDFACT_INV_SRC_COLR
;
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
;
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
;
125 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, factor
);
126 return BLENDFACT_ZERO
;
129 int intel_translate_logic_op( GLenum opcode
)
133 return LOGICOP_CLEAR
;
137 return LOGICOP_AND_RVRSE
;
140 case GL_COPY_INVERTED
:
141 return LOGICOP_COPY_INV
;
142 case GL_AND_INVERTED
:
143 return LOGICOP_AND_INV
;
151 return LOGICOP_OR_INV
;
155 return LOGICOP_EQUIV
;
159 return LOGICOP_OR_RVRSE
;
170 static void intelClearColor(GLcontext
*ctx
, const GLfloat color
[4])
172 struct intel_context
*intel
= intel_context(ctx
);
173 intelScreenPrivate
*screen
= intel
->intelScreen
;
175 UNCLAMPED_FLOAT_TO_RGBA_CHAN(intel
->clear_chan
, color
);
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]);
186 /* Fallback to swrast for select and feedback.
188 static void intelRenderMode( GLcontext
*ctx
, GLenum mode
)
190 struct intel_context
*intel
= intel_context(ctx
);
191 FALLBACK( intel
, INTEL_FALLBACK_RENDERMODE
, (mode
!= GL_RENDER
) );
195 void intelInitStateFuncs( struct dd_function_table
*functions
)
197 functions
->RenderMode
= intelRenderMode
;
198 functions
->ClearColor
= intelClearColor
;
204 void intelInitState( GLcontext
*ctx
)
206 /* Mesa should do this for us:
208 ctx
->Driver
.AlphaFunc( ctx
,
209 ctx
->Color
.AlphaFunc
,
210 ctx
->Color
.AlphaRef
);
212 ctx
->Driver
.BlendColor( ctx
,
213 ctx
->Color
.BlendColor
);
215 ctx
->Driver
.BlendEquationSeparate( ctx
,
216 ctx
->Color
.BlendEquationRGB
,
217 ctx
->Color
.BlendEquationA
);
219 ctx
->Driver
.BlendFuncSeparate( ctx
,
220 ctx
->Color
.BlendSrcRGB
,
221 ctx
->Color
.BlendDstRGB
,
222 ctx
->Color
.BlendSrcA
,
223 ctx
->Color
.BlendDstA
);
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
]);
231 ctx
->Driver
.CullFace( ctx
, ctx
->Polygon
.CullFaceMode
);
232 ctx
->Driver
.DepthFunc( ctx
, ctx
->Depth
.Func
);
233 ctx
->Driver
.DepthMask( ctx
, ctx
->Depth
.Mask
);
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
);
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
);
260 ctx
->Driver
.FrontFace( ctx
, ctx
->Polygon
.FrontFace
);
263 GLfloat f
= (GLfloat
)ctx
->Light
.Model
.ColorControl
;
264 ctx
->Driver
.LightModelfv( ctx
, GL_LIGHT_MODEL_COLOR_CONTROL
, &f
);
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],
277 ctx
->Stencil
.ValueMask
[0] );
278 ctx
->Driver
.StencilFuncSeparate( ctx
, GL_BACK
,
279 ctx
->Stencil
.Function
[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]);
294 ctx
->Driver
.DrawBuffer( ctx
, ctx
->Color
.DrawBuffer
[0] );