OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
Shader Class Reference

#include <Shader.h>

Collaboration diagram for Shader:
[legend]

Public Member Functions

 Shader ()
 
 ~Shader ()
 
int compile (const char *vertex, const char *fragment)
 
void use ()
 
int addUniform (const char *name)
 
unsigned int getUniform (int n)
 
void loadUniform (int uni, glm::vec2 vec)
 
void loadUniform (int uni, glm::vec4 vec)
 
void loadUniform (int uni, glm::mat4 mat)
 
void loadUniform (int uni, int texture, TextureStorage store)
 

Static Public Member Functions

static int initialize ()
 
static void shutdown ()
 
static void set2DState (bool on, bool depth=true)
 
static void drawGL (ShaderBuffer &vertices, ShaderBuffer &uvs, glm::vec4 color, unsigned int texture, TextureStorage store=TextureStorage::SYSTEM, unsigned int mode=GL_TRIANGLES, ShaderTexture *target=nullptr, Shader &shader=textShader)
 
static void drawGL (ShaderBuffer &vertices, ShaderBuffer &uvs, unsigned int texture, glm::mat4 MVP, TextureStorage store=TextureStorage::GAME, ShaderTexture *target=nullptr, Shader &shader=textureShader)
 
static void drawGL (ShaderBuffer &vertices, ShaderBuffer &uvs, ShaderBuffer &indices, unsigned int texture, glm::mat4 MVP, TextureStorage store=TextureStorage::GAME, ShaderTexture *target=nullptr, Shader &shader=textureShader)
 
static void drawGL (ShaderBuffer &vertices, ShaderBuffer &colors, glm::mat4 MVP, unsigned int mode=GL_TRIANGLES, ShaderTexture *target=nullptr, Shader &shader=colorShader)
 
static void drawGL (ShaderBuffer &vertices, ShaderBuffer &colors, ShaderBuffer &indices, glm::mat4 MVP, unsigned int mode=GL_TRIANGLES, ShaderTexture *target=nullptr, Shader &shader=colorShader)
 

Private Attributes

int programID
 
std::vector< unsigned int > uniforms
 

Static Private Attributes

static Shader textShader
 
static const char * textShaderVertex
 
static const char * textShaderFragment
 
static Shader textureShader
 
static const char * textureShaderVertex
 
static const char * textureShaderFragment
 
static Shader colorShader
 
static const char * colorShaderVertex
 
static const char * colorShaderFragment
 
static unsigned int vertexArrayID = 0
 

Detailed Description

Definition at line 54 of file Shader.h.

Constructor & Destructor Documentation

Shader::Shader ( )
inline

Definition at line 56 of file Shader.h.

Shader::~Shader ( )

Definition at line 96 of file Shader.cpp.

Member Function Documentation

int Shader::compile ( const char *  vertex,
const char *  fragment 
)

Definition at line 139 of file Shader.cpp.

void Shader::use ( )

Definition at line 134 of file Shader.cpp.

int Shader::addUniform ( const char *  name)

Definition at line 101 of file Shader.cpp.

unsigned int Shader::getUniform ( int  n)

Definition at line 112 of file Shader.cpp.

void Shader::loadUniform ( int  uni,
glm::vec2  vec 
)

Definition at line 118 of file Shader.cpp.

void Shader::loadUniform ( int  uni,
glm::vec4  vec 
)

Definition at line 122 of file Shader.cpp.

void Shader::loadUniform ( int  uni,
glm::mat4  mat 
)

Definition at line 126 of file Shader.cpp.

void Shader::loadUniform ( int  uni,
int  texture,
TextureStorage  store 
)

Definition at line 130 of file Shader.cpp.

int Shader::initialize ( )
static

Definition at line 218 of file Shader.cpp.

void Shader::shutdown ( )
static

Definition at line 262 of file Shader.cpp.

void Shader::set2DState ( bool  on,
bool  depth = true 
)
static

Definition at line 266 of file Shader.cpp.

void Shader::drawGL ( ShaderBuffer vertices,
ShaderBuffer uvs,
glm::vec4  color,
unsigned int  texture,
TextureStorage  store = TextureStorage::SYSTEM,
unsigned int  mode = GL_TRIANGLES,
ShaderTexture target = nullptr,
Shader shader = textShader 
)
static

Definition at line 278 of file Shader.cpp.

