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"
32 #include "framebuffer.h"
40 * If a fragment program is enabled, check that it's valid.
41 * \return GL_TRUE if valid, GL_FALSE otherwise
44 valid_fragment_program(GLcontext
*ctx
)
46 return !(ctx
->FragmentProgram
.Enabled
&& !ctx
->FragmentProgram
._Enabled
);
53 * Execute glDrawPixels
56 _mesa_DrawPixels( GLsizei width
, GLsizei height
,
57 GLenum format
, GLenum type
, const GLvoid
*pixels
)
59 GET_CURRENT_CONTEXT(ctx
);
60 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
62 if (width
< 0 || height
< 0) {
63 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDrawPixels(width or height < 0" );
67 /* We're not using the current vertex program, and the driver may install
70 _mesa_set_vp_override(ctx
, GL_TRUE
);
73 _mesa_update_state(ctx
);
76 if (!valid_fragment_program(ctx
)) {
77 _mesa_error(ctx
, GL_INVALID_OPERATION
,
78 "glDrawPixels (invalid fragment program)");
82 if (_mesa_error_check_format_type(ctx
, format
, type
, GL_TRUE
)) {
83 /* the error was already recorded */
87 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
88 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
89 "glDrawPixels(incomplete framebuffer)" );
93 if (!ctx
->Current
.RasterPosValid
) {
94 goto end
; /* no-op, not an error */
97 if (ctx
->RenderMode
== GL_RENDER
) {
98 if (width
> 0 && height
> 0) {
99 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
100 GLint x
= IROUND(ctx
->Current
.RasterPos
[0]);
101 GLint y
= IROUND(ctx
->Current
.RasterPos
[1]);
103 if (ctx
->Unpack
.BufferObj
->Name
) {
104 /* unpack from PBO */
105 if (!_mesa_validate_pbo_access(2, &ctx
->Unpack
, width
, height
, 1,
106 format
, type
, pixels
)) {
107 _mesa_error(ctx
, GL_INVALID_OPERATION
,
108 "glDrawPixels(invalid PBO access)");
111 if (_mesa_bufferobj_mapped(ctx
->Unpack
.BufferObj
)) {
112 /* buffer is mapped - that's an error */
113 _mesa_error(ctx
, GL_INVALID_OPERATION
,
114 "glDrawPixels(PBO is mapped)");
119 ctx
->Driver
.DrawPixels(ctx
, x
, y
, width
, height
, format
, type
,
120 &ctx
->Unpack
, pixels
);
123 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
124 /* Feedback the current raster pos info */
125 FLUSH_CURRENT( ctx
, 0 );
126 _mesa_feedback_token( ctx
, (GLfloat
) (GLint
) GL_DRAW_PIXEL_TOKEN
);
127 _mesa_feedback_vertex( ctx
,
128 ctx
->Current
.RasterPos
,
129 ctx
->Current
.RasterColor
,
130 ctx
->Current
.RasterIndex
,
131 ctx
->Current
.RasterTexCoords
[0] );
134 ASSERT(ctx
->RenderMode
== GL_SELECT
);
135 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
139 _mesa_set_vp_override(ctx
, GL_FALSE
);
144 _mesa_CopyPixels( GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
147 GET_CURRENT_CONTEXT(ctx
);
148 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
150 if (width
< 0 || height
< 0) {
151 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyPixels(width or height < 0)");
155 if (type
!= GL_COLOR
&& type
!= GL_DEPTH
&& type
!= GL_STENCIL
) {
156 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyPixels(type=%s)",
157 _mesa_lookup_enum_by_nr(type
));
161 /* We're not using the current vertex program, and the driver may install
164 _mesa_set_vp_override(ctx
, GL_TRUE
);
167 _mesa_update_state(ctx
);
170 if (!valid_fragment_program(ctx
)) {
171 _mesa_error(ctx
, GL_INVALID_OPERATION
,
172 "glCopyPixels (invalid fragment program)");
176 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
||
177 ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
178 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
179 "glCopyPixels(incomplete framebuffer)" );
183 if (!_mesa_source_buffer_exists(ctx
, type
) ||
184 !_mesa_dest_buffer_exists(ctx
, type
)) {
185 _mesa_error(ctx
, GL_INVALID_OPERATION
,
186 "glCopyPixels(missing source or dest buffer)");
190 if (!ctx
->Current
.RasterPosValid
|| width
==0 || height
== 0) {
191 goto end
; /* no-op, not an error */
194 if (ctx
->RenderMode
== GL_RENDER
) {
195 /* Round to satisfy conformance tests (matches SGI's OpenGL) */
196 if (width
> 0 && height
> 0) {
197 GLint destx
= IROUND(ctx
->Current
.RasterPos
[0]);
198 GLint desty
= IROUND(ctx
->Current
.RasterPos
[1]);
199 ctx
->Driver
.CopyPixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
,
203 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
204 FLUSH_CURRENT( ctx
, 0 );
205 _mesa_feedback_token( ctx
, (GLfloat
) (GLint
) GL_COPY_PIXEL_TOKEN
);
206 _mesa_feedback_vertex( ctx
,
207 ctx
->Current
.RasterPos
,
208 ctx
->Current
.RasterColor
,
209 ctx
->Current
.RasterIndex
,
210 ctx
->Current
.RasterTexCoords
[0] );
213 ASSERT(ctx
->RenderMode
== GL_SELECT
);
214 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
218 _mesa_set_vp_override(ctx
, GL_FALSE
);
221 #endif /* _HAVE_FULL_GL */
226 _mesa_Bitmap( GLsizei width
, GLsizei height
,
227 GLfloat xorig
, GLfloat yorig
, GLfloat xmove
, GLfloat ymove
,
228 const GLubyte
*bitmap
)
230 GET_CURRENT_CONTEXT(ctx
);
231 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
233 if (width
< 0 || height
< 0) {
234 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBitmap(width or height < 0)" );
238 if (!ctx
->Current
.RasterPosValid
) {
239 return; /* do nothing */
243 _mesa_update_state(ctx
);
246 if (!valid_fragment_program(ctx
)) {
247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
248 "glBitmap (invalid fragment program)");
252 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
253 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
254 "glBitmap(incomplete framebuffer)");
258 if (ctx
->RenderMode
== GL_RENDER
) {
259 /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
260 const GLfloat epsilon
= 0.0001F
;
261 GLint x
= IFLOOR(ctx
->Current
.RasterPos
[0] + epsilon
- xorig
);
262 GLint y
= IFLOOR(ctx
->Current
.RasterPos
[1] + epsilon
- yorig
);
264 if (ctx
->Unpack
.BufferObj
->Name
) {
265 /* unpack from PBO */
266 if (!_mesa_validate_pbo_access(2, &ctx
->Unpack
, width
, height
, 1,
267 GL_COLOR_INDEX
, GL_BITMAP
,
268 (GLvoid
*) bitmap
)) {
269 _mesa_error(ctx
, GL_INVALID_OPERATION
,
270 "glBitmap(invalid PBO access)");
273 if (_mesa_bufferobj_mapped(ctx
->Unpack
.BufferObj
)) {
274 /* buffer is mapped - that's an error */
275 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBitmap(PBO is mapped)");
280 ctx
->Driver
.Bitmap( ctx
, x
, y
, width
, height
, &ctx
->Unpack
, bitmap
);
283 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
284 FLUSH_CURRENT(ctx
, 0);
285 _mesa_feedback_token( ctx
, (GLfloat
) (GLint
) GL_BITMAP_TOKEN
);
286 _mesa_feedback_vertex( ctx
,
287 ctx
->Current
.RasterPos
,
288 ctx
->Current
.RasterColor
,
289 ctx
->Current
.RasterIndex
,
290 ctx
->Current
.RasterTexCoords
[0] );
293 ASSERT(ctx
->RenderMode
== GL_SELECT
);
294 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
298 /* update raster position */
299 ctx
->Current
.RasterPos
[0] += xmove
;
300 ctx
->Current
.RasterPos
[1] += ymove
;