Skip to content

Commit

Permalink
[render] DrawableMesh allows to update a subset of buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Feb 18, 2025
1 parent 9fb6fbc commit cd153c4
Show file tree
Hide file tree
Showing 7 changed files with 521 additions and 454 deletions.
8 changes: 5 additions & 3 deletions examples/render/02-mesh-viewer/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ int main(int argc, char** argv)
// load and set up a drawable mesh
auto m = getDrawableMesh<vcl::TriMesh>();

using enum vcl::MeshRenderInfo::Buffers;

m.enablePerFaceColor();
for (auto& f : m.faces()) {
if (f.index() % 3 == 0)
Expand All @@ -46,10 +48,10 @@ int main(int argc, char** argv)
else
f.color() = vcl::Color::Blue;
}
m.updateBuffers();
m.updateBuffers({TRI_COLORS});

auto v = std::make_shared<vcl::DrawableObjectVector>();
v->pushBack(m);
v->pushBack(std::move(m));

// load and set up a drawable mesh
vcl::DrawableMesh<vcl::TriMesh> drawable = getDrawableMesh<vcl::TriMesh>();
Expand All @@ -61,7 +63,7 @@ int main(int argc, char** argv)
vcl::scale(drawable, 0.5f);
vcl::translate(drawable, vcl::Point3d(bb.size().x(), 0, 0));

drawable.updateBuffers();
drawable.updateBuffers({VERTICES, VERT_NORMALS});
v->pushBack(std::move(drawable));

mv.setDrawableObjectVector(v);
Expand Down
9 changes: 5 additions & 4 deletions examples/render/05-two-window-viewers/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ int main(int argc, char** argv)
// load and set up a drawable mesh
vcl::DrawableMesh<vcl::TriMesh> drawable = getDrawableMesh<vcl::TriMesh>();

// FIXME #1: Fix crash on Windows/DirectX when updating buffers
// drawable.color() = vcl::Color::Yellow;
// drawable.updateBuffers();
using enum vcl::MeshRenderInfo::Buffers;
drawable.color() = vcl::Color::Yellow;
drawable.updateBuffers({MESH_UNIFORMS});

auto mrs = drawable.renderSettings();
// mrs.setSurfaceColorPerMesh();
mrs.setSurface(vcl::MeshRenderInfo::Surface::COLOR_MESH);
mrs.setSurface(vcl::MeshRenderInfo::Surface::SHADING_FLAT);
drawable.setRenderSettings(mrs);

Expand All @@ -54,6 +54,7 @@ int main(int argc, char** argv)
viewer1.show();

mrs.setSurface(vcl::MeshRenderInfo::Surface::SHADING_SMOOTH);
mrs.setSurface(vcl::MeshRenderInfo::Surface::COLOR_VERTEX);
drawable.setRenderSettings(mrs);

// add the drawable mesh to the scene
Expand Down
9 changes: 5 additions & 4 deletions vclib/render/include/vclib/bgfx/drawable/drawable_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace vcl {
template<MeshConcept MeshType>
class DrawableMeshBGFX : public AbstractDrawableMesh, public MeshType
{
using MRI = MeshRenderInfo;

Box3d mBoundingBox;

MeshRenderBuffers<MeshType> mMRB;
Expand Down Expand Up @@ -100,7 +102,8 @@ class DrawableMeshBGFX : public AbstractDrawableMesh, public MeshType
return *this;
}

void updateBuffers() override
void updateBuffers(
MRI::BuffersBitSet buffersToUpdate = MRI::BUFFERS_ALL) override
{
if constexpr (HasName<MeshType>) {
AbstractDrawableMesh::name() = MeshType::name();
Expand All @@ -121,7 +124,7 @@ class DrawableMeshBGFX : public AbstractDrawableMesh, public MeshType
mBoundingBox = vcl::boundingBox(*this);
}

mMRB.update(*this);
mMRB.update(*this, buffersToUpdate);
mMRS.setRenderCapabilityFrom(*this);
mMeshRenderSettingsUniforms.updateSettings(mMRS);
}
Expand All @@ -148,8 +151,6 @@ class DrawableMeshBGFX : public AbstractDrawableMesh, public MeshType

void draw(uint viewId) const override
{
using MRI = MeshRenderInfo;

uint64_t state = 0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A |
BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LEQUAL |
BGFX_STATE_BLEND_NORMAL;
Expand Down
Loading

0 comments on commit cd153c4

Please sign in to comment.