aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/shaders/je_shader.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-12-20 23:53:26 +0800
committerchai <chaifix@163.com>2018-12-20 23:53:26 +0800
commit1aecfab7ce9a7d25ba0ecf9525bd1058ca2b1ba0 (patch)
treea7f6b1487ac125e2b92a13ac009e2ca0cd1573d3 /src/libjin/graphics/shaders/je_shader.cpp
parent22da8ebd408e5d70c5ac1d2bb35070938a1d2820 (diff)
*misc
Diffstat (limited to 'src/libjin/graphics/shaders/je_shader.cpp')
-rw-r--r--src/libjin/graphics/shaders/je_shader.cpp94
1 files changed, 41 insertions, 53 deletions
diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp
index 8fbb133..f752e99 100644
--- a/src/libjin/graphics/shaders/je_shader.cpp
+++ b/src/libjin/graphics/shaders/je_shader.cpp
@@ -27,52 +27,40 @@ namespace JinEngine
// SHADER_FORMAT_SIZE
// formatShader
//
-#include "built-in/je_default.shader.h"
+ #include "built-in/je_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;
-/*
- Shader* Shader::createShader(const string& program)
- {
- Shader* shader = nullptr;
- try
- {
- shader = new Shader(program);
- }
- catch (...)
- {
- return nullptr;
- }
- return shader;
- }
-*/
+
Shader::Shader(const string& program)
: mCurrentTextureUnit(DEFAULT_TEXTURE_UNIT)
{
if (!compile(program))
+ {
throw 0;
+ }
}
Shader::~Shader()
@@ -97,23 +85,23 @@ 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)
+ #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)
// Compile vertex shader.
GLuint vid = glCreateShader(GL_VERTEX_SHADER);
glsl(GL_VERTEX_SHADER, vid, vertex_shader);
// Compile fragment shader.
GLuint fid = glCreateShader(GL_FRAGMENT_SHADER);
glsl(GL_FRAGMENT_SHADER, fid, fragment_shader);
-#undef glsl
+ #undef glsl
// Create OpenGL shader program.
mPID = glCreateProgram();
glAttachShader(mPID, vid);
@@ -144,9 +132,9 @@ if (success == GL_FALSE) \
return mCurrentTextureUnit;
}
-#define checkJSL() \
- if (gl.getShader() != this) \
- return
+ #define checkJSL() \
+ if (gl.getShader() != this) \
+ return
void Shader::sendInt(const char* name, int value)
{