diff options
Diffstat (limited to 'src/libjin/Graphics/Shader/Shader.cpp')
-rw-r--r-- | src/libjin/Graphics/Shader/Shader.cpp | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/src/libjin/Graphics/Shader/Shader.cpp b/src/libjin/Graphics/Shader/Shader.cpp index 877ef5b..a075d7d 100644 --- a/src/libjin/Graphics/Shader/Shader.cpp +++ b/src/libjin/Graphics/Shader/Shader.cpp @@ -1,6 +1,6 @@ #include <regex> #include "../../configuration.h" -#if LIBJIN_MODULES_RENDER +#if defined(jin_graphics_shader) #include <iostream> @@ -15,37 +15,37 @@ namespace jin using namespace jin::filesystem; using namespace std; - /** - * default_texture - * base_shader - * SHADER_FORMAT_SIZE - * formatShader - */ + // + // default_texture + // base_shader + // SHADER_FORMAT_SIZE + // formatShader + // #include "default.shader.h" - /** - * https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value - * The default value of a sampler variable is 0. From the GLSL 3.30 spec, - * section "4.3.5 Uniforms": - * - * The link time initial value is either the value of the variable's - * initializer, if present, or 0 if no initializer is present.Sampler - * types cannot have initializers. - * - * Since a value of 0 means that it's sampling from texture unit 0, it will - * work without ever setting the value as long as you bind your textures to - * unit 0. This is well defined behavior. - * - * Since texture unit 0 is also the default until you call glActiveTexture() - * with a value other than GL_TEXTURE0, it's very common to always use unit - * 0 as long as shaders do not need more than one texture.Which means that - * often times, setting the sampler uniforms is redundant for simple - * applications. - * - * I would still prefer to always set the values.If nothing else, it makes - * it clear to anybody reading your code that you really mean to sample from - * texture unit 0, and did not just forget to set the value. - */ + // + // https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value + // The default value of a sampler variable is 0. From the GLSL 3.30 spec, + // section "4.3.5 Uniforms": + // + // The link time initial value is either the value of the variable's + // initializer, if present, or 0 if no initializer is present.Sampler + // types cannot have initializers. + // + // Since a value of 0 means that it's sampling from texture unit 0, it will + // work without ever setting the value as long as you bind your textures to + // unit 0. This is well defined behavior. + // + // Since texture unit 0 is also the default until you call glActiveTexture() + // with a value other than GL_TEXTURE0, it's very common to always use unit + // 0 as long as shaders do not need more than one texture.Which means that + // often times, setting the sampler uniforms is redundant for simple + // applications. + // + // I would still prefer to always set the values.If nothing else, it makes + // it clear to anybody reading your code that you really mean to sample from + // texture unit 0, and did not just forget to set the value. + // const int DEFAULT_TEXTURE_UNIT = 0; /*static*/ Shader* Shader::CurrentShader = nullptr; @@ -79,7 +79,7 @@ namespace jin bool Shader::compile(const string& program) { - /* parse shader source, need some optimizations */ + // parse shader source, need some optimizations int loc_VERTEX_SHADER = program.find("#VERTEX_SHADER"); int loc_END_VERTEX_SHADER = program.find("#END_VERTEX_SHADER"); int loc_FRAGMENT_SHADER = program.find("#FRAGMENT_SHADER"); @@ -90,7 +90,7 @@ namespace jin || loc_END_FRAGMENT_SHADER == string::npos ) return false; - /* load vertex and fragment shader source into buffers */ + // load vertex and fragment shader source into buffers int start = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER"); string vertex_shader = program.substr(start, loc_END_VERTEX_SHADER - start); Buffer vbuffer = Buffer(vertex_shader.length() + BASE_VERTEX_SHADER_SIZE); @@ -99,7 +99,7 @@ namespace jin string fragment_shader = program.substr(start, loc_END_FRAGMENT_SHADER - start); Buffer fbuffer = Buffer(fragment_shader.length() + BASE_FRAGMENT_SHADER_SIZE); formatFragmentShader((char*)fbuffer.data, fragment_shader.c_str()); - /* compile */ + // compile GLint success; GLuint vshader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vshader, 1, (const GLchar**)&vbuffer.data, NULL); @@ -172,20 +172,20 @@ namespace jin glUniform1f(loc, number); } - /** - * https://www.douban.com/note/627332677/ - * struct TextureUnit - * { - * GLuint targetTexture1D; - * GLuint targetTexture2D; - * GLuint targetTexture3D; - * GLuint targetTextureCube; - * ... - * }; - * - * TextureUnit mTextureUnits[GL_MAX_TEXTURE_IMAGE_UNITS] - * GLuint mCurrentTextureUnit = 0; - */ + // + // https://www.douban.com/note/627332677/ + // struct TextureUnit + // { + // GLuint targetTexture1D; + // GLuint targetTexture2D; + // GLuint targetTexture3D; + // GLuint targetTextureCube; + // ... + // }; + // + // TextureUnit mTextureUnits[GL_MAX_TEXTURE_IMAGE_UNITS] + // GLuint mCurrentTextureUnit = 0; + // void Shader::sendTexture(const char* variable, const Texture* tex) { checkJSL(); @@ -279,4 +279,4 @@ namespace jin } // namespace graphics } // namespace jin -#endif // LIBJIN_MODULES_RENDER
\ No newline at end of file +#endif // jin_graphics_shader
\ No newline at end of file |