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

VolShader.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-17-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 /// VolShader.cpp
00019 
00020 #include "VolShader.h"
00021 
00022 using namespace glift;
00023 using namespace std;
00024 
00025 ///////////////////////////////////////////////////////////////////////////
00026 /// Construct / Destruct
00027 ///////////////////////////////////////////////////////////////////////////
00028 VolShader::VolShader()
00029 :StateGLI(),
00030 SimBase(),
00031 _curPixShade(0),
00032 _curVertShade(0),
00033 _blendMode(BLEND_NONE)
00034 {
00035 
00036 }
00037 
00038 
00039 VolShader::~VolShader()
00040 {
00041 }
00042 
00043 ///////////////////////////////////////////////////////////////////////////
00044 /// Bind / Release
00045 ///////////////////////////////////////////////////////////////////////////
00046 void VolShader::bindDef()
00047 {
00048    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);   
00049    glDepthMask(GL_TRUE);
00050    glColor4f(1,0,0,1); //red lines!
00051    glDisable(GL_LIGHTING);
00052 }
00053 
00054 void VolShader::releaseDef()
00055 {
00056    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00057    glColor4f(1,1,1,1);
00058    glEnable(GL_LIGHTING);
00059 }
00060 
00061 ///////////////////////////////////////////////////////////////////////////
00062 /// Shaders Bind / Release
00063 ///////////////////////////////////////////////////////////////////////////
00064 void VolShader::bindShaders()
00065 {
00066    if(_curVertShade) _curVertShade->bind();
00067    if(_curPixShade)  _curPixShade->bind();
00068 }
00069 
00070 void VolShader::releaseShaders()
00071 {
00072    if(_curVertShade) _curVertShade->release();
00073    if(_curPixShade)  _curPixShade->release();
00074 }
00075 
00076 ///////////////////////////////////////////////////////////////////////////
00077 /// Set/get Shaders
00078 ///////////////////////////////////////////////////////////////////////////
00079 
00080 ///////////////////////////////////////////////////////////////////////////
00081 /// Set Pixel Shaders
00082 ///////////////////////////////////////////////////////////////////////////
00083 void VolShader::setPixelShader(glift::PixelShader *ps)
00084 {
00085    if(isBound() && _curPixShade)
00086    {
00087       _curPixShade->release();
00088    }
00089    _curPixShade = ps;
00090 
00091    if(isBound() && _curPixShade)
00092    {
00093       _curPixShade->bind();
00094    }
00095 }
00096 
00097 ///////////////////////////////////////////////////////////////////////////
00098 /// Get Pixel Shaders
00099 ///////////////////////////////////////////////////////////////////////////
00100 PixelShaderSP VolShader::getPixelShader()
00101 {
00102    return _curPixShade;
00103 }
00104 
00105 ///////////////////////////////////////////////////////////////////////////
00106 /// Set Vertex Shaders
00107 ///////////////////////////////////////////////////////////////////////////
00108 void VolShader::setVertexShader(glift::VertexShader *vs)
00109 {
00110    if(isBound() && _curVertShade)
00111    {
00112       _curVertShade->release();
00113    }
00114    _curVertShade = vs;
00115    if(isBound() && _curVertShade)
00116    {
00117       _curVertShade->bind();
00118    }
00119 }
00120 
00121 ///////////////////////////////////////////////////////////////////////////
00122 /// Get Vertex Shaders
00123 ///////////////////////////////////////////////////////////////////////////
00124 VertexShaderSP VolShader::getVertexShader()
00125 {
00126    return _curVertShade;
00127 }
00128 
00129 ///////////////////////////////////////////////////////////////////////////
00130 /// State
00131 ///////////////////////////////////////////////////////////////////////////
00132 /// Bind State
00133 ///////////////////////////////////////////////////////////////////////////
00134 void VolShader::bindState()
00135 {
00136    for(unsigned int i=0; i < _state.size(); i++) {
00137       if( _state[i] ) { _state[i]->bind(); }
00138    }
00139 }
00140 
00141 ///////////////////////////////////////////////////////////////////////////
00142 /// Release State
00143 ///////////////////////////////////////////////////////////////////////////
00144 void VolShader::releaseState()
00145 {
00146    for(unsigned int i=0; i < _state.size(); i++) {
00147       if( _state[i] ) { _state[i]->release(); }
00148    }
00149 }
00150 
00151 ///////////////////////////////////////////////////////////////////////////
00152 /// Blending
00153 ///////////////////////////////////////////////////////////////////////////
00154 
00155 ///////////////////////////////////////////////////////////////////////////
00156 /// Set Blend
00157 ///////////////////////////////////////////////////////////////////////////
00158 void  VolShader::setBlend(int blendMode)
00159 {
00160    if(isBound())
00161    {
00162       releaseBlend();
00163    }
00164    _blendMode = blendMode;
00165    if(isBound())
00166    {
00167       bindBlend();
00168    }
00169 }
00170 
00171 ///////////////////////////////////////////////////////////////////////////
00172 /// Bind Blend (Protected)
00173 ///////////////////////////////////////////////////////////////////////////
00174 void VolShader::bindBlend()
00175 {
00176    if(_blendMode == BLEND_B2F)
00177    {
00178       glEnable(GL_BLEND);
00179       glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
00180    }
00181    else if(_blendMode == BLEND_F2B)
00182    {
00183       glEnable(GL_BLEND);
00184       glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
00185    }
00186    else
00187    {
00188       SimBase::derr("bindBlend(), unknown blendop");
00189    }
00190 }
00191 
00192 ///////////////////////////////////////////////////////////////////////////
00193 /// Release Blend (Protected)
00194 ///////////////////////////////////////////////////////////////////////////
00195 void VolShader::releaseBlend()
00196 {
00197    glDisable(GL_BLEND);
00198 }
00199 

Send questions, comments, and bug reports to:
jmk