diff options
Diffstat (limited to 'src/libjin/Graphics/Shaders/base.shader.h')
-rw-r--r-- | src/libjin/Graphics/Shaders/base.shader.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/libjin/Graphics/Shaders/base.shader.h b/src/libjin/Graphics/Shaders/base.shader.h new file mode 100644 index 0000000..3790a47 --- /dev/null +++ b/src/libjin/Graphics/Shaders/base.shader.h @@ -0,0 +1,104 @@ +/* + * https://stackoverflow.com/questions/10868958/what-does-sampler2d-store + * The sampler2D is bound to a texture unit. The glUniform call binds it to texture + * unit zero. The glActiveTexture call is only needed if you are going to use multiple + * texture units (because GL_TEXTURE0 is the default anyway). +*/ +/* +#VERTEX_SHADER + +vertex vert(vertex v) +{ + return v; +} + +#END_VERTEX_SHADER + +#FRAGMENT_SHADER + +vec4 frag(vec4 color, Texture tex, vertex v) +{ + return Texel(tex, v.uv); +} + +#END_FRAGMENT_SHADER + +*/ + +static const char* base_shared = R"( +#define Number float +#define Texture sampler2D +#define Canvas sampler2D +#define Color vec4 +#define Vec2 vec2 +#define Vec3 vec3 +#define Vec4 vec4 + +#define texel texture2D + +struct Vertex +{ + vec2 xy; + vec2 uv; +}; + +)"; + +static const int BASE_SHARED_SIZE = strlen(base_shared); + +static const char* base_vertex = R"( +#version 130 core + +%s + +uniform mat4 _projectionMatrix_; +uniform mat4 _modelMatrix_; + +in vec2 _vert_coord_; +in vec2 _tex_coord_; + +out vec4 _color; +out vec2 _xy; +out vec2 _uv; + +%s + +void main() +{ + vec4 v = _modelMatrix_ * vec4(_vert_coord_, 0, 1.0); + Vertex _v = vert(Vertex(v.xy, _tex_coord_)); + gl_Position = _projectionMatrix_ * vec4(_v.xy, 0, 1.0f); + _color = gl_Color; + _xy = _v.xy; + _uv = _v.uv; +} +)"; + +static const int BASE_VERTEX_SHADER_SIZE = strlen(base_vertex) + BASE_SHARED_SIZE; + +#define formatVertexShader(buf, program) sprintf(buf,base_vertex, base_shared, program) + +static const char* base_fragment = R"( +#version 130 core + +%s + +uniform Texture _main_texture_; + +in vec4 _color; +in vec2 _xy; +in vec2 _uv; + +out vec4 _outColor_; + +%s + +void main() +{ + _outColor_ = frag(_color, _main_texture_, Vertex(_xy, _uv)); +} +)"; + +static const int BASE_FRAGMENT_SHADER_SIZE = strlen(base_fragment) + BASE_SHARED_SIZE; + +#define formatFragmentShader(buf, program) sprintf(buf, base_fragment, base_shared, program) |