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"
34 #include "mfeatures.h"
44 * Execute glDrawPixels
46 static void GLAPIENTRY
47 _mesa_DrawPixels( GLsizei width
, GLsizei height
,
48 GLenum format
, GLenum type
, const GLvoid
*pixels
)
50 GET_CURRENT_CONTEXT(ctx
);
51 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
53 if (MESA_VERBOSE
& VERBOSE_API
)
54 _mesa_debug(ctx
, "glDrawPixels(%d, %d, %s, %s, %p) // to %s at %d, %d\n",
56 _mesa_lookup_enum_by_nr(format
),
57 _mesa_lookup_enum_by_nr(type
),
59 _mesa_lookup_enum_by_nr(ctx
->DrawBuffer
->ColorDrawBuffer
),
60 IROUND(ctx
->Current
.RasterPos
[0]),
61 IROUND(ctx
->Current
.RasterPos
[1]));
64 if (width
< 0 || height
< 0) {
65 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDrawPixels(width or height < 0)" );
69 /* Note: this call does state validation */
70 if (!_mesa_valid_to_render(ctx
, "glDrawPixels")) {
71 return; /* the error code was recorded */
74 /* GL 3.0 introduced a new restriction on glDrawPixels() over what was in
75 * GL_EXT_texture_integer. From section 3.7.4 ("Rasterization of Pixel
76 * Rectangles) on page 151 of the GL 3.0 specification:
78 * "If format contains integer components, as shown in table 3.6, an
79 * INVALID OPERATION error is generated."
81 * Since DrawPixels rendering would be merely undefined if not an error (due
82 * to a lack of defined mapping from integer data to gl_Color fragment shader
83 * input), NVIDIA's implementation also just returns this error despite
84 * exposing GL_EXT_texture_integer, just return an error regardless.
86 if (_mesa_is_integer_format(format
)) {
87 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glDrawPixels(integer format)");
91 if (_mesa_error_check_format_type(ctx
, format
, type
, GL_TRUE
)) {
92 return; /* the error code was recorded */
95 if (ctx
->RasterDiscard
) {
99 if (!ctx
->Current
.RasterPosValid
) {
100 return; /* no-op, not an error */
103 if (ctx
->RenderMode
== GL_RENDER
) {
104 if (width
> 0 && height
> 0) {
105 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
106 GLint x
= IROUND(ctx
->Current
.RasterPos
[0]);
107 GLint y
= IROUND(ctx
->Current
.RasterPos
[1]);
109 ctx
->Driver
.DrawPixels(ctx
, x
, y
, width
, height
, format
, type
,
110 &ctx
->Unpack
, pixels
);
113 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
114 /* Feedback the current raster pos info */
115 FLUSH_CURRENT( ctx
, 0 );
116 _mesa_feedback_token( ctx
, (GLfloat
) (GLint
) GL_DRAW_PIXEL_TOKEN
);
117 _mesa_feedback_vertex( ctx
,
118 ctx
->Current
.RasterPos
,
119 ctx
->Current
.RasterColor
,
120 ctx
->Current
.RasterTexCoords
);
123 ASSERT(ctx
->RenderMode
== GL_SELECT
);
124 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
129 static void GLAPIENTRY
130 _mesa_CopyPixels( GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
133 GET_CURRENT_CONTEXT(ctx
);
134 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
136 if (MESA_VERBOSE
& VERBOSE_API
)
138 "glCopyPixels(%d, %d, %d, %d, %s) // from %s to %s at %d, %d\n",
139 srcx
, srcy
, width
, height
,
140 _mesa_lookup_enum_by_nr(type
),
141 _mesa_lookup_enum_by_nr(ctx
->ReadBuffer
->ColorReadBuffer
),
142 _mesa_lookup_enum_by_nr(ctx
->DrawBuffer
->ColorDrawBuffer
),
143 IROUND(ctx
->Current
.RasterPos
[0]),
144 IROUND(ctx
->Current
.RasterPos
[1]));
146 if (width
< 0 || height
< 0) {
147 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyPixels(width or height < 0)");
151 /* Note: more detailed 'type' checking is done by the
152 * _mesa_source/dest_buffer_exists() calls below. That's where we
153 * check if the stencil buffer exists, etc.
155 if (type
!= GL_COLOR
&&
157 type
!= GL_STENCIL
) {
158 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyPixels(type=%s)",
159 _mesa_lookup_enum_by_nr(type
));
163 /* Note: this call does state validation */
164 if (!_mesa_valid_to_render(ctx
, "glCopyPixels")) {
165 return; /* the error code was recorded */
168 if (!_mesa_source_buffer_exists(ctx
, type
) ||
169 !_mesa_dest_buffer_exists(ctx
, type
)) {
170 _mesa_error(ctx
, GL_INVALID_OPERATION
,
171 "glCopyPixels(missing source or dest buffer)");
175 if (ctx
->RasterDiscard
) {
179 if (!ctx
->Current
.RasterPosValid
|| width
== 0 || height
== 0) {
180 return; /* no-op, not an error */
183 if (ctx
->RenderMode
== GL_RENDER
) {
184 /* Round to satisfy conformance tests (matches SGI's OpenGL) */
185 if (width
> 0 && height
> 0) {
186 GLint destx
= IROUND(ctx
->Current
.RasterPos
[0]);
187 GLint desty
= IROUND(ctx
->Current
.RasterPos
[1]);
188 ctx
->Driver
.CopyPixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
,
192 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
193 FLUSH_CURRENT( ctx
, 0 );
194 _mesa_feedback_token( ctx
, (GLfloat
) (GLint
) GL_COPY_PIXEL_TOKEN
);
195 _mesa_feedback_vertex( ctx
,
196 ctx
->Current
.RasterPos
,
197 ctx
->Current
.RasterColor
,
198 ctx
->Current
.RasterTexCoords
);
201 ASSERT(ctx
->RenderMode
== GL_SELECT
);
202 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
207 static void GLAPIENTRY
208 _mesa_Bitmap( GLsizei width
, GLsizei height
,
209 GLfloat xorig
, GLfloat yorig
, GLfloat xmove
, GLfloat ymove
,
210 const GLubyte
*bitmap
)
212 GET_CURRENT_CONTEXT(ctx
);
213 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
215 if (width
< 0 || height
< 0) {
216 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBitmap(width or height < 0)" );
220 if (!ctx
->Current
.RasterPosValid
) {
221 return; /* do nothing */
224 /* Note: this call does state validation */
225 if (!_mesa_valid_to_render(ctx
, "glBitmap")) {
226 /* the error code was recorded */
230 if (ctx
->RasterDiscard
)
233 if (ctx
->RenderMode
== GL_RENDER
) {
234 /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
235 if (width
> 0 && height
> 0) {
236 const GLfloat epsilon
= 0.0001F
;
237 GLint x
= IFLOOR(ctx
->Current
.RasterPos
[0] + epsilon
- xorig
);
238 GLint y
= IFLOOR(ctx
->Current
.RasterPos
[1] + epsilon
- yorig
);
240 ctx
->Driver
.Bitmap( ctx
, x
, y
, width
, height
, &ctx
->Unpack
, bitmap
);
244 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
245 FLUSH_CURRENT(ctx
, 0);
246 _mesa_feedback_token( ctx
, (GLfloat
) (GLint
) GL_BITMAP_TOKEN
);
247 _mesa_feedback_vertex( ctx
,
248 ctx
->Current
.RasterPos
,
249 ctx
->Current
.RasterColor
,
250 ctx
->Current
.RasterTexCoords
);
253 ASSERT(ctx
->RenderMode
== GL_SELECT
);
254 /* Do nothing. See OpenGL Spec, Appendix B, Corollary 6. */
258 /* update raster position */
259 ctx
->Current
.RasterPos
[0] += xmove
;
260 ctx
->Current
.RasterPos
[1] += ymove
;
265 _mesa_init_drawpix_dispatch(struct _glapi_table
*disp
)
267 SET_Bitmap(disp
, _mesa_Bitmap
);
268 SET_CopyPixels(disp
, _mesa_CopyPixels
);
269 SET_DrawPixels(disp
, _mesa_DrawPixels
);
273 #endif /* FEATURE_drawpix */