aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/render/jsl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/render/jsl.cpp')
-rw-r--r--src/libjin/render/jsl.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/libjin/render/jsl.cpp b/src/libjin/render/jsl.cpp
index 1fb4482..1935edc 100644
--- a/src/libjin/render/jsl.cpp
+++ b/src/libjin/render/jsl.cpp
@@ -11,12 +11,15 @@ namespace render
"#define Image sampler2D \n"
"#define Texel texture2D \n"
"#define extern uniform \n"
- "uniform sampler2D _tex0_; \n"
+ "uniform Image _tex0_; \n"
"%s \n"
"void main(){ \n"
"gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy);\n"
"}\0";
+ shared GLint JSLProgram::_current_texture_unit;
+ shared GLint JSLProgram::_max_texture_units;
+
void JSLProgram::init(const char* program)
{
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &_max_texture_units);
@@ -32,27 +35,17 @@ namespace render
glLinkProgram(pid);
}
- shared std::map<std::string, GLint> JSLProgram::_texture_unit_pool;
- shared GLint JSLProgram::_current_texture_unit = 0;
- shared GLint JSLProgram::_max_texture_units = 0;
-
shared GLint JSLProgram::getTextureUnit(const std::string& name)
{
- std::map<std::string, GLint>::const_iterator it = _texture_unit_pool.find(name);
-
- if (it != _texture_unit_pool.end())
- return it->second;
-
- if (++_current_texture_unit >= _max_texture_units)
- return 0;
-
- _texture_unit_pool[name] = _current_texture_unit;
- return _current_texture_unit;
+ if (++_current_texture_unit >= _max_texture_units)
+ return 0;
+ return _current_texture_unit;
}
void JSLProgram::use()
{
glUseProgram(pid);
+ _current_texture_unit = 0;
}
shared void JSLProgram::unuse()
@@ -71,10 +64,10 @@ namespace render
GLint texture_unit = getTextureUnit(variable);
GLint location = glGetUniformLocation(pid, variable);
+ glUniform1i(location, texture_unit);
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindTexture(GL_TEXTURE_2D, image->getTexture()); // guarantee it gets bound
- glUniform1i(location, texture_unit);
// reset texture unit
glActiveTexture(GL_TEXTURE0);