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.cpp54
1 files changed, 30 insertions, 24 deletions
diff --git a/src/libjin/render/jsl.cpp b/src/libjin/render/jsl.cpp
index 56cbc31..49bb18f 100644
--- a/src/libjin/render/jsl.cpp
+++ b/src/libjin/render/jsl.cpp
@@ -18,15 +18,31 @@ namespace render
"gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy);\n"
"}\0";
- shared GLint JSLProgram::current_texture_unit = 0;
- shared GLint JSLProgram::max_texture_units = 0;
+ shared GLint JSLProgram::currentTextureUnit = 0;
+ shared GLint JSLProgram::maxTextureUnits = -1;
- shared JSLProgram* JSLProgram::current_JSL_program = nullptr;
+ shared JSLProgram* JSLProgram::currentJSLProgram = nullptr;
- void JSLProgram::init(const char* program)
+ JSLProgram::JSLProgram(const char* program)
{
- if(max_texture_units == 0)
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units);
+ initialize(program);
+ }
+
+ JSLProgram::~JSLProgram()
+ {
+ destroy();
+ }
+
+ void JSLProgram::destroy()
+ {
+ if (currentJSLProgram == this)
+ unuse();
+ }
+
+ void JSLProgram::initialize(const char* program)
+ {
+ if (maxTextureUnits == -1)
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
char* fs = (char*)alloca(strlen(program) + strlen(base_f));
sprintf(fs, base_f, program);
@@ -39,28 +55,18 @@ namespace render
glLinkProgram(pid);
}
- shared GLint JSLProgram::getTextureUnit(const std::string& name)
+ GLint JSLProgram::getTextureUnit(const std::string& name)
{
- if (++current_texture_unit >= max_texture_units)
+ std::map<std::string, GLint>::iterator texture_unit = texturePool.find(name);
+ if (texture_unit != texturePool.end())
+ return texture_unit->second;
+ if (++currentTextureUnit >= maxTextureUnits)
return 0;
- return current_texture_unit;
- }
-
- void JSLProgram::use()
- {
- glUseProgram(pid);
- JSLProgram::current_JSL_program = this;
- JSLProgram::current_texture_unit = 0;
- }
-
- shared void JSLProgram::unuse()
- {
- glUseProgram(0);
- JSLProgram::current_JSL_program = nullptr;
- JSLProgram::current_texture_unit = 0;
+ texturePool[name] = currentTextureUnit;
+ return currentTextureUnit;
}
-#define checkJSL() if (current_JSL_program != this) return
+#define checkJSL() if (currentJSLProgram != this) return
void JSLProgram::sendFloat(const char* variable, float number)
{