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

sglGeoSetDataPtr.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: sglGeoSetDataPtr.hpp
00021  *   Author: Tom Stimson
00022  *  Created: 6 April 2002
00023  *  Summary: Container class used internally by the sglGeoSet classes.
00024  *****************************************************************************/
00025 
00026 #ifndef __SGL_GEO_SET_DATA_PTR_HPP
00027 #define __SGL_GEO_SET_DATA_PTR_HPP
00028 
00029 #include <sglDataPtr.hpp>
00030 #include <sglVector.hpp>
00031 
00032 #ifdef USE_SHORT_INDEX
00033 # define GLINDEXTYPE GL_UNSIGNED_SHORT
00034    typedef unsigned short sglIndexType;
00035 #else
00036 # define GLINDEXTYPE GL_UNSIGNED_INT
00037    typedef unsigned int sglIndexType;
00038 #endif
00039 
00040 
00043 class SGL_DLL_API sglGeoSetDataPtr
00044 {
00045 public:
00046    sglGeoSetDataPtr()
00047       : m_data_ptr(NULL), m_stride(0) {}
00048 
00049    virtual ~sglGeoSetDataPtr()
00050       { derefDataPtr(); }
00051 
00052    sglDataPtr *getDataPtr() const { return m_data_ptr; }
00053    int getStride() const { return m_stride; }
00054 
00055    typedef void (APIENTRY *FuncType1)(const void*);
00056 
00057 protected:
00058    void derefDataPtr();
00059 
00060    void set(sglDataPtr *data, int stride);
00061 
00062    static void APIENTRY invalidFunc(const void*);
00063 
00064 private:
00065    // Not Implemented.
00066    sglGeoSetDataPtr(const sglGeoSetDataPtr &);
00067    sglGeoSetDataPtr &operator=(const sglGeoSetDataPtr &);
00068 
00069 protected:
00070    sglDataPtr               *m_data_ptr;
00071    int                       m_stride;
00072 };
00073 
00076 class SGL_DLL_API sglMultiTypePtr : public sglGeoSetDataPtr
00077 {
00078 public:
00079    sglMultiTypePtr() : sglGeoSetDataPtr(),
00080       m_type(sglDataPtr::eFLOAT), m_gltype(0), m_size(0), m_byte_inc(0),
00081       m_start(NULL), m_func(invalidFunc) {}
00082    virtual ~sglMultiTypePtr() {}
00083 
00084    void set(sglDataPtr *data, sglDataPtr::DataTypeEnum type,
00085             int size, int offset, int stride);
00086 
00087    bool isValid() const { return (m_func != invalidFunc); }
00088 
00089    FuncType1 getFunc() const { return m_func; }
00090    int getInc() const { return m_byte_inc; }
00091    int getSize() const { return m_size; }
00092    sglDataPtr::DataTypeEnum getDataType() const { return m_type; }
00093 
00094    int getOffset() const
00095       { return m_data_ptr ? (m_start - (char*)m_data_ptr->getData()) : 0; }
00096 
00097    typedef const char* iterator;
00098    iterator begin() const { return m_start; }
00099 
00100    void apply0() const { m_func(m_start); }
00101 
00102 protected:
00103    virtual void setFunc() = 0;
00104 
00105 private:
00106    // Not Implemented.
00107    sglMultiTypePtr(const sglMultiTypePtr &);
00108    sglMultiTypePtr &operator=(const sglMultiTypePtr &);
00109 
00110 protected:
00111    sglDataPtr::DataTypeEnum  m_type;
00112    GLenum                    m_gltype;
00113    int                       m_size;
00114    int                       m_byte_inc;
00115    char                     *m_start;
00116    FuncType1                 m_func;
00117 };
00118 
00121 class SGL_DLL_API sglVertexPtr : public sglMultiTypePtr
00122 {
00123 public:
00124    sglVertexPtr() : sglMultiTypePtr() {}
00125    virtual ~sglVertexPtr() {}
00126 
00127    void applyArray() const
00128       {
00129          glEnableClientState(GL_VERTEX_ARRAY);
00130          glVertexPointer(m_size, m_gltype, m_stride, m_start);
00131       }
00132 
00133    int getTypeIndex() const { return (((m_size-2) << 3) | m_type); }
00134 
00135 protected:
00136    virtual void setFunc();
00137 
00138 private:
00139    // Not Implemented.
00140    sglVertexPtr(const sglVertexPtr &);
00141    sglVertexPtr &operator=(const sglVertexPtr &);
00142 
00143 private:
00144    static FuncType1 s_func[24];
00145 };
00146 
00149 class SGL_DLL_API sglNormalPtr : public sglMultiTypePtr
00150 {
00151 public:
00152    sglNormalPtr() : sglMultiTypePtr() {}
00153    virtual ~sglNormalPtr() {}
00154 
00155    void applyArray() const
00156       {
00157          glEnableClientState(GL_NORMAL_ARRAY);
00158          glNormalPointer(m_gltype, m_stride, m_start);
00159       }
00160 
00161    int getTypeIndex() const { return m_type; }
00162 
00163 protected:
00164    virtual void setFunc();
00165 
00166 private:
00167    static FuncType1 s_func[8];
00168 };
00169 
00172 class SGL_DLL_API sglColorPtr : public sglMultiTypePtr
00173 {
00174 public:
00175    sglColorPtr() : sglMultiTypePtr() {}
00176    virtual ~sglColorPtr() {}
00177 
00178    void applyArray() const
00179       {
00180          glEnableClientState(GL_COLOR_ARRAY);
00181          glColorPointer(m_size, m_gltype, m_stride, m_start);
00182       }
00183 
00184    int getTypeIndex() const { return (((m_size-3) << 3) | m_type); }
00185 
00186 protected:
00187    virtual void setFunc();
00188 
00189 private:
00190    // Not Implemented.
00191    sglColorPtr(const sglColorPtr &);
00192    sglColorPtr &operator=(const sglColorPtr &);
00193 
00194 private:
00195    static FuncType1 s_func[16];
00196 };
00197 
00198 
00201 class SGL_DLL_API sglIndexPtr : public sglGeoSetDataPtr
00202 {
00203 public:
00204    sglIndexPtr() : sglGeoSetDataPtr(), m_inc(0) {}
00205    virtual ~sglIndexPtr() {}
00206 
00207    void set(sglDataPtr *data, int offset, int stride);
00208 
00209    bool isValid() const
00210       { return m_data_ptr && m_data_ptr->getData() && m_stride >= 0; }
00211 
00212    typedef const sglIndexType* iterator;
00213 
00214    int getOffset() const
00215       { return m_data_ptr ? (
00216          (char*)m_start - (char*)m_data_ptr->getData()) : 0; }
00217 
00218    iterator begin() const { return m_start; }
00219    int getInc() const { return m_inc; }
00220 
00221 private:
00222    // Not Implemented.
00223    sglIndexPtr(const sglIndexPtr &);
00224    sglIndexPtr &operator=(const sglIndexPtr &);
00225 
00226 private:
00227    iterator  m_start;
00228    int       m_inc;
00229 };
00230 
00231 #endif

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