Added documentation

This commit is contained in:
Robert 2021-01-21 15:30:48 +01:00
parent 0a7a835bcc
commit da26e0391f
12 changed files with 930 additions and 79 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(openglu)
project(OpenGLUtility)
set(build_examples ON CACHE BOOL "Build examples")
set(build_documentation ON CACHE BOOL "Generate documentation")
@ -43,8 +43,8 @@ target_include_directories(openglu PUBLIC
if(${build_documentation})
configure_file(doxyfile.in ${CMAKE_BINARY_DIR}/doxyfile @ONLY)
add_custom_target(openglu_doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_SOURCE_DIR}/doxyfile.in"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_BINARY_DIR}/doxyfile"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Building documentation..."
VERBATIM
)

View file

@ -4,7 +4,7 @@
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "OpenGL Utility"
PROJECT_NAME = "@CMAKE_PROJECT_NAME@"
PROJECT_NUMBER =
PROJECT_BRIEF =
PROJECT_LOGO =
@ -29,7 +29,8 @@ ABBREVIATE_BRIEF = "The $name class" \
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ \
@PROJECT_BINARY_DIR@
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
@ -66,7 +67,7 @@ NUM_PROC_THREADS = 1
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_PRIVATE = YES
EXTRACT_PRIV_VIRTUAL = NO
EXTRACT_PACKAGE = NO
EXTRACT_STATIC = NO
@ -118,7 +119,7 @@ WARN_LOGFILE =
#---------------------------------------------------------------------------
# Configuration options related to the input files
#---------------------------------------------------------------------------
#INPUT = ../include
INPUT = @PROJECT_SOURCE_DIR@/include
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.c \
*.cc \

View file

@ -61,7 +61,7 @@ int main(int argc, char** argv)
};
// Make a square
oglu::VertexArray square = oglu::MakeObject(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology));
oglu::VertexArray square = oglu::MakeVertexArray(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology));
// Create a shader
oglu::Shader shader;

View file

@ -1,3 +1,11 @@
/*****************************************************************//**
* @file color.hpp
* @brief Contains convenience for working with colors.
*
* @author Robert
* @date January 2021
*********************************************************************/
#ifndef COLOR_HPP
#define COLOR_HPP
@ -6,33 +14,130 @@
namespace oglu
{
/**
* Convenience class for storing and working with color
*/
class OGLU_API Color
{
public:
/**
* Constructs a transparent black
*/
Color();
/**
* Constructs a new color
*
* @param red Red component
* @param blue Blue component
* @param green Green component
* @param alpha Red component
*/
Color(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha = 255);
public:
GLfloat r, g, b, a;
GLfloat r; ///< Red channel
GLfloat g; ///< Green channel
GLfloat b; ///< Blue channel
GLfloat a; ///< Alpha channel
static const Color Black;
static const Color White;
static const Color Red;
static const Color Green;
static const Color Blue;
static const Color Yellow;
static const Color Magenta;
static const Color Cyan;
static const Color Transparent;
static const Color Black; ///< Predefined Black
static const Color White; ///< Predefined White
static const Color Red; ///< Predefined Red
static const Color Green; ///< Predefined Green
static const Color Blue; ///< Predefined Blue
static const Color Yellow; ///< Predefined Yellow
static const Color Magenta; ///< Predefined Magenta
static const Color Cyan; ///< Predefined Cyan
static const Color Transparent; ///< Predefined Transparent
};
/**
* @relates Color
* @brief Checks if two colors are equal.
*
* @param left Left operand
* @param right Right operand
*
* @returns True if every color channel is equal
*/
OGLU_API bool operator==(const Color& left, const Color& right);
/**
* @relates Color
* @brief Checks if two colors are different.
*
* @param left Left operand
* @param right Right operand
*
* @returns True if not every color channel is equal
*/
OGLU_API bool operator!=(const Color& left, const Color& right);
/**
* @relates Color
* @brief Sums two colors
*
* @param left Left operand
* @param right Right operand
*
* @returns The sum of @p left and @p right. The result is clamped to the OpenGL color range.
*/
OGLU_API Color operator+(const Color& left, const Color& right);
/**
* @relates Color
* @brief Subtracts two colors
*
* @param left Left operand
* @param right Right operand
*
* @returns The difference of @p left and @p right. The result is clamped to the OpenGL color range.
*/
OGLU_API Color operator-(const Color& left, const Color& right);
/**
* @relates Color
* @brief Multiplies two colors component-wise
*
* @param left Left operand
* @param right Right operand
*
* @returns The componen-wise product of @p left and @p right.
*/
OGLU_API Color operator*(const Color& left, const Color& right);
/**
* @relates Color
* @brief Sums two colors
*
* @param left Left operand
* @param right Right operand
*
* @returns Reference to @p left
*/
OGLU_API Color& operator+=(Color& left, const Color& right);
/**
* @relates Color
* @brief Subtracts two colors
*
* @param left Left operand
* @param right Right operand
*
* @returns Reference to @p left
*/
OGLU_API Color& operator-=(Color& left, const Color& right);
/**
* @relates Color
* @brief Multiplies two colors component-wise
*
* @param left Left operand
* @param right Right operand
*
* @returns Reference to @p left
*/
OGLU_API Color& operator*=(Color& left, const Color& right);
}

