aboutsummaryrefslogtreecommitdiff
path: root/src/render/jsl.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-05-17 19:10:57 +0800
committerchai <chaifix@163.com>2018-05-17 19:10:57 +0800
commit70cdd89e887641b7423e5d4d05928d14ee014aba (patch)
tree248b87ae35197a9e5941e65ef20eea359e87a5ed /src/render/jsl.cpp
parentdf4b054b8e8d00f7817daaa4cbf6961712cd0b75 (diff)
change file tree
Diffstat (limited to 'src/render/jsl.cpp')
-rw-r--r--src/render/jsl.cpp84
1 files changed, 0 insertions, 84 deletions
diff --git a/src/render/jsl.cpp b/src/render/jsl.cpp
deleted file mode 100644
index 6fcee53..0000000
--- a/src/render/jsl.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-#include "utils/macros.h"
-#include "jsl.h"
-namespace jin
-{
-namespace render
-{
- //vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
- static const char* base_f = " "
- "#version 120 \n"
- "#define number float \n"
- "#define Image sampler2D \n"
- "#define Texel texture2D \n"
- "#define extern uniform \n"
- "uniform sampler2D _tex0_; \n"
- "%s \n"
- "void main(){ \n"
- "gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy);\n"
- "}\0";
-
- void JSLProgram::init(const char* program)
- {
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &_max_texture_units);
-
- char* fs = (char*)alloca(strlen(program) + strlen(base_f));
- sprintf(fs, base_f, program);
- GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fragmentShader, 1, (const GLchar**)&fs, NULL);
- glCompileShader(fragmentShader);
-
- pid = glCreateProgram();
- glAttachShader(pid, fragmentShader);
- 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;
- }
-
- void JSLProgram::use()
- {
- glUseProgram(pid);
- }
-
- shared void JSLProgram::unuse()
- {
- glUseProgram(0);
- }
-
- void JSLProgram::sendFloat(const char* variable, float number)
- {
- int loc = glGetUniformLocation(pid, variable);
- glUniform1f(loc, number);
- }
-
- void JSLProgram::sendImage(const char* variable, const Image* image)
- {
- GLint texture_unit = getTextureUnit(variable);
-
- GLint location = glGetUniformLocation(pid, variable);
-
- 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);
- }
-
-}
-}