void Shader::drawGL ( ShaderBuffer vertices,
ShaderBuffer uvs,
unsigned int  texture,
glm::mat4  MVP,
TextureStorage  store = TextureStorage::GAME,
ShaderTexture target = nullptr,
Shader shader = textureShader 
)
static

Definition at line 308 of file Shader.cpp.

void Shader::drawGL ( ShaderBuffer vertices,
ShaderBuffer uvs,
ShaderBuffer indices,
unsigned int  texture,
glm::mat4  MVP,
TextureStorage  store = TextureStorage::GAME,
ShaderTexture target = nullptr,
Shader shader = textureShader 
)
static

Definition at line 331 of file Shader.cpp.

void Shader::drawGL ( ShaderBuffer vertices,
ShaderBuffer colors,
glm::mat4  MVP,
unsigned int  mode = GL_TRIANGLES,
ShaderTexture target = nullptr,
Shader shader = colorShader 
)
static

Definition at line 370 of file Shader.cpp.

void Shader::drawGL ( ShaderBuffer vertices,
ShaderBuffer colors,
ShaderBuffer indices,
glm::mat4  MVP,
unsigned int  mode = GL_TRIANGLES,
ShaderTexture target = nullptr,
Shader shader = colorShader 
)
static

Definition at line 393 of file Shader.cpp.

Member Data Documentation

int Shader::programID
private

Definition at line 95 of file Shader.h.

std::vector<unsigned int> Shader::uniforms
private

Definition at line 96 of file Shader.h.

Shader Shader::textShader
staticprivate

Definition at line 98 of file Shader.h.

const char * Shader::textShaderVertex
staticprivate
Initial value:
= R"!?!(
#version 330 core
layout(location = 0) in vec2 vertexPosition_screen;
layout(location = 1) in vec2 vertexUV;
out vec2 UV;
uniform vec2 screen;
void main() {
vec2 halfScreen = screen / 2;
vec2 vertexPosition_homogenous = (vertexPosition_screen - halfScreen) / halfScreen;
gl_Position = vec4(vertexPosition_homogenous.x, -vertexPosition_homogenous.y, 0, 1);
UV = vertexUV;
}
)!?!"

Definition at line 99 of file Shader.h.

const char * Shader::textShaderFragment
staticprivate
Initial value:
= R"!?!(
#version 330 core
in vec2 UV;
layout(location = 0) out vec4 color;
uniform sampler2D textureSampler;
uniform vec4 colorVar;
void main() {
color = texture(textureSampler, UV) * colorVar;
}
)!?!"

Definition at line 100 of file Shader.h.

Shader Shader::textureShader
staticprivate

Definition at line 102 of file Shader.h.

const char * Shader::textureShaderVertex
staticprivate
Initial value:
= R"!?!(
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
out vec2 UV;
uniform mat4 MVP;
void main() {
vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
-vertexPosition_modelspace.y,
vertexPosition_modelspace.z,
1);
gl_Position = vec4(-pos.x, pos.yzw);
UV = vertexUV;
}
)!?!"

Definition at line 103 of file Shader.h.

const char * Shader::textureShaderFragment
staticprivate
Initial value:
= R"!?!(
#version 330 core
in vec2 UV;
layout(location = 0) out vec4 color;
uniform sampler2D textureSampler;
void main() {
color = texture(textureSampler, UV);
}
)!?!"

Definition at line 104 of file Shader.h.

Shader Shader::colorShader
staticprivate

Definition at line 106 of file Shader.h.

const char * Shader::colorShaderVertex
staticprivate
Initial value:
= R"!?!(
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexColor;
out vec3 color;
uniform mat4 MVP;
void main() {
vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
-vertexPosition_modelspace.y,
vertexPosition_modelspace.z,
1);
gl_Position = vec4(-pos.x, pos.yzw);
color = vertexColor;
}
)!?!"

Definition at line 107 of file Shader.h.

const char * Shader::colorShaderFragment
staticprivate
Initial value:
= R"!?!(
#version 330 core
in vec3 color;
layout(location = 0) out vec4 color_out;
void main() {
color_out = vec4(color, 1);
}
)!?!"

Definition at line 108 of file Shader.h.

unsigned int Shader::vertexArrayID = 0
staticprivate

Definition at line 110 of file Shader.h.


The documentation for this class was generated from the following files: