Changeset 2956


Ignore:
Timestamp:
Apr 9, 2012, 11:13:08 PM (8 years ago)
Author:
ldelgass
Message:

First batch of converting shaders to use new parameter support in NvShader?.

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

Legend:

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

    r2953 r2956  
    11 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 
    32#include <GL/glew.h>
    4 #include <Cg/cgGL.h>
    53
    64#include "Grid.h"
     
    1816HeightMap::HeightMap() :
    1917    _vertexBufferObjectID(0),
    20     _textureBufferObjectID(0),
     18    _texcoordBufferObjectID(0),
    2119    _vertexCount(0),
    2220    _contour(0),
     
    3634    _shader = new NvShader();
    3735    _shader->loadFragmentProgram("heightcolor.cg", "main");
    38     _tfParam      = _shader->getNamedParameterFromFP("tf");
    39     _opacityParam = _shader->getNamedParameterFromFP("opacity");
    4036}
    4137
     
    4440    reset();
    4541
    46     if (_shader) {
     42    if (_shader != NULL) {
    4743        delete _shader;
    4844    }
     
    9692            //
    9793            _shader->bind();
    98  
    99             cgGLSetTextureParameter(_tfParam, _tfPtr->id());
    100             cgGLEnableTextureParameter(_tfParam);
    101             cgGLSetParameter1f(_opacityParam, _opacity);
     94            _shader->setFPTextureParameter("tf", _tfPtr->id());
     95            _shader->setFPParameter1f("opacity", _opacity);
    10296
    10397            glEnable(GL_TEXTURE_1D);
     
    110104        glVertexPointer(3, GL_FLOAT, 12, 0);
    111105
    112         glBindBuffer(GL_ARRAY_BUFFER, _textureBufferObjectID);
     106        glBindBuffer(GL_ARRAY_BUFFER, _texcoordBufferObjectID);
    113107        glTexCoordPointer(3, GL_FLOAT, 12, 0);
    114108
     
    129123            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    130124
     125            _shader->disableFPTextureParameter("tf");
    131126            _shader->unbind();
    132127        }
     
    238233        _vertexBufferObjectID = 0;
    239234    }
    240     if (_textureBufferObjectID) {
    241         glDeleteBuffers(1, &_textureBufferObjectID);
    242         _textureBufferObjectID = 0;
     235    if (_texcoordBufferObjectID) {
     236        glDeleteBuffers(1, &_texcoordBufferObjectID);
     237        _texcoordBufferObjectID = 0;
    243238    }
    244239    if (_contour != NULL) {
     
    251246    }
    252247}
    253 
     248#if 0
    254249void
    255250HeightMap::setHeight(int xCount, int yCount, Vector3 *heights)
     
    293288    glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof( Vector3 ), heights,
    294289        GL_STATIC_DRAW);
    295     glGenBuffers(1, &_textureBufferObjectID);
    296     glBindBuffer(GL_ARRAY_BUFFER, _textureBufferObjectID);
     290    glGenBuffers(1, &_texcoordBufferObjectID);
     291    glBindBuffer(GL_ARRAY_BUFFER, _texcoordBufferObjectID);
    297292    glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord,
    298293        GL_STATIC_DRAW);
     
    324319    //}
    325320}
    326 
     321#endif
    327322void
    328323HeightMap::setHeight(float xMin, float yMin, float xMax, float yMax,
     
    385380    glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(Vector3), map,
    386381        GL_STATIC_DRAW);
    387     glGenBuffers(1, &_textureBufferObjectID);
    388     glBindBuffer(GL_ARRAY_BUFFER, _textureBufferObjectID);
     382    glGenBuffers(1, &_texcoordBufferObjectID);
     383    glBindBuffer(GL_ARRAY_BUFFER, _texcoordBufferObjectID);
    389384    glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord,
    390385        GL_STATIC_DRAW);
     
    485480    glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(Vector3), vertices,
    486481        GL_STATIC_DRAW);
    487     glGenBuffers(1, &_textureBufferObjectID);
    488     glBindBuffer(GL_ARRAY_BUFFER, _textureBufferObjectID);
     482    glGenBuffers(1, &_texcoordBufferObjectID);
     483    glBindBuffer(GL_ARRAY_BUFFER, _texcoordBufferObjectID);
    489484    glBufferData(GL_ARRAY_BUFFER, _vertexCount * sizeof(float) * 3, texcoord,
    490485        GL_STATIC_DRAW);
     
    569564        if (_tfPtr != NULL) {
    570565            _shader->bind();
    571            
    572             cgGLSetTextureParameter(_tfParam, _tfPtr->id());
    573             cgGLEnableTextureParameter(_tfParam);
     566
     567            _shader->setFPTextureParameter("tf", _tfPtr->id());
    574568
    575569            glEnable(GL_TEXTURE_1D);
     
    584578        glVertexPointer(3, GL_FLOAT, 12, 0);
    585579
    586         glBindBuffer(GL_ARRAY_BUFFER, _textureBufferObjectID);
     580        glBindBuffer(GL_ARRAY_BUFFER, _texcoordBufferObjectID);
    587581        glTexCoordPointer(3, GL_FLOAT, 12, 0);
    588582
     
    603597            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    604598
     599            _shader->disableFPTextureParameter("tf");
    605600            _shader->unbind();
    606601        }
  • trunk/packages/vizservers/nanovis/HeightMap.h

    r2953 r2956  
    22#ifndef HEIGHTMAP_H
    33#define HEIGHTMAP_H
    4 
    5 #include <Cg/cg.h>
    64
    75#include <R2/graphics/R2Geometry.h>
     
    4644    void setHeight(float startX, float startY, float endX, float endY,
    4745                   int xCount, int yCount, float *height);
    48 
     46#if 0
    4947    /**
    5048     *@brief Create a height map with a set of points
     
    5351     */
    5452    void setHeight(int xCount, int yCount, Vector3 *heights);
    55 
     53#endif
    5654    void mapToGrid(Grid *gridPtr);
    5755
     
    133131
    134132    unsigned int _vertexBufferObjectID;
    135     unsigned int _textureBufferObjectID;
     133    unsigned int _texcoordBufferObjectID;
    136134    int _vertexCount;
    137     CGparameter _tfParam;
    138     CGparameter _opacityParam;
    139135    R2Geometry *_contour;
    140136    R2Geometry *_topContour;
  • trunk/packages/vizservers/nanovis/NvColorTableShader.cpp

    r2953 r2956  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 
    3 #include <GL/glew.h>
    4 #include <Cg/cgGL.h>
    5 
    62#include "NvColorTableShader.h"
    7 #include "Trace.h"
    83
    94NvColorTableShader::NvColorTableShader()
     
    1914{
    2015    loadFragmentProgram("one_plane.cg", "main");
    21     _dataParam = getNamedParameterFromFP("data");
    22     _tfParam = getNamedParameterFromFP("tf");
    23     _renderParam = getNamedParameterFromFP("render_param");
    2416}
    2517
    2618void NvColorTableShader::bind(Texture2D *plane, TransferFunction *tf)
    2719{
    28     cgGLSetTextureParameter(_dataParam, plane->id());
    29     cgGLSetTextureParameter(_tfParam, tf->id());
    30     cgGLEnableTextureParameter(_dataParam);
    31     cgGLEnableTextureParameter(_tfParam);
    32     cgGLSetParameter4f(_renderParam, 0., 0., 0., 0.);
     20    setFPTextureParameter("data", plane->id());
     21    setFPTextureParameter("tf", tf->id());
     22
     23    setFPParameter4f("render_param", 0., 0., 0., 0.);
    3324
    3425    NvShader::bind();
     
    3728void NvColorTableShader::unbind()
    3829{
    39     cgGLDisableTextureParameter(_dataParam);
    40     cgGLDisableTextureParameter(_tfParam);
     30    disableFPTextureParameter("data");
     31    disableFPTextureParameter("tf");
    4132
    4233    NvShader::unbind();
  • trunk/packages/vizservers/nanovis/NvColorTableShader.h

    r2914 r2956  
    22#ifndef NV_COLORTABLE_SHADER_H
    33#define NV_COLORTABLE_SHADER_H
    4 
    5 #include <Cg/cg.h>
    64
    75#include "NvShader.h"
     
    2220private :
    2321    void init();
    24 
    25     CGparameter _dataParam;
    26     CGparameter _tfParam;
    27     CGparameter _renderParam;
    2822};
    2923
  • trunk/packages/vizservers/nanovis/NvParticleAdvectionShader.cpp

    r2953 r2956  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 
    3 #include <GL/glew.h>
    4 #include <Cg/cgGL.h>
    5 
    62#include "NvParticleAdvectionShader.h"
    7 #include "Trace.h"
    83
    94NvParticleAdvectionShader::NvParticleAdvectionShader() :
     
    2419{
    2520    loadFragmentProgram("update_pos.cg", "main");
    26     _posTexParam       = getNamedParameterFromFP("pos_tex");
    27     _initPosTexParam   = getNamedParameterFromFP("init_pos_tex");
    28     _velTexParam       = getNamedParameterFromFP("vel_tex");
    29     _posTimestepParam  = getNamedParameterFromFP("timestep");
    30     _maxParam          = getNamedParameterFromFP("max");
    31     _modeParam         = getNamedParameterFromFP("mode");
    32     _scaleParam        = getNamedParameterFromFP("scale");
    3321}
    3422
     
    3624NvParticleAdvectionShader::bind(unsigned int texID, unsigned int initPosTexID)
    3725{
    38     cgGLSetTextureParameter(_posTexParam, texID);
    39     cgGLEnableTextureParameter(_posTexParam);
     26    setFPTextureParameter("pos_tex", texID);
     27    setFPTextureParameter("init_pos_tex", initPosTexID);
     28    setFPTextureParameter("vel_tex", _velocityVolumeID);
    4029
    41     cgGLSetTextureParameter(_initPosTexParam, initPosTexID);
    42     cgGLEnableTextureParameter(_initPosTexParam);
    43 
    44     cgGLSetTextureParameter(_velTexParam, _velocityVolumeID);
    45     cgGLEnableTextureParameter(_velTexParam);
    46 
    47     cgGLSetParameter1f(_posTimestepParam, _timeStep);
    48     cgGLSetParameter1f(_maxParam, _max);
    49     cgGLSetParameter1f(_modeParam, _mode);
    50     cgGLSetParameter3f(_scaleParam, _scale.x, _scale.y, _scale.z);
     30    setFPParameter1f("timestep", _timeStep);
     31    setFPParameter1f("max", _max);
     32    setFPParameter1f("mode", _mode);
     33    setFPParameter3f("scale", _scale.x, _scale.y, _scale.z);
    5134
    5235    NvShader::bind();
     
    5639NvParticleAdvectionShader::unbind()
    5740{
    58      cgGLDisableTextureParameter(_posTexParam);
    59      cgGLDisableTextureParameter(_initPosTexParam);
    60      cgGLDisableTextureParameter(_velTexParam);
     41     disableFPTextureParameter("pos_tex");
     42     disableFPTextureParameter("init_pos_tex");
     43     disableFPTextureParameter("vel_tex");
    6144
    6245     NvShader::unbind();
  • trunk/packages/vizservers/nanovis/NvParticleAdvectionShader.h

    r2953 r2956  
    4444    void init();
    4545
    46     CGparameter _posTexParam;
    47     CGparameter _initPosTexParam;
    48     CGparameter _velTexParam;
    49     CGparameter _posTimestepParam;
    50     CGparameter _maxParam;
    51     CGparameter _modeParam;
    52     CGparameter _scaleParam;
    53 
    5446    unsigned int _velocityVolumeID;
    5547    Vector3 _scale;
  • trunk/packages/vizservers/nanovis/NvParticleRenderer.cpp

    r2953 r2956  
    8888                              GL_TEXTURE_RECTANGLE_ARB, _psysTex[0], 0);
    8989
     90    CHECK_FRAMEBUFFER_STATUS();
    9091
    9192    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _psysFbo[1]);
     
    104105                              GL_TEXTURE_RECTANGLE_ARB, _psysTex[1], 0);
    105106 
     107    CHECK_FRAMEBUFFER_STATUS();
     108
    106109    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig);
    107110
     
    117120                 _psysWidth, _psysHeight, 0, GL_RGBA, GL_FLOAT, NULL);
    118121#endif
    119 
    120     CHECK_FRAMEBUFFER_STATUS();
    121122
    122123    if (_advectionShader == NULL) {
     
    312313}
    313314
    314 void
    315 NvParticleRenderer::drawBoundingBox(float x0, float y0, float z0,
    316                                     float x1, float y1, float z1,
    317                                     float r, float g, float b,
    318                                     float line_width)
    319 {
    320     glPushAttrib(GL_ENABLE_BIT);
    321 
    322     glEnable(GL_DEPTH_TEST);
    323     glDisable(GL_TEXTURE_2D);
    324     glEnable(GL_BLEND);
    325 
    326     glColor4d(r, g, b, 1.0);
    327     glLineWidth(line_width);
    328 
    329     glBegin(GL_LINE_LOOP);
    330     {
    331         glVertex3d(x0, y0, z0);
    332         glVertex3d(x1, y0, z0);
    333         glVertex3d(x1, y1, z0);
    334         glVertex3d(x0, y1, z0);
    335     }
    336     glEnd();
    337 
    338     glBegin(GL_LINE_LOOP);
    339     {
    340         glVertex3d(x0, y0, z1);
    341         glVertex3d(x1, y0, z1);
    342         glVertex3d(x1, y1, z1);
    343         glVertex3d(x0, y1, z1);
    344     }
    345     glEnd();
    346 
    347     glBegin(GL_LINE_LOOP);
    348     {
    349         glVertex3d(x0, y0, z0);
    350         glVertex3d(x0, y0, z1);
    351         glVertex3d(x0, y1, z1);
    352         glVertex3d(x0, y1, z0);
    353     }
    354     glEnd();
    355 
    356     glBegin(GL_LINE_LOOP);
    357     {
    358         glVertex3d(x1, y0, z0);
    359         glVertex3d(x1, y0, z1);
    360         glVertex3d(x1, y1, z1);
    361         glVertex3d(x1, y1, z0);
    362     }
    363     glEnd();
    364 
    365     glPopAttrib();
    366 }
    367 
    368315void
    369316NvParticleRenderer::render()
     
    382329    glScaled(_scale.x, _scale.y, _scale.z);
    383330
    384     // TBD...
    385     /*
    386       drawBoundingBox(0, 0, 0,
    387       1, 1, 1,
    388       1, 1, 1, 2);
    389 
    390       drawBoundingBox(0, 0.5f / 4.5f, 0.5f / 4.5,
    391       1, 4.0f / 4.5f, 4.0f / 4.5,
    392       1, 0, 0, 2);
    393 
    394       drawBoundingBox(1/3.0f, 1.0f / 4.5f, 0.5f / 4.5,
    395       2/3.0f, 3.5f / 4.5f, 3.5f / 4.5,
    396       1, 1, 0, 2);
    397     */
    398 
    399331    glPointSize(_particleSize);
    400332    glColor4f(_color.x, _color.y, _color.z, _color.w);
     333
    401334    glEnableClientState(GL_VERTEX_ARRAY);
    402335    _vertexArray->setPointer(0);
     
    405338
    406339    glPopMatrix();
    407 
    408340    glPopAttrib();
    409 
    410     //assert(glGetError()==0);
    411341}
    412342
  • trunk/packages/vizservers/nanovis/NvParticleRenderer.h

    r2953 r2956  
    1616#ifndef NVPARTICLERENDERER_H
    1717#define NVPARTICLERENDERER_H
    18 
    19 #include <vector>
    20 
    21 #include <GL/glew.h>
    22 #include <Cg/cgGL.h>
    2318
    2419#include "Renderable.h"
     
    8176    void setPos(float pos);
    8277
    83     void drawBoundingBox(float x0, float y0, float z0,
    84                          float x1, float y1, float z1,
    85                          float r, float g, float b, float line_width);
    86 
    8778    void initializeDataArray();
    8879
  • trunk/packages/vizservers/nanovis/NvStdVertexShader.cpp

    r2953 r2956  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 
    3 #include <GL/glew.h>
    4 #include <Cg/cgGL.h>
    5 
    62#include "NvStdVertexShader.h"
    73
     
    1814{
    1915    loadVertexProgram("vertex_std.cg", "main");
    20     _mvpVertStdParam = getNamedParameterFromVP("modelViewProjMatrix");
    21     _mviVertStdParam = getNamedParameterFromVP("modelViewInv");
    2216}
    2317
    2418void NvStdVertexShader::bind()
    2519{
    26     cgGLSetStateMatrixParameter(_mvpVertStdParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
    27     cgGLSetStateMatrixParameter(_mviVertStdParam, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE);
     20    setGLStateMatrixVPParameter("modelViewProjMatrix", MODELVIEW_PROJECTION_MATRIX, MATRIX_IDENTITY);
     21    setGLStateMatrixVPParameter("modelViewInv", MODELVIEW_MATRIX, MATRIX_INVERSE);
    2822
    2923    NvShader::bind();
  • trunk/packages/vizservers/nanovis/NvStdVertexShader.h

    r2914 r2956  
    2121private:
    2222    void init();
    23 
    24     /// A parameter id for ModelViewProjection matrix of Cg program
    25     CGparameter _mvpVertStdParam;
    26 
    27     /// A parameter id for ModelViewInverse matrix of Cg program
    28     CGparameter _mviVertStdParam;
    2923};
    3024
  • trunk/packages/vizservers/nanovis/PointShader.cpp

    r2953 r2956  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 
    3 #include <GL/glew.h>
    4 #include <Cg/cgGL.h>
    5 
    62#include "PointShader.h"
    73
     
    128{
    139    loadVertexProgram("pointsvp.cg", "main");
    14     _modelviewVP  = getNamedParameterFromVP("modelview");
    15     _projectionVP = getNamedParameterFromVP("projection");
    16     _attenVP      = getNamedParameterFromVP("atten");
    17     _posoffsetVP  = getNamedParameterFromVP("posoffset");
    18     _baseposVP    = getNamedParameterFromVP("basepos");
    19     _scaleVP      = getNamedParameterFromVP("scale");
    20     _normalParam  = getNamedParameterFromVP("normal");
    2110}
    2211
     
    2716void PointShader::bind()
    2817{
    29     cgGLSetStateMatrixParameter(_modelviewVP, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);
    30     cgGLSetStateMatrixParameter(_projectionVP, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
     18    setGLStateMatrixVPParameter("modelview", MODELVIEW_MATRIX, MATRIX_IDENTITY);
     19    setGLStateMatrixVPParameter("projection", PROJECTION_MATRIX, MATRIX_IDENTITY);
    3120
    32     cgGLSetParameter1f(_attenVP, 1.0f);
    33     cgGLSetParameter4f(_posoffsetVP, 1.0f, 1.0f, 1.0f, 1.0f);
    34     cgGLSetParameter4f(_baseposVP, 1.0f, 1.0f, 1.0f, 1.0f);
    35     cgGLSetParameter4f(_scaleVP, _scale, 1.0f, 1.0f, 1.0f);
    36 
    37     //cgGLSetTextureParameter(_normalParam, _normal->getGraphicsObjectID());
    38     //cgGLEnableTextureParameter(_normalParam);
     21    setVPParameter1f("atten", 1.0f);
     22    setVPParameter4f("posoffset", 1.0f, 1.0f, 1.0f, 1.0f);
     23    setVPParameter4f("basepos", 1.0f, 1.0f, 1.0f, 1.0f);
     24    setVPParameter4f("scale", _scale, 1.0f, 1.0f, 1.0f);
     25    //setVPTextureParameter("normal", _normal->getGraphicsObjectID());
    3926
    4027    NvShader::bind();
     
    4330void PointShader::unbind()
    4431{
    45     //cgGLDisableTextureParameter(_normalParam);
     32    //disableVPTextureParameter("normal");
    4633
    4734    NvShader::unbind();
  • trunk/packages/vizservers/nanovis/PointShader.h

    r2953 r2956  
    2525    virtual void bind();
    2626
    27     virtual  void unbind();
     27    virtual void unbind();
    2828
    2929private:
    30     CGparameter _modelviewVP;
    31     CGparameter _projectionVP;
    32 
    33     CGparameter _attenVP;
    34     CGparameter _posoffsetVP;
    35     CGparameter _baseposVP;
    36     CGparameter _scaleVP;
    37     CGparameter _normalParam;
    38 
     30    float _scale;
    3931    float _scale;
    4032    Texture3D *_normal;
  • trunk/packages/vizservers/nanovis/shaders/update_pos.cg

    r2916 r2956  
    4949
    5050    //reconstruct negative value
    51     float4 vel = float4(tex3D(vel_tex, pos.xyz).yzw, 0) - float4(0.5, 0.5, 0.5, 0.0f);
    52     vel = vel * (2 * max);
     51    float4 vel = float4(tex3D(vel_tex, pos.xyz).yzw, 0.0) * 2.0 - float4(1.0, 1.0, 1.0, 0.0f);
     52    vel = vel * max;
    5353    //vel *= float4(scale, 1);
    5454    ret = pos + (vel * timestep);
Note: See TracChangeset for help on using the changeset viewer.