7d29257c4979b5eb477fc7a3eaf1d102e773d592
1 /* $Id: drawpix.c,v 1.55 2001/06/26 01:32:48 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.
48 * Execute glDrawPixels
51 _mesa_DrawPixels( GLsizei width
, GLsizei height
,
52 GLenum format
, GLenum type
, const GLvoid
*pixels
)
54 GET_CURRENT_CONTEXT(ctx
);
55 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
57 if (ctx
->RenderMode
==GL_RENDER
) {
59 if (!pixels
|| !ctx
->Current
.RasterPosValid
) {
64 _mesa_update_state(ctx
);
68 x
= IROUND(ctx
->Current
.RasterPos
[0]);
69 y
= IROUND(ctx
->Current
.RasterPos
[1]);
71 x
= IFLOOR(ctx
->Current
.RasterPos
[0]);
72 y
= IFLOOR(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 if (ctx
->Current
.RasterPosValid
) {
80 GLfloat texcoord
[4], invq
;
82 FLUSH_CURRENT(ctx
, 0);
83 invq
= 1.0F
/ ctx
->Current
.Texcoord
[0][3];
84 texcoord
[0] = ctx
->Current
.Texcoord
[0][0] * invq
;
85 texcoord
[1] = ctx
->Current
.Texcoord
[0][1] * invq
;
86 texcoord
[2] = ctx
->Current
.Texcoord
[0][2] * invq
;
87 texcoord
[3] = ctx
->Current
.Texcoord
[0][3];
88 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_DRAW_PIXEL_TOKEN
);
89 _mesa_feedback_vertex( ctx
,
90 ctx
->Current
.RasterPos
,
96 else if (ctx
->RenderMode
==GL_SELECT
) {
97 if (ctx
->Current
.RasterPosValid
) {
98 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
106 _mesa_ReadPixels( GLint x
, GLint y
, GLsizei width
, GLsizei height
,
107 GLenum format
, GLenum type
, GLvoid
*pixels
)
109 GET_CURRENT_CONTEXT(ctx
);
110 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
113 _mesa_error( ctx
, GL_INVALID_VALUE
, "glReadPixels(pixels)" );
118 _mesa_update_state(ctx
);
120 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
121 format
, type
, &ctx
->Pack
, pixels
);
128 _mesa_CopyPixels( GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
131 GET_CURRENT_CONTEXT(ctx
);
133 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
135 if (width
< 0 || height
< 0) {
136 _mesa_error( ctx
, GL_INVALID_VALUE
, "glCopyPixels" );
141 _mesa_update_state(ctx
);
144 if (ctx
->RenderMode
==GL_RENDER
) {
145 /* Destination of copy: */
146 if (!ctx
->Current
.RasterPosValid
) {
150 destx
= IROUND(ctx
->Current
.RasterPos
[0]);
151 desty
= IROUND(ctx
->Current
.RasterPos
[1]);
153 destx
= IFLOOR(ctx
->Current
.RasterPos
[0]);
154 desty
= IFLOOR(ctx
->Current
.RasterPos
[1]);
156 ctx
->OcclusionResult
= GL_TRUE
;
158 ctx
->Driver
.CopyPixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
,
161 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
162 FLUSH_CURRENT( ctx
, 0 );
163 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_COPY_PIXEL_TOKEN
);
164 _mesa_feedback_vertex( ctx
,
165 ctx
->Current
.RasterPos
,
168 ctx
->Current
.Texcoord
[0] );
170 else if (ctx
->RenderMode
== GL_SELECT
) {
171 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
178 _mesa_Bitmap( GLsizei width
, GLsizei height
,
179 GLfloat xorig
, GLfloat yorig
, GLfloat xmove
, GLfloat ymove
,
180 const GLubyte
*bitmap
)
182 GET_CURRENT_CONTEXT(ctx
);
183 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
187 if (width
< 0 || height
< 0) {
188 _mesa_error( ctx
, GL_INVALID_VALUE
, "glBitmap" );
192 if (ctx
->Current
.RasterPosValid
== GL_FALSE
) {
193 return; /* do nothing */
196 if (ctx
->RenderMode
==GL_RENDER
) {
199 GLint x
= (GLint
) ( (ctx
->Current
.RasterPos
[0] - xorig
) + 0.0F
);
200 GLint y
= (GLint
) ( (ctx
->Current
.RasterPos
[1] - yorig
) + 0.0F
);
202 GLint x
= IFLOOR(ctx
->Current
.RasterPos
[0] - xorig
);
203 GLint y
= IFLOOR(ctx
->Current
.RasterPos
[1] - yorig
);
206 _mesa_update_state(ctx
);
209 ctx
->OcclusionResult
= GL_TRUE
;
210 ctx
->Driver
.Bitmap( ctx
, x
, y
, width
, height
, &ctx
->Unpack
, bitmap
);
213 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
214 GLfloat color
[4], texcoord
[4], invq
;
216 color
[0] = ctx
->Current
.RasterColor
[0];
217 color
[1] = ctx
->Current
.RasterColor
[1];
218 color
[2] = ctx
->Current
.RasterColor
[2];
219 color
[3] = ctx
->Current
.RasterColor
[3];
220 if (ctx
->Current
.Texcoord
[0][3] == 0.0)
223 invq
= 1.0F
/ ctx
->Current
.RasterTexCoord
[3];
224 texcoord
[0] = ctx
->Current
.RasterTexCoord
[0] * invq
;
225 texcoord
[1] = ctx
->Current
.RasterTexCoord
[1] * invq
;
226 texcoord
[2] = ctx
->Current
.RasterTexCoord
[2] * invq
;
227 texcoord
[3] = ctx
->Current
.RasterTexCoord
[3];
228 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_BITMAP_TOKEN
);
229 _mesa_feedback_vertex( ctx
,
230 ctx
->Current
.RasterPos
,
231 color
, ctx
->Current
.RasterIndex
, texcoord
);
233 else if (ctx
->RenderMode
==GL_SELECT
) {
234 /* Bitmaps don't generate selection hits. See appendix B of 1.1 spec. */
237 /* update raster position */
238 ctx
->Current
.RasterPos
[0] += xmove
;
239 ctx
->Current
.RasterPos
[1] += ymove
;