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 **************************************************************************/
35 #include "intel_screen.h"
36 #include "intel_context.h"
37 #include "swrast/swrast.h"
39 int intel_translate_compare_func( GLenum func
)
43 return COMPAREFUNC_NEVER
;
45 return COMPAREFUNC_LESS
;
47 return COMPAREFUNC_LEQUAL
;
49 return COMPAREFUNC_GREATER
;
51 return COMPAREFUNC_GEQUAL
;
53 return COMPAREFUNC_NOTEQUAL
;
55 return COMPAREFUNC_EQUAL
;
57 return COMPAREFUNC_ALWAYS
;
60 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, func
);
61 return COMPAREFUNC_ALWAYS
;
64 int intel_translate_stencil_op( GLenum op
)
68 return STENCILOP_KEEP
;
70 return STENCILOP_ZERO
;
72 return STENCILOP_REPLACE
;
74 return STENCILOP_INCRSAT
;
76 return STENCILOP_DECRSAT
;
78 return STENCILOP_INCR
;
80 return STENCILOP_DECR
;
82 return STENCILOP_INVERT
;
84 return STENCILOP_ZERO
;
88 int intel_translate_blend_factor( GLenum factor
)
92 return BLENDFACT_ZERO
;
94 return BLENDFACT_SRC_ALPHA
;
98 return BLENDFACT_SRC_COLR
;
99 case GL_ONE_MINUS_SRC_COLOR
:
100 return BLENDFACT_INV_SRC_COLR
;
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
;
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
;
123 fprintf(stderr
, "Unknown value in %s: %x\n", __FUNCTION__
, factor
);
124 return BLENDFACT_ZERO
;
127 int intel_translate_logic_op( GLenum opcode
)
131 return LOGICOP_CLEAR
;
135 return LOGICOP_AND_RVRSE
;
138 case GL_COPY_INVERTED
:
139 return LOGICOP_COPY_INV
;
140 case GL_AND_INVERTED
:
141 return LOGICOP_AND_INV
;
149 return LOGICOP_OR_INV
;
153 return LOGICOP_EQUIV
;
157 return LOGICOP_OR_RVRSE
;
167 static void intelDrawBuffer(GLcontext
*ctx
, GLenum mode
)
169 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
172 if (!ctx
->DrawBuffer
)
175 switch ( ctx
->DrawBuffer
->_ColorDrawBufferMask
[0] ) {
176 case BUFFER_BIT_FRONT_LEFT
:
178 FALLBACK( intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
180 case BUFFER_BIT_BACK_LEFT
:
182 FALLBACK( intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
185 FALLBACK( intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_TRUE
);
189 if ( intel
->sarea
->pf_current_page
== 1 )
192 intelSetFrontClipRects( intel
);
195 intel
->drawRegion
= &intel
->intelScreen
->front
;
196 intel
->readRegion
= &intel
->intelScreen
->front
;
198 intel
->drawRegion
= &intel
->intelScreen
->back
;
199 intel
->readRegion
= &intel
->intelScreen
->back
;
202 intel
->vtbl
.set_color_region( intel
, intel
->drawRegion
);
205 static void intelReadBuffer( GLcontext
*ctx
, GLenum mode
)
207 /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
211 static void intelClearColor(GLcontext
*ctx
, const GLfloat color
[4])
213 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
214 intelScreenPrivate
*screen
= intel
->intelScreen
;
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]);
221 intel
->ClearColor
= INTEL_PACKCOLOR(screen
->fbFormat
,
229 static void intelCalcViewport( GLcontext
*ctx
)
231 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
232 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
233 GLfloat
*m
= intel
->ViewportMatrix
.m
;
236 if (intel
->driDrawable
)
237 h
= intel
->driDrawable
->h
+ SUBPIXEL_Y
;
239 /* See also intel_translate_vertex. SUBPIXEL adjustments can be done
240 * via state vars, too.
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
;
250 static void intelViewport( GLcontext
*ctx
,
252 GLsizei width
, GLsizei height
)
254 intelCalcViewport( ctx
);
257 static void intelDepthRange( GLcontext
*ctx
,
258 GLclampd nearval
, GLclampd farval
)
260 intelCalcViewport( ctx
);
263 /* Fallback to swrast for select and feedback.
265 static void intelRenderMode( GLcontext
*ctx
, GLenum mode
)
267 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
268 FALLBACK( intel
, INTEL_FALLBACK_RENDERMODE
, (mode
!= GL_RENDER
) );
272 void intelInitStateFuncs( struct dd_function_table
*functions
)
274 functions
->DrawBuffer
= intelDrawBuffer
;
275 functions
->ReadBuffer
= intelReadBuffer
;
276 functions
->RenderMode
= intelRenderMode
;
277 functions
->Viewport
= intelViewport
;
278 functions
->DepthRange
= intelDepthRange
;
279 functions
->ClearColor
= intelClearColor
;