Easy3D 2.5.3
Drawable Class Referenceabstract

The base class for drawable objects. A drawable represent a set of points, line segments, or triangles. More...

#include <easy3d/renderer/drawable.h>

Inheritance diagram for Drawable:
State LinesDrawable PointsDrawable TrianglesDrawable

Public Types

enum  Type { DT_POINTS = 0x0000 , DT_LINES = 0x0001 , DT_TRIANGLES = 0x0004 }
 
- Public Types inherited from State
enum  Method { UNIFORM_COLOR , COLOR_PROPERTY , SCALAR_FIELD , TEXTURED }
 
enum  Location { VERTEX , FACE , EDGE , HALFEDGE }
 

Public Member Functions

 Drawable (const std::string &name="unknown", Model *model=nullptr)
 
virtual Type type () const =0
 Returns the type of the drawable. More...
 
const std::string & name () const
 
void set_name (const std::string &n)
 
Modelmodel ()
 the model to which the drawable is attached to (can be NULL).
 
const Modelmodel () const
 
void set_model (Model *m)
 
const Box3bounding_box () const
 
Statestate ()
 
const Statestate () const
 
void set_state (const State &s)
 
void buffer_stats (std::ostream &output) const
 print statistics (e.g., num vertices, memory usage) of the buffers to an output stream (e.g., std::cout).
 
std::size_t num_vertices () const
 
VertexArrayObjectvao ()
 Returns the vertex array object of this drawable.
 
const VertexArrayObjectvao () const
 Returns the vertex array object of this drawable.
 
Buffer access and management
unsigned int vertex_buffer () const
 
unsigned int color_buffer () const
 
unsigned int normal_buffer () const
 
unsigned int texcoord_buffer () const
 
unsigned int element_buffer () const
 
void update_vertex_buffer (const std::vector< vec3 > &vertices, bool dynamic=false)
 Creates/Updates a single buffer. More...
 
void update_color_buffer (const std::vector< vec3 > &colors, bool dynamic=false)
 
void update_normal_buffer (const std::vector< vec3 > &normals, bool dynamic=false)
 
void update_texcoord_buffer (const std::vector< vec2 > &texcoords, bool dynamic=false)
 
void update_element_buffer (const std::vector< unsigned int > &elements)
 
void update_element_buffer (const std::vector< std::vector< unsigned int > > &elements)
 Updates the element buffer. More...
 
void disable_element_buffer ()
 Disables the use of the element buffer. More...
 
Rendering
virtual void draw (const Camera *camera) const =0
 The draw method. More...
 
void gl_draw () const
 
void update ()
 Requests an update of the OpenGL buffers. More...
 
void set_update_func (const std::function< void(Model *, Drawable *)> &func)
 Setups how a drawable updates its rendering buffers. More...
 
Manipulation
Manipulatormanipulator ()
 Gets the manipulator attached to this drawable. More...
 
const Manipulatormanipulator () const
 Gets the manipulator attached to this drawable. More...
 
void set_manipulator (Manipulator *manip)
 Attaches a manipulator to this model. More...
 
mat4 manipulated_matrix () const
 Returns the manipulation matrix.
 
- Public Member Functions inherited from State
 State (const State &s)
 
Stateoperator= (const State &rhs)
 assign rhs to *this. performs a deep copy of all member variables.
 
bool is_visible () const
 
void set_visible (bool v)
 
bool is_selected () const
 
void set_selected (bool b)
 
void set_uniform_coloring (const vec4 &color)
 
void set_property_coloring (Location color_location, const std::string &color_name="")
 
void set_texture_coloring (Location texcoord_location, const std::string &texcoord_name, const Texture *texture=nullptr, float repeat=1.0f, float repeat_fraction=0.0f)
 
void set_scalar_coloring (Location scalar_location, const std::string &scalar_name, const Texture *texture=nullptr, float clamp_lower=0.05f, float clamp_upper=0.05f)
 
void set_coloring (Method method, Location location, const std::string &name)
 
void set_coloring_method (Method method)
 
Method coloring_method () const
 
const vec4color () const
 
void set_color (const vec4 &c)
 
Location property_location () const
 
const std::string & property_name () const
 
bool lighting () const
 returns whether lighting is enabled.
 
void set_lighting (bool l)
 enables/disables lighting.
 
bool lighting_two_sides () const
 returns whether double-sided lighting is enabled.
 
void set_lighting_two_sides (bool b)
 enables/disables double-sided lighting.
 
bool distinct_back_color () const
 
void set_distinct_back_color (bool b)
 
const vec4back_color () const
 
void set_back_color (const vec4 &c)
 
const Texturetexture () const
 
void set_texture (Texture *tex)
 
float texture_repeat () const
 
void set_texture_repeat (float r)
 
float texture_fractional_repeat () const
 
void set_texture_fractional_repeat (float fr)
 
bool is_ssao_enabled () const
 
void enable_ssao (bool b)
 
