Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglGeoSet.hpp

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sglGeoSet.hpp
00021  *  Created: 22 October 1997
00022  *  Summary: Contains vertex, color, and normal data for geometry (texcoords
00023  *           have been moved to sglDrawable with setting of state).  Specific
00024  *           primitive types are defined in the subclasses
00025  *****************************************************************************/
00026 
00027 #ifndef __SGL_GEOSET_HPP
00028 #define __SGL_GEOSET_HPP
00029 
00030 #include <sgl.h>
00031 #include <sglVector.hpp>
00032 #include <sglDrawable.hpp>
00033 #include <sglGeoSetDataPtr.hpp>
00034 
00035 //============================================================================
00036 
00104 class SGL_DLL_API sglGeoSet : public sglDrawable
00105 {
00106 public:
00108    enum BindEnum {eOFF,
00109                   eOVERALL,
00110                   ePER_PRIM,
00111                   ePER_VERTEX};
00112 
00113 public:
00115    sglGeoSet();
00117    virtual ~sglGeoSet();
00118 
00120    virtual sglStats::PrimEnum getPrimType() const = 0;
00122    virtual GLenum getGLPrimType() const = 0;
00124    virtual unsigned int getPrimSize() const = 0;
00125 
00127    unsigned int getNumPrims() const {return m_num_prims;}
00129    void setNumPrims(unsigned int num);
00130 
00132    void setCoordList(sglVec3f *alist)
00133       { setCoordList(new sglNoRefDataPtr(alist)); }
00134 
00148    void setCoordList(sglDataPtr *data,
00149                      sglDataPtr::DataTypeEnum type = sglDataPtr::eFLOAT,
00150                      int size = 3,
00151                      int offset = 0,
00152                      int stride = 0);
00153 
00155    void setNormalList(BindEnum bind, sglVec3f *alist)
00156       { setNormalList(bind, new sglNoRefDataPtr(alist)); }
00157 
00172    void setNormalList(BindEnum bind,
00173                       sglDataPtr *data,
00174                       sglDataPtr::DataTypeEnum type = sglDataPtr::eFLOAT,
00175                       int offset = 0,
00176                       int stride = 0);
00177 
00179    void setColorList(BindEnum bind, sglVec4f *alist)
00180       { setColorList(bind, new sglNoRefDataPtr(alist)); }
00181 
00196    void setColorList(BindEnum bind,
00197                      sglDataPtr *data,
00198                      sglDataPtr::DataTypeEnum type = sglDataPtr::eFLOAT,
00199                      int size = 4,
00200                      int offset = 0,
00201                      int stride = 0);
00202 
00204    BindEnum getNormalBind() const;
00206    BindEnum getColorBind() const;
00207 
00209    sglDataPtr *getCoordList() const { return m_vertices.getDataPtr(); }
00211    sglDataPtr *getNormalList() const { return m_normals.getDataPtr(); }
00213    sglDataPtr *getColorList() const { return m_colors.getDataPtr(); }
00214 
00216    sglDataPtr::DataTypeEnum getCoordType() const
00217       { return m_vertices.getDataType(); }
00219    sglDataPtr::DataTypeEnum getNormalType() const
00220       { return m_normals.getDataType(); }
00222    sglDataPtr::DataTypeEnum getColorType() const
00223       { return m_colors.getDataType(); }
00224 
00226    int getCoordSize() const { return m_vertices.getSize(); }
00228    int getColorSize() const { return m_colors.getSize(); }
00229 
00231    int getCoordOffset() const { return m_vertices.getOffset(); }
00233    int getNormalOffset() const { return m_normals.getOffset(); }
00235    int getColorOffset() const { return m_colors.getOffset(); }
00236 
00238    int getCoordStride() const { return m_vertices.getStride(); }
00240    int getNormalStride() const { return m_normals.getStride(); }
00242    int getColorStride() const { return m_colors.getStride(); }
00243 
00245    virtual bool isValid() const;
00246 
00248    virtual void addStats(sglStats &stats) const;
00249 
00251    virtual void printInfo(ostream &ostrm, const char *indent_string) const;
00252 
00253 protected:
00254    virtual bool computeBounds();
00255    virtual void updateDrawFunc();
00256 
00257    enum NormalEnum
00258    {
00259       eNORMALS_NONE         = 0x00000,
00260       eNORMALS_OVERALL      = 0x00001,
00261       eNORMALS_PER_PRIM     = 0x00002,
00262       eNORMALS_PER_VERTEX   = 0x00003
00263    };
00264 
00265    enum ColorEnum
00266    {
00267       eCOLORS_NONE          = 0x00000,
00268       eCOLORS_OVERALL       = 0x00004,
00269       eCOLORS_PER_PRIM      = 0x00008,
00270       eCOLORS_PER_VERTEX    = 0x0000c
00271    };
00272 
00273    enum ModeEnum
00274    {
00275       eNORMALS              = 0x00003,
00276       eCOLORS               = 0x0000c,
00277       eMULTI_TEXTURE        = 0x00010,
00278       ePREFETCH             = 0x00020
00279    };
00280 
00281    // For bezier classes.
00282    enum TexCoordsEnum
00283    {
00284       eTEXCOORDS_OVERALL    = 0x01000,
00285       eTEXCOORDS_PER_PRIM   = 0x02000,
00286       eTEXCOORDS_PER_VERTEX = 0x04000,
00287       eTEXCOORDS            = 0x07000
00288    };
00289 
00290 private:  // not implemented
00291    sglGeoSet(const sglGeoSet &);
00292    sglGeoSet &operator=(const sglGeoSet &);
00293 
00294 #ifdef INLINE_BOXBOUND
00295    typedef void (*BBFunc)(
00296       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00297 
00298    static void buildBoxBound2s(
00299       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00300    static void buildBoxBound2i(
00301       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00302    static void buildBoxBound2f(
00303       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00304    static void buildBoxBound2d(
00305       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00306    static void buildBoxBound3s(
00307       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00308    static void buildBoxBound3i(
00309       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00310    static void buildBoxBound3f(
00311       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00312    static void buildBoxBound3d(
00313       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00314    static void buildBoxBound4s(
00315       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00316    static void buildBoxBound4i(
00317       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00318    static void buildBoxBound4f(
00319       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00320    static void buildBoxBound4d(
00321       sglBoxBound &bbox, void *ptr, int vert_inc, int num_verts);
00322 #endif
00323 
00324    void drawVT(const vector<sglTexCoords> &tex_coords) const;
00325    void drawVNoT(const vector<sglTexCoords> &tex_coords) const;
00326    void drawVNpT(const vector<sglTexCoords> &tex_coords) const;
00327    void drawVNvT(const vector<sglTexCoords> &tex_coords) const;
00328    void drawVCoT(const vector<sglTexCoords> &tex_coords) const;
00329    void drawVCoNoT(const vector<sglTexCoords> &tex_coords) const;
00330    void drawVCoNpT(const vector<sglTexCoords> &tex_coords) const;
00331    void drawVCoNvT(const vector<sglTexCoords> &tex_coords) const;
00332    void drawVCpT(const vector<sglTexCoords> &tex_coords) const;
00333    void drawVCpNoT(const vector<sglTexCoords> &tex_coords) const;
00334    void drawVCpNpT(const vector<sglTexCoords> &tex_coords) const;
00335    void drawVCpNvT(const vector<sglTexCoords> &tex_coords) const;
00336    void drawVCvT(const vector<sglTexCoords> &tex_coords) const;
00337    void drawVCvNoT(const vector<sglTexCoords> &tex_coords) const;
00338    void drawVCvNpT(const vector<sglTexCoords> &tex_coords) const;
00339    void drawVCvNvT(const vector<sglTexCoords> &tex_coords) const;
00340 
00341 #ifndef SGL_NO_VERTEX_ARRAYS
00342    void drawVTm(const vector<sglTexCoords> &tex_coords) const;
00343    void drawVNoTm(const vector<sglTexCoords> &tex_coords) const;
00344    void drawVNpTm(const vector<sglTexCoords> &tex_coords) const;
00345    void drawVNvTm(const vector<sglTexCoords> &tex_coords) const;
00346    void drawVCoTm(const vector<sglTexCoords> &tex_coords) const;
00347    void drawVCoNoTm(const vector<sglTexCoords> &tex_coords) const;
00348    void drawVCoNpTm(const vector<sglTexCoords> &tex_coords) const;
00349    void drawVCoNvTm(const vector<sglTexCoords> &tex_coords) const;
00350    void drawVCpTm(const vector<sglTexCoords> &tex_coords) const;
00351    void drawVCpNoTm(const vector<sglTexCoords> &tex_coords) const;
00352    void drawVCpNpTm(const vector<sglTexCoords> &tex_coords) const;
00353    void drawVCpNvTm(const vector<sglTexCoords> &tex_coords) const;
00354    void drawVCvTm(const vector<sglTexCoords> &tex_coords) const;
00355    void drawVCvNoTm(const vector<sglTexCoords> &tex_coords) const;
00356    void drawVCvNpTm(const vector<sglTexCoords> &tex_coords) const;
00357    void drawVCvNvTm(const vector<sglTexCoords> &tex_coords) const;
00358 #endif
00359 
00360    class Initializer;
00361    friend class Initializer;
00362    static void setupFuncTable();
00363 
00364 protected:
00365    unsigned int m_mode; // encodes everything about this geoset
00366 
00367    unsigned int m_num_prims;
00368 
00369    sglVertexPtr m_vertices;
00370    sglNormalPtr m_normals;
00371    sglColorPtr  m_colors;
00372 
00373    enum BoundsEnum {eNUMPRIMS  = 0x01,
00374                     eLENGTHS   = 0x02,
00375                     eVERTICES  = 0x04,
00376                     eVINDICES  = 0x08};
00377 
00378    unsigned int m_compute_bounds;
00379 
00380 private:
00381    static DrawFunc s_func_table[(eMULTI_TEXTURE|eCOLORS|eNORMALS)+1];
00382 #ifdef INLINE_BOXBOUND
00383    static BBFunc s_bb_func_table[24];
00384 #endif
00385    static Initializer sInitializer;
00386 };
00387 
00388 #endif

Generated at Mon Jul 1 18:00:04 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001