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_fbo.h"
39 #include "intel_regions.h"
40 #include "swrast/swrast.h"
43 intel_translate_compare_func(GLenum func
)
47 return COMPAREFUNC_NEVER
;
49 return COMPAREFUNC_LESS
;
51 return COMPAREFUNC_LEQUAL
;
53 return COMPAREFUNC_GREATER
;
55 return COMPAREFUNC_GEQUAL
;
57 return COMPAREFUNC_NOTEQUAL
;
59 return COMPAREFUNC_EQUAL
;
61 return COMPAREFUNC_ALWAYS
;
64 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, func
);
65 return COMPAREFUNC_ALWAYS
;
69 intel_translate_stencil_op(GLenum op
)
73 return STENCILOP_KEEP
;
75 return STENCILOP_ZERO
;
77 return STENCILOP_REPLACE
;
79 return STENCILOP_INCRSAT
;
81 return STENCILOP_DECRSAT
;
83 return STENCILOP_INCR
;
85 return STENCILOP_DECR
;
87 return STENCILOP_INVERT
;
89 return STENCILOP_ZERO
;
94 intel_translate_blend_factor(GLenum factor
)
98 return BLENDFACT_ZERO
;
100 return BLENDFACT_SRC_ALPHA
;
102 return BLENDFACT_ONE
;
104 return BLENDFACT_SRC_COLR
;
105 case GL_ONE_MINUS_SRC_COLOR
:
106 return BLENDFACT_INV_SRC_COLR
;
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
;
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
;
129 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, factor
);
130 return BLENDFACT_ZERO
;
134 intel_translate_logic_op(GLenum opcode
)
138 return LOGICOP_CLEAR
;
142 return LOGICOP_AND_RVRSE
;
145 case GL_COPY_INVERTED
:
146 return LOGICOP_COPY_INV
;
147 case GL_AND_INVERTED
:
148 return LOGICOP_AND_INV
;
156 return LOGICOP_OR_INV
;
160 return LOGICOP_EQUIV
;
164 return LOGICOP_OR_RVRSE
;
176 intelClearColor(GLcontext
* ctx
, const GLfloat color
[4])
178 struct intel_context
*intel
= intel_context(ctx
);
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]);
186 /* compute both 32 and 16-bit clear values */
187 intel
->ClearColor8888
= INTEL_PACKCOLOR8888(clear
[0], clear
[1],
189 intel
->ClearColor565
= INTEL_PACKCOLOR565(clear
[0], clear
[1], clear
[2]);
194 * Update the viewport transformation matrix. Depends on:
195 * - viewport pos/size
197 * - window pos/size or FBO size
200 intelCalcViewport(GLcontext
* ctx
)
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
;
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
) {
215 yBias
= irb
->Base
.Height
;
224 /* window buffer, y=0=top */
226 yBias
= (intel
->driDrawable
) ? intel
->driDrawable
->h
: 0.0F
;
229 m
[MAT_SX
] = v
[MAT_SX
];
230 m
[MAT_TX
] = v
[MAT_TX
] + SUBPIXEL_X
;
232 m
[MAT_SY
] = v
[MAT_SY
] * yScale
;
233 m
[MAT_TY
] = v
[MAT_TY
] * yScale
+ yBias
+ SUBPIXEL_Y
;
235 m
[MAT_SZ
] = v
[MAT_SZ
] * depthScale
;
236 m
[MAT_TZ
] = v
[MAT_TZ
] * depthScale
;
240 intelViewport(GLcontext
* ctx
,
241 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
243 intelCalcViewport(ctx
);
247 intelDepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
)
249 intelCalcViewport(ctx
);
252 /* Fallback to swrast for select and feedback.
255 intelRenderMode(GLcontext
* ctx
, GLenum mode
)
257 struct intel_context
*intel
= intel_context(ctx
);
258 FALLBACK(intel
, INTEL_FALLBACK_RENDERMODE
, (mode
!= GL_RENDER
));
263 intelInitStateFuncs(struct dd_function_table
*functions
)
265 functions
->RenderMode
= intelRenderMode
;
266 functions
->Viewport
= intelViewport
;
267 functions
->DepthRange
= intelDepthRange
;
268 functions
->ClearColor
= intelClearColor
;