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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 #ifndef VRS_OPENGL_VERTEXATTRIBUTEBUFFEROBJECTGL_H
00102 #define VRS_OPENGL_VERTEXATTRIBUTEBUFFEROBJECTGL_H
00103
00104 #include <vrs/vector.h>
00105 #include <vrs/vertexdata.h>
00106 #include <vrs/container/staticarray.h>
00107 #include <vrs/opengl/bufferobjectgl.h>
00108 #include <vrs/opengl/openglconfig.h>
00109 #include <vector>
00110
00111 namespace VRS {
00112
00113 class Color;
00114
00117 class VRS_CORE_API BaseVertexAttributeBufferObjectGL : public BufferObjectGL {
00118 public:
00119 virtual GLenum componentType() const = 0;
00123 virtual UINT components() const = 0;
00127 virtual UINT elements() const = 0;
00129
00130 Iterator<Vector>* copyIntoVectorIterator() const;
00135 Iterator<Color>* copyIntoColorIterator() const;
00140 Iterator<unsigned int>* copyIntoIndexIterator() const;
00146
00147 virtual SO<BaseVertexAttributeBufferObjectGL> clone(EngineGL* engine, UsagePattern usagePattern) = 0;
00148
00150 virtual SO<BaseVertexAttributeBufferObjectGL> clone(EngineGL* engine, UINT elements, UsagePattern usagePattern) = 0;
00151
00152 VRS_TYPEINFO(BaseVertexAttributeBufferObjectGL, BufferObjectGL);
00153 VRS_SERIALIZABLE_ABSTRACT_CLASS(BaseVertexAttributeBufferObjectGL);
00154
00155 protected:
00156 BaseVertexAttributeBufferObjectGL(EngineGL* engine, UINT bytes, const void* pointer,
00157 DataType type, UsagePattern usage)
00158 : BufferObjectGL(engine, bytes, pointer, type, usage) {
00159 }
00160 BaseVertexAttributeBufferObjectGL(UINT bytes, void* pointer, SharedObj* owner = NULL)
00161 : BufferObjectGL(bytes, pointer, owner) {
00162 }
00163 };
00164
00165 template<typename T>
00166 class VertexAttributeBufferObjectGL : public BaseVertexAttributeBufferObjectGL {
00167 public:
00168 VertexAttributeBufferObjectGL(EngineGL* engine, UINT elements,
00169 DataType type, UsagePattern usagePattern);
00175 VertexAttributeBufferObjectGL(EngineGL* engine, Iterator<T>* iter,
00176 DataType type, UsagePattern usagePattern);
00177 VertexAttributeBufferObjectGL(EngineGL* engine, const std::vector<T>& values,
00178 DataType type, UsagePattern usagePattern);
00184
00185 VertexAttributeBufferObjectGL(Iterator<T>* iter);
00191 virtual ~VertexAttributeBufferObjectGL();
00192
00193 virtual GLenum componentType() const { return getComponentType(static_cast<T*>(NULL)); }
00194 virtual UINT components() const { return getComponents(static_cast<T*>(NULL)); }
00195 virtual UINT elements() const { return (bytes() / sizeof(T)); }
00197
00198 T* mapAttributePointer(MapAccess access) { return static_cast<T*>(mapPointer(access)); }
00199 const T* mapAttributePointer(MapAccess access) const { return static_cast<const T*>(mapPointer(access)); }
00200 bool unmapAttributePointer() const { return unmapPointer(); }
00201 bool attributePointerIsMapped() const { return pointerIsMapped(); }
00206 void update(Iterator<T>* iter, UINT offset = 0);
00207 void update(const std::vector<T>& values, UINT offset = 0);
00212 void replace(Iterator<T>* iter);
00213 void replace(const std::vector<T>& values);
00218 virtual SO<BaseVertexAttributeBufferObjectGL> clone(EngineGL* engine, UsagePattern usagePattern);
00219 virtual SO<BaseVertexAttributeBufferObjectGL> clone(EngineGL* engine, UINT elements, UsagePattern usagePattern);
00220
00221 VRS_TYPEINFO(VertexAttributeBufferObjectGL, BaseVertexAttributeBufferObjectGL);
00222 VRS_SERIALIZABLE(VertexAttributeBufferObjectGL);
00223
00224 protected:
00225 static UINT getComponents(const GLubyte* ) { return 1; }
00226 static UINT getComponents(const GLbyte* ) { return 1; }
00227 static UINT getComponents(const GLushort* ) { return 1; }
00228 static UINT getComponents(const GLshort* ) { return 1; }
00229 static UINT getComponents(const GLuint* ) { return 1; }
00230 static UINT getComponents(const GLint* ) { return 1; }
00231 #ifdef __APPLE__
00232
00233
00234 #endif // __APPLE__
00235 static UINT getComponents(const GLfloat* ) { return 1; }
00236 static UINT getComponents(const GLdouble* ) { return 1; }
00237
00238 static UINT getComponents(const bool* ) { return 1; }
00239 template<unsigned int DIM, typename TYPE>
00240 static UINT getComponents(const VertexData<DIM, TYPE>* ) { return DIM; }
00241
00242 static GLenum getComponentType(const GLubyte* ) { return GL_UNSIGNED_BYTE; }
00243 static GLenum getComponentType(const GLbyte* ) { return GL_BYTE; }
00244 static GLenum getComponentType(const GLushort* ) { return GL_UNSIGNED_SHORT; }
00245 static GLenum getComponentType(const GLshort* ) { return GL_SHORT; }
00246 static GLenum getComponentType(const GLuint* ) { return GL_UNSIGNED_INT; }
00247 static GLenum getComponentType(const GLint* ) { return GL_INT; }
00248 #ifdef __APPLE__
00249
00250
00251 #endif // __APPLE__
00252 static GLenum getComponentType(const GLfloat* ) { return GL_FLOAT; }
00253 static GLenum getComponentType(const GLdouble* ) { return GL_DOUBLE; }
00254
00255 static GLenum getComponentType(const bool* ) { return GL_UNSIGNED_BYTE; }
00256 template<unsigned int DIM, typename TYPE>
00257 static GLenum getComponentType(const VertexData<DIM, TYPE>* ) { return getComponentType(static_cast<TYPE*>(NULL)); }
00258
00259 private:
00260 VertexAttributeBufferObjectGL();
00261 NonPersistentStaticArray<T>* data_;
00262 };
00263
00264 }
00265
00266 #include <vrs/opengl/vertexattributebufferobjectgl.tli>
00267
00268 #endif // VRS_OPENGL_VERTEXATTRIBUTEBUFFEROBJECTGL_H