27#ifndef EASY3D_RENDERER_DRAWABLE_H
28#define EASY3D_RENDERER_DRAWABLE_H
35#include <easy3d/core/types.h>
36#include <easy3d/renderer/state.h>
92 const std::string &
name()
const {
return name_; }
97 void set_name(
const std::string& n) { name_ = n; }
315 virtual void update_buffers_internal();
326 std::shared_ptr<VertexArrayObject> vao_;
328 std::size_t num_vertices_;
329 std::size_t num_indices_;
334 unsigned int vertex_buffer_;
335 unsigned int color_buffer_;
336 unsigned int normal_buffer_;
337 unsigned int texcoord_buffer_;
338 unsigned int element_buffer_;
341 std::shared_ptr<Manipulator> manipulator_;
A perspective or orthographic camera.
Definition camera.h:113
The base class for drawable objects. A drawable represent a set of points, line segments,...
Definition drawable.h:58
unsigned int color_buffer() const
Returns the color buffer ID.
Definition drawable.h:154
void update_color_buffer(const std::vector< vec3 > &colors, bool dynamic=false)
Creates/Updates the color buffer.
Definition drawable.cpp:164
Manipulator * manipulator()
Returns the manipulator attached to this drawable.
Definition drawable.cpp:252
virtual Type type() const =0
Returns the type of the drawable.
State & state()
Returns the state of the drawable.
Definition drawable.h:125
Type
The type of the drawable.
Definition drawable.h:63
@ DT_TRIANGLES
Triangles drawable (GL_TRIANGLES).
Definition drawable.h:66
@ DT_LINES
Lines drawable (GL_LINES).
Definition drawable.h:65
@ DT_POINTS
Points drawable (GL_POINTS).
Definition drawable.h:64
const std::string & name() const
Returns the name of the drawable.
Definition drawable.h:92
Model * model()
Returns the model to which the drawable is attached.
Definition drawable.h:103
void set_update_func(const std::function< void(Model *, Drawable *)> &func)
Sets the update function for the drawable.
Definition drawable.h:267
void update_vertex_buffer(const std::vector< vec3 > &vertices, bool dynamic=false)
Creates/Updates the vertex buffer.
Definition drawable.cpp:139
const Model * model() const
Returns the model to which the drawable is attached (const version).
Definition drawable.h:108
unsigned int normal_buffer() const
Returns the normal buffer ID.
Definition drawable.h:159
void set_manipulator(std::shared_ptr< Manipulator > manip)
Attaches a manipulator to this drawable.
Definition drawable.h:293
unsigned int element_buffer() const
Returns the element buffer ID.
Definition drawable.h:169
void update_texcoord_buffer(const std::vector< vec2 > &texcoords, bool dynamic=false)
Updates the texture coordinate buffer.
Definition drawable.cpp:181
void gl_draw() const
Draws the drawable using OpenGL.
Definition drawable.cpp:221
void set_state(const State &s)
Sets the state of the drawable.
Definition drawable.h:135
VertexArrayObject * vao()
Returns the vertex array object of this drawable.
Definition drawable.h:306
void disable_element_buffer()
Disables the use of the element buffer.
Definition drawable.cpp:112
Drawable(const std::string &name="unknown", Model *model=nullptr)
Constructor that initializes the drawable with a name and an optional model.
Definition drawable.cpp:46
void update_element_buffer(const std::vector< unsigned int > &elements)
Updates the element buffer.
Definition drawable.cpp:190
void set_model(Model *m)
Sets the model to which the drawable is attached.
Definition drawable.h:113
~Drawable() override
Destructor.
Definition drawable.cpp:55
unsigned int vertex_buffer() const
Returns the vertex buffer ID.
Definition drawable.h:149
void buffer_stats(std::ostream &output) const
Prints statistics of the buffers to an output stream.
Definition drawable.cpp:68
void update()
Requests an update of the OpenGL buffers.
Definition drawable.cpp:93
mat4 manipulated_matrix() const
Returns the manipulation matrix.
Definition drawable.cpp:272
const Box3 & bounding_box() const
Returns the bounding box of the drawable.
Definition drawable.cpp:60
const State & state() const
Returns the state of the drawable (const version).
Definition drawable.h:130
std::size_t num_vertices() const
Returns the number of vertices.
Definition drawable.h:225
void update_normal_buffer(const std::vector< vec3 > &normals, bool dynamic=false)
Updates the normal buffer.
Definition drawable.cpp:173
const VertexArrayObject * vao() const
Returns the vertex array object of this drawable (const version).
Definition drawable.h:311
virtual void draw(const Camera *camera) const =0
Draws the drawable.
void set_name(const std::string &n)
Sets the name of the drawable.
Definition drawable.h:97
unsigned int texcoord_buffer() const
Returns the texture coordinate buffer ID.
Definition drawable.h:164
A manipulator is for manipulation of an object.
Definition manipulator.h:58
The base class of renderable 3D models.
Definition model.h:50
State()
Default constructor.
Definition state.cpp:42
A thin wrapper around an OpenGL Vertex Array Object (VAO).
Definition vertex_array_object.h:52
Definition collider.cpp:182
GenericBox< 3, float > Box3
A 3D axis-aligned bounding box of float type.
Definition types.h:108
Mat4< float > mat4
A 4 by 4 matrix of float type.
Definition types.h:67