1 /**************************************************************************
3 * Copyright 2006 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 portionsalloc
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 **************************************************************************/
28 #include "main/enums.h"
29 #include "main/state.h"
30 #include "main/context.h"
31 #include "main/enable.h"
32 #include "main/matrix.h"
33 #include "swrast/swrast.h"
34 #include "shader/arbprogram.h"
35 #include "shader/program.h"
37 #include "intel_context.h"
38 #include "intel_pixel.h"
39 #include "intel_regions.h"
41 #define FILE_DEBUG_FLAG DEBUG_PIXEL
44 effective_func(GLenum func
, GLboolean src_alpha_is_one
)
46 if (src_alpha_is_one
) {
47 if (func
== GL_SRC_ALPHA
)
49 if (func
== GL_ONE_MINUS_SRC_ALPHA
)
57 * Check if any fragment operations are in effect which might effect
61 intel_check_blit_fragment_ops(GLcontext
* ctx
, GLboolean src_alpha_is_one
)
64 _mesa_update_state(ctx
);
66 if (ctx
->FragmentProgram
._Enabled
) {
67 DBG("fallback due to fragment program\n");
71 if (ctx
->Color
.BlendEnabled
&&
72 (effective_func(ctx
->Color
.BlendSrcRGB
, src_alpha_is_one
) != GL_ONE
||
73 effective_func(ctx
->Color
.BlendDstRGB
, src_alpha_is_one
) != GL_ZERO
||
74 ctx
->Color
.BlendEquationRGB
!= GL_FUNC_ADD
||
75 effective_func(ctx
->Color
.BlendSrcA
, src_alpha_is_one
) != GL_ONE
||
76 effective_func(ctx
->Color
.BlendDstA
, src_alpha_is_one
) != GL_ZERO
||
77 ctx
->Color
.BlendEquationA
!= GL_FUNC_ADD
)) {
78 DBG("fallback due to blend\n");
82 if (ctx
->Texture
._EnabledUnits
) {
83 DBG("fallback due to texturing\n");
87 if (!(ctx
->Color
.ColorMask
[0] &&
88 ctx
->Color
.ColorMask
[1] &&
89 ctx
->Color
.ColorMask
[2] &&
90 ctx
->Color
.ColorMask
[3])) {
91 DBG("fallback due to color masking\n");
95 if (ctx
->Color
.AlphaEnabled
) {
96 DBG("fallback due to alpha\n");
100 if (ctx
->Depth
.Test
) {
101 DBG("fallback due to depth test\n");
105 if (ctx
->Fog
.Enabled
) {
106 DBG("fallback due to fog\n");
110 if (ctx
->_ImageTransferState
) {
111 DBG("fallback due to image transfer\n");
115 if (ctx
->Stencil
.Enabled
) {
116 DBG("fallback due to image stencil\n");
120 if (ctx
->RenderMode
!= GL_RENDER
) {
121 DBG("fallback due to render mode\n");
130 intel_check_meta_tex_fragment_ops(GLcontext
* ctx
)
133 _mesa_update_state(ctx
);
135 /* Some of _ImageTransferState (scale, bias) could be done with
136 * fragment programs on i915.
138 return !(ctx
->_ImageTransferState
|| ctx
->Fog
.Enabled
|| /* not done yet */
139 ctx
->Texture
._EnabledUnits
|| ctx
->FragmentProgram
._Enabled
);
142 /* The intel_region struct doesn't really do enough to capture the
143 * format of the pixels in the region. For now this code assumes that
144 * the region is a display surface and hence is either ARGB8888 or
146 * XXX FBO: If we'd pass in the intel_renderbuffer instead of region, we'd
147 * know the buffer's pixel format.
149 * \param format as given to glDraw/ReadPixels
150 * \param type as given to glDraw/ReadPixels
153 intel_check_blit_format(struct intel_region
* region
,
154 GLenum format
, GLenum type
)
156 if (region
->cpp
== 4 &&
157 (type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
158 type
== GL_UNSIGNED_BYTE
) && format
== GL_BGRA
) {
162 if (region
->cpp
== 2 &&
163 type
== GL_UNSIGNED_SHORT_5_6_5_REV
&& format
== GL_BGR
) {
167 if (INTEL_DEBUG
& DEBUG_PIXEL
)
168 fprintf(stderr
, "%s: bad format for blit (cpp %d, type %s format %s)\n",
169 __FUNCTION__
, region
->cpp
,
170 _mesa_lookup_enum_by_nr(type
), _mesa_lookup_enum_by_nr(format
));
176 intel_meta_set_passthrough_transform(struct intel_context
*intel
)
178 GLcontext
*ctx
= &intel
->ctx
;
180 intel
->meta
.saved_vp_x
= ctx
->Viewport
.X
;
181 intel
->meta
.saved_vp_y
= ctx
->Viewport
.Y
;
182 intel
->meta
.saved_vp_width
= ctx
->Viewport
.Width
;
183 intel
->meta
.saved_vp_height
= ctx
->Viewport
.Height
;
184 intel
->meta
.saved_matrix_mode
= ctx
->Transform
.MatrixMode
;
186 _mesa_Viewport(0, 0, ctx
->DrawBuffer
->Width
, ctx
->DrawBuffer
->Height
);
188 _mesa_MatrixMode(GL_PROJECTION
);
190 _mesa_LoadIdentity();
191 _mesa_Ortho(0, ctx
->DrawBuffer
->Width
, 0, ctx
->DrawBuffer
->Height
, 1, -1);
193 _mesa_MatrixMode(GL_MODELVIEW
);
195 _mesa_LoadIdentity();
199 intel_meta_restore_transform(struct intel_context
*intel
)
201 _mesa_MatrixMode(GL_PROJECTION
);
203 _mesa_MatrixMode(GL_MODELVIEW
);
206 _mesa_MatrixMode(intel
->meta
.saved_matrix_mode
);
208 _mesa_Viewport(intel
->meta
.saved_vp_x
, intel
->meta
.saved_vp_y
,
209 intel
->meta
.saved_vp_width
, intel
->meta
.saved_vp_height
);
213 * Set up a vertex program to pass through the position and first texcoord
217 intel_meta_set_passthrough_vertex_program(struct intel_context
*intel
)
219 GLcontext
*ctx
= &intel
->ctx
;
220 static const char *vp
=
223 "DP4 vertexClip.x, state.matrix.mvp.row[0], vertex.position;\n"
224 "DP4 vertexClip.y, state.matrix.mvp.row[1], vertex.position;\n"
225 "DP4 vertexClip.z, state.matrix.mvp.row[2], vertex.position;\n"
226 "DP4 vertexClip.w, state.matrix.mvp.row[3], vertex.position;\n"
227 "MOV result.position, vertexClip;\n"
228 "MOV result.texcoord[0], vertex.texcoord[0];\n"
229 "MOV result.color, vertex.color;\n"
232 assert(intel
->meta
.saved_vp
== NULL
);
234 _mesa_reference_vertprog(ctx
, &intel
->meta
.saved_vp
,
235 ctx
->VertexProgram
.Current
);
236 if (intel
->meta
.passthrough_vp
== NULL
) {
238 _mesa_GenPrograms(1, &prog_name
);
239 _mesa_BindProgram(GL_VERTEX_PROGRAM_ARB
, prog_name
);
240 _mesa_ProgramStringARB(GL_VERTEX_PROGRAM_ARB
,
241 GL_PROGRAM_FORMAT_ASCII_ARB
,
242 strlen(vp
), (const GLubyte
*)vp
);
243 _mesa_reference_vertprog(ctx
, &intel
->meta
.passthrough_vp
,
244 ctx
->VertexProgram
.Current
);
245 _mesa_DeletePrograms(1, &prog_name
);
248 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
249 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
250 intel
->meta
.passthrough_vp
);
251 ctx
->Driver
.BindProgram(ctx
, GL_VERTEX_PROGRAM_ARB
,
252 &intel
->meta
.passthrough_vp
->Base
);
254 intel
->meta
.saved_vp_enable
= ctx
->VertexProgram
.Enabled
;
255 _mesa_Enable(GL_VERTEX_PROGRAM_ARB
);
259 * Restores the previous vertex program after
260 * intel_meta_set_passthrough_vertex_program()
263 intel_meta_restore_vertex_program(struct intel_context
*intel
)
265 GLcontext
*ctx
= &intel
->ctx
;
267 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
268 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
269 intel
->meta
.saved_vp
);
270 _mesa_reference_vertprog(ctx
, &intel
->meta
.saved_vp
, NULL
);
271 ctx
->Driver
.BindProgram(ctx
, GL_VERTEX_PROGRAM_ARB
,
272 &ctx
->VertexProgram
.Current
->Base
);
274 if (!intel
->meta
.saved_vp_enable
)
275 _mesa_Disable(GL_VERTEX_PROGRAM_ARB
);
279 * Binds the given program string to GL_FRAGMENT_PROGRAM_ARB, caching the
283 intel_meta_set_fragment_program(struct intel_context
*intel
,
284 struct gl_fragment_program
**prog
,
285 const char *prog_string
)
287 GLcontext
*ctx
= &intel
->ctx
;
288 assert(intel
->meta
.saved_fp
== NULL
);
290 _mesa_reference_fragprog(ctx
, &intel
->meta
.saved_fp
,
291 ctx
->FragmentProgram
.Current
);
294 _mesa_GenPrograms(1, &prog_name
);
295 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, prog_name
);
296 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
,
297 GL_PROGRAM_FORMAT_ASCII_ARB
,
298 strlen(prog_string
), (const GLubyte
*)prog_string
);
299 _mesa_reference_fragprog(ctx
, prog
, ctx
->FragmentProgram
.Current
);
300 /* Note that DeletePrograms unbinds the program on us */
301 _mesa_DeletePrograms(1, &prog_name
);
304 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
305 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
, *prog
);
306 ctx
->Driver
.BindProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
, &((*prog
)->Base
));
308 intel
->meta
.saved_fp_enable
= ctx
->FragmentProgram
.Enabled
;
309 _mesa_Enable(GL_FRAGMENT_PROGRAM_ARB
);
313 * Restores the previous fragment program after
314 * intel_meta_set_fragment_program()
317 intel_meta_restore_fragment_program(struct intel_context
*intel
)
319 GLcontext
*ctx
= &intel
->ctx
;
321 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
322 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
323 intel
->meta
.saved_fp
);
324 _mesa_reference_fragprog(ctx
, &intel
->meta
.saved_fp
, NULL
);
325 ctx
->Driver
.BindProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
326 &ctx
->FragmentProgram
.Current
->Base
);
328 if (!intel
->meta
.saved_fp_enable
)
329 _mesa_Disable(GL_FRAGMENT_PROGRAM_ARB
);
333 intelInitPixelFuncs(struct dd_function_table
*functions
)
335 functions
->Accum
= _swrast_Accum
;
336 if (!getenv("INTEL_NO_BLIT")) {
337 functions
->Bitmap
= intelBitmap
;
338 functions
->CopyPixels
= intelCopyPixels
;
339 functions
->DrawPixels
= intelDrawPixels
;
341 functions
->ReadPixels
= intelReadPixels
;
347 intel_free_pixel_state(struct intel_context
*intel
)
349 GLcontext
*ctx
= &intel
->ctx
;
351 _mesa_reference_vertprog(ctx
, &intel
->meta
.passthrough_vp
, NULL
);
352 _mesa_reference_fragprog(ctx
, &intel
->meta
.bitmap_fp
, NULL
);