Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# 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
    00085     //-----------------------------------------------------------------------
    00086     template <int Type>
    00087     inline COGLBuffer<Type>::~COGLBuffer()
    00088     {
    00089         if (m_nBuffer)
    00090             COGLRenderSystem::glDeleteBuffersARB(1, &m_nBuffer);
    00091     }
    00092
    00093     //-----------------------------------------------------------------------
    00094     template <int Type>
    00095     inline uint COGLBuffer<Type>::GetBuffer() const
    00096     {
    00097         return m_nBuffer;
    00098     }
    00099
    00100     //-----------------------------------------------------------------------
    00101     template <int Type>
    00102     inline void* COGLBuffer<Type>::Lock(ulong nOffset, ulong nSize, ulong nFlags)
    00103     {
    00104         COGLRenderSystem::glBindBufferARB(Type, m_nBuffer);
    00105         uchar* pBuffer = reinterpret_cast<uchar*>(COGLRenderSystem::glMapBufferARB(Type, COGLEnum::LockFlags(nFlags)));
    00106
    00107         return pBuffer + nOffset;
    00108     }
    00109
    00110     //-----------------------------------------------------------------------
    00111     template <int Type>
    00112     inline void COGLBuffer<Type>::Unlock()
    00113     {
    00114         COGLRenderSystem::glUnmapBufferARB(Type);
    00115     }
    00116
    00117 } // namespace Keos
    00118
    00119 #endif // KEOS_OGLBUFFER_H