ReactOS 0.4.15-dev-7953-g1f49173
feedback.c
Go to the documentation of this file.
1/* $Id: feedback.c,v 1.12 1998/02/03 23:45:02 brianp Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 2.4
6 * Copyright (C) 1995-1997 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
24/*
25 * $Log: feedback.c,v $
26 * Revision 1.12 1998/02/03 23:45:02 brianp
27 * added casts to prevent warnings with Amiga StormC compiler
28 *
29 * Revision 1.11 1997/11/07 03:38:07 brianp
30 * added stdio.h include for SunOS 4.x
31 *
32 * Revision 1.10 1997/07/24 01:25:01 brianp
33 * changed precompiled header symbol from PCH to PC_HEADER
34 *
35 * Revision 1.9 1997/05/28 03:24:54 brianp
36 * added precompiled header (PCH) support
37 *
38 * Revision 1.8 1997/03/08 02:03:46 brianp
39 * better error checking
40 *
41 * Revision 1.7 1997/01/21 03:09:15 brianp
42 * fixed an error message in gl_RenderMode()
43 *
44 * Revision 1.6 1997/01/16 19:10:24 brianp
45 * kludged around a SunOS 5.x/GCC bug in write_hit_record()
46 *
47 * Revision 1.5 1996/12/13 21:03:19 brianp
48 * fixed feedback buffer overflow bug in write_hit_record()
49 *
50 * Revision 1.4 1996/10/22 22:58:25 brianp
51 * fixed bug in gl_update_hitflag() reported by Erich Eder
52 *
53 * Revision 1.3 1996/09/27 01:28:13 brianp
54 * added missing error check to gl_RenderMode()
55 *
56 * Revision 1.2 1996/09/15 14:17:30 brianp
57 * now use GLframebuffer and GLvisual
58 *
59 * Revision 1.1 1996/09/13 01:38:16 brianp
60 * Initial revision
61 *
62 */
63
64
65#ifdef PC_HEADER
66#include "all.h"
67#else
68#include <assert.h>
69#include <stdio.h>
70#include "context.h"
71#include "feedback.h"
72#include "dlist.h"
73#include "macros.h"
74#include "types.h"
75#endif
76
77
78
79#define FB_3D 0x01
80#define FB_4D 0x02
81#define FB_INDEX 0x04
82#define FB_COLOR 0x08
83#define FB_TEXTURE 0X10
84
85
86
87void
89{
90 if (ctx->RenderMode==GL_FEEDBACK || INSIDE_BEGIN_END(ctx)) {
91 gl_error( ctx, GL_INVALID_OPERATION, "glFeedbackBuffer" );
92 return;
93 }
94
95 if (size<0) {
96 gl_error( ctx, GL_INVALID_VALUE, "glFeedbackBuffer(size<0)" );
97 return;
98 }
99 if (!buffer) {
100 gl_error( ctx, GL_INVALID_VALUE, "glFeedbackBuffer(buffer==NULL)" );
101 ctx->Feedback.BufferSize = 0;
102 return;
103 }
104
105 switch (type) {
106 case GL_2D:
107 ctx->Feedback.Mask = 0;
108 ctx->Feedback.Type = type;
109 break;
110 case GL_3D:
111 ctx->Feedback.Mask = FB_3D;
112 ctx->Feedback.Type = type;
113 break;
114 case GL_3D_COLOR:
115 ctx->Feedback.Mask = FB_3D
116 | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX);
117 ctx->Feedback.Type = type;
118 break;
120 ctx->Feedback.Mask = FB_3D
121 | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX)
122 | FB_TEXTURE;
123 ctx->Feedback.Type = type;
124 break;
126 ctx->Feedback.Mask = FB_3D | FB_4D
127 | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX)
128 | FB_TEXTURE;
129 ctx->Feedback.Type = type;
130 break;
131 default:
132 ctx->Feedback.Mask = 0;
133 gl_error( ctx, GL_INVALID_ENUM, "glFeedbackBuffer" );
134 }
135
136 ctx->Feedback.BufferSize = size;
137 ctx->Feedback.Buffer = buffer;
138 ctx->Feedback.Count = 0;
139}
140
141
142
144{
145 if (INSIDE_BEGIN_END(ctx)) {
146 gl_error( ctx, GL_INVALID_OPERATION, "glPassThrough" );
147 return;
148 }
149
150 if (ctx->RenderMode==GL_FEEDBACK) {
153 }
154}
155
156
157
158/*
159 * Put a vertex into the feedback buffer.
160 */
163 const GLfloat color[4], GLfloat index,
164 const GLfloat texcoord[4] )
165{
166 FEEDBACK_TOKEN( ctx, x );
167 FEEDBACK_TOKEN( ctx, y );
168 if (ctx->Feedback.Mask & FB_3D) {
169 FEEDBACK_TOKEN( ctx, z );
170 }
171 if (ctx->Feedback.Mask & FB_4D) {
172 FEEDBACK_TOKEN( ctx, w );
173 }
174 if (ctx->Feedback.Mask & FB_INDEX) {
176 }
177 if (ctx->Feedback.Mask & FB_COLOR) {
178 FEEDBACK_TOKEN( ctx, color[0] );
179 FEEDBACK_TOKEN( ctx, color[1] );
180 FEEDBACK_TOKEN( ctx, color[2] );
181 FEEDBACK_TOKEN( ctx, color[3] );
182 }
183 if (ctx->Feedback.Mask & FB_TEXTURE) {
184 FEEDBACK_TOKEN( ctx, texcoord[0] );
185 FEEDBACK_TOKEN( ctx, texcoord[1] );
186 FEEDBACK_TOKEN( ctx, texcoord[2] );
187 FEEDBACK_TOKEN( ctx, texcoord[3] );
188 }
189}
190
191
192
193/**********************************************************************/
194/* Selection */
195/**********************************************************************/
196
197
198/*
199 * NOTE: this function can't be put in a display list.
200 */
202{
203 if (INSIDE_BEGIN_END(ctx)) {
204 gl_error( ctx, GL_INVALID_OPERATION, "glSelectBuffer" );
205 }
206 if (ctx->RenderMode==GL_SELECT) {
207 gl_error( ctx, GL_INVALID_OPERATION, "glSelectBuffer" );
208 }
209 ctx->Select.Buffer = buffer;
210 ctx->Select.BufferSize = size;
211 ctx->Select.BufferCount = 0;
212
213 ctx->Select.HitFlag = GL_FALSE;
214 ctx->Select.HitMinZ = 1.0;
215 ctx->Select.HitMaxZ = 0.0;
216}
217
218
220{
221 if (INSIDE_BEGIN_END(ctx)) {
222 gl_error( ctx, GL_INVALID_OPERATION, "glInitNames" );
223 }
224 ctx->Select.NameStackDepth = 0;
225 ctx->Select.HitFlag = GL_FALSE;
226 ctx->Select.HitMinZ = 1.0;
227 ctx->Select.HitMaxZ = 0.0;
228}
229
230
231
232#define WRITE_RECORD( CTX, V ) \
233 if (CTX->Select.BufferCount < CTX->Select.BufferSize) { \
234 CTX->Select.Buffer[CTX->Select.BufferCount] = (V); \
235 } \
236 CTX->Select.BufferCount++;
237
238
239
241{
242 ctx->Select.HitFlag = GL_TRUE;
243 if (z < ctx->Select.HitMinZ) {
244 ctx->Select.HitMinZ = z;
245 }
246 if (z > ctx->Select.HitMaxZ) {
247 ctx->Select.HitMaxZ = z;
248 }
249}
250
251
252
254{
255 GLuint i;
256 GLuint zmin, zmax, zscale = (~0u);
257
258 /* HitMinZ and HitMaxZ are in [0,1]. Multiply these values by */
259 /* 2^32-1 and round to nearest unsigned integer. */
260
261 assert( ctx != NULL ); /* this line magically fixes a SunOS 5.x/gcc bug */
262 zmin = (GLuint) ((GLfloat) zscale * ctx->Select.HitMinZ);
263 zmax = (GLuint) ((GLfloat) zscale * ctx->Select.HitMaxZ);
264
265 WRITE_RECORD( ctx, ctx->Select.NameStackDepth );
266 WRITE_RECORD( ctx, zmin );
268 for (i=0;i<ctx->Select.NameStackDepth;i++) {
269 WRITE_RECORD( ctx, ctx->Select.NameStack[i] );
270 }
271
272 ctx->Select.Hits++;
273 ctx->Select.HitFlag = GL_FALSE;
274 ctx->Select.HitMinZ = 1.0;
275 ctx->Select.HitMaxZ = -1.0;
276}
277
278
279
281{
282 if (INSIDE_BEGIN_END(ctx)) {
283 gl_error( ctx, GL_INVALID_OPERATION, "glLoadName" );
284 return;
285 }
286 if (ctx->RenderMode!=GL_SELECT) {
287 return;
288 }
289 if (ctx->Select.NameStackDepth==0) {
290 gl_error( ctx, GL_INVALID_OPERATION, "glLoadName" );
291 return;
292 }
293 if (ctx->Select.HitFlag) {
295 }
296 if (ctx->Select.NameStackDepth<MAX_NAME_STACK_DEPTH) {
297 ctx->Select.NameStack[ctx->Select.NameStackDepth-1] = name;
298 }
299 else {
300 ctx->Select.NameStack[MAX_NAME_STACK_DEPTH-1] = name;
301 }
302}
303
304
306{
307 if (INSIDE_BEGIN_END(ctx)) {
308 gl_error( ctx, GL_INVALID_OPERATION, "glPushName" );
309 return;
310 }
311 if (ctx->RenderMode!=GL_SELECT) {
312 return;
313 }
314 if (ctx->Select.HitFlag) {
316 }
317 if (ctx->Select.NameStackDepth<MAX_NAME_STACK_DEPTH) {
318 ctx->Select.NameStack[ctx->Select.NameStackDepth++] = name;
319 }
320 else {
321 gl_error( ctx, GL_STACK_OVERFLOW, "glPushName" );
322 }
323}
324
325
326
328{
329 if (INSIDE_BEGIN_END(ctx)) {
330 gl_error( ctx, GL_INVALID_OPERATION, "glPopName" );
331 return;
332 }
333 if (ctx->RenderMode!=GL_SELECT) {
334 return;
335 }
336 if (ctx->Select.HitFlag) {
338 }
339 if (ctx->Select.NameStackDepth>0) {
340 ctx->Select.NameStackDepth--;
341 }
342 else {
343 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopName" );
344 }
345}
346
347
348
349/**********************************************************************/
350/* Render Mode */
351/**********************************************************************/
352
353
354
355/*
356 * NOTE: this function can't be put in a display list.
357 */
359{
361
362 if (INSIDE_BEGIN_END(ctx)) {
363 gl_error( ctx, GL_INVALID_OPERATION, "glRenderMode" );
364 }
365
366 switch (ctx->RenderMode) {
367 case GL_RENDER:
368 result = 0;
369 break;
370 case GL_SELECT:
371 if (ctx->Select.HitFlag) {
373 }
374 if (ctx->Select.BufferCount > ctx->Select.BufferSize) {
375 /* overflow */
376#ifdef DEBUG
377 gl_warning(ctx, "Feedback buffer overflow");
378#endif
379 result = -1;
380 }
381 else {
382 result = ctx->Select.Hits;
383 }
384 ctx->Select.BufferCount = 0;
385 ctx->Select.Hits = 0;
386 ctx->Select.NameStackDepth = 0;
387 break;
388 case GL_FEEDBACK:
389 if (ctx->Feedback.Count > ctx->Feedback.BufferSize) {
390 /* overflow */
391 result = -1;
392 }
393 else {
394 result = ctx->Feedback.Count;
395 }
396 ctx->Feedback.Count = 0;
397 break;
398 default:
399 gl_error( ctx, GL_INVALID_ENUM, "glRenderMode" );
400 return 0;
401 }
402
403 switch (mode) {
404 case GL_RENDER:
405 break;
406 case GL_SELECT:
407 if (ctx->Select.BufferSize==0) {
408 /* haven't called glSelectBuffer yet */
409 gl_error( ctx, GL_INVALID_OPERATION, "glRenderMode" );
410 }
411 break;
412 case GL_FEEDBACK:
413 if (ctx->Feedback.BufferSize==0) {
414 /* haven't called glFeedbackBuffer yet */
415 gl_error( ctx, GL_INVALID_OPERATION, "glRenderMode" );
416 }
417 break;
418 default:
419 gl_error( ctx, GL_INVALID_ENUM, "glRenderMode" );
420 return 0;
421 }
422
423 ctx->RenderMode = mode;
424 ctx->NewState |= NEW_ALL;
425
426 return result;
427}
428
#define NULL
Definition: types.h:112
#define MAX_NAME_STACK_DEPTH
Definition: config.h:109
void gl_warning(const GLcontext *ctx, const char *s)
Definition: context.c:1406
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define NEW_ALL
Definition: types.h:1236
#define assert(x)
Definition: debug.h:53
void gl_feedback_vertex(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w, const GLfloat color[4], GLfloat index, const GLfloat texcoord[4])
Definition: feedback.c:161
#define FB_3D
Definition: feedback.c:79
#define FB_TEXTURE
Definition: feedback.c:83
#define WRITE_RECORD(CTX, V)
Definition: feedback.c:232
void gl_PopName(GLcontext *ctx)
Definition: feedback.c:327
void gl_update_hitflag(GLcontext *ctx, GLfloat z)
Definition: feedback.c:240
void gl_LoadName(GLcontext *ctx, GLuint name)
Definition: feedback.c:280
GLint gl_RenderMode(GLcontext *ctx, GLenum mode)
Definition: feedback.c:358
void gl_PushName(GLcontext *ctx, GLuint name)
Definition: feedback.c:305
void gl_PassThrough(GLcontext *ctx, GLfloat token)
Definition: feedback.c:143
static void write_hit_record(GLcontext *ctx)
Definition: feedback.c:253
#define FB_COLOR
Definition: feedback.c:82
void gl_InitNames(GLcontext *ctx)
Definition: feedback.c:219
#define FB_INDEX
Definition: feedback.c:81
#define FB_4D
Definition: feedback.c:80
void gl_FeedbackBuffer(GLcontext *ctx, GLsizei size, GLenum type, GLfloat *buffer)
Definition: feedback.c:88
void gl_SelectBuffer(GLcontext *ctx, GLsizei size, GLuint *buffer)
Definition: feedback.c:201
#define FEEDBACK_TOKEN(CTX, T)
Definition: feedback.h:39
#define GL_RENDER
Definition: gl.h:388
#define GL_TRUE
Definition: gl.h:174
#define GL_INVALID_VALUE
Definition: gl.h:695
float GLfloat
Definition: gl.h:161
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define GL_2D
Definition: gl.h:392
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_3D_COLOR_TEXTURE
Definition: gl.h:395
#define GL_SELECT
Definition: gl.h:389
unsigned int GLenum
Definition: gl.h:150
#define GL_FEEDBACK
Definition: gl.h:387
#define GL_STACK_OVERFLOW
Definition: gl.h:697
unsigned int GLuint
Definition: gl.h:159
#define GL_3D
Definition: gl.h:393
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define GL_4D_COLOR_TEXTURE
Definition: gl.h:396
#define GL_3D_COLOR
Definition: gl.h:394
#define GL_FALSE
Definition: gl.h:173
int GLsizei
Definition: gl.h:160
int GLint
Definition: gl.h:156
#define GL_INVALID_ENUM
Definition: gl.h:694
#define GL_STACK_UNDERFLOW
Definition: gl.h:698
#define GL_PASS_THROUGH_TOKEN
Definition: gl.h:404
GLsizeiptr size
Definition: glext.h:5919
GLuint buffer
Definition: glext.h:5915
GLuint color
Definition: glext.h:6243
GLclampd zmax
Definition: glext.h:10123
GLuint index
Definition: glext.h:6031
GLenum mode
Definition: glext.h:6217
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLuint64EXT * result
Definition: glext.h:11304
GLdouble GLdouble z
Definition: glext.h:5874
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
Definition: name.c:39