diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libjin/Graphics/Graphics.h | 2 | ||||
-rw-r--r-- | src/libjin/Graphics/JSL.cpp | 142 | ||||
-rw-r--r-- | src/libjin/Graphics/JSL.h | 59 | ||||
-rw-r--r-- | src/libjin/Graphics/Texture.cpp | 1 | ||||
-rw-r--r-- | src/lua/modules/embed/boot.lua.h | 1 |
5 files changed, 2 insertions, 203 deletions
diff --git a/src/libjin/Graphics/Graphics.h b/src/libjin/Graphics/Graphics.h index 210dadf..bca3812 100644 --- a/src/libjin/Graphics/Graphics.h +++ b/src/libjin/Graphics/Graphics.h @@ -8,7 +8,7 @@ #include "font.h" #include "Shapes.h" #include "texture.h" -#include "jsl.h" +#include "Shader.h" #include "window.h" #endif // JIN_MODULES_RENDER diff --git a/src/libjin/Graphics/JSL.cpp b/src/libjin/Graphics/JSL.cpp deleted file mode 100644 index 1eb1357..0000000 --- a/src/libjin/Graphics/JSL.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include "../modules.h" -#if JIN_MODULES_RENDER - -#include "../utils/macros.h" -#include "jsl.h" -namespace jin -{ -namespace graphics -{ - - static const char* base_f = R"base_f( -#define number float -#define Texture sampler2D -#define Canvas sampler2D -#define Color vec4 -#define Texel texture2D -#define extern uniform -uniform Texture _tex0_; -%s -void main() -{ - gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy); -} - )base_f"; - - /*static*/ JSLProgram* JSLProgram::currentJSLProgram = nullptr; - - JSLProgram* JSLProgram::createJSLProgram(const char* program) - { - return new JSLProgram(program); - } - - JSLProgram::JSLProgram(const char* program) - : currentTextureUnit(0) - { - 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); - } - - JSLProgram::~JSLProgram() - { - if (currentJSLProgram == this) - unuse(); - } - - static inline GLint getMaxTextureUnits() - { - GLint maxTextureUnits = 0; - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); - return maxTextureUnits; - } - - GLint JSLProgram::getTextureUnit(const std::string& name) - { - std::map<std::string, GLint>::iterator texture_unit = texturePool.find(name); - if (texture_unit != texturePool.end()) - return texture_unit->second; - static GLint maxTextureUnits = getMaxTextureUnits(); - if (++currentTextureUnit >= maxTextureUnits) - return 0; - texturePool[name] = currentTextureUnit; - return currentTextureUnit; - } - -#define checkJSL() if (currentJSLProgram != this) return - - void JSLProgram::sendFloat(const char* variable, float number) - { - checkJSL(); - int loc = glGetUniformLocation(pid, variable); - glUniform1f(loc, number); - } - - void JSLProgram::sendTexture(const char* variable, const Texture* tex) - { - checkJSL(); - GLint location = glGetUniformLocation(pid, variable); - if (location == -1) - return; - GLint texture_unit = getTextureUnit(variable); - glUniform1i(location, texture_unit); - glActiveTexture(GL_TEXTURE0 + texture_unit); - glBindTexture(GL_TEXTURE_2D, tex->getTexture()); - glActiveTexture(GL_TEXTURE0); - } - - void JSLProgram::sendCanvas(const char* variable, const Canvas* canvas) - { - checkJSL(); - GLint location = glGetUniformLocation(pid, variable); - if (location == -1) - return; - GLint texture_unit = getTextureUnit(variable); - glUniform1i(location, texture_unit); - glActiveTexture(GL_TEXTURE0 + texture_unit); - glBindTexture(GL_TEXTURE_2D, canvas->getTexture()); - glActiveTexture(GL_TEXTURE0); - } - - void JSLProgram::sendVec2(const char* name, float x, float y) - { - checkJSL(); - int loc = glGetUniformLocation(pid, name); - glUniform2f(loc, x, y); - } - - void JSLProgram::sendVec3(const char* name, float x, float y, float z) - { - checkJSL(); - int loc = glGetUniformLocation(pid, name); - glUniform3f(loc, x, y, z); - } - - void JSLProgram::sendVec4(const char* name, float x, float y, float z, float w) - { - checkJSL(); - int loc = glGetUniformLocation(pid, name); - glUniform4f(loc, x, y, z, w); - } - - void JSLProgram::sendColor(const char* name, const color* col) - { - checkJSL(); - int loc = glGetUniformLocation(pid, name); - glUniform4f(loc, - col->rgba.r / 255.f, - col->rgba.g / 255.f, - col->rgba.b / 255.f, - col->rgba.a / 255.f - ); - } - -} // graphics -} // jin - -#endif // JIN_MODULES_RENDER
\ No newline at end of file diff --git a/src/libjin/Graphics/JSL.h b/src/libjin/Graphics/JSL.h deleted file mode 100644 index a99a4c7..0000000 --- a/src/libjin/Graphics/JSL.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __JIN_JSL_H -#define __JIN_JSL_H -#include "../modules.h" -#if JIN_MODULES_RENDER - -#include <string> -#include <map> -#include "color.h" -#include "texture.h" -#include "canvas.h" -#include "../3rdparty/GLee/GLee.h" - -namespace jin -{ -namespace graphics -{ - - class JSLProgram - { - public: - static JSLProgram* createJSLProgram(const char* program); - static inline JSLProgram* getCurrentJSL() { return currentJSLProgram; } - virtual ~JSLProgram(); - - inline void use() - { - glUseProgram(pid); - currentJSLProgram = this; - } - static inline void unuse() - { - glUseProgram(0); - currentJSLProgram = nullptr; - } - - void sendFloat(const char* name, float number); - void sendTexture(const char* name, const Texture* image); - void sendVec2(const char* name, float x, float y); - void sendVec3(const char* name, float x, float y, float z); - 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); - - protected: - static JSLProgram* currentJSLProgram; - JSLProgram(const char* program); - - GLuint pid; - std::map<std::string, GLint> texturePool; - GLint currentTextureUnit; - GLint getTextureUnit(const std::string& name); - - }; - -} // graphics -} // jin - -#endif // JIN_MODULES_RENDER -#endif // __JIN_JSL_H
\ No newline at end of file diff --git a/src/libjin/Graphics/Texture.cpp b/src/libjin/Graphics/Texture.cpp index 633eeac..708042e 100644 --- a/src/libjin/Graphics/Texture.cpp +++ b/src/libjin/Graphics/Texture.cpp @@ -68,7 +68,6 @@ namespace graphics bool Texture::loadb(const void* b, size_t s) { - // ʹstbi_load_from_memory int w; int h; pixels = (color*)stbi_load_from_memory((unsigned char *)b, s, &w, &h, NULL, STBI_rgb_alpha); diff --git a/src/lua/modules/embed/boot.lua.h b/src/lua/modules/embed/boot.lua.h index 1638cbd..8ff89ee 100644 --- a/src/lua/modules/embed/boot.lua.h +++ b/src/lua/modules/embed/boot.lua.h @@ -26,6 +26,7 @@ jin.config.fps = jin.config.fps or 60 jin.graphics.init(jin.config) jin.audio.init() +-- TODO: ϵͳģ ------------------------------------------------------------------------- -- Default game loop |