VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_rasterpos.c@ 50311

最後變更 在這個檔案從50311是 15532,由 vboxsync 提交於 16 年 前

crOpenGL: export to OSE

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 8.0 KB
 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include <stdio.h>
8#include "state.h"
9#include "state/cr_statetypes.h"
10#include "state_internals.h"
11
12
13/*
14 * Apply modelview, projection, viewport transformations to (x,y,z,w)
15 * and update the current raster position attributes.
16 * Do NOT set dirty state.
17 */
18void
19crStateRasterPosUpdate(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
20{
21 CRContext *g = GetCurrentContext();
22 CRCurrentState *c = &(g->current);
23 CRTransformState *t = &(g->transform);
24 CRViewportState *v = &(g->viewport);
25 GLvectorf p;
26 int i;
27
28 if (g->current.inBeginEnd)
29 {
30 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "RasterPos called in Begin/End");
31 return;
32 }
33
34 FLUSH();
35
36 /* update current color, texcoord, etc from the CurrentStatePointers */
37 crStateCurrentRecover();
38
39 p.x = x;
40 p.y = y;
41 p.z = z;
42 p.w = w;
43
44 /* Apply modelview and projection matrix */
45 crStateTransformXformPoint(t, &p);
46
47 /* clip test */
48 if (p.x > p.w || p.y > p.w || p.z > p.w ||
49 p.x < -p.w || p.y < -p.w || p.z < -p.w)
50 {
51 c->rasterValid = GL_FALSE;
52 return;
53 }
54
55 /* divide by W (perspective projection) */
56 p.x /= p.w;
57 p.y /= p.w;
58 p.z /= p.w;
59 p.w = 1.0f;
60
61 /* map from NDC to window coords */
62 crStateViewportApply(v, &p);
63
64 c->rasterValid = GL_TRUE;
65 ASSIGN_4V(c->rasterAttrib[VERT_ATTRIB_POS], p.x, p.y, p.z, p.w);
66 ASSIGN_4V(c->rasterAttribPre[VERT_ATTRIB_POS], p.x, p.y, p.z, p.w);
67 for (i = 1; i < CR_MAX_VERTEX_ATTRIBS; i++) {
68 COPY_4V(c->rasterAttrib[i] , c->vertexAttrib[i]);
69 }
70
71 /* XXX need to update raster distance... */
72 /* from Mesa... */
73#ifdef CR_EXT_fog_coord
74 if (g->fog.fogCoordinateSource == GL_FOG_COORDINATE_EXT)
75 c->rasterAttrib[VERT_ATTRIB_FOG][0] = c->vertexAttrib[VERT_ATTRIB_FOG][0];
76 else
77#endif
78 c->rasterAttrib[VERT_ATTRIB_FOG][0] = 0.0; /*(GLfloat)
79 sqrt( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );*/
80}
81
82
83/* As above, but set dirty flags */
84static void RasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
85{
86 CRContext *g = GetCurrentContext();
87 CRStateBits *sb = GetCurrentBits();
88 CRCurrentBits *cb = &(sb->current);
89
90 crStateRasterPosUpdate(x, y, z, w);
91
92 DIRTY(cb->dirty, g->neg_bitid);
93 DIRTY(cb->rasterPos, g->neg_bitid);
94}
95
96void STATE_APIENTRY crStateRasterPos2d(GLdouble x, GLdouble y)
97{
98 RasterPos4f((GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
99}
100
101void STATE_APIENTRY crStateRasterPos2f(GLfloat x, GLfloat y)
102{
103 RasterPos4f(x, y, 0.0f, 1.0f);
104}
105
106void STATE_APIENTRY crStateRasterPos2i(GLint x, GLint y)
107{
108 RasterPos4f((GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
109}
110
111void STATE_APIENTRY crStateRasterPos2s(GLshort x, GLshort y)
112{
113 RasterPos4f((GLfloat) x, (GLfloat) y, 0.0f, 1.0f);
114}
115
116void STATE_APIENTRY crStateRasterPos3d(GLdouble x, GLdouble y, GLdouble z)
117{
118 RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
119}
120
121void STATE_APIENTRY crStateRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
122{
123 RasterPos4f(x, y, z, 1.0f);
124}
125
126void STATE_APIENTRY crStateRasterPos3i(GLint x, GLint y, GLint z)
127{
128 RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
129}
130
131void STATE_APIENTRY crStateRasterPos3s(GLshort x, GLshort y, GLshort z)
132{
133 RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, 1.0f);
134}
135
136void STATE_APIENTRY crStateRasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
137{
138 RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
139}
140
141void STATE_APIENTRY crStateRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
142{
143 RasterPos4f(x, y, z, w);
144}
145
146void STATE_APIENTRY crStateRasterPos4i(GLint x, GLint y, GLint z, GLint w)
147{
148 RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
149}
150
151void STATE_APIENTRY crStateRasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w)
152{
153 RasterPos4f((GLfloat) x, (GLfloat) y, (GLfloat) z, (GLfloat) w);
154}
155
156void STATE_APIENTRY crStateRasterPos2dv(const GLdouble *v)
157{
158 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
159}
160
161void STATE_APIENTRY crStateRasterPos2fv(const GLfloat *v)
162{
163 RasterPos4f(v[0], v[1], 0.0f, 1.0f);
164}
165
166void STATE_APIENTRY crStateRasterPos2iv(const GLint *v)
167{
168 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
169}
170
171void STATE_APIENTRY crStateRasterPos2sv(const GLshort *v)
172{
173 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], 0.0f, 1.0f);
174}
175
176void STATE_APIENTRY crStateRasterPos3dv(const GLdouble *v)
177{
178 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
179}
180
181void STATE_APIENTRY crStateRasterPos3fv(const GLfloat *v)
182{
183 RasterPos4f(v[0], v[1], v[2], 1.0f);
184}
185
186void STATE_APIENTRY crStateRasterPos3iv(const GLint *v)
187{
188 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
189}
190
191void STATE_APIENTRY crStateRasterPos3sv(const GLshort *v)
192{
193 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], 1.0f);
194}
195
196void STATE_APIENTRY crStateRasterPos4dv(const GLdouble *v)
197{
198 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
199}
200
201void STATE_APIENTRY crStateRasterPos4fv(const GLfloat *v)
202{
203 RasterPos4f(v[0], v[1], v[2], v[3]);
204}
205
206void STATE_APIENTRY crStateRasterPos4iv(const GLint *v)
207{
208 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
209}
210
211void STATE_APIENTRY crStateRasterPos4sv(const GLshort *v)
212{
213 RasterPos4f((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2], (GLfloat) v[3]);
214}
215
216
217/**********************************************************************/
218
219
220static void
221crStateWindowPosUpdate(GLfloat x, GLfloat y, GLfloat z)
222{
223 CRContext *g = GetCurrentContext();
224 CRCurrentState *c = &(g->current);
225 CRStateBits *sb = GetCurrentBits();
226 CRCurrentBits *cb = &(sb->current);
227 int i;
228
229 if (g->current.inBeginEnd)
230 {
231 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "WindowPos called in Begin/End");
232 return;
233 }
234
235 FLUSH();
236 DIRTY(cb->dirty, g->neg_bitid);
237 DIRTY(cb->rasterPos, g->neg_bitid);
238
239 c->rasterValid = GL_TRUE;
240 ASSIGN_4V(c->rasterAttrib[VERT_ATTRIB_POS], x, y , z, 1.0);
241 ASSIGN_4V(c->rasterAttribPre[VERT_ATTRIB_POS], x, y, z, 1.0);
242 for (i = 1; i < CR_MAX_VERTEX_ATTRIBS; i++) {
243 COPY_4V(c->rasterAttrib[i] , c->vertexAttrib[i]);
244 }
245}
246
247
248void STATE_APIENTRY crStateWindowPos2dARB (GLdouble x, GLdouble y)
249{
250 crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, 0.0);
251}
252
253void STATE_APIENTRY crStateWindowPos2dvARB (const GLdouble *v)
254{
255 crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], 0.0);
256}
257
258void STATE_APIENTRY crStateWindowPos2fARB (GLfloat x, GLfloat y)
259{
260 crStateWindowPosUpdate(x, y, 0.0);
261}
262
263void STATE_APIENTRY crStateWindowPos2fvARB (const GLfloat *v)
264{
265 crStateWindowPosUpdate(v[0], v[1], 0.0);
266}
267
268void STATE_APIENTRY crStateWindowPos2iARB (GLint x, GLint y)
269{
270 crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, 0.0);
271}
272
273void STATE_APIENTRY crStateWindowPos2ivARB (const GLint *v)
274{
275 crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], 0.0);
276}
277
278void STATE_APIENTRY crStateWindowPos2sARB (GLshort x, GLshort y)
279{
280 crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, 0.0);
281}
282
283void STATE_APIENTRY crStateWindowPos2svARB (const GLshort *v)
284{
285 crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], 0.0);
286}
287
288void STATE_APIENTRY crStateWindowPos3dARB (GLdouble x, GLdouble y, GLdouble z)
289{
290 crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, (GLfloat) z);
291}
292
293void STATE_APIENTRY crStateWindowPos3dvARB (const GLdouble *v)
294{
295 crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
296}
297
298void STATE_APIENTRY crStateWindowPos3fARB (GLfloat x, GLfloat y, GLfloat z)
299{
300 crStateWindowPosUpdate(x, y, z);
301}
302
303void STATE_APIENTRY crStateWindowPos3fvARB (const GLfloat *v)
304{
305 crStateWindowPosUpdate(v[0], v[1], v[2]);
306}
307
308void STATE_APIENTRY crStateWindowPos3iARB (GLint x, GLint y, GLint z)
309{
310 crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, (GLfloat) z);
311}
312
313void STATE_APIENTRY crStateWindowPos3ivARB (const GLint *v)
314{
315 crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
316}
317
318void STATE_APIENTRY crStateWindowPos3sARB (GLshort x, GLshort y, GLshort z)
319{
320 crStateWindowPosUpdate((GLfloat) x, (GLfloat) y, (GLfloat) z);
321}
322
323void STATE_APIENTRY crStateWindowPos3svARB (const GLshort *v)
324{
325 crStateWindowPosUpdate((GLfloat) v[0], (GLfloat) v[1], (GLfloat) v[2]);
326}
327
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette