ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

feedback.c
Go to the documentation of this file.
00001 
00006 /*
00007  * Mesa 3-D graphics library
00008  * Version:  5.1
00009  *
00010  * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a
00013  * copy of this software and associated documentation files (the "Software"),
00014  * to deal in the Software without restriction, including without limitation
00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00016  * and/or sell copies of the Software, and to permit persons to whom the
00017  * Software is furnished to do so, subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be included
00020  * in all copies or substantial portions of the Software.
00021  *
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00025  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00026  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00027  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00028  */
00029 
00030 
00031 #include "glheader.h"
00032 #include "colormac.h"
00033 #include "context.h"
00034 #include "enums.h"
00035 #include "feedback.h"
00036 #include "macros.h"
00037 #include "mtypes.h"
00038 
00039 
00040 #if _HAVE_FULL_GL
00041 
00042 
00043 #define FB_3D       0x01
00044 #define FB_4D       0x02
00045 #define FB_INDEX    0x04
00046 #define FB_COLOR    0x08
00047 #define FB_TEXTURE  0X10
00048 
00049 
00050 
00051 void GLAPIENTRY
00052 _mesa_FeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer )
00053 {
00054    GET_CURRENT_CONTEXT(ctx);
00055    ASSERT_OUTSIDE_BEGIN_END(ctx);
00056 
00057    if (ctx->RenderMode==GL_FEEDBACK) {
00058       _mesa_error( ctx, GL_INVALID_OPERATION, "glFeedbackBuffer" );
00059       return;
00060    }
00061    if (size<0) {
00062       _mesa_error( ctx, GL_INVALID_VALUE, "glFeedbackBuffer(size<0)" );
00063       return;
00064    }
00065    if (!buffer) {
00066       _mesa_error( ctx, GL_INVALID_VALUE, "glFeedbackBuffer(buffer==NULL)" );
00067       ctx->Feedback.BufferSize = 0;
00068       return;
00069    }
00070 
00071    switch (type) {
00072       case GL_2D:
00073      ctx->Feedback._Mask = 0;
00074      break;
00075       case GL_3D:
00076      ctx->Feedback._Mask = FB_3D;
00077      break;
00078       case GL_3D_COLOR:
00079      ctx->Feedback._Mask = (FB_3D |
00080                 (ctx->Visual.rgbMode ? FB_COLOR : FB_INDEX));
00081      break;
00082       case GL_3D_COLOR_TEXTURE:
00083      ctx->Feedback._Mask = (FB_3D |
00084                 (ctx->Visual.rgbMode ? FB_COLOR : FB_INDEX) |
00085                 FB_TEXTURE);
00086      break;
00087       case GL_4D_COLOR_TEXTURE:
00088      ctx->Feedback._Mask = (FB_3D | FB_4D |
00089                 (ctx->Visual.rgbMode ? FB_COLOR : FB_INDEX) |
00090                 FB_TEXTURE);
00091      break;
00092       default:
00093          _mesa_error( ctx, GL_INVALID_ENUM, "glFeedbackBuffer" );
00094      return;
00095    }
00096 
00097    FLUSH_VERTICES(ctx, _NEW_RENDERMODE); /* Always flush */
00098    ctx->Feedback.Type = type;
00099    ctx->Feedback.BufferSize = size;
00100    ctx->Feedback.Buffer = buffer;
00101    ctx->Feedback.Count = 0;               /* Becaues of this. */
00102 }
00103 
00104 
00105 void GLAPIENTRY
00106 _mesa_PassThrough( GLfloat token )
00107 {
00108    GET_CURRENT_CONTEXT(ctx);
00109    ASSERT_OUTSIDE_BEGIN_END(ctx);
00110 
00111    if (ctx->RenderMode==GL_FEEDBACK) {
00112       FLUSH_VERTICES(ctx, 0);
00113       FEEDBACK_TOKEN( ctx, (GLfloat) (GLint) GL_PASS_THROUGH_TOKEN );
00114       FEEDBACK_TOKEN( ctx, token );
00115    }
00116 }
00117 
00118 
00119 
00120 /*
00121  * Put a vertex into the feedback buffer.
00122  */
00123 void _mesa_feedback_vertex( GLcontext *ctx,
00124                             const GLfloat win[4],
00125                             const GLfloat color[4],
00126                             GLfloat index,
00127                             const GLfloat texcoord[4] )
00128 {
00129 #if 0
00130    {
00131       /* snap window x, y to fractional pixel position */
00132       const GLint snapMask = ~((FIXED_ONE / (1 << SUB_PIXEL_BITS)) - 1);
00133       GLfixed x, y;
00134       x = FloatToFixed(win[0]) & snapMask;
00135       y = FloatToFixed(win[1]) & snapMask;
00136       FEEDBACK_TOKEN(ctx, FixedToFloat(x));
00137       FEEDBACK_TOKEN(ctx, FixedToFloat(y) );
00138    }
00139 #else
00140    FEEDBACK_TOKEN( ctx, win[0] );
00141    FEEDBACK_TOKEN( ctx, win[1] );
00142 #endif
00143    if (ctx->Feedback._Mask & FB_3D) {
00144       FEEDBACK_TOKEN( ctx, win[2] );
00145    }
00146    if (ctx->Feedback._Mask & FB_4D) {
00147       FEEDBACK_TOKEN( ctx, win[3] );
00148    }
00149    if (ctx->Feedback._Mask & FB_INDEX) {
00150       FEEDBACK_TOKEN( ctx, (GLfloat) index );
00151    }
00152    if (ctx->Feedback._Mask & FB_COLOR) {
00153       FEEDBACK_TOKEN( ctx, color[0] );
00154       FEEDBACK_TOKEN( ctx, color[1] );
00155       FEEDBACK_TOKEN( ctx, color[2] );
00156       FEEDBACK_TOKEN( ctx, color[3] );
00157    }
00158    if (ctx->Feedback._Mask & FB_TEXTURE) {
00159       FEEDBACK_TOKEN( ctx, texcoord[0] );
00160       FEEDBACK_TOKEN( ctx, texcoord[1] );
00161       FEEDBACK_TOKEN( ctx, texcoord[2] );
00162       FEEDBACK_TOKEN( ctx, texcoord[3] );
00163    }
00164 }
00165 
00166 #endif
00167 
00168 
00169 /**********************************************************************/
00172 
00186 void GLAPIENTRY
00187 _mesa_SelectBuffer( GLsizei size, GLuint *buffer )
00188 {
00189    GET_CURRENT_CONTEXT(ctx);
00190    ASSERT_OUTSIDE_BEGIN_END(ctx);
00191 
00192    if (ctx->RenderMode==GL_SELECT) {
00193       _mesa_error( ctx, GL_INVALID_OPERATION, "glSelectBuffer" );
00194       return;           /* KW: added return */
00195    }
00196 
00197    FLUSH_VERTICES(ctx, _NEW_RENDERMODE); 
00198    ctx->Select.Buffer = buffer;
00199    ctx->Select.BufferSize = size;
00200    ctx->Select.BufferCount = 0;
00201    ctx->Select.HitFlag = GL_FALSE;
00202    ctx->Select.HitMinZ = 1.0;
00203    ctx->Select.HitMaxZ = 0.0;
00204 }
00205 
00206 
00216 #define WRITE_RECORD( CTX, V )                  \
00217     if (CTX->Select.BufferCount < CTX->Select.BufferSize) { \
00218        CTX->Select.Buffer[CTX->Select.BufferCount] = (V);   \
00219     }                           \
00220     CTX->Select.BufferCount++;
00221 
00222 
00232 void _mesa_update_hitflag( GLcontext *ctx, GLfloat z )
00233 {
00234    ctx->Select.HitFlag = GL_TRUE;
00235    if (z < ctx->Select.HitMinZ) {
00236       ctx->Select.HitMinZ = z;
00237    }
00238    if (z > ctx->Select.HitMaxZ) {
00239       ctx->Select.HitMaxZ = z;
00240    }
00241 }
00242 
00243 
00255 static void write_hit_record( GLcontext *ctx )
00256 {
00257    GLuint i;
00258    GLuint zmin, zmax, zscale = (~0u);
00259 
00260    /* HitMinZ and HitMaxZ are in [0,1].  Multiply these values by */
00261    /* 2^32-1 and round to nearest unsigned integer. */
00262 
00263    assert( ctx != NULL ); /* this line magically fixes a SunOS 5.x/gcc bug */
00264    zmin = (GLuint) ((GLfloat) zscale * ctx->Select.HitMinZ);
00265    zmax = (GLuint) ((GLfloat) zscale * ctx->Select.HitMaxZ);
00266 
00267    WRITE_RECORD( ctx, ctx->Select.NameStackDepth );
00268    WRITE_RECORD( ctx, zmin );
00269    WRITE_RECORD( ctx, zmax );
00270    for (i = 0; i < ctx->Select.NameStackDepth; i++) {
00271       WRITE_RECORD( ctx, ctx->Select.NameStack[i] );
00272    }
00273 
00274    ctx->Select.Hits++;
00275    ctx->Select.HitFlag = GL_FALSE;
00276    ctx->Select.HitMinZ = 1.0;
00277    ctx->Select.HitMaxZ = -1.0;
00278 }
00279 
00280 
00288 void GLAPIENTRY
00289 _mesa_InitNames( void )
00290 {
00291    GET_CURRENT_CONTEXT(ctx);
00292    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
00293 
00294    /* Record the hit before the HitFlag is wiped out again. */
00295    if (ctx->RenderMode == GL_SELECT) {
00296       if (ctx->Select.HitFlag) {
00297          write_hit_record( ctx );
00298       }
00299    }
00300    ctx->Select.NameStackDepth = 0;
00301    ctx->Select.HitFlag = GL_FALSE;
00302    ctx->Select.HitMinZ = 1.0;
00303    ctx->Select.HitMaxZ = 0.0;
00304    ctx->NewState |= _NEW_RENDERMODE;
00305 }
00306 
00307 
00319 void GLAPIENTRY
00320 _mesa_LoadName( GLuint name )
00321 {
00322    GET_CURRENT_CONTEXT(ctx);
00323    ASSERT_OUTSIDE_BEGIN_END(ctx);
00324 
00325    if (ctx->RenderMode != GL_SELECT) {
00326       return;
00327    }
00328    if (ctx->Select.NameStackDepth == 0) {
00329       _mesa_error( ctx, GL_INVALID_OPERATION, "glLoadName" );
00330       return;
00331    }
00332 
00333    FLUSH_VERTICES(ctx, _NEW_RENDERMODE);
00334 
00335    if (ctx->Select.HitFlag) {
00336       write_hit_record( ctx );
00337    }
00338    if (ctx->Select.NameStackDepth < MAX_NAME_STACK_DEPTH) {
00339       ctx->Select.NameStack[ctx->Select.NameStackDepth-1] = name;
00340    }
00341    else {
00342       ctx->Select.NameStack[MAX_NAME_STACK_DEPTH-1] = name;
00343    }
00344 }
00345 
00346 
00358 void GLAPIENTRY
00359 _mesa_PushName( GLuint name )
00360 {
00361    GET_CURRENT_CONTEXT(ctx);
00362    ASSERT_OUTSIDE_BEGIN_END(ctx);
00363 
00364    if (ctx->RenderMode != GL_SELECT) {
00365       return;
00366    }
00367 
00368    FLUSH_VERTICES(ctx, _NEW_RENDERMODE);
00369    if (ctx->Select.HitFlag) {
00370       write_hit_record( ctx );
00371    }
00372    if (ctx->Select.NameStackDepth >= MAX_NAME_STACK_DEPTH) {
00373       _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushName" );
00374    }
00375    else
00376       ctx->Select.NameStack[ctx->Select.NameStackDepth++] = name;
00377 }
00378 
00379 
00389 void GLAPIENTRY
00390 _mesa_PopName( void )
00391 {
00392    GET_CURRENT_CONTEXT(ctx);
00393    ASSERT_OUTSIDE_BEGIN_END(ctx);
00394 
00395    if (ctx->RenderMode != GL_SELECT) {
00396       return;
00397    }
00398 
00399    FLUSH_VERTICES(ctx, _NEW_RENDERMODE);
00400    if (ctx->Select.HitFlag) {
00401       write_hit_record( ctx );
00402    }
00403    if (ctx->Select.NameStackDepth == 0) {
00404       _mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopName" );
00405    }
00406    else
00407       ctx->Select.NameStackDepth--;
00408 }
00409 
00413 /**********************************************************************/
00416 
00432 GLint GLAPIENTRY
00433 _mesa_RenderMode( GLenum mode )
00434 {
00435    GET_CURRENT_CONTEXT(ctx);
00436    GLint result;
00437    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
00438 
00439    if (MESA_VERBOSE & VERBOSE_API)
00440       _mesa_debug(ctx, "glRenderMode %s\n", _mesa_lookup_enum_by_nr(mode));
00441 
00442    FLUSH_VERTICES(ctx, _NEW_RENDERMODE);
00443 
00444    switch (ctx->RenderMode) {
00445       case GL_RENDER:
00446      result = 0;
00447      break;
00448       case GL_SELECT:
00449      if (ctx->Select.HitFlag) {
00450         write_hit_record( ctx );
00451      }
00452      if (ctx->Select.BufferCount > ctx->Select.BufferSize) {
00453         /* overflow */
00454 #ifdef DEBUG
00455             _mesa_warning(ctx, "Feedback buffer overflow");
00456 #endif
00457         result = -1;
00458      }
00459      else {
00460         result = ctx->Select.Hits;
00461      }
00462      ctx->Select.BufferCount = 0;
00463      ctx->Select.Hits = 0;
00464      ctx->Select.NameStackDepth = 0;
00465      break;
00466 #if _HAVE_FULL_GL
00467       case GL_FEEDBACK:
00468      if (ctx->Feedback.Count > ctx->Feedback.BufferSize) {
00469         /* overflow */
00470         result = -1;
00471      }
00472      else {
00473         result = ctx->Feedback.Count;
00474      }
00475      ctx->Feedback.Count = 0;
00476      break;
00477 #endif
00478       default:
00479      _mesa_error( ctx, GL_INVALID_ENUM, "glRenderMode" );
00480      return 0;
00481    }
00482 
00483    switch (mode) {
00484       case GL_RENDER:
00485          break;
00486       case GL_SELECT:
00487      if (ctx->Select.BufferSize==0) {
00488         /* haven't called glSelectBuffer yet */
00489         _mesa_error( ctx, GL_INVALID_OPERATION, "glRenderMode" );
00490      }
00491      break;
00492 #if _HAVE_FULL_GL
00493       case GL_FEEDBACK:
00494      if (ctx->Feedback.BufferSize==0) {
00495         /* haven't called glFeedbackBuffer yet */
00496         _mesa_error( ctx, GL_INVALID_OPERATION, "glRenderMode" );
00497      }
00498      break;
00499 #endif
00500       default:
00501      _mesa_error( ctx, GL_INVALID_ENUM, "glRenderMode" );
00502      return 0;
00503    }
00504 
00505    ctx->RenderMode = mode;
00506    if (ctx->Driver.RenderMode)
00507       ctx->Driver.RenderMode( ctx, mode );
00508 
00509    return result;
00510 }
00511 
00515 /**********************************************************************/
00518 
00522 void _mesa_init_feedback( GLcontext * ctx )
00523 {
00524    /* Feedback */
00525    ctx->Feedback.Type = GL_2D;   /* TODO: verify */
00526    ctx->Feedback.Buffer = NULL;
00527    ctx->Feedback.BufferSize = 0;
00528    ctx->Feedback.Count = 0;
00529 
00530    /* Selection/picking */
00531    ctx->Select.Buffer = NULL;
00532    ctx->Select.BufferSize = 0;
00533    ctx->Select.BufferCount = 0;
00534    ctx->Select.Hits = 0;
00535    ctx->Select.NameStackDepth = 0;
00536 
00537    /* Miscellaneous */
00538    ctx->RenderMode = GL_RENDER;
00539 }
00540 

Generated on Fri May 25 2012 04:18:22 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.