Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/PatchRData.cpp
Show First 20 Lines • Show All 302 Lines • ▼ Show 20 Lines | void CPatchRData::BuildBlends() | ||||
{ | { | ||||
// Construct vertex buffer | // Construct vertex buffer | ||||
m_VBBlends = g_VBMan.Allocate(sizeof(SBlendVertex), blendVertices.size(), GL_STATIC_DRAW, GL_ARRAY_BUFFER); | m_VBBlends = g_VBMan.Allocate(sizeof(SBlendVertex), blendVertices.size(), GL_STATIC_DRAW, GL_ARRAY_BUFFER); | ||||
m_VBBlends->m_Owner->UpdateChunkVertices(m_VBBlends, &blendVertices[0]); | m_VBBlends->m_Owner->UpdateChunkVertices(m_VBBlends, &blendVertices[0]); | ||||
// Update the indices to include the base offset of the vertex data | // Update the indices to include the base offset of the vertex data | ||||
for (size_t k = 0; k < blendIndices.size(); ++k) | for (size_t k = 0; k < blendIndices.size(); ++k) | ||||
blendIndices[k] += m_VBBlends->m_Index; | blendIndices[k] += static_cast<u16>(m_VBBlends->m_Index); | ||||
m_VBBlendIndices = g_VBMan.Allocate(sizeof(u16), blendIndices.size(), GL_STATIC_DRAW, GL_ELEMENT_ARRAY_BUFFER); | m_VBBlendIndices = g_VBMan.Allocate(sizeof(u16), blendIndices.size(), GL_STATIC_DRAW, GL_ELEMENT_ARRAY_BUFFER); | ||||
m_VBBlendIndices->m_Owner->UpdateChunkVertices(m_VBBlendIndices, &blendIndices[0]); | m_VBBlendIndices->m_Owner->UpdateChunkVertices(m_VBBlendIndices, &blendIndices[0]); | ||||
} | } | ||||
} | } | ||||
void CPatchRData::AddBlend(std::vector<SBlendVertex>& blendVertices, std::vector<u16>& blendIndices, | void CPatchRData::AddBlend(std::vector<SBlendVertex>& blendVertices, std::vector<u16>& blendIndices, | ||||
u16 i, u16 j, u8 shape, CTerrainTextureEntry* texture) | u16 i, u16 j, u8 shape, CTerrainTextureEntry* texture) | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | void CPatchRData::AddBlend(std::vector<SBlendVertex>& blendVertices, std::vector<u16>& blendIndices, | ||||
vtx[(base + 2) % 4].m_AlphaUVs[1] = v1; | vtx[(base + 2) % 4].m_AlphaUVs[1] = v1; | ||||
vtx[(base + 3) % 4].m_AlphaUVs[0] = u0; | vtx[(base + 3) % 4].m_AlphaUVs[0] = u0; | ||||
vtx[(base + 3) % 4].m_AlphaUVs[1] = v1; | vtx[(base + 3) % 4].m_AlphaUVs[1] = v1; | ||||
SBlendVertex dst; | SBlendVertex dst; | ||||
CVector3D normal; | CVector3D normal; | ||||
size_t index = blendVertices.size(); | u16 index = static_cast<u16>(blendVertices.size()); | ||||
terrain->CalcPosition(gx, gz, dst.m_Position); | terrain->CalcPosition(gx, gz, dst.m_Position); | ||||
terrain->CalcNormal(gx, gz, normal); | terrain->CalcNormal(gx, gz, normal); | ||||
dst.m_Normal = normal; | dst.m_Normal = normal; | ||||
dst.m_AlphaUVs[0] = vtx[0].m_AlphaUVs[0]; | dst.m_AlphaUVs[0] = vtx[0].m_AlphaUVs[0]; | ||||
dst.m_AlphaUVs[1] = vtx[0].m_AlphaUVs[1]; | dst.m_AlphaUVs[1] = vtx[0].m_AlphaUVs[1]; | ||||
blendVertices.push_back(dst); | blendVertices.push_back(dst); | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | for (ssize_t j=0;j<PATCH_SIZE;j++) { | ||||
} | } | ||||
} | } | ||||
// now build base splats from interior textures | // now build base splats from interior textures | ||||
m_Splats.resize(textures.size()); | m_Splats.resize(textures.size()); | ||||
// build indices for base splats | // build indices for base splats | ||||
size_t base=m_VBBase->m_Index; | size_t base=m_VBBase->m_Index; | ||||
for (size_t i=0;i<m_Splats.size();i++) { | for (size_t k = 0; k < m_Splats.size(); ++k) | ||||
CTerrainTextureEntry* tex=textures[i]; | { | ||||
CTerrainTextureEntry* tex = textures[k]; | |||||
SSplat& splat=m_Splats[i]; | SSplat& splat=m_Splats[k]; | ||||
splat.m_Texture=tex; | splat.m_Texture=tex; | ||||
splat.m_IndexStart=indices.size(); | splat.m_IndexStart=indices.size(); | ||||
for (ssize_t j = 0; j < PATCH_SIZE; j++) | for (ssize_t j = 0; j < PATCH_SIZE; j++) | ||||
{ | { | ||||
for (ssize_t i = 0; i < PATCH_SIZE; i++) | for (ssize_t i = 0; i < PATCH_SIZE; i++) | ||||
{ | { | ||||
if (texgrid[j][i] == tex) | if (texgrid[j][i] == tex) | ||||
▲ Show 20 Lines • Show All 617 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
CVertexBuffer::Unbind(); | CVertexBuffer::Unbind(); | ||||
} | } | ||||
void CPatchRData::RenderStreams(const std::vector<CPatchRData*>& patches, const CShaderProgramPtr& shader, int streamflags) | void CPatchRData::RenderStreams(const std::vector<CPatchRData*>& patches, const CShaderProgramPtr& shader, int streamflags) | ||||
{ | { | ||||
// Each batch has a list of index counts, and a list of pointers-to-first-indexes | // Each batch has a list of index counts, and a list of pointers-to-first-indexes | ||||
typedef std::pair<std::vector<GLint>, std::vector<void*> > BatchElements; | using StreamBatchElements = std::pair<std::vector<GLint>, std::vector<void*> > ; | ||||
wraitii: I fail the point of adding `Stream`? | |||||
// Group batches by index buffer | // Group batches by index buffer | ||||
typedef std::map<CVertexBuffer*, BatchElements> IndexBufferBatches; | using StreamIndexBufferBatches = std::map<CVertexBuffer*, StreamBatchElements> ; | ||||
// Group batches by vertex buffer | // Group batches by vertex buffer | ||||
typedef std::map<CVertexBuffer*, IndexBufferBatches> VertexBufferBatches; | using StreamVertexBufferBatches = std::map<CVertexBuffer*, StreamIndexBufferBatches> ; | ||||
Done Inline ActionsMake these using wraitii: Make these `using` | |||||
VertexBufferBatches batches; | using StreamBatchElement = const std::pair<CVertexBuffer*, StreamIndexBufferBatches>&; | ||||
using StreamIndexBufferBatch = const std::pair<CVertexBuffer*, StreamBatchElements>&; | |||||
Done Inline ActionsTBH those two don't really help much. Probably better off using StreamBatchElements::value_type or just the pair where relevant. wraitii: TBH those two don't really help much. Probably better off using `StreamBatchElements… | |||||
StreamVertexBufferBatches batches; | |||||
PROFILE_START("compute batches"); | PROFILE_START("compute batches"); | ||||
// Collect all the patches into their appropriate batches | // Collect all the patches into their appropriate batches | ||||
for (size_t i = 0; i < patches.size(); ++i) | for (const CPatchRData* patch : patches) | ||||
{ | { | ||||
CPatchRData* patch = patches[i]; | StreamBatchElements& batch = batches[patch->m_VBBase->m_Owner][patch->m_VBBaseIndices->m_Owner]; | ||||
BatchElements& batch = batches[patch->m_VBBase->m_Owner][patch->m_VBBaseIndices->m_Owner]; | |||||
batch.first.push_back(patch->m_VBBaseIndices->m_Count); | batch.first.push_back(patch->m_VBBaseIndices->m_Count); | ||||
u8* indexBase = patch->m_VBBaseIndices->m_Owner->GetBindAddress(); | u8* indexBase = patch->m_VBBaseIndices->m_Owner->GetBindAddress(); | ||||
batch.second.push_back(indexBase + sizeof(u16)*(patch->m_VBBaseIndices->m_Index)); | batch.second.push_back(indexBase + sizeof(u16)*(patch->m_VBBaseIndices->m_Index)); | ||||
} | } | ||||
PROFILE_END("compute batches"); | PROFILE_END("compute batches"); | ||||
ENSURE(!(streamflags & ~(STREAM_POS|STREAM_POSTOUV0|STREAM_POSTOUV1))); | ENSURE(!(streamflags & ~(STREAM_POS|STREAM_POSTOUV0|STREAM_POSTOUV1))); | ||||
// Render each batch | // Render each batch | ||||
for (VertexBufferBatches::iterator itv = batches.begin(); itv != batches.end(); ++itv) | for (StreamBatchElement streamBatch : batches) | ||||
{ | { | ||||
GLsizei stride = sizeof(SBaseVertex); | GLsizei stride = sizeof(SBaseVertex); | ||||
SBaseVertex *base = (SBaseVertex *)itv->first->Bind(); | SBaseVertex *base = (SBaseVertex *)streamBatch.first->Bind(); | ||||
shader->VertexPointer(3, GL_FLOAT, stride, &base->m_Position); | shader->VertexPointer(3, GL_FLOAT, stride, &base->m_Position); | ||||
if (streamflags & STREAM_POSTOUV0) | if (streamflags & STREAM_POSTOUV0) | ||||
shader->TexCoordPointer(GL_TEXTURE0, 3, GL_FLOAT, stride, &base->m_Position); | shader->TexCoordPointer(GL_TEXTURE0, 3, GL_FLOAT, stride, &base->m_Position); | ||||
if (streamflags & STREAM_POSTOUV1) | if (streamflags & STREAM_POSTOUV1) | ||||
shader->TexCoordPointer(GL_TEXTURE1, 3, GL_FLOAT, stride, &base->m_Position); | shader->TexCoordPointer(GL_TEXTURE1, 3, GL_FLOAT, stride, &base->m_Position); | ||||
shader->AssertPointersBound(); | shader->AssertPointersBound(); | ||||
for (IndexBufferBatches::iterator it = itv->second.begin(); it != itv->second.end(); ++it) | for (StreamIndexBufferBatch batchIndexBuffer : streamBatch.second) | ||||
{ | { | ||||
Done Inline Actionscould using those above too for readability wraitii: could `using` those above too for readability | |||||
it->first->Bind(); | batchIndexBuffer.first->Bind(); | ||||
BatchElements& batch = it->second; | const StreamBatchElements& batch = batchIndexBuffer.second; | ||||
if (!g_Renderer.m_SkipSubmit) | if (!g_Renderer.m_SkipSubmit) | ||||
{ | { | ||||
for (size_t i = 0; i < batch.first.size(); ++i) | for (size_t i = 0; i < batch.first.size(); ++i) | ||||
glDrawElements(GL_TRIANGLES, batch.first[i], GL_UNSIGNED_SHORT, batch.second[i]); | glDrawElements(GL_TRIANGLES, batch.first[i], GL_UNSIGNED_SHORT, batch.second[i]); | ||||
} | } | ||||
g_Renderer.m_Stats.m_DrawCalls++; | g_Renderer.m_Stats.m_DrawCalls++; | ||||
▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | for (ssize_t x = 0; x < PATCH_SIZE; x += water_cell_size) | ||||
float depth = waterHeight - vertex.m_Position.Y; | float depth = waterHeight - vertex.m_Position.Y; | ||||
vertex.m_Position.Y = waterHeight; | vertex.m_Position.Y = waterHeight; | ||||
m_WaterBounds += vertex.m_Position; | m_WaterBounds += vertex.m_Position; | ||||
vertex.m_WaterData = CVector2D(WaterMgr->m_WindStrength[xx + zz*mapSize], depth); | vertex.m_WaterData = CVector2D(WaterMgr->m_WindStrength[xx + zz*mapSize], depth); | ||||
water_index_map[z+moves[i][1]][x+moves[i][0]] = water_vertex_data.size(); | water_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast<u16>(water_vertex_data.size()); | ||||
water_vertex_data.push_back(vertex); | water_vertex_data.push_back(vertex); | ||||
} | } | ||||
water_indices.push_back(water_index_map[z + moves[2][1]][x + moves[2][0]]); | water_indices.push_back(water_index_map[z + moves[2][1]][x + moves[2][0]]); | ||||
water_indices.push_back(water_index_map[z + moves[0][1]][x + moves[0][0]]); | water_indices.push_back(water_index_map[z + moves[0][1]][x + moves[0][0]]); | ||||
water_indices.push_back(water_index_map[z + moves[1][1]][x + moves[1][0]]); | water_indices.push_back(water_index_map[z + moves[1][1]][x + moves[1][0]]); | ||||
water_indices.push_back(water_index_map[z + moves[1][1]][x + moves[1][0]]); | water_indices.push_back(water_index_map[z + moves[1][1]][x + moves[1][0]]); | ||||
water_indices.push_back(water_index_map[z + moves[3][1]][x + moves[3][0]]); | water_indices.push_back(water_index_map[z + moves[3][1]][x + moves[3][0]]); | ||||
water_indices.push_back(water_index_map[z + moves[2][1]][x + moves[2][0]]); | water_indices.push_back(water_index_map[z + moves[2][1]][x + moves[2][0]]); | ||||
Show All 16 Lines | for (ssize_t x = 0; x < PATCH_SIZE; x += water_cell_size) | ||||
SWaterVertex vertex; | SWaterVertex vertex; | ||||
terrain->CalcPosition(xx,zz, vertex.m_Position); | terrain->CalcPosition(xx,zz, vertex.m_Position); | ||||
vertex.m_Position.Y += 0.02f; | vertex.m_Position.Y += 0.02f; | ||||
m_WaterBounds += vertex.m_Position; | m_WaterBounds += vertex.m_Position; | ||||
vertex.m_WaterData = CVector2D(0.0f, -5.0f); | vertex.m_WaterData = CVector2D(0.0f, -5.0f); | ||||
water_shore_index_map[z+moves[i][1]][x+moves[i][0]] = water_vertex_data_shore.size(); | water_shore_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast<u16>(water_vertex_data.size()); | ||||
water_vertex_data_shore.push_back(vertex); | water_vertex_data_shore.push_back(vertex); | ||||
} | } | ||||
if (terrain->GetTriangulationDir(x + px, z + pz)) | if (terrain->GetTriangulationDir(x + px, z + pz)) | ||||
{ | { | ||||
water_indices_shore.push_back(water_shore_index_map[z + moves[2][1]][x + moves[2][0]]); | water_indices_shore.push_back(water_shore_index_map[z + moves[2][1]][x + moves[2][0]]); | ||||
water_indices_shore.push_back(water_shore_index_map[z + moves[0][1]][x + moves[0][0]]); | water_indices_shore.push_back(water_shore_index_map[z + moves[0][1]][x + moves[0][0]]); | ||||
water_indices_shore.push_back(water_shore_index_map[z + moves[1][1]][x + moves[1][0]]); | water_indices_shore.push_back(water_shore_index_map[z + moves[1][1]][x + moves[1][0]]); | ||||
water_indices_shore.push_back(water_shore_index_map[z + moves[1][1]][x + moves[1][0]]); | water_indices_shore.push_back(water_shore_index_map[z + moves[1][1]][x + moves[1][0]]); | ||||
▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I fail the point of adding Stream?