View file

@ -1,3 +1,11 @@
/*****************************************************************//**
* \file core.hpp
* \brief Core includes and defines
*
* \author Robert
* \date January 2021
*********************************************************************/
#ifndef CORE_HPP
#define CORE_HPP

View file

@ -1,44 +0,0 @@
#ifndef DRAWABLE_HPP
#define DRAWABLE_HPP
#include <core.hpp>
namespace oglu
{
typedef OGLU_API struct {
GLuint index;
GLint size;
GLenum type;
GLboolean normalized;
GLsizei stride;
const GLvoid* pointer;
} VertexAttribute;
class OGLU_API AbstractVertexArray
{
public:
AbstractVertexArray(const AbstractVertexArray& other);
~AbstractVertexArray();
friend std::shared_ptr<AbstractVertexArray> OGLU_API MakeObject(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize);
GLuint GetVAO() { return VAO; }
void Bind();
void Unbind();
void Draw();
void BindAndDraw();
private:
AbstractVertexArray(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize);
inline void RegisterVertexAttribPointer(GLuint index, const VertexAttribute& topology);
GLuint VAO, VBO, EBO;
GLsizei count;
};
typedef std::shared_ptr<AbstractVertexArray> VertexArray;
}
#endif

View file

@ -1,17 +1,48 @@
/*****************************************************************//**
* @file openglu.hpp
* @brief Basic includes and some exposed OpenGL
*
* @author Lauchmelder
* @date January 2021
*********************************************************************/
#ifndef OPENGLU_HPP
#define OPENGLU_HPP
#include <color.hpp>
#include <object.hpp>
#include <vertexArray.hpp>
#include <shader.hpp>
#include <texture.hpp>
namespace oglu
{
/**
* @brief Loads the GL Loader to be used by OGLU.
*
* OpenGL function addresses can vary across platforms and drivers, so we
* need to know where these functions are in order to work properly.
*
* @param[in] proc A pointer to a function that returns the addresses of OpenGL functions
*/
OGLU_API void LoadGLLoader(GLADloadproc proc);
// Some raw, exposed OpenGL until I know where to put then
/**
* @brief Wrapper of glViewport.
*
* @param[in] x Horizontal Position of the viewport
* @param[in] y Vertical Position of the viewport
* @param[in] width Width of the viewport
* @param[in] height Height of the viewport
*/
OGLU_API void SetViewport(GLint x, GLint y, GLsizei width, GLsizei height);
/**
* @brief Convenience function for glClear
*
* Sets the clear color and then clears the screen.
*
* @param[in] mask Buffers to be cleared
* @param[in] clearColor Color to clear the screen with
*/
OGLU_API void ClearScreen(GLbitfield mask, Color clearColor);
}

View file

