Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

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:28 jeroen Exp $ */
     1/* $Id: feedback.c,v 1.3 2000-05-23 20:40:33 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    3232#include "all.h"
    3333#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"
    4035#include "types.h"
    4136#include "context.h"
     
    5853
    5954void
    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);
    6258   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "glFeedbackBuffer" );
    6359
     
    7975   switch (type) {
    8076      case GL_2D:
    81         ctx->Feedback.Mask = 0;
     77        ctx->Feedback.Mask = 0;
    8278         ctx->Feedback.Type = type;
    83         break;
     79        break;
    8480      case GL_3D:
    85         ctx->Feedback.Mask = FB_3D;
     81        ctx->Feedback.Mask = FB_3D;
    8682         ctx->Feedback.Type = type;
    87         break;
     83        break;
    8884      case GL_3D_COLOR:
    89         ctx->Feedback.Mask = FB_3D
     85        ctx->Feedback.Mask = FB_3D
    9086                           | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX);
    9187         ctx->Feedback.Type = type;
    92         break;
     88        break;
    9389      case GL_3D_COLOR_TEXTURE:
    94         ctx->Feedback.Mask = FB_3D
     90        ctx->Feedback.Mask = FB_3D
    9591                           | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX)
    96                            | FB_TEXTURE;
     92                           | FB_TEXTURE;
    9793         ctx->Feedback.Type = type;
    98         break;
     94        break;
    9995      case GL_4D_COLOR_TEXTURE:
    100         ctx->Feedback.Mask = FB_3D | FB_4D
     96        ctx->Feedback.Mask = FB_3D | FB_4D
    10197                           | (ctx->Visual->RGBAflag ? FB_COLOR : FB_INDEX)
    102                            | FB_TEXTURE;
     98                           | FB_TEXTURE;
    10399         ctx->Feedback.Type = type;
    104         break;
     100        break;
    105101      default:
    106         ctx->Feedback.Mask = 0;
     102        ctx->Feedback.Mask = 0;
    107103         gl_error( ctx, GL_INVALID_ENUM, "glFeedbackBuffer" );
    108104   }
     
    115111
    116112
    117 void gl_PassThrough( GLcontext *ctx, GLfloat token )
    118 {
     113void
     114_mesa_PassThrough( GLfloat token )
     115{
     116   GET_CURRENT_CONTEXT(ctx);
    119117   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPassThrough");
    120118
     
    132130void gl_feedback_vertex( GLcontext *ctx,
    133131                         const GLfloat win[4],
    134                         const GLfloat color[4],
    135                         GLuint index,
    136                         const GLfloat texcoord[4] )
     132                        const GLfloat color[4],
     133                        GLuint index,
     134                        const GLfloat texcoord[4] )
    137135{
    138136   FEEDBACK_TOKEN( ctx, win[0] );
     
    163161
    164162
    165 static void gl_do_feedback_vertex( GLcontext *ctx, GLuint v, GLuint pv )
     163static void feedback_vertex( GLcontext *ctx, GLuint v, GLuint pv )
    166164{
    167165   GLfloat win[4];
     
    169167   GLfloat tc[4];
    170168   GLuint texUnit = ctx->Texture.CurrentTransformUnit;
    171    struct vertex_buffer *VB = ctx->VB;
     169   const struct vertex_buffer *VB = ctx->VB;
     170   GLuint index;
    172171
    173172   win[0] = VB->Win.data[v][0];
    174173   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;
    176175   win[3] = 1.0 / VB->Win.data[v][3];
    177176
    178    if (ctx->Light.ShadeModel==GL_SMOOTH) pv = v;
     177   if (ctx->Light.ShadeModel == GL_SMOOTH)
     178      pv = v;
    179179
    180180   UBYTE_RGBA_TO_FLOAT_RGBA( color, VB->ColorPtr->data[pv] );
    181181
    182182   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) {
    185184      GLfloat invq = 1.0F / VB->TexCoordPtr[texUnit]->data[v][3];
    186185      tc[0] = VB->TexCoordPtr[texUnit]->data[v][0] * invq;
     
    188187      tc[2] = VB->TexCoordPtr[texUnit]->data[v][2] * invq;
    189188      tc[3] = VB->TexCoordPtr[texUnit]->data[v][3];
    190    } else {
     189   }
     190   else {
    191191      ASSIGN_4V(tc, 0,0,0,1);
    192192      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 );
    198203}
    199204
     
    204209 */
    205210void gl_feedback_triangle( GLcontext *ctx,
    206                            GLuint v0, GLuint v1, GLuint v2, GLuint pv )
     211                           GLuint v0, GLuint v1, GLuint v2, GLuint pv )
    207212{
    208213   if (gl_cull_triangle( ctx, v0, v1, v2, 0 )) {
    209214      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 );
    215220   }
    216221}
     
    226231   FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) token );
    227232
    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 );
    230235
    231236   ctx->StippleCounter++;
     
    235240void gl_feedback_points( GLcontext *ctx, GLuint first, GLuint last )
    236241{
    237    struct vertex_buffer *VB = ctx->VB;
     242   const struct vertex_buffer *VB = ctx->VB;
    238243   GLuint i;
    239244
    240    for (i=first;i<=last;i++)
     245   for (i=first;i<=last;i++) {
    241246      if (VB->ClipMask[i]==0) {
    242247         FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_POINT_TOKEN );
    243          gl_do_feedback_vertex( ctx, i, i );
     248         feedback_vertex( ctx, i, i );
    244249      }
     250   }
    245251}
    246252
     
    257263 * NOTE: this function can't be put in a display list.
    258264 */
    259 void gl_SelectBuffer( GLcontext *ctx, GLsizei size, GLuint *buffer )
    260 {
     265void
     266_mesa_SelectBuffer( GLsizei size, GLuint *buffer )
     267{
     268   GET_CURRENT_CONTEXT(ctx);
    261269   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glSelectBuffer");
    262270   if (ctx->RenderMode==GL_SELECT) {
     
    273281
    274282
    275 #define WRITE_RECORD( CTX, V )                                  \
    276         if (CTX->Select.BufferCount < CTX->Select.BufferSize) { \
    277            CTX->Select.Buffer[CTX->Select.BufferCount] = (V);   \
    278         }                                                       \
    279         CTX->Select.BufferCount++;
     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++;
    280288
    281289
     
    293301
    294302void 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
     316void 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
     326void gl_select_points( GLcontext *ctx, GLuint first, GLuint last )
    296327{
    297328   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;
    319330   GLuint i;
    320331
    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   }
    324337}
    325338
     
    333346   /* 2^32-1 and round to nearest unsigned integer. */
    334347
    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 */
    336349   zmin = (GLuint) ((GLfloat) zscale * ctx->Select.HitMinZ);
    337350   zmax = (GLuint) ((GLfloat) zscale * ctx->Select.HitMaxZ);
     
    340353   WRITE_RECORD( ctx, zmin );
    341354   WRITE_RECORD( ctx, zmax );
    342    for (i=0;i<ctx->Select.NameStackDepth;i++) {
     355   for (i = 0; i < ctx->Select.NameStackDepth; i++) {
    343356      WRITE_RECORD( ctx, ctx->Select.NameStack[i] );
    344357   }
     
    352365
    353366
    354 void gl_InitNames( GLcontext *ctx )
    355 {
     367void
     368_mesa_InitNames( void )
     369{
     370   GET_CURRENT_CONTEXT(ctx);
    356371   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glInitNames");
    357372   /* Record the hit before the HitFlag is wiped out again. */
    358    if (ctx->RenderMode==GL_SELECT) {
     373   if (ctx->RenderMode == GL_SELECT) {
    359374      if (ctx->Select.HitFlag) {
    360375         write_hit_record( ctx );
     
    369384
    370385
    371 void gl_LoadName( GLcontext *ctx, GLuint name )
    372 {
     386void
     387_mesa_LoadName( GLuint name )
     388{
     389   GET_CURRENT_CONTEXT(ctx);
    373390   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) {
    378395      gl_error( ctx, GL_INVALID_OPERATION, "glLoadName" );
    379396      return;
     
    382399      write_hit_record( ctx );
    383400   }
    384    if (ctx->Select.NameStackDepth<MAX_NAME_STACK_DEPTH) {
     401   if (ctx->Select.NameStackDepth < MAX_NAME_STACK_DEPTH) {
    385402      ctx->Select.NameStack[ctx->Select.NameStackDepth-1] = name;
    386403   }
     
    391408
    392409
    393 void gl_PushName( GLcontext *ctx, GLuint name )
    394 {
     410void
     411_mesa_PushName( GLuint name )
     412{
     413   GET_CURRENT_CONTEXT(ctx);
    395414   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushName");
    396    if (ctx->RenderMode!=GL_SELECT) {
     415   if (ctx->RenderMode != GL_SELECT) {
    397416      return;
    398417   }
     
    400419      write_hit_record( ctx );
    401420   }
    402    if (ctx->Select.NameStackDepth<MAX_NAME_STACK_DEPTH) {
     421   if (ctx->Select.NameStackDepth < MAX_NAME_STACK_DEPTH) {
    403422      ctx->Select.NameStack[ctx->Select.NameStackDepth++] = name;
    404423   }
     
    410429
    411430
    412 void gl_PopName( GLcontext *ctx )
    413 {
     431void
     432_mesa_PopName( void )
     433{
     434   GET_CURRENT_CONTEXT(ctx);
    414435   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopName");
    415    if (ctx->RenderMode!=GL_SELECT) {
     436   if (ctx->RenderMode != GL_SELECT) {
    416437      return;
    417438   }
     
    419440      write_hit_record( ctx );
    420441   }
    421    if (ctx->Select.NameStackDepth>0) {
     442   if (ctx->Select.NameStackDepth > 0) {
    422443      ctx->Select.NameStackDepth--;
    423444   }
     
    438459 * NOTE: this function can't be put in a display list.
    439460 */
    440 GLint gl_RenderMode( GLcontext *ctx, GLenum mode )
    441 {
     461GLint
     462_mesa_RenderMode( GLenum mode )
     463{
     464   GET_CURRENT_CONTEXT(ctx);
    442465   GLint result;
    443466
     
    451474   switch (ctx->RenderMode) {
    452475      case GL_RENDER:
    453         result = 0;
    454         break;
     476        result = 0;
     477        break;
    455478      case GL_SELECT:
    456         if (ctx->Select.HitFlag) {
    457             write_hit_record( ctx );
    458         }
    459         if (ctx->Select.BufferCount > ctx->Select.BufferSize) {
    460             /* overflow */
     479        if (ctx->Select.HitFlag) {
     480            write_hit_record( ctx );
     481        }
     482        if (ctx->Select.BufferCount > ctx->Select.BufferSize) {
     483            /* overflow */
    461484#ifdef DEBUG
    462485            gl_warning(ctx, "Feedback buffer overflow");
    463486#endif
    464             result = -1;
    465         }
    466         else {
    467             result = ctx->Select.Hits;
    468         }
    469         ctx->Select.BufferCount = 0;
    470         ctx->Select.Hits = 0;
    471         ctx->Select.NameStackDepth = 0;
    472         break;
     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;
    473496      case GL_FEEDBACK:
    474         if (ctx->Feedback.Count > ctx->Feedback.BufferSize) {
    475             /* overflow */
    476             result = -1;
    477         }
    478         else {
    479             result = ctx->Feedback.Count;
    480         }
    481         ctx->Feedback.Count = 0;
    482         break;
     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;
    483506      default:
    484         gl_error( ctx, GL_INVALID_ENUM, "glRenderMode" );
    485         return 0;
     507        gl_error( ctx, GL_INVALID_ENUM, "glRenderMode" );
     508        return 0;
    486509   }
    487510
     
    490513         break;
    491514      case GL_SELECT:
    492         ctx->TriangleCaps |= DD_SELECT;
    493         if (ctx->Select.BufferSize==0) {
    494             /* haven't called glSelectBuffer yet */
    495             gl_error( ctx, GL_INVALID_OPERATION, "glRenderMode" );
    496         }
    497         break;
     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;
    498521      case GL_FEEDBACK:
    499         ctx->TriangleCaps |= DD_FEEDBACK;
    500         if (ctx->Feedback.BufferSize==0) {
    501             /* haven't called glFeedbackBuffer yet */
    502             gl_error( ctx, GL_INVALID_OPERATION, "glRenderMode" );
    503         }
    504         break;
     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;
    505528      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   }
    510532
    511533   ctx->RenderMode = mode;
Note: See TracChangeset for help on using the changeset viewer.