Examples of DSA OpenGL
The evolution of OpenGL basically goes like this: Immediate mode -> Modern OpenGL (3.0+) -> Direct State Access -> Vulkan.
Direct State Access in OpenGL provides a nice balance between verbosity and control. In particular, getting rid of the “state-machine” construct makes programming feel more similar to C++.
Early OpenGL does not provide enough control to the user, but Vulkan can make getting started with graphics very intimidating and prototyping / experimenting with the GPU challenging.
The examples contained in this repo examine many OpenGL concepts and almost exclusively use DSA techniques. There remains more that could be covered.
A very small amount of redundant code was abstracted in the base_app
class. This takes care of loading shaders and setting up a window.
Most of the examples in this project are API examples with limited graphical output, but there is some interesting graphical output.
(All of these are included)
- Linux
- Windows
This project uses Git LFS for assets and CMAKE to build
- Clone this project using git
- From the root of this project update all the submodules with:
git submodule update --init --recursive
- From the root of this project type
cmake -G ${GENERATOR} -DCMAKE_BUILD_TYPE=Debug
or open the project in an editor that directly supports CMAKE files
Where ${GENERATOR}
is the platform (i.e. "Unix Makefiles"
)
- Build and run the individual examples
NOTE: Asset paths are relative and expect your current working directory to be a directory below the assets folder.
i.e. the basic_cube
example should be run from /bin/basic_cube/Debug
bin
: This is where the final binary applications are putbuild
: This holds the generates build filesinclude
: This includes headers from this project and third partiessrc
: This holds the source code for these examples
There are three classes used in the examples: Application
, Camera
and Glslprogram
.
These provided basic needed functionality.
This is an abstract base class used in the examples but it has no graphical output
This is a rotating cube with model-space positions as colors
This renders a cube to an FBO then uses a compute shader to invert that image
This renders to a texture using an FBO
This is a pass through geometry shader
This is a cube geometry shader which converts faces to lines to show normals
This uses mapped buffers to upload data
The buffer backing the VAO is switched to change vertex data quickly
The attribute binding could also be switched to change the vertex data quickly
Interactivity: The spacebar toggles which buffer backs the active VAO
This is a Phong lighting example
Interactivity: This implements cursor lock to control camera position
Mouse wheel to move forward / black
This is a very simple point sprite example
A raytracer
This uses glReadnPixels and mapped Pixel Buffer Objects (to improve performance)
It saves the rendered image as a .tga file
Interactivity: Press spacebar to take a screenshot
This compares the various tesselation spacing options
Interactivity: The up arrow increases tesselation, down arrow decreases tesselationThis compares the var
This uses a displacment map to offset vertices and tesselation
This uses an instanced quad with vertices embedded in the shader (there are no vertex attributes)
Interactivity: w
key toggles showing wireframeThis uses a displacment map to offset vertices and tesselation
This loads an image in the S3TC format
It checks to make sure it is compressed and gets the compressed size
This loads a jpeg image and stores it in the S3TC compressed format
It checks that it is compressed and gets the compressed size
This calculates the square root of some values and reads it back with transform feedback
There is no graphical output
- To use these examples your graphics card must support at least OpenGL 4.5
©️ Willy Nolan 2018