@ -1,3 +1,11 @@
/*****************************************************************//**
* \file shader.hpp
* \brief Contains functions and objects relevant to shading
*
* \author Robert
* \date January 2021
*********************************************************************/
#ifndef SHADER_HPP
#define SHADER_HPP
@ -7,128 +15,689 @@ namespace oglu
{
class Color;
/**
* @brief An object representing an OpenGL Shader Program.
*
* This class contains the OpenGL Shader Program and supplies the user
* with functions to operate on this program.
*
* This class cannot be instantiated, this should be done via MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile).
*/
class OGLU_API AbstractShader
{
public:
/**
* @brief Constructs a new shader program.
*
* Use this function to create new shaders.
*
* @param[in] vertexShaderFile Filepath to the vertex shader
* @param[in] fragmentShaderFile Filepath to the fragment shader
*
* @return A shared pointer to the shader program.
*/
friend std::shared_ptr<AbstractShader> OGLU_API MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile);
/**
* @brief Copy constructor.
*
* Copying a shader is generally possible. Since the user is given a shared pointer the
* shader program is only deleted once every instance has been deconstructed.
*
* @param[in] other Shader to copy from
*/
AbstractShader(const AbstractShader& other);
~AbstractShader();
/**
* @brief Use this shader.
*/
void Use();
/**
* @brief Get the uniform location within the program.
*
* @param[in] name Name of the uniform
*
* @return Location of the uniform.
*/
GLint GetUniformLocation(const GLchar* name);
#pragma region Uniforms
/**
* @brief Set uniform float.
*
* @param[in] name Name of the uniform
* @param[in] v0 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLfloat v0);
/**
* @brief Set uniform float.
*
* @param[in] location Location of the uniform
* @param[in] v0 Value to set the uniform to
*/
void SetUniform(GLint location, GLfloat v0);
/**
* @brief Set uniform vec2.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLfloat v0, GLfloat v1);
/**
* @brief Set uniform vec2.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1 Value to set the uniform to
*/
void SetUniform(GLint location, GLfloat v0, GLfloat v1);
/**
* @brief Set uniform vec3.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1, v2 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLfloat v0, GLfloat v1, GLfloat v2);
/**
* @brief Set uniform vec3.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1, v2 Value to set the uniform to
*/
void SetUniform(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
/**
* @brief Set uniform vec4.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1, v2, v3 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
/**
* @brief Set uniform vec4.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1, v2, v3 Value to set the uniform to
*/
void SetUniform(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
/**
* @brief Set uniform int.
*
* @param[in] name Name of the uniform
* @param[in] v0 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLint v0);
/**
* @brief Set uniform int.
*
* @param[in] location Location of the uniform
* @param[in] v0 Value to set the uniform to
*/
void SetUniform(GLint location, GLint v0);
/**
* @brief Set uniform ivec2.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLint v0, GLint v1);
/**
* @brief Set uniform ivec2.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1 Value to set the uniform to
*/
void SetUniform(GLint location, GLint v0, GLint v1);
/**
* @brief Set uniform ivec3.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1, v2 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLint v0, GLint v1, GLint v2);
/**
* @brief Set uniform ivec3.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1, v2 Value to set the uniform to
*/
void SetUniform(GLint location, GLint v0, GLint v1, GLint v2);
/**
* @brief Set uniform ivec4.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1, v2, v3 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLint v0, GLint v1, GLint v2, GLint v3);
/**
* @brief Set uniform ivec4.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1, v2, v3 Value to set the uniform to
*/
void SetUniform(GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
/**
* @brief Set uniform uint.
*
* @param[in] name Name of the uniform
* @param[in] v0 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLuint v0);
/**
* @brief Set uniform uint.
*
* @param[in] location Location of the uniform
* @param[in] v0 Value to set the uniform to
*/
void SetUniform(GLint location, GLuint v0);
/**
* @brief Set uniform uvec2.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLuint v0, GLuint v1);
/**
* @brief Set uniform uvec2.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1 Value to set the uniform to
*/
void SetUniform(GLint location, GLuint v0, GLuint v1);
/**
* @brief Set uniform uvec3.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1, v2 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLuint v0, GLuint v1, GLuint v2);
/**
* @brief Set uniform uvec3.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1, v2 Value to set the uniform to
*/
void SetUniform(GLint location, GLuint v0, GLuint v1, GLuint v2);
/**
* @brief Set uniform uvec4.
*
* @param[in] name Name of the uniform
* @param[in] v0, v1, v2, v3 Value to set the uniform to
*/
void SetUniform(const GLchar* name, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
/**
* @brief Set uniform uvec4.
*
* @param[in] location Location of the uniform
* @param[in] v0, v1, v2, v3 Value to set the uniform to
*/
void SetUniform(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
void SetUniform(const GLchar* name, const Color* v0, bool ignoreAlpha = false);
void SetUniform(GLint location, const Color* v0, bool ignoreAlpha = false);
/**
* @brief Set uniform color.
*
* Sets either a uniform vec3 or vec4, depending on wether alpha is enabled.
*
* @param[in] name Name of the uniform
* @param[in] v0 Value to set the uniform to
* @param[in] ignoreAlpha Toggles the alpha channel
*/
void SetUniform(const GLchar* name, const Color& v0, bool ignoreAlpha = false);
/**
* @brief Set uniform color.
*
* Sets either a uniform vec3 or vec4, depending on wether alpha is enabled.
*
* @param[in] location Location of the uniform
* @param[in] v0 Value to set the uniform to
* @param[in] ignoreAlpha Toggles the alpha channel
*/
void SetUniform(GLint location, const Color& v0, bool ignoreAlpha = false);
/**
* @brief Set array of uniform float.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value);
/**
* @brief Set array of uniform float.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform1fv(GLint location, GLsizei count, const GLfloat* value);
/**
* @brief Set array of uniform vec2.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform2fv(const GLchar* name, GLsizei count, const GLfloat* value);
/**
* @brief Set array of uniform vec2.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform2fv(GLint location, GLsizei count, const GLfloat* value);
/**
* @brief Set array of uniform vec3.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform3fv(const GLchar* name, GLsizei count, const GLfloat* value);
/**
* @brief Set array of uniform vec3.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform3fv(GLint location, GLsizei count, const GLfloat* value);
/**
* @brief Set array of uniform vec4.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform4fv(const GLchar* name, GLsizei count, const GLfloat* value);
/**
* @brief Set array of uniform vec4.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform4fv(GLint location, GLsizei count, const GLfloat* value);
/**
* @brief Set array of uniform int.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform1iv(const GLchar* name, GLsizei count, const GLint* value);
/**
* @brief Set array of uniform int.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform1iv(GLint location, GLsizei count, const GLint* value);
/**
* @brief Set array of uniform ivec2.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform2iv(const GLchar* name, GLsizei count, const GLint* value);
/**
* @brief Set array of uniform ivec2.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform2iv(GLint location, GLsizei count, const GLint* value);
/**
* @brief Set array of uniform ivec3.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform3iv(const GLchar* name, GLsizei count, const GLint* value);
/**
* @brief Set array of uniform ivec3.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform3iv(GLint location, GLsizei count, const GLint* value);
/**
* @brief Set array of uniform ivec4.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform4iv(const GLchar* name, GLsizei count, const GLint* value);
/**
* @brief Set array of uniform ivec4.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform4iv(GLint location, GLsizei count, const GLint* value);
/**
* @brief Set array of uniform uint.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform1uiv(const GLchar* name, GLsizei count, const GLuint* value);
/**
* @brief Set array of uniform uint.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform1uiv(GLint location, GLsizei count, const GLuint* value);
/**
* @brief Set array of uniform uvec2.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform2uiv(const GLchar* name, GLsizei count, const GLuint* value);
/**
* @brief Set array of uniform uvec2.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform2uiv(GLint location, GLsizei count, const GLuint* value);
/**
* @brief Set array of uniform uvec3.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform3uiv(const GLchar* name, GLsizei count, const GLuint* value);
/**
* @brief Set array of uniform uvec3.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform3uiv(GLint location, GLsizei count, const GLuint* value);
/**
* @brief Set array of uniform uvec4.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform4uiv(const GLchar* name, GLsizei count, const GLuint* value);
/**
* @brief Set array of uniform uvec4.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] value Values to set uniforms to
*/
void SetUniform4uiv(GLint location, GLsizei count, const GLuint* value);
/**
* @brief Set (array of) uniform 2x2 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix2fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 2x2 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 3x3 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix3fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 3x3 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 4x4 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix4fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 4x4 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 2x3 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix2x3fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 2x3 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 3x2 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix3x2fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 3x2 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 2x4 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix2x4fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 2x4 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 4x2 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix4x2fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 4x2 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 3x4 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix3x4fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 3x4 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 4x3 matrix.
*
* @param[in] name Name of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix4x3fv(const GLchar* name, GLsizei count, GLboolean transpose, const GLfloat* value);
/**
* @brief Set (array of) uniform 4x3 matrix.
*
* @param[in] location Location of the uniform
* @param[in] count Amount of elements to set
* @param[in] transpose Wether to transpose the supplied matrix
* @param[in] value Values to set uniforms to
*/
void SetUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
#pragma endregion Uniforms
private:
/**
* @brief Construct a shader program.
*
* To avoid accidental deletion of shader programs while they're still in use,
* this constructor has been made private. To create a shader program use
* MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile).
*
* @param[in] vertexShaderFile Filepath to the vertex shader
* @param[in] fragmentShaderFile Filepath to the fragment shader
*/
AbstractShader(const char* vertexShaderFile, const char* fragmentShaderFile);
/**
* @brief Loads a shader file from disk
*
* @param[in] filename Filepath to the shader
* @param[out] buffer Contents of the shader file
*/
void LoadShaderSource(const char* filename, char** buffer);
private:
GLuint program;
GLuint program; ///< Handle to the Shader program
};
typedef std::shared_ptr<AbstractShader> Shader;

View file

@ -1,3 +1,11 @@
/*****************************************************************//**
* \file texture.hpp
* \brief Contains functions and objects relevant to textures
*
* \author Robert
* \date January 2021
*********************************************************************/
#ifndef TEXTURE_HPP
#define TEXTURE_HPP
@ -5,25 +13,74 @@
namespace oglu
{
/**
* @relates AbstractTexture
* @brief Set active texture unit
*
* @param[in] index Index of the texture unit (Note: This index is actually an offset to @p GL_TEXTURE0)
*/
void ActiveTexture(GLubyte index);
/**
* @brief An object representing an OpenGL Texture.
*
* This class contains the OpenGL Texture and supplies the user
* with functions to operate on this texture.
*
* This class cannot be instantiated, this should be done via MakeTexture(const char* filename).
*/
class OGLU_API AbstractTexture
{
public:
/**
* @brief Constructs a new texture.
*
* Use this function to create new textures.
*
* @param[in] vertexShaderFile Filepath to the image file
*
* @return A shared pointer to the texture.
*/
friend std::shared_ptr<AbstractTexture> OGLU_API MakeTexture(const char* filename);
/**
* @brief Copy constructor.
*
* Copying a texture is generally possible. Since the user is given a shared pointer the
* texture is only deleted once every instance has been deconstructed.
*
* @param[in] other Texture to copy from
*/
AbstractTexture(const AbstractTexture& other);
~AbstractTexture();
friend std::shared_ptr<AbstractTexture> OGLU_API MakeTexture(const char* filename);
/**
* @brief Bind this texture.
*/
void Bind();
/**
* @brief Unbind this texture.
*/
void Unbind();
private:
/**
* @brief Construct a texture.
*
* To avoid accidental deletion of textures while they're still in use,
* this constructor has been made private. To create a texture use
* MakeTexture(const char* filename).
*
* @param[in] vertexShaderFile Filepath to the image file
*/
AbstractTexture(const char* filename);
private:
int width, height, nrChannels;
GLuint texture;
int width; ///< Width of the loaded image
int height; ///< Height of the loaded image
int nrChannels; ///< Channels of the loaded image
GLuint texture; ///< OpenGL handle to the texture
};
typedef std::shared_ptr<AbstractTexture> Texture;

124
include/vertexArray.hpp Normal file
View file

@ -0,0 +1,124 @@
/*****************************************************************//**
* \file vertexArray.hpp
* \brief Contains functions and objects relevant to VAOs
*
* \author Robert
* \date January 2021
*********************************************************************/
#ifndef VERTEXARRAY_HPP
#define VERTEXARRAY_HPP
#include <core.hpp>
namespace oglu
{
/**
* @brief Structure to store topology data.
*/
OGLU_API struct VertexAttribute {
/*@{*/
GLuint index; ///< Index of the vertex attribute
GLint size; ///< Number of elements in this attribute
GLenum type; ///< Datatype of the elements
GLboolean normalized; ///< Normalize fixed-point data
GLsizei stride; ///< Byte offset between these attributes
const GLvoid* pointer; ///< Offset of this attribute into the data
/*@}*/
};
/**
* @brief An object representing an OpenGL VAO.
*
* This class contains the OpenGL VAO and supplies the user
* with functions to operate on this VAO.
*
* This class cannot be instantiated, this should be done via MakeVertexArray().
*/
class OGLU_API AbstractVertexArray
{
public:
/**
* @brief Constructs a new VAO.
*
* Use this function to create new VAOs.
*
* @param[in] vertices Array of vertex data
* @param[in] verticesSize Size of vertex array
* @param[in] indices Array of index data
* @param[in] indicesSize Size of index array
* @param[in] topology Array of VertexAttribute
* @param[in] topologySize Size of topology array
*
* @return A shared pointer to the texture.
*/
friend std::shared_ptr<AbstractVertexArray> OGLU_API MakeVertexArray(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize);
/**
* @brief Copy constructor.
*
* Copying a VAO is generally possible. Since the user is given a shared pointer the
* VAO is only deleted once every instance has been deconstructed.
*
* @param[in] other VAO to copy from
*/
AbstractVertexArray(const AbstractVertexArray& other);
~AbstractVertexArray();
/**
* @brief Bind this VAO.
*/
void Bind();
/**
* @brief Unbind this VAO.
*/
void Unbind();
/**
* @brief Draw this VAO.
*
* This function does not bind the VAO before drawing, be careful when using this. Also see: BindAndDraw()
*/
void Draw();
/**
* @brief Draw this VAO.
*
* This function binds, draws, then unbinds the VAO. Also see: Draw()
*/
void BindAndDraw();
private:
/**
* @brief Construct a VAO.
*
* To avoid accidental deletion of VAO while they're still in use,
* this constructor has been made private. To create a texture use
* MakeVertexArray().
*
* @param[in] vertices Array of vertex data
* @param[in] verticesSize Size of vertex array
* @param[in] indices Array of index data
* @param[in] indicesSize Size of index array
* @param[in] topology Array of VertexAttribute
* @param[in] topologySize Size of topology array
*/
AbstractVertexArray(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize);
/**
* @brief Registers and enables a Vertex Attribute Pointer.
*/
inline void RegisterVertexAttribPointer(GLuint index, const VertexAttribute& topology);
// TODO: Create new class for Buffer objects. Then multiple VAOs can use the same buffers
GLuint VAO; ///< Handle to OpenGL VAO
GLuint VBO; ///< Handle to OpenGL VBO
GLuint EBO; ///< Handle to OpenGL EBO
GLsizei count; ///< Amount of indices
};
typedef std::shared_ptr<AbstractVertexArray> VertexArray;
}
#endif

View file

@ -213,17 +213,17 @@ namespace oglu
glUniform4ui(location, v0, v1, v2, v3);
}
void AbstractShader::SetUniform(const GLchar* name, const Color* v0, bool ignoreAlpha)
void AbstractShader::SetUniform(const GLchar* name, const Color& v0, bool ignoreAlpha)
{
SetUniform(glGetUniformLocation(program, name), v0, ignoreAlpha);
}
void AbstractShader::SetUniform(GLint location, const Color* v0, bool ignoreAlpha)
void AbstractShader::SetUniform(GLint location, const Color& v0, bool ignoreAlpha)
{
if (ignoreAlpha)
glUniform3f(location, v0->r, v0->g, v0->b);
glUniform3f(location, v0.r, v0.g, v0.b);
else
glUniform4f(location, v0->r, v0->g, v0->b, v0->a);
glUniform4f(location, v0.r, v0.g, v0.b, v0.a);
}
void AbstractShader::SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value)

View file

@ -1,4 +1,4 @@
#include "object.hpp"
#include "vertexArray.hpp"
namespace oglu
{
@ -16,7 +16,7 @@ namespace oglu
glDeleteBuffers(1, &EBO);
}
VertexArray MakeObject(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize)
VertexArray MakeVertexArray(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize)
{
AbstractVertexArray* obj = new AbstractVertexArray(vertices, verticesSize, indices, indicesSize, topology, topologySize);
return VertexArray(obj);