Changeset 3598 for trunk/src/opengl/mesa/feedback.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/feedback.c
r2962 r3598 1 /* $Id: feedback.c,v 1. 2 2000-03-01 18:49:28jeroen Exp $ */1 /* $Id: feedback.c,v 1.3 2000-05-23 20:40:33 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 32 32 #include "all.h" 33 33 #else 34 #ifndef XFree86Server 35 #include <assert.h> 36 #include <stdio.h> 37 #else 38 #include "GL/xf86glx.h" 39 #endif 34 #include "glheader.h" 40 35 #include "types.h" 41 36 #include "context.h" … … 58 53 59 54 void 60 gl_FeedbackBuffer( GLcontext *ctx, GLsizei size, GLenum type, GLfloat *buffer ) 61 { 55 _mesa_FeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer ) 56 { 57 GET_CURRENT_CONTEXT(ctx); 62 58 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "glFeedbackBuffer" ); 63 59 … … 79 75 switch (type) { 80 76 case GL_2D: 81 77 ctx->Feedback.Mask = 0; 82 78 ctx->Feedback.Type = type; 83 79 break; 84 80 case GL_3D: 85 81 ctx->Feedback.Mask = FB_3D; 86 82 ctx->Feedback.Type = type; 87 83 break; 88 84 case GL_3D_COLOR: 89 85 ctx->Feedback.Mask = FB_3D 90 86 | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX); 91 87 ctx->Feedback.Type = type; 92 88 break; 93 89 case GL_3D_COLOR_TEXTURE: 94 90 ctx->Feedback.Mask = FB_3D 95 91 | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX) 96 92 | FB_TEXTURE; 97 93 ctx->Feedback.Type = type; 98 94 break; 99 95 case GL_4D_COLOR_TEXTURE: 100 96 ctx->Feedback.Mask = FB_3D | FB_4D 101 97 | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX) 102 98 | FB_TEXTURE; 103 99 ctx->Feedback.Type = type; 104 100 break; 105 101 default: 106 102 ctx->Feedback.Mask = 0; 107 103 gl_error( ctx, GL_INVALID_ENUM, "glFeedbackBuffer" ); 108 104 } … … 115 111 116 112 117 void gl_PassThrough( GLcontext *ctx, GLfloat token ) 118 { 113 void 114 _mesa_PassThrough( GLfloat token ) 115 { 116 GET_CURRENT_CONTEXT(ctx); 119 117 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPassThrough"); 120 118 … … 132 130 void gl_feedback_vertex( GLcontext *ctx, 133 131 const GLfloat win[4], 134 135 136 132 const GLfloat color[4], 133 GLuint index, 134 const GLfloat texcoord[4] ) 137 135 { 138 136 FEEDBACK_TOKEN( ctx, win[0] ); … … 163 161 164 162 165 static void gl_do_feedback_vertex( GLcontext *ctx, GLuint v, GLuint pv )163 static void feedback_vertex( GLcontext *ctx, GLuint v, GLuint pv ) 166 164 { 167 165 GLfloat win[4]; … … 169 167 GLfloat tc[4]; 170 168 GLuint texUnit = ctx->Texture.CurrentTransformUnit; 171 struct vertex_buffer *VB = ctx->VB; 169 const struct vertex_buffer *VB = ctx->VB; 170 GLuint index; 172 171 173 172 win[0] = VB->Win.data[v][0]; 174 173 win[1] = VB->Win.data[v][1]; 175 win[2] = VB->Win.data[v][2] / DEPTH_SCALE;174 win[2] = VB->Win.data[v][2] / ctx->Visual->DepthMaxF; 176 175 win[3] = 1.0 / VB->Win.data[v][3]; 177 176 178 if (ctx->Light.ShadeModel==GL_SMOOTH) pv = v; 177 if (ctx->Light.ShadeModel == GL_SMOOTH) 178 pv = v; 179 179 180 180 UBYTE_RGBA_TO_FLOAT_RGBA( color, VB->ColorPtr->data[pv] ); 181 181 182 182 if (VB->TexCoordPtr[texUnit]->size == 4 && 183 VB->TexCoordPtr[texUnit]->data[v][3]!=0.0) 184 { 183 VB->TexCoordPtr[texUnit]->data[v][3] != 0.0) { 185 184 GLfloat invq = 1.0F / VB->TexCoordPtr[texUnit]->data[v][3]; 186 185 tc[0] = VB->TexCoordPtr[texUnit]->data[v][0] * invq; … … 188 187 tc[2] = VB->TexCoordPtr[texUnit]->data[v][2] * invq; 189 188 tc[3] = VB->TexCoordPtr[texUnit]->data[v][3]; 190 } else { 189 } 190 else { 191 191 ASSIGN_4V(tc, 0,0,0,1); 192 192 COPY_SZ_4V(tc, 193 VB->TexCoordPtr[texUnit]->size, 194 VB->TexCoordPtr[texUnit]->data[v]); 195 } 196 197 gl_feedback_vertex( ctx, win, color, VB->IndexPtr->data[v], tc ); 193 VB->TexCoordPtr[texUnit]->size, 194 VB->TexCoordPtr[texUnit]->data[v]); 195 } 196 197 if (VB->IndexPtr) 198 index = VB->IndexPtr->data[v]; 199 else 200 index = 0; 201 202 gl_feedback_vertex( ctx, win, color, index, tc ); 198 203 } 199 204 … … 204 209 */ 205 210 void gl_feedback_triangle( GLcontext *ctx, 206 211 GLuint v0, GLuint v1, GLuint v2, GLuint pv ) 207 212 { 208 213 if (gl_cull_triangle( ctx, v0, v1, v2, 0 )) { 209 214 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POLYGON_TOKEN ); 210 FEEDBACK_TOKEN( ctx, (GLfloat) 3 ); /* three vertices*/211 212 gl_do_feedback_vertex( ctx, v0, pv );213 gl_do_feedback_vertex( ctx, v1, pv );214 gl_do_feedback_vertex( ctx, v2, pv );215 FEEDBACK_TOKEN( ctx, (GLfloat) 3 ); /* three vertices*/ 216 217 feedback_vertex( ctx, v0, pv ); 218 feedback_vertex( ctx, v1, pv ); 219 feedback_vertex( ctx, v2, pv ); 215 220 } 216 221 } … … 226 231 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) token ); 227 232 228 gl_do_feedback_vertex( ctx, v1, pv );229 gl_do_feedback_vertex( ctx, v2, pv );233 feedback_vertex( ctx, v1, pv ); 234 feedback_vertex( ctx, v2, pv ); 230 235 231 236 ctx->StippleCounter++; … … 235 240 void gl_feedback_points( GLcontext *ctx, GLuint first, GLuint last ) 236 241 { 237 struct vertex_buffer *VB = ctx->VB;242 const struct vertex_buffer *VB = ctx->VB; 238 243 GLuint i; 239 244 240 for (i=first;i<=last;i++) 245 for (i=first;i<=last;i++) { 241 246 if (VB->ClipMask[i]==0) { 242 247 FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POINT_TOKEN ); 243 gl_do_feedback_vertex( ctx, i, i );248 feedback_vertex( ctx, i, i ); 244 249 } 250 } 245 251 } 246 252 … … 257 263 * NOTE: this function can't be put in a display list. 258 264 */ 259 void gl_SelectBuffer( GLcontext *ctx, GLsizei size, GLuint *buffer ) 260 { 265 void 266 _mesa_SelectBuffer( GLsizei size, GLuint *buffer ) 267 { 268 GET_CURRENT_CONTEXT(ctx); 261 269 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glSelectBuffer"); 262 270 if (ctx->RenderMode==GL_SELECT) { … … 273 281 274 282 275 #define WRITE_RECORD( CTX, V ) 276 if (CTX->Select.BufferCount < CTX->Select.BufferSize) {\277 CTX->Select.Buffer[CTX->Select.BufferCount] = (V);\278 }\279 283 #define WRITE_RECORD( CTX, V ) \ 284 if (CTX->Select.BufferCount < CTX->Select.BufferSize) { \ 285 CTX->Select.Buffer[CTX->Select.BufferCount] = (V); \ 286 } \ 287 CTX->Select.BufferCount++; 280 288 281 289 … … 293 301 294 302 void gl_select_triangle( GLcontext *ctx, 295 GLuint v0, GLuint v1, GLuint v2, GLuint pv ) 303 GLuint v0, GLuint v1, GLuint v2, GLuint pv ) 304 { 305 const struct vertex_buffer *VB = ctx->VB; 306 307 if (gl_cull_triangle( ctx, v0, v1, v2, 0 )) { 308 const GLfloat zs = 1.0F / ctx->Visual->DepthMaxF; 309 gl_update_hitflag( ctx, VB->Win.data[v0][2] * zs ); 310 gl_update_hitflag( ctx, VB->Win.data[v1][2] * zs ); 311 gl_update_hitflag( ctx, VB->Win.data[v2][2] * zs ); 312 } 313 } 314 315 316 void gl_select_line( GLcontext *ctx, 317 GLuint v0, GLuint v1, GLuint pv ) 318 { 319 const struct vertex_buffer *VB = ctx->VB; 320 const GLfloat zs = 1.0F / ctx->Visual->DepthMaxF; 321 gl_update_hitflag( ctx, VB->Win.data[v0][2] * zs ); 322 gl_update_hitflag( ctx, VB->Win.data[v1][2] * zs ); 323 } 324 325 326 void gl_select_points( GLcontext *ctx, GLuint first, GLuint last ) 296 327 { 297 328 struct vertex_buffer *VB = ctx->VB; 298 299 if (gl_cull_triangle( ctx, v0, v1, v2, 0 )) { 300 gl_update_hitflag( ctx, VB->Win.data[v0][3] / DEPTH_SCALE ); 301 gl_update_hitflag( ctx, VB->Win.data[v1][3] / DEPTH_SCALE ); 302 gl_update_hitflag( ctx, VB->Win.data[v2][3] / DEPTH_SCALE ); 303 } 304 } 305 306 307 void gl_select_line( GLcontext *ctx, 308 GLuint v0, GLuint v1, GLuint pv ) 309 { 310 struct vertex_buffer *VB = ctx->VB; 311 312 gl_update_hitflag( ctx, VB->Win.data[v0][3] / DEPTH_SCALE ); 313 gl_update_hitflag( ctx, VB->Win.data[v1][3] / DEPTH_SCALE ); 314 } 315 316 void gl_select_points( GLcontext *ctx, GLuint first, GLuint last ) 317 { 318 struct vertex_buffer *VB = ctx->VB; 329 const GLfloat zs = 1.0F / ctx->Visual->DepthMaxF; 319 330 GLuint i; 320 331 321 for (i=first;i<=last;i++) 322 if (VB->ClipMask[i]==0) 323 gl_update_hitflag( ctx, VB->Win.data[i][3] / DEPTH_SCALE); 332 for (i=first;i<=last;i++) { 333 if (VB->ClipMask[i]==0) { 334 gl_update_hitflag( ctx, VB->Win.data[i][2] * zs ); 335 } 336 } 324 337 } 325 338 … … 333 346 /* 2^32-1 and round to nearest unsigned integer. */ 334 347 335 assert( ctx != NULL ); /* this line magically fixes a SunOS 5.x/gcc bug */348 ASSERT( ctx != NULL ); /* this line magically fixes a SunOS 5.x/gcc bug */ 336 349 zmin = (GLuint) ((GLfloat) zscale * ctx->Select.HitMinZ); 337 350 zmax = (GLuint) ((GLfloat) zscale * ctx->Select.HitMaxZ); … … 340 353 WRITE_RECORD( ctx, zmin ); 341 354 WRITE_RECORD( ctx, zmax ); 342 for (i =0;i<ctx->Select.NameStackDepth;i++) {355 for (i = 0; i < ctx->Select.NameStackDepth; i++) { 343 356 WRITE_RECORD( ctx, ctx->Select.NameStack[i] ); 344 357 } … … 352 365 353 366 354 void gl_InitNames( GLcontext *ctx ) 355 { 367 void 368 _mesa_InitNames( void ) 369 { 370 GET_CURRENT_CONTEXT(ctx); 356 371 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glInitNames"); 357 372 /* Record the hit before the HitFlag is wiped out again. */ 358 if (ctx->RenderMode ==GL_SELECT) {373 if (ctx->RenderMode == GL_SELECT) { 359 374 if (ctx->Select.HitFlag) { 360 375 write_hit_record( ctx ); … … 369 384 370 385 371 void gl_LoadName( GLcontext *ctx, GLuint name ) 372 { 386 void 387 _mesa_LoadName( GLuint name ) 388 { 389 GET_CURRENT_CONTEXT(ctx); 373 390 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLoadName"); 374 if (ctx->RenderMode !=GL_SELECT) {375 return; 376 } 377 if (ctx->Select.NameStackDepth ==0) {391 if (ctx->RenderMode != GL_SELECT) { 392 return; 393 } 394 if (ctx->Select.NameStackDepth == 0) { 378 395 gl_error( ctx, GL_INVALID_OPERATION, "glLoadName" ); 379 396 return; … … 382 399 write_hit_record( ctx ); 383 400 } 384 if (ctx->Select.NameStackDepth <MAX_NAME_STACK_DEPTH) {401 if (ctx->Select.NameStackDepth < MAX_NAME_STACK_DEPTH) { 385 402 ctx->Select.NameStack[ctx->Select.NameStackDepth-1] = name; 386 403 } … … 391 408 392 409 393 void gl_PushName( GLcontext *ctx, GLuint name ) 394 { 410 void 411 _mesa_PushName( GLuint name ) 412 { 413 GET_CURRENT_CONTEXT(ctx); 395 414 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushName"); 396 if (ctx->RenderMode !=GL_SELECT) {415 if (ctx->RenderMode != GL_SELECT) { 397 416 return; 398 417 } … … 400 419 write_hit_record( ctx ); 401 420 } 402 if (ctx->Select.NameStackDepth <MAX_NAME_STACK_DEPTH) {421 if (ctx->Select.NameStackDepth < MAX_NAME_STACK_DEPTH) { 403 422 ctx->Select.NameStack[ctx->Select.NameStackDepth++] = name; 404 423 } … … 410 429 411 430 412 void gl_PopName( GLcontext *ctx ) 413 { 431 void 432 _mesa_PopName( void ) 433 { 434 GET_CURRENT_CONTEXT(ctx); 414 435 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopName"); 415 if (ctx->RenderMode !=GL_SELECT) {436 if (ctx->RenderMode != GL_SELECT) { 416 437 return; 417 438 } … … 419 440 write_hit_record( ctx ); 420 441 } 421 if (ctx->Select.NameStackDepth >0) {442 if (ctx->Select.NameStackDepth > 0) { 422 443 ctx->Select.NameStackDepth--; 423 444 } … … 438 459 * NOTE: this function can't be put in a display list. 439 460 */ 440 GLint gl_RenderMode( GLcontext *ctx, GLenum mode ) 441 { 461 GLint 462 _mesa_RenderMode( GLenum mode ) 463 { 464 GET_CURRENT_CONTEXT(ctx); 442 465 GLint result; 443 466 … … 451 474 switch (ctx->RenderMode) { 452 475 case GL_RENDER: 453 454 476 result = 0; 477 break; 455 478 case GL_SELECT: 456 457 458 459 460 479 if (ctx->Select.HitFlag) { 480 write_hit_record( ctx ); 481 } 482 if (ctx->Select.BufferCount > ctx->Select.BufferSize) { 483 /* overflow */ 461 484 #ifdef DEBUG 462 485 gl_warning(ctx, "Feedback buffer overflow"); 463 486 #endif 464 465 466 467 468 469 470 471 472 487 result = -1; 488 } 489 else { 490 result = ctx->Select.Hits; 491 } 492 ctx->Select.BufferCount = 0; 493 ctx->Select.Hits = 0; 494 ctx->Select.NameStackDepth = 0; 495 break; 473 496 case GL_FEEDBACK: 474 475 476 477 478 479 480 481 482 497 if (ctx->Feedback.Count > ctx->Feedback.BufferSize) { 498 /* overflow */ 499 result = -1; 500 } 501 else { 502 result = ctx->Feedback.Count; 503 } 504 ctx->Feedback.Count = 0; 505 break; 483 506 default: 484 485 507 gl_error( ctx, GL_INVALID_ENUM, "glRenderMode" ); 508 return 0; 486 509 } 487 510 … … 490 513 break; 491 514 case GL_SELECT: 492 493 494 495 496 497 515 ctx->TriangleCaps |= DD_SELECT; 516 if (ctx->Select.BufferSize==0) { 517 /* haven't called glSelectBuffer yet */ 518 gl_error( ctx, GL_INVALID_OPERATION, "glRenderMode" ); 519 } 520 break; 498 521 case GL_FEEDBACK: 499 500 501 502 503 504 522 ctx->TriangleCaps |= DD_FEEDBACK; 523 if (ctx->Feedback.BufferSize==0) { 524 /* haven't called glFeedbackBuffer yet */ 525 gl_error( ctx, GL_INVALID_OPERATION, "glRenderMode" ); 526 } 527 break; 505 528 default: 506 gl_error( ctx, GL_INVALID_ENUM, "glRenderMode" ); 507 return 0; 508 } 509 529 gl_error( ctx, GL_INVALID_ENUM, "glRenderMode" ); 530 return 0; 531 } 510 532 511 533 ctx->RenderMode = mode;
Note:
See TracChangeset
for help on using the changeset viewer.