Fix function call bug 11731. Also, fix up IR_CALL/IR_FUNC confusion.
[mesa.git] / src / mesa / drivers / dri / i915tex / 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_fbo.h"
39 #include "intel_regions.h"
40 #include "swrast/swrast.h"
41
42 int
43 intel_translate_compare_func(GLenum func)
44 {
45 switch (func) {
46 case GL_NEVER:
47 return COMPAREFUNC_NEVER;
48 case GL_LESS:
49 return COMPAREFUNC_LESS;
50 case GL_LEQUAL:
51 return COMPAREFUNC_LEQUAL;
52 case GL_GREATER:
53 return COMPAREFUNC_GREATER;
54 case GL_GEQUAL:
55 return COMPAREFUNC_GEQUAL;
56 case GL_NOTEQUAL:
57 return COMPAREFUNC_NOTEQUAL;
58 case GL_EQUAL:
59 return COMPAREFUNC_EQUAL;
60 case GL_ALWAYS:
61 return COMPAREFUNC_ALWAYS;
62 }
63
64 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, func);
65 return COMPAREFUNC_ALWAYS;
66 }
67
68 int
69 intel_translate_stencil_op(GLenum op)
70 {
71 switch (op) {
72 case GL_KEEP:
73 return STENCILOP_KEEP;
74 case GL_ZERO:
75 return STENCILOP_ZERO;
76 case GL_REPLACE:
77 return STENCILOP_REPLACE;
78 case GL_INCR:
79 return STENCILOP_INCRSAT;
80 case GL_DECR:
81 return STENCILOP_DECRSAT;
82 case GL_INCR_WRAP:
83 return STENCILOP_INCR;
84 case GL_DECR_WRAP:
85 return STENCILOP_DECR;
86 case GL_INVERT:
87 return STENCILOP_INVERT;
88 default:
89 return STENCILOP_ZERO;
90 }
91 }
92
93 int
94 intel_translate_blend_factor(GLenum factor)
95 {
96 switch (factor) {
97 case GL_ZERO:
98 return BLENDFACT_ZERO;
99 case GL_SRC_ALPHA:
100 return BLENDFACT_SRC_ALPHA;
101 case GL_ONE:
102 return BLENDFACT_ONE;
103 case GL_SRC_COLOR:
104 return BLENDFACT_SRC_COLR;
105 case GL_ONE_MINUS_SRC_COLOR:
106 return BLENDFACT_INV_SRC_COLR;
107 case GL_DST_COLOR:
108 return BLENDFACT_DST_COLR;
109 case GL_ONE_MINUS_DST_COLOR:
110 return BLENDFACT_INV_DST_COLR;
111 case GL_ONE_MINUS_SRC_ALPHA:
112 return BLENDFACT_INV_SRC_ALPHA;
113 case GL_DST_ALPHA:
114 return BLENDFACT_DST_ALPHA;
115 case GL_ONE_MINUS_DST_ALPHA:
116 return BLENDFACT_INV_DST_ALPHA;
117 case GL_SRC_ALPHA_SATURATE:
118 return BLENDFACT_SRC_ALPHA_SATURATE;
119 case GL_CONSTANT_COLOR:
120 return BLENDFACT_CONST_COLOR;
121 case GL_ONE_MINUS_CONSTANT_COLOR:
122 return BLENDFACT_INV_CONST_COLOR;
123 case GL_CONSTANT_ALPHA:
124 return BLENDFACT_CONST_ALPHA;
125 case GL_ONE_MINUS_CONSTANT_ALPHA:
126 return BLENDFACT_INV_CONST_ALPHA;
127 }
128
129 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, factor);
130 return BLENDFACT_ZERO;
131 }
132
133 int
134 intel_translate_logic_op(GLenum opcode)
135 {
136 switch (opcode) {
137 case GL_CLEAR:
138 return LOGICOP_CLEAR;
139 case GL_AND:
140 return LOGICOP_AND;
141 case GL_AND_REVERSE:
142 return LOGICOP_AND_RVRSE;
143 case GL_COPY:
144 return LOGICOP_COPY;
145 case GL_COPY_INVERTED:
146 return LOGICOP_COPY_INV;
147 case GL_AND_INVERTED:
148 return LOGICOP_AND_INV;
149 case GL_NOOP:
150 return LOGICOP_NOOP;
151 case GL_XOR:
152 return LOGICOP_XOR;
153 case GL_OR:
154 return LOGICOP_OR;
155 case GL_OR_INVERTED:
156 return LOGICOP_OR_INV;
157 case GL_NOR:
158 return LOGICOP_NOR;
159 case GL_EQUIV:
160 return LOGICOP_EQUIV;
161 case GL_INVERT:
162 return LOGICOP_INV;
163 case GL_OR_REVERSE:
164 return LOGICOP_OR_RVRSE;
165 case GL_NAND:
166 return LOGICOP_NAND;
167 case GL_SET:
168 return LOGICOP_SET;
169 default:
170 return LOGICOP_SET;
171 }
172 }
173
174
175 static void
176 intelClearColor(GLcontext * ctx, const GLfloat color[4])
177 {
178 struct intel_context *intel = intel_context(ctx);
179 GLubyte clear[4];
180
181 CLAMPED_FLOAT_TO_UBYTE(clear[0], color[0]);
182 CLAMPED_FLOAT_TO_UBYTE(clear[1], color[1]);
183 CLAMPED_FLOAT_TO_UBYTE(clear[2], color[2]);
184 CLAMPED_FLOAT_TO_UBYTE(clear[3], color[3]);
185
186 /* compute both 32 and 16-bit clear values */
187 intel->ClearColor8888 = INTEL_PACKCOLOR8888(clear[0], clear[1],
188 clear[2], clear[3]);
189 intel->ClearColor565 = INTEL_PACKCOLOR565(clear[0], clear[1], clear[2]);
190 }
191
192
193 /**
194 * Update the viewport transformation matrix. Depends on:
195 * - viewport pos/size
196 * - depthrange
197 * - window pos/size or FBO size
198 */
199 static void
200 intelCalcViewport(GLcontext * ctx)
201 {
202 struct intel_context *intel = intel_context(ctx);
203 const GLfloat *v = ctx->Viewport._WindowMap.m;
204 const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
205 GLfloat *m = intel->ViewportMatrix.m;
206 GLfloat yScale, yBias;
207
208 if (ctx->DrawBuffer->Name) {
209 /* User created FBO */
210 struct intel_renderbuffer *irb
211 = intel_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0][0]);
212 if (irb && !irb->RenderToTexture) {
213 /* y=0=top */
214 yScale = -1.0;
215 yBias = irb->Base.Height;
216 }
217 else {
218 /* y=0=bottom */
219 yScale = 1.0;
220 yBias = 0.0;
221 }
222 }
223 else {
224 /* window buffer, y=0=top */
225 yScale = -1.0;
226 yBias = (intel->driDrawable) ? intel->driDrawable->h : 0.0F;
227 }
228
229 m[MAT_SX] = v[MAT_SX];
230 m[MAT_TX] = v[MAT_TX] + SUBPIXEL_X;
231
232 m[MAT_SY] = v[MAT_SY] * yScale;
233 m[MAT_TY] = v[MAT_TY] * yScale + yBias + SUBPIXEL_Y;
234
235 m[MAT_SZ] = v[MAT_SZ] * depthScale;
236 m[MAT_TZ] = v[MAT_TZ] * depthScale;
237 }
238
239 static void
240 intelViewport(GLcontext * ctx,
241 GLint x, GLint y, GLsizei width, GLsizei height)
242 {
243 intelCalcViewport(ctx);
244 }
245
246 static void
247 intelDepthRange(GLcontext * ctx, GLclampd nearval, GLclampd farval)
248 {
249 intelCalcViewport(ctx);
250 }
251
252 /* Fallback to swrast for select and feedback.
253 */
254 static void
255 intelRenderMode(GLcontext * ctx, GLenum mode)
256 {
257 struct intel_context *intel = intel_context(ctx);
258 FALLBACK(intel, INTEL_FALLBACK_RENDERMODE, (mode != GL_RENDER));
259 }
260
261
262 void
263 intelInitStateFuncs(struct dd_function_table *functions)
264 {
265 functions->RenderMode = intelRenderMode;
266 functions->Viewport = intelViewport;
267 functions->DepthRange = intelDepthRange;
268 functions->ClearColor = intelClearColor;
269 }