Ignore:
Timestamp:
Apr 1, 2012 5:19:58 PM (12 years ago)
Author:
ldelgass
Message:

Convert LIC renderer to use NvShader? class. Also, prevent GL state leaks from
LIC renderer, esp. with framebuffer binding.

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

Legend:

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

    r2877 r2920  
    10651065        }
    10661066        // FIXME: This doesn't work when there is more than one flow.
    1067         licRenderer->set_offset(flowPtr->GetRelativePosition());
     1067        licRenderer->setOffset(flowPtr->GetRelativePosition());
    10681068        NanoVis::velocityArrowsSlice->slicePos(flowPtr->GetRelativePosition());
    10691069       
  • trunk/packages/vizservers/nanovis/FlowCmd.h

    r2875 r2920  
    298298    {
    299299        /* Must set axis before offset or position goes to wrong axis. */
    300         NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
    301         NanoVis::licRenderer->set_offset(_sv.slicePos.value);
     300        NanoVis::licRenderer->setAxis(_sv.slicePos.axis);
     301        NanoVis::licRenderer->setOffset(_sv.slicePos.value);
    302302        NanoVis::licRenderer->active(true);
    303303    }
     
    322322    void SetAxis()
    323323    {
    324         NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
     324        NanoVis::licRenderer->setAxis(_sv.slicePos.axis);
    325325    }
    326326
     
    328328    {
    329329        _sv.slicePos.axis = axis;
    330         NanoVis::licRenderer->set_axis(_sv.slicePos.axis);
     330        NanoVis::licRenderer->setAxis(_sv.slicePos.axis);
    331331    }
    332332
     
    334334    {
    335335        _sv.slicePos.value = position;
    336         NanoVis::licRenderer->set_offset(_sv.slicePos.value);
     336        NanoVis::licRenderer->setOffset(_sv.slicePos.value);
    337337    }
    338338
    339339    void SetCurrentPosition()
    340340    {
    341         NanoVis::licRenderer->set_offset(_sv.slicePos.value);
     341        NanoVis::licRenderer->setOffset(_sv.slicePos.value);
    342342    }
    343343
  • trunk/packages/vizservers/nanovis/NvLIC.cpp

    r2884 r2920  
    2929#define SCALE 3.0 //scale for background pattern. small value -> fine texture
    3030
    31 NvLIC::NvLIC(int _size, int _width, int _height, int _axis,
    32              const Vector3& _offset, CGcontext _context) :
     31NvLIC::NvLIC(int size, int width, int height, int axis,
     32             const Vector3& offset) :
    3333    Renderable(Vector3(0.0f, 0.0f, 0.0f)),
    34     disListID(0),
    35     width(_width),
    36     height(_height),
    37     size(_size),
    38     scale(1.0f, 1.0f, 1.0f),
    39     offset(_offset),
    40     iframe(0),
    41     Npat(64),
    42     alpha((int) 0.12*255),
    43     tmax(NPIX/(SCALE*NPN)),
    44     dmax(SCALE/NPIX),
    45     max(1.0f),
    46     _cgContext(_context),
     34    _width(width),
     35    _height(height),
     36    _size(size),
     37    _scale(1.0f, 1.0f, 1.0f),
     38    _origin(0, 0, 0),
     39    _offset(offset),
     40    _axis(axis),
     41    _iframe(0),
     42    _Npat(64),
     43    _alpha((int)0.12*255),
     44    _tmax(NPIX/(SCALE*NPN)),
     45    _dmax(SCALE/NPIX),
     46    _max(1.0f),
     47    _disListID(0),
    4748    _vectorFieldId(0),
    4849    _activate(false)
    4950{
    50 
    51     axis = _axis;
    52     slice_vector = new float[size*size*4];
    53     memset(slice_vector, 0, sizeof(float) * size * size * 4);
    54 
    55     origin.set(0, 0, 0);
     51    _sliceVector = new float[_size*_size*4];
     52    memset(_sliceVector, 0, sizeof(float) * _size * _size * 4);
     53
     54    int fboOrig;
     55    glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fboOrig);
    5656
    5757    //initialize the pattern texture
    58     glGenTextures(1, &pattern_tex);
    59     glBindTexture(GL_TEXTURE_2D, pattern_tex);
     58    glGenTextures(1, &_patternTex);
     59    glBindTexture(GL_TEXTURE_2D, _patternTex);
    6060    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    6161    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     
    6464    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    6565
     66    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NPN, NPN, 0,
     67                 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
     68
    6669    //initialize frame buffer objects
    6770    //render buffer for projecting 3D velocity onto a 2D plane
    68     glGenFramebuffersEXT(1, &vel_fbo);
    69     glGenTextures(1, &slice_vector_tex);
    70 
    71     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo);
    72 
    73     glBindTexture(GL_TEXTURE_RECTANGLE_ARB, slice_vector_tex);
     71    glGenFramebuffersEXT(1, &_velFbo);
     72    glGenTextures(1, &_sliceVectorTex);
     73
     74    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _velFbo);
     75
     76    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _sliceVectorTex);
    7477    glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    7578    glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    76 
    77     // ADD INSOO
    78     glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
    79                     GL_CLAMP_TO_EDGE);
    80     glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
    81                     GL_CLAMP_TO_EDGE);
    82 
    83     glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB, size, size,
    84                 0, GL_RGBA, GL_FLOAT, NULL);
     79    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     80    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     81
     82    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA32F_ARB, _size, _size,
     83                 0, GL_RGBA, GL_FLOAT, NULL);
    8584
    8685    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    87                   GL_TEXTURE_RECTANGLE_ARB, slice_vector_tex, 0);
     86                              GL_TEXTURE_RECTANGLE_ARB, _sliceVectorTex, 0);
    8887
    8988    //render buffer for the convolution
    90     glGenFramebuffersEXT(1, &fbo);
    91     glGenTextures(1, &color_tex);
    92 
    93     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
     89    glGenFramebuffersEXT(1, &_fbo);
     90    glGenTextures(1, &_colorTex);
     91
     92    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fbo);
    9493
    9594    //initialize color texture for lic
    96     glBindTexture(GL_TEXTURE_2D, color_tex);
    97     // INSOO
    98     //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    99     //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    100     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    101     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    102 
    103     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0,
    104                  GL_RGB, GL_INT, NULL);
    105 
    106     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
    107                             GL_COLOR_ATTACHMENT0_EXT,
    108                             GL_TEXTURE_2D, color_tex, 0);
     95    glBindTexture(GL_TEXTURE_2D, _colorTex);
     96    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     97    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     98    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     99
     100    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, _width, _height, 0,
     101                 GL_RGB, GL_UNSIGNED_BYTE, NULL);
     102
     103    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
     104                              GL_TEXTURE_2D, _colorTex, 0);
    109105
    110106    // Check framebuffer completeness at the end of initialization.
    111107    CHECK_FRAMEBUFFER_STATUS();
    112108
    113     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    114 
    115     _render_vel_fprog =
    116         LoadCgSourceProgram(_cgContext, "render_vel.cg",
    117                             CG_PROFILE_FP40, "main");
    118 
    119     _vel_tex_param_render_vel =
    120         cgGetNamedParameter(_render_vel_fprog, "vel_tex");
    121 
    122     _plane_normal_param_render_vel =
    123         cgGetNamedParameter(_render_vel_fprog, "plane_normal");
    124 
    125     _max_param = cgGetNamedParameter(_render_vel_fprog, "vmax");
    126 
    127     make_patterns();
     109    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig);
     110
     111    _renderVelShader = new NvShader();
     112    _renderVelShader->loadFragmentProgram("render_vel.cg", "main");
     113
     114    _velTexParamRenderVel =
     115        _renderVelShader->getNamedParameterFromFP("vel_tex");
     116
     117    _planeNormalParamRenderVel =
     118        _renderVelShader->getNamedParameterFromFP("plane_normal");
     119
     120    _maxParam =
     121        _renderVelShader->getNamedParameterFromFP("vmax");
     122
     123    makePatterns();
    128124}
    129125
    130126NvLIC::~NvLIC()
    131127{
    132     glDeleteTextures(1, &pattern_tex);
    133     glDeleteTextures(1, &mag_tex);
    134 
    135     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo);
    136     glDeleteTextures(1, &slice_vector_tex);
    137 
    138     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
    139     glDeleteTextures(1, &color_tex);
    140 
    141     GLuint buffers[2] = {vel_fbo, fbo};
     128    glDeleteTextures(1, &_patternTex);
     129    glDeleteTextures(1, &_magTex);
     130
     131    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _velFbo);
     132    glDeleteTextures(1, &_sliceVectorTex);
     133
     134    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fbo);
     135    glDeleteTextures(1, &_colorTex);
     136
     137    GLuint buffers[2] = {_velFbo, _fbo};
    142138    glDeleteFramebuffersEXT(2, buffers);
    143139
    144     glDeleteLists(disListID, Npat);
    145    
    146 /*
    147     TBD..
    148     cgDestroyParameter(_vel_tex_param_render_vel);
    149     cgDestroyParameter(_plane_normal_param_render_vel);
    150     cgDestroyParameter(_max_param);
    151 */
    152     cgDestroyProgram(_render_vel_fprog);
    153 
    154     delete [] slice_vector;
    155 }
    156 
    157 void
    158 NvLIC::make_patterns()
     140    glDeleteLists(_disListID, _Npat);
     141
     142    delete _renderVelShader;
     143
     144    delete [] _sliceVector;
     145}
     146
     147void
     148NvLIC::makePatterns()
    159149{
    160     TRACE("begin make_patterns\n");
    161     if (disListID > 0) {
    162         glDeleteLists(disListID, Npat);
    163     }
    164     disListID = glGenLists(Npat);
    165 
    166     TRACE("DisplayList : %d\n", disListID);
     150    TRACE("begin makePatterns\n");
     151    if (_disListID > 0) {
     152        glDeleteLists(_disListID, _Npat);
     153    }
     154    _disListID = glGenLists(_Npat);
     155
     156    TRACE("DisplayList : %d\n", _disListID);
    167157
    168158    int lut[256];
     
    179169        }
    180170    }
    181     for (k = 0; k < Npat; k++) {
    182         t = (k << 8) / Npat;
     171    for (k = 0; k < _Npat; k++) {
     172        t = (k << 8) / _Npat;
    183173        for (i = 0; i < NPN; i++) {
    184174            for (j = 0; j < NPN; j++) {
    185175                pat[i][j][0] = pat[i][j][1] = pat[i][j][2] =
    186176                    lut[(t + phase[i][j]) % 255];
    187                 pat[i][j][3] = alpha;
     177                pat[i][j][3] = _alpha;
    188178            }
    189179        }
    190         glNewList(disListID + k, GL_COMPILE);
    191         glBindTexture(GL_TEXTURE_2D, pattern_tex);
    192         glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0, GL_RGBA,
    193                      GL_UNSIGNED_BYTE, pat);
     180        glNewList(_disListID + k, GL_COMPILE);
     181        glBindTexture(GL_TEXTURE_2D, _patternTex);
     182        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NPN, NPN, 0,
     183                     GL_RGBA, GL_UNSIGNED_BYTE, pat);
    194184        glEndList();
    195185    }
    196186
    197     glBindTexture(GL_TEXTURE_2D, pattern_tex);
    198     glTexImage2D(GL_TEXTURE_2D, 0, 4, NPN, NPN, 0,
     187    glBindTexture(GL_TEXTURE_2D, _patternTex);
     188    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, NPN, NPN, 0,
    199189                 GL_RGBA, GL_UNSIGNED_BYTE, pat);
    200     TRACE("finish make_patterns\n");
    201 }
    202 
    203 void NvLIC::make_magnitudes()
     190    TRACE("finish makePatterns\n");
     191}
     192
     193void NvLIC::makeMagnitudes()
    204194{
    205195    GLubyte mag[NMESH][NMESH][4];
     
    225215        }
    226216    }
    227     glGenTextures(1, &mag_tex);
    228     glBindTexture(GL_TEXTURE_2D, mag_tex);
     217    glGenTextures(1, &_magTex);
     218    glBindTexture(GL_TEXTURE_2D, _magTex);
    229219    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    230220    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     
    238228
    239229void
    240 NvLIC::get_slice()
    241 {
    242     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, vel_fbo);
     230NvLIC::getSlice()
     231{
     232    int fboOrig;
     233    glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fboOrig);
     234
     235    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _velFbo);
     236
     237    glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
    243238
    244239    glClear(GL_COLOR_BUFFER_BIT);
    245 
    246     glViewport(0, 0, size, size);
     240    glDisable(GL_DEPTH_TEST);
     241    glDisable(GL_BLEND);
     242
     243    glViewport(0, 0, _size, _size);
    247244    glMatrixMode(GL_PROJECTION);
     245    glPushMatrix();
    248246    glLoadIdentity();
    249     gluOrtho2D(0, size, 0, size);
     247    gluOrtho2D(0, _size, 0, _size);
    250248    glMatrixMode(GL_MODELVIEW);
     249    glPushMatrix();
    251250    glLoadIdentity();
    252251
    253252    glEnable(GL_TEXTURE_3D);
    254253    glBindTexture(GL_TEXTURE_3D, _vectorFieldId);
    255     cgGLBindProgram(_render_vel_fprog);
    256 
    257     cgGLSetTextureParameter(_vel_tex_param_render_vel, _vectorFieldId);
    258     cgGLEnableTextureParameter(_vel_tex_param_render_vel);
    259     cgGLSetParameter4f(_plane_normal_param_render_vel, 1., 1., 0., 0);
    260     cgGLSetParameter1f(_max_param, max);
    261 
    262     cgGLEnableProfile(CG_PROFILE_FP40);
     254
     255    cgGLSetTextureParameter(_velTexParamRenderVel, _vectorFieldId);
     256    cgGLEnableTextureParameter(_velTexParamRenderVel);
     257    cgGLSetParameter4f(_planeNormalParamRenderVel, 1., 1., 0., 0);
     258    cgGLSetParameter1f(_maxParam, _max);
     259
     260    _renderVelShader->bind();
    263261
    264262    glBegin(GL_QUADS);
    265263    {
    266         switch (axis) {
    267         case 0 :
    268             // TBD..
    269             glTexCoord3f(offset.x, 0., 0.); glVertex2f(0.,   0.);
    270             glTexCoord3f(offset.x, 1., 0.); glVertex2f(size, 0.);
    271             glTexCoord3f(offset.x, 1., 1.); glVertex2f(size, size);
    272             glTexCoord3f(offset.x, 0., 1.); glVertex2f(0.,   size);
    273                 break;
    274         case 1 :
    275             // TBD..
    276             glTexCoord3f(0., offset.y, 0.); glVertex2f(0.,   0.);
    277             glTexCoord3f(1., offset.y, 0.); glVertex2f(size, 0.);
    278             glTexCoord3f(1., offset.y, 1.); glVertex2f(size, size);
    279             glTexCoord3f(0., offset.y, 1.); glVertex2f(0.,   size);
    280                 break;
    281         case 2 :
    282             glTexCoord3f(0., 0., offset.z); glVertex2f(0.,   0.);
    283             glTexCoord3f(1., 0., offset.z); glVertex2f(size, 0.);
    284             glTexCoord3f(1., 1., offset.z); glVertex2f(size, size);
    285             glTexCoord3f(0., 1., offset.z); glVertex2f(0.,   size);
    286             break;     
    287         }
     264        switch (_axis) {
     265        case 0 :
     266            // TBD..
     267            glTexCoord3f(_offset.x, 0., 0.); glVertex2f(0.,    0.);
     268            glTexCoord3f(_offset.x, 1., 0.); glVertex2f(_size, 0.);
     269            glTexCoord3f(_offset.x, 1., 1.); glVertex2f(_size, _size);
     270            glTexCoord3f(_offset.x, 0., 1.); glVertex2f(0.,    _size);
     271                break;
     272        case 1 :
     273            // TBD..
     274            glTexCoord3f(0., _offset.y, 0.); glVertex2f(0.,    0.);
     275            glTexCoord3f(1., _offset.y, 0.); glVertex2f(_size, 0.);
     276            glTexCoord3f(1., _offset.y, 1.); glVertex2f(_size, _size);
     277            glTexCoord3f(0., _offset.y, 1.); glVertex2f(0.,    _size);
     278                break;
     279        case 2 :
     280            glTexCoord3f(0., 0., _offset.z); glVertex2f(0.,    0.);
     281            glTexCoord3f(1., 0., _offset.z); glVertex2f(_size, 0.);
     282            glTexCoord3f(1., 1., _offset.z); glVertex2f(_size, _size);
     283            glTexCoord3f(0., 1., _offset.z); glVertex2f(0.,    _size);
     284            break;
     285        }
    288286    }
    289287    glEnd();
    290288
    291     cgGLDisableProfile(CG_PROFILE_FP40);
    292 
    293     cgGLDisableTextureParameter(_vel_tex_param_render_vel);
     289    _renderVelShader->unbind();
     290
     291    cgGLDisableTextureParameter(_velTexParamRenderVel);
    294292
    295293    glBindTexture(GL_TEXTURE_3D, 0);
     
    297295
    298296    //read the vectors
    299     glReadPixels(0, 0, size, size, GL_RGBA, GL_FLOAT, slice_vector);
    300     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    301 
    302     int lim = size * size * 4;
    303     float* v= slice_vector;
     297    glReadPixels(0, 0, _size, _size, GL_RGBA, GL_FLOAT, _sliceVector);
     298
     299    int lim = _size * _size * 4;
     300    float *v = _sliceVector;
    304301    for (int i = 0; i < lim; ++i) {
    305302        if (isnan(*v)) {
     
    308305        ++v;
    309306    }
     307
     308    glMatrixMode(GL_PROJECTION);
     309    glPopMatrix();
     310    glMatrixMode(GL_MODELVIEW);
     311    glPopMatrix();
     312
     313    glPopAttrib();
     314
     315    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig);
    310316}
    311317
     
    315321{
    316322    if (_vectorFieldId == 0) {
    317         return;
     323        return;
    318324    }
    319325
     
    321327    float x1, x2, y, px, py;
    322328
     329    int fboOrig;
     330    glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fboOrig);
     331
     332    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fbo);
     333
     334    glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     335
     336    glMatrixMode(GL_PROJECTION);
    323337    glPushMatrix();
    324     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
    325 
    326     glMatrixMode(GL_PROJECTION);
    327     glLoadIdentity();
    328     glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
    329 
    330     /*glPushMatrix();*/
     338    glLoadIdentity();
     339
    331340    glViewport(0, 0, (GLsizei) NPIX, (GLsizei) NPIX);
    332341    //glTranslatef(-1.0, -1.0, 0.0);
     
    335344
    336345    glMatrixMode(GL_MODELVIEW);
    337     glLoadIdentity();
    338 
    339     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    340 
    341     //sa = 0.010*cos(iframe*2.0*M_PI/200.0);
     346    glPushMatrix();
     347    glLoadIdentity();
     348
     349    glClear(GL_COLOR_BUFFER_BIT);
     350    //glDepthMask(GL_FALSE);
     351    glDisable(GL_DEPTH_TEST);
     352    glDisable(GL_LIGHTING);
     353    glDisable(GL_ALPHA_TEST);
     354
     355    //_sa = 0.010*cos(_iframe*2.0*M_PI/200.0);
    342356    glEnable(GL_TEXTURE_2D);
    343     glBindTexture(GL_TEXTURE_2D, pattern_tex);
    344     sa = 0.01;
     357    glBindTexture(GL_TEXTURE_2D, _patternTex);
     358    _sa = 0.01;
    345359 
     360    glColor4f(1, 1, 1, 1);
    346361    for (i = 0; i < NMESH-1; i++) {
    347362        x1 = DM*i; x2 = x1 + DM;
     
    350365            y = DM*j;
    351366            glTexCoord2f(x1, y);
    352             get_velocity(x1, y, &px, &py);
     367            getVelocity(x1, y, &px, &py);
    353368            glVertex2f(px, py);
    354            
     369
    355370            glTexCoord2f(x2, y);
    356             get_velocity(x2, y, &px, &py);
     371            getVelocity(x2, y, &px, &py);
    357372            glVertex2f(px, py);
    358373        }
    359374        glEnd();
    360375    }
    361     iframe = iframe + 1;
     376    _iframe = _iframe + 1;
    362377
    363378    glEnable(GL_BLEND);
     
    366381
    367382    glEnable(GL_TEXTURE_2D);
    368     glCallList(iframe % Npat + disListID);
     383    glCallList(_iframe % _Npat + _disListID);
    369384    glBegin(GL_QUAD_STRIP);
    370385    {
    371         glTexCoord2f(0.0,  0.0);  glVertex2f(0.0, 0.0);
    372         glTexCoord2f(0.0,  tmax); glVertex2f(0.0, 1.0);
    373         glTexCoord2f(tmax, 0.0);  glVertex2f(1.0, 0.0);
    374         glTexCoord2f(tmax, tmax); glVertex2f(1.0, 1.0);
     386        glTexCoord2f(0.0,   0.0);   glVertex2f(0.0, 0.0);
     387        glTexCoord2f(0.0,   _tmax); glVertex2f(0.0, 1.0);
     388        glTexCoord2f(_tmax, 0.0);   glVertex2f(1.0, 0.0);
     389        glTexCoord2f(_tmax, _tmax); glVertex2f(1.0, 1.0);
    375390        glEnd();
    376391    }
     
    389404    */
    390405
    391     glDisable(GL_ALPHA_TEST);
    392 
    393406    glDisable(GL_BLEND);
    394407    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, NPIX, NPIX, 0);
     
    396409    /*
    397410    //blend magnitude texture
    398     glBindTexture(GL_TEXTURE_2D, mag_tex);
     411    glBindTexture(GL_TEXTURE_2D, _magTex);
    399412    glEnable(GL_TEXTURE_2D);
    400413    glEnable(GL_BLEND);
     
    407420    */
    408421
    409     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     422    glMatrixMode(GL_PROJECTION);
     423    glPopMatrix();
     424    glMatrixMode(GL_MODELVIEW);
     425    glPopMatrix();
     426
    410427    glPopAttrib();
     428
     429    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig);
     430}
     431
     432void
     433NvLIC::render()
     434{
     435    if (_vectorFieldId == 0) {
     436        return;
     437    }
     438
     439    //draw line integral convolution quad
     440
     441    glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
     442    glBindTexture(GL_TEXTURE_2D, _colorTex);
     443    glEnable(GL_TEXTURE_2D);
     444    //glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
     445    //glEnable(GL_LIGHTING);
     446    glDisable(GL_LIGHTING);
     447    glEnable(GL_DEPTH_TEST);
     448
     449    glMatrixMode(GL_MODELVIEW);
     450    glPushMatrix();
     451
     452    float w = 1.0f / _scale.x;
     453    glTranslatef(_origin.x, _origin.y, _origin.z);
     454    glScalef(1.0f, 1.0f / _scale.y / w, 1.0f / _scale.z / w);
     455
     456    glColor4f(1, 1, 1, 1);
     457    glBegin(GL_QUADS);
     458    switch (_axis) {
     459    case 0:
     460        glNormal3f(1, 0, 0);
     461        glTexCoord2f(0, 0); glVertex3f(_offset.x, 0, 0);
     462        glTexCoord2f(1, 0); glVertex3f(_offset.x, 1, 0);
     463        glTexCoord2f(1, 1); glVertex3f(_offset.x, 1, 1);
     464        glTexCoord2f(0, 1); glVertex3f(_offset.x, 0, 1);
     465        break;
     466    case 1:
     467        glNormal3f(0, 1, 0);
     468        glTexCoord2f(0, 0); glVertex3f(0, _offset.y, 0);
     469        glTexCoord2f(1, 0); glVertex3f(1, _offset.y, 0);
     470        glTexCoord2f(1, 1); glVertex3f(1, _offset.y, 1);
     471        glTexCoord2f(0, 1); glVertex3f(0, _offset.y, 1);
     472        break;
     473    case 2:
     474        glNormal3f(0, 0, 1);
     475        glTexCoord2f(0, 0); glVertex3f(0, 0, _offset.z);
     476        glTexCoord2f(1, 0); glVertex3f(1, 0, _offset.z);
     477        glTexCoord2f(1, 1); glVertex3f(1, 1, _offset.z);
     478        glTexCoord2f(0, 1); glVertex3f(0, 1, _offset.z);
     479        break;
     480    }
     481    glEnd();
     482
    411483    glPopMatrix();
    412     glMatrixMode(GL_PROJECTION);
    413     /*glPopMatrix();*/
    414     glMatrixMode(GL_MODELVIEW);
    415 }
    416 
    417 void NvLIC::render()
    418 {
    419     display();
    420 }
    421 
    422 void
    423 NvLIC::display()
    424 {
    425     if (_vectorFieldId == 0) {
    426         return;
    427     }
    428 
    429     glBindTexture(GL_TEXTURE_2D, color_tex);
    430     glEnable(GL_TEXTURE_2D);
    431 
    432     //draw line integral convolution quad
    433     glEnable(GL_DEPTH_TEST);
    434 
    435     glPushMatrix();
    436 
    437     float w = 1.0f / scale.x;
    438     glTranslatef(origin.x, origin.y, origin.z);
    439     glScalef(1.0f, 1.0f / scale.y / w, 1.0f / scale.z / w);
    440 
    441     glBegin(GL_QUADS);
    442     switch (axis) {
    443     case 0:
    444         glTexCoord2f(0, 0); glVertex3f(offset.x, 0, 0);
    445         glTexCoord2f(1, 0); glVertex3f(offset.x, 1, 0);
    446         glTexCoord2f(1, 1); glVertex3f(offset.x, 1, 1);
    447         glTexCoord2f(0, 1); glVertex3f(offset.x, 0, 1);
    448         break;
    449     case 1:
    450         glTexCoord2f(0, 0); glVertex3f(0, offset.y, 0);
    451         glTexCoord2f(1, 0); glVertex3f(1, offset.y, 0);
    452         glTexCoord2f(1, 1); glVertex3f(1, offset.y, 1);
    453         glTexCoord2f(0, 1); glVertex3f(0, offset.y, 1);
    454         break;
    455     case 2:
    456         glTexCoord2f(0, 0); glVertex3f(0, 0, offset.z);
    457         glTexCoord2f(1, 0); glVertex3f(1, 0, offset.z);
    458         glTexCoord2f(1, 1); glVertex3f(1, 1, offset.z);
    459         glTexCoord2f(0, 1); glVertex3f(0, 1, offset.z);
    460         break;
    461     }
    462     glEnd();
    463 
    464     glPopMatrix();
    465 
    466     glBindTexture(GL_TEXTURE_2D,0);
    467 
    468     glDisable(GL_DEPTH_TEST);
    469     glDisable(GL_TEXTURE_2D);
    470 }
    471 
    472 void
    473 NvLIC::setVectorField(unsigned int texID, const Vector3& ori,
    474                       float scaleX, float scaleY, float scaleZ, float max)
     484
     485    glBindTexture(GL_TEXTURE_2D, 0);
     486
     487    glPopAttrib();
     488}
     489
     490void
     491NvLIC::setVectorField(unsigned int texID, const Vector3& origin,
     492                      float scaleX, float scaleY, float scaleZ, float max)
    475493{
    476494    TRACE("NvLIC: vector field is assigned [%d]\n", texID);
    477495    _vectorFieldId = texID;
    478     origin = ori;
    479     scale = Vector3(scaleX, scaleY, scaleZ);
    480     this->max = max;
    481 
    482     make_patterns();
    483 
    484     get_slice();
    485 }
    486 
    487 void
    488 NvLIC::get_velocity(float x, float y, float *px, float *py)
     496    _origin = origin;
     497    _scale = Vector3(scaleX, scaleY, scaleZ);
     498    _max = max;
     499
     500    makePatterns();
     501
     502    getSlice();
     503}
     504
     505void
     506NvLIC::getVelocity(float x, float y, float *px, float *py)
    489507{
    490508   float vx, vy, r;
    491509
    492    int xi = (int)(x*size);
    493    int yi = (int)(y*size);
     510   int xi = (int)(x*_size);
     511   int yi = (int)(y*_size);
    494512
    495513    //TRACE("(xi yi) = (%d %d), ", xi, yi);
    496    vx = slice_vector[4 * (xi+yi*size)];
    497    vy = slice_vector[4 * (xi+yi*size)+1];
     514   vx = _sliceVector[4 * (xi+yi*_size)];
     515   vy = _sliceVector[4 * (xi+yi*_size)+1];
    498516   r  = vx*vx + vy*vy;
    499517
    500518    //TRACE("(vx vx) = (%f %f), r=%f, ", vx, vy, r);
    501    if (r > (dmax*dmax)) {
     519   if (r > (_dmax * _dmax)) {
    502520      r  = sqrt(r);
    503       vx *= dmax/r;
    504       vy *= dmax/r;
     521      vx *= _dmax/r;
     522      vy *= _dmax/r;
    505523   }
    506524
     
    512530
    513531void
    514 NvLIC::set_offset(float v)
    515 {
    516     switch (axis) {
    517     case 0 : offset.x = v; break;
    518     case 1 : offset.y = v; break;
    519     case 2 : offset.z = v; break;
    520     }
    521     get_slice();
    522 }
    523 
    524 void NvLIC::set_axis(int axis)
    525 {
    526     this->axis = axis;
     532NvLIC::setOffset(float v)
     533{
     534    switch (_axis) {
     535    case 0 : _offset.x = v; break;
     536    case 1 : _offset.y = v; break;
     537    case 2 : _offset.z = v; break;
     538    }
     539    getSlice();
     540}
     541
     542void NvLIC::setAxis(int axis)
     543{
     544    _axis = axis;
    527545}
    528546
    529547void NvLIC::reset()
    530548{
    531     make_patterns();
    532 }
     549    makePatterns();
     550}
  • trunk/packages/vizservers/nanovis/NvLIC.h

    r2870 r2920  
    1818
    1919#include <GL/glew.h>
    20 #include <Cg/cgGL.h>
     20#include <Cg/cg.h>
    2121
    2222#include "config.h"
     
    2626#include "Vector3.h"
    2727#include "Volume.h"
     28#include "NvShader.h"
    2829
    2930class NvLIC : public Renderable
    3031{
    3132public:
    32     NvLIC(int _size, int _width, int _height, int axis,
    33           const Vector3& _offset, CGcontext _context);
     33    NvLIC(int size, int width, int height, int axis,
     34          const Vector3& offset);
    3435    ~NvLIC();
    3536
     
    3839
    3940    /// Display the convolution result
    40     void display();
    41 
    4241    void render();
    4342
    44     void make_patterns();
     43    void makePatterns();
    4544
    46     void make_magnitudes();
     45    void makeMagnitudes();
    4746
    48     void get_velocity(float x, float y, float *px, float *py);
     47    void getVelocity(float x, float y, float *px, float *py);
    4948
    50     void get_slice();
     49    void getSlice();
    5150
    52     void set_offset(float v);
     51    void setOffset(float v);
    5352
    5453    /**
    55      * @brief Specify the perdicular axis
     54     * @brief Specify the perpendicular axis
    5655     *
    5756     * 0 : x axis<br>
     
    5958     * 2 : z axis<br>
    6059     */
    61     void set_axis(int axis);
     60    void setAxis(int axis);
    6261
    63     void setVectorField(unsigned int texID, const Vector3& ori,
     62    void setVectorField(unsigned int texID, const Vector3& origin,
    6463                        float scaleX, float scaleY, float scaleZ, float max);
    6564
     
    9190     * the inherited Vector3 location is its center
    9291     */
    93     Vector3 normal;
     92    Vector3 _normal;
    9493
    95     GLuint disListID;
    96 
    97     int width, height;
    98     int size;                           // The lic is a square of size, it can
     94    int _width, _height;
     95    int _size;                          // The lic is a square of size, it can
    9996                                        // be stretched
    100     float *slice_vector;                // Storage for the per slice vectors
     97    float *_sliceVector;                // Storage for the per slice vectors
    10198                                        // driving the follow.
    102     Vector3 scale;                      // Scaling factor stretching the lic
     99    Vector3 _scale;                     // Scaling factor stretching the lic
    103100                                        // plane to fit the actual dimensions
    104     Vector3 origin;
    105     Vector3 offset;                     // [0,1] offset could be x, y, or z
     101    Vector3 _origin;
     102    Vector3 _offset;                    // [0,1] offset could be x, y, or z
    106103                                        // direction
    107     int axis;
     104    int _axis;
    108105
    109106    //some convolve variables. They can pretty much stay fixed
    110     int iframe;
    111     int Npat;
    112     int alpha;
    113     float sa;
    114     float tmax;
    115     float dmax;
    116     float max;
     107    int _iframe;
     108    int _Npat;
     109    int _alpha;
     110    float _sa;
     111    float _tmax;
     112    float _dmax;
     113    float _max;
    117114
     115    GLuint _disListID;
     116
     117    NvShader *_renderVelShader;
    118118    //CG shader parameters
    119     CGcontext _cgContext;
    120     CGparameter _vel_tex_param;
    121     CGparameter _vel_tex_param_render_vel;
    122     CGparameter _plane_normal_param_render_vel;
    123     CGprogram _render_vel_fprog;
    124     CGparameter _max_param;
     119    CGparameter _velTexParam;
     120    CGparameter _velTexParamRenderVel;
     121    CGparameter _planeNormalParamRenderVel;
     122    CGparameter _maxParam;
    125123 
    126     GLuint color_tex, pattern_tex, mag_tex;
    127     GLuint fbo, vel_fbo, slice_vector_tex;  // For projecting 3d vector to 2d
     124    GLuint _colorTex, _patternTex, _magTex;
     125    GLuint _fbo, _velFbo, _sliceVectorTex;  // For projecting 3d vector to 2d
    128126                                            // vector on a plane.
    129127    GLuint _vectorFieldId;
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r2885 r2920  
    712712{
    713713    flowVisRenderer->initialize();
    714     licRenderer->make_patterns();
     714    licRenderer->makePatterns();
    715715}
    716716
     
    795795
    796796    licRenderer = new NvLIC(NMESH, NPIX, NPIX, _licAxis,
    797                             Vector3(_licSliceX, _licSliceY, _licSliceZ),
    798                             NvShader::getCgContext());
     797                            Vector3(_licSliceX, _licSliceY, _licSliceZ));
    799798
    800799    grid = new Grid();
Note: See TracChangeset for help on using the changeset viewer.