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/texobj.h"
36 #include "main/texstate.h"
37 #include "main/matrix.h"
38 #include "main/varray.h"
39 #include "main/attrib.h"
40 #include "main/enable.h"
41 #include "glapi/dispatch.h"
42 #include "swrast/swrast.h"
44 #include "intel_screen.h"
45 #include "intel_context.h"
46 #include "intel_batchbuffer.h"
47 #include "intel_blit.h"
48 #include "intel_buffers.h"
49 #include "intel_regions.h"
50 #include "intel_pixel.h"
51 #include "intel_buffer_objects.h"
52 #include "intel_tris.h"
56 intel_texture_drawpixels(GLcontext
* ctx
,
58 GLsizei width
, GLsizei height
,
61 const struct gl_pixelstore_attrib
*unpack
,
65 GLfloat vertices
[4][4];
66 GLfloat texcoords
[4][2];
68 /* We're going to mess with texturing with no regard to existing texture
69 * state, so if there is some set up we have to bail.
71 if (ctx
->Texture
._EnabledUnits
!= 0)
74 /* Can't do textured DrawPixels with a fragment program, unless we were
75 * to generate a new program that sampled our texture and put the results
76 * in the fragment color before the user's program started.
78 if (ctx
->FragmentProgram
.Enabled
)
81 /* Don't even want to think about it */
82 if (format
== GL_COLOR_INDEX
)
85 /* We don't have a way to generate fragments with stencil values which *
86 * will set the resulting stencil value.
88 if (format
== GL_STENCIL_INDEX
)
91 /* To do DEPTH_COMPONENT, we would need to change our setup to not draw to
92 * the color buffer, and sample the texture values into the fragment depth
95 if (format
== GL_DEPTH_COMPONENT
)
98 _mesa_PushAttrib(GL_ENABLE_BIT
| GL_TRANSFORM_BIT
| GL_TEXTURE_BIT
|
100 _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT
);
102 /* XXX: pixel store stuff */
103 _mesa_Disable(GL_POLYGON_STIPPLE
);
105 _mesa_ActiveTextureARB(GL_TEXTURE0_ARB
);
106 _mesa_Enable(GL_TEXTURE_2D
);
107 _mesa_GenTextures(1, &texname
);
108 _mesa_BindTexture(GL_TEXTURE_2D
, texname
);
109 _mesa_TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
110 _mesa_TexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
111 _mesa_TexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
113 _mesa_TexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
114 _mesa_TexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
116 _mesa_TexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, width
, height
, 0, format
,
119 _mesa_MatrixMode(GL_PROJECTION
);
121 _mesa_LoadIdentity();
122 _mesa_Ortho(0, ctx
->DrawBuffer
->Width
, 0, ctx
->DrawBuffer
->Height
, 1, -1);
124 _mesa_MatrixMode(GL_MODELVIEW
);
126 _mesa_LoadIdentity();
130 vertices
[0][2] = ctx
->Current
.RasterPos
[2];
131 vertices
[0][3] = ctx
->Current
.RasterPos
[3];
132 vertices
[1][0] = x
+ width
* ctx
->Pixel
.ZoomX
;
134 vertices
[1][2] = ctx
->Current
.RasterPos
[2];
135 vertices
[1][3] = ctx
->Current
.RasterPos
[3];
136 vertices
[2][0] = x
+ width
* ctx
->Pixel
.ZoomX
;
137 vertices
[2][1] = y
+ height
* ctx
->Pixel
.ZoomY
;
138 vertices
[2][2] = ctx
->Current
.RasterPos
[2];
139 vertices
[2][3] = ctx
->Current
.RasterPos
[3];
141 vertices
[3][1] = y
+ height
* ctx
->Pixel
.ZoomY
;
142 vertices
[3][2] = ctx
->Current
.RasterPos
[2];
143 vertices
[3][3] = ctx
->Current
.RasterPos
[3];
145 texcoords
[0][0] = 0.0;
146 texcoords
[0][1] = 0.0;
147 texcoords
[1][0] = 1.0;
148 texcoords
[1][1] = 0.0;
149 texcoords
[2][0] = 1.0;
150 texcoords
[2][1] = 1.0;
151 texcoords
[3][0] = 0.0;
152 texcoords
[3][1] = 1.0;
154 _mesa_VertexPointer(4, GL_FLOAT
, 4 * sizeof(GLfloat
), &vertices
);
155 _mesa_TexCoordPointer(2, GL_FLOAT
, 2 * sizeof(GLfloat
), &texcoords
);
156 _mesa_Enable(GL_VERTEX_ARRAY
);
157 _mesa_Enable(GL_TEXTURE_COORD_ARRAY
);
158 CALL_DrawArrays(ctx
->Exec
, (GL_TRIANGLE_FAN
, 0, 4));
160 _mesa_MatrixMode(GL_PROJECTION
);
162 _mesa_MatrixMode(GL_MODELVIEW
);
164 _mesa_PopClientAttrib();
167 _mesa_DeleteTextures(1, &texname
);
173 intelDrawPixels(GLcontext
* ctx
,
175 GLsizei width
, GLsizei height
,
178 const struct gl_pixelstore_attrib
*unpack
,
179 const GLvoid
* pixels
)
181 if (intel_texture_drawpixels(ctx
, x
, y
, width
, height
, format
, type
,
185 if (INTEL_DEBUG
& DEBUG_PIXEL
)
186 _mesa_printf("%s: fallback to swrast\n", __FUNCTION__
);
188 if (ctx
->FragmentProgram
._Current
== ctx
->FragmentProgram
._TexEnvProgram
) {
190 * We don't want the i915 texenv program to be applied to DrawPixels.
191 * This is really just a performance optimization (mesa will other-
192 * wise happily run the fragment program on each pixel in the image).
194 struct gl_fragment_program
*fpSave
= ctx
->FragmentProgram
._Current
;
195 /* can't just set current frag prog to 0 here as on buffer resize
196 we'll get new state checks which will segfault. Remains a hack. */
197 ctx
->FragmentProgram
._Current
= NULL
;
198 ctx
->FragmentProgram
._UseTexEnvProgram
= GL_FALSE
;
199 ctx
->FragmentProgram
._Active
= GL_FALSE
;
200 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,
202 ctx
->FragmentProgram
._Current
= fpSave
;
203 ctx
->FragmentProgram
._UseTexEnvProgram
= GL_TRUE
;
204 ctx
->FragmentProgram
._Active
= GL_TRUE
;
205 _swrast_InvalidateState(ctx
, _NEW_PROGRAM
);
208 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,