A simple template implementation using SDL for quickly applying the modern OpenGL pipeline to projects.
The easiest way to utilise this library appears to be:
include
directory into your own include directory's root.lib\<architecture>
directory into your relevant lib directories.<configuration>\<architecture>
into your relevant build directories.SDL2.lib
SDL2_image.lib
glew32.lib
OpenGL32.lib
glu32.lib
freetype263.lib
main.cpp
, to remove the duplicate entry point.sdl_exp/visualisation
directory into your own source directory.Scene
and overrides all of its virtual methods
EntityScene.h
& EntityScene.cpp
are provided as an example of how to configure your own Scene
.TwoPassScene.h
& TwoPassScene.cpp
are provided as an example of how to configure a more advanced multipass Scene
.Visualisation v = Visualisation("Visulisation Example", 1280, 720);
EntityScene *scene = new EntityScene(v);
v.run();
The Shaders
, Entity
and Model
objects attempt to automatically manage uniforms and attributes, you can assist their functioning by using the below naming schemes for your uniforms and vertex attributes. Each shader object should only be attached to a single entity, otherwise their bindings will all be shared. You can also configure your own static and dynamic uniform floats and ints by calling addStaticUniform()
and addDynamicUniform()
on the relevant Shaders
object.
_modelViewMat
- ModelView Matrix[mat4]_projectionMat
- Projection Matrix[mat4]_modelViewProjectionMat
- ModelViewProjection Matrix[mat4]_viewMat
- View Matrix[mat4]_normalMat
- Normal Matrix[mat3]_texture
- Texture Sampler[sampler2D/samplerCube]_materialID
- Active material index within material uniform buffer[uint]_materials
- Materials uniform block, see example shader material_phong.frag
_lights
- Lighting uniform block, see example shader material_phong.frag
_bones
- Bones uniform block, see example shader bone.vert
_color
- gl_Color equivalent[vec3/vec4] (Material support has replaced this in most example shaders, partial support may still be present)_vertex
- Vertex Position[vec3/vec4]_normal
- Vertex Normal[vec3/vec4]_color
- Vertex Color[vec3/vec4]_texCoords
- Texture Coordinates[Vec2/Vec3]_boneIDs
- Bone indexes, carries 4 individual bone indexes for the vertex[uvec4]_boneWeights
- Bone weights, carries 4 individual bone weights[vec4]It's possible to force laptops with Optimus hybrid graphics to handle this application with the dedicated GPU by building with the preprocessor macro FORCE_OPTIMUS
, this is disabled by default to better facilitate testing on Intel integrated.
The header visualisation/util/cuda.cuh
provides functionality for allocating and freeing OpenGL texture buffers that can be accessed by CUDA.
If you wish to write to these textures asynchronously of their accesses by shaders it is recommended you use some form of locking.
The header was initially written for use with the CUDA 7.5 API.
In order to enable CUDA compilation/support in the project you must follow these steps:
.cu.cpp
files to .cu
. (Without this the .cu.cpp
files will not CUDA compiled correctly.).cu
files to build with the CUDA compilercuda.lib
and cudart.lib
dependencies to the linker settingsUsage:
CUDATextureBuffer
using mallocGLInteropTextureBuffer<float>()
float
can be replaced with int
or unsigned int
TextureBuffer
object, which can be treated like other Texture
subclasses.d_mappedPointer
member variable to read/write from the buffer as you would with any normal device pointer.tex1Dfetch<float4>()
) passing the cuTextureObj
member variable as the first argument.cuTextureObj
member variable as a kernel parameter or copy it to a device constantinstanced_flat.vert
provides an example.i
and u
respectively should be prepended to samplerBuffer
, texelFetch()
and vec4
in the following steps if you are using int
or unsigned int
data instead of the default float
.uniform samplerBuffer
sampler inside your shader.texelFetch()
, passing the identifer of your samplerBuffer
as the first argument, and the desired index as the second argument.
vec4
, if your element has less than 4 components ignore those you do not require.gl_InstanceID
. #extension GL_EXT_gpu_shader4 : require
to the shader on the line directly after #version
.texelFetch()
, itexelFetch()
and utexelFetch()
with calls to texelFetchBuffer()
. This function returns the right type of vec4
, based on the samplerBuffer
type.Shaders
object from your vertex shader source:addTextureUniform()
on your Shaders
object:
glTexName
member variable.uniform sampleBuffer
within your vertex shader source.GL_TEXTURE_BUFFER
.Shaders
object to an Entity
and render!CUDATextureBuffer
to freeGLInteropTextureBuffer(CUDATextureBuffer *texBuf)
. This will deallocate the texture buffer and delete the CUDATextureBuffer
struct.Additional Usage:
glBindBuffer()
passing the glTBO
member variable as the argument.glTBO
member variable is the buffers 'name', you can use this with various OpenGL buffer methods.glBufferData()
passing GL_TEXTURE_BUFFER
as the first argument.glGetBufferSubData()
passing GL_TEXTURE_BUFFER
as the first argument.glBindBuffer(0)
.uniform samplerBuffer
within the shader, to the texture unit into which you will load the desired texture buffer.
glGet(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)-1
(remember this value, it must be reused at render). In most cases you can simply increment this value from 0 for each unique texture, texture units can be reused across seperate render calls per frame.glUniform1i()
to then set this value within the shader, where the second parameter can be gained using glGetUniformLocation()
if not stated within the vertex shader source.glActiveTexture()
GL_TEXTURE0
+ the value you earlier stored in the shaders uniform samplerBuffer
glBindTexture()
passing GL_TEXTURE_BUFFER
as the first argument, and the glTexName
member variable as the second argument.glActiveTexture()
again, followed by glBindBuffer(0)
to clear the texture unit.All dependent libraries are included within the repo, licenses are available on their respective websites.