arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

VolRenAlgBase.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     9-20-02
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2002 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 //VolRenAlgBase.cpp
00019 
00020 #include "VolRenAlgBase.h"
00021 #ifdef WIN32
00022 #include <windows.h>
00023 #endif
00024 #include <GL/glew.h>
00025 #include <GL/gl.h>
00026 #include <iostream>
00027 
00028 using namespace gutz;
00029 using namespace glift;
00030 using namespace std;
00031 
00032 ///////////////////////////////////////////////////////////////////////////
00033 /// Bind def
00034 ///////////////////////////////////////////////////////////////////////////
00035 
00036 void VolRenAlgBase::bindDef()
00037 {
00038    if(_curVSamp) _curVSamp->bind();
00039    if(_curShader) _curShader->bind();
00040 
00041    bindTex();
00042 }
00043 
00044 ///////////////////////////////////////////////////////////////////////////
00045 /// Release def
00046 ///////////////////////////////////////////////////////////////////////////
00047 void VolRenAlgBase::releaseDef()
00048 {
00049    if(_curVSamp) _curVSamp->release();
00050    if(_curShader) _curShader->release();
00051 
00052    releaseTex();
00053 }
00054 
00055 ///////////////////////////////////////////////////////////////////////////
00056 /// Set Slice Axis
00057 ///////////////////////////////////////////////////////////////////////////
00058 void VolRenAlgBase::setSliceAxis(gutz::vec3f sliceAxis)
00059 {  
00060    _currentAxis = sliceAxis; 
00061    updateShader();
00062 }
00063 
00064 ///////////////////////////////////////////////////////////////////////////
00065 /// Draw Tris
00066 ///////////////////////////////////////////////////////////////////////////
00067 void VolRenAlgBase::drawTris(VolSamples *vs)
00068 {
00069    //////////////////////////////////////////
00070    /// draw volume
00071    vs->bind();
00072    vs->draw();
00073    vs->release();
00074 }
00075 
00076 ///////////////////////////////////////////////////////////////////////////
00077 /// Set Volytope
00078 ///////////////////////////////////////////////////////////////////////////
00079 void VolRenAlgBase::setVolytope(VolytopeSP vt)
00080 {
00081    if(isBound())
00082       releaseTex();
00083 
00084    _curVoly = vt;
00085 
00086    if(isBound())
00087       bindTex();
00088 }
00089 
00090 ///////////////////////////////////////////////////////////////////////////
00091 /// Set Geom
00092 ///////////////////////////////////////////////////////////////////////////
00093 void VolRenAlgBase::setGeom(VolSamples *vs)
00094 {
00095    if(isBound() && _curVSamp)
00096       _curVSamp->release();
00097 
00098    _curVSamp = vs;
00099 
00100    if(isBound() && _curVSamp)
00101       _curVSamp->bind();
00102 }
00103 
00104 ///////////////////////////////////////////////////////////////////////////
00105 /// Set Shader
00106 ///////////////////////////////////////////////////////////////////////////
00107 void VolRenAlgBase::setShader(VolShader *vs)
00108 {
00109    if(isBound() && _curShader)
00110    {
00111       _curShader->release();
00112    }
00113 
00114    _curShader = vs;
00115 
00116    if(isBound() && _curShader)
00117    {
00118       _curShader->bind();
00119    }
00120 
00121    updateShader();
00122 }
00123 
00124 ///////////////////////////////////////////////////////////////////////////
00125 /// Bind Textures
00126 ///////////////////////////////////////////////////////////////////////////
00127 void VolRenAlgBase::bindTex()
00128 {
00129    for(int i= 0; i<_curVoly->numTextures(); ++i)
00130    {
00131       glActiveTexture(GL_TEXTURE0_ARB + i);
00132       {
00133          _curVoly->getTexture(i)->bind();
00134       }
00135    }
00136    glActiveTexture(GL_TEXTURE0_ARB);
00137 
00138 }
00139 
00140 ///////////////////////////////////////////////////////////////////////////
00141 /// Release Textures
00142 ///////////////////////////////////////////////////////////////////////////
00143 void VolRenAlgBase::releaseTex()
00144 {
00145 
00146    for(int i= 0; i<_curVoly->numTextures(); ++i)
00147    {
00148       glActiveTexture(GL_TEXTURE0_ARB + i);
00149       {
00150          _curVoly->getTexture(i)->release();
00151       }
00152    }
00153    glActiveTexture(GL_TEXTURE0_ARB);
00154 
00155 }
00156 
00157 ///////////////////////////////////////////////////////////////////////////
00158 /// Update Shader
00159 ///////////////////////////////////////////////////////////////////////////
00160 void VolRenAlgBase::updateShader()
00161 {
00162    if(!_curShader) return;
00163 
00164    ////////////////////////////////////////
00165    /// update Blending
00166    if(_blend)
00167    {
00168       if(_currentAxis.dot(vec3f_neg_z)>0)
00169       {
00170          _curShader->setBlend(VolShader::BLEND_B2F);                    
00171       }
00172       else
00173       {
00174          _curShader->setBlend(VolShader::BLEND_F2B);
00175       }
00176    }
00177    else
00178    {
00179       _curShader->setBlend(VolShader::BLEND_NONE);
00180    }
00181    /// End update Blending
00182    ////////////////////////////////////////
00183 }

Send questions, comments, and bug reports to:
jmk