My Project
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ParaEngine::RenderableChunk Class Reference

Classes

struct  InstanceGroup
 

Public Types

enum  ChunkBuildState {
  ChunkBuild_Ready, ChunkBuild_RequestRebuild, ChunkBuild_Rebuilding, ChunkBuild_RequestBufferUpload,
  ChunkBuild_empty
}
 

Public Member Functions

void ReuseChunk (BlockRegion *m_ownerBlockRegion, int16_t chunkIndex)
 
void ClearChunkData ()
 
void ReleaseVertexBuffers ()
 
void Reset ()
 
bool ShouldRebuildRenderBuffer (CBlockWorld *pWorld, bool bNewBuffer=true, bool bUpdatedBuffer=true)
 every frame, we will ensure some new buffer is updated, and some updated buffer is updated as well. More...
 
bool RebuildRenderBuffer (CBlockWorld *pWorld, bool bAsyncMode)
 every frame, we will ensure some new buffer is updated, and some updated buffer is updated as well. More...
 
void FillRenderQueue (CBlockWorld *pWorld)
 fill the render queue with buffer data. More...
 
void OnLeaveWorld ()
 
void DeleteDeviceObjects ()
 
void ClearRenderTasks ()
 
void RendererRecreated ()
 
bool IsEmptyChunk ()
 
uint16_t GetChunkIndex ()
 
Int16x3 GetChunkPosWs ()
 chunk position in world space. More...
 
BlockChunkGetChunk ()
 get the associated raw chunk data
 
void FillRenderQueue (CBlockWorld *pWorld, Vector3 &renderOfs, float verticalOffset)
 
void SetChunkDirty (bool isDirty)
 only dirty if chunk is first loaded or reused and all render buffer content can not be used to render
 
bool IsDirty () const
 only dirty if chunk is first loaded or reused and all render buffer content can not be used to render this has NOTHING to do when the actual block or light content of the chunk has changed or not.
 
bool IsDirtyByNeighbor ()
 
bool GetIsDirtyByBlockChange ()
 whether this chunk is made dirty by actual block changes. More...
 
bool IsIntersect (CShapeSphere &sphere)
 whether the chunk intersect with the given sphere. More...
 
bool IsNearbyChunksLoaded ()
 return true if the nearby 4 chunk columns have been generated (and loaded)
 
RenderableChunk::ChunkBuildState GetChunkBuildState () const
 
bool IsBuildingBuffer () const
 
bool IsReadyOrEmpty () const
 
void SetChunkBuildState (RenderableChunk::ChunkBuildState val)
 
void WaitUntilChunkReady ()
 only used when the chunk is destroyed. More...
 
void RebuildRenderBufferToMemory (Scoped_ReadLock< BlockReadWriteLock > *Lock_, int *pnCpuYieldCount)
 call this function to generate all vertices to memory buffer. More...
 
void ClearBuilderBuffer ()
 
void UploadFromMemoryToDeviceBuffer ()
 only call in main thread
 
int32 GetTotalFaceCount () const
 
int32 GetDelayedRebuildTick () const
 how many render ticks that this chunk has been delayed from buffer rebuilding. More...
 
void SetDelayedRebuildTick (int32 val)
 
int16 GetChunkViewDistance () const
 distance to current camera in chunk space. More...
 
void SetChunkViewDistance (int16 val)
 
int16 GetViewIndex () const
 each chunk has a unique view index, the smaller the closer to the current view center. More...
 
void SetViewIndex (int16 val)
 
int GetRenderFrameCount () const
 when this chunk should be rendered last time. More...
 
void SetRenderFrameCount (int val)
 
int GetVertexBufferBytes ()
 get the current size of all of its vertex buffer. More...
 
int GetLastBufferBytes ()
 this is usually same as GetVertexBufferBytes(), except that when we clear vertex buffer, this size remain unchanged until the chunk is reused. More...
 
std::vector< BlockRenderTask * > GetRenderTasks ()
 
const CShapeBoxGetShapeAABB () const
 
int GetShaderID () const
 this determined how the vertex buffer format is. More...
 
void SetShaderID (int val)
 
bool IsMainRenderer () const
 for main renderer (default to true), we will set chuck dirty to false, whenever the buffer is rebuilt. More...
 
void SetIsMainRenderer (bool val)
 
bool IsDirtyByBlockChange () const
 
void IsDirtyByBlockChange (bool val)
 
std::vector< InstanceGroup *> & GetInstanceGroups ()
 this function returns thread local data
 
std::map< int32_t, int > & GetInstanceMap ()
 mapping from a hashed value of block_template id and template data if any. More...
 
BlockGeneralTessellatorGetBlockTessellator ()
 get thread local block tessellator
 

Static Public Member Functions

static void StaticInit ()
 
static void StaticRelease ()
 
static ParaVertexBufferPoolGetVertexBufferPool ()
 
static int GetTotalRenderableChunks ()
 total number of renderable chunks in memory. More...
 
static void StaticReleaseInstGroup (std::vector< RenderableChunk::InstanceGroup * > *pInstances)
 

Protected Member Functions

void BuildRenderGroup ()
 
void ResetInstanceGroups ()
 
int32 BuildInstanceGroupsByIdAndData (BlockChunk *pChunk)
 
