GPUKit
A framework for implementing reconfigurable rendering pipelines in C++ / OpenGL
github project
About
GPUKit is a C++ framework for rendering with OpenGL in an object-oriented way. The framework implements the following:
- vertex, geometry and fragment shaders.
- programs.
- buffers (FBO).
- 2D and 3D (Cubemap) textures.
- geometry (VAO + VBO + EBO).
Additionally, GPUKit implements the following convenience classes:
Material
: A proxy between programs and per-instance uniform values, allowing multiple materials to share a common program.Pass
: a way to organize the rendering code associated with a program and buffer combination.AssetImporter
: allows importing shaders, 3D geometry and textures and automatically obtaining C++ objects from these.
The project includes an example implementation of a rendering pipeline consisting of:
- deferred shading.
- skybox.
- dynamic point shadows.
- bloom.
- rudimentary rigid-body animation.
Example Shader Program
Creating a vertex + fragment program involves two steps:
- Implement the shaders in a single file annotated with GPUKit commands (Code 1).
#GPUKIT_VERTEX_STAGE
#version 410 core
#pragma debug(on)
// your uniforms, ins and outs...
void main() {
// your vertex code...
}
#GPUKIT_END_STAGE
#GPUKIT_FRAGMENT_STAGE
#GPUKIT_ENABLE depth
#version 410 core
#pragma debug(on)
// your uniforms, ins and outs...
void main() {
// your fragment code...
}
#GPUKIT_END_STAGE
- Import the program via the framework’s
AssetImporter
and link it (Code 2).
Program* program = AssetImporter<Program*>::import("example.glsl");
program->link();
The framework automatically maps uniform locations and pre-sets texture-unit indices. After linking, setting attributes of a program in C++ is straightforward (Code 3).
program->setUniform<vec3>("uniform name", { 1., 1., 1. });
program->commit();
Materials work in a similar way. Any attributes declared as Material
structs in glsl files are automatically picked up by GPUKit and the Material
class proxies their values to the corresponding Program
object, allowing many materials to reference a single program.
For an example on how the rest of the framework’s classes work take a look at the repo.