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

stateGLI.h

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////
00002 // 6/8/02       Aaron Lefohn    Scientific Computing and Imaging Institute
00003 // School of Computing          University of Utah
00004 //
00005 //  This library is free software; you can redistribute it and/or
00006 //  modify it under the terms of the GNU Lesser General Public
00007 //  License as published by the Free Software Foundation; either
00008 //  version 2.1 of the License, or (at your option) any later version.
00009 //
00010 //  This library is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 //  Lesser General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU Lesser General Public
00016 //  License along with this library; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 #ifndef __LIFTGL_STATEGL___H___
00020 #define __LIFTGL_STATEGL___H___
00021 
00022 #include "../core/gliftObject.h"
00023 #include "../util/dispList.h"
00024 #include "../util/compilable.h"
00025 #include "../util/gliftDecl.h"
00026 #include <vector>
00027 #include <mathGutz.h>
00028 #include <smartptr.h>
00029 #include <iostream>
00030 
00031 
00032 namespace glift {
00033 
00034 
00035 //////////////////////////////////////////////////////////////////////////
00036 ///
00037 /// "state.h" implementation file for the Attribute class
00038 ///
00039 /// - This abstract class provides the interface for any bindDef()/release()
00040 ///   state. Exs are pixelShaders, vertexShaders, textures, pbuffers, 
00041 ///   or any other state change to the rendering pipeline that can be
00042 ///   modeled with the init/bind/release abstraction.
00043 ///   
00044 /// - The "GenState" class should be sub-classed for states where it 
00045 ///   is okay to have more than one of that state. If there can be only one,
00046 ///   the new class should be parallel to texture, pixelShader, etc. and added
00047 ///   to the Shader class (constructor, private member, wrapped in another state, etc). 
00048 ///   Hopefully there won't be many more of these...
00049 ///   
00050 /// For the other pure virtual classes, their "raison d'etre" is to enforce a
00051 /// class heirarchy to allow for shader typechecking.
00052 /// 
00053 /// - The pure virtual destructor has an empty implementation b/c it 
00054 ///   is required by the compiler (see Eff. C++ by Scott Meyer).
00055 /// 
00056 /// The Base State Object
00057 /// StateGLI - Abstract interface for a bind()/release() state class
00058 ///////////////////////////////////////////////////////////////////
00059 class _export_ StateGLI : 
00060    public GliftObject, 
00061    public Compilable, 
00062    public gutz::Counted
00063 {
00064 public:
00065    StateGLI();
00066    virtual ~StateGLI();
00067 
00068    void bind();
00069    void release();
00070    bool isBound(){return m_isBound;}
00071    virtual void compile();
00072    virtual bool hasNonCompilable() {return false;}
00073 
00074 protected:
00075    /// Redefine these for specific attributes.
00076    /// - All calls def'd inside will be compiled
00077    ///   into display list.
00078    virtual void bindDef() = 0;
00079    virtual void releaseDef() = 0;
00080 
00081    virtual bool isCompiled() const {return m_bindList.isCompiled(); }
00082 
00083 private:
00084    DispList          m_bindList;
00085    DispList          m_releaseList;
00086    bool          m_isBound;
00087    std::ostream *m_err;
00088 };
00089 
00090 ///////////////////////////////////////////////////////////////////
00091 /// A Generic State object
00092 /// Any attribute where it is okay to have more than one of the 
00093 ///   same attribute in a shader.
00094 ///////////////////////////////////////////////////////////////////
00095 class _export_ GenState : public StateGLI
00096 {
00097 public:
00098    virtual ~GenState() = 0;
00099 };
00100 
00101 typedef gutz::SmartPtr<GenState> GenStateSP;
00102 typedef std::vector<GenState*>  VecStateP;
00103 
00104 ///////////////////////////////////////////////////////////////////
00105 /// Pixel shader
00106 ///////////////////////////////////////////////////////////////////
00107 class _export_ PixelShader : public StateGLI
00108 {
00109 public:
00110    virtual ~PixelShader() = 0;
00111    virtual void reset() = 0;//Destroy GL shader and re-initialize.
00112 
00113    virtual void setLocalConstf( unsigned int constNum, const gutz::vec4f& val ) = 0;
00114 };
00115 
00116 typedef gutz::SmartPtr<PixelShader> PixelShaderSP;
00117 
00118 ///////////////////////////////////////////////////////////////////
00119 /// Vertex shader
00120 ///////////////////////////////////////////////////////////////////
00121 class _export_ VertexShader : public StateGLI
00122 {
00123 public:
00124    virtual ~VertexShader() = 0;
00125 };
00126 
00127 typedef gutz::SmartPtr<VertexShader> VertexShaderSP;
00128 
00129 } /// End of namespace glift
00130 
00131 
00132 #endif
00133 

Send questions, comments, and bug reports to:
jmk