Changeset 2930 for trunk/packages


Ignore:
Timestamp:
Apr 2, 2012 9:14:15 AM (12 years ago)
Author:
ldelgass
Message:

Rename offscreenBufferCapture to bindOffscreenBuffer. Fix more GL state leaks.
Require OpenGL 2.1 as a minimum. Style changes for PlaneRenderer? and rework
plane commands.

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

Legend:

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

    r2929 r2930  
    191191}
    192192
    193 /*
    194  * -----------------------------------------------------------------------
     193/**
     194 * Creates a heightmap from the given the data. The format of the data
     195 * should be as follows:
    195196 *
    196  * CreateHeightMap --
     197 *     xMin, xMax, xNum, yMin, yMax, yNum, heights...
    197198 *
    198  *      Creates a heightmap from the given the data. The format of the data
    199  *      should be as follows:
    200  *
    201  *              xMin, xMax, xNum, yMin, yMax, yNum, heights...
    202  *
    203  *      xNum and yNum must be integer values, all others are real numbers.
    204  *      The number of heights must be xNum * yNum;
    205  *
    206  * -----------------------------------------------------------------------
     199 * xNum and yNum must be integer values, all others are real numbers.
     200 * The number of heights must be xNum * yNum;
    207201 */
    208202static HeightMap *
     
    266260}
    267261
    268 /*
    269  * ----------------------------------------------------------------------
    270  *
    271  * GetHeightMapFromObj --
    272  *
    273  * ----------------------------------------------------------------------
    274  */
    275262static int
    276263GetHeightMapFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, HeightMap **hmPtrPtr)
     
    293280
    294281
    295 /*
    296  * ----------------------------------------------------------------------
    297  * FUNCTION: GetVolumeFromObj
    298  *
     282/**
    299283 * Used internally to decode a series of volume index values and
    300284 * store then in the specified vector.  If there are no volume index
     
    304288 * Updates pushes index values into the vector.  Returns TCL_OK or
    305289 * TCL_ERROR to indicate an error.
    306  * ----------------------------------------------------------------------
    307290 */
    308291static int
     
    325308}
    326309
    327 /*
    328  * ----------------------------------------------------------------------
    329  * FUNCTION: GetVolumes()
    330  *
     310/**
    331311 * Used internally to decode a series of volume index values and
    332312 * store then in the specified vector.  If there are no volume index
     
    336316 * Updates pushes index values into the vector.  Returns TCL_OK or
    337317 * TCL_ERROR to indicate an error.
    338  * ----------------------------------------------------------------------
    339318 */
    340319static int
     
    366345}
    367346
    368 /*
    369  * ----------------------------------------------------------------------
    370  * FUNCTION: GetHeightMaps()
    371  *
     347/**
    372348 * Used internally to decode a series of volume index values and
    373349 * store then in the specified vector.  If there are no volume index
     
    377353 * Updates pushes index values into the vector.  Returns TCL_OK or
    378354 * TCL_ERROR to indicate an error.
    379  * ----------------------------------------------------------------------
    380355 */
    381356static int
     
    406381}
    407382
    408 
    409 /*
    410  * ----------------------------------------------------------------------
    411  * FUNCTION: GetAxis()
    412  *
     383/**
    413384 * Used internally to decode an axis value from a string ("x", "y",
    414385 * or "z") to its index (0, 1, or 2).  Returns TCL_OK if successful,
    415386 * along with a value in valPtr.  Otherwise, it returns TCL_ERROR
    416387 * and an error message in the interpreter.
    417  * ----------------------------------------------------------------------
    418388 */
    419389static int
     
    441411}
    442412
    443 /*
    444  * ----------------------------------------------------------------------
    445  * FUNCTION: GetAxisFromObj()
    446  *
     413/**
    447414 * Used internally to decode an axis value from a string ("x", "y",
    448415 * or "z") to its index (0, 1, or 2).  Returns TCL_OK if successful,
    449416 * along with a value in indexPtr.  Otherwise, it returns TCL_ERROR
    450417 * and an error message in the interpreter.
    451  * ----------------------------------------------------------------------
    452418 */
    453419int
     
    457423}
    458424
    459 /*
    460  * ----------------------------------------------------------------------
    461  * FUNCTION: GetAxisDirFromObj()
    462  *
     425/**
    463426 * Used internally to decode an axis value from a string ("x", "y",
    464427 * or "z") to its index (0, 1, or 2).  Returns TCL_OK if successful,
    465428 * along with a value in indexPtr.  Otherwise, it returns TCL_ERROR
    466429 * and an error message in the interpreter.
    467  * ----------------------------------------------------------------------
    468430 */
    469431static int
     
    486448}
    487449
    488 /*
    489  * ----------------------------------------------------------------------
    490  * FUNCTION: GetColor()
    491  *
     450/**
    492451 * Used internally to decode a color value from a string ("R G B")
    493452 * as a list of three numbers 0-1.  Returns TCL_OK if successful,
    494453 * along with RGB values in rgbPtr.  Otherwise, it returns TCL_ERROR
    495454 * and an error message in the interpreter.
    496  * ----------------------------------------------------------------------
    497455 */
    498456static int
     
    513471
    514472
    515 /*
    516  * -----------------------------------------------------------------------
    517  *
    518  * GetDataStream --
    519  *
    520  *      Read the requested number of bytes from standard input into the given
    521  *      buffer.  The buffer is then decompressed and decoded.
    522  *
    523  * -----------------------------------------------------------------------
     473/**
     474 * Read the requested number of bytes from standard input into the given
     475 * buffer.  The buffer is then decompressed and decoded.
    524476 */
    525477int
     
    576528}
    577529
    578 
    579530static int
    580531CameraAimOp(ClientData clientData, Tcl_Interp *interp, int objc,
     
    691642
    692643    w = NanoVis::winWidth, h = NanoVis::winHeight;
     644
    693645    NanoVis::resizeOffscreenBuffer(2048, 2048);
    694646#ifdef notdef
     
    696648    NanoVis::cam->setScreenSize(30, 90, 2048 - 60, 2048 - 120);
    697649#endif
    698     NanoVis::offscreenBufferCapture();  //enable offscreen render
     650    NanoVis::bindOffscreenBuffer();  //enable offscreen render
    699651    NanoVis::display();
    700652    NanoVis::readScreen();
    701 #ifdef notdef
    702     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    703 #endif
     653
    704654    NanoVis::ppmWrite("nv>image -bytes %d -type print");
    705655    NanoVis::resizeOffscreenBuffer(w, h);
     656
    706657    return TCL_OK;
    707658}
     
    1015966}
    1016967
    1017 
    1018968static int
    1019969VolumeAnimationCaptureOp(ClientData clientData, Tcl_Interp *interp, int objc,
     
    1037987            interpolator->update(fraction);
    1038988
    1039             NanoVis::offscreenBufferCapture();  //enable offscreen render
     989            int fboOrig;
     990            glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fboOrig);
     991
     992            NanoVis::bindOffscreenBuffer();  //enable offscreen render
    1040993
    1041994            NanoVis::display();
    1042995            NanoVis::readScreen();
    1043996
    1044             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     997            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig);
    1045998
    1046999            NanoVis::bmpWriteToFile(frame_num, fileName);
     
    11171070    return (*proc) (clientData, interp, objc, objv);
    11181071}
    1119 
    11201072
    11211073static int
     
    21692121#if PLANE_CMD
    21702122static int
    2171 PlaneNewOp(ClientData clientData, Tcl_Interp *interp, int objc,
     2123PlaneAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
    21722124           Tcl_Obj *const *objv)
    21732125{
     
    21812133    }
    21822134    if (Tcl_GetIntFromObj(interp, objv[1], &index) != TCL_OK) {
     2135        return TCL_ERROR;
     2136    }
     2137    if (index >= NanoVis::numPlanes) {
     2138        Tcl_AppendResult(interp, "Invalid plane_index", (char*)NULL);
    21832139        return TCL_ERROR;
    21842140    }
     
    21982154    }
    21992155    bzero(tmp, w*h*4);
    2200     int status = read(0, tmp, w*h*sizeof(float));
     2156    int status = read(fileno(NanoVis::stdin), tmp, w*h*sizeof(float));
    22012157    if (status <= 0) {
    2202         exit(0);                // Bail out on read error?  Should log the
    2203                                 // error and return a non-zero exit status.
     2158        delete[] tmp;
     2159        Tcl_AppendResult(interp, "Failed to read image data for plane", (char*)NULL);
     2160        return TCL_ERROR;
    22042161    }
    22052162    NanoVis::plane[index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp);
     
    22142171    TRACE("link the plane to the 2D renderer command\n");
    22152172
    2216     int plane_index, tf_index;
     2173    int plane_index;
    22172174
    22182175    if (objc != 3) {
    22192176        Tcl_AppendResult(interp, "wrong # args: should be \"",
    2220             Tcl_GetString(objv[0]), " plane_index tf_index \"", (char*)NULL);
     2177            Tcl_GetString(objv[0]), " plane_index transfunc_name \"", (char*)NULL);
    22212178        return TCL_ERROR;
    22222179    }
     
    22242181        return TCL_ERROR;
    22252182    }
    2226     if (Tcl_GetIntFromObj(interp, objv[2], &tf_index) != TCL_OK) {
    2227         return TCL_ERROR;
    2228     }
    2229     //NanoVis::plane_renderer->add_plane(NanoVis::plane[plane_index], tf[tf_index]);
     2183    if (plane_index >= NanoVis::numPlanes) {
     2184        Tcl_AppendResult(interp, "Invalid plane_index", (char*)NULL);
     2185        return TCL_ERROR;
     2186    }
     2187    NanoVis::planeRenderer->addPlane(NanoVis::plane[plane_index],
     2188                                     NanoVis::getTransfunc(Tcl_GetString(objv[2])));
    22302189    return TCL_OK;
    22312190}
     
    22482207        return TCL_ERROR;
    22492208    }
    2250     int mode;
    2251     if (Tcl_GetIntFromObj(interp, objv[2], &mode) != TCL_OK) {
    2252         return TCL_ERROR;
    2253     }
    2254     if (mode == 0) {
     2209    if (plane_index >= NanoVis::numPlanes) {
     2210        Tcl_AppendResult(interp, "Invalid plane_index", (char*)NULL);
     2211        return TCL_ERROR;
     2212    } else if (plane_index < 0) {
    22552213        plane_index = -1;
    22562214    }
    2257     NanoVis::plane_renderer->set_active_plane(plane_index);
     2215
     2216    NanoVis::planeRenderer->setActivePlane(plane_index);
    22582217    return TCL_OK;
    22592218}
    22602219
    22612220static Rappture::CmdSpec planeOps[] = {
    2262     {"enable",     1, PlaneEnableOp,    4, 4, "planeIdx mode",},
     2221    {"active",     1, PlaneEnableOp,    3, 3, "planeIdx",},
     2222    {"add",        1, PlaneAddOp,       5, 5, "planeIdx width height",},
    22632223    {"link",       1, PlaneLinkOp,      4, 4, "planeIdx transfuncIdx",},
    2264     {"new",        1, PlaneNewOp,       5, 5, "planeIdx width height",},
    22652224};
    22662225static int nPlaneOps = NumCmdSpecs(planeOps);
  • trunk/packages/vizservers/nanovis/FlowCmd.cpp

    r2922 r2930  
    190190{
    191191    TRACE("Rendering box %s\n", _name);
    192     glColor4d(_sv.color.r, _sv.color.g, _sv.color.b, _sv.color.a);
    193 
    194     glPushMatrix();
     192
     193    glPushAttrib(GL_ENABLE_BIT);
    195194
    196195    glEnable(GL_DEPTH_TEST);
    197196    glDisable(GL_TEXTURE_2D);
    198     glEnable(GL_BLEND);
    199 
     197    glDisable(GL_BLEND);
     198    //glEnable(GL_BLEND);
     199
     200    glMatrixMode(GL_MODELVIEW);
    200201    glPushMatrix();
     202
    201203    Vector3 origin = volPtr->location();
    202204    glTranslatef(origin.x, origin.y, origin.z);
     
    239241    TRACE("rendering box %g,%g %g,%g %g,%g\n", x0, x1, y0, y1, z0, z1);
    240242
     243    glColor4d(_sv.color.r, _sv.color.g, _sv.color.b, _sv.color.a);
    241244    glLineWidth(_sv.lineWidth);
    242245    glBegin(GL_LINE_LOOP);
     
    276279
    277280    glPopMatrix();
     281    glPopAttrib();
     282
    278283    assert(CheckGL(AT));
    279     glPopMatrix();
    280     assert(CheckGL(AT));
    281 
    282     glDisable(GL_DEPTH_TEST);
    283     glDisable(GL_BLEND);
    284     glEnable(GL_TEXTURE_2D);
    285284}
    286285
     
    633632    float *destPtr = data;
    634633    const float *values = _dataPtr->values();
    635     for (size_t iz=0; iz < _dataPtr->zNum(); iz++) {
    636         for (size_t iy=0; iy < _dataPtr->yNum(); iy++) {
    637             for (size_t ix=0; ix < _dataPtr->xNum(); ix++) {
     634    for (size_t iz = 0; iz < _dataPtr->zNum(); iz++) {
     635        for (size_t iy = 0; iy < _dataPtr->yNum(); iy++) {
     636            for (size_t ix = 0; ix < _dataPtr->xNum(); ix++) {
    638637                double vx, vy, vz, vm;
    639638                vx = values[0];
     
    641640                vz = values[2];
    642641                vm = sqrt(vx*vx + vy*vy + vz*vz);
    643                 destPtr[0] = vm / NanoVis::magMax; 
    644                 destPtr[1] = vx /(2.0*NanoVis::magMax) + 0.5; 
    645                 destPtr[2] = vy /(2.0*NanoVis::magMax) + 0.5; 
    646                 destPtr[3] = vz /(2.0*NanoVis::magMax) + 0.5; 
     642                destPtr[0] = vm / NanoVis::magMax;
     643                destPtr[1] = vx /(2.0*NanoVis::magMax) + 0.5;
     644                destPtr[2] = vy /(2.0*NanoVis::magMax) + 0.5;
     645                destPtr[3] = vz /(2.0*NanoVis::magMax) + 0.5;
    647646                values += 3;
    648647                destPtr += 4;
     
    10671066        licRenderer->setOffset(flowPtr->GetRelativePosition());
    10681067        NanoVis::velocityArrowsSlice->slicePos(flowPtr->GetRelativePosition());
    1069        
    10701068    }
    10711069    AdvectFlows();
     
    19471945        }
    19481946        NanoVis::AdvectFlows();
    1949         NanoVis::offscreenBufferCapture();
     1947
     1948        int fboOrig;
     1949        glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &fboOrig);
     1950
     1951        NanoVis::bindOffscreenBuffer();
    19501952        NanoVis::display();
    19511953        NanoVis::readScreen();
    1952         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     1954
     1955        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboOrig);
     1956
    19531957        movie.append(context, NanoVis::screenBuffer, pad);
    19541958    }
     
    19671971
    19681972        char command[200];
    1969         sprintf(command,"nv>image -bytes %lu -type movie -token \"%s\"\n",
    1970                 (unsigned long)data.size(), token);
     1973        sprintf(command,"nv>image -type movie -token \"%s\" -bytes %lu\n",
     1974                token, (unsigned long)data.size());
    19711975        NanoVis::sendDataToClient(command, data.bytes(), data.size());
    19721976    }
  • trunk/packages/vizservers/nanovis/PlaneRenderer.cpp

    r2870 r2930  
    1919
    2020PlaneRenderer::PlaneRenderer(int width, int height) :
    21     _active_plane(-1),
    22     _n_planes(0),
    23     _render_width(width),
    24     _render_height(height),
     21    _activePlane(-1),
     22    _numPlanes(0),
     23    _renderWidth(width),
     24    _renderHeight(height),
    2525    _shader(new NvColorTableShader())
    2626{
     
    3535
    3636int
    37 PlaneRenderer::add_plane(Texture2D *p, TransferFunction *tfPtr)
     37PlaneRenderer::addPlane(Texture2D *p, TransferFunction *tfPtr)
    3838{
    39     int ret = _n_planes;
     39    int ret = _numPlanes;
    4040
    4141    _plane.push_back(p);
     
    4343
    4444    if (ret == 0)
    45         _active_plane = ret;
     45        _activePlane = ret;
    4646
    47     _n_planes++;
     47    _numPlanes++;
    4848    return ret;
    4949}
    5050
    5151void
    52 PlaneRenderer::remove_plane(int index)
     52PlaneRenderer::removePlane(int index)
    5353{
    5454    std::vector<Texture2D *>::iterator piter = _plane.begin()+index;
     
    5858    _tf.erase(tfiter);
    5959
    60     _n_planes--;
     60    _numPlanes--;
    6161}
    6262
     
    6464PlaneRenderer::render()
    6565{
    66     if (_n_planes == 0)
     66    if (_numPlanes == 0)
    6767        return;
     68
     69    glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
    6870
    6971    glEnable(GL_TEXTURE_2D);
    7072    glEnable(GL_BLEND);
    7173
    72     glViewport(0, 0, _render_width, _render_height);
     74    glViewport(0, 0, _renderWidth, _renderHeight);
    7375    glMatrixMode(GL_PROJECTION);
     76    glPushMatrix();
    7477    glLoadIdentity();
    75     gluOrtho2D(0, _render_width, 0, _render_height);
     78    gluOrtho2D(0, _renderWidth, 0, _renderHeight);
    7679    glMatrixMode(GL_MODELVIEW);
     80    glPushMatrix();
    7781    glLoadIdentity();
    7882
     
    8084
    8185    //if no active plane
    82     if (_active_plane == -1)
     86    if (_activePlane == -1)
    8387        return;
    8488
    85     _shader->bind(_plane[_active_plane], _tf[_active_plane]);
     89    _shader->bind(_plane[_activePlane], _tf[_activePlane]);
    8690    glBegin(GL_QUADS);
    8791    glTexCoord2f(0, 0); glVertex2f(0, 0);
    88     glTexCoord2f(1, 0); glVertex2f(_render_width, 0);
    89     glTexCoord2f(1, 1); glVertex2f(_render_width, _render_height);
    90     glTexCoord2f(0, 1); glVertex2f(0, _render_height);
     92    glTexCoord2f(1, 0); glVertex2f(_renderWidth, 0);
     93    glTexCoord2f(1, 1); glVertex2f(_renderWidth, _renderHeight);
     94    glTexCoord2f(0, 1); glVertex2f(0, _renderHeight);
    9195    glEnd();
    9296    _shader->unbind();
     97
     98    glMatrixMode(GL_PROJECTION);
     99    glPopMatrix();
     100
     101    glMatrixMode(GL_MODELVIEW);
     102    glPopMatrix();
     103
     104    glPopAttrib();
    93105}
    94106
    95107void
    96 PlaneRenderer::set_active_plane(int index)
     108PlaneRenderer::setActivePlane(int index)
    97109{
    98     _active_plane = index;
     110    _activePlane = index;
    99111}
    100112
    101113void
    102 PlaneRenderer::set_screen_size(int w, int h)
     114PlaneRenderer::setScreenSize(int w, int h)
    103115{
    104     _render_width = w;
    105     _render_height = h;
     116    _renderWidth = w;
     117    _renderHeight = h;
    106118}
  • trunk/packages/vizservers/nanovis/PlaneRenderer.h

    r2870 r2930  
    3838    ~PlaneRenderer();
    3939
    40     int add_plane(Texture2D *p, TransferFunction *tf);
     40    /// Add a plane and its transfer function.
     41    int addPlane(Texture2D *p, TransferFunction *tf);
    4142
    42     // Add a plane and its transfer function. We require a transfer function
    43     // when a plane is added.
    44     void remove_plane(int index);
     43    void removePlane(int index);
    4544
    46     void set_active_plane(int index); //set the active plane to be rendered
     45    /// Set the active plane to be rendered
     46    void setActivePlane(int index);
    4747
    48     void set_screen_size(int w, int h); //change the rendering size
     48    /// Change the rendering size
     49    void setScreenSize(int w, int h);
    4950
    5051    void render();
    5152
    5253private:
    53     std::vector<Texture2D *> _plane;    // Array of volumes
    54     std::vector<TransferFunction *> _tf; // Array of corresponding transfer functions
    55     int _active_plane;          // The active plane, only one is rendered
    56     int _n_planes;
     54    std::vector<Texture2D *> _plane;     ///< Array of images
     55    std::vector<TransferFunction *> _tf; ///< Array of corresponding transfer functions
     56    int _activePlane;                    ///< The active plane, only one is rendered
     57    int _numPlanes;
    5758
    58     int _render_width;   //render size
    59     int _render_height; 
     59    int _renderWidth;
     60    int _renderHeight; 
    6061
    6162    NvColorTableShader *_shader;
  • trunk/packages/vizservers/nanovis/nanovis.cpp

    r2928 r2930  
    128128#if PLANE_CMD
    129129// pointers to 2D planes, currently handle up 10
     130int NanoVis::numPlanes = 10;
    130131Texture2D *NanoVis::plane[10];
    131132#endif
     
    458459{
    459460    Tcl_HashEntry *hPtr;
    460     hPtr = Tcl_FindHashEntry(&NanoVis::volumeTable, name);
     461    hPtr = Tcl_FindHashEntry(&volumeTable, name);
    461462    if (hPtr != NULL) {
    462463        Volume *volPtr;
     
    466467    }
    467468    int isNew;
    468     hPtr = Tcl_CreateHashEntry(&NanoVis::volumeTable, name, &isNew);
     469    hPtr = Tcl_CreateHashEntry(&volumeTable, name, &isNew);
    469470    Volume* volPtr;
    470471    volPtr = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., n_component,
    471                 data, vmin, vmax, nzero_min);
     472                        data, vmin, vmax, nzero_min);
    472473    Tcl_SetHashValue(hPtr, volPtr);
    473     volPtr->name(Tcl_GetHashKey(&NanoVis::volumeTable, hPtr));
     474    volPtr->name(Tcl_GetHashKey(&volumeTable, hPtr));
    474475    return volPtr;
    475476}
    476477
    477478// Gets a colormap 1D texture by name.
    478 TransferFunction*
     479TransferFunction *
    479480NanoVis::getTransfunc(const char *name)
    480481{
     
    485486        return NULL;
    486487    }
    487     return (TransferFunction*)Tcl_GetHashValue(hPtr);
     488    return (TransferFunction *)Tcl_GetHashValue(hPtr);
    488489}
    489490
    490491// Creates of updates a colormap 1D texture by name.
    491 TransferFunction*
     492TransferFunction *
    492493NanoVis::defineTransferFunction(const char *name, size_t n, float *data)
    493494{
     
    521522    int old_height = winHeight;
    522523
    523     planeRenderer->set_screen_size(width, height);
     524    planeRenderer->setScreenSize(width, height);
    524525    resizeOffscreenBuffer(width, height);
    525526
     
    530531    }
    531532    legendTexture = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data);
    532     int index = planeRenderer->add_plane(legendTexture, tf);
    533     planeRenderer->set_active_plane(index);
    534 
    535     offscreenBufferCapture();
     533    int index = planeRenderer->addPlane(legendTexture, tf);
     534    planeRenderer->setActivePlane(index);
     535
     536    bindOffscreenBuffer();
    536537    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    537538    planeRenderer->render();
     
    551552        assert(nWritten == 1);
    552553    }
    553     planeRenderer->remove_plane(index);
     554    planeRenderer->removePlane(index);
    554555    resizeOffscreenBuffer(old_width, old_height);
    555556
     
    564565{
    565566    TRACE("in initOffscreenBuffer\n");
     567    assert(_finalFbo == 0);
    566568    // Initialize a fbo for final display.
    567569    glGenFramebuffersEXT(1, &_finalFbo);
     
    572574    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    573575    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     576    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     577
    574578#if defined(HAVE_FLOAT_TEXTURES) && defined(USE_HALF_FLOAT)
    575579    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, winWidth, winHeight, 0,
     
    582586                 GL_RGB, GL_INT, NULL);
    583587#endif
     588
    584589    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo);
    585590    glGenRenderbuffersEXT(1, &_finalDepthRb);
     
    598603    }
    599604
    600     // Check framebuffer completeness at the end of initialization.
    601     //CHECK_FRAMEBUFFER_STATUS();
    602 
    603     //assert(glGetError()==0);
    604605    TRACE("leaving initOffscreenBuffer\n");
    605606}
     
    646647    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    647648    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     649    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     650
    648651#if defined(HAVE_FLOAT_TEXTURES) && defined(USE_HALF_FLOAT)
    649652    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, winWidth, winHeight, 0,
     
    656659                 GL_RGB, GL_INT, NULL);
    657660#endif
    658     TRACE("before bindframebuffer\n");
     661
    659662    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo);
    660     TRACE("after bindframebuffer\n");
    661663    glGenRenderbuffersEXT(1, &_finalDepthRb);
    662664    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, _finalDepthRb);
     
    674676    }
    675677
    676     //CHECK_FRAMEBUFFER_STATUS();
    677678    TRACE("change camera\n");
    678679    //change the camera setting
    679680    cam->setScreenSize(0, 0, winWidth, winHeight);
    680     planeRenderer->set_screen_size(winWidth, winHeight);
     681    planeRenderer->setScreenSize(winWidth, winHeight);
    681682
    682683    TRACE("leaving resizeOffscreenBuffer(%d, %d)\n", w, h);
     
    726727void NanoVis::init(const char* path)
    727728{
    728     // print system information
     729    // print OpenGL driver information
    729730    TRACE("-----------------------------------------------------------\n");
    730     TRACE("OpenGL driver: %s %s\n", glGetString(GL_VENDOR),
    731           glGetString(GL_VERSION));
    732     TRACE("Graphics hardware: %s\n", glGetString(GL_RENDERER));
     731    TRACE("OpenGL version: %s\n", glGetString(GL_VERSION));
     732    TRACE("OpenGL vendor: %s\n", glGetString(GL_VENDOR));
     733    TRACE("OpenGL renderer: %s\n", glGetString(GL_RENDERER));
    733734    TRACE("-----------------------------------------------------------\n");
    734735
     
    744745    TRACE("Using GLEW %s\n", glewGetString(GLEW_VERSION));
    745746
     747    // OpenGL 2.1 includes VBOs, PBOs, MRT, NPOT textures, point parameters, point sprites,
     748    // GLSL 1.2, and occlusion queries.
     749    if (!GLEW_VERSION_2_1) {
     750        ERROR("OpenGL version 2.1 or greater is required\n");
     751        doExit(1);
     752    }
     753
     754    // Additional extensions not in 2.1 core
     755
     756    // Framebuffer objects were promoted in 3.0
    746757    if (!GLEW_EXT_framebuffer_object) {
    747         ERROR("EXT_framebuffer_oject extension is required to run nanovis\n");
     758        ERROR("EXT_framebuffer_oject extension is required\n");
    748759        doExit(1);
    749760    }
    750 #ifdef HAVE_NPOT_TEXTURES
    751     if (!GLEW_ARB_texture_non_power_of_two) {
    752         ERROR("ARB_texture_non_power_of_two extension is required to run nanovis\n");
     761    // Rectangle textures were promoted in 3.1
     762    // FIXME: can use NPOT in place of rectangle textures
     763    if (!GLEW_ARB_texture_rectangle) {
     764        ERROR("ARB_texture_rectangle extension is required\n");
    753765        doExit(1);
    754766    }
    755 #endif
    756     if (!GLEW_ARB_texture_rectangle) {
    757         ERROR("ARB_texture_rectangle extension is required to run nanovis\n");
    758         doExit(1);
    759     }
    760767#ifdef HAVE_FLOAT_TEXTURES
     768    // Float color buffers and textures were promoted in 3.0
    761769    if (!GLEW_ARB_texture_float ||
    762770        !GLEW_ARB_color_buffer_float) {
    763         ERROR("ARB_texture_float and ARB_color_buffer_float extensions are required to run nanovis\n");
     771        ERROR("ARB_texture_float and ARB_color_buffer_float extensions are required\n");
    764772        doExit(1);
    765773    }
    766774#endif
     775    // FIXME: should use ARB programs or (preferably) a GLSL profile for portability
    767776    if (!GLEW_NV_vertex_program3 ||
    768777        !GLEW_NV_fragment_program2) {
    769         ERROR("NV_vertex_program3 and NV_fragment_program2 extensions are required to run nanovis\n");
     778        ERROR("NV_vertex_program3 and NV_fragment_program2 extensions are required\n");
    770779        doExit(1);
    771780    }
     
    792801    flowVisRenderer = new NvFlowVisRenderer(NMESH, NMESH);
    793802
    794     NanoVis::velocityArrowsSlice = new VelocityArrowsSlice;
     803    velocityArrowsSlice = new VelocityArrowsSlice;
    795804
    796805    licRenderer = new NvLIC(NMESH, NPIX, NPIX, _licAxis,
     
    805814}
    806815
    807 /*----------------------------------------------------*/
    808816void
    809 NanoVis::initGL(void)
     817NanoVis::initGL()
    810818{
    811819    TRACE("in initGL\n");
     
    827835    glShadeModel(GL_FLAT);
    828836    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    829 
    830     glClearColor(0,0,0,1);
    831     glClear(GL_COLOR_BUFFER_BIT);
     837    glClearColor(0, 0, 0, 1);
     838    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    832839
    833840    //initialize lighting
     
    865872#if PROTOTYPE
    866873    make_test_2D_data();
    867     planeRenderer->add_plane(plane[0], getTransfunc("default"));
     874    planeRenderer->addPlane(plane[0], getTransfunc("default"));
    868875#endif
    869876
     
    12301237{
    12311238    TRACE("in display_offscreen_buffer\n");
     1239
    12321240    glEnable(GL_TEXTURE_2D);
    12331241    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     
    12501258    }
    12511259    glEnd();
     1260
    12521261    TRACE("leaving display_offscreen_buffer\n");
    12531262}
     
    13371346draw3dAxis()
    13381347{
     1348    glPushAttrib(GL_ENABLE_BIT);
     1349
    13391350    glDisable(GL_TEXTURE_2D);
    13401351    glEnable(GL_DEPTH_TEST);
     1352    glEnable(GL_COLOR_MATERIAL);
     1353    glDisable(GL_BLEND);
    13411354
    13421355    //draw axes
     
    13441357
    13451358    obj = gluNewQuadric();
    1346 
    1347     glDepthFunc(GL_LESS);
    1348     glEnable(GL_COLOR_MATERIAL);
    1349     glEnable(GL_DEPTH_TEST);
    1350     glDisable(GL_BLEND);
    13511359
    13521360    int segments = 50;
     
    14161424    glPopMatrix();
    14171425
    1418     glDisable(GL_LIGHTING);
    1419     glDisable(GL_DEPTH_TEST);
    14201426    gluDeleteQuadric(obj);
    14211427
    1422     glEnable(GL_TEXTURE_2D);
    1423     glDisable(GL_DEPTH_TEST);
     1428    glPopAttrib();
    14241429}
    14251430
     
    15901595        setVolumeRanges();
    15911596    }
     1597
     1598    //start final rendering
     1599
     1600    // Need to reset fbo since it may have been changed to default (0)
     1601    bindOffscreenBuffer();
     1602
    15921603    TRACE("in display: glClear\n");
    1593     //start final rendering
    15941604    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    15951605
     
    15971607        TRACE("in display: volumeMode\n");
    15981608        //3D rendering mode
    1599         // TBD..
    1600         //glEnable(GL_TEXTURE_2D);
    16011609        glEnable(GL_DEPTH_TEST);
     1610        glEnable(GL_COLOR_MATERIAL);
    16021611
    16031612        //camera setting activated
     
    16311640        }
    16321641
    1633         // TBD : This will be removed after being sure that all the functions work well.
    1634         //glPushMatrix();
    1635 
    16361642        //now render things in the scene
    16371643        if (axisOn) {
     
    18441850            Tcl_Eval(interp, cmd);
    18451851#ifdef notdef
    1846             NanoVis::flowVisRenderer->active(true);
    1847             NanoVis::licRenderer->active(true);
     1852            flowVisRenderer->active(true);
     1853            licRenderer->active(true);
    18481854#endif
    18491855        }
     
    18591865            Tcl_Eval(interp, cmd);
    18601866#ifdef notdef
    1861             NanoVis::flowVisRenderer->active(false);
    1862             NanoVis::licRenderer->active(false);
     1867            flowVisRenderer->active(false);
     1868            licRenderer->active(false);
    18631869#endif
    18641870        }
     
    19161922            Tcl_Eval(interp, cmd);
    19171923#ifdef notdef
    1918             NanoVis::flowVisRenderer->deactivatePlane("vf_name1", "plane_name2");
     1924            flowVisRenderer->deactivatePlane("vf_name1", "plane_name2");
    19191925#endif
    19201926        }
     
    19281934            Tcl_Eval(interp, cmd);
    19291935#ifdef notdef
    1930             NanoVis::flowVisRenderer->removeVectorField("vf_name2");
     1936            flowVisRenderer->removeVectorField("vf_name2");
    19311937#endif
    19321938        }
     
    19461952            shape.max.set(30, 3, 3);
    19471953            shape.color.set(1, 0, 0, 1);
    1948             NanoVis::flowVisRenderer->addDeviceShape("vf_name1", "device1", shape);
     1954            flowVisRenderer->addDeviceShape("vf_name1", "device1", shape);
    19491955            shape.min.set(0, -1, -1);
    19501956            shape.max.set(30, 4, 4);
    19511957            shape.color.set(0, 1, 0, 1);
    1952             NanoVis::flowVisRenderer->addDeviceShape("vf_name1", "device2", shape);
     1958            flowVisRenderer->addDeviceShape("vf_name1", "device2", shape);
    19531959            shape.min.set(10, -1.5, -1);
    19541960            shape.max.set(20, 4.5, 4.5);
    19551961            shape.color.set(0, 0, 1, 1);
    1956             NanoVis::flowVisRenderer->addDeviceShape("vf_name1", "device3", shape);
    1957             NanoVis::flowVisRenderer->activateDeviceShape("vf_name1");
     1962            flowVisRenderer->addDeviceShape("vf_name1", "device3", shape);
     1963            flowVisRenderer->activateDeviceShape("vf_name1");
    19581964#endif
    19591965        }
     
    19671973            Tcl_Eval(interp, cmd);
    19681974#ifdef notdef
    1969             NanoVis::flowVisRenderer->deactivateDeviceShape("vf_name1");
     1975            flowVisRenderer->deactivateDeviceShape("vf_name1");
    19701976#endif
    19711977        }
     
    19791985            Tcl_Eval(interp, cmd);
    19801986#ifdef notdef
    1981             NanoVis::flowVisRenderer->activateDeviceShape("vf_name1");
     1987            flowVisRenderer->activateDeviceShape("vf_name1");
    19821988#endif
    19831989        }
     
    19911997            Tcl_Eval(interp, cmd);
    19921998#ifdef notdef
    1993             NanoVis::flowVisRenderer->activateDeviceShape("vf_name1", "device3");
     1999            flowVisRenderer->activateDeviceShape("vf_name1", "device3");
    19942000#endif
    19952001        }
     
    20032009            Tcl_Eval(interp, cmd);
    20042010#ifdef notdef
    2005             NanoVis::flowVisRenderer->deactivateDeviceShape("vf_name1", "device3");
     2011            flowVisRenderer->deactivateDeviceShape("vf_name1", "device3");
    20062012#endif
    20072013        }
     
    20152021            Tcl_Eval(interp, cmd);
    20162022#ifdef notdef
    2017             NanoVis::flowVisRenderer->reset();
    2018             NanoVis::licRenderer->reset();
     2023            flowVisRenderer->reset();
     2024            licRenderer->reset();
    20192025#endif
    20202026        }
     
    20662072}
    20672073
    2068 #endif /*XINETD*/
    2069 
    20702074void
    20712075NanoVis::render()
     
    20732077
    20742078#ifdef notdef
    2075     if ((NanoVis::licRenderer != NULL) && (NanoVis::licRenderer->active())) {
    2076         NanoVis::licRenderer->convolve();
     2079    if ((licRenderer != NULL) && (licRenderer->active())) {
     2080        licRenderer->convolve();
    20772081    }
    20782082#else
    2079     if (NanoVis::licRenderer != NULL) {
    2080         NanoVis::licRenderer->convolve();
     2083    if (licRenderer != NULL) {
     2084        licRenderer->convolve();
    20812085    }
    20822086#endif
    20832087
    20842088#ifdef notdef
    2085     if ((NanoVis::flowVisRenderer != NULL) && (NanoVis::flowVisRenderer->active())) {
    2086         NanoVis::flowVisRenderer->advect();
    2087     }
    2088 #endif
    2089     NanoVis::update();
     2089    if ((flowVisRenderer != NULL) && (flowVisRenderer->active())) {
     2090        flowVisRenderer->advect();
     2091    }
     2092#endif
     2093    update();
    20902094    display();
    20912095    glutSwapBuffers();
     
    20982102}
    20992103
     2104#endif /*XINETD*/
     2105
    21002106void
    2101 NanoVis::xinetdListen(void)
    2102 {
    2103     NanoVis::flags &= ~REDRAW_PENDING;
     2107NanoVis::xinetdListen()
     2108{
     2109    flags &= ~REDRAW_PENDING;
    21042110
    21052111    TRACE("Enter xinetdListen\n");
     
    21842190    }
    21852191
    2186     NanoVis::update();
    2187 
    2188     NanoVis::offscreenBufferCapture();  //enable offscreen render
    2189 
    2190     NanoVis::display();
    2191 
    2192     // INSOO
     2192    update();
     2193
     2194    bindOffscreenBuffer();  //enable offscreen render
     2195
     2196    display();
     2197
    21932198#ifdef XINETD
    2194     NanoVis::readScreen();
    2195     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     2199    readScreen();
    21962200#else
    2197     NanoVis::displayOffscreenBuffer(); //display the final rendering on screen
    2198     NanoVis::readScreen();
     2201    displayOffscreenBuffer(); //display the final rendering on screen
     2202    readScreen();
    21992203    glutSwapBuffers();
    22002204#endif
     
    22112215    write(1, rle, rle_size);    //unsigned byte
    22122216#else
    2213     NanoVis::ppmWrite("\nnv>image -type image -bytes");
     2217    ppmWrite("\nnv>image -type image -bytes");
    22142218#endif
    22152219    TRACE("Leaving xinetd_listen OK\n");
    22162220}
    22172221
    2218 
    2219 /*----------------------------------------------------*/
    22202222int
    22212223main(int argc, char **argv)
     
    23882390
    23892391    /*
    2390       planeRenderer->set_screen_size(width, height);
     2392      planeRenderer->setScreenSize(width, height);
    23912393
    23922394      // generate data for the legend
    23932395      float data[512];
    23942396      for (int i=0; i < 256; i++) {
    2395       data[i] = data[i+256] = (float)(i/255.0);
     2397          data[i] = data[i+256] = (float)(i/255.0);
    23962398      }
    23972399      plane[0] = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data);
    2398       int index = planeRenderer->add_plane(plane[0], tf);
    2399       planeRenderer->set_active_plane(index);
    2400 
    2401       offscreenBufferCapture();
     2400      int index = planeRenderer->addPlane(plane[0], tf);
     2401      planeRenderer->setActivePlane(index);
     2402
     2403      bindOffscreenBuffer();
    24022404      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    24032405
     
    24192421    //ppmWrite(prefix);
    24202422    //write(1, "\n", 1);
    2421     //planeRenderer->remove_plane(index);
     2423    //planeRenderer->removePlane(index);
    24222424
    24232425    // CURRENT
    2424     offscreenBufferCapture();
     2426    bindOffscreenBuffer();
    24252427    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
    24262428    //glEnable(GL_TEXTURE_2D);
    24272429    //glEnable(GL_DEPTH_TEST);
    2428     //heightmap->render_topview(renderContext, width, height);
     2430    //heightmap->renderTopview(renderContext, width, height);
    24292431    //NanoVis::display();
    24302432    if (HeightMap::updatePending) {
     
    24362438    heightmap->renderTopview(renderContext, width, height);
    24372439
    2438     NanoVis::readScreen();
    2439     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     2440    readScreen();
    24402441
    24412442    // INSOO TEST CODE
  • trunk/packages/vizservers/nanovis/nanovis.h

    r2877 r2930  
    7272    };
    7373
     74    static void xinetdListen();
    7475    static void init(const char *path);
    75     static void xinetdListen();
    7676    static void initGL();
    7777    static void initOffscreenBuffer();
    7878    static void resizeOffscreenBuffer(int w, int h);
    79     static void resize(int w, int h);
    80     static void render();
     79    static void displayOffscreenBuffer();
    8180    static void display();
    8281    static void idle();
    8382    static void update();
    84     static void displayOffscreenBuffer();
     83
    8584    static void pan(float dx, float dy);
    8685    static void zoom(float z);
     
    120119    static void updateRot(int delta_x, int delta_y);
    121120    static void updateTrans(int delta_x, int delta_y, int delta_z);
     121    static void resize(int w, int h);
     122    static void render();
    122123#endif
    123124
     
    127128                     screenBuffer);
    128129    }
    129     static void offscreenBufferCapture()
     130    static void bindOffscreenBuffer()
    130131    {
    131132        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo);
     
    174175    static PlaneRenderer *planeRenderer;
    175176#if PLANE_CMD
     177    static int numPlanes;
    176178    static Texture2D *plane[]; ///< Pointers to 2D planes
    177179#endif
Note: See TracChangeset for help on using the changeset viewer.