Easy3D 2.5.3
|
The base class for drawable objects. A drawable represent a set of points, line segments, or triangles. More...
#include <easy3d/renderer/drawable.h>
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) |
Model * | model () |
the model to which the drawable is attached to (can be NULL). | |
const Model * | model () const |
void | set_model (Model *m) |
const Box3 & | bounding_box () const |
State & | state () |
const State & | state () 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 |
VertexArrayObject * | vao () |
Returns the vertex array object of this drawable. | |
const VertexArrayObject * | vao () 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 | |
Manipulator * | manipulator () |
Gets the manipulator attached to this drawable. More... | |
const Manipulator * | manipulator () 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) | |
State & | operator= (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 vec4 & | color () 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 vec4 & | back_color () const |
void | set_back_color (const vec4 &c) |
const Texture * | texture () 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) |
Material & | material () |
const Material & | material () 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 |
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.
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).
|
pure virtual |
The draw method.
Implemented in LinesDrawable, PointsDrawable, and TrianglesDrawable.
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);
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.
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.
|
inline |
Attaches a manipulator to this model.
This is used to manipulate a drawable that is not part of a model.
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
.
|
pure virtual |
Returns the type of the drawable.
Implemented in LinesDrawable, PointsDrawable, and TrianglesDrawable.
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.
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.
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.