From 316e502f4be0c74b28bd30db9168876045bf528d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 16 May 2020 23:29:01 +0900 Subject: [PATCH] shaderir: Add predefined macros --- internal/shaderir/glsl.go | 4 ++++ internal/shaderir/ir_test.go | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/shaderir/glsl.go b/internal/shaderir/glsl.go index 9ef4f6f3b..6874a0894 100644 --- a/internal/shaderir/glsl.go +++ b/internal/shaderir/glsl.go @@ -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 diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index 226911871..9eb7e6d21 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -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 {