Show vertexbuffer-glsl.cpp syntax highlighted
/***************************************************************************
shader-arb.h - ARB vertex/fragment programs
-------------------
begin : Mon Jan 5 2004
copyright : (C) 2004 by Reality Rift Studios
email : mattias@realityrift.com
last modify date : Mon Sep 20 2004
last modify : GLSL manager
l.m. copyright : (C) 2004 by Arcadia Design s.r.l.
email : Dario Deledda (penguindark@hotmail.com)
***************************************************************************
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the NeoEngine, NeoDevOpenGL, shader-arb.h
The Initial Developer of the Original Code is Mattias Jansson.
Portions created by Mattias Jansson are Copyright (C) 2004
Reality Rift Studios. All Rights Reserved.
Contributors: Dario Deledda (penguindark@hotmail.com)
***************************************************************************/
#include "vertexbuffer-glsl.h"
#include "vertexbuffermanager-glsl.h"
#include "device.h"
using namespace NeoEngine;
using namespace std;
namespace NeoOGL
{
VertexBufferGLSL::VertexBufferGLSL( Device *pkDevice, VertexBufferManagerGLSL *pkBufferManager, unsigned int uiType, unsigned int uiNumVertices, const VertexDeclaration *pkFormat, const void *pData ) :
VertexBufferGL( pkDevice, uiType, 0, 0, 0 ),
m_pkBufferManager( pkBufferManager ),
m_uiObject( 0 )
{
AllocateVertices( uiNumVertices, pkFormat, pData );
}
VertexBufferGLSL::~VertexBufferGLSL()
{
Release();
}
void VertexBufferGLSL::Release()
{
if( m_pkBufferManager->m_pkBoundBuffer == this )
m_pkBufferManager->m_pkBoundBuffer = 0;
if( m_uiObject )
neoglDeleteBuffersARB( 1, &m_uiObject );
m_uiObject = 0;
}
void VertexBufferGLSL::AllocateVertices( unsigned int uiNumVertices, const VertexDeclaration *pkFormat, const void *pData )
{
//Completely override normal allocator to allow NOREADWRITE buffers
assert( !m_uiLock );
if( ( uiNumVertices == m_uiNumAllocated ) && pkFormat && m_pkVertexFormat && ( *m_pkVertexFormat == *pkFormat ) && !( m_uiType & Buffer::NOREADWRITE ) )
{
m_uiNumCurrent = m_uiNumAllocated;
if( !pData || !uiNumVertices )
return;
Lock( Buffer::WRITE );
LoadVertexData( pData );
Unlock();
return;
}
Release();
delete [] m_pucBuffer, m_pucBuffer = 0;
if( pkFormat )
{
delete m_pkVertexFormat;
m_pkVertexFormat = pkFormat->Duplicate();
}
m_uiVertexFormatSize = m_pkVertexFormat ? m_pkVertexFormat->GetVertexSize() : 0;
m_uiNumAllocated = m_pkVertexFormat ? uiNumVertices : 0;
m_uiNumCurrent = m_uiNumAllocated;
if( !m_uiNumAllocated )
return;
if( !( m_uiType & Buffer::NOREADWRITE ) )
m_pucBuffer = new unsigned char[ m_uiVertexFormatSize * m_uiNumAllocated ];
ParseDeclaration();
if( !( m_uiType & Buffer::NOREADWRITE ) )
{
if( pData )
{
Lock( Buffer::WRITE );
LoadVertexData( pData );
Unlock();
}
}
else
{
GLuint uiBuffer = 0;
neoglGenBuffersARB( 1, &uiBuffer );
m_uiObject = uiBuffer;
m_pkBufferManager->BindBuffer( this );
neoglBufferDataARB( GL_ARRAY_BUFFER_ARB, m_uiNumAllocated * m_uiVertexFormatSize, pData, GL_STATIC_DRAW_ARB );
m_bDirty = false;
}
}
void VertexBufferGLSL::Upload()
{
if( !m_uiNumCurrent )
return;
if( !m_uiObject )
{
GLuint uiBuffer = 0;
neoglGenBuffersARB( 1, &uiBuffer );
m_uiObject = uiBuffer;
m_pkBufferManager->BindBuffer( this );
neoglBufferDataARB( GL_ARRAY_BUFFER_ARB, m_uiNumCurrent * m_uiVertexFormatSize, m_pucBuffer, ( ( m_uiType & Buffer::WRITEPRIORITIZED ) || !( m_uiType & Buffer::STATIC ) ) ? GL_DYNAMIC_DRAW_ARB : GL_STATIC_DRAW_ARB );
}
else
{
m_pkBufferManager->BindBuffer( this );
neoglBufferDataARB( GL_ARRAY_BUFFER_ARB, m_uiNumCurrent * m_uiVertexFormatSize, m_pucBuffer, ( ( m_uiType & Buffer::WRITEPRIORITIZED ) || !( m_uiType & Buffer::STATIC ) ) ? GL_DYNAMIC_DRAW_ARB : GL_STATIC_DRAW_ARB );
}
VertexBufferGL::Upload();
}
};
See more files for this project here