27#ifndef EASY3D_RENDERER_DRAWABLE_H
28#define EASY3D_RENDERER_DRAWABLE_H
34#include <easy3d/core/types.h>
35#include <easy3d/renderer/state.h>
42 class VertexArrayObject;
71 virtual Type
type()
const = 0;
73 const std::string &name()
const {
return name_; }
74 void set_name(
const std::string& n) { name_ = n; }
79 void set_model(Model *m) { model_ = m; }
81 const Box3 &bounding_box()
const;
83 State& state() {
return *
this; };
84 const State& state()
const {
return *
this; };
85 void set_state(
const State& s) { state() = s; };
92 unsigned int vertex_buffer()
const {
return vertex_buffer_; }
93 unsigned int color_buffer()
const {
return color_buffer_; }
94 unsigned int normal_buffer()
const {
return normal_buffer_; }
95 unsigned int texcoord_buffer()
const {
return texcoord_buffer_; }
96 unsigned int element_buffer()
const {
return element_buffer_; }
107 void update_color_buffer(
const std::vector<vec3> &colors,
bool dynamic =
false);
108 void update_normal_buffer(
const std::vector<vec3> &normals,
bool dynamic =
false);
109 void update_texcoord_buffer(
const std::vector<vec2> &texcoords,
bool dynamic =
false);
110 void update_element_buffer(
const std::vector<unsigned int> &elements);
116 void update_element_buffer(
const std::vector< std::vector<unsigned int> > &elements);
126 std::size_t num_vertices()
const {
return num_vertices_; }
198 virtual void update_buffers_internal();
210 std::size_t num_vertices_;
211 std::size_t num_indices_;
216 unsigned int vertex_buffer_;
217 unsigned int color_buffer_;
218 unsigned int normal_buffer_;
219 unsigned int texcoord_buffer_;
220 unsigned int element_buffer_;
A perspective or orthographic camera.
Definition: camera.h:116
The base class for drawable objects. A drawable represent a set of points, line segments,...
Definition: drawable.h:56
Manipulator * manipulator()
Gets the manipulator attached to this drawable.
Definition: drawable.cpp:250
virtual Type type() const =0
Returns the type of the drawable.
Model * model()
the model to which the drawable is attached to (can be NULL).
Definition: drawable.h:77
void set_update_func(const std::function< void(Model *, Drawable *)> &func)
Setups how a drawable updates its rendering buffers.
Definition: drawable.h:162
void update_vertex_buffer(const std::vector< vec3 > &vertices, bool dynamic=false)
Creates/Updates a single buffer.
Definition: drawable.cpp:142
void set_manipulator(Manipulator *manip)
Attaches a manipulator to this model.
Definition: drawable.h:185
void gl_draw() const
Definition: drawable.cpp:224
VertexArrayObject * vao()
Returns the vertex array object of this drawable.
Definition: drawable.h:192
void disable_element_buffer()
Disables the use of the element buffer.
Definition: drawable.cpp:114
void buffer_stats(std::ostream &output) const
print statistics (e.g., num vertices, memory usage) of the buffers to an output stream (e....
Definition: drawable.cpp:70
void update()
Requests an update of the OpenGL buffers.
Definition: drawable.cpp:95
mat4 manipulated_matrix() const
Returns the manipulation matrix.
Definition: drawable.cpp:270
const VertexArrayObject * vao() const
Returns the vertex array object of this drawable.
Definition: drawable.h:194
virtual void draw(const Camera *camera) const =0
The draw method.
A manipulator is for manipulation of an object.
Definition: manipulator.h:62
The base class of renderable 3D models.
Definition: model.h:49
Class representing the rendering state of a drawable.
Definition: state.h:45
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:109