Debian Codegraph @

nx-X11/extras/Mesa/src/mesa/main/drawpix.c

raw
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.4
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "glheader.h"
26 #include "imports.h"
27 #include "colormac.h"
28 #include "context.h"
29 #include "drawpix.h"
30 #include "feedback.h"
31 #include "macros.h"
32 #include "state.h"
33 #include "mtypes.h"
34
35
36 #if _HAVE_FULL_GL
37
38 /*
39 * Execute glDrawPixels
40 */
41 void GLAPIENTRY
42 _mesa_DrawPixels( GLsizei width, GLsizei height,
43 GLenum format, GLenum type, const GLvoid *pixels )
44 {
45 GET_CURRENT_CONTEXT(ctx);
46 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
47
48 if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
49 _mesa_error(ctx, GL_INVALID_OPERATION,
50 "glDrawPixels (invalid fragment program)");
51 return;
52 }
53
54 if (width < 0 || height < 0) {
55 _mesa_error( ctx, GL_INVALID_VALUE, "glDrawPixels(width or height < 0" );
56 return;
57 }
58
59 if (ctx->NewState) {
60 _mesa_update_state(ctx);
61 }
62
63 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
64 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
65 "glDrawPixels(incomplete framebuffer)" );
66 return;
67 }
68
69 if (!ctx->Current.RasterPosValid) {
70 return;
71 }
72
73 if (ctx->RenderMode == GL_RENDER) {
74 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
75 GLint x = IROUND(ctx->Current.RasterPos[0]);
76 GLint y = IROUND(ctx->Current.RasterPos[1]);
77 ctx->OcclusionResult = GL_TRUE;
78 ctx->Driver.DrawPixels(ctx, x, y, width, height, format, type,
79 &ctx->Unpack, pixels);
80 }
81 else if (ctx->RenderMode == GL_FEEDBACK) {
82 /* Feedback the current raster pos info */
83 FLUSH_CURRENT( ctx, 0 );
84 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN );
85 _mesa_feedback_vertex( ctx,
86 ctx->Current.RasterPos,
87 ctx->Current.RasterColor,
88 ctx->Current.RasterIndex,
89 ctx->Current.RasterTexCoords[0] );
90 }
91 else {
92 ASSERT(ctx->RenderMode == GL_SELECT);
93 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
94 }
95 }
96
97
98 void GLAPIENTRY
99 _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
100 GLenum type )
101 {
102 GET_CURRENT_CONTEXT(ctx);
103 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
104
105 if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
106 _mesa_error(ctx, GL_INVALID_OPERATION,
107 "glCopyPixels (invalid fragment program)");
108 return;
109 }
110
111 if (width < 0 || height < 0) {
112 _mesa_error( ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)" );
113 return;
114 }
115
116 if (ctx->NewState) {
117 _mesa_update_state(ctx);
118 }
119
120 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
121 ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
122 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
123 "glCopyPixels(incomplete framebuffer)" );
124 return;
125 }
126
127 if (!ctx->Current.RasterPosValid) {
128 return;
129 }
130
131 if (ctx->RenderMode == GL_RENDER) {
132 /* Round to satisfy conformance tests (matches SGI's OpenGL) */
133 GLint destx = IROUND(ctx->Current.RasterPos[0]);
134 GLint desty = IROUND(ctx->Current.RasterPos[1]);
135 ctx->OcclusionResult = GL_TRUE;
136 ctx->Driver.CopyPixels( ctx, srcx, srcy, width, height, destx, desty,
137 type );
138 }
139 else if (ctx->RenderMode == GL_FEEDBACK) {
140 FLUSH_CURRENT( ctx, 0 );
141 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_COPY_PIXEL_TOKEN );
142 _mesa_feedback_vertex( ctx,
143 ctx->Current.RasterPos,
144 ctx->Current.RasterColor,
145 ctx->Current.RasterIndex,
146 ctx->Current.RasterTexCoords[0] );
147 }
148 else {
149 ASSERT(ctx->RenderMode == GL_SELECT);
150 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
151 }
152 }
153
154 #endif /* _HAVE_FULL_GL */
155
156
157
158 void GLAPIENTRY
159 _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
160 GLenum format, GLenum type, GLvoid *pixels )
161 {
162 GET_CURRENT_CONTEXT(ctx);
163 const struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
164 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
165
166 if (width < 0 || height < 0) {
167 _mesa_error( ctx, GL_INVALID_VALUE,
168 "glReadPixels(width=%d height=%d)", width, height );
169 return;
170 }
171
172 if (ctx->NewState)
173 _mesa_update_state(ctx);
174
175 if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
176 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
177 "glReadPixels(incomplete framebuffer)" );
178 return;
179 }
180
181 if (!rb) {
182 _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
183 return;
184 }
185
186 ctx->Driver.ReadPixels(ctx, x, y, width, height,
187 format, type, &ctx->Pack, pixels);
188 }
189
190
191
192 void GLAPIENTRY
193 _mesa_Bitmap( GLsizei width, GLsizei height,
194 GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
195 const GLubyte *bitmap )
196 {
197 GET_CURRENT_CONTEXT(ctx);
198 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
199
200 if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
201 _mesa_error(ctx, GL_INVALID_OPERATION,
202 "glBitmap (invalid fragment program)");
203 return;
204 }
205
206 if (width < 0 || height < 0) {
207 _mesa_error( ctx, GL_INVALID_VALUE, "glBitmap(width or height < 0)" );
208 return;
209 }
210
211 if (!ctx->Current.RasterPosValid) {
212 return; /* do nothing */
213 }
214
215 if (ctx->NewState) {
216 _mesa_update_state(ctx);
217 }
218
219 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
220 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
221 "glBitmap(incomplete framebuffer)");
222 return;
223 }
224
225 if (ctx->RenderMode == GL_RENDER) {
226 /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
227 GLint x = IFLOOR(ctx->Current.RasterPos[0] - xorig);
228 GLint y = IFLOOR(ctx->Current.RasterPos[1] - yorig);
229 ctx->OcclusionResult = GL_TRUE;
230 ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
231 }
232 #if _HAVE_FULL_GL
233 else if (ctx->RenderMode == GL_FEEDBACK) {
234 FLUSH_CURRENT(ctx, 0);
235 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_BITMAP_TOKEN );
236 _mesa_feedback_vertex( ctx,
237 ctx->Current.RasterPos,
238 ctx->Current.RasterColor,
239 ctx->Current.RasterIndex,
240 ctx->Current.RasterTexCoords[0] );
241 }
242 else {
243 ASSERT(ctx->RenderMode == GL_SELECT);
244 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
245 }
246 #endif
247
248 /* update raster position */
249 ctx->Current.RasterPos[0] += xmove;
250 ctx->Current.RasterPos[1] += ymove;
251 }
252
253
254
255 #if 0 /* experimental */
256 /*
257 * Execute glDrawDepthPixelsMESA(). This function accepts both a color
258 * image and depth (Z) image. Rasterization produces fragments with
259 * color and Z taken from these images. This function is intended for
260 * Z-compositing. Normally, this operation requires two glDrawPixels
261 * calls with stencil testing.
262 */
263 void GLAPIENTRY
264 _mesa_DrawDepthPixelsMESA( GLsizei width, GLsizei height,
265 GLenum colorFormat, GLenum colorType,
266 const GLvoid *colors,
267 GLenum depthType, const GLvoid *depths )
268 {
269 GET_CURRENT_CONTEXT(ctx);
270 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
271
272 if (width < 0 || height < 0) {
273 _mesa_error( ctx, GL_INVALID_VALUE,
274 "glDrawDepthPixelsMESA(width or height < 0" );
275 return;
276 }
277
278 if (!ctx->Current.RasterPosValid) {
279 return;
280 }
281
282 if (ctx->NewState) {
283 _mesa_update_state(ctx);
284 }
285
286 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
287 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
288 "glDrawDepthPixelsMESA(incomplete framebuffer)");
289 return;
290 }
291
292 if (ctx->RenderMode == GL_RENDER) {
293 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
294 GLint x = IROUND(ctx->Current.RasterPos[0]);
295 GLint y = IROUND(ctx->Current.RasterPos[1]);
296 ctx->OcclusionResult = GL_TRUE;
297 ctx->Driver.DrawDepthPixelsMESA(ctx, x, y, width, height,
298 colorFormat, colorType, colors,
299 depthType, depths, &ctx->Unpack);
300 }
301 else if (ctx->RenderMode == GL_FEEDBACK) {
302 /* Feedback the current raster pos info */
303 FLUSH_CURRENT( ctx, 0 );
304 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN );
305 _mesa_feedback_vertex( ctx,
306 ctx->Current.RasterPos,
307 ctx->Current.RasterColor,
308 ctx->Current.RasterIndex,
309 ctx->Current.RasterTexCoords[0] );
310 }
311 else {
312 ASSERT(ctx->RenderMode == GL_SELECT);
313 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
314 }
315 }
316
317 #endif