KeosOGLBuffer.h

Go to the documentation of this file.
00001 /*
00002  * This source file is part of KEOS (Free 3D Engine)
00003  * For the latest info, see http://www.keosengine.org/
00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
00005  *
00006  * This program is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free Software
00008  * Foundation; either version 2 of the License, or (at your option) any later
00009  * version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00018  * http://www.gnu.org/copyleft/lesser.txt.
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     // OGL buffer id
00064     uint m_nBuffer;
00065   };
00066 
00067   // Index and vertex buffer definition from COGLBuffer template
00068   typedef COGLBuffer<GL_ARRAY_BUFFER_ARB>         COGLVertexBuffer;
00069   typedef COGLBuffer<GL_ELEMENT_ARRAY_BUFFER_ARB> COGLIndexBuffer;
00070 
00071 
00072   //=======================================================================
00073   // COGLBuffer inline functions
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 } // namespace Keos
00116 
00117 #endif // KEOS_OGLBUFFER_H

Generated on Fri Mar 9 14:29:04 2007 for Keos by  doxygen 1.5.1-p1