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 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/macros.h"
32 #include "main/enums.h"
33 #include "main/colormac.h"
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"
43 intel_translate_shadow_compare_func( GLenum func
)
47 return COMPAREFUNC_ALWAYS
;
49 return COMPAREFUNC_LEQUAL
;
51 return COMPAREFUNC_LESS
;
53 return COMPAREFUNC_GEQUAL
;
55 return COMPAREFUNC_GREATER
;
57 return COMPAREFUNC_EQUAL
;
59 return COMPAREFUNC_NOTEQUAL
;
61 return COMPAREFUNC_NEVER
;
64 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, func
);
65 return COMPAREFUNC_NEVER
;
69 intel_translate_compare_func(GLenum func
)
73 return COMPAREFUNC_NEVER
;
75 return COMPAREFUNC_LESS
;
77 return COMPAREFUNC_LEQUAL
;
79 return COMPAREFUNC_GREATER
;
81 return COMPAREFUNC_GEQUAL
;
83 return COMPAREFUNC_NOTEQUAL
;
85 return COMPAREFUNC_EQUAL
;
87 return COMPAREFUNC_ALWAYS
;
90 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, func
);
91 return COMPAREFUNC_ALWAYS
;
95 intel_translate_stencil_op(GLenum op
)
99 return STENCILOP_KEEP
;
101 return STENCILOP_ZERO
;
103 return STENCILOP_REPLACE
;
105 return STENCILOP_INCRSAT
;
107 return STENCILOP_DECRSAT
;
109 return STENCILOP_INCR
;
111 return STENCILOP_DECR
;
113 return STENCILOP_INVERT
;
115 return STENCILOP_ZERO
;
120 intel_translate_blend_factor(GLenum factor
)
124 return BLENDFACT_ZERO
;
126 return BLENDFACT_SRC_ALPHA
;
128 return BLENDFACT_ONE
;
130 return BLENDFACT_SRC_COLR
;
131 case GL_ONE_MINUS_SRC_COLOR
:
132 return BLENDFACT_INV_SRC_COLR
;
134 return BLENDFACT_DST_COLR
;
135 case GL_ONE_MINUS_DST_COLOR
:
136 return BLENDFACT_INV_DST_COLR
;
137 case GL_ONE_MINUS_SRC_ALPHA
:
138 return BLENDFACT_INV_SRC_ALPHA
;
140 return BLENDFACT_DST_ALPHA
;
141 case GL_ONE_MINUS_DST_ALPHA
:
142 return BLENDFACT_INV_DST_ALPHA
;
143 case GL_SRC_ALPHA_SATURATE
:
144 return BLENDFACT_SRC_ALPHA_SATURATE
;
145 case GL_CONSTANT_COLOR
:
146 return BLENDFACT_CONST_COLOR
;
147 case GL_ONE_MINUS_CONSTANT_COLOR
:
148 return BLENDFACT_INV_CONST_COLOR
;
149 case GL_CONSTANT_ALPHA
:
150 return BLENDFACT_CONST_ALPHA
;
151 case GL_ONE_MINUS_CONSTANT_ALPHA
:
152 return BLENDFACT_INV_CONST_ALPHA
;
155 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, factor
);
156 return BLENDFACT_ZERO
;
160 intel_translate_logic_op(GLenum opcode
)
164 return LOGICOP_CLEAR
;
168 return LOGICOP_AND_RVRSE
;
171 case GL_COPY_INVERTED
:
172 return LOGICOP_COPY_INV
;
173 case GL_AND_INVERTED
:
174 return LOGICOP_AND_INV
;
182 return LOGICOP_OR_INV
;
186 return LOGICOP_EQUIV
;
190 return LOGICOP_OR_RVRSE
;
202 intelClearColor(GLcontext
* ctx
, const GLfloat color
[4])
204 struct intel_context
*intel
= intel_context(ctx
);
207 CLAMPED_FLOAT_TO_UBYTE(clear
[0], color
[0]);
208 CLAMPED_FLOAT_TO_UBYTE(clear
[1], color
[1]);
209 CLAMPED_FLOAT_TO_UBYTE(clear
[2], color
[2]);
210 CLAMPED_FLOAT_TO_UBYTE(clear
[3], color
[3]);
212 /* compute both 32 and 16-bit clear values */
213 intel
->ClearColor8888
= INTEL_PACKCOLOR8888(clear
[0], clear
[1],
215 intel
->ClearColor565
= INTEL_PACKCOLOR565(clear
[0], clear
[1], clear
[2]);
220 * Update the viewport transformation matrix. Depends on:
221 * - viewport pos/size
223 * - window pos/size or FBO size
226 intelCalcViewport(GLcontext
* ctx
)
228 struct intel_context
*intel
= intel_context(ctx
);
229 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
230 const GLfloat depthScale
= 1.0F
/ ctx
->DrawBuffer
->_DepthMaxF
;
231 GLfloat
*m
= intel
->ViewportMatrix
.m
;
232 GLfloat yScale
, yBias
;
234 if (ctx
->DrawBuffer
->Name
) {
235 /* User created FBO */
236 struct intel_renderbuffer
*irb
237 = intel_renderbuffer(ctx
->DrawBuffer
->_ColorDrawBuffers
[0]);
238 if (irb
&& !irb
->RenderToTexture
) {
241 yBias
= irb
->Base
.Height
;
250 /* window buffer, y=0=top */
252 yBias
= (intel
->driDrawable
) ? intel
->driDrawable
->h
: 0.0F
;
255 m
[MAT_SX
] = v
[MAT_SX
];
256 m
[MAT_TX
] = v
[MAT_TX
];
258 m
[MAT_SY
] = v
[MAT_SY
] * yScale
;
259 m
[MAT_TY
] = v
[MAT_TY
] * yScale
+ yBias
;
261 m
[MAT_SZ
] = v
[MAT_SZ
] * depthScale
;
262 m
[MAT_TZ
] = v
[MAT_TZ
] * depthScale
;
266 intelViewport(GLcontext
* ctx
,
267 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
269 intelCalcViewport(ctx
);
271 intel_viewport(ctx
, x
, y
, width
, height
);
275 intelDepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
)
277 intelCalcViewport(ctx
);
280 /* Fallback to swrast for select and feedback.
283 intelRenderMode(GLcontext
* ctx
, GLenum mode
)
285 struct intel_context
*intel
= intel_context(ctx
);
286 FALLBACK(intel
, INTEL_FALLBACK_RENDERMODE
, (mode
!= GL_RENDER
));
291 intelInitStateFuncs(struct dd_function_table
*functions
)
293 functions
->RenderMode
= intelRenderMode
;
294 functions
->Viewport
= intelViewport
;
295 functions
->DepthRange
= intelDepthRange
;
296 functions
->ClearColor
= intelClearColor
;