23#ifndef VCL_BGFX_DRAWABLE_DRAWABLE_MESH_H
24#define VCL_BGFX_DRAWABLE_DRAWABLE_MESH_H
26#include <vclib/algorithms/mesh/stat/bounding_box.h>
27#include <vclib/render/drawable/abstract_drawable_mesh.h>
29#include <vclib/bgfx/context.h>
30#include <vclib/bgfx/drawable/mesh/mesh_render_buffers.h>
31#include <vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.h>
37template<MeshConcept MeshType>
46 bgfx::ProgramHandle mProgramEdges =
49 .getProgram<VertFragProgram::DRAWABLE_MESH_EDGES>();
51 bgfx::ProgramHandle mProgramPoints =
54 .getProgram<VertFragProgram::DRAWABLE_MESH_POINTS>();
56 bgfx::ProgramHandle mProgramSurface =
59 .getProgram<VertFragProgram::DRAWABLE_MESH_SURFACE>();
61 bgfx::ProgramHandle mProgramWireframe =
64 .getProgram<VertFragProgram::DRAWABLE_MESH_WIREFRAME>();
86 mMeshRenderSettingsUniforms(
114 if (this->MeshType::boundingBox().isNull()) {
128 mMRS.setRenderCapabilityFrom(*
this);
129 mMeshRenderSettingsUniforms.updateSettings(mMRS);
132 std::string&
name()
override {
return MeshType::name(); }
134 const std::string&
name()
const override {
return MeshType::name(); }
139 AbstractDrawableMesh::swap(
other);
140 MeshType::swap(
other);
141 swap(mBoundingBox,
other.mBoundingBox);
142 swap(mMRB,
other.mMRB);
143 swap(mMeshRenderSettingsUniforms,
other.mMeshRenderSettingsUniforms);
146 friend void swap(DrawableMeshBGFX& a, DrawableMeshBGFX& b) { a.swap(b); }
152 void draw(uint viewId)
const override
158 if (mMRS.
isPoints(MRI::Points::VISIBLE)) {
159 if (bgfx::isValid(mProgramPoints)) {
160 mMRB.bindVertexBuffers(mMRS);
165 bgfx::submit(viewId, mProgramPoints);
169 if (mMRS.
isSurface(MRI::Surface::VISIBLE)) {
170 if (bgfx::isValid(mProgramSurface)) {
172 mMRB.bindVertexBuffers(mMRS);
173 mMRB.bindIndexBuffers(mMRS);
176 bgfx::setState(
state);
178 bgfx::submit(viewId, mProgramSurface);
183 if (bgfx::isValid(mProgramWireframe)) {
184 mMRB.bindVertexBuffers(mMRS);
185 mMRB.bindIndexBuffers(mMRS, MRI::Buffers::WIREFRAME);
190 bgfx::submit(viewId, mProgramWireframe);
194 if (mMRS.
isEdges(MRI::Edges::VISIBLE)) {
195 if (bgfx::isValid(mProgramEdges)) {
196 mMRB.bindVertexBuffers(mMRS);
197 mMRB.bindIndexBuffers(mMRS, MRI::Buffers::EDGES);
202 bgfx::submit(viewId, mProgramEdges);
211 return std::make_shared<DrawableMeshBGFX>(*
this);
214 std::shared_ptr<DrawableObject>
clone() &&
override
216 return std::make_shared<DrawableMeshBGFX>(std::move(*
this));
222 mMeshRenderSettingsUniforms.updateSettings(mMRS);
227 AbstractDrawableMesh::setRenderSettings(
rs);
228 mMeshRenderSettingsUniforms.updateSettings(
rs);
232 void bindUniforms()
const
234 mMeshRenderSettingsUniforms.bind();
Definition abstract_drawable_mesh.h:32
void setVisibility(bool vis)
This member function is used to set the visibility of the object.
Definition abstract_drawable_mesh.h:58
The BitSet class allows to treat an integral type as an array of booleans of a guaranteed size.
Definition bit_set.h:53
static Context & instance(void *windowHandle=nullptr, void *displayHandle=nullptr)
Return the context instance.
Definition context.cpp:365
Definition drawable_mesh.h:39
std::shared_ptr< DrawableObject > clone() const &override
This member function is used to create a new copy of the DrawableObject. Each derived class must impl...
Definition drawable_mesh.h:209
const std::string & name() const override
Returns the name of the object.
Definition drawable_mesh.h:134
Box3d boundingBox() const override
This member function is used to find a good camera position to render object. It should return the th...
Definition drawable_mesh.h:207
std::shared_ptr< DrawableObject > clone() &&override
This member function is used to create a new DrawableObject that is a moved from the current one....
Definition drawable_mesh.h:214
std::string & name() override
Returns a reference of the name of the object, that allows to modify it.
Definition drawable_mesh.h:132
void draw(uint viewId) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_mesh.h:152
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_mesh.h:219
void init() override
This member function is called after the initialization of the Context. It must initialize and bind d...
Definition drawable_mesh.h:150
virtual const std::string & name() const
Returns the name of the object.
Definition drawable_object.h:153
The MeshRenderInfo class is a collection of rendering settings for a Mesh.
Definition mesh_render_info.h:61
The MeshRenderSettings class allows an easy management of render settings of a Mesh....
Definition mesh_render_settings.h:71
bool isPoints(MeshRenderInfo::Points p) const
Returns whether the given points option is set.
Definition mesh_render_settings.h:226
bool isSurface(MeshRenderInfo::Surface s) const
Returns whether the given surface option is set.
Definition mesh_render_settings.h:251
bool isWireframe(MeshRenderInfo::Wireframe w) const
Returns whether the given wireframe option is set.
Definition mesh_render_settings.h:271
bool isEdges(MeshRenderInfo::Edges e) const
Returns whether the given edges option is set.
Definition mesh_render_settings.h:296
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Concept that is evaluated true if a Mesh has the BoundingBox component.
Definition per_mesh.h:60
Concept that checks if a Mesh has the Name component.
Definition per_mesh.h:95
auto boundingBox(const PointType &p)
Compute the bounding box of a single point.
Definition bounding_box.h:65