Add PCI IDs for the G33, Q33, and Q35 chipsets.
[mesa.git] / src / mesa / drivers / dri / i915 / 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 "dd.h"
34
35 #include "intel_screen.h"
36 #include "intel_context.h"
37 #include "swrast/swrast.h"
38
39 int intel_translate_compare_func( GLenum func )
40 {
41 switch(func) {
42 case GL_NEVER:
43 return COMPAREFUNC_NEVER;
44 case GL_LESS:
45 return COMPAREFUNC_LESS;
46 case GL_LEQUAL:
47 return COMPAREFUNC_LEQUAL;
48 case GL_GREATER:
49 return COMPAREFUNC_GREATER;
50 case GL_GEQUAL:
51 return COMPAREFUNC_GEQUAL;
52 case GL_NOTEQUAL:
53 return COMPAREFUNC_NOTEQUAL;
54 case GL_EQUAL:
55 return COMPAREFUNC_EQUAL;
56 case GL_ALWAYS:
57 return COMPAREFUNC_ALWAYS;
58 }
59
60 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, func);
61 return COMPAREFUNC_ALWAYS;
62 }
63
64 int intel_translate_stencil_op( GLenum op )
65 {
66 switch(op) {
67 case GL_KEEP:
68 return STENCILOP_KEEP;
69 case GL_ZERO:
70 return STENCILOP_ZERO;
71 case GL_REPLACE:
72 return STENCILOP_REPLACE;
73 case GL_INCR:
74 return STENCILOP_INCRSAT;
75 case GL_DECR:
76 return STENCILOP_DECRSAT;
77 case GL_INCR_WRAP:
78 return STENCILOP_INCR;
79 case GL_DECR_WRAP:
80 return STENCILOP_DECR;
81 case GL_INVERT:
82 return STENCILOP_INVERT;
83 default:
84 return STENCILOP_ZERO;
85 }
86 }
87
88 int intel_translate_blend_factor( GLenum factor )
89 {
90 switch(factor) {
91 case GL_ZERO:
92 return BLENDFACT_ZERO;
93 case GL_SRC_ALPHA:
94 return BLENDFACT_SRC_ALPHA;
95 case GL_ONE:
96 return BLENDFACT_ONE;
97 case GL_SRC_COLOR:
98 return BLENDFACT_SRC_COLR;
99 case GL_ONE_MINUS_SRC_COLOR:
100 return BLENDFACT_INV_SRC_COLR;
101 case GL_DST_COLOR:
102 return BLENDFACT_DST_COLR;
103 case GL_ONE_MINUS_DST_COLOR:
104 return BLENDFACT_INV_DST_COLR;
105 case GL_ONE_MINUS_SRC_ALPHA:
106 return BLENDFACT_INV_SRC_ALPHA;
107 case GL_DST_ALPHA:
108 return BLENDFACT_DST_ALPHA;
109 case GL_ONE_MINUS_DST_ALPHA:
110 return BLENDFACT_INV_DST_ALPHA;
111 case GL_SRC_ALPHA_SATURATE:
112 return BLENDFACT_SRC_ALPHA_SATURATE;
113 case GL_CONSTANT_COLOR:
114 return BLENDFACT_CONST_COLOR;
115 case GL_ONE_MINUS_CONSTANT_COLOR:
116 return BLENDFACT_INV_CONST_COLOR;
117 case GL_CONSTANT_ALPHA:
118 return BLENDFACT_CONST_ALPHA;
119 case GL_ONE_MINUS_CONSTANT_ALPHA:
120 return BLENDFACT_INV_CONST_ALPHA;
121 }
122
123 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, factor);
124 return BLENDFACT_ZERO;
125 }
126
127 int intel_translate_logic_op( GLenum opcode )
128 {
129 switch(opcode) {
130 case GL_CLEAR:
131 return LOGICOP_CLEAR;
132 case GL_AND:
133 return LOGICOP_AND;
134 case GL_AND_REVERSE:
135 return LOGICOP_AND_RVRSE;
136 case GL_COPY:
137 return LOGICOP_COPY;
138 case GL_COPY_INVERTED:
139 return LOGICOP_COPY_INV;
140 case GL_AND_INVERTED:
141 return LOGICOP_AND_INV;
142 case GL_NOOP:
143 return LOGICOP_NOOP;
144 case GL_XOR:
145 return LOGICOP_XOR;
146 case GL_OR:
147 return LOGICOP_OR;
148 case GL_OR_INVERTED:
149 return LOGICOP_OR_INV;
150 case GL_NOR:
151 return LOGICOP_NOR;
152 case GL_EQUIV:
153 return LOGICOP_EQUIV;
154 case GL_INVERT:
155 return LOGICOP_INV;
156 case GL_OR_REVERSE:
157 return LOGICOP_OR_RVRSE;
158 case GL_NAND:
159 return LOGICOP_NAND;
160 case GL_SET:
161 return LOGICOP_SET;
162 default:
163 return LOGICOP_SET;
164 }
165 }
166
167 static void intelDrawBuffer(GLcontext *ctx, GLenum mode )
168 {
169 intelContextPtr intel = INTEL_CONTEXT(ctx);
170 int front = 0;
171
172 if (!ctx->DrawBuffer)
173 return;
174
175 switch ( ctx->DrawBuffer->_ColorDrawBufferMask[0] ) {
176 case BUFFER_BIT_FRONT_LEFT:
177 front = 1;
178 FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE );
179 break;
180 case BUFFER_BIT_BACK_LEFT:
181 front = 0;
182 FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_FALSE );
183 break;
184 default:
185 FALLBACK( intel, INTEL_FALLBACK_DRAW_BUFFER, GL_TRUE );
186 return;
187 }
188
189 if ( intel->sarea->pf_current_page == 1 )
190 front ^= 1;
191
192 intelSetFrontClipRects( intel );
193
194 if (front) {
195 intel->drawRegion = &intel->intelScreen->front;
196 intel->readRegion = &intel->intelScreen->front;
197 } else {
198 intel->drawRegion = &intel->intelScreen->back;
199 intel->readRegion = &intel->intelScreen->back;
200 }
201
202 intel->vtbl.set_color_region( intel, intel->drawRegion );
203 }
204
205 static void intelReadBuffer( GLcontext *ctx, GLenum mode )
206 {
207 /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
208 }
209
210
211 static void intelClearColor(GLcontext *ctx, const GLfloat color[4])
212 {
213 intelContextPtr intel = INTEL_CONTEXT(ctx);
214 intelScreenPrivate *screen = intel->intelScreen;
215
216 CLAMPED_FLOAT_TO_UBYTE(intel->clear_red, color[0]);
217 CLAMPED_FLOAT_TO_UBYTE(intel->clear_green, color[1]);
218 CLAMPED_FLOAT_TO_UBYTE(intel->clear_blue, color[2]);
219 CLAMPED_FLOAT_TO_UBYTE(intel->clear_alpha, color[3]);
220
221 intel->ClearColor = INTEL_PACKCOLOR(screen->fbFormat,
222 intel->clear_red,
223 intel->clear_green,
224 intel->clear_blue,
225 intel->clear_alpha);
226 }
227
228
229 static void intelCalcViewport( GLcontext *ctx )
230 {
231 intelContextPtr intel = INTEL_CONTEXT(ctx);
232 const GLfloat *v = ctx->Viewport._WindowMap.m;
233 GLfloat *m = intel->ViewportMatrix.m;
234 GLint h = 0;
235
236 if (intel->driDrawable)
237 h = intel->driDrawable->h + SUBPIXEL_Y;
238
239 /* See also intel_translate_vertex. SUBPIXEL adjustments can be done
240 * via state vars, too.
241 */
242 m[MAT_SX] = v[MAT_SX];
243 m[MAT_TX] = v[MAT_TX] + SUBPIXEL_X;
244 m[MAT_SY] = - v[MAT_SY];
245 m[MAT_TY] = - v[MAT_TY] + h;
246 m[MAT_SZ] = v[MAT_SZ] * intel->depth_scale;
247 m[MAT_TZ] = v[MAT_TZ] * intel->depth_scale;
248 }
249
250 static void intelViewport( GLcontext *ctx,
251 GLint x, GLint y,
252 GLsizei width, GLsizei height )
253 {
254 intelCalcViewport( ctx );
255 }
256
257 static void intelDepthRange( GLcontext *ctx,
258 GLclampd nearval, GLclampd farval )
259 {
260 intelCalcViewport( ctx );
261 }
262
263 /* Fallback to swrast for select and feedback.
264 */
265 static void intelRenderMode( GLcontext *ctx, GLenum mode )
266 {
267 intelContextPtr intel = INTEL_CONTEXT(ctx);
268 FALLBACK( intel, INTEL_FALLBACK_RENDERMODE, (mode != GL_RENDER) );
269 }
270
271
272 void intelInitStateFuncs( struct dd_function_table *functions )
273 {
274 functions->DrawBuffer = intelDrawBuffer;
275 functions->ReadBuffer = intelReadBuffer;
276 functions->RenderMode = intelRenderMode;
277 functions->Viewport = intelViewport;
278 functions->DepthRange = intelDepthRange;
279 functions->ClearColor = intelClearColor;
280 }
281