00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _OPENGL_INDEX_BUFFER_H_
00021 #define _OPENGL_INDEX_BUFFER_H_
00022
00023 #include <GL\glew.h>
00024 #include <boost\shared_array.hpp>
00025 #include "OpenglException.h"
00026
00027 namespace TestFrameWork
00028 {
00029
00030 template<class T>
00031 class OpenglIndexBuffer
00032 {
00033 public:
00034 OpenglIndexBuffer(boost::shared_array<T> indices, size_t indicesCount);
00035
00036 ~OpenglIndexBuffer(void);
00037
00038 GLuint GetOpenglId(void) const;
00039
00040 size_t GetIndicesCount(void) const;
00041
00042 private:
00043 GLuint m_id;
00044
00045 size_t m_indicesCount;
00046
00047 GLuint CreateBuffer(boost::shared_array<T> indices, size_t indicesCount);
00048 };
00049
00050 typedef OpenglIndexBuffer<int> OpenglIndexBuffer32;
00051 typedef boost::shared_ptr<OpenglIndexBuffer32> OpenglIndexBuffer32Ptr;
00052 typedef boost::shared_array<int> Indices32;
00053
00054 template<class T>
00055 OpenglIndexBuffer<T>::OpenglIndexBuffer(boost::shared_array<T> indices, size_t indicesCount) : m_id(CreateBuffer(indices, indicesCount)),
00056 m_indicesCount(indicesCount)
00057 {
00058
00059 }
00060
00061 template<class T>
00062 OpenglIndexBuffer<T>::~OpenglIndexBuffer(void)
00063 {
00064 glDeleteBuffers(1, &m_id);
00065 }
00066
00067 template<class T>
00068 GLuint OpenglIndexBuffer<T>::GetOpenglId(void) const
00069 {
00070 return m_id;
00071 }
00072
00073 template<class T>
00074 size_t OpenglIndexBuffer<T>::GetIndicesCount(void) const
00075 {
00076 return m_indicesCount;
00077 }
00078
00079 template<class T>
00080 GLuint OpenglIndexBuffer<T>::CreateBuffer(boost::shared_array<T> indices, size_t indicesCount)
00081 {
00082 GLuint id;
00083 glGenBuffers(1, &id);
00084 TestFrameWork::OnGLErrorThrowException();
00085
00086 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
00087 TestFrameWork::OnGLErrorThrowException();
00088
00089 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(T) * indicesCount, indices.get(), GL_STATIC_DRAW);
00090 TestFrameWork::OnGLErrorThrowException();
00091
00092 return id;
00093 }
00094
00095 }
00096
00097 #endif