CG_Labs  2021.2
Public Member Functions | Private Attributes | List of all members
Node Class Reference

Represents a node of a scene graph.

#include <node.hpp>

Public Member Functions

void render (glm::mat4 const &view_projection, glm::mat4 const &parent_transform=glm::mat4(1.0f)) const
 Render this node. More...
 
void render (glm::mat4 const &view_projection, glm::mat4 const &world, GLuint program, std::function< void(GLuint)> const &set_uniforms=[](GLuint){}) const
 Render this node with a specific shader program. More...
 
void set_geometry (bonobo::mesh_data const &shape)
 Set the geometry of this node. More...
 
void set_material_constants (bonobo::material_data const &constants)
 Set the material constants of this node. More...
 
size_t get_indices_nb () const
 Get the number of indices to use. More...
 
void set_indices_nb (size_t const &indices_nb)
 Set the number of indices to use. More...
 
void set_program (GLuint const *const program, std::function< void(GLuint)> const &set_uniforms=[](GLuint){})
 Set the program of this node. More...
 
void set_name (std::string const &name)
 Set the name of this node. More...
 
void add_texture (std::string const &name, GLuint tex_id, GLenum type)
 Add a texture to this node. More...
 
void add_child (Node const *child)
 Add a child to this node. More...
 
size_t get_children_nb () const
 Return the number of children to this node. More...
 
Node const * get_child (size_t index) const
 Return the ith child. More...
 
TRSTransformf const & get_transform () const
 Return this node transformation matrix. More...
 
TRSTransformfget_transform ()
 

Private Attributes

GLuint _vao { 0u }
 
GLsizei _vertices_nb { 0u }
 
GLsizei _indices_nb { 0u }
 
GLenum _drawing_mode { GL_TRIANGLES }
 
bool _has_indices { false }
 
GLuint const * _program { nullptr }
 
std::function< void(GLuint)> _set_uniforms
 
std::vector< std::tuple< std::string, GLuint, GLenum > > _textures
 
bonobo::material_data _constants
 
TRSTransformf _transform
 
std::vector< Node const * > _children
 
std::string _name {"Render un-named node"}
 

Member Function Documentation

◆ add_child()

void Node::add_child ( Node const *  child)
Parameters
[in]childpointer to the child to add; the pointer has to be non-null

◆ add_texture()

void Node::add_texture ( std::string const &  name,
GLuint  tex_id,
GLenum  type 
)
Parameters
[in]namethe variable name used by the attached OpenGL shader program; in assignment 1, this will be diffuse_texture
[in]tex_idthe name of an OpenGL 2D-texture
[in]typethe type of texture, i.e. GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.

◆ get_child()

Node const * Node::get_child ( size_t  index) const
Parameters
[in]indexthe index of the child to return; index should be strictly less than the number of children
Returns
a pointer to the desired child

◆ get_children_nb()

size_t Node::get_children_nb ( ) const
Returns
the number of children

◆ get_indices_nb()

size_t Node::get_indices_nb ( ) const
Returns
how many indices to use when rendering

◆ get_transform() [1/2]

TRSTransformf & Node::get_transform ( )

◆ get_transform() [2/2]

TRSTransformf const & Node::get_transform ( ) const
Returns
the composition of the rotation, scaling and translation transformations; this is the model matrix of this node

◆ render() [1/2]

void Node::render ( glm::mat4 const &  view_projection,
glm::mat4 const &  parent_transform = glm::mat4(1.0f) 
) const
Parameters
[in]view_projectionMatrix transforming from world-space to clip-space
[in]parent_transformMatrix transforming from parent-space to world-space

◆ render() [2/2]

void Node::render ( glm::mat4 const &  view_projection,
glm::mat4 const &  world,
GLuint  program,
std::function< void(GLuint)> const &  set_uniforms = [](GLuint ){} 
) const

Note that the internal transform of this node is not used during the rendering, only the |view_projection| and |world| matrices are.

Parameters
[in]view_projectionMatrix transforming from world-space to clip-space
[in]worldMatrix transforming from model-space to world-space
[in]programOpenGL shader program to use
[in]set_uniformsfunction that will take as argument an OpenGL shader program, and will setup that program's uniforms

◆ set_geometry()

void Node::set_geometry ( bonobo::mesh_data const &  shape)

It will overwrite any constants provided by an earlier call to |set_material_constants()|.

A node without any geometry will not render itself, but its children will be rendered if they have any geometry.

Parameters
[in]shapeOpenGL data to use as geometry

◆ set_indices_nb()

void Node::set_indices_nb ( size_t const &  indices_nb)
Parameters
[in]indices_nbhow many indices to use when rendering

◆ set_material_constants()

void Node::set_material_constants ( bonobo::material_data const &  constants)

It will overwrite any constants provided by the geometry.

A node without any geometry will not render itself, but its children will be rendered if they have any geometry.

Parameters
[in]constantsMaterial constants to be made available during rendering

◆ set_name()

void Node::set_name ( std::string const &  name)

This name will be used when pushing debug groups to scope OpenGL commands and help when debugging or profiling the application using third-party applications.

Parameters
[in]namethe name used when creating the debug group during rendering; it will automatically be prefixed by "Render ".

◆ set_program()

void Node::set_program ( GLuint const *const  program,
std::function< void(GLuint)> const &  set_uniforms = [](GLuint ){} 
)

A node without a program will not render itself, but its children will be rendered if they have one.

Parameters
[in]programpointer to the program OpenGL shader program to use; the pointer should not be null.
[in]set_uniformsfunction that will take as argument an OpenGL shader program, and will setup that program's uniforms

Member Data Documentation

◆ _children

std::vector<Node const*> Node::_children
private

◆ _constants

bonobo::material_data Node::_constants
private

◆ _drawing_mode

GLenum Node::_drawing_mode { GL_TRIANGLES }
private

◆ _has_indices

bool Node::_has_indices { false }
private

◆ _indices_nb

GLsizei Node::_indices_nb { 0u }
private

◆ _name

std::string Node::_name {"Render un-named node"}
private

◆ _program

GLuint const* Node::_program { nullptr }
private

◆ _set_uniforms

std::function<void (GLuint)> Node::_set_uniforms
private

◆ _textures

std::vector<std::tuple<std::string, GLuint, GLenum> > Node::_textures
private

◆ _transform

TRSTransformf Node::_transform
private

◆ _vao

GLuint Node::_vao { 0u }
private

◆ _vertices_nb

GLsizei Node::_vertices_nb { 0u }
private

The documentation for this class was generated from the following files: