CG_Labs
2021.2
|
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_data > | loadObjects (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... | |
using bonobo::texture_bindings = typedef std::unordered_map<std::string, GLuint> |
|
strong |
|
strong |
|
strong |
|
noexcept |
|
noexcept |
GLuint bonobo::createFBO | ( | std::vector< GLuint > const & | color_attachments, |
GLuint | depth_attachment = 0u |
||
) |
[in] | color_attachments | a vector of all the texture to bind as color attachment, i.e. not as depth texture |
[in] | depth_attachment | a texture, if any, to use as depth attachment |
GLuint bonobo::createProgram | ( | std::string const & | vert_shader_source_path, |
std::string const & | frag_shader_source_path | ||
) |
[in] | vert_shader_source_path | of the vertex shader source code, relative to the shaders/ folder |
[in] | frag_shader_source_path | of the fragment shader source code, relative to the shaders/ folder |
GLuint bonobo::createSampler | ( | std::function< void(GLuint)> const & | setup | ) |
[in] | setup | a lambda function to parameterise the sampler |
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 |
||
) |
[in] | width | width of the texture to create |
[in] | height | height of the texture to create |
[in] | target | OpenGL texture target to create, i.e. GL_TEXTURE_2D & co. |
[in] | internal_format | formatting of the texture, i.e. how many channels |
[in] | format | formatting of the pixel data, i.e. in which layout are the channels stored |
[in] | type | data type of the pixel data |
[in] | data | what to put in the texture |
void bonobo::deinit | ( | ) |
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 |
||
) |
[in] | lower_left | the lower left corner of the rectangle containing the texture |
[in] | upper_right | the upper rigth corner of the rectangle containing the texture |
[in] | texture | the OpenGL name of the texture to display |
[in] | sampler | the OpenGL name of the sampler to use |
[in] | swizzle | how 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_size | the size in pixels of the main window, the one relative to which you want to draw this texture |
[in] | linearise | whether the given texture should be linearised using the provided |nearPlane| and |farPlane|. |
[in] | nearPlane | the near plane used when linearising depth textures; it is ignored if |linearise| is false. |
[in] | farPlane | the far plane used when linearising depth textures; it is ignored if |linearise| is false. |
void bonobo::drawFullscreen | ( | ) |
GLuint bonobo::getDebugTextureID | ( | ) |
void bonobo::init | ( | ) |
std::vector< bonobo::mesh_data > bonobo::loadObjects | ( | std::string const & | filename | ) |
[in] | filename | of the object/scene file to load. |
mesh_data
structures, one per object found in the input file GLuint bonobo::loadTexture2D | ( | std::string const & | filename, |
bool | generate_mipmap = true |
||
) |
[in] | filename | of the image. |
[in] | generate_mipmap | whether or not to generate a mipmap hierarchy |
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 |
||
) |
[in] | posx | path to the texture on the left of the cubemap |
[in] | negx | path to the texture on the right of the cubemap |
[in] | posy | path to the texture on the top of the cubemap |
[in] | negy | path to the texture on the bottom of the cubemap |
[in] | posz | path to the texture on the back of the cubemap |
[in] | negz | path to the texture on the front of the cubemap |
[in] | generate_mipmap | whether or not to generate a mipmap hierarchy |
void bonobo::renderBasis | ( | float | thickness_scale, |
float | length_scale, | ||
glm::mat4 const & | view_projection, | ||
glm::mat4 const & | world = glm::mat4(1.0f) |
||
) |
[in] | thickness_scale | By how much to scale the thickness of the axes |
[in] | length_scale | By how much to scale the length of the axes |
[in] | view_projection | Matrix transforming from world-space to clip-space |
[in] | world | Matrix transforming from model-space to world-space |
|
noexcept |
[in] | label | Text to be displayed near the combo box. |
[in,out] | cull_mode | The currently selected cull mode, which will be modified to contain the newly selected one. |
|
noexcept |
[in] | label | Text to be displayed near the combo box. |
[in,out] | polygon_mode | The currently selected polygon mode, which will be modified to contain the newly selected one. |