void set_ssao_texture (unsigned int tex)
 
bool clamp_range () const
 
void set_clamp_range (bool b)
 
float clamp_lower () const
 
void set_clamp_lower (float v)
 
float clamp_upper () const
 
void set_clamp_upper (float v)
 
Materialmaterial ()
 
const Materialmaterial () const
 
void set_material (const Material &m)
 
bool plane_clip_discard_primitive () const
 Controls the behavior for vertex clipping. More...
 
void set_plane_clip_discard_primitive (bool b)
 
bool highlight () const
 
void set_highlight (bool b)
 
void set_highlight_range (const std::pair< int, int > &range)
 
const std::pair< int, int > & highlight_range () const
 

Detailed Description

The base class for drawable objects. A drawable represent a set of points, line segments, or triangles.

A Drawable is an abstraction for "something that can be drawn", e.g., a point cloud, the surface of a mesh, the wireframe of a surface mesh, the vertices of a graph, the border of a polyhedral mesh. A drawable manages its rendering status and controls the upload of the data to the GPU. A drawable can live independently or be associated with a Model. The rendering states of a drawable can be accessed/modified through the functions provided in its parent class State.

See also
State, Renderer
Examples
Tutorial_301_Drawables.

Member Function Documentation

◆ disable_element_buffer()

void disable_element_buffer ( )

Disables the use of the element buffer.

This method should be used if existing vertex data is sufficient for rendering (may require duplicating vertex data).

Note
This method also releases the element buffer.

◆ draw()

virtual void draw ( const Camera camera) const
pure virtual

The draw method.

Implemented in LinesDrawable, PointsDrawable, and TrianglesDrawable.

◆ gl_draw()

void gl_draw ( ) const

The internal draw method of this drawable. NOTE: this functions should be called when your shader program is in use, i.e., between glUseProgram(id) and glUseProgram(0);

Examples
Tutorial_203_Viewer_wxWidgets, and Tutorial_204_Viewer_Qt.

◆ manipulator() [1/2]

Manipulator * manipulator ( )

Gets the manipulator attached to this drawable.

If the drawable is part of a model, it returns the model's manipulator. Returns nullptr if the drawable cannot be manipulated.

◆ manipulator() [2/2]

const Manipulator * manipulator ( ) const

Gets the manipulator attached to this drawable.

If the drawable is part of a model, it returns the model's manipulator. Returns nullptr if the drawable cannot be manipulated.

◆ set_manipulator()

void set_manipulator ( Manipulator manip)
inline

Attaches a manipulator to this model.

This is used to manipulate a drawable that is not part of a model.

◆ set_update_func()

void set_update_func ( const std::function< void(Model *, Drawable *)> &  func)
inline

Setups how a drawable updates its rendering buffers.

This function is required by only non-standard drawables for a special visualization purpose. Rendering buffers of standard drawables attached to a model can be automatically updated and do not require this function. The drawable is considered standalone if Model is null.

See also
update(), Renderer::update().
Note
For a subclassed drawable, you can also reimplement update_buffers_internal() for the same purpose.

◆ type()

virtual Type type ( ) const
pure virtual

Returns the type of the drawable.

Implemented in LinesDrawable, PointsDrawable, and TrianglesDrawable.

◆ update()

void update ( )

Requests an update of the OpenGL buffers.

This function sets the status to trigger an update of the OpenGL buffers. The actual update does not occur immediately but is deferred to the rendering phase.

Note
This method works for both standard drawables (no update function required) and non-standard drawable (update function required). Standard drawables include:
  • SurfaceMesh: "faces", "edges", "vertices", "borders", and "locks";
  • PointCloud: "vertices";
  • Graph: "edges", and "vertices",
  • PolyMesh: "faces:border" and "faces:interior".
See also
set_update_func(), Renderer::update()

◆ update_element_buffer()

void update_element_buffer ( const std::vector< std::vector< unsigned int > > &  elements)

Updates the element buffer.

This is an overload of the above update_element_buffer() method.

Note
Each entry must have 2 (for LinesDrawable) or 3 elements (for TrianglesDrawable).

◆ update_vertex_buffer()

void update_vertex_buffer ( const std::vector< vec3 > &  vertices,
bool  dynamic = false 
)

Creates/Updates a single buffer.

Primitives like lines and triangles can be drawn with or without the element buffer.

  • With an element buffer: this can reduce the GPU memory consumption.
  • Without an element buffer: easier data transfer, but uses more GPU memory. In this case, vertices need to be in a correct order, like f1_v1, f1_v2, f1_v3, f2_v1, f2_v2, f2_v3... This requires the shared vertices be duplicated in the vertex buffer.
Examples
Tutorial_203_Viewer_wxWidgets, Tutorial_204_Viewer_Qt, Tutorial_301_Drawables, Tutorial_302_Imposters, and Tutorial_310_TextMesher.

The documentation for this class was generated from the following files: