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.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp
index 0eb3631..0803e65 100644
--- a/src/libjin/graphics/shaders/je_shader.cpp
+++ b/src/libjin/graphics/shaders/je_shader.cpp
@@ -5,6 +5,7 @@
#include "../../time/je_timer.h"
#include "../../filesystem/je_buffer.h"
+#include "../../utils/je_log.h"
#include "../../utils/je_macros.h"
#include "../je_gl.h"
@@ -57,7 +58,8 @@ namespace JinEngine
//
const int DEFAULT_TEXTURE_UNIT = 0;
- GLint Shader::mTextureUnit = DEFAULT_TEXTURE_UNIT;
+ static GLint textureUnit = 0;
+
GLint Shader::mAttributeIndex = 0;
Shader::Shader(const string& program)
@@ -65,7 +67,8 @@ namespace JinEngine
{
if (!compile(program))
{
- throw 0;
+ jin_log_error("Compile jsl shader failed.");
+ throw Exception("Compile jsl shader failed");
}
}
@@ -77,8 +80,11 @@ namespace JinEngine
glDeleteShader(mPID);
}
- Shader& Shader::prepare()
+ Shader& Shader::begin()
{
+
+ textureUnit = DEFAULT_TEXTURE_UNIT;
+
// Send uniforms.
sendInt(SHADER_MAIN_TEXTURE, DEFAULT_TEXTURE_UNIT);
sendVec2(SHADER_TIME, Time::getSecond(), Time::getDeltaTime());
@@ -91,15 +97,17 @@ namespace JinEngine
{
sendVec2(SHADER_RENDERTARGET_SIZE, rt->getWidth(), rt->getHeight());
}
- // Reset attribute index.
- for(; mAttributeIndex > 0; --mAttributeIndex)
- glDisableVertexAttribArray(mAttributeIndex);
-
- mTextureUnit = DEFAULT_TEXTURE_UNIT;
return *this;
}
+ void Shader::end()
+ {
+ // Reset attribute index.
+ for (; mAttributeIndex > 0; --mAttributeIndex)
+ glDisableVertexAttribArray(mAttributeIndex);
+ }
+
bool Shader::compile(const string& program)
{
string vertex_shader, fragment_shader;
@@ -157,7 +165,7 @@ namespace JinEngine
// return 0;
//mTextureUnits[name] = mCurrentTextureUnit;
//return mCurrentTextureUnit;
- return mTextureUnit++;
+ return textureUnit++;
}
GLint Shader::getUniformLocation(const char* uniform)