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

Crank.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     3-20-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 /// Crank.h
00019 
00020 /// the grinder's driver class, turn the crank to see the monkey dance!!
00021 ///  A base class for specialized grinders, a grinder should only produce
00022 ///  one thing, fragment/vertex/shader programs, you should link 
00023 ///  vertex and fragment (etc..) grinders to a shader grinder...
00024 
00025 ///  specialized Crank base classes are defined at the bottom!!!
00026 
00027 #ifndef __GRINDER_CRANK_DOT_H
00028 #define __GRINDER_CRANK_DOT_H
00029 
00030 #include <simBase/simBase.h>
00031 #include <stateGlift.h>
00032 #include "Tape.h"
00033 #include <volume/Volume.h>
00034 #include <mathGutz.h>
00035 #include "GrinderKeys.h"
00036 #include "GrinderKinds.h"
00037 #include "MetaProg.h"
00038 #include <arrayGutz.h>
00039 
00040 class Crank : public SimBase {
00041 public:
00042    virtual ~Crank() {}
00043 
00044    /// from <GrinderKinds.h>
00045    int getKind() const { return _kind; }
00046 
00047    /// Vertex Shader
00048    virtual glift::VertexShaderSP getVertShader() 
00049    { return glift::VertexShaderSP(0); }
00050    
00051    /// Pixel Shader
00052    virtual glift::PixelShaderSP  getPixelShader()
00053    { return glift::PixelShaderSP(0); }
00054 
00055    /// a complete shader specification
00056    virtual glift::ProgShaderSP   getShader()     
00057    { return glift::ProgShaderSP(0); }
00058 
00059    ////////////////////////////////////////////////////
00060    //// meta program management.
00061    int        addMP(MetaProgSP m);
00062    int        insertMP(int idx, MetaProgSP m);
00063    void       setMP(SNameType name, MetaProgSP m);
00064    void       setMP(int idx, MetaProgSP m);
00065    MetaProgSP getMP(int idx);
00066    MetaProgSP getMP(SNameType name);
00067    int        getMPIdx(SNameType name);
00068    int        getMPIdx(MetaProgSP m);
00069    MetaProgSP delMP(int idx);
00070    MetaProgSP delMP(SNameType name);
00071    MetaProgSP delMP(MetaProgSP m);
00072 
00073 protected:
00074    Crank() : _kind(GK_UNKNOWN), _lastCh(1,-1) {}
00075    Crank(int kind) : _kind(kind) {}
00076    Crank(const Crank &c);
00077 
00078    //// Customize behavior of MP management:
00079 
00080    //// you might want to be smarter about how
00081    ////  you check kinds....
00082    //// this is called with every modification to
00083    //// the meta-prog vector, from management ^^^
00084    /// false = valid kind, true = invalid kind
00085    virtual bool   checkKind(MetaProgSP m)
00086    {
00087       if(_kind == GK_UNKNOWN) return false;
00088       if(m.isNull()) return true;
00089       if(m->getKind() == GK_UNKNOWN) return false;
00090       return !(_kind == m->getKind());
00091    }
00092    /// this prints when you have a bad kind...
00093    /// might want to print an err insteand of a derr
00094    virtual void kindErr(const char *where = 0)
00095    {
00096       derr("Invalid Kind", where);
00097    }
00098 
00099    bool mpsChanged();
00100    gutz::arrayo1i _lastCh; ///keep track of changes
00101 
00102    /// generic tape management
00103    void   addTape(TapeSPVec &v, TapeSP t);
00104    void   insertTape(TapeSPVec &v, int i, TapeSP t);
00105    void   setTape(TapeSPVec &v, int i, TapeSP t);
00106    TapeSP getTape(TapeSPVec &v, int i);
00107    void   delTape(TapeSPVec &v, int i);
00108    void   delTape(TapeSPVec &v, TapeSP t);
00109 
00110    virtual GrinderKeysSP buildFPEnvKeys();
00111 
00112    MetaProgSPVec _mprogs;
00113    
00114    int _kind;
00115 };
00116 
00117 //////////////////////////////////////////////////////////////////
00118 /// typed base classes for specific cranks
00119 //////////////////////////////////////////////////////////////////
00120 
00121 ///////////////////////
00122 /// vertex
00123 ///////////////////////
00124 
00125 class VPCrank : public Crank {
00126 public:
00127    virtual ~VPCrank() {}
00128 
00129    virtual glift::VertexShaderSP getVertShader() = 0;
00130 
00131 protected:
00132    VPCrank() : Crank(GK_VERTEX) {}
00133    VPCrank(const VPCrank &vpc);
00134 
00135    glift::VertexShaderSP _lastVP;
00136 };
00137 
00138 ///////////////////////
00139 /// fragment
00140 ///////////////////////
00141 
00142 class FPCrank : public Crank {
00143 public:
00144    virtual ~FPCrank() {}
00145 
00146    virtual glift::PixelShaderSP getPixelShader() = 0;
00147 
00148 protected:
00149    FPCrank() : Crank(GK_FRAGMENT) {}
00150    FPCrank(const FPCrank &vpc);
00151 
00152    glift::PixelShaderSP _lastPS;
00153 };
00154 
00155 #endif

Send questions, comments, and bug reports to:
jmk