00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KEOS_OGLBUFFER_H
00023 #define KEOS_OGLBUFFER_H
00024
00025 #include "KeosOGLPrerequisites.h"
00026 #include "KeosBufferBase.h"
00027 #include "KeosOGLEnum.h"
00028
00029 namespace Keos
00030 {
00031
00034 template <int Type>
00035 class COGLBuffer : public IBufferBase
00036 {
00037 public :
00038
00043 COGLBuffer(ulong nCount, uint nBuffer);
00044
00047 virtual ~COGLBuffer();
00048
00051 uint GetBuffer() const;
00052
00053 private :
00054
00057 void* Lock(ulong nOffset, ulong nSize, ulong nFlags);
00058
00061 void Unlock();
00062
00063
00064 uint m_nBuffer;
00065 };
00066
00067
00068 typedef COGLBuffer<GL_ARRAY_BUFFER_ARB> COGLVertexBuffer;
00069 typedef COGLBuffer<GL_ELEMENT_ARRAY_BUFFER_ARB> COGLIndexBuffer;
00070
00071
00072
00073
00074
00075
00076
00077 template <int Type>
00078 inline COGLBuffer<Type>::COGLBuffer(ulong nCount, uint nBuffer) :
00079 IBufferBase(nCount),
00080 m_nBuffer (nBuffer)
00081 {}
00082
00083
00084 template <int Type>
00085 inline COGLBuffer<Type>::~COGLBuffer()
00086 {
00087 if (m_nBuffer)
00088 COGLRenderSystem::glDeleteBuffersARB(1, &m_nBuffer);
00089 }
00090
00091
00092 template <int Type>
00093 inline uint COGLBuffer<Type>::GetBuffer() const
00094 {
00095 return m_nBuffer;
00096 }
00097
00098
00099 template <int Type>
00100 inline void* COGLBuffer<Type>::Lock(ulong nOffset, ulong nSize, ulong nFlags)
00101 {
00102 COGLRenderSystem::glBindBufferARB(Type, m_nBuffer);
00103 uchar* pBuffer = reinterpret_cast<uchar*>(COGLRenderSystem::glMapBufferARB(Type, COGLEnum::LockFlags(nFlags)));
00104
00105 return pBuffer + nOffset;
00106 }
00107
00108
00109 template <int Type>
00110 inline void COGLBuffer<Type>::Unlock()
00111 {
00112 COGLRenderSystem::glUnmapBufferARB(Type);
00113 }
00114
00115 }
00116
00117 #endif // KEOS_OGLBUFFER_H