Skip to content

Shader Class

Nolan Burfield edited this page Aug 4, 2016 · 3 revisions

Functions

Shader()

Sets the program to 0.

~Shader()

Deletes the list of shaders that were created. Deletes the program that was built.

bool Initialize()

Creates a program to attach the shaders to.

void Enable()

Sets the program as the rendering state in the OpenGL pipeline.

bool AddShader(GLenum ShaderType)

The shaders here are written into the code and will be set to the string depending on the type selected to load. A shader object is creates and added to the list. The shader code is added to the shader object and compiled. Check for errors compiling and then add it to the program.

bool Finalize()

Finally the program must be linked and validated. Then the shader list is no longer needed so it can be deleted.

GLint GetUniformLocation(const char* pUniformName)

This function is used to find the location of variables in the program and return the location to the caller. Used to find items such as model, view, and projection matrix.

Variables

GLuint m_shaderProg

The program that all is linked to and loaded for use in the rendering.

std::vector m_shaderObjList

A list of the shaders to keep them together.

Notes

Adding shaders can be adjusted later on when needed to read a shader from a file. Multiple shader classes can be used in one Project to render objects differently. Think Per-Vertex and Per-Fragment lighting and there is no need to write multiple programs to see the difference just have different shaders. The getting of a uniform location does not need to be constrained to the model, view, and projection. An example would be sending in a time float value and have time influence vertex rendering locations. Look up "How to render a flag in OpenGL".

Clone this wiki locally