Mesa: allow suppression of debug messages in a debug build
[mesa.git] / src / mesa / main / drawpix.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2008 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 "bufferobj.h"
28 #include "context.h"
29 #include "drawpix.h"
30 #include "feedback.h"
31 #include "framebuffer.h"
32 #include "image.h"
33 #include "readpix.h"
34 #include "state.h"
35
36
37 #if _HAVE_FULL_GL
38
39 /*
40 * Execute glDrawPixels
41 */
42 void GLAPIENTRY
43 _mesa_DrawPixels( GLsizei width, GLsizei height,
44 GLenum format, GLenum type, const GLvoid *pixels )
45 {
46 GET_CURRENT_CONTEXT(ctx);
47 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
48
49 if (width < 0 || height < 0) {
50 _mesa_error( ctx, GL_INVALID_VALUE, "glDrawPixels(width or height < 0" );
51 return;
52 }
53
54 if (ctx->NewState) {
55 _mesa_update_state(ctx);
56 }
57
58 if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
59 _mesa_error(ctx, GL_INVALID_OPERATION,
60 "glDrawPixels (invalid fragment program)");
61 return;
62 }
63
64 if (_mesa_error_check_format_type(ctx, format, type, GL_TRUE)) {
65 /* found an error */
66 return;
67 }
68
69 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
70 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
71 "glDrawPixels(incomplete framebuffer)" );
72 return;
73 }
74
75 if (!ctx->Current.RasterPosValid) {
76 return;
77 }
78
79 if (ctx->RenderMode == GL_RENDER) {
80 if (width > 0 && height > 0) {
81 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
82 GLint x = IROUND(ctx->Current.RasterPos[0]);
83 GLint y = IROUND(ctx->Current.RasterPos[1]);
84
85 if (ctx->Unpack.BufferObj->Name) {
86 /* unpack from PBO */
87 if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
88 format, type, pixels)) {
89 _mesa_error(ctx, GL_INVALID_OPERATION,
90 "glDrawPixels(invalid PBO access)");
91 return;
92 }
93 if (ctx->Unpack.BufferObj->Pointer) {
94 /* buffer is mapped - that's an error */
95 _mesa_error(ctx, GL_INVALID_OPERATION,
96 "glDrawPixels(PBO is mapped)");
97 return;
98 }
99 }
100
101 ctx->Driver.DrawPixels(ctx, x, y, width, height, format, type,
102 &ctx->Unpack, pixels);
103 }
104 }
105 else if (ctx->RenderMode == GL_FEEDBACK) {
106 /* Feedback the current raster pos info */
107 FLUSH_CURRENT( ctx, 0 );
108 _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN );
109 _mesa_feedback_vertex( ctx,
110 ctx->Current.RasterPos,
111 ctx->Current.RasterColor,
112 ctx->Current.RasterIndex,
113 ctx->Current.RasterTexCoords[0] );
114 }
115 else {
116 ASSERT(ctx->RenderMode == GL_SELECT);
117 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
118 }
119 }
120
121
122 void GLAPIENTRY
123 _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
124 GLenum type )
125 {
126 GET_CURRENT_CONTEXT(ctx);
127 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
128
129 if (ctx->NewState) {
130 _mesa_update_state(ctx);
131 }
132
133 if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
134 _mesa_error(ctx, GL_INVALID_OPERATION,
135 "glCopyPixels (invalid fragment program)");
136 return;
137 }
138
139 if (width < 0 || height < 0) {
140 _mesa_error(ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)");
141 return;
142 }
143
144 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
145 ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
146 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
147 "glCopyPixels(incomplete framebuffer)" );
148 return;
149 }
150
151 if (!_mesa_source_buffer_exists(ctx, type) ||
152 !_mesa_dest_buffer_exists(ctx, type)) {
153 _mesa_error(ctx, GL_INVALID_OPERATION,
154 "glCopyPixels(missing source or dest buffer)");
155 return;
156 }
157
158 if (!ctx->Current.RasterPosValid || width ==0 || height == 0) {
159 return;
160 }
161
162 if (ctx->RenderMode == GL_RENDER) {
163 /* Round to satisfy conformance tests (matches SGI's OpenGL) */
164 if (width > 0 && height > 0) {
165 GLint destx = IROUND(ctx->Current.RasterPos[0]);
166 GLint desty = IROUND(ctx->Current.RasterPos[1]);
167 ctx->Driver.CopyPixels( ctx, srcx, srcy, width, height, destx, desty,
168 type );
169 }
170 }
171 else if (ctx->RenderMode == GL_FEEDBACK) {
172 FLUSH_CURRENT( ctx, 0 );
173 _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_COPY_PIXEL_TOKEN );
174 _mesa_feedback_vertex( ctx,
175 ctx->Current.RasterPos,
176 ctx->Current.RasterColor,
177 ctx->Current.RasterIndex,
178 ctx->Current.RasterTexCoords[0] );
179 }
180 else {
181 ASSERT(ctx->RenderMode == GL_SELECT);
182 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
183 }
184 }
185
186 #endif /* _HAVE_FULL_GL */
187
188
189
190 void GLAPIENTRY
191 _mesa_Bitmap( GLsizei width, GLsizei height,
192 GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
193 const GLubyte *bitmap )
194 {
195 GET_CURRENT_CONTEXT(ctx);
196 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
197
198 if (width < 0 || height < 0) {
199 _mesa_error( ctx, GL_INVALID_VALUE, "glBitmap(width or height < 0)" );
200 return;
201 }
202
203 if (!ctx->Current.RasterPosValid) {
204 return; /* do nothing */
205 }
206
207 if (ctx->NewState) {
208 _mesa_update_state(ctx);
209 }
210
211 if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
212 _mesa_error(ctx, GL_INVALID_OPERATION,
213 "glBitmap (invalid fragment program)");
214 return;
215 }
216
217 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
218 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
219 "glBitmap(incomplete framebuffer)");
220 return;
221 }
222
223 if (ctx->RenderMode == GL_RENDER) {
224 /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
225 const GLfloat epsilon = 0.0001F;
226 GLint x = IFLOOR(ctx->Current.RasterPos[0] + epsilon - xorig);
227 GLint y = IFLOOR(ctx->Current.RasterPos[1] + epsilon - yorig);
228
229 if (ctx->Unpack.BufferObj->Name) {
230 /* unpack from PBO */
231 if (!_mesa_validate_pbo_access(2, &ctx->Unpack, width, height, 1,
232 GL_COLOR_INDEX, GL_BITMAP,
233 (GLvoid *) bitmap)) {
234 _mesa_error(ctx, GL_INVALID_OPERATION,
235 "glBitmap(invalid PBO access)");
236 return;
237 }
238 if (ctx->Unpack.BufferObj->Pointer) {
239 /* buffer is mapped - that's an error */
240 _mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)");
241 return;
242 }
243 }
244
245 ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
246 }
247 #if _HAVE_FULL_GL
248 else if (ctx->RenderMode == GL_FEEDBACK) {
249 FLUSH_CURRENT(ctx, 0);
250 _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_BITMAP_TOKEN );
251 _mesa_feedback_vertex( ctx,
252 ctx->Current.RasterPos,
253 ctx->Current.RasterColor,
254 ctx->Current.RasterIndex,
255 ctx->Current.RasterTexCoords[0] );
256 }
257 else {
258 ASSERT(ctx->RenderMode == GL_SELECT);
259 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
260 }
261 #endif
262
263 /* update raster position */
264 ctx->Current.RasterPos[0] += xmove;
265 ctx->Current.RasterPos[1] += ymove;
266 }
267
268
269
270 #if 0 /* experimental */
271 /*
272 * Execute glDrawDepthPixelsMESA(). This function accepts both a color
273 * image and depth (Z) image. Rasterization produces fragments with
274 * color and Z taken from these images. This function is intended for
275 * Z-compositing. Normally, this operation requires two glDrawPixels
276 * calls with stencil testing.
277 */
278 void GLAPIENTRY
279 _mesa_DrawDepthPixelsMESA( GLsizei width, GLsizei height,
280 GLenum colorFormat, GLenum colorType,
281 const GLvoid *colors,
282 GLenum depthType, const GLvoid *depths )
283 {
284 GET_CURRENT_CONTEXT(ctx);
285 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
286
287 if (width < 0 || height < 0) {
288 _mesa_error( ctx, GL_INVALID_VALUE,
289 "glDrawDepthPixelsMESA(width or height < 0" );
290 return;
291 }
292
293 if (!ctx->Current.RasterPosValid) {
294 return;
295 }
296
297 if (ctx->NewState) {
298 _mesa_update_state(ctx);
299 }
300
301 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
302 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
303 "glDrawDepthPixelsMESA(incomplete framebuffer)");
304 return;
305 }
306
307 if (ctx->RenderMode == GL_RENDER) {
308 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
309 GLint x = IROUND(ctx->Current.RasterPos[0]);
310 GLint y = IROUND(ctx->Current.RasterPos[1]);
311 ctx->Driver.DrawDepthPixelsMESA(ctx, x, y, width, height,
312 colorFormat, colorType, colors,
313 depthType, depths, &ctx->Unpack);
314 }
315 else if (ctx->RenderMode == GL_FEEDBACK) {
316 /* Feedback the current raster pos info */
317 FLUSH_CURRENT( ctx, 0 );
318 _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN );
319 _mesa_feedback_vertex( ctx,
320 ctx->Current.RasterPos,
321 ctx->Current.RasterColor,
322 ctx->Current.RasterIndex,
323 ctx->Current.RasterTexCoords[0] );
324 }
325 else {
326 ASSERT(ctx->RenderMode == GL_SELECT);
327 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
328 }
329 }
330
331 #endif