aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/shaders')
-rw-r--r--src/libjin/graphics/shaders/je_shader.cpp77
-rw-r--r--src/libjin/graphics/shaders/je_shader.h30
2 files changed, 62 insertions, 45 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
diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h
index 6a2db9c..92e1c4c 100644
--- a/src/libjin/graphics/shaders/je_shader.h
+++ b/src/libjin/graphics/shaders/je_shader.h
@@ -52,7 +52,7 @@ namespace JinEngine
/// @param name Name of the uniform variable to be assigned.
/// @param number Value of uniform variable to be sent.
///
- void sendFloat(const char* name, float number);
+ Shader& sendFloat(const char* name, float number);
///
/// Send texture to shader.
@@ -60,7 +60,7 @@ namespace JinEngine
/// @param name Name of the uniform variable to be assigned.
/// @param texture Texture to be sent.
///
- void sendTexture(const char* name, const Texture* texture);
+ Shader& sendTexture(const char* name, const Texture* texture);
///
/// Send integer value to shader
@@ -68,7 +68,7 @@ namespace JinEngine
/// @param name Name of the uniform variable to be assigned.
/// @param value Value to be sent.
///
- void sendInt(const char* name, int value);
+ Shader& sendInt(const char* name, int value);
///
/// Send 2D vector to shader.
@@ -77,7 +77,7 @@ namespace JinEngine
/// @param x X value of the vector to be sent.
/// @param y Y value of the vector to be sent.
///
- void sendVec2(const char* name, float x, float y);
+ Shader& sendVec2(const char* name, float x, float y);
///
/// Send 3D vector to shader.
@@ -87,7 +87,7 @@ namespace JinEngine
/// @param y Y value of the vector to be sent.
/// @param z Z value of the vector to be sent.
///
- void sendVec3(const char* name, float x, float y, float z);
+ Shader& sendVec3(const char* name, float x, float y, float z);
///
/// Send 4D vector to shader.
@@ -98,7 +98,7 @@ namespace JinEngine
/// @param z Z value of the vector to be sent.
/// @param w W value of the vector to be sent.
///
- void sendVec4(const char* name, float x, float y, float z, float w);
+ Shader& sendVec4(const char* name, float x, float y, float z, float w);
///
/// Send canvas to shader.
@@ -106,7 +106,7 @@ namespace JinEngine
/// @param name Name of the uniform variable to be assigned.
/// @param canvas Canvas to be sent.
///
- void sendCanvas(const char* name, const Canvas* canvas);
+ Shader& sendCanvas(const char* name, const Canvas* canvas);
///
/// Send color to shader.
@@ -114,7 +114,7 @@ namespace JinEngine
/// @param name Name of the uniform variable to be assigned.
/// @param color Color to be sent.
///
- void sendColor(const char* name, const Color* color);
+ Shader& sendColor(const char* name, const Color* color);
///
/// Send 4 by 4 matrix to shader.
@@ -122,7 +122,7 @@ namespace JinEngine
/// @param name Name of the uniform variable to be assigned.
/// @param mat4 Matrix to be sent.
///
- void sendMatrix4(const char* name, const Math::Matrix* mat4);
+ Shader& sendMatrix4(const char* name, const Math::Matrix* mat4);
///
/// Set vertices value.
@@ -132,7 +132,7 @@ namespace JinEngine
/// @param stride Byte offset between consecutive generic vertex attributes.
/// @param pointers Pointer to the first component of the first generic vertex attribute in the array.
///
- void uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE);
+ Shader& uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE);
///
/// Set texture UV coordinates.
@@ -142,27 +142,27 @@ namespace JinEngine
/// @param stride Byte offset between consecutive generic vertex attributes.
/// @param pointers Pointer to the first component of the first generic vertex attribute in the array.
///
- void uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE);
+ Shader& uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE);
///
/// Upload vertex color array.
///
- void uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE);
+ Shader& uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE);
///
/// Set attribute.
///
- void uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE);
+ Shader& uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE);
///
/// Reset attribute index.
///
- void beginUploadAttributes();
+ Shader& beginUploadAttributes();
///
/// Reset attribute index.
///
- void endUploadAttributes();
+ Shader& endUploadAttributes();
///
/// Program ID.