43 #include <ACG/GL/acg_glew.hh> 44 #include "BoxesNode.hh" 45 #include <ACG/GL/IRenderer.hh> 51 BoxesNode::BoxesNode(
BaseNode* _parent,
56 const std::array<Vec4f,3> dim_color = {
57 Vec4f{1.f,0.f,0.f,1.f},
58 Vec4f{0.f,1.f,0.f,1.f},
59 Vec4f{0.f,0.f,1.f,1.f}
62 const std::array<Vec3f, 8> vertices = {
63 Vec3f( 1.f, -1.f, -1.f),
64 Vec3f( 1.f, 1.f, -1.f),
65 Vec3f( 1.f, 1.f, 1.f),
66 Vec3f( 1.f, -1.f, 1.f),
67 Vec3f(-1.f, -1.f, -1.f),
68 Vec3f(-1.f, 1.f, -1.f),
69 Vec3f(-1.f, 1.f, 1.f),
70 Vec3f(-1.f, -1.f, 1.f)};
72 auto add_triangle = [
this, &vertices, &dim_color]
73 (
size_t v0,
size_t v1,
size_t v2,
size_t dim)
75 triangles_.push_back({vertices[v0], vertices[v1], vertices[v2]});
76 triangle_colors_.push_back(dim_color[dim]);
79 triangles_.reserve(6*2);
80 triangle_colors_.reserve(6*2);
81 add_triangle(0, 1, 2, 0);
82 add_triangle(0, 2, 3, 0);
83 add_triangle(4, 6, 5, 0);
84 add_triangle(4, 7, 6, 0);
86 add_triangle(1, 5, 6, 1);
87 add_triangle(1, 6, 2, 1);
88 add_triangle(0, 3, 7, 1);
89 add_triangle(0, 7, 4, 1);
91 add_triangle(2, 7, 3, 2);
92 add_triangle(2, 6, 7, 2);
93 add_triangle(0, 4, 1, 2);
94 add_triangle(1, 4, 5, 2);
102 for (
const auto &be: elem_) {
103 _bbMax.
maximize(be.pos +
Vec3d(scaleFactor_,scaleFactor_,scaleFactor_));
104 _bbMin.
minimize(be.pos +
Vec3d(-scaleFactor_, -scaleFactor_, -scaleFactor_));
108 void BoxesNode::createVBO()
114 geometry_vbo_.bind();
115 instance_vbo_.bind();
119 vertexDecl_.addElement(GL_FLOAT, 4,
VERTEX_USAGE_COLOR,
nullptr,
nullptr, 0, geometry_vbo_.id());
120 std::vector<float> geom_vbo_data; geom_vbo_data.reserve(3 * (3+4) * triangles_.size());
126 std::vector<float> instance_vbo_data; instance_vbo_data.reserve(3 * 4 * elem_.size());
128 assert(triangles_.size() == triangle_colors_.size());
129 for (
size_t i = 0; i < triangles_.size(); ++i)
131 auto &tri = triangles_[i];
132 auto &color = triangle_colors_[i];
133 for (
const auto &point: tri) {
134 std::copy(point.begin(), point.end(), std::back_inserter(geom_vbo_data));
135 std::copy(color.begin(), color.end(), std::back_inserter(geom_vbo_data));
138 for (
const auto &be: elem_) {
139 for (
const auto &point: {
140 be.transform.getRow(0),
141 be.transform.getRow(1),
142 be.transform.getRow(2),
145 std::copy(point.begin(), point.end(), std::back_inserter(instance_vbo_data));
149 geometry_vbo_.upload(
150 static_cast<GLsizeiptr>(geom_vbo_data.size()*
sizeof(float)),
151 geom_vbo_data.data(),
153 instance_vbo_.upload(
154 static_cast<GLsizeiptr>(instance_vbo_data.size()*
sizeof(float)),
155 instance_vbo_data.data(),
172 ro.setMaterial(_mat);
174 boxesNodeName_ = std::string(
"BoxesNode: ")+name();
175 ro.debugName = boxesNodeName_;
178 ro.depthWrite =
true;
181 ro.blendSrc = GL_SRC_ALPHA;
186 ro.
shaderDesc.vertexTemplateFile =
"BoxesNode/vert.glsl";
194 ro.glDrawInstancedArrays(GL_TRIANGLES, 0,
195 static_cast<GLsizei>(3 * triangles_.size()),
196 static_cast<GLsizei>(elem_.size()));
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
defined by user via VertexElement::shaderInputName_
Namespace providing different geometric functions concerning angles.
ShaderGenDesc shaderDesc
Drawmode and other shader params.
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
Interface class between scenegraph and renderer.