Debian Codegraph @

debian/external_deps/fetk/sg/src/gl/bitmap.c

raw
1 /* $Id: bitmap.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 2.0
6 * Copyright (C) 1995-1996 Brian Paul
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include "bitmap.h"
26 #include "context.h"
27 #include "feedback.h"
28 #include "image.h"
29 #include "macros.h"
30 #include "pb.h"
31 #include "types.h"
32
33
34
35
36 /*
37 * Unpack a bitmap image
38 */
39 struct gl_image *gl_unpack_bitmap( GLcontext* ctx,
40 GLsizei width, GLsizei height,
41 const GLubyte *bitmap )
42 {
43 return gl_unpack_image( ctx, width, height,
44 GL_COLOR_INDEX, GL_BITMAP, GL_BITMAP,
45 bitmap, GL_FALSE );
46 }
47
48
49
50
51 /*
52 * Do actual rendering of a bitmap.
53 */
54 void gl_render_bitmap( GLcontext* ctx,
55 GLsizei width, GLsizei height,
56 GLfloat xorig, GLfloat yorig,
57 GLfloat xmove, GLfloat ymove,
58 const struct gl_image *bitmap )
59 {
60 struct pixel_buffer *PB = ctx->PB;
61 GLint bx, by; /* bitmap position */
62 GLint px, py, pz; /* pixel position */
63 GLubyte *ptr;
64
65 if (ctx->NewState) {
66 gl_update_state(ctx);
67 PB_INIT( PB, GL_BITMAP );
68 }
69
70 if (ctx->Visual->RGBAflag) {
71 GLint r, g, b, a;
72 r = (GLint) (ctx->Current.RasterColor[0] * ctx->Visual->RedScale);
73 g = (GLint) (ctx->Current.RasterColor[1] * ctx->Visual->GreenScale);
74 b = (GLint) (ctx->Current.RasterColor[2] * ctx->Visual->BlueScale);
75 a = (GLint) (ctx->Current.RasterColor[3] * ctx->Visual->AlphaScale);
76 PB_SET_COLOR( ctx, PB, r, g, b, a );
77 }
78 else {
79 PB_SET_INDEX( ctx, PB, ctx->Current.RasterIndex );
80 }
81
82 px = (GLint) ( (ctx->Current.RasterPos[0] - xorig) + 0.0F );
83 py = (GLint) ( (ctx->Current.RasterPos[1] - yorig) + 0.0F );
84 pz = (GLint) ( ctx->Current.RasterPos[2] * DEPTH_SCALE );
85 ptr = (GLubyte *) bitmap->Data;
86
87 for (by=0;by<height;by++) {
88 GLubyte bitmask;
89
90 /* do a row */
91 bitmask = 128;
92 for (bx=0;bx<width;bx++) {
93 if (*ptr&bitmask) {
94 PB_WRITE_PIXEL( PB, px+bx, py+by, pz );
95 }
96 bitmask = bitmask >> 1;
97 if (bitmask==0) {
98 ptr++;
99 bitmask = 128;
100 }
101 }
102
103 PB_CHECK_FLUSH( ctx, PB )
104
105 /* get ready for next row */
106 if (bitmask!=128) ptr++;
107 }
108
109 gl_flush_pb(ctx);
110 }
111
112
113
114
115 /*
116 * Execute a glBitmap command:
117 * 1. check for errors
118 * 2. feedback/render/select
119 * 3. advance raster position
120 */
121 void gl_Bitmap( GLcontext* ctx,
122 GLsizei width, GLsizei height,
123 GLfloat xorig, GLfloat yorig,
124 GLfloat xmove, GLfloat ymove,
125 const struct gl_image *bitmap )
126 {
127 if (width<0 || height<0) {
128 gl_error( ctx, GL_INVALID_VALUE, "glBitmap" );
129 return;
130 }
131 if (INSIDE_BEGIN_END(ctx)) {
132 gl_error( ctx, GL_INVALID_OPERATION, "glBitmap" );
133 return;
134 }
135 if (ctx->Current.RasterPosValid==GL_FALSE) {
136 /* do nothing */
137 return;
138 }
139
140 if (ctx->RenderMode==GL_RENDER) {
141 GLboolean completed = GL_FALSE;
142 if (ctx->Driver.Bitmap) {
143 /* let device driver try to render the bitmap */
144 completed = (*ctx->Driver.Bitmap)( ctx, width, height, xorig, yorig,
145 xmove, ymove, bitmap );
146 }
147 if (!completed) {
148 /* use generic function */
149 gl_render_bitmap( ctx, width, height, xorig, yorig,
150 xmove, ymove, bitmap );
151 }
152 }
153 else if (ctx->RenderMode==GL_FEEDBACK) {
154 GLfloat color[4], texcoord[4], invq;
155 color[0] = ctx->Current.IntColor[0] * ctx->Visual->InvRedScale;
156 color[1] = ctx->Current.IntColor[1] * ctx->Visual->InvGreenScale;
157 color[2] = ctx->Current.IntColor[2] * ctx->Visual->InvBlueScale;
158 color[3] = ctx->Current.IntColor[3] * ctx->Visual->InvAlphaScale;
159 invq = 1.0F / ctx->Current.TexCoord[3];
160 texcoord[0] = ctx->Current.TexCoord[0] * invq;
161 texcoord[1] = ctx->Current.TexCoord[1] * invq;
162 texcoord[2] = ctx->Current.TexCoord[2] * invq;
163 texcoord[3] = ctx->Current.TexCoord[3];
164 FEEDBACK_TOKEN( ctx, (GLfloat) GL_BITMAP_TOKEN );
165 /* TODO: Verify XYZW values are correct: */
166 gl_feedback_vertex( ctx, ctx->Current.RasterPos[0] - xorig,
167 ctx->Current.RasterPos[1] - yorig,
168 ctx->Current.RasterPos[2],
169 ctx->Current.RasterPos[3],
170 color, ctx->Current.Index, texcoord );
171 }
172 else if (ctx->RenderMode==GL_SELECT) {
173 /* Bitmaps don't generate selection hits. See appendix B of 1.1 spec. */
174 }
175
176 /* update raster position */
177 ctx->Current.RasterPos[0] += xmove;
178 ctx->Current.RasterPos[1] += ymove;
179 }
180
181