00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __SGL_TEX_COORDS_HPP
00026 #define __SGL_TEX_COORDS_HPP
00027
00028 #include <sgl.h>
00029 #include <sglDataPtr.hpp>
00030
00036 class SGL_DLL_API sglTexCoords
00037 {
00038 typedef void (APIENTRY *FuncType1)(const void*);
00039 typedef void (APIENTRY *FuncType2)(GLenum, const void*);
00040
00041 public:
00046 sglTexCoords(float *tex_coords, unsigned int size = 2)
00047 : m_data_ptr(NULL), m_start(NULL)
00048 { set(new sglNoRefDataPtr(tex_coords), sglDataPtr::eFLOAT, size); }
00049
00061 sglTexCoords(sglDataPtr *data = NULL,
00062 sglDataPtr::DataTypeEnum type = sglDataPtr::eFLOAT,
00063 int size = 2,
00064 int offset = 0,
00065 int stride = 0)
00066 : m_data_ptr(NULL), m_start(NULL)
00067 { set(data, type, size, offset, stride); }
00068
00070 ~sglTexCoords() { derefDataPtr(); }
00071
00073 sglTexCoords(const sglTexCoords &rhs)
00074 : m_data_ptr(rhs.m_data_ptr), m_type(rhs.m_type),
00075 m_size(rhs.m_size), m_stride(rhs.m_stride),
00076 m_gltype(rhs.m_gltype), m_byte_inc(rhs.m_byte_inc),
00077 m_start(rhs.m_start), m_func1(rhs.m_func1), m_func2(rhs.m_func2)
00078 { if (m_data_ptr) m_data_ptr->ref(); }
00079
00081 sglTexCoords &operator=(const sglTexCoords &rhs);
00082
00094 void set(sglDataPtr *data,
00095 sglDataPtr::DataTypeEnum type = sglDataPtr::eFLOAT,
00096 int size = 2,
00097 int offset = 0,
00098 int stride = 0);
00099
00103 sglDataPtr* getDataPtr() const { return m_data_ptr; }
00104
00108 sglDataPtr::DataTypeEnum getType() const { return m_type; }
00109
00113 int getNumDimensions() const { return m_size; }
00114
00119 int getOffset() const
00120 { return m_data_ptr ? (m_start - (char*)m_data_ptr->getData()) : 0; }
00121
00127 int getStride() const { return m_stride; }
00128
00129
00130
00131
00132
00133
00134 void apply(unsigned int index) const
00135 {
00136 if (m_start)
00137 m_func1(m_start + m_byte_inc * index);
00138 }
00139 void applyMulti(GLenum unit, unsigned int index) const
00140 {
00141 if (m_start)
00142 m_func2(unit, m_start + m_byte_inc * index);
00143 }
00144
00145 static void applySet(const vector<sglTexCoords> &tc,
00146 unsigned int index,
00147 GLenum max)
00148 {
00149 vector<sglTexCoords>::const_iterator it = tc.begin();
00150 it->apply(index);
00151 for (GLenum unit = GL_TEXTURE0 + 1; unit != max; ++unit)
00152 {
00153 ++it;
00154 it->applyMulti(unit, index);
00155 }
00156 }
00157
00158 static void applyArraySet(const vector<sglTexCoords> &tc)
00159 {
00160 if (!tc.empty())
00161 {
00162 vector<sglTexCoords>::const_iterator it = tc.begin();
00163 if (it->m_start)
00164 {
00165 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
00166 glTexCoordPointer(it->m_size, it->m_gltype,
00167 it->m_stride, it->m_start);
00168 }
00169 }
00170 }
00171
00172 static void applyArraySetMulti(const vector<sglTexCoords> &tc)
00173 {
00174 vector<sglTexCoords>::const_iterator it = tc.begin();
00175 vector<sglTexCoords>::const_iterator end =
00176 SGL_MIN(it+sgl::s_num_texture_units, tc.end());
00177 for (GLenum unit = GL_TEXTURE0;
00178 it != end;
00179 ++it, ++unit)
00180 {
00181 if (it->m_start)
00182 {
00183 sgl::setClientActiveTextureUnit(unit);
00184 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
00185 glTexCoordPointer(it->m_size, it->m_gltype,
00186 it->m_stride, it->m_start);
00187 }
00188 }
00189 }
00190
00191 bool isValid() const { return m_start != NULL; }
00192 int getInc() const { return m_byte_inc; }
00193 int getSize() const { return m_size; }
00194 sglDataPtr::DataTypeEnum getDataType() const { return m_type; }
00195 int getTypeIndex() const { return (((m_size-1) << 3) | m_type); }
00196
00197 typedef const char* iterator;
00198 iterator begin() const { return m_start; }
00199
00200 void printInfo(ostream &ostrm, const char *indent_string) const;
00201
00202 private:
00203 void derefDataPtr();
00204
00205 private:
00206 sglDataPtr *m_data_ptr;
00207 sglDataPtr::DataTypeEnum m_type;
00208 int m_size;
00209 int m_stride;
00210
00211 GLenum m_gltype;
00212 int m_byte_inc;
00213 char *m_start;
00214 void (APIENTRY *m_func1)(const void*);
00215 void (APIENTRY *m_func2)(GLenum, const void*);
00216
00217 static FuncType1 s_func1[32];
00218 static FuncType2* s_func2[32];
00219 };
00220
00221 #endif