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]);
185 static void intelCalcViewport( GLcontext
*ctx
)
187 struct intel_context
*intel
= intel_context(ctx
);
188 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
189 GLfloat
*m
= intel
->ViewportMatrix
.m
;
192 if (intel
->driDrawable
)
193 h
= intel
->driDrawable
->h
+ SUBPIXEL_Y
;
195 /* See also intel_translate_vertex. SUBPIXEL adjustments can be done
196 * via state vars, too.
198 m
[MAT_SX
] = v
[MAT_SX
];
199 m
[MAT_TX
] = v
[MAT_TX
] + SUBPIXEL_X
;
200 m
[MAT_SY
] = - v
[MAT_SY
];
201 m
[MAT_TY
] = - v
[MAT_TY
] + h
;
202 m
[MAT_SZ
] = v
[MAT_SZ
] * intel
->depth_scale
;
203 m
[MAT_TZ
] = v
[MAT_TZ
] * intel
->depth_scale
;
206 static void intelViewport( GLcontext
*ctx
,
208 GLsizei width
, GLsizei height
)
210 intelCalcViewport( ctx
);
213 static void intelDepthRange( GLcontext
*ctx
,
214 GLclampd nearval
, GLclampd farval
)
216 intelCalcViewport( ctx
);
219 /* Fallback to swrast for select and feedback.
221 static void intelRenderMode( GLcontext
*ctx
, GLenum mode
)
223 struct intel_context
*intel
= intel_context(ctx
);
224 FALLBACK( intel
, INTEL_FALLBACK_RENDERMODE
, (mode
!= GL_RENDER
) );
228 void intelInitStateFuncs( struct dd_function_table
*functions
)
230 functions
->RenderMode
= intelRenderMode
;
231 functions
->Viewport
= intelViewport
;
232 functions
->DepthRange
= intelDepthRange
;
233 functions
->ClearColor
= intelClearColor
;
239 void intelInitState( GLcontext
*ctx
)
241 /* Mesa should do this for us:
243 ctx
->Driver
.AlphaFunc( ctx
,
244 ctx
->Color
.AlphaFunc
,
245 ctx
->Color
.AlphaRef
);
247 ctx
->Driver
.BlendColor( ctx
,
248 ctx
->Color
.BlendColor
);
250 ctx
->Driver
.BlendEquationSeparate( ctx
,
251 ctx
->Color
.BlendEquationRGB
,
252 ctx
->Color
.BlendEquationA
);
254 ctx
->Driver
.BlendFuncSeparate( ctx
,
255 ctx
->Color
.BlendSrcRGB
,
256 ctx
->Color
.BlendDstRGB
,
257 ctx
->Color
.BlendSrcA
,
258 ctx
->Color
.BlendDstA
);
260 ctx
->Driver
.ColorMask( ctx
,
261 ctx
->Color
.ColorMask
[RCOMP
],
262 ctx
->Color
.ColorMask
[GCOMP
],
263 ctx
->Color
.ColorMask
[BCOMP
],
264 ctx
->Color
.ColorMask
[ACOMP
]);
266 ctx
->Driver
.CullFace( ctx
, ctx
->Polygon
.CullFaceMode
);
267 ctx
->Driver
.DepthFunc( ctx
, ctx
->Depth
.Func
);
268 ctx
->Driver
.DepthMask( ctx
, ctx
->Depth
.Mask
);
270 ctx
->Driver
.Enable( ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
271 ctx
->Driver
.Enable( ctx
, GL_BLEND
, ctx
->Color
.BlendEnabled
);
272 ctx
->Driver
.Enable( ctx
, GL_COLOR_LOGIC_OP
, ctx
->Color
.ColorLogicOpEnabled
);
273 ctx
->Driver
.Enable( ctx
, GL_COLOR_SUM
, ctx
->Fog
.ColorSumEnabled
);
274 ctx
->Driver
.Enable( ctx
, GL_CULL_FACE
, ctx
->Polygon
.CullFlag
);
275 ctx
->Driver
.Enable( ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
276 ctx
->Driver
.Enable( ctx
, GL_DITHER
, ctx
->Color
.DitherFlag
);
277 ctx
->Driver
.Enable( ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
278 ctx
->Driver
.Enable( ctx
, GL_LIGHTING
, ctx
->Light
.Enabled
);
279 ctx
->Driver
.Enable( ctx
, GL_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
280 ctx
->Driver
.Enable( ctx
, GL_POLYGON_STIPPLE
, ctx
->Polygon
.StippleFlag
);
281 ctx
->Driver
.Enable( ctx
, GL_SCISSOR_TEST
, ctx
->Scissor
.Enabled
);
282 ctx
->Driver
.Enable( ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
283 ctx
->Driver
.Enable( ctx
, GL_TEXTURE_1D
, GL_FALSE
);
284 ctx
->Driver
.Enable( ctx
, GL_TEXTURE_2D
, GL_FALSE
);
285 ctx
->Driver
.Enable( ctx
, GL_TEXTURE_RECTANGLE_NV
, GL_FALSE
);
286 ctx
->Driver
.Enable( ctx
, GL_TEXTURE_3D
, GL_FALSE
);
287 ctx
->Driver
.Enable( ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
289 ctx
->Driver
.Fogfv( ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
290 ctx
->Driver
.Fogfv( ctx
, GL_FOG_MODE
, 0 );
291 ctx
->Driver
.Fogfv( ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
292 ctx
->Driver
.Fogfv( ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
293 ctx
->Driver
.Fogfv( ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
295 ctx
->Driver
.FrontFace( ctx
, ctx
->Polygon
.FrontFace
);
298 GLfloat f
= (GLfloat
)ctx
->Light
.Model
.ColorControl
;
299 ctx
->Driver
.LightModelfv( ctx
, GL_LIGHT_MODEL_COLOR_CONTROL
, &f
);
302 ctx
->Driver
.LineWidth( ctx
, ctx
->Line
.Width
);
303 ctx
->Driver
.LogicOpcode( ctx
, ctx
->Color
.LogicOp
);
304 ctx
->Driver
.PointSize( ctx
, ctx
->Point
.Size
);
305 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*)ctx
->PolygonStipple
);
306 ctx
->Driver
.Scissor( ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
307 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
308 ctx
->Driver
.ShadeModel( ctx
, ctx
->Light
.ShadeModel
);
309 ctx
->Driver
.StencilFuncSeparate( ctx
, GL_FRONT
,
310 ctx
->Stencil
.Function
[0],
312 ctx
->Stencil
.ValueMask
[0] );
313 ctx
->Driver
.StencilFuncSeparate( ctx
, GL_BACK
,
314 ctx
->Stencil
.Function
[1],
316 ctx
->Stencil
.ValueMask
[1] );
317 ctx
->Driver
.StencilMaskSeparate( ctx
, GL_FRONT
, ctx
->Stencil
.WriteMask
[0] );
318 ctx
->Driver
.StencilMaskSeparate( ctx
, GL_BACK
, ctx
->Stencil
.WriteMask
[1] );
319 ctx
->Driver
.StencilOpSeparate( ctx
, GL_FRONT
,
320 ctx
->Stencil
.FailFunc
[0],
321 ctx
->Stencil
.ZFailFunc
[0],
322 ctx
->Stencil
.ZPassFunc
[0]);
323 ctx
->Driver
.StencilOpSeparate( ctx
, GL_BACK
,
324 ctx
->Stencil
.FailFunc
[1],
325 ctx
->Stencil
.ZFailFunc
[1],
326 ctx
->Stencil
.ZPassFunc
[1]);
329 ctx
->Driver
.DrawBuffer( ctx
, ctx
->Color
.DrawBuffer
[0] );