shaderir: Add predefined macros

This commit is contained in:
Hajime Hoshi 2020-05-16 23:29:01 +09:00
parent 66e76597d8
commit 316e502f4b
2 changed files with 12 additions and 2 deletions

View File

@ -53,16 +53,20 @@ func (p *Program) Glsl() string {
// Vertex func
if len(p.VertexFunc.Block.Stmts) > 0 {
lines = append(lines, "#if defined(COMPILING_VERTEX_SHADER)")
lines = append(lines, "void main(void) {")
lines = append(lines, p.glslBlock(&p.VertexFunc.Block, 0, 0)...)
lines = append(lines, "}")
lines = append(lines, "#endif")
}
// Fragment func
if len(p.FragmentFunc.Block.Stmts) > 0 {
lines = append(lines, "#if defined(COMPILING_FRAGMENT_SHADER)")
lines = append(lines, "void main(void) {")
lines = append(lines, p.glslBlock(&p.FragmentFunc.Block, 0, 0)...)
lines = append(lines, "}")
lines = append(lines, "#endif")
}
var stLines []string

View File

@ -562,11 +562,13 @@ attribute float A1;
attribute vec2 A2;
varying float V0;
varying vec2 V1;
#if defined(COMPILING_VERTEX_SHADER)
void main(void) {
gl_Position = A0;
V0 = A1;
V1 = A2;
}`,
}
#endif`,
},
{
Name: "FragmentFunc",
@ -628,11 +630,14 @@ attribute float A1;
attribute vec2 A2;
varying float V0;
varying vec2 V1;
#if defined(COMPILING_VERTEX_SHADER)
void main(void) {
gl_Position = A0;
V0 = A1;
V1 = A2;
}
#endif
#if defined(COMPILING_FRAGMENT_SHADER)
void main(void) {
vec2 l0;
vec4 l1;
@ -640,7 +645,8 @@ void main(void) {
l2 = V0;
l0 = V1;
l1 = gl_FragCoord;
}`,
}
#endif`,
},
}
for _, tc := range tests {