1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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 jin_ProjectionMatrix;
uniform mat4 jin_ModelMatrix;
in vec2 jin_VertexCoords;
in vec2 jin_TextureCoords;
out vec4 jin_Color;
out vec2 jin_XY;
out vec2 jin_UV;
%s
void main()
{
vec4 v = jin_ModelMatrix * vec4(jin_VertexCoords, 0, 1.0);
Vertex _v = vert(Vertex(v.xy, jin_TextureCoords));
gl_Position = jin_ProjectionMatrix * vec4(_v.xy, 0, 1.0f);
jin_Color = gl_Color;
jin_XY = _v.xy;
jin_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 jin_MainTexture;
in vec4 jin_Color;
in vec2 jin_XY;
in vec2 jin_UV;
out vec4 jin_OutColor;
%s
void main()
{
jin_OutColor = frag(jin_Color, jin_MainTexture, Vertex(jin_XY, jin_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)
|