2 #include "BlockRenderTask.h" 3 #include "BlockCommon.h" 5 #include "BlockReadWriteLock.h" 10 class BlockRenderTask;
14 class ParaVertexBufferPool;
15 class BlockGeneralTessellator;
25 ChunkBuild_RequestRebuild,
27 ChunkBuild_Rebuilding,
29 ChunkBuild_RequestBufferUpload,
38 void ReuseChunk(
BlockRegion* m_ownerBlockRegion,int16_t chunkIndex);
40 void ClearChunkData();
42 void ReleaseVertexBuffers();
64 void DeleteDeviceObjects();
66 void ClearRenderTasks();
68 void RendererRecreated();
71 inline uint16_t GetChunkIndex(){
return m_packedChunkID;}
95 bool IsDirtyByNeighbor();
105 RenderableChunk::ChunkBuildState GetChunkBuildState()
const;
106 bool IsBuildingBuffer()
const;
107 bool IsReadyOrEmpty()
const;
108 void SetChunkBuildState(RenderableChunk::ChunkBuildState val);
110 static void StaticInit();
111 static void StaticRelease();
125 void ClearBuilderBuffer();
130 int32 GetTotalFaceCount()
const;
135 void SetDelayedRebuildTick(int32 val);
139 void SetChunkViewDistance(int16 val);
143 void SetViewIndex(int16 val);
147 void SetRenderFrameCount(
int val);
158 std::vector<BlockRenderTask*> GetRenderTasks();
166 void SetShaderID(
int val);
170 void SetIsMainRenderer(
bool val);
172 bool IsDirtyByBlockChange()
const;
173 void IsDirtyByBlockChange(
bool val);
178 uint32_t m_blockData;
179 uint32_t m_nFaceCount;
182 std::vector<uint16_t> instances;
183 InstanceGroup() :m_pTemplate(NULL), m_blockData(0), m_nFaceCount(0){}
189 inline bool isEmpty()
const {
190 return !(m_pTemplate || instances.size() > 0);
192 inline void AddFace(uint32_t nCount){
193 m_nFaceCount += nCount;
195 inline void AddInstance(uint16_t nIndex, uint32_t nFaceCount = 0){
196 instances.push_back(nIndex);
199 inline uint32_t GetFaceCount()
const {
return m_nFaceCount; }
201 AddFace(right.GetFaceCount());
202 instances.insert(instances.end(), right.instances.begin(), right.instances.end());
216 static void StaticReleaseInstGroup(std::vector<RenderableChunk::InstanceGroup* >* pInstances);
222 void BuildRenderGroup();
224 void ResetInstanceGroups();
226 int32 BuildInstanceGroupsByIdAndData(
BlockChunk* pChunk);
227 void SortAndMergeInstanceGroupsByTexture();
231 ParaMemoryBuffer RequestMemoryBuffer(int32 nFaceCountInVertexBuffer, int32* pBufferIndex);
234 std::vector<BlockRenderTask*> m_builder_tasks;
235 std::vector<ParaMemoryBuffer> m_memoryBuffers;
239 static int s_nTotalRenderableChunks;
241 int16_t m_regionX, m_regionZ;
242 int16_t m_packedChunkID;
244 int32 m_nRenderFrameCount;
245 int32 m_nLastVertexBufferBytes;
248 int32 m_nDelayedRebuildTick;
250 int16 m_nChunkViewDistance;
254 ChunkBuildState m_chunkBuildState;
261 std::vector<BlockRenderTask*> m_renderTasks;
262 std::vector<ParaVertexBuffer*> m_vertexBuffers;
265 int32 m_totalFaceCount;
268 bool m_bIsMainRenderer : 1;
270 bool m_bIsDirtyByBlockChange : 1;
void UploadFromMemoryToDeviceBuffer()
only call in main thread
Definition: RenderableChunk.cpp:849
pure memory buffer, useful for filling in another thread and then upload to a real vertex buffer in t...
Definition: ParaVertexBuffer.h:87
ParaVertexBuffer * RequestVertexBuffer(int32 nFaceCountInVertexBuffer)
each rectangle face is 2 triangles or 4 vertices.
Definition: RenderableChunk.cpp:491
simple scoped read lock function
Definition: BlockReadWriteLock.h:123
different physics engine has different winding order.
Definition: EventBinding.h:32
bool CanShareRenderBufferWith(InstanceGroup *pOther=NULL)
whether this instance group can share vertex buffer with the other instance, providing that both inst...
Definition: RenderableChunk.cpp:1068
pool of vertex buffer object.
Definition: ParaVertexBufferPool.h:10
void SetChunkDirty(bool isDirty)
only dirty if chunk is first loaded or reused and all render buffer content can not be used to render...
Definition: RenderableChunk.h:83
void RebuildRenderBufferToMemory(Scoped_ReadLock< BlockReadWriteLock > *Lock_, int *pnCpuYieldCount)
call this function to generate all vertices to memory buffer.
Definition: RenderableChunk.cpp:657
int GetShaderID() const
this determined how the vertex buffer format is.
Definition: RenderableChunk.cpp:999
Definition: RenderableChunk.h:17
cross platform vertex/index buffer.
Definition: ParaVertexBuffer.h:18
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
BlockChunk * GetChunk()
get the associated raw chunk data
Definition: RenderableChunk.cpp:436
static int GetTotalRenderableChunks()
total number of renderable chunks in memory.
Definition: RenderableChunk.cpp:984
bool IsDirty() const
only dirty if chunk is first loaded or reused and all render buffer content can not be used to render...
Definition: RenderableChunk.h:91
std::vector< InstanceGroup *> & GetInstanceGroups()
this function returns thread local data
Definition: RenderableChunk.cpp:536
BlockGeneralTessellator & GetBlockTessellator()
get thread local block tessellator
Definition: RenderableChunk.cpp:516
Definition: ShapeSphere.h:6
void FillRenderQueue(CBlockWorld *pWorld)
fill the render queue with buffer data.
base class for an instance of block world
Definition: BlockWorld.h:35
bool RebuildRenderBuffer(CBlockWorld *pWorld, bool bAsyncMode)
every frame, we will ensure some new buffer is updated, and some updated buffer is updated as well...
Definition: RenderableChunk.cpp:58
int GetRenderFrameCount() const
when this chunk should be rendered last time.
Definition: RenderableChunk.cpp:1038
int32 GetDelayedRebuildTick() const
how many render ticks that this chunk has been delayed from buffer rebuilding.
Definition: RenderableChunk.cpp:900
Chunk is a 16*16*16 inside a region.
Definition: BlockChunk.h:138
Int16x3 GetChunkPosWs()
chunk position in world space.
Definition: RenderableChunk.cpp:893
bool GetIsDirtyByBlockChange()
whether this chunk is made dirty by actual block changes.
Definition: RenderableChunk.cpp:415
block template base class.
Definition: BlockTemplate.h:15
int GetLastBufferBytes()
this is usually same as GetVertexBufferBytes(), except that when we clear vertex buffer, this size remain unchanged until the chunk is reused.
Definition: RenderableChunk.cpp:1058
int16 GetViewIndex() const
each chunk has a unique view index, the smaller the closer to the current view center.
Definition: RenderableChunk.cpp:920
custom model tessellation like button, stairs, etc.
Definition: BlockTessellators.h:72
bool IsIntersect(CShapeSphere &sphere)
whether the chunk intersect with the given sphere.
Definition: RenderableChunk.cpp:421
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...
Definition: RenderableChunk.cpp:46
bool IsNearbyChunksLoaded()
return true if the nearby 4 chunk columns have been generated (and loaded)
Definition: RenderableChunk.cpp:447
bool IsMainRenderer() const
for main renderer (default to true), we will set chuck dirty to false, whenever the buffer is rebuilt...
Definition: RenderableChunk.cpp:1009
void WaitUntilChunkReady()
only used when the chunk is destroyed.
Definition: RenderableChunk.cpp:648
std::map< int32_t, int > & GetInstanceMap()
mapping from a hashed value of block_template id and template data if any.
Definition: RenderableChunk.cpp:544
int16 GetChunkViewDistance() const
distance to current camera in chunk space.
Definition: RenderableChunk.cpp:910
512*512 region
Definition: BlockRegion.h:22
int GetVertexBufferBytes()
get the current size of all of its vertex buffer.
Definition: RenderableChunk.cpp:1048
basic block world coordinate
Definition: BlockCoordinate.h:10
Definition: RenderableChunk.h:175
a min max box.
Definition: ShapeAABB.h:190