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,6> dir_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},
60 Vec4f{.4f,0.f,0.f,1.f},
61 Vec4f{0.f,.4f,0.f,1.f},
62 Vec4f{0.f,0.f,.3f,1.f}
65 const std::array<Vec3f, 8> vertices = {
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),
71 Vec3f(-1.f, -1.f, -1.f),
72 Vec3f(-1.f, 1.f, -1.f),
73 Vec3f(-1.f, 1.f, 1.f),
74 Vec3f(-1.f, -1.f, 1.f)};
76 auto add_triangle = [
this, &vertices, &dir_color]
77 (
size_t v0,
size_t v1,
size_t v2,
size_t dim)
79 triangles_.push_back({vertices[v0], vertices[v1], vertices[v2]});
80 triangle_colors_.push_back(dir_color[dim]);
83 triangles_.reserve(6*2);
84 triangle_colors_.reserve(6*2);
85 add_triangle(0, 1, 2, 0);
86 add_triangle(0, 2, 3, 0);
87 add_triangle(4, 6, 5, 3);
88 add_triangle(4, 7, 6, 3);
90 add_triangle(1, 5, 6, 1);
91 add_triangle(1, 6, 2, 1);
92 add_triangle(0, 3, 7, 4);
93 add_triangle(0, 7, 4, 4);
95 add_triangle(2, 7, 3, 2);
96 add_triangle(2, 6, 7, 2);
97 add_triangle(0, 4, 1, 5);
98 add_triangle(1, 4, 5, 5);
106 for (
const auto &be: elem_) {
107 _bbMax.
maximize(be.pos +
Vec3d(scaleFactor_,scaleFactor_,scaleFactor_));
108 _bbMin.
minimize(be.pos +
Vec3d(-scaleFactor_, -scaleFactor_, -scaleFactor_));
112 void BoxesNode::createVBO()
118 geometry_vbo_.bind();
119 instance_vbo_.bind();
123 vertexDecl_.addElement(GL_FLOAT, 4,
VERTEX_USAGE_COLOR,
nullptr,
nullptr, 0, geometry_vbo_.id());
124 std::vector<float> geom_vbo_data; geom_vbo_data.reserve(3 * (3+4) * triangles_.size());
130 std::vector<float> instance_vbo_data; instance_vbo_data.reserve(3 * 4 * elem_.size());
132 assert(triangles_.size() == triangle_colors_.size());
133 for (
size_t i = 0; i < triangles_.size(); ++i)
135 auto &tri = triangles_[i];
136 auto &color = triangle_colors_[i];
137 for (
const auto &point: tri) {
138 std::copy(point.begin(), point.end(), std::back_inserter(geom_vbo_data));
139 std::copy(color.begin(), color.end(), std::back_inserter(geom_vbo_data));
142 for (
const auto &be: elem_) {
143 for (
const auto &point: {
144 be.transform.getRow(0),
145 be.transform.getRow(1),
146 be.transform.getRow(2),
149 std::copy(point.begin(), point.end(), std::back_inserter(instance_vbo_data));
153 geometry_vbo_.upload(
154 static_cast<GLsizeiptr>(geom_vbo_data.size()*
sizeof(float)),
155 geom_vbo_data.data(),
157 instance_vbo_.upload(
158 static_cast<GLsizeiptr>(instance_vbo_data.size()*
sizeof(float)),
159 instance_vbo_data.data(),
176 ro.setMaterial(_mat);
178 boxesNodeName_ = std::string(
"BoxesNode: ")+name();
179 ro.debugName = boxesNodeName_;
182 ro.depthWrite =
true;
185 ro.blendSrc = GL_SRC_ALPHA;
190 ro.
shaderDesc.vertexTemplateFile =
"BoxesNode/vert.glsl";
198 ro.glDrawInstancedArrays(GL_TRIANGLES, 0,
199 static_cast<GLsizei>(3 * triangles_.size()),
200 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.