void SortAndMergeInstanceGroupsByTexture ()
 
ParaVertexBufferRequestVertexBuffer (int32 nFaceCountInVertexBuffer)
 each rectangle face is 2 triangles or 4 vertices. More...
 
ParaMemoryBuffer RequestMemoryBuffer (int32 nFaceCountInVertexBuffer, int32 *pBufferIndex)
 

Protected Attributes

std::vector< BlockRenderTask * > m_builder_tasks
 
std::vector< ParaMemoryBufferm_memoryBuffers
 

Member Function Documentation

§ FillRenderQueue()

void ParaEngine::RenderableChunk::FillRenderQueue ( CBlockWorld pWorld)

fill the render queue with buffer data.

please note, it does not fill if the buffer has not been created before.

§ GetChunkPosWs()

Int16x3 ParaEngine::RenderableChunk::GetChunkPosWs ( )

chunk position in world space.

§ GetChunkViewDistance()

int16 ParaEngine::RenderableChunk::GetChunkViewDistance ( ) const

distance to current camera in chunk space.

§ GetDelayedRebuildTick()

int32 ParaEngine::RenderableChunk::GetDelayedRebuildTick ( ) const

how many render ticks that this chunk has been delayed from buffer rebuilding.

If a chunk has been delayed for too long, we will force it to rebuild even it is farther from the camera than other dirty chunks with smaller delayed ticks.

§ GetInstanceMap()

std::map< int32_t, int > & ParaEngine::RenderableChunk::GetInstanceMap ( )

mapping from a hashed value of block_template id and template data if any.

§ GetIsDirtyByBlockChange()

bool ParaEngine::RenderableChunk::GetIsDirtyByBlockChange ( )

whether this chunk is made dirty by actual block changes.

§ GetLastBufferBytes()

int ParaEngine::RenderableChunk::GetLastBufferBytes ( )

this is usually same as GetVertexBufferBytes(), except that when we clear vertex buffer, this size remain unchanged until the chunk is reused.

It will internally call GetVertexBufferBytes() to refresh size

§ GetRenderFrameCount()

int ParaEngine::RenderableChunk::GetRenderFrameCount ( ) const

when this chunk should be rendered last time.

we will likely to remove old chunks when memory is small.

§ GetShaderID()

int ParaEngine::RenderableChunk::GetShaderID ( ) const

this determined how the vertex buffer format is.

this is -1, pWorld->GetBlockRenderMethod() is used. otherwise it is one of the BlockRenderMethod enumeration

§ GetTotalRenderableChunks()

int ParaEngine::RenderableChunk::GetTotalRenderableChunks ( )
static

total number of renderable chunks in memory.

§ GetVertexBufferBytes()

int ParaEngine::RenderableChunk::GetVertexBufferBytes ( )

get the current size of all of its vertex buffer.

§ GetViewIndex()

int16 ParaEngine::RenderableChunk::GetViewIndex ( ) const

each chunk has a unique view index, the smaller the closer to the current view center.

§ IsIntersect()

bool ParaEngine::RenderableChunk::IsIntersect ( CShapeSphere sphere)

whether the chunk intersect with the given sphere.

used in fast view culling.

§ IsMainRenderer()

bool ParaEngine::RenderableChunk::IsMainRenderer ( ) const

for main renderer (default to true), we will set chuck dirty to false, whenever the buffer is rebuilt.

§ RebuildRenderBuffer()

bool ParaEngine::RenderableChunk::RebuildRenderBuffer ( CBlockWorld pWorld,
bool  bAsyncMode 
)

every frame, we will ensure some new buffer is updated, and some updated buffer is updated as well.

Parameters
bAsyncModetrue to update in a separate thread.

§ RebuildRenderBufferToMemory()

void ParaEngine::RenderableChunk::RebuildRenderBufferToMemory ( Scoped_ReadLock< BlockReadWriteLock > *  Lock_,
int *  pnCpuYieldCount 
)

call this function to generate all vertices to memory buffer.

this functions take 20-30ms to complete. Better run from another thread.

Parameters
Lock_if this function is called from chunk builder thread, we need to pass the lock, so that we only process nMaxBlockPerStep of blocks per step and yield CPU to main render thread.
pnCpuYieldCounthow many times we have yield CPU to writer thread.
Returns
total face count is returned.

§ RequestVertexBuffer()

ParaVertexBuffer * ParaEngine::RenderableChunk::RequestVertexBuffer ( int32  nFaceCountInVertexBuffer)
protected

each rectangle face is 2 triangles or 4 vertices.

§ ShouldRebuildRenderBuffer()

bool ParaEngine::RenderableChunk::ShouldRebuildRenderBuffer ( CBlockWorld pWorld,
bool  bNewBuffer = true,
bool  bUpdatedBuffer = true 
)

every frame, we will ensure some new buffer is updated, and some updated buffer is updated as well.

Parameters
bNewBufferif true, we will update buffer that has not been created yet.
bUpdatedBufferif true, we will update buffer within which some light is updated. return true if the buffer is updated. and false, it is not dirty.

§ WaitUntilChunkReady()

void ParaEngine::RenderableChunk::WaitUntilChunkReady ( )

only used when the chunk is destroyed.

do not call this function is other cases.


The documentation for this class was generated from the following files: