CG_Labs  2021.2
Classes | Typedefs | Enumerations | Functions
bonobo Namespace Reference

Namespace containing a few helpers for the LUGG computer graphics labs.

Classes

struct  material_data
 
struct  mesh_data
 Contains the data for a mesh in OpenGL. More...
 

Typedefs

using texture_bindings = std::unordered_map< std::string, GLuint >
 Association of a sampler name used in GLSL to a corresponding texture ID. More...
 

Enumerations

enum class  shader_bindings : unsigned int {
  vertices = 0u , normals , texcoords , tangents ,
  binormals
}
 Formalise mapping between an OpenGL VAO attribute binding, and the meaning of that attribute. More...
 
enum class  cull_mode_t : unsigned int { disabled = 0u , back_faces , front_faces }
 
enum class  polygon_mode_t : unsigned int { fill = 0u , line , point }
 

Functions

void init ()
 Allocate some objects needed by some helper functions. More...
 
void deinit ()
 Deallocate objects allocated by the init() function. More...
 
std::vector< mesh_dataloadObjects (std::string const &filename)
 Load objects found in an object/scene file, using assimp. More...
 
GLuint createTexture (uint32_t width, uint32_t height, GLenum target=GL_TEXTURE_2D, GLint internal_format=GL_RGBA, GLenum format=GL_RGBA, GLenum type=GL_UNSIGNED_BYTE, GLvoid const *data=nullptr)
 Creates an OpenGL texture without any content nor parameters. More...
 
GLuint loadTexture2D (std::string const &filename, bool generate_mipmap=true)
 Load an image into an OpenGL 2D-texture. More...
 
GLuint loadTextureCubeMap (std::string const &posx, std::string const &negx, std::string const &posy, std::string const &negy, std::string const &posz, std::string const &negz, bool generate_mipmap=true)
 Load six images into an OpenGL cubemap-texture. More...
 
GLuint createProgram (std::string const &vert_shader_source_path, std::string const &frag_shader_source_path)
 Create an OpenGL program consisting of a vertex and a fragment shader. More...
 
void displayTexture (glm::vec2 const &lower_left, glm::vec2 const &upper_right, GLuint texture, GLuint sampler, glm::ivec4 const &swizzle, glm::ivec2 const &window_size, bool linearise=false, float nearPlane=0.0f, float farPlane=0.0f)
 Display the current texture in the specified rectangle. More...
 
GLuint createFBO (std::vector< GLuint > const &color_attachments, GLuint depth_attachment=0u)
 Create an OpenGL FrameBuffer Object using the specified attachments. More...
 
GLuint createSampler (std::function< void(GLuint)> const &setup)
 Create an OpenGL sampler and set it up. More...
 
void drawFullscreen ()
 Draw full screen. More...
 
GLuint getDebugTextureID ()
 Retrieve the ID of a small placeholder texture. More...
 
void renderBasis (float thickness_scale, float length_scale, glm::mat4 const &view_projection, glm::mat4 const &world=glm::mat4(1.0f))
 Render a right-hand orthonormal basis. More...
 
bool uiSelectCullMode (std::string const &label, enum cull_mode_t &cull_mode) noexcept
 Add a combo box to the current ImGUI window, to choose a cull mode. More...
 
void changeCullMode (enum cull_mode_t const cull_mode) noexcept
 Enable or disable culling, and call glCullFace with the specified cull mode. More...
 
bool uiSelectPolygonMode (std::string const &label, enum polygon_mode_t &polygon_mode) noexcept
 Add a combo box to the current ImGUI window, to choose a polygon mode. More...
 
void changePolygonMode (enum polygon_mode_t const polygon_mode) noexcept
 Call glPolygonMode for both front and back faces, with the specified polygon mode. More...
 

Typedef Documentation

◆ texture_bindings

using bonobo::texture_bindings = typedef std::unordered_map<std::string, GLuint>

Enumeration Type Documentation

◆ cull_mode_t

enum bonobo::cull_mode_t : unsigned int
strong
Enumerator
disabled 
back_faces 
front_faces 

◆ polygon_mode_t

enum bonobo::polygon_mode_t : unsigned int
strong
Enumerator
fill 
line 
point 

◆ shader_bindings

enum bonobo::shader_bindings : unsigned int
strong
Enumerator
vertices 

= 0, value of the binding point for vertices

normals 

= 1, value of the binding point for normals

texcoords 

= 2, value of the binding point for texcoords

tangents 

= 3, value of the binding point for tangents

binormals 

= 4, value of the binding point for binormals

Function Documentation

◆ changeCullMode()

void bonobo::changeCullMode ( enum cull_mode_t const  cull_mode)
noexcept

◆ changePolygonMode()

void bonobo::changePolygonMode ( enum polygon_mode_t const  polygon_mode)
noexcept

◆ createFBO()

GLuint bonobo::createFBO ( std::vector< GLuint > const &  color_attachments,
GLuint  depth_attachment = 0u 
)
Parameters
[in]color_attachmentsa vector of all the texture to bind as color attachment, i.e. not as depth texture
[in]depth_attachmenta texture, if any, to use as depth attachment
Returns
the name of the OpenGL FBO

◆ createProgram()

GLuint bonobo::createProgram ( std::string const &  vert_shader_source_path,
std::string const &  frag_shader_source_path 
)
Parameters
[in]vert_shader_source_pathof the vertex shader source code, relative to the shaders/ folder
[in]frag_shader_source_pathof the fragment shader source code, relative to the shaders/ folder
Returns
the name of the OpenGL shader program

◆ createSampler()

GLuint bonobo::createSampler ( std::function< void(GLuint)> const &  setup)
Parameters
[in]setupa lambda function to parameterise the sampler
Returns
the name of the OpenGL sampler

◆ createTexture()

GLuint bonobo::createTexture ( uint32_t  width,
uint32_t  height,
GLenum  target = GL_TEXTURE_2D,
GLint  internal_format = GL_RGBA,
GLenum  format = GL_RGBA,
GLenum  type = GL_UNSIGNED_BYTE,
GLvoid const *  data = nullptr 
)
Parameters
[in]widthwidth of the texture to create
[in]heightheight of the texture to create
[in]targetOpenGL texture target to create, i.e. GL_TEXTURE_2D & co.
[in]internal_formatformatting of the texture, i.e. how many channels
[in]formatformatting of the pixel data, i.e. in which layout are the channels stored
[in]typedata type of the pixel data
[in]datawhat to put in the texture

◆ deinit()

void bonobo::deinit ( )

◆ displayTexture()

void bonobo::displayTexture ( glm::vec2 const &  lower_left,
glm::vec2 const &  upper_right,
GLuint  texture,
GLuint  sampler,
glm::ivec4 const &  swizzle,
glm::ivec2 const &  window_size,
bool  linearise = false,
float  nearPlane = 0.0f,
float  farPlane = 0.0f 
)
Parameters
[in]lower_leftthe lower left corner of the rectangle containing the texture
[in]upper_rightthe upper rigth corner of the rectangle containing the texture
[in]texturethe OpenGL name of the texture to display
[in]samplerthe OpenGL name of the sampler to use
[in]swizzlehow to mix in the different channels, for example (0, 2, 1, -1) will swap the green and blue channels as well as invalidating (setting it to 1) the alpha channel
[in]window_sizethe size in pixels of the main window, the one relative to which you want to draw this texture
[in]linearisewhether the given texture should be linearised using the provided |nearPlane| and |farPlane|.
[in]nearPlanethe near plane used when linearising depth textures; it is ignored if |linearise| is false.
[in]farPlanethe far plane used when linearising depth textures; it is ignored if |linearise| is false.

◆ drawFullscreen()

void bonobo::drawFullscreen ( )

◆ getDebugTextureID()

GLuint bonobo::getDebugTextureID ( )

◆ init()

void bonobo::init ( )

◆ loadObjects()

std::vector< bonobo::mesh_data > bonobo::loadObjects ( std::string const &  filename)
Parameters
[in]filenameof the object/scene file to load.
Returns
a vector of filled in mesh_data structures, one per object found in the input file

◆ loadTexture2D()

GLuint bonobo::loadTexture2D ( std::string const &  filename,
bool  generate_mipmap = true 
)
Parameters
[in]filenameof the image.
[in]generate_mipmapwhether or not to generate a mipmap hierarchy
Returns
the name of the OpenGL 2D-texture

◆ loadTextureCubeMap()

GLuint bonobo::loadTextureCubeMap ( std::string const &  posx,
std::string const &  negx,
std::string const &  posy,
std::string const &  negy,
std::string const &  posz,
std::string const &  negz,
bool  generate_mipmap = true 
)
Parameters
[in]posxpath to the texture on the left of the cubemap
[in]negxpath to the texture on the right of the cubemap
[in]posypath to the texture on the top of the cubemap
[in]negypath to the texture on the bottom of the cubemap
[in]poszpath to the texture on the back of the cubemap
[in]negzpath to the texture on the front of the cubemap
[in]generate_mipmapwhether or not to generate a mipmap hierarchy
Returns
the name of the OpenGL cubemap-texture
Todo:
fill me
Todo:
repeat now the texture filling for the 5 remaining faces

◆ renderBasis()

void bonobo::renderBasis ( float  thickness_scale,
float  length_scale,
glm::mat4 const &  view_projection,
glm::mat4 const &  world = glm::mat4(1.0f) 
)
Parameters
[in]thickness_scaleBy how much to scale the thickness of the axes
[in]length_scaleBy how much to scale the length of the axes
[in]view_projectionMatrix transforming from world-space to clip-space
[in]worldMatrix transforming from model-space to world-space

◆ uiSelectCullMode()

bool bonobo::uiSelectCullMode ( std::string const &  label,
enum cull_mode_t cull_mode 
)
noexcept
Parameters
[in]labelText to be displayed near the combo box.
[in,out]cull_modeThe currently selected cull mode, which will be modified to contain the newly selected one.
Returns
whether the selection was changed

◆ uiSelectPolygonMode()

bool bonobo::uiSelectPolygonMode ( std::string const &  label,
enum polygon_mode_t polygon_mode 
)
noexcept
Parameters
[in]labelText to be displayed near the combo box.
[in,out]polygon_modeThe currently selected polygon mode, which will be modified to contain the newly selected one.
Returns
whether the selection was changed