2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
27 #include "bufferobj.h"
31 #include "framebuffer.h"
40 * Execute glDrawPixels
43 _mesa_DrawPixels( GLsizei width
, GLsizei height
,
44 GLenum format
, GLenum type
, const GLvoid
*pixels
)
46 GET_CURRENT_CONTEXT(ctx
);
47 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
49 if (width
< 0 || height
< 0) {
50 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDrawPixels(width or height < 0" );
55 _mesa_update_state(ctx
);
58 if (ctx
->FragmentProgram
.Enabled
&& !ctx
->FragmentProgram
._Enabled
) {
59 _mesa_error(ctx
, GL_INVALID_OPERATION
,
60 "glDrawPixels (invalid fragment program)");
64 if (_mesa_error_check_format_type(ctx
, format
, type
, GL_TRUE
)) {
69 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
70 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
71 "glDrawPixels(incomplete framebuffer)" );
75 if (!ctx
->Current
.RasterPosValid
) {
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]);
85 if (ctx
->Unpack
.BufferObj
->Name
) {
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)");
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)");
101 ctx
->Driver
.DrawPixels(ctx
, x
, y
, width
, height
, format
, type
,
102 &ctx
->Unpack
, pixels
);
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] );
116 ASSERT(ctx
->RenderMode
== GL_SELECT
);
117 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
123 _mesa_CopyPixels( GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
126 GET_CURRENT_CONTEXT(ctx
);
127 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
130 _mesa_update_state(ctx
);
133 if (ctx
->FragmentProgram
.Enabled
&& !ctx
->FragmentProgram
._Enabled
) {
134 _mesa_error(ctx
, GL_INVALID_OPERATION
,
135 "glCopyPixels (invalid fragment program)");
139 if (width
< 0 || height
< 0) {
140 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyPixels(width or height < 0)");
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)" );
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)");
158 if (!ctx
->Current
.RasterPosValid
|| width
==0 || height
== 0) {
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
,
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] );
181 ASSERT(ctx
->RenderMode
== GL_SELECT
);
182 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
186 #endif /* _HAVE_FULL_GL */
191 _mesa_Bitmap( GLsizei width
, GLsizei height
,
192 GLfloat xorig
, GLfloat yorig
, GLfloat xmove
, GLfloat ymove
,
193 const GLubyte
*bitmap
)
195 GET_CURRENT_CONTEXT(ctx
);
196 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
198 if (width
< 0 || height
< 0) {
199 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBitmap(width or height < 0)" );
203 if (!ctx
->Current
.RasterPosValid
) {
204 return; /* do nothing */
208 _mesa_update_state(ctx
);
211 if (ctx
->FragmentProgram
.Enabled
&& !ctx
->FragmentProgram
._Enabled
) {
212 _mesa_error(ctx
, GL_INVALID_OPERATION
,
213 "glBitmap (invalid fragment program)");
217 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
218 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
219 "glBitmap(incomplete framebuffer)");
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
);
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)");
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)");
245 ctx
->Driver
.Bitmap( ctx
, x
, y
, width
, height
, &ctx
->Unpack
, bitmap
);
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] );
258 ASSERT(ctx
->RenderMode
== GL_SELECT
);
259 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
263 /* update raster position */
264 ctx
->Current
.RasterPos
[0] += xmove
;
265 ctx
->Current
.RasterPos
[1] += ymove
;
270 #if 0 /* experimental */
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.
279 _mesa_DrawDepthPixelsMESA( GLsizei width
, GLsizei height
,
280 GLenum colorFormat
, GLenum colorType
,
281 const GLvoid
*colors
,
282 GLenum depthType
, const GLvoid
*depths
)
284 GET_CURRENT_CONTEXT(ctx
);
285 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
287 if (width
< 0 || height
< 0) {
288 _mesa_error( ctx
, GL_INVALID_VALUE
,
289 "glDrawDepthPixelsMESA(width or height < 0" );
293 if (!ctx
->Current
.RasterPosValid
) {
298 _mesa_update_state(ctx
);
301 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
302 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
303 "glDrawDepthPixelsMESA(incomplete framebuffer)");
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
);
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] );
326 ASSERT(ctx
->RenderMode
== GL_SELECT
);
327 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */