esp::gfx::Drawable class

Drawable for use with DrawableGroup.

Drawable will retrieve its shader from its group, and draw itself with the shader.

Derived classes

class GenericDrawable
class MeshVisualizerDrawable
class PbrDrawable

Public types

enum class Flag { HasTangent = 1 << 0, HasSeparateBitangent = 1 << 1, HasVertexColor = 1 << 2 }
Flag It will not be used directly in the base class "Drawable" but it will be used in a couple of sub-classes.
using Flags = Corrade::Containers::EnumSet<Flag>
Flags.

Public static variables

static const char* SHADER_KEY_TEMPLATE constexpr
Key template for entry in shader map.

Constructors, destructors, conversion operators

Drawable(scene::SceneNode& node, Magnum::GL::Mesh* mesh, DrawableType type, DrawableConfiguration& cfg, Mn::Resource<LightSetup> lightSetup)
Constructor.
~Drawable() override

Public functions

auto getSceneNode() -> scene::SceneNode& virtual
auto drawables() -> DrawableGroup*
Get the DrawableGroup this drawable is in.
auto getDrawableId() const -> uint64_t
Get the drawable id.
void setLightSetup(const Magnum::ResourceKey& lightSetup) virtual
setup the lights. NOTE: sub-class should override this function
auto getSceneNode() const -> scene::SceneNode& virtual
the the scene node
auto getMesh() const -> Magnum::GL::Mesh&
get the GL mesh
auto getDrawableType() const -> DrawableType
get the drawable type
auto getVisualizerMesh() -> Magnum::GL::Mesh& virtual
Get the Magnum GL mesh for visualization, highlighting (e.g., used in object picking) See MeshVisualizer3D in Magnum library for more details.
void setMaterialValues(const Magnum::Resource<Magnum::Trade::MaterialData, Magnum::Trade::MaterialData>& material)
void resetMaterialValues(const Magnum::Resource<Magnum::Trade::MaterialData, Magnum::Trade::MaterialData>& material)

Protected functions

void resizeJointTransformArray(Mn::UnsignedInt jointCount)
resize the jointTransformArray_
void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override
Draw the object using given camera.
template<class FlagsType>
auto getShaderKey(const std::string& shaderType, Magnum::UnsignedInt lightCount, FlagsType flags, Magnum::UnsignedInt jointCount) const -> std::string
Derive the shader key appropriate for the calling child drawable.
void buildSkinJointTransforms()
Build the joint transformations on every draw if skinData exists.
template<class ShaderType>
void updateShaderLightingParameters(const Mn::Matrix4& transformationMatrix, Mn::SceneGraph::Camera3D& camera, ShaderType shader, const std::function<Magnum::Vector4(const LightInfo&, const Magnum::Matrix4&, const Magnum::Matrix4&)>& getLightPosition)
Update lighting-related parameters on every draw call.
void updateShaderLightingParametersInternal() virtual
Drawable-specific update called at the end of updateShaderLightingParameters.
auto glMeshExists() const -> bool

Protected static variables

static uint64_t drawableIdCounter

Protected variables

DrawableType type_
scene::SceneNode& node_
uint64_t drawableId_
Mn::Resource<LightSetup> lightSetup_
std::shared_ptr<InstanceSkinData> skinData_
Corrade::Containers::Array<Magnum::Matrix4> jointTransformations_

Private functions

void setMaterialValuesInternal(const Magnum::Resource<Magnum::Trade::MaterialData, Magnum::Trade::MaterialData>& material, bool reset) virtual

Enum documentation

enum class esp::gfx::Drawable::Flag

Flag It will not be used directly in the base class "Drawable" but it will be used in a couple of sub-classes.

Enumerators
HasTangent

indicates the mesh data has tangent attribute

HasSeparateBitangent

indicates the mesh data has separate bi-tangent attribute

HasVertexColor

indicates whether the mesh is vertex colored

Function documentation

esp::gfx::Drawable::Drawable(scene::SceneNode& node, Magnum::GL::Mesh* mesh, DrawableType type, DrawableConfiguration& cfg, Mn::Resource<LightSetup> lightSetup)

Constructor.

Parameters
node Node which will be made drawable.
mesh Mesh to draw when on render.
type the type of this drawable
cfg
lightSetup

DrawableGroup* esp::gfx::Drawable::drawables()

Get the DrawableGroup this drawable is in.

This overrides Magnum::SceneGraph::Drawable so that the derived DrawableGroup can be used

Magnum::GL::Mesh& esp::gfx::Drawable::getVisualizerMesh() virtual

Get the Magnum GL mesh for visualization, highlighting (e.g., used in object picking) See MeshVisualizer3D in Magnum library for more details.

Returns mesh_ by default. NOTE: sub-class should override this function if the "visualizer mesh" is different from mesh_

void esp::gfx::Drawable::setMaterialValues(const Magnum::Resource<Magnum::Trade::MaterialData, Magnum::Trade::MaterialData>& material)

Parameters
material material values to set

Change this drawable's Magnum::Trade::MaterialData values from passed material, keeping existing values if not overwritten This is only pertinent for material-equipped drawables.

void esp::gfx::Drawable::resetMaterialValues(const Magnum::Resource<Magnum::Trade::MaterialData, Magnum::Trade::MaterialData>& material)

Parameters
material material values to set

Reset this drawable's Magnum::Trade::MaterialData values from passed material, completely replacing the existing values This is only pertinent for material-equipped drawables.

void esp::gfx::Drawable::draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override protected

Draw the object using given camera.

Parameters
transformationMatrix Transformation relative to camera.
camera Camera to draw from.

Each derived drawable class needs to implement this draw() function. It's nothing more than drawing itself with its group's shader.

template<class FlagsType>
std::string esp::gfx::Drawable::getShaderKey(const std::string& shaderType, Magnum::UnsignedInt lightCount, FlagsType flags, Magnum::UnsignedInt jointCount) const protected

Derive the shader key appropriate for the calling child drawable.

Template parameters
FlagsType is the underlying type of the flags used by the calling drawable.
Parameters
shaderType Name of shader class (i.e. "Phong" or "PBR")
lightCount Number of lights used by drawable
flags The flags used by the owning drawable.
jointCount The number of joints if an articulated object with a skin, 0 otherwise

template<class ShaderType>
void esp::gfx::Drawable::updateShaderLightingParameters(const Mn::Matrix4& transformationMatrix, Mn::SceneGraph::Camera3D& camera, ShaderType shader, const std::function<Magnum::Vector4(const LightInfo&, const Magnum::Matrix4&, const Magnum::Matrix4&)>& getLightPosition) protected

Update lighting-related parameters on every draw call.

Template parameters
ShaderType is the type of shader being passed (wrapped in a Magnum::Resource).
Parameters
transformationMatrix The transformation matrix passed to this drawables draw function.
camera The camera passed to this drawable's draw function
shader The shader this drawable consumes.
getLightPosition The function to query for each light to acquire its proper position in the world. Flat/Phong objects query esp::gfx::getLightPositionRelativeToCamera(), while PBR objects query esp::gfx::getLightPositionRelativeToWorld()

void esp::gfx::Drawable::setMaterialValuesInternal(const Magnum::Resource<Magnum::Trade::MaterialData, Magnum::Trade::MaterialData>& material, bool reset) virtual private

Parameters
material material values to set
reset whether to reset underlying material or to write over it

Set or change this drawable's Magnum::Trade::MaterialData values from passed material. This is only pertinent for material-equipped drawables.