ac1c68af5ed3020a87389223f41c5ee1585855c1
1 /* $Id: drawpix.c,v 1.58 2001/12/14 02:55:08 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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 (ctx
->RenderMode
==GL_RENDER
) {
57 if (!pixels
|| !ctx
->Current
.RasterPosValid
) {
62 _mesa_update_state(ctx
);
65 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
66 x
= IROUND(ctx
->Current
.RasterPos
[0]);
67 y
= IROUND(ctx
->Current
.RasterPos
[1]);
69 ctx
->OcclusionResult
= GL_TRUE
;
70 ctx
->Driver
.DrawPixels(ctx
, x
, y
, width
, height
, format
, type
,
71 &ctx
->Unpack
, pixels
);
73 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
74 /* Feedback the current raster pos info */
75 if (ctx
->Current
.RasterPosValid
) {
76 FLUSH_CURRENT( ctx
, 0 );
77 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_DRAW_PIXEL_TOKEN
);
78 _mesa_feedback_vertex( ctx
,
79 ctx
->Current
.RasterPos
,
80 ctx
->Current
.RasterColor
,
81 ctx
->Current
.RasterIndex
,
82 ctx
->Current
.RasterTexCoord
);
85 else if (ctx
->RenderMode
==GL_SELECT
) {
86 if (ctx
->Current
.RasterPosValid
) {
87 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
95 _mesa_ReadPixels( GLint x
, GLint y
, GLsizei width
, GLsizei height
,
96 GLenum format
, GLenum type
, GLvoid
*pixels
)
98 GET_CURRENT_CONTEXT(ctx
);
99 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
102 _mesa_error( ctx
, GL_INVALID_VALUE
, "glReadPixels(pixels)" );
107 _mesa_update_state(ctx
);
109 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
110 format
, type
, &ctx
->Pack
, pixels
);
117 _mesa_CopyPixels( GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
120 GET_CURRENT_CONTEXT(ctx
);
122 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
124 if (width
< 0 || height
< 0) {
125 _mesa_error( ctx
, GL_INVALID_VALUE
, "glCopyPixels" );
130 _mesa_update_state(ctx
);
133 if (ctx
->RenderMode
==GL_RENDER
) {
134 /* Destination of copy: */
135 if (!ctx
->Current
.RasterPosValid
) {
139 /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
140 destx
= IROUND(ctx
->Current
.RasterPos
[0]);
141 desty
= IROUND(ctx
->Current
.RasterPos
[1]);
143 ctx
->OcclusionResult
= GL_TRUE
;
145 ctx
->Driver
.CopyPixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
,
148 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
149 if (ctx
->Current
.RasterPosValid
) {
150 FLUSH_CURRENT( ctx
, 0 );
151 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_COPY_PIXEL_TOKEN
);
152 _mesa_feedback_vertex( ctx
,
153 ctx
->Current
.RasterPos
,
154 ctx
->Current
.RasterColor
,
155 ctx
->Current
.RasterIndex
,
156 ctx
->Current
.RasterTexCoord
);
159 else if (ctx
->RenderMode
== GL_SELECT
) {
160 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
167 _mesa_Bitmap( GLsizei width
, GLsizei height
,
168 GLfloat xorig
, GLfloat yorig
, GLfloat xmove
, GLfloat ymove
,
169 const GLubyte
*bitmap
)
171 GET_CURRENT_CONTEXT(ctx
);
172 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
175 if (width
< 0 || height
< 0) {
176 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBitmap" );
180 if (ctx
->Current
.RasterPosValid
== GL_FALSE
) {
181 return; /* do nothing */
184 if (ctx
->RenderMode
==GL_RENDER
) {
186 /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
187 GLint x
= IFLOOR(ctx
->Current
.RasterPos
[0] - xorig
);
188 GLint y
= IFLOOR(ctx
->Current
.RasterPos
[1] - yorig
);
191 _mesa_update_state(ctx
);
194 ctx
->OcclusionResult
= GL_TRUE
;
195 ctx
->Driver
.Bitmap( ctx
, x
, y
, width
, height
, &ctx
->Unpack
, bitmap
);
198 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
199 if (ctx
->Current
.RasterPosValid
) {
200 FLUSH_CURRENT(ctx
, 0);
201 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_BITMAP_TOKEN
);
202 _mesa_feedback_vertex( ctx
,
203 ctx
->Current
.RasterPos
,
204 ctx
->Current
.RasterColor
,
205 ctx
->Current
.RasterIndex
,
206 ctx
->Current
.RasterTexCoord
);
209 else if (ctx
->RenderMode
==GL_SELECT
) {
210 /* Bitmaps don't generate selection hits. See appendix B of 1.1 spec. */
213 /* update raster position */
214 ctx
->Current
.RasterPos
[0] += xmove
;
215 ctx
->Current
.RasterPos
[1] += ymove
;