CG_Labs  2020.0
node.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "TRSTransform.h"
4 
5 #include <glad/glad.h>
6 #include <GLFW/glfw3.h>
7 #include <glm/glm.hpp>
8 
9 #include <functional>
10 #include <string>
11 #include <tuple>
12 #include <vector>
13 
14 namespace bonobo
15 {
16  struct mesh_data;
17 }
18 
20 class Node
21 {
22 public:
24  Node();
25 
31  void render(glm::mat4 const& WVP, glm::mat4 const& parentTransform = glm::mat4(1.0f)) const;
32 
42  void render(glm::mat4 const& WVP, glm::mat4 const& world,
43  GLuint program,
44  std::function<void (GLuint)> const& set_uniforms = [](GLuint /*programID*/){}) const;
45 
52  void set_geometry(bonobo::mesh_data const& shape);
53 
57  size_t get_indices_nb() const;
58 
62  void set_indices_nb(size_t const& indices_nb);
63 
74  void set_program(GLuint const* const program,
75  std::function<void (GLuint)> const& set_uniforms = [](GLuint /*programID*/){});
76 
85  void add_texture(std::string const& name, GLuint tex_id, GLenum type);
86 
91  void add_child(Node const* child);
92 
96  size_t get_children_nb() const;
97 
103  Node const* get_child(size_t index) const;
104 
109  TRSTransformf const& get_transform() const;
111 
112 private:
113  // Geometry data
114  GLuint _vao;
115  GLsizei _vertices_nb;
116  GLsizei _indices_nb;
119 
120  // Program data
121  GLuint const* _program;
122  std::function<void (GLuint)> _set_uniforms;
123 
124  // Textures data
125  std::vector<std::tuple<std::string, GLuint, GLenum>> _textures;
126 
127  // Transformation data
129 
130  // Children data
131  std::vector<Node const*> _children;
132 
133  // Debug data
134  std::string _name;
135 };
Node::_vao
GLuint _vao
Definition: node.hpp:114
Node::_name
std::string _name
Definition: node.hpp:134
Node::_textures
std::vector< std::tuple< std::string, GLuint, GLenum > > _textures
Definition: node.hpp:125
TRSTransform.h
Node::_drawing_mode
GLenum _drawing_mode
Definition: node.hpp:117
Node::_has_indices
bool _has_indices
Definition: node.hpp:118
Node::set_indices_nb
void set_indices_nb(size_t const &indices_nb)
Set the number of indices to use.
Definition: node.cpp:108
Node::get_children_nb
size_t get_children_nb() const
Return the number of children to this node.
Definition: node.cpp:129
Node::_set_uniforms
std::function< void(GLuint)> _set_uniforms
Definition: node.hpp:122
Node::_transform
TRSTransformf _transform
Definition: node.hpp:128
Node::add_texture
void add_texture(std::string const &name, GLuint tex_id, GLenum type)
Add a texture to this node.
Definition: node.cpp:114
Node::set_program
void set_program(GLuint const *const program, std::function< void(GLuint)> const &set_uniforms=[](GLuint){})
Set the program of this node.
Definition: node.cpp:92
Node::render
void render(glm::mat4 const &WVP, glm::mat4 const &parentTransform=glm::mat4(1.0f)) const
Render this node.
Definition: node.cpp:15
Node::_vertices_nb
GLsizei _vertices_nb
Definition: node.hpp:115
bonobo::mesh_data
Contains the data for a mesh in OpenGL.
Definition: helpers.hpp:32
TRSTransform< float, glm::defaultp >
Node
Represents a node of a scene graph.
Definition: node.hpp:21
Node::_program
GLuint const * _program
Definition: node.hpp:121
Node::set_geometry
void set_geometry(bonobo::mesh_data const &shape)
Set the geometry of this node.
Definition: node.cpp:76
Node::get_child
Node const * get_child(size_t index) const
Return the ith child.
Definition: node.cpp:135
Node::Node
Node()
Default constructor.
Definition: node.cpp:10
Node::get_indices_nb
size_t get_indices_nb() const
Get the number of indices to use.
Definition: node.cpp:102
bonobo
Namespace containing a few helpers for the LUGG computer graphics labs.
Definition: helpers.hpp:16
Node::add_child
void add_child(Node const *child)
Add a child to this node.
Definition: node.cpp:121
Node::get_transform
TRSTransformf const & get_transform() const
Return this node transformation matrix.
Definition: node.cpp:142
Node::_children
std::vector< Node const * > _children
Definition: node.hpp:131
Node::_indices_nb
GLsizei _indices_nb
Definition: node.hpp:116