1 /* $Id: drawpix.c,v 1.59 2002/01/15 21:49:57 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 * Execute glDrawPixels
49 _mesa_DrawPixels( GLsizei width
, GLsizei height
,
50 GLenum format
, GLenum type
, const GLvoid
*pixels
)
52 GET_CURRENT_CONTEXT(ctx
);
53 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
55 if (width
< 0 || height
< 0) {
56 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDrawPixels(width or height < 0" );
60 if (ctx
->RenderMode
==GL_RENDER
) {
62 if (!pixels
|| !ctx
->Current
.RasterPosValid
) {
67 _mesa_update_state(ctx
);
70 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
71 x
= IROUND(ctx
->Current
.RasterPos
[0]);
72 y
= IROUND(ctx
->Current
.RasterPos
[1]);
74 ctx
->OcclusionResult
= GL_TRUE
;
75 ctx
->Driver
.DrawPixels(ctx
, x
, y
, width
, height
, format
, type
,
76 &ctx
->Unpack
, pixels
);
78 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
79 /* Feedback the current raster pos info */
80 if (ctx
->Current
.RasterPosValid
) {
81 FLUSH_CURRENT( ctx
, 0 );
82 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_DRAW_PIXEL_TOKEN
);
83 _mesa_feedback_vertex( ctx
,
84 ctx
->Current
.RasterPos
,
85 ctx
->Current
.RasterColor
,
86 ctx
->Current
.RasterIndex
,
87 ctx
->Current
.RasterTexCoord
);
90 else if (ctx
->RenderMode
==GL_SELECT
) {
91 if (ctx
->Current
.RasterPosValid
) {
92 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
100 _mesa_ReadPixels( GLint x
, GLint y
, GLsizei width
, GLsizei height
,
101 GLenum format
, GLenum type
, GLvoid
*pixels
)
103 GET_CURRENT_CONTEXT(ctx
);
104 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
106 if (width
< 0 || height
< 0) {
107 _mesa_error( ctx
, GL_INVALID_VALUE
, "glReadPixels(width or height < 0)" );
112 _mesa_error( ctx
, GL_INVALID_VALUE
, "glReadPixels(pixels)" );
117 _mesa_update_state(ctx
);
119 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
120 format
, type
, &ctx
->Pack
, pixels
);
127 _mesa_CopyPixels( GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
130 GET_CURRENT_CONTEXT(ctx
);
132 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
134 if (width
< 0 || height
< 0) {
135 _mesa_error( ctx
, GL_INVALID_VALUE
, "glCopyPixels(width or height < 0)" );
140 _mesa_update_state(ctx
);
143 if (ctx
->RenderMode
==GL_RENDER
) {
144 /* Destination of copy: */
145 if (!ctx
->Current
.RasterPosValid
) {
149 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
150 destx
= IROUND(ctx
->Current
.RasterPos
[0]);
151 desty
= IROUND(ctx
->Current
.RasterPos
[1]);
153 ctx
->OcclusionResult
= GL_TRUE
;
155 ctx
->Driver
.CopyPixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
,
158 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
159 if (ctx
->Current
.RasterPosValid
) {
160 FLUSH_CURRENT( ctx
, 0 );
161 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_COPY_PIXEL_TOKEN
);
162 _mesa_feedback_vertex( ctx
,
163 ctx
->Current
.RasterPos
,
164 ctx
->Current
.RasterColor
,
165 ctx
->Current
.RasterIndex
,
166 ctx
->Current
.RasterTexCoord
);
169 else if (ctx
->RenderMode
== GL_SELECT
) {
170 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
177 _mesa_Bitmap( GLsizei width
, GLsizei height
,
178 GLfloat xorig
, GLfloat yorig
, GLfloat xmove
, GLfloat ymove
,
179 const GLubyte
*bitmap
)
181 GET_CURRENT_CONTEXT(ctx
);
182 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
184 if (width
< 0 || height
< 0) {
185 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBitmap(width or height < 0)" );
189 if (ctx
->Current
.RasterPosValid
== GL_FALSE
) {
190 return; /* do nothing */
193 if (ctx
->RenderMode
==GL_RENDER
) {
195 /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
196 GLint x
= IFLOOR(ctx
->Current
.RasterPos
[0] - xorig
);
197 GLint y
= IFLOOR(ctx
->Current
.RasterPos
[1] - yorig
);
200 _mesa_update_state(ctx
);
203 ctx
->OcclusionResult
= GL_TRUE
;
204 ctx
->Driver
.Bitmap( ctx
, x
, y
, width
, height
, &ctx
->Unpack
, bitmap
);
207 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
208 if (ctx
->Current
.RasterPosValid
) {
209 FLUSH_CURRENT(ctx
, 0);
210 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_BITMAP_TOKEN
);
211 _mesa_feedback_vertex( ctx
,
212 ctx
->Current
.RasterPos
,
213 ctx
->Current
.RasterColor
,
214 ctx
->Current
.RasterIndex
,
215 ctx
->Current
.RasterTexCoord
);
218 else if (ctx
->RenderMode
==GL_SELECT
) {
219 /* Bitmaps don't generate selection hits. See appendix B of 1.1 spec. */
222 /* update raster position */
223 ctx
->Current
.RasterPos
[0] += xmove
;
224 ctx
->Current
.RasterPos
[1] += ymove
;