aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/shaders/je_shader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/shaders/je_shader.cpp')
-rw-r--r--src/libjin/graphics/shaders/je_shader.cpp77
1 files changed, 47 insertions, 30 deletions
diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp
index 16627d5..0137978 100644
--- a/src/libjin/graphics/shaders/je_shader.cpp
+++ b/src/libjin/graphics/shaders/je_shader.cpp
@@ -85,16 +85,18 @@ namespace JinEngine
{
return false;
}
+
#define glsl(SHADER_MODE, SHADER, SRC) \
- do{ \
- const GLchar* src = SRC.c_str(); \
- glShaderSource(SHADER, 1, &src, NULL); \
- glCompileShader(SHADER); \
- GLint success; \
- glGetShaderiv(SHADER, GL_COMPILE_STATUS, &success); \
- if (success == GL_FALSE) \
- return false; \
- }while(0)
+ do{ \
+ const GLchar* src = SRC.c_str(); \
+ glShaderSource(SHADER, 1, &src, NULL); \
+ glCompileShader(SHADER); \
+ GLint success; \
+ glGetShaderiv(SHADER, GL_COMPILE_STATUS, &success); \
+ if (success == GL_FALSE) \
+ return false; \
+ }while(0)
+
// Compile vertex shader.
GLuint vid = glCreateShader(GL_VERTEX_SHADER);
glsl(GL_VERTEX_SHADER, vid, vertex_shader);
@@ -133,21 +135,23 @@ namespace JinEngine
}
#define checkJSL() \
- if (gl.getShader() != this) \
- return
+ if (gl.getShader() != this) \
+ return *this
- void Shader::sendInt(const char* name, int value)
+ Shader & Shader::sendInt(const char* name, int value)
{
checkJSL();
int loc = glGetUniformLocation(mPID, name);
glUniform1i(loc, value);
+ return *this;
}
- void Shader::sendFloat(const char* variable, float number)
+ Shader& Shader::sendFloat(const char* variable, float number)
{
checkJSL();
int loc = glGetUniformLocation(mPID, variable);
glUniform1f(loc, number);
+ return *this;
}
//
@@ -164,65 +168,70 @@ namespace JinEngine
// TextureUnit mTextureUnits[GL_MAX_TEXTURE_IMAGE_UNITS]
// GLuint mCurrentTextureUnit = 0;
//
- void Shader::sendTexture(const char* variable, const Texture* tex)
+ Shader& Shader::sendTexture(const char* variable, const Texture* tex)
{
checkJSL();
GLint location = glGetUniformLocation(mPID, variable);
if (location == -1)
- return;
+ return *this;
GLint unit = claimTextureUnit(variable);
if (unit == 0)
{
// TODO: 쳣󶨵
- return;
+ return *this;
}
gl.activeTexUnit(unit);
glUniform1i(location, unit);
gl.bindTexture(tex->getGLTexture());
gl.activeTexUnit(0);
+ return *this;
}
- void Shader::sendCanvas(const char* variable, const Canvas* canvas)
+ Shader& Shader::sendCanvas(const char* variable, const Canvas* canvas)
{
checkJSL();
GLint location = glGetUniformLocation(mPID, variable);
if (location == -1)
- return;
+ return *this;
GLint unit = claimTextureUnit(variable);
if (unit == 0)
{
// TODO: 쳣󶨵
- return;
+ return *this;
}
glUniform1i(location, unit);
glActiveTexture(GL_TEXTURE0 + unit);
gl.bindTexture(canvas->getGLTexture());
glActiveTexture(GL_TEXTURE0);
+ return *this;
}
- void Shader::sendVec2(const char* name, float x, float y)
+ Shader& Shader::sendVec2(const char* name, float x, float y)
{
checkJSL();
int loc = glGetUniformLocation(mPID, name);
glUniform2f(loc, x, y);
+ return *this;
}
- void Shader::sendVec3(const char* name, float x, float y, float z)
+ Shader& Shader::sendVec3(const char* name, float x, float y, float z)
{
checkJSL();
int loc = glGetUniformLocation(mPID, name);
glUniform3f(loc, x, y, z);
+ return *this;
}
- void Shader::sendVec4(const char* name, float x, float y, float z, float w)
+ Shader& Shader::sendVec4(const char* name, float x, float y, float z, float w)
{
checkJSL();
int loc = glGetUniformLocation(mPID, name);
glUniform4f(loc, x, y, z, w);
+ return *this;
}
- void Shader::sendColor(const char* name, const Color* col)
+ Shader& Shader::sendColor(const char* name, const Color* col)
{
checkJSL();
int loc = glGetUniformLocation(mPID, name);
@@ -232,44 +241,52 @@ namespace JinEngine
col->b / 255.f,
col->a / 255.f
);
+ return *this;
}
- void Shader::sendMatrix4(const char* name, const Math::Matrix* mat4)
+ Shader& Shader::sendMatrix4(const char* name, const Math::Matrix* mat4)
{
int loc = glGetUniformLocation(mPID, name);
glUniformMatrix4fv(loc, 1, GL_FALSE, mat4->getElements());
+ return *this;
}
- void Shader::uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized)
+ Shader& Shader::uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized)
{
uploadAttribute(SHADER_VERTEX_COORDS, n, type, stride, pointers, normalized);
+ return *this;
}
- void Shader::uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized)
+ Shader& Shader::uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized)
{
uploadAttribute(SHADER_TEXTURE_COORDS, n, type, stride, pointers, normalized);
+ return *this;
}
- void Shader::uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized)
+ Shader& Shader::uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized)
{
uploadAttribute(SHADER_VERTEX_COLOR, n, type, stride, pointers, normalized);
+ return *this;
}
- void Shader::beginUploadAttributes()
+ Shader& Shader::beginUploadAttributes()
{
mAttributeIndex = 0;
+ return *this;
}
- void Shader::endUploadAttributes()
+ Shader& Shader::endUploadAttributes()
{
mAttributeIndex = 0;
+ return *this;
}
- void Shader::uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized)
+ Shader& Shader::uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized)
{
GLint loc = glGetAttribLocation(mPID, name);
glEnableVertexAttribArray(mAttributeIndex++);
glVertexAttribPointer(loc, n, type, normalized, stride, pointers);
+ return *this;
}
} // namespace Shaders