mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Split CIndexBuffer from CMeshBuffer
This commit is contained in:
parent
5d6e15bc49
commit
47e4c33a50
13 changed files with 197 additions and 104 deletions
|
@ -1358,11 +1358,8 @@ video::SMaterial &ClientMap::DrawDescriptor::getMaterial()
|
|||
u32 ClientMap::DrawDescriptor::draw(video::IVideoDriver* driver)
|
||||
{
|
||||
if (m_use_partial_buffer) {
|
||||
m_partial_buffer->beforeDraw();
|
||||
driver->drawMeshBuffer(m_partial_buffer->getBuffer());
|
||||
auto count = m_partial_buffer->getBuffer()->getVertexCount();
|
||||
m_partial_buffer->afterDraw();
|
||||
return count;
|
||||
m_partial_buffer->draw(driver);
|
||||
return m_partial_buffer->getBuffer()->getVertexCount();
|
||||
} else {
|
||||
driver->drawMeshBuffer(m_buffer);
|
||||
return m_buffer->getVertexCount();
|
||||
|
|
|
@ -179,6 +179,7 @@ void Clouds::updateMesh()
|
|||
|
||||
auto *mb = m_meshbuffer.get();
|
||||
auto &vertices = mb->Vertices->Data;
|
||||
auto &indices = mb->Indices->Data;
|
||||
{
|
||||
const u32 vertex_count = num_faces_to_draw * 16 * m_cloud_radius_i * m_cloud_radius_i;
|
||||
const u32 quad_count = vertex_count / 4;
|
||||
|
@ -186,7 +187,7 @@ void Clouds::updateMesh()
|
|||
|
||||
// reserve memory
|
||||
vertices.reserve(vertex_count);
|
||||
mb->Indices.reserve(index_count);
|
||||
indices.reserve(index_count);
|
||||
}
|
||||
|
||||
#define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius))
|
||||
|
@ -323,18 +324,18 @@ void Clouds::updateMesh()
|
|||
const u32 index_count = quad_count * 6;
|
||||
// rewrite index array as needed
|
||||
if (mb->getIndexCount() > index_count) {
|
||||
mb->Indices.resize(index_count);
|
||||
indices.resize(index_count);
|
||||
mb->setDirty(scene::EBT_INDEX);
|
||||
} else if (mb->getIndexCount() < index_count) {
|
||||
const u32 start = mb->getIndexCount() / 6;
|
||||
assert(start * 6 == mb->getIndexCount());
|
||||
for (u32 k = start; k < quad_count; k++) {
|
||||
mb->Indices.push_back(4 * k + 0);
|
||||
mb->Indices.push_back(4 * k + 1);
|
||||
mb->Indices.push_back(4 * k + 2);
|
||||
mb->Indices.push_back(4 * k + 2);
|
||||
mb->Indices.push_back(4 * k + 3);
|
||||
mb->Indices.push_back(4 * k + 0);
|
||||
indices.push_back(4 * k + 0);
|
||||
indices.push_back(4 * k + 1);
|
||||
indices.push_back(4 * k + 2);
|
||||
indices.push_back(4 * k + 2);
|
||||
indices.push_back(4 * k + 3);
|
||||
indices.push_back(4 * k + 0);
|
||||
}
|
||||
mb->setDirty(scene::EBT_INDEX);
|
||||
}
|
||||
|
|
|
@ -135,8 +135,9 @@ Hud::Hud(Client *client, LocalPlayer *player,
|
|||
// Prepare mesh for compass drawing
|
||||
auto &b = m_rotation_mesh_buffer;
|
||||
auto &vertices = b.Vertices->Data;
|
||||
auto &indices = b.Indices->Data;
|
||||
vertices.resize(4);
|
||||
b.Indices.resize(6);
|
||||
indices.resize(6);
|
||||
|
||||
video::SColor white(255, 255, 255, 255);
|
||||
v3f normal(0.f, 0.f, 1.f);
|
||||
|
@ -146,12 +147,12 @@ Hud::Hud(Client *client, LocalPlayer *player,
|
|||
vertices[2] = video::S3DVertex(v3f( 1.f, 1.f, 0.f), normal, white, v2f(1.f, 0.f));
|
||||
vertices[3] = video::S3DVertex(v3f( 1.f, -1.f, 0.f), normal, white, v2f(1.f, 1.f));
|
||||
|
||||
b.Indices[0] = 0;
|
||||
b.Indices[1] = 1;
|
||||
b.Indices[2] = 2;
|
||||
b.Indices[3] = 2;
|
||||
b.Indices[4] = 3;
|
||||
b.Indices[5] = 0;
|
||||
indices[0] = 0;
|
||||
indices[1] = 1;
|
||||
indices[2] = 2;
|
||||
indices[3] = 2;
|
||||
indices[4] = 3;
|
||||
indices[5] = 0;
|
||||
|
||||
b.getMaterial().Lighting = false;
|
||||
b.getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||
|
|
|
@ -592,17 +592,14 @@ void MapBlockBspTree::traverse(s32 node, v3f viewpoint, std::vector<s32> &output
|
|||
PartialMeshBuffer
|
||||
*/
|
||||
|
||||
void PartialMeshBuffer::beforeDraw() const
|
||||
void PartialMeshBuffer::draw(video::IVideoDriver *driver) const
|
||||
{
|
||||
// Patch the indexes in the mesh buffer before draw
|
||||
m_buffer->Indices = std::move(m_vertex_indexes);
|
||||
m_buffer->setDirty(scene::EBT_INDEX);
|
||||
}
|
||||
|
||||
void PartialMeshBuffer::afterDraw() const
|
||||
{
|
||||
// Take the data back
|
||||
m_vertex_indexes = std::move(m_buffer->Indices);
|
||||
// Swap out the index buffer before drawing the mesh
|
||||
auto *old = m_buffer->Indices;
|
||||
m_buffer->Indices = m_indices.get();
|
||||
m_buffer->setDirty(scene::EBT_INDEX); // TODO remove
|
||||
driver->drawMeshBuffer(m_buffer);
|
||||
m_buffer->Indices = old;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -789,6 +786,7 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
|
|||
}
|
||||
|
||||
// Transparent parts have changing indices
|
||||
// TODO: remove
|
||||
for (auto &it : m_transparent_triangles)
|
||||
it.buffer->setHardwareMappingHint(scene::EHM_STREAM, scene::EBT_INDEX);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#pragma once
|
||||
|
||||
#include "irrlichttypes_extrabloated.h"
|
||||
#include "irr_ptr.h"
|
||||
#include "util/numeric.h"
|
||||
#include "client/tile.h"
|
||||
#include "voxel.h"
|
||||
|
@ -145,25 +146,24 @@ private:
|
|||
* Attach alternate `Indices` to an existing mesh buffer, to make it possible to use different
|
||||
* indices with the same vertex buffer.
|
||||
*
|
||||
* Irrlicht does not currently support this: `CMeshBuffer` ties together a single vertex buffer
|
||||
* and a single index buffer. There's no way to share these between mesh buffers.
|
||||
*
|
||||
*/
|
||||
class PartialMeshBuffer
|
||||
{
|
||||
public:
|
||||
PartialMeshBuffer(scene::SMeshBuffer *buffer, std::vector<u16> &&vertex_indexes) :
|
||||
m_buffer(buffer), m_vertex_indexes(std::move(vertex_indexes))
|
||||
{}
|
||||
PartialMeshBuffer(scene::SMeshBuffer *buffer, std::vector<u16> &&vertex_indices) :
|
||||
m_buffer(buffer)
|
||||
{
|
||||
m_indices.reset(new scene::SIndexBuffer());
|
||||
m_indices->Data = std::move(vertex_indices);
|
||||
}
|
||||
|
||||
scene::IMeshBuffer *getBuffer() const { return m_buffer; }
|
||||
const std::vector<u16> &getVertexIndexes() const { return m_vertex_indexes; }
|
||||
|
||||
void beforeDraw() const;
|
||||
void afterDraw() const;
|
||||
void draw(video::IVideoDriver *driver) const;
|
||||
|
||||
private:
|
||||
scene::SMeshBuffer *m_buffer;
|
||||
mutable std::vector<u16> m_vertex_indexes;
|
||||
irr_ptr<scene::SIndexBuffer> m_indices;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -556,8 +556,9 @@ scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
|
|||
{
|
||||
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
|
||||
auto &vertices = buf->Vertices->Data;
|
||||
auto &indices = buf->Indices->Data;
|
||||
vertices.resize(4);
|
||||
buf->Indices.resize(6);
|
||||
indices.resize(6);
|
||||
static const video::SColor c(255, 255, 255, 255);
|
||||
|
||||
vertices[0] = video::S3DVertex(-1, -1, 0, 0, 0, 1, c, 0, 1);
|
||||
|
@ -565,12 +566,12 @@ scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
|
|||
vertices[2] = video::S3DVertex( 1, 1, 0, 0, 0, 1, c, 1, 0);
|
||||
vertices[3] = video::S3DVertex( 1, -1, 0, 0, 0, 1, c, 1, 1);
|
||||
|
||||
buf->Indices[0] = 0;
|
||||
buf->Indices[1] = 1;
|
||||
buf->Indices[2] = 2;
|
||||
buf->Indices[3] = 2;
|
||||
buf->Indices[4] = 3;
|
||||
buf->Indices[5] = 0;
|
||||
indices[0] = 0;
|
||||
indices[1] = 1;
|
||||
indices[2] = 2;
|
||||
indices[3] = 2;
|
||||
indices[4] = 3;
|
||||
indices[5] = 0;
|
||||
|
||||
buf->setHardwareMappingHint(scene::EHM_STATIC);
|
||||
return buf;
|
||||
|
|
|
@ -831,8 +831,9 @@ void Sky::updateStars()
|
|||
m_star_params.count = 0x4000;
|
||||
}
|
||||
auto &vertices = m_stars->Vertices->Data;
|
||||
auto &indices = m_stars->Indices->Data;
|
||||
vertices.reserve(4 * m_star_params.count);
|
||||
m_stars->Indices.reserve(6 * m_star_params.count);
|
||||
indices.reserve(6 * m_star_params.count);
|
||||
|
||||
video::SColor fallback_color = m_star_params.starcolor; // used on GLES 2 “without shaders”
|
||||
PcgRandom rgen(m_seed);
|
||||
|
@ -859,12 +860,12 @@ void Sky::updateStars()
|
|||
vertices.push_back(video::S3DVertex(p3, {}, fallback_color, {}));
|
||||
}
|
||||
for (u16 i = 0; i < m_star_params.count; i++) {
|
||||
m_stars->Indices.push_back(i * 4 + 0);
|
||||
m_stars->Indices.push_back(i * 4 + 1);
|
||||
m_stars->Indices.push_back(i * 4 + 2);
|
||||
m_stars->Indices.push_back(i * 4 + 2);
|
||||
m_stars->Indices.push_back(i * 4 + 3);
|
||||
m_stars->Indices.push_back(i * 4 + 0);
|
||||
indices.push_back(i * 4 + 0);
|
||||
indices.push_back(i * 4 + 1);
|
||||
indices.push_back(i * 4 + 2);
|
||||
indices.push_back(i * 4 + 2);
|
||||
indices.push_back(i * 4 + 3);
|
||||
indices.push_back(i * 4 + 0);
|
||||
}
|
||||
m_stars->setHardwareMappingHint(scene::EHM_STATIC);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue