diff options
author | chai <chaifix@163.com> | 2018-05-18 14:39:38 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-05-18 14:39:38 +0800 |
commit | 1b773ad2c250e09c09c065eb3eec64bfebde09ca (patch) | |
tree | b3f1f367694d5f86cc0caa7f4eea2e6a1d3424c5 /src/libjin/render/jsl.h | |
parent | 91a592da979827b1735901388dba8712e6e3ecf3 (diff) |
修改userdata创建方式
Diffstat (limited to 'src/libjin/render/jsl.h')
-rw-r--r-- | src/libjin/render/jsl.h | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/libjin/render/jsl.h b/src/libjin/render/jsl.h index 80ef4dc..7183325 100644 --- a/src/libjin/render/jsl.h +++ b/src/libjin/render/jsl.h @@ -17,11 +17,22 @@ namespace render { public: - void init(const char* program); + JSLProgram(const char* program); + ~JSLProgram(); - void use(); - - static void unuse(); + inline void JSLProgram::use() + { + glUseProgram(pid); + JSLProgram::currentJSLProgram = this; + JSLProgram::currentTextureUnit = 0; + } + + static inline void JSLProgram::unuse() + { + glUseProgram(0); + JSLProgram::currentJSLProgram = nullptr; + JSLProgram::currentTextureUnit = 0; + } void sendFloat(const char* name, float number); void sendImage(const char* name, const Image* image); @@ -30,18 +41,27 @@ namespace render void sendVec4(const char* name, float x, float y, float z, float w); void sendCanvas(const char* name, const Canvas* canvas); void sendColor(const char* name, const color* col); - - private: - JSLProgram(); + static inline JSLProgram* getCurrentJSL() + { + return currentJSLProgram; + } + + private: GLuint pid; - - static JSLProgram* current_JSL_program; - static GLint current_texture_unit; - static GLint max_texture_units; - static GLint getTextureUnit(const std::string& name); + std::map<std::string, GLint> texturePool; + + static JSLProgram* currentJSLProgram; + static GLint currentTextureUnit; + static GLint maxTextureUnits; + + GLint getTextureUnit(const std::string& name); + + void initialize(const char* program); + void destroy(); + }; } |