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

primGL.h

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////
00002 // 6/6/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 GLIFT_PRIM_GL_H__
00020 #define GLIFT_PRIM_GL_H__
00021 
00022 #include "rawPrim.h"
00023 #include "drawAlgorithm.h"
00024 #include <GL/glew.h>
00025 
00026 namespace glift {
00027 
00028 /////////////////////////////////////////////////////////////////////////
00029 ///
00030 ///  PrimGL - GLIFT wrapper for an OpenGL primitive
00031 ///
00032 ///  - The 'm_scale' member requires some explaining:
00033 ///    It is the dimensions of the primitive that are used to determine
00034 ///    what size primitive is being texture mapped. It's values should
00035 ///    match the x,y,z dimensions (perhaps bounding box?) of the primitive.
00036 ///    It's values must be greater than 0 and should default to 1.0;
00037 ///
00038 ///  - 'drawAlgType' is one of the enumerated types def'd in "drawAlgorithm.h"
00039 ///    It defines the drawing algorithm to use (immediate, vertex array, etc).
00040 ///
00041 ///////////////////////////////////////////////////////////////////////
00042 
00043 class _export_ PrimGL : public SinglePrim
00044 {
00045 public: 
00046    PrimGL( GLenum primType, GLint minVerts, GLint vertDivisor, const gutz::vec3f& scale,
00047       const gutz::arrayw2f&     vert, 
00048       const gutz::arrayw2f&     texCoord, 
00049       const gutz::arrayw2f&     norm            = gutz::arrayo2f(),  
00050       const gutz::arrayw1ui&    indices         = gutz::arrayo1ui(), 
00051       DrawAlg                                   drawAlgType = GLIFT_DRAW_IMM ); 
00052 
00053    PrimGL( GLenum primType, GLint minVerts, GLint vertDivisor, const gutz::vec3f& scale,
00054       const gutz::arrayw2f&     vert, 
00055       const gutz::arrayw2f&     texCoord, 
00056       const gutz::arrayw2f&     normalize       = gutz::arrayo2f(), 
00057       const gutz::arrayw1ui&    indices         = gutz::arrayo1ui(), 
00058       const gutz::arrayw2f&     color           = gutz::arrayo2f(), 
00059       const gutz::arrayw1ub&    edgeFlag        = gutz::arrayo1ub(), 
00060       DrawAlg                                   drawAlgType     = GLIFT_DRAW_IMM ); 
00061 
00062    PrimGL( const PrimGL& rhs );
00063    PrimGL& operator=( const PrimGL& rhs );
00064 
00065    virtual ~PrimGL();
00066 
00067    /// Set Functions
00068    virtual void bindTexCoords( const MultiPrimTexCoord* texCoords );
00069    virtual void bindTexCoords( const MultiTexCoord* texCoords );
00070    virtual void releaseTexCoords();
00071 
00072    virtual void bindIndices( const MultiPrimIndices* indices );
00073    virtual void bindIndices( const gutz::arrayw1ui* indices ); 
00074    virtual void releaseIndices();
00075 
00076    /// Constant Accessors
00077    virtual const gutz::arrayo2f&  vert()          const                         {return m_vert;}
00078    virtual const gutz::arrayo2f&  texCoord() const                              {return m_curTexCoords ? (*m_curTexCoords)[0]           : m_texCoords[0];}
00079    virtual const gutz::arrayo2f&  texCoord(int texUnit) const   {return m_curTexCoords ? (*m_curTexCoords)[texUnit] : m_texCoords[0];}
00080    virtual int                             numVerts() const                     {return m_vert.dim(0);}
00081    virtual const gutz::vec3f&     scale()    const                      {return m_scale;}
00082    virtual bool                                    hasTexCoords() const                 {return !m_texCoords[0].empty(); }
00083 
00084 protected:
00085    virtual void drawDef();
00086 
00087 private:
00088    GLenum                       m_primType;
00089    GLint                        m_minVerts;
00090    GLint                        m_vertDiv;
00091    gutz::vec3f                  m_scale;
00092 
00093    gutz::arrayo2f                       m_vert;
00094    MultiTexCoord                        m_texCoords;    /// m_texCoord[ texUnit ][ vertNum ][ texCoord ]
00095    const MultiTexCoord*         m_curTexCoords; /// The ptr to the current texture coordinates
00096    gutz::arrayo2f                       m_norm;
00097    gutz::arrayo2f                       m_color;
00098    gutz::arrayo1ub                      m_edgeFlag;             /// Is each vertex GL_TRUE/GL_FALSE an edge-forming vert?
00099    gutz::arrayo1ui                      m_indices;              /// Original indices (empty if all verts are to be drawn)
00100    const gutz::arrayw1ui*       m_curIndices;   /// Indices of which verts to draw (all drawn if empty)
00101    DrawAlgorithm*                       m_drawAlg;
00102 
00103    PrimGL();
00104    void initMembers(const PrimGL& rhs);
00105    void initMembers( GLenum primType, GLint minVerts, GLint vertDivisor, const gutz::vec3f& scale,
00106       const gutz::arrayw2f& vert,               const MultiTexCoord& texCoord,                  const MultiTexCoord* curTexCoords,
00107       const gutz::arrayw2f& normal,     const gutz::arrayw1ui& indices,         const gutz::arrayw2f& color, 
00108       const gutz::arrayw1ub& edgeFlag,  const gutz::arrayw1ui* curIndices,      DrawAlgorithm* drawAlg );
00109 
00110    void verifyScale();
00111    void verifySizes();
00112    void verifyMinVerts();
00113    void verifyPrimType();
00114    void verifyNumPrims();
00115    void setVertPos(             const gutz::arrayw2f& vert, int vertNum );
00116    void setTexCoords(           const Vecarrayw2f* curTexCoords, GLint vert );  /// Multi-texturing
00117    void outputTexCoords(        const MultiTexCoord& texCoords, int texCoordDimen, int texUnit, int vertNum );
00118 };
00119 
00120 } /// End of namespace glift
00121 
00122 #endif
00123 

Send questions, comments, and bug reports to:
jmk