diff options
author | chai <chaifix@163.com> | 2018-12-22 11:25:55 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-12-22 11:25:55 +0800 |
commit | f319b9646941c8967db7e48079689483e13c00e4 (patch) | |
tree | 17c7868cc6be670a5b429da3e4353ccd41d5c609 /src | |
parent | 908ca5872294ad7c6de27bd63c1eed97be5ef37a (diff) |
*misc
Diffstat (limited to 'src')
-rw-r--r-- | src/3rdparty/LuaJIT-2.0.5/src/buildvm.lib | bin | 33996 -> 33996 bytes | |||
-rw-r--r-- | src/3rdparty/LuaJIT-2.0.5/src/minilua.lib | bin | 33996 -> 33996 bytes | |||
-rw-r--r-- | src/libjin/graphics/je_mesh.cpp | 14 | ||||
-rw-r--r-- | src/libjin/graphics/shaders/je_shader.cpp | 77 | ||||
-rw-r--r-- | src/libjin/graphics/shaders/je_shader.h | 30 |
5 files changed, 69 insertions, 52 deletions
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/buildvm.lib b/src/3rdparty/LuaJIT-2.0.5/src/buildvm.lib Binary files differindex c7be727..d4372fd 100644 --- a/src/3rdparty/LuaJIT-2.0.5/src/buildvm.lib +++ b/src/3rdparty/LuaJIT-2.0.5/src/buildvm.lib diff --git a/src/3rdparty/LuaJIT-2.0.5/src/minilua.lib b/src/3rdparty/LuaJIT-2.0.5/src/minilua.lib Binary files differindex e2b3ac3..a3cce18 100644 --- a/src/3rdparty/LuaJIT-2.0.5/src/minilua.lib +++ b/src/3rdparty/LuaJIT-2.0.5/src/minilua.lib diff --git a/src/libjin/graphics/je_mesh.cpp b/src/libjin/graphics/je_mesh.cpp index d220bcb..7a409b4 100644 --- a/src/libjin/graphics/je_mesh.cpp +++ b/src/libjin/graphics/je_mesh.cpp @@ -60,13 +60,13 @@ namespace JinEngine Math::Matrix modelViewMatrix = gl.getModelViewMatrix(x, y, sx, sy, r, ox, oy); Shader* shader = gl.getShader(); - shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()); - shader->beginUploadAttributes(); - shader->uploadVertices(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].xy)); - shader->uploadUV(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].uv)); - shader->uploadColor(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &(mVertices[0].color), GL_TRUE); - shader->endUploadAttributes(); + shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix) + .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix()) + .beginUploadAttributes() + .uploadVertices(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].xy)) + .uploadUV(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].uv)) + .uploadColor(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &(mVertices[0].color), GL_TRUE) + .endUploadAttributes(); gl.bindTexture(mGraphic->getGLTexture()); gl.drawArrays(GL_POLYGON, 0, mVertices.size()); diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp index 16627d5..0137978 100644 --- a/src/libjin/graphics/shaders/je_shader.cpp +++ b/src/libjin/graphics/shaders/je_shader.cpp @@ -85,16 +85,18 @@ namespace JinEngine { return false; } + #define glsl(SHADER_MODE, SHADER, SRC) \ - do{ \ - const GLchar* src = SRC.c_str(); \ - glShaderSource(SHADER, 1, &src, NULL); \ - glCompileShader(SHADER); \ - GLint success; \ - glGetShaderiv(SHADER, GL_COMPILE_STATUS, &success); \ - if (success == GL_FALSE) \ - return false; \ - }while(0) + do{ \ + const GLchar* src = SRC.c_str(); \ + glShaderSource(SHADER, 1, &src, NULL); \ + glCompileShader(SHADER); \ + GLint success; \ + glGetShaderiv(SHADER, GL_COMPILE_STATUS, &success); \ + if (success == GL_FALSE) \ + return false; \ + }while(0) + // Compile vertex shader. GLuint vid = glCreateShader(GL_VERTEX_SHADER); glsl(GL_VERTEX_SHADER, vid, vertex_shader); @@ -133,21 +135,23 @@ namespace JinEngine } #define checkJSL() \ - if (gl.getShader() != this) \ - return + if (gl.getShader() != this) \ + return *this - void Shader::sendInt(const char* name, int value) + Shader & Shader::sendInt(const char* name, int value) { checkJSL(); int loc = glGetUniformLocation(mPID, name); glUniform1i(loc, value); + return *this; } - void Shader::sendFloat(const char* variable, float number) + Shader& Shader::sendFloat(const char* variable, float number) { checkJSL(); int loc = glGetUniformLocation(mPID, variable); glUniform1f(loc, number); + return *this; } // @@ -164,65 +168,70 @@ namespace JinEngine // TextureUnit mTextureUnits[GL_MAX_TEXTURE_IMAGE_UNITS] // GLuint mCurrentTextureUnit = 0; // - void Shader::sendTexture(const char* variable, const Texture* tex) + Shader& Shader::sendTexture(const char* variable, const Texture* tex) { checkJSL(); GLint location = glGetUniformLocation(mPID, variable); if (location == -1) - return; + return *this; GLint unit = claimTextureUnit(variable); if (unit == 0) { // TODO: 쳣 - return; + return *this; } gl.activeTexUnit(unit); glUniform1i(location, unit); gl.bindTexture(tex->getGLTexture()); gl.activeTexUnit(0); + return *this; } - void Shader::sendCanvas(const char* variable, const Canvas* canvas) + Shader& Shader::sendCanvas(const char* variable, const Canvas* canvas) { checkJSL(); GLint location = glGetUniformLocation(mPID, variable); if (location == -1) - return; + return *this; GLint unit = claimTextureUnit(variable); if (unit == 0) { // TODO: 쳣 - return; + return *this; } glUniform1i(location, unit); glActiveTexture(GL_TEXTURE0 + unit); gl.bindTexture(canvas->getGLTexture()); glActiveTexture(GL_TEXTURE0); + return *this; } - void Shader::sendVec2(const char* name, float x, float y) + Shader& Shader::sendVec2(const char* name, float x, float y) { checkJSL(); int loc = glGetUniformLocation(mPID, name); glUniform2f(loc, x, y); + return *this; } - void Shader::sendVec3(const char* name, float x, float y, float z) + Shader& Shader::sendVec3(const char* name, float x, float y, float z) { checkJSL(); int loc = glGetUniformLocation(mPID, name); glUniform3f(loc, x, y, z); + return *this; } - void Shader::sendVec4(const char* name, float x, float y, float z, float w) + Shader& Shader::sendVec4(const char* name, float x, float y, float z, float w) { checkJSL(); int loc = glGetUniformLocation(mPID, name); glUniform4f(loc, x, y, z, w); + return *this; } - void Shader::sendColor(const char* name, const Color* col) + Shader& Shader::sendColor(const char* name, const Color* col) { checkJSL(); int loc = glGetUniformLocation(mPID, name); @@ -232,44 +241,52 @@ namespace JinEngine col->b / 255.f, col->a / 255.f ); + return *this; } - void Shader::sendMatrix4(const char* name, const Math::Matrix* mat4) + Shader& Shader::sendMatrix4(const char* name, const Math::Matrix* mat4) { int loc = glGetUniformLocation(mPID, name); glUniformMatrix4fv(loc, 1, GL_FALSE, mat4->getElements()); + return *this; } - void Shader::uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) + Shader& Shader::uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) { uploadAttribute(SHADER_VERTEX_COORDS, n, type, stride, pointers, normalized); + return *this; } - void Shader::uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) + Shader& Shader::uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) { uploadAttribute(SHADER_TEXTURE_COORDS, n, type, stride, pointers, normalized); + return *this; } - void Shader::uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) + Shader& Shader::uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) { uploadAttribute(SHADER_VERTEX_COLOR, n, type, stride, pointers, normalized); + return *this; } - void Shader::beginUploadAttributes() + Shader& Shader::beginUploadAttributes() { mAttributeIndex = 0; + return *this; } - void Shader::endUploadAttributes() + Shader& Shader::endUploadAttributes() { mAttributeIndex = 0; + return *this; } - void Shader::uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) + Shader& Shader::uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized) { GLint loc = glGetAttribLocation(mPID, name); glEnableVertexAttribArray(mAttributeIndex++); glVertexAttribPointer(loc, n, type, normalized, stride, pointers); + return *this; } } // namespace Shaders diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h index 6a2db9c..92e1c4c 100644 --- a/src/libjin/graphics/shaders/je_shader.h +++ b/src/libjin/graphics/shaders/je_shader.h @@ -52,7 +52,7 @@ namespace JinEngine /// @param name Name of the uniform variable to be assigned. /// @param number Value of uniform variable to be sent. /// - void sendFloat(const char* name, float number); + Shader& sendFloat(const char* name, float number); /// /// Send texture to shader. @@ -60,7 +60,7 @@ namespace JinEngine /// @param name Name of the uniform variable to be assigned. /// @param texture Texture to be sent. /// - void sendTexture(const char* name, const Texture* texture); + Shader& sendTexture(const char* name, const Texture* texture); /// /// Send integer value to shader @@ -68,7 +68,7 @@ namespace JinEngine /// @param name Name of the uniform variable to be assigned. /// @param value Value to be sent. /// - void sendInt(const char* name, int value); + Shader& sendInt(const char* name, int value); /// /// Send 2D vector to shader. @@ -77,7 +77,7 @@ namespace JinEngine /// @param x X value of the vector to be sent. /// @param y Y value of the vector to be sent. /// - void sendVec2(const char* name, float x, float y); + Shader& sendVec2(const char* name, float x, float y); /// /// Send 3D vector to shader. @@ -87,7 +87,7 @@ namespace JinEngine /// @param y Y value of the vector to be sent. /// @param z Z value of the vector to be sent. /// - void sendVec3(const char* name, float x, float y, float z); + Shader& sendVec3(const char* name, float x, float y, float z); /// /// Send 4D vector to shader. @@ -98,7 +98,7 @@ namespace JinEngine /// @param z Z value of the vector to be sent. /// @param w W value of the vector to be sent. /// - void sendVec4(const char* name, float x, float y, float z, float w); + Shader& sendVec4(const char* name, float x, float y, float z, float w); /// /// Send canvas to shader. @@ -106,7 +106,7 @@ namespace JinEngine /// @param name Name of the uniform variable to be assigned. /// @param canvas Canvas to be sent. /// - void sendCanvas(const char* name, const Canvas* canvas); + Shader& sendCanvas(const char* name, const Canvas* canvas); /// /// Send color to shader. @@ -114,7 +114,7 @@ namespace JinEngine /// @param name Name of the uniform variable to be assigned. /// @param color Color to be sent. /// - void sendColor(const char* name, const Color* color); + Shader& sendColor(const char* name, const Color* color); /// /// Send 4 by 4 matrix to shader. @@ -122,7 +122,7 @@ namespace JinEngine /// @param name Name of the uniform variable to be assigned. /// @param mat4 Matrix to be sent. /// - void sendMatrix4(const char* name, const Math::Matrix* mat4); + Shader& sendMatrix4(const char* name, const Math::Matrix* mat4); /// /// Set vertices value. @@ -132,7 +132,7 @@ namespace JinEngine /// @param stride Byte offset between consecutive generic vertex attributes. /// @param pointers Pointer to the first component of the first generic vertex attribute in the array. /// - void uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); + Shader& uploadVertices(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); /// /// Set texture UV coordinates. @@ -142,27 +142,27 @@ namespace JinEngine /// @param stride Byte offset between consecutive generic vertex attributes. /// @param pointers Pointer to the first component of the first generic vertex attribute in the array. /// - void uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); + Shader& uploadUV(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); /// /// Upload vertex color array. /// - void uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); + Shader& uploadColor(int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); /// /// Set attribute. /// - void uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); + Shader& uploadAttribute(const String& name, int n, GLenum type, GLsizei stride, const GLvoid * pointers, GLboolean normalized = GL_FALSE); /// /// Reset attribute index. /// - void beginUploadAttributes(); + Shader& beginUploadAttributes(); /// /// Reset attribute index. /// - void endUploadAttributes(); + Shader& endUploadAttributes(); /// /// Program ID. |