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

drawAlgorithm.h

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////
00002 // 6/28/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_DRAW_ALGORITHM_H
00020 #define GLIFT_DRAW_ALGORITHM_H
00021 
00022 #include <iostream>
00023 #include <arrayGutz.h>
00024 #include <GL/glew.h>
00025 #include "../core/gliftObject.h"
00026 #include "../texCoordGen/texCoordGen.h"
00027 
00028 namespace glift {
00029 
00030    /// TODO: Extend this as more algorithm subclasses are defined
00031 enum DrawAlg { GLIFT_DRAW_IMM, GLIFT_DRAW_ARR };
00032 
00033 /////////////////////////////////////////////////////////////////////////
00034 ///
00035 /// DrawAlgorithm - Interface for an OpenGL Drawing algorithm
00036 /// 
00037 /// - Intended to be created using the 'DrawAlg' enumeration 
00038 ///   and the 'makeDrawAlg( DrawAlg type )' factory function.
00039 /// - Essentially a functor but with ->draw(...) syntax
00040 /// - TODO: These really should all be Singleton classes...
00041 ///
00042 /// Base class
00043 class DrawAlgorithm : public GliftObject
00044 {
00045 public:
00046    virtual void draw( GLenum primType,
00047       const gutz::arrayw2f& vert, 
00048       const MultiTexCoord* curTexCoords,
00049       const gutz::arrayw2f& norm, 
00050       const gutz::arrayw2f& color, 
00051       const gutz::arrayw1ub& edgeFlag,
00052       const gutz::arrayw1ui* curIndices ) = 0;
00053 };
00054 
00055 /// DrawAlgImm - Standard OpenGL drawing algorithm. 
00056 class DrawAlgImm : public DrawAlgorithm
00057 {
00058 public:
00059    virtual void draw( GLenum primType, 
00060       const gutz::arrayw2f& vert, 
00061       const MultiTexCoord* curTexCoords,
00062       const gutz::arrayw2f& norm, 
00063       const gutz::arrayw2f& color, 
00064       const gutz::arrayw1ub& edgeFlag,
00065       const gutz::arrayw1ui* curIndices );
00066 
00067 private:
00068    void draw( int vertNum, const gutz::arrayw2f& vert, const MultiTexCoord* curTexCoords, 
00069       const gutz::arrayw2f& norm, const gutz::arrayw2f& color, 
00070       const gutz::arrayw1ub& edgeFlag );
00071 
00072    void setVertPos( const gutz::arrayw2f& vert, int vertNum );
00073    void setTexCoords( const MultiTexCoord* curTexCoords, GLint vertNum );
00074    void outputTexCoords( const MultiTexCoord& texCoords, int texCoordDimen, 
00075       int texUnit, int vertNum );
00076 };
00077 
00078 /// DrawAlgArr - Vertex Array OpenGL drawing algorithm.
00079 /// NOTE: Assumes that all necessary arrays have been enabled!!!
00080 class DrawAlgArr : public DrawAlgorithm
00081 {
00082 public:
00083    virtual void draw( GLenum primType, 
00084       const gutz::arrayw2f& vert, 
00085       const MultiTexCoord* curTexCoords,
00086       const gutz::arrayw2f& norm, 
00087       const gutz::arrayw2f& color, 
00088       const gutz::arrayw1ub& edgeFlag,
00089       const gutz::arrayw1ui* curIndices );
00090 
00091    void enable( const gutz::arrayw2f& vert, const MultiTexCoord* curTexCoords,
00092       const gutz::arrayw2f& norm, const gutz::arrayw2f& color, 
00093       const gutz::arrayw1ub& edgeFlag );
00094    void disable( const gutz::arrayw2f& vert, const MultiTexCoord* curTexCoords,
00095       const gutz::arrayw2f& norm, const gutz::arrayw2f& color, 
00096       const gutz::arrayw1ub& edgeFlag );
00097 };
00098 
00099 /// Factory function
00100 inline DrawAlgorithm* makeDrawAlg( DrawAlg type ) 
00101 {
00102    DrawAlgorithm* drawAlg = NULL;       
00103 
00104    switch(type) {
00105 case GLIFT_DRAW_IMM: drawAlg = new DrawAlgImm(); break;
00106 case GLIFT_DRAW_ARR: drawAlg = new DrawAlgArr(); break;
00107 default:                         drawAlg = new DrawAlgImm(); break;
00108    }
00109 
00110    return drawAlg;
00111 }
00112 
00113 } /// End of namespace glift
00114 
00115 #endif

Send questions, comments, and bug reports to:
jmk