Show renderqueue.cpp syntax highlighted
/***************************************************************************
renderqueue.cpp - Render queue
-------------------
begin : Thu May 22 2003
copyright : (C) 2003 by Reality Rift Studios
email : mattias@realityrift.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, renderqueue.cpp
The Initial Developer of the Original Code is Mattias Jansson.
Portions created by Mattias Jansson are Copyright (C) 2003
Reality Rift Studios. All Rights Reserved.
***************************************************************************/
#include "renderqueue.h"
#include "op.h"
using namespace NeoEngine;
namespace NeoOGL
{
RenderQueue::RenderQueue( Device *pkDevice, int iArrayPointers, int iArrays, bool bSky ) :
m_pkDevice( pkDevice ),
m_ppkOpArray( 0 ),
m_puiOpSort( 0 ),
m_iNumOps( 0 ),
m_iLastNumOps( 0 ),
m_bIsSky( bSky ),
m_kSorter( RadixSort::UINT64 )
{
if( iArrayPointers < iArrays )
iArrayPointers = iArrays;
m_iNumOpArrays = iArrays;
m_iMaxOps = iArrays * OpArray::ARRAYSIZE;
m_iNumOpArrayPointers = iArrayPointers;
if( m_iNumOpArrayPointers > 0 )
{
m_ppkOpArray = new OpArray*[ m_iNumOpArrayPointers ];
memset( m_ppkOpArray, 0, sizeof( OpArray* ) * m_iNumOpArrayPointers );
if( m_iNumOpArrays > 0 )
{
for( int i = 0; i < m_iNumOpArrays; ++i )
m_ppkOpArray[i] = new OpArray;
m_puiOpSort = new uint64_t[ m_iNumOpArrays * OpArray::ARRAYSIZE ];
}
}
}
RenderQueue::~RenderQueue()
{
for( int i = 0; i < m_iNumOpArrays; ++i )
delete m_ppkOpArray[i];
delete [] m_ppkOpArray;
delete [] m_puiOpSort;
}
void RenderQueue::AllocArray()
{
//Check if we need to allocate more op array pointers
if( m_iNumOpArrays >= m_iNumOpArrayPointers )
{
//Resize the pointer array to double size
OpArray **ppkOpArray = new OpArray*[ m_iNumOpArrayPointers * 2 ];
fmemcpy( ppkOpArray, m_ppkOpArray, sizeof( OpArray* ) * m_iNumOpArrayPointers );
delete [] m_ppkOpArray;
m_ppkOpArray = ppkOpArray;
m_iNumOpArrayPointers *= 2;
}
//Allocate a new array
m_ppkOpArray[ m_iNumOpArrays++ ] = new OpArray;
m_iMaxOps = ( m_iNumOpArrays << OpArray::ARRAYSHIFT );
//Allocate new sort key array
uint64_t *puiOpSort = new uint64_t[ OpArray::ARRAYSIZE * m_iNumOpArrays ];
fmemcpy( puiOpSort, m_puiOpSort, sizeof( uint64_t ) * ( m_iNumOpArrays - 1 ) * OpArray::ARRAYSIZE );
delete [] m_puiOpSort;
m_puiOpSort = puiOpSort;
}
void RenderQueue::CleanOps()
{
int iStartArray = ( m_iNumOps >> OpArray::ARRAYSHIFT );
int iStartIndex = ( m_iNumOps & OpArray::ARRAYMASK );
int iEndArray = ( m_iLastNumOps >> OpArray::ARRAYSHIFT );
int iEndIndex = ( m_iLastNumOps & OpArray::ARRAYMASK );
for( int iArray = iStartArray; iArray <= iEndArray; ++iArray )
{
int iStart = 0;
int iEnd = OpArray::ARRAYSIZE;
if( iArray == iStartArray )
iStart = iStartIndex;
if( iArray == iEndArray )
iEnd = iEndIndex;
RenderPrimitive *pkOp = &m_ppkOpArray[ iArray ]->m_akOps[ iStart ];
for( int iIndex = iStart; iIndex < iEnd; ++iIndex, ++pkOp )
{
pkOp->m_pkMaterial = 0;
pkOp->m_pkVertexBuffer = 0;
pkOp->m_pkPolygonBuffer = 0;
}
}
m_iLastNumOps = m_iNumOps;
}
void RenderQueue::SortOps()
{
if( !m_bIsSky )
m_kSorter.Sort( m_puiOpSort, m_iNumOps );
}
};
See more files for this project here