Ignore:
Timestamp:
Apr 1, 2012 11:16:54 PM (12 years ago)
Author:
ldelgass
Message:

Style fixes and GL state leak fixes in HeightMap?

Location:
trunk/packages/vizservers/nanovis
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/HeightMap.cpp

    r2882 r2927  
    6262
    6363void
    64 HeightMap::render(graphics::RenderContext* renderContext)
    65 {
     64HeightMap::render(graphics::RenderContext *renderContext)
     65{
     66    glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_LIGHTING_BIT);
     67
    6668    if (renderContext->getCullMode() == graphics::RenderContext::NO_CULL) {
    6769        glDisable(GL_CULL_FACE);
    6870    } else {
    6971        glEnable(GL_CULL_FACE);
    70         glCullFace((GLuint) renderContext->getCullMode());
    71     }
    72     glPolygonMode(GL_FRONT_AND_BACK, (GLuint) renderContext->getPolygonMode());
    73     glShadeModel((GLuint) renderContext->getShadingModel());
    74 
     72        glCullFace((GLuint)renderContext->getCullMode());
     73    }
     74    glPolygonMode(GL_FRONT_AND_BACK, (GLuint)renderContext->getPolygonMode());
     75    glShadeModel((GLuint)renderContext->getShadingModel());
     76
     77    glMatrixMode(GL_MODELVIEW);
    7578    glPushMatrix();
    7679
     
    8386
    8487    if (_contour != NULL) {
    85         glDepthRange (0.001, 1.0);
     88        glDepthRange(0.001, 1.0);
    8689    }
    8790       
     
    9699        glDisableClientState(GL_INDEX_ARRAY);
    97100        glDisableClientState(GL_NORMAL_ARRAY);
    98        
     101
    99102        if (_tfPtr) {
    100103            // PUT vertex program here
    101104            //
    102105            //
    103            
    104             cgGLBindProgram(_shader->getFP());
    105             cgGLEnableProfile(CG_PROFILE_FP40);
    106            
     106            _shader->bind();
     107 
    107108            cgGLSetTextureParameter(_tfParam, _tfPtr->id());
    108109            cgGLEnableTextureParameter(_tfParam);
    109110            cgGLSetParameter1f(_opacityParam, _opacity);
    110            
     111
    111112            glEnable(GL_TEXTURE_1D);
    112113            _tfPtr->getTexture()->activate();
    113             
     114 
    114115            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    115116        }
    116        
     117
    117118        glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObjectID);
    118119        glVertexPointer(3, GL_FLOAT, 12, 0);
    119        
     120
    120121        glBindBuffer(GL_ARRAY_BUFFER, _textureBufferObjectID);
    121         ::glTexCoordPointer(3, GL_FLOAT, 12, 0);
    122        
     122        glTexCoordPointer(3, GL_FLOAT, 12, 0);
     123
    123124#define _TRIANGLES_
    124125#ifdef _TRIANGLES_
    125126        glDrawElements(GL_TRIANGLES, _indexCount, GL_UNSIGNED_INT,
    126127                       _indexBuffer);
    127 #else                   
     128#else
    128129        glDrawElements(GL_QUADS, _indexCount, GL_UNSIGNED_INT,
    129130                       _indexBuffer);
     
    131132
    132133        glBindBuffer(GL_ARRAY_BUFFER, 0);
    133        
     134
    134135        glDisableClientState(GL_VERTEX_ARRAY);
    135136        if (_tfPtr != NULL) {
    136137            _tfPtr->getTexture()->deactivate();
    137138            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    138            
    139             cgGLDisableProfile(CG_PROFILE_FP40);
     139
     140            _shader->unbind();
    140141        }
    141142    }
    142143    glShadeModel(GL_FLAT);
    143144    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    144    
     145
    145146    if (_contour != NULL) {
    146147        if (_contourVisible) {
     
    148149            glDisable(GL_TEXTURE_2D);
    149150            glColor4f(_contourColor.x, _contourColor.y, _contourColor.z,
    150                 _opacity /*1.0f*/);
     151                      _opacity /*1.0f*/);
    151152            glDepthRange (0.0, 0.999);
    152153            _contour->render();
    153             glDepthRange (0.0, 1.0);
    154154        }
    155155
     
    159159            glDisable(GL_TEXTURE_2D);
    160160            glColor4f(_contourColor.x, _contourColor.y, _contourColor.z,
    161                 _opacity /*1.0f*/);
     161                      _opacity /*1.0f*/);
    162162            //glDepthRange (0.0, 0.999);
    163163            _topContour->render();
    164             //glDepthRange (0.0, 1.0);
    165         }
    166 #endif
    167     }
     164        }
     165#endif
     166        glDepthRange (0.0, 1.0);
     167    }
     168
    168169    glPopMatrix();
     170    glPopAttrib();
    169171}
    170172
     
    446448}
    447449
    448 // Maps the data coordinates of the surface into the grid's axes.
     450/**
     451 * \brief Maps the data coordinates of the surface into the grid's axes.
     452 */
    449453void
    450 HeightMap::MapToGrid(Grid *gridPtr)
     454HeightMap::mapToGrid(Grid *gridPtr)
    451455{
    452456    int count = _xNum * _yNum;
     
    517521
    518522void
    519 HeightMap::render_topview(graphics::RenderContext* renderContext,
    520                           int render_width, int render_height)
    521 {
    522    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     523HeightMap::renderTopview(graphics::RenderContext* renderContext,
     524                         int render_width, int render_height)
     525{
     526    glClear(GL_COLOR_BUFFER_BIT);
    523527    glPushAttrib(GL_VIEWPORT_BIT);
    524528    glViewport(0, 0, render_width, render_height);
     
    574578       
    575579        if (_tfPtr != NULL) {
    576             cgGLBindProgram(_shader->getFP());
    577             cgGLEnableProfile(CG_PROFILE_FP40);
     580            _shader->bind();
    578581           
    579582            cgGLSetTextureParameter(_tfParam, _tfPtr->id());
    580583            cgGLEnableTextureParameter(_tfParam);
    581            
     584
    582585            glEnable(GL_TEXTURE_1D);
    583586            _tfPtr->getTexture()->activate();
    584            
     587
    585588            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    586         }
    587         else {
     589        } else {
    588590            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    589591        }
    590        
     592
    591593        glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObjectID);
    592594        glVertexPointer(3, GL_FLOAT, 12, 0);
    593        
     595
    594596        glBindBuffer(GL_ARRAY_BUFFER, _textureBufferObjectID);
    595         ::glTexCoordPointer(3, GL_FLOAT, 12, 0);
    596        
     597        glTexCoordPointer(3, GL_FLOAT, 12, 0);
     598
    597599#define _TRIANGLES_
    598600#ifdef _TRIANGLES_
    599601        glDrawElements(GL_TRIANGLES, _indexCount, GL_UNSIGNED_INT,
    600602                       _indexBuffer);
    601 #else                   
     603#else
    602604        glDrawElements(GL_QUADS, _indexCount, GL_UNSIGNED_INT,
    603605                       _indexBuffer);
     
    605607
    606608        glBindBuffer(GL_ARRAY_BUFFER, 0);
    607        
     609
    608610        glDisableClientState(GL_VERTEX_ARRAY);
    609611        if (_tfPtr != NULL) {
    610612            _tfPtr->getTexture()->deactivate();
    611613            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    612            
    613             cgGLDisableProfile(CG_PROFILE_FP40);
    614         }
    615     }
    616    
     614
     615            _shader->unbind();
     616        }
     617    }
     618
    617619    glShadeModel(GL_FLAT);
    618620    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    619    
     621
    620622    if (_contour != NULL) {
    621623        if (_contourVisible) {
  • trunk/packages/vizservers/nanovis/HeightMap.h

    r2877 r2927  
    3131    void render(graphics::RenderContext *renderContext);
    3232
    33     void render_topview(graphics::RenderContext *renderContext,
    34                         int render_width, int render_height);
     33    void renderTopview(graphics::RenderContext *renderContext,
     34                       int render_width, int render_height);
    3535
    3636    /**
     
    5454    void setHeight(int xCount, int yCount, Vector3 *heights);
    5555
    56     void MapToGrid(Grid *gridPtr);
     56    void mapToGrid(Grid *gridPtr);
    5757
    5858    /**
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r2923 r2927  
    15601560        HeightMap *hmPtr;
    15611561        hmPtr = (HeightMap *)Tcl_GetHashValue(hPtr);
    1562         hmPtr->MapToGrid(grid);
     1562        hmPtr->mapToGrid(grid);
    15631563    }
    15641564    HeightMap::updatePending = false;
     
    24342434    //cam->initialize();
    24352435
    2436     heightmap->render_topview(renderContext, width, height);
     2436    heightmap->renderTopview(renderContext, width, height);
    24372437
    24382438    NanoVis::readScreen();
Note: See TracChangeset for help on using the changeset viewer.