21c74ffdf08a05ba65c324331f5b9350d94b204a
[mesa.git] / src / mesa / main / drawpix.c
1 /* $Id: drawpix.c,v 1.46 2000/11/22 07:32:16 joukj Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "colormac.h"
33 #include "context.h"
34 #include "drawpix.h"
35 #include "feedback.h"
36 #include "macros.h"
37 #include "mem.h"
38 #include "mmath.h"
39 #include "state.h"
40 #include "mtypes.h"
41 #include "swrast/swrast.h"
42 #endif
43
44
45
46
47
48 /*
49 * Execute glDrawPixels
50 */
51 void
52 _mesa_DrawPixels( GLsizei width, GLsizei height,
53 GLenum format, GLenum type, const GLvoid *pixels )
54 {
55 GET_CURRENT_CONTEXT(ctx);
56 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "_mesa_DrawPixels" );
57
58 if (ctx->RenderMode==GL_RENDER) {
59 GLint x, y;
60 if (!pixels || !ctx->Current.RasterPosValid) {
61 return;
62 }
63
64 if (ctx->NewState) {
65 gl_update_state(ctx);
66 }
67
68 x = (GLint) (ctx->Current.RasterPos[0] + 0.5F);
69 y = (GLint) (ctx->Current.RasterPos[1] + 0.5F);
70
71 ctx->OcclusionResult = GL_TRUE;
72
73 /* see if device driver can do the drawpix */
74 RENDER_START(ctx);
75
76 if (ctx->Driver.DrawPixels
77 && (*ctx->Driver.DrawPixels)(ctx, x, y, width, height, format, type,
78 &ctx->Unpack, pixels)) {
79 /* finished */
80 } else
81 _swrast_DrawPixels( ctx, x, y, width, height, format, type,
82 &ctx->Unpack, pixels );
83
84 RENDER_FINISH(ctx);
85 }
86 else if (ctx->RenderMode==GL_FEEDBACK) {
87 if (ctx->Current.RasterPosValid) {
88 GLfloat color[4];
89 GLfloat texcoord[4], invq;
90
91 FLUSH_TNL( ctx, FLUSH_UPDATE_CURRENT );
92
93 color[0] = CHAN_TO_FLOAT(ctx->Current.Color[0]);
94 color[1] = CHAN_TO_FLOAT(ctx->Current.Color[1]);
95 color[2] = CHAN_TO_FLOAT(ctx->Current.Color[2]);
96 color[3] = CHAN_TO_FLOAT(ctx->Current.Color[3]);
97 invq = 1.0F / ctx->Current.Texcoord[0][3];
98 texcoord[0] = ctx->Current.Texcoord[0][0] * invq;
99 texcoord[1] = ctx->Current.Texcoord[0][1] * invq;
100 texcoord[2] = ctx->Current.Texcoord[0][2] * invq;
101 texcoord[3] = ctx->Current.Texcoord[0][3];
102 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_DRAW_PIXEL_TOKEN );
103 gl_feedback_vertex( ctx,
104 ctx->Current.RasterPos,
105 color, ctx->Current.Index, texcoord );
106 }
107 }
108 else if (ctx->RenderMode==GL_SELECT) {
109 if (ctx->Current.RasterPosValid) {
110 gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
111 }
112 }
113 }
114