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/glheader.h"
29 #include "main/enums.h"
30 #include "main/image.h"
31 #include "main/mtypes.h"
32 #include "main/macros.h"
33 #include "main/bufferobj.h"
34 #include "main/teximage.h"
35 #include "main/texenv.h"
36 #include "main/texobj.h"
37 #include "main/texstate.h"
38 #include "main/texparam.h"
39 #include "main/matrix.h"
40 #include "main/varray.h"
41 #include "main/attrib.h"
42 #include "main/enable.h"
43 #include "glapi/dispatch.h"
44 #include "swrast/swrast.h"
46 #include "intel_screen.h"
47 #include "intel_context.h"
48 #include "intel_batchbuffer.h"
49 #include "intel_blit.h"
50 #include "intel_buffers.h"
51 #include "intel_regions.h"
52 #include "intel_pixel.h"
53 #include "intel_buffer_objects.h"
57 intel_texture_drawpixels(GLcontext
* ctx
,
59 GLsizei width
, GLsizei height
,
62 const struct gl_pixelstore_attrib
*unpack
,
66 GLfloat vertices
[4][4];
67 GLfloat texcoords
[4][2];
69 /* We're going to mess with texturing with no regard to existing texture
70 * state, so if there is some set up we have to bail.
72 if (ctx
->Texture
._EnabledUnits
!= 0)
75 /* Can't do textured DrawPixels with a fragment program, unless we were
76 * to generate a new program that sampled our texture and put the results
77 * in the fragment color before the user's program started.
79 if (ctx
->FragmentProgram
.Enabled
)
82 /* Don't even want to think about it */
83 if (format
== GL_COLOR_INDEX
)
86 /* We don't have a way to generate fragments with stencil values which *
87 * will set the resulting stencil value.
89 if (format
== GL_STENCIL_INDEX
)
92 /* To do DEPTH_COMPONENT, we would need to change our setup to not draw to
93 * the color buffer, and sample the texture values into the fragment depth
96 if (format
== GL_DEPTH_COMPONENT
)
99 _mesa_PushAttrib(GL_ENABLE_BIT
| GL_TRANSFORM_BIT
| GL_TEXTURE_BIT
|
101 _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT
);
103 /* XXX: pixel store stuff */
104 _mesa_Disable(GL_POLYGON_STIPPLE
);
106 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
);
107 _mesa_Enable(GL_TEXTURE_2D
);
108 _mesa_GenTextures(1, &texname
);
109 _mesa_BindTexture(GL_TEXTURE_2D
, texname
);
110 _mesa_TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
111 _mesa_TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
112 _mesa_TexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
114 _mesa_TexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
115 _mesa_TexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
117 _mesa_TexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, width
, height
, 0, format
,
120 _mesa_MatrixMode(GL_PROJECTION
);
122 _mesa_LoadIdentity();
123 _mesa_Ortho(0, ctx
->DrawBuffer
->Width
, 0, ctx
->DrawBuffer
->Height
, 1, -1);
125 _mesa_MatrixMode(GL_MODELVIEW
);
127 _mesa_LoadIdentity();
131 vertices
[0][2] = ctx
->Current
.RasterPos
[2];
132 vertices
[0][3] = ctx
->Current
.RasterPos
[3];
133 vertices
[1][0] = x
+ width
* ctx
->Pixel
.ZoomX
;
135 vertices
[1][2] = ctx
->Current
.RasterPos
[2];
136 vertices
[1][3] = ctx
->Current
.RasterPos
[3];
137 vertices
[2][0] = x
+ width
* ctx
->Pixel
.ZoomX
;
138 vertices
[2][1] = y
+ height
* ctx
->Pixel
.ZoomY
;
139 vertices
[2][2] = ctx
->Current
.RasterPos
[2];
140 vertices
[2][3] = ctx
->Current
.RasterPos
[3];
142 vertices
[3][1] = y
+ height
* ctx
->Pixel
.ZoomY
;
143 vertices
[3][2] = ctx
->Current
.RasterPos
[2];
144 vertices
[3][3] = ctx
->Current
.RasterPos
[3];
146 texcoords
[0][0] = 0.0;
147 texcoords
[0][1] = 0.0;
148 texcoords
[1][0] = 1.0;
149 texcoords
[1][1] = 0.0;
150 texcoords
[2][0] = 1.0;
151 texcoords
[2][1] = 1.0;
152 texcoords
[3][0] = 0.0;
153 texcoords
[3][1] = 1.0;
155 _mesa_VertexPointer(4, GL_FLOAT
, 4 * sizeof(GLfloat
), &vertices
);
156 _mesa_TexCoordPointer(2, GL_FLOAT
, 2 * sizeof(GLfloat
), &texcoords
);
157 _mesa_Enable(GL_VERTEX_ARRAY
);
158 _mesa_Enable(GL_TEXTURE_COORD_ARRAY
);
159 CALL_DrawArrays(ctx
->Exec
, (GL_TRIANGLE_FAN
, 0, 4));
161 _mesa_MatrixMode(GL_PROJECTION
);
163 _mesa_MatrixMode(GL_MODELVIEW
);
165 _mesa_PopClientAttrib();
168 _mesa_DeleteTextures(1, &texname
);
174 intelDrawPixels(GLcontext
* ctx
,
176 GLsizei width
, GLsizei height
,
179 const struct gl_pixelstore_attrib
*unpack
,
180 const GLvoid
* pixels
)
182 if (intel_texture_drawpixels(ctx
, x
, y
, width
, height
, format
, type
,
186 if (INTEL_DEBUG
& DEBUG_PIXEL
)
187 _mesa_printf("%s: fallback to swrast\n", __FUNCTION__
);
189 if (ctx
->FragmentProgram
._Current
== ctx
->FragmentProgram
._TexEnvProgram
) {
191 * We don't want the i915 texenv program to be applied to DrawPixels.
192 * This is really just a performance optimization (mesa will other-
193 * wise happily run the fragment program on each pixel in the image).
195 struct gl_fragment_program
*fpSave
= ctx
->FragmentProgram
._Current
;
196 /* can't just set current frag prog to 0 here as on buffer resize
197 we'll get new state checks which will segfault. Remains a hack. */
198 ctx
->FragmentProgram
._Current
= NULL
;
199 ctx
->FragmentProgram
._UseTexEnvProgram
= GL_FALSE
;
200 ctx
->FragmentProgram
._Active
= GL_FALSE
;
201 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,
203 ctx
->FragmentProgram
._Current
= fpSave
;
204 ctx
->FragmentProgram
._UseTexEnvProgram
= GL_TRUE
;
205 ctx
->FragmentProgram
._Active
= GL_TRUE
;
206 _swrast_InvalidateState(ctx
, _NEW_PROGRAM
);
209 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,