diff --git a/app/headless/shaders.go b/app/headless/shaders.go index bda6e588..d4fa92ac 100644 --- a/app/headless/shaders.go +++ b/app/headless/shaders.go @@ -7,8 +7,9 @@ import "gioui.org/gpu/backend" var ( shader_input_vert = backend.ShaderSources{ Inputs: []backend.InputLocation{backend.InputLocation{Name: "position", Location: 0, Semantic: "POSITION", SemanticIndex: 0, Type: 0x0, Size: 4}}, - GLSL100ES: "#version 100\n\nattribute vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n", + GLSL100ES: "\nattribute vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n", GLSL300ES: "#version 300 es\n\nlayout(location = 0) in vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n", + GLSL130: "#version 130\n\nin vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n", /* static float4 gl_Position; static float4 position; @@ -41,8 +42,9 @@ var ( HLSL: []byte(nil), } shader_simple_frag = backend.ShaderSources{ - GLSL100ES: "#version 100\nprecision mediump float;\nprecision highp int;\n\nvoid main()\n{\n gl_FragData[0] = vec4(0.25, 0.5, 0.75, 1.0);\n}\n\n", - GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nlayout(location = 0) out vec4 fragColor;\n\nvoid main()\n{\n fragColor = vec4(0.25, 0.5, 0.75, 1.0);\n}\n\n", + GLSL100ES: "precision mediump float;\nprecision highp int;\n\nvoid main()\n{\n gl_FragData[0] = vec4(0.25, 0.550000011920928955078125, 0.75, 1.0);\n}\n\n", + GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nlayout(location = 0) out vec4 fragColor;\n\nvoid main()\n{\n fragColor = vec4(0.25, 0.550000011920928955078125, 0.75, 1.0);\n}\n\n", + GLSL130: "#version 130\n\nout vec4 fragColor;\n\nvoid main()\n{\n fragColor = vec4(0.25, 0.550000011920928955078125, 0.75, 1.0);\n}\n\n", /* static float4 fragColor; @@ -53,7 +55,7 @@ var ( void frag_main() { - fragColor = float4(0.25f, 0.5f, 0.75f, 1.0f); + fragColor = float4(0.25f, 0.550000011920928955078125f, 0.75f, 1.0f); } SPIRV_Cross_Output main() @@ -68,8 +70,9 @@ var ( HLSL: []byte(nil), } shader_simple_vert = backend.ShaderSources{ - GLSL100ES: "#version 100\n\nvoid main()\n{\n float x;\n float y;\n if (gl_VertexID == 0)\n {\n x = 0.0;\n y = 0.5;\n }\n else\n {\n if (gl_VertexID == 1)\n {\n x = 0.5;\n y = -0.5;\n }\n else\n {\n x = -0.5;\n y = -0.5;\n }\n }\n gl_Position = vec4(x, y, 0.5, 1.0);\n}\n\n", + GLSL100ES: "\nvoid main()\n{\n float x;\n float y;\n if (gl_VertexID == 0)\n {\n x = 0.0;\n y = 0.5;\n }\n else\n {\n if (gl_VertexID == 1)\n {\n x = 0.5;\n y = -0.5;\n }\n else\n {\n x = -0.5;\n y = -0.5;\n }\n }\n gl_Position = vec4(x, y, 0.5, 1.0);\n}\n\n", GLSL300ES: "#version 300 es\n\nvoid main()\n{\n float x;\n float y;\n if (gl_VertexID == 0)\n {\n x = 0.0;\n y = 0.5;\n }\n else\n {\n if (gl_VertexID == 1)\n {\n x = 0.5;\n y = -0.5;\n }\n else\n {\n x = -0.5;\n y = -0.5;\n }\n }\n gl_Position = vec4(x, y, 0.5, 1.0);\n}\n\n", + GLSL130: "#version 130\n\nvoid main()\n{\n float x;\n float y;\n if (gl_VertexID == 0)\n {\n x = 0.0;\n y = 0.5;\n }\n else\n {\n if (gl_VertexID == 1)\n {\n x = 0.5;\n y = -0.5;\n }\n else\n {\n x = -0.5;\n y = -0.5;\n }\n }\n gl_Position = vec4(x, y, 0.5, 1.0);\n}\n\n", /* static float4 gl_Position; static int gl_VertexIndex; diff --git a/gpu/backend/backend.go b/gpu/backend/backend.go index b9964014..8f0d6a4b 100644 --- a/gpu/backend/backend.go +++ b/gpu/backend/backend.go @@ -49,6 +49,7 @@ type Device interface { type ShaderSources struct { GLSL100ES string GLSL300ES string + GLSL130 string HLSL []byte Uniforms UniformsReflection Inputs []InputLocation diff --git a/gpu/gl/backend.go b/gpu/gl/backend.go index f15a0144..150fa606 100644 --- a/gpu/gl/backend.go +++ b/gpu/gl/backend.go @@ -19,8 +19,10 @@ type Backend struct { state glstate - gles300 bool - feats backend.Caps + gl3 bool + gles bool + ubo bool + feats backend.Caps // floatTriple holds the settings for floating point // textures. floatTriple textureTriple @@ -129,9 +131,12 @@ func NewBackend(f Functions) (*Backend, error) { if err != nil { return nil, err } - gles300 := gles && ver[0] >= 3 + gl3 := ver[0] >= 3 + ubo := gl3 && gles b := &Backend{ - gles300: gles300, + gl3: gl3, + gles: gles, + ubo: ubo, funcs: f, floatTriple: floatTriple, alphaTriple: alphaTripleFor(ver), @@ -240,12 +245,12 @@ func (b *Backend) NewBuffer(typ backend.BufferBinding, size int) (backend.Buffer if typ != backend.BufferBindingUniforms { return nil, errors.New("uniforms buffers cannot be bound as anything else") } - if !b.gles300 { + if !b.ubo { // GLES 2 doesn't support uniform buffers. buf.data = make([]byte, size) } } - if typ&^backend.BufferBindingUniforms != 0 || b.gles300 { + if typ&^backend.BufferBindingUniforms != 0 || b.ubo { buf.hasBuffer = true buf.obj = b.funcs.CreateBuffer() if err := glErr(b.funcs); err != nil { @@ -432,8 +437,12 @@ func (b *Backend) NewProgram(vertShader, fragShader backend.ShaderSources) (back attr[inp.Location] = inp.Name } vsrc, fsrc := vertShader.GLSL100ES, fragShader.GLSL100ES - if b.gles300 { - vsrc, fsrc = vertShader.GLSL300ES, fragShader.GLSL300ES + if b.gl3 { + if b.gles { + vsrc, fsrc = vertShader.GLSL300ES, fragShader.GLSL300ES + } else { + vsrc, fsrc = vertShader.GLSL130, fragShader.GLSL130 + } } p, err := CreateProgram(b.funcs, vsrc, fsrc, attr) if err != nil { @@ -458,7 +467,7 @@ func (b *Backend) NewProgram(vertShader, fragShader backend.ShaderSources) (back b.funcs.Uniform1i(u, tex.Binding) } } - if b.gles300 { + if b.ubo { for _, block := range vertShader.Uniforms.Blocks { blockIdx := b.funcs.GetUniformBlockIndex(p, block.Name) if blockIdx != INVALID_INDEX { @@ -497,7 +506,7 @@ func (p *gpuProgram) SetFragmentUniforms(buffer backend.Buffer) { func (p *gpuProgram) updateUniforms() { f := p.backend.funcs - if p.backend.gles300 { + if p.backend.ubo { if b := p.vertUniforms.buf; b != nil { f.BindBufferBase(UNIFORM_BUFFER, 0, b.obj) } diff --git a/gpu/shaders.go b/gpu/shaders.go index 414d3f98..8ab02b8c 100644 --- a/gpu/shaders.go +++ b/gpu/shaders.go @@ -12,8 +12,9 @@ var ( Locations: []backend.UniformLocation{backend.UniformLocation{Name: "_12._color", Type: 0x0, Size: 4, Offset: 0}}, Size: 16, }, - GLSL100ES: "#version 100\nprecision mediump float;\nprecision highp int;\n\nstruct Color\n{\n vec4 _color;\n};\n\nuniform Color _12;\n\nvarying vec2 vUV;\n\nvoid main()\n{\n gl_FragData[0] = _12._color;\n}\n\n", + GLSL100ES: "precision mediump float;\nprecision highp int;\n\nstruct Color\n{\n vec4 _color;\n};\n\nuniform Color _12;\n\nvarying vec2 vUV;\n\nvoid main()\n{\n gl_FragData[0] = _12._color;\n}\n\n", GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nlayout(std140) uniform Color\n{\n vec4 _color;\n} _12;\n\nlayout(location = 0) out vec4 fragColor;\nin vec2 vUV;\n\nvoid main()\n{\n fragColor = _12._color;\n}\n\n", + GLSL130: "#version 130\n\nstruct Color\n{\n vec4 _color;\n};\n\nuniform Color _12;\n\nout vec4 fragColor;\nin vec2 vUV;\n\nvoid main()\n{\n fragColor = _12._color;\n}\n\n", /* cbuffer Color : register(b0) { @@ -53,8 +54,9 @@ var ( }, backend.ShaderSources{ Textures: []backend.TextureBinding{backend.TextureBinding{Name: "tex", Binding: 0}}, - GLSL100ES: "#version 100\nprecision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D tex;\n\nvarying vec2 vUV;\n\nvoid main()\n{\n gl_FragData[0] = texture2D(tex, vUV);\n}\n\n", + GLSL100ES: "precision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D tex;\n\nvarying vec2 vUV;\n\nvoid main()\n{\n gl_FragData[0] = texture2D(tex, vUV);\n}\n\n", GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D tex;\n\nlayout(location = 0) out vec4 fragColor;\nin vec2 vUV;\n\nvoid main()\n{\n fragColor = texture(tex, vUV);\n}\n\n", + GLSL130: "#version 130\n\nuniform sampler2D tex;\n\nout vec4 fragColor;\nin vec2 vUV;\n\nvoid main()\n{\n fragColor = texture(tex, vUV);\n}\n\n", /* Texture2D tex : register(t0); SamplerState _tex_sampler : register(s0); @@ -97,8 +99,9 @@ var ( Locations: []backend.UniformLocation{backend.UniformLocation{Name: "_24.transform", Type: 0x0, Size: 4, Offset: 0}, backend.UniformLocation{Name: "_24.uvTransform", Type: 0x0, Size: 4, Offset: 16}, backend.UniformLocation{Name: "_24.z", Type: 0x0, Size: 1, Offset: 32}}, Size: 36, }, - GLSL100ES: "#version 100\n\nstruct Block\n{\n vec4 transform;\n vec4 uvTransform;\n float z;\n};\n\nuniform Block _24;\n\nattribute vec2 pos;\nvarying vec2 vUV;\nattribute vec2 uv;\n\nvec4 toClipSpace(vec4 pos_1)\n{\n return pos_1;\n}\n\nvoid main()\n{\n vec2 p = (pos * _24.transform.xy) + _24.transform.zw;\n vec4 param = vec4(p, _24.z, 1.0);\n gl_Position = toClipSpace(param);\n vUV = (uv * _24.uvTransform.xy) + _24.uvTransform.zw;\n}\n\n", + GLSL100ES: "\nstruct Block\n{\n vec4 transform;\n vec4 uvTransform;\n float z;\n};\n\nuniform Block _24;\n\nattribute vec2 pos;\nvarying vec2 vUV;\nattribute vec2 uv;\n\nvec4 toClipSpace(vec4 pos_1)\n{\n return pos_1;\n}\n\nvoid main()\n{\n vec2 p = (pos * _24.transform.xy) + _24.transform.zw;\n vec4 param = vec4(p, _24.z, 1.0);\n gl_Position = toClipSpace(param);\n vUV = (uv * _24.uvTransform.xy) + _24.uvTransform.zw;\n}\n\n", GLSL300ES: "#version 300 es\n\nlayout(std140) uniform Block\n{\n vec4 transform;\n vec4 uvTransform;\n float z;\n} _24;\n\nlayout(location = 0) in vec2 pos;\nout vec2 vUV;\nlayout(location = 1) in vec2 uv;\n\nvec4 toClipSpace(vec4 pos_1)\n{\n return pos_1;\n}\n\nvoid main()\n{\n vec2 p = (pos * _24.transform.xy) + _24.transform.zw;\n vec4 param = vec4(p, _24.z, 1.0);\n gl_Position = toClipSpace(param);\n vUV = (uv * _24.uvTransform.xy) + _24.uvTransform.zw;\n}\n\n", + GLSL130: "#version 130\n\nstruct Block\n{\n vec4 transform;\n vec4 uvTransform;\n float z;\n};\n\nuniform Block _24;\n\nin vec2 pos;\nout vec2 vUV;\nin vec2 uv;\n\nvec4 toClipSpace(vec4 pos_1)\n{\n return pos_1;\n}\n\nvoid main()\n{\n vec2 p = (pos * _24.transform.xy) + _24.transform.zw;\n vec4 param = vec4(p, _24.z, 1.0);\n gl_Position = toClipSpace(param);\n vUV = (uv * _24.uvTransform.xy) + _24.uvTransform.zw;\n}\n\n", /* cbuffer Block : register(b0) { @@ -160,8 +163,9 @@ var ( Size: 16, }, Textures: []backend.TextureBinding{backend.TextureBinding{Name: "cover", Binding: 1}}, - GLSL100ES: "#version 100\nprecision mediump float;\nprecision highp int;\n\nstruct Color\n{\n vec4 _color;\n};\n\nuniform Color _12;\n\nuniform mediump sampler2D cover;\n\nvarying highp vec2 vCoverUV;\nvarying vec2 vUV;\n\nvoid main()\n{\n gl_FragData[0] = _12._color;\n float cover_1 = abs(texture2D(cover, vCoverUV).x);\n gl_FragData[0] *= cover_1;\n}\n\n", + GLSL100ES: "precision mediump float;\nprecision highp int;\n\nstruct Color\n{\n vec4 _color;\n};\n\nuniform Color _12;\n\nuniform mediump sampler2D cover;\n\nvarying highp vec2 vCoverUV;\nvarying vec2 vUV;\n\nvoid main()\n{\n gl_FragData[0] = _12._color;\n float cover_1 = abs(texture2D(cover, vCoverUV).x);\n gl_FragData[0] *= cover_1;\n}\n\n", GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nlayout(std140) uniform Color\n{\n vec4 _color;\n} _12;\n\nuniform mediump sampler2D cover;\n\nlayout(location = 0) out vec4 fragColor;\nin highp vec2 vCoverUV;\nin vec2 vUV;\n\nvoid main()\n{\n fragColor = _12._color;\n float cover_1 = abs(texture(cover, vCoverUV).x);\n fragColor *= cover_1;\n}\n\n", + GLSL130: "#version 130\n\nstruct Color\n{\n vec4 _color;\n};\n\nuniform Color _12;\n\nuniform sampler2D cover;\n\nout vec4 fragColor;\nin vec2 vCoverUV;\nin vec2 vUV;\n\nvoid main()\n{\n fragColor = _12._color;\n float cover_1 = abs(texture(cover, vCoverUV).x);\n fragColor *= cover_1;\n}\n\n", /* cbuffer Color : register(b0) { @@ -208,8 +212,9 @@ var ( }, backend.ShaderSources{ Textures: []backend.TextureBinding{backend.TextureBinding{Name: "tex", Binding: 0}, backend.TextureBinding{Name: "cover", Binding: 1}}, - GLSL100ES: "#version 100\nprecision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D tex;\nuniform mediump sampler2D cover;\n\nvarying vec2 vUV;\nvarying highp vec2 vCoverUV;\n\nvoid main()\n{\n gl_FragData[0] = texture2D(tex, vUV);\n float cover_1 = abs(texture2D(cover, vCoverUV).x);\n gl_FragData[0] *= cover_1;\n}\n\n", + GLSL100ES: "precision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D tex;\nuniform mediump sampler2D cover;\n\nvarying vec2 vUV;\nvarying highp vec2 vCoverUV;\n\nvoid main()\n{\n gl_FragData[0] = texture2D(tex, vUV);\n float cover_1 = abs(texture2D(cover, vCoverUV).x);\n gl_FragData[0] *= cover_1;\n}\n\n", GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D tex;\nuniform mediump sampler2D cover;\n\nlayout(location = 0) out vec4 fragColor;\nin vec2 vUV;\nin highp vec2 vCoverUV;\n\nvoid main()\n{\n fragColor = texture(tex, vUV);\n float cover_1 = abs(texture(cover, vCoverUV).x);\n fragColor *= cover_1;\n}\n\n", + GLSL130: "#version 130\n\nuniform sampler2D tex;\nuniform sampler2D cover;\n\nout vec4 fragColor;\nin vec2 vUV;\nin vec2 vCoverUV;\n\nvoid main()\n{\n fragColor = texture(tex, vUV);\n float cover_1 = abs(texture(cover, vCoverUV).x);\n fragColor *= cover_1;\n}\n\n", /* Texture2D tex : register(t0); SamplerState _tex_sampler : register(s0); @@ -259,8 +264,9 @@ var ( Locations: []backend.UniformLocation{backend.UniformLocation{Name: "_66.transform", Type: 0x0, Size: 4, Offset: 0}, backend.UniformLocation{Name: "_66.uvCoverTransform", Type: 0x0, Size: 4, Offset: 16}, backend.UniformLocation{Name: "_66.uvTransform", Type: 0x0, Size: 4, Offset: 32}, backend.UniformLocation{Name: "_66.z", Type: 0x0, Size: 1, Offset: 48}}, Size: 52, }, - GLSL100ES: "#version 100\n\nstruct Block\n{\n vec4 transform;\n vec4 uvCoverTransform;\n vec4 uvTransform;\n float z;\n};\n\nuniform Block _66;\n\nattribute vec2 pos;\nvarying vec2 vUV;\nattribute vec2 uv;\nvarying vec2 vCoverUV;\n\nvec4 toClipSpace(vec4 pos_1)\n{\n return pos_1;\n}\n\nvec3[2] fboTextureTransform()\n{\n vec3 t[2];\n t[0] = vec3(1.0, 0.0, 0.0);\n t[1] = vec3(0.0, 1.0, 0.0);\n return t;\n}\n\nvec3 transform3x2(vec3 t[2], vec3 v)\n{\n return vec3(dot(t[0], v), dot(t[1], v), dot(vec3(0.0, 0.0, 1.0), v));\n}\n\nvoid main()\n{\n vec4 param = vec4((pos * _66.transform.xy) + _66.transform.zw, _66.z, 1.0);\n gl_Position = toClipSpace(param);\n vUV = (uv * _66.uvTransform.xy) + _66.uvTransform.zw;\n vec3 fboTrans[2] = fboTextureTransform();\n vec3 param_1[2] = fboTrans;\n vec3 param_2 = vec3(uv, 1.0);\n vec3 uv3 = transform3x2(param_1, param_2);\n vCoverUV = ((uv3 * vec3(_66.uvCoverTransform.xy, 1.0)) + vec3(_66.uvCoverTransform.zw, 0.0)).xy;\n}\n\n", + GLSL100ES: "\nstruct Block\n{\n vec4 transform;\n vec4 uvCoverTransform;\n vec4 uvTransform;\n float z;\n};\n\nuniform Block _66;\n\nattribute vec2 pos;\nvarying vec2 vUV;\nattribute vec2 uv;\nvarying vec2 vCoverUV;\n\nvec4 toClipSpace(vec4 pos_1)\n{\n return pos_1;\n}\n\nvec3[2] fboTextureTransform()\n{\n vec3 t[2];\n t[0] = vec3(1.0, 0.0, 0.0);\n t[1] = vec3(0.0, 1.0, 0.0);\n return t;\n}\n\nvec3 transform3x2(vec3 t[2], vec3 v)\n{\n return vec3(dot(t[0], v), dot(t[1], v), dot(vec3(0.0, 0.0, 1.0), v));\n}\n\nvoid main()\n{\n vec4 param = vec4((pos * _66.transform.xy) + _66.transform.zw, _66.z, 1.0);\n gl_Position = toClipSpace(param);\n vUV = (uv * _66.uvTransform.xy) + _66.uvTransform.zw;\n vec3 fboTrans[2] = fboTextureTransform();\n vec3 param_1[2] = fboTrans;\n vec3 param_2 = vec3(uv, 1.0);\n vec3 uv3 = transform3x2(param_1, param_2);\n vCoverUV = ((uv3 * vec3(_66.uvCoverTransform.xy, 1.0)) + vec3(_66.uvCoverTransform.zw, 0.0)).xy;\n}\n\n", GLSL300ES: "#version 300 es\n\nlayout(std140) uniform Block\n{\n vec4 transform;\n vec4 uvCoverTransform;\n vec4 uvTransform;\n float z;\n} _66;\n\nlayout(location = 0) in vec2 pos;\nout vec2 vUV;\nlayout(location = 1) in vec2 uv;\nout vec2 vCoverUV;\n\nvec4 toClipSpace(vec4 pos_1)\n{\n return pos_1;\n}\n\nvec3[2] fboTextureTransform()\n{\n vec3 t[2];\n t[0] = vec3(1.0, 0.0, 0.0);\n t[1] = vec3(0.0, 1.0, 0.0);\n return t;\n}\n\nvec3 transform3x2(vec3 t[2], vec3 v)\n{\n return vec3(dot(t[0], v), dot(t[1], v), dot(vec3(0.0, 0.0, 1.0), v));\n}\n\nvoid main()\n{\n vec4 param = vec4((pos * _66.transform.xy) + _66.transform.zw, _66.z, 1.0);\n gl_Position = toClipSpace(param);\n vUV = (uv * _66.uvTransform.xy) + _66.uvTransform.zw;\n vec3 fboTrans[2] = fboTextureTransform();\n vec3 param_1[2] = fboTrans;\n vec3 param_2 = vec3(uv, 1.0);\n vec3 uv3 = transform3x2(param_1, param_2);\n vCoverUV = ((uv3 * vec3(_66.uvCoverTransform.xy, 1.0)) + vec3(_66.uvCoverTransform.zw, 0.0)).xy;\n}\n\n", + GLSL130: "#version 130\n\nstruct Block\n{\n vec4 transform;\n vec4 uvCoverTransform;\n vec4 uvTransform;\n float z;\n};\n\nuniform Block _66;\n\nin vec2 pos;\nout vec2 vUV;\nin vec2 uv;\nout vec2 vCoverUV;\n\nvec4 toClipSpace(vec4 pos_1)\n{\n return pos_1;\n}\n\nvec3[2] fboTextureTransform()\n{\n vec3 t[2];\n t[0] = vec3(1.0, 0.0, 0.0);\n t[1] = vec3(0.0, 1.0, 0.0);\n return t;\n}\n\nvec3 transform3x2(vec3 t[2], vec3 v)\n{\n return vec3(dot(t[0], v), dot(t[1], v), dot(vec3(0.0, 0.0, 1.0), v));\n}\n\nvoid main()\n{\n vec4 param = vec4((pos * _66.transform.xy) + _66.transform.zw, _66.z, 1.0);\n gl_Position = toClipSpace(param);\n vUV = (uv * _66.uvTransform.xy) + _66.uvTransform.zw;\n vec3 fboTrans[2] = fboTextureTransform();\n vec3 param_1[2] = fboTrans;\n vec3 param_2 = vec3(uv, 1.0);\n vec3 uv3 = transform3x2(param_1, param_2);\n vCoverUV = ((uv3 * vec3(_66.uvCoverTransform.xy, 1.0)) + vec3(_66.uvCoverTransform.zw, 0.0)).xy;\n}\n\n", /* cbuffer Block : register(b0) { @@ -339,8 +345,9 @@ var ( } shader_intersect_frag = backend.ShaderSources{ Textures: []backend.TextureBinding{backend.TextureBinding{Name: "cover", Binding: 0}}, - GLSL100ES: "#version 100\nprecision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D cover;\n\nvarying highp vec2 vUV;\n\nvoid main()\n{\n float cover_1 = abs(texture2D(cover, vUV).x);\n gl_FragData[0].x = cover_1;\n}\n\n", + GLSL100ES: "precision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D cover;\n\nvarying highp vec2 vUV;\n\nvoid main()\n{\n float cover_1 = abs(texture2D(cover, vUV).x);\n gl_FragData[0].x = cover_1;\n}\n\n", GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nuniform mediump sampler2D cover;\n\nin highp vec2 vUV;\nlayout(location = 0) out vec4 fragColor;\n\nvoid main()\n{\n float cover_1 = abs(texture(cover, vUV).x);\n fragColor.x = cover_1;\n}\n\n", + GLSL130: "#version 130\n\nuniform sampler2D cover;\n\nin vec2 vUV;\nout vec4 fragColor;\n\nvoid main()\n{\n float cover_1 = abs(texture(cover, vUV).x);\n fragColor.x = cover_1;\n}\n\n", /* Texture2D cover : register(t0); SamplerState _cover_sampler : register(s0); @@ -383,8 +390,9 @@ var ( Locations: []backend.UniformLocation{backend.UniformLocation{Name: "_40.uvTransform", Type: 0x0, Size: 4, Offset: 0}}, Size: 16, }, - GLSL100ES: "#version 100\n\nstruct Block\n{\n vec4 uvTransform;\n};\n\nuniform Block _40;\n\nattribute vec2 pos;\nvarying vec2 vUV;\nattribute vec2 uv;\n\nvoid main()\n{\n vec2 p = pos;\n p.y = -p.y;\n gl_Position = vec4(p, 0.0, 1.0);\n vUV = (uv * _40.uvTransform.xy) + _40.uvTransform.zw;\n}\n\n", + GLSL100ES: "\nstruct Block\n{\n vec4 uvTransform;\n};\n\nuniform Block _40;\n\nattribute vec2 pos;\nvarying vec2 vUV;\nattribute vec2 uv;\n\nvoid main()\n{\n vec2 p = pos;\n p.y = -p.y;\n gl_Position = vec4(p, 0.0, 1.0);\n vUV = (uv * _40.uvTransform.xy) + _40.uvTransform.zw;\n}\n\n", GLSL300ES: "#version 300 es\n\nlayout(std140) uniform Block\n{\n vec4 uvTransform;\n} _40;\n\nlayout(location = 0) in vec2 pos;\nout vec2 vUV;\nlayout(location = 1) in vec2 uv;\n\nvoid main()\n{\n vec2 p = pos;\n p.y = -p.y;\n gl_Position = vec4(p, 0.0, 1.0);\n vUV = (uv * _40.uvTransform.xy) + _40.uvTransform.zw;\n}\n\n", + GLSL130: "#version 130\n\nstruct Block\n{\n vec4 uvTransform;\n};\n\nuniform Block _40;\n\nin vec2 pos;\nout vec2 vUV;\nin vec2 uv;\n\nvoid main()\n{\n vec2 p = pos;\n p.y = -p.y;\n gl_Position = vec4(p, 0.0, 1.0);\n vUV = (uv * _40.uvTransform.xy) + _40.uvTransform.zw;\n}\n\n", /* cbuffer Block : register(b0) { @@ -432,8 +440,9 @@ var ( HLSL: []byte(nil), } shader_stencil_frag = backend.ShaderSources{ - GLSL100ES: "#version 100\nprecision mediump float;\nprecision highp int;\n\nvarying vec2 vTo;\nvarying vec2 vFrom;\nvarying vec2 vCtrl;\n\nvoid main()\n{\n float dx = vTo.x - vFrom.x;\n bool increasing = vTo.x >= vFrom.x;\n bvec2 _35 = bvec2(increasing);\n vec2 left = vec2(_35.x ? vFrom.x : vTo.x, _35.y ? vFrom.y : vTo.y);\n bvec2 _41 = bvec2(increasing);\n vec2 right = vec2(_41.x ? vTo.x : vFrom.x, _41.y ? vTo.y : vFrom.y);\n vec2 extent = clamp(vec2(vFrom.x, vTo.x), vec2(-0.5), vec2(0.5));\n float midx = mix(extent.x, extent.y, 0.5);\n float x0 = midx - left.x;\n vec2 p1 = vCtrl - left;\n vec2 v = right - vCtrl;\n float t = x0 / (p1.x + sqrt((p1.x * p1.x) + ((v.x - p1.x) * x0)));\n float y = mix(mix(left.y, vCtrl.y, t), mix(vCtrl.y, right.y, t), t);\n vec2 d_half = mix(p1, v, vec2(t));\n float dy = d_half.y / d_half.x;\n float width = extent.y - extent.x;\n dy = abs(dy * width);\n vec4 sides = vec4((dy * 0.5) + y, (dy * (-0.5)) + y, (0.5 - y) / dy, ((-0.5) - y) / dy);\n sides = clamp(sides + vec4(0.5), vec4(0.0), vec4(1.0));\n float area = 0.5 * ((((sides.z - (sides.z * sides.y)) + 1.0) - sides.x) + (sides.x * sides.w));\n area *= width;\n if (width == 0.0)\n {\n area = 0.0;\n }\n gl_FragData[0].x = area;\n}\n\n", + GLSL100ES: "precision mediump float;\nprecision highp int;\n\nvarying vec2 vTo;\nvarying vec2 vFrom;\nvarying vec2 vCtrl;\n\nvoid main()\n{\n float dx = vTo.x - vFrom.x;\n bool increasing = vTo.x >= vFrom.x;\n bvec2 _35 = bvec2(increasing);\n vec2 left = vec2(_35.x ? vFrom.x : vTo.x, _35.y ? vFrom.y : vTo.y);\n bvec2 _41 = bvec2(increasing);\n vec2 right = vec2(_41.x ? vTo.x : vFrom.x, _41.y ? vTo.y : vFrom.y);\n vec2 extent = clamp(vec2(vFrom.x, vTo.x), vec2(-0.5), vec2(0.5));\n float midx = mix(extent.x, extent.y, 0.5);\n float x0 = midx - left.x;\n vec2 p1 = vCtrl - left;\n vec2 v = right - vCtrl;\n float t = x0 / (p1.x + sqrt((p1.x * p1.x) + ((v.x - p1.x) * x0)));\n float y = mix(mix(left.y, vCtrl.y, t), mix(vCtrl.y, right.y, t), t);\n vec2 d_half = mix(p1, v, vec2(t));\n float dy = d_half.y / d_half.x;\n float width = extent.y - extent.x;\n dy = abs(dy * width);\n vec4 sides = vec4((dy * 0.5) + y, (dy * (-0.5)) + y, (0.5 - y) / dy, ((-0.5) - y) / dy);\n sides = clamp(sides + vec4(0.5), vec4(0.0), vec4(1.0));\n float area = 0.5 * ((((sides.z - (sides.z * sides.y)) + 1.0) - sides.x) + (sides.x * sides.w));\n area *= width;\n if (width == 0.0)\n {\n area = 0.0;\n }\n gl_FragData[0].x = area;\n}\n\n", GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nin vec2 vTo;\nin vec2 vFrom;\nin vec2 vCtrl;\nlayout(location = 0) out vec4 fragCover;\n\nvoid main()\n{\n float dx = vTo.x - vFrom.x;\n bool increasing = vTo.x >= vFrom.x;\n bvec2 _35 = bvec2(increasing);\n vec2 left = vec2(_35.x ? vFrom.x : vTo.x, _35.y ? vFrom.y : vTo.y);\n bvec2 _41 = bvec2(increasing);\n vec2 right = vec2(_41.x ? vTo.x : vFrom.x, _41.y ? vTo.y : vFrom.y);\n vec2 extent = clamp(vec2(vFrom.x, vTo.x), vec2(-0.5), vec2(0.5));\n float midx = mix(extent.x, extent.y, 0.5);\n float x0 = midx - left.x;\n vec2 p1 = vCtrl - left;\n vec2 v = right - vCtrl;\n float t = x0 / (p1.x + sqrt((p1.x * p1.x) + ((v.x - p1.x) * x0)));\n float y = mix(mix(left.y, vCtrl.y, t), mix(vCtrl.y, right.y, t), t);\n vec2 d_half = mix(p1, v, vec2(t));\n float dy = d_half.y / d_half.x;\n float width = extent.y - extent.x;\n dy = abs(dy * width);\n vec4 sides = vec4((dy * 0.5) + y, (dy * (-0.5)) + y, (0.5 - y) / dy, ((-0.5) - y) / dy);\n sides = clamp(sides + vec4(0.5), vec4(0.0), vec4(1.0));\n float area = 0.5 * ((((sides.z - (sides.z * sides.y)) + 1.0) - sides.x) + (sides.x * sides.w));\n area *= width;\n if (width == 0.0)\n {\n area = 0.0;\n }\n fragCover.x = area;\n}\n\n", + GLSL130: "#version 130\n\nin vec2 vTo;\nin vec2 vFrom;\nin vec2 vCtrl;\nout vec4 fragCover;\n\nvoid main()\n{\n float dx = vTo.x - vFrom.x;\n bool increasing = vTo.x >= vFrom.x;\n bvec2 _35 = bvec2(increasing);\n vec2 left = vec2(_35.x ? vFrom.x : vTo.x, _35.y ? vFrom.y : vTo.y);\n bvec2 _41 = bvec2(increasing);\n vec2 right = vec2(_41.x ? vTo.x : vFrom.x, _41.y ? vTo.y : vFrom.y);\n vec2 extent = clamp(vec2(vFrom.x, vTo.x), vec2(-0.5), vec2(0.5));\n float midx = mix(extent.x, extent.y, 0.5);\n float x0 = midx - left.x;\n vec2 p1 = vCtrl - left;\n vec2 v = right - vCtrl;\n float t = x0 / (p1.x + sqrt((p1.x * p1.x) + ((v.x - p1.x) * x0)));\n float y = mix(mix(left.y, vCtrl.y, t), mix(vCtrl.y, right.y, t), t);\n vec2 d_half = mix(p1, v, vec2(t));\n float dy = d_half.y / d_half.x;\n float width = extent.y - extent.x;\n dy = abs(dy * width);\n vec4 sides = vec4((dy * 0.5) + y, (dy * (-0.5)) + y, (0.5 - y) / dy, ((-0.5) - y) / dy);\n sides = clamp(sides + vec4(0.5), vec4(0.0), vec4(1.0));\n float area = 0.5 * ((((sides.z - (sides.z * sides.y)) + 1.0) - sides.x) + (sides.x * sides.w));\n area *= width;\n if (width == 0.0)\n {\n area = 0.0;\n }\n fragCover.x = area;\n}\n\n", /* static float2 vTo; static float2 vFrom; @@ -503,8 +512,9 @@ var ( Locations: []backend.UniformLocation{backend.UniformLocation{Name: "_16.transform", Type: 0x0, Size: 4, Offset: 0}, backend.UniformLocation{Name: "_16.pathOffset", Type: 0x0, Size: 2, Offset: 16}}, Size: 24, }, - GLSL100ES: "#version 100\n\nstruct Block\n{\n vec4 transform;\n vec2 pathOffset;\n};\n\nuniform Block _16;\n\nattribute vec2 from;\nattribute vec2 ctrl;\nattribute vec2 to;\nattribute float maxy;\nattribute ivec2 corner;\nvarying vec2 vFrom;\nvarying vec2 vCtrl;\nvarying vec2 vTo;\n\nvoid main()\n{\n vec2 from_1 = from + _16.pathOffset;\n vec2 ctrl_1 = ctrl + _16.pathOffset;\n vec2 to_1 = to + _16.pathOffset;\n float maxy_1 = maxy + _16.pathOffset.y;\n vec2 pos;\n if (corner.x > 0)\n {\n pos.x = max(max(from_1.x, ctrl_1.x), to_1.x) + 1.0;\n }\n else\n {\n pos.x = min(min(from_1.x, ctrl_1.x), to_1.x) - 1.0;\n }\n if (corner.y > 0)\n {\n pos.y = maxy_1 + 1.0;\n }\n else\n {\n pos.y = min(min(from_1.y, ctrl_1.y), to_1.y) - 1.0;\n }\n vFrom = from_1 - pos;\n vCtrl = ctrl_1 - pos;\n vTo = to_1 - pos;\n pos = (pos * _16.transform.xy) + _16.transform.zw;\n gl_Position = vec4(pos, 1.0, 1.0);\n}\n\n", + GLSL100ES: "\nstruct Block\n{\n vec4 transform;\n vec2 pathOffset;\n};\n\nuniform Block _16;\n\nattribute vec2 from;\nattribute vec2 ctrl;\nattribute vec2 to;\nattribute float maxy;\nattribute ivec2 corner;\nvarying vec2 vFrom;\nvarying vec2 vCtrl;\nvarying vec2 vTo;\n\nvoid main()\n{\n vec2 from_1 = from + _16.pathOffset;\n vec2 ctrl_1 = ctrl + _16.pathOffset;\n vec2 to_1 = to + _16.pathOffset;\n float maxy_1 = maxy + _16.pathOffset.y;\n vec2 pos;\n if (corner.x > 0)\n {\n pos.x = max(max(from_1.x, ctrl_1.x), to_1.x) + 1.0;\n }\n else\n {\n pos.x = min(min(from_1.x, ctrl_1.x), to_1.x) - 1.0;\n }\n if (corner.y > 0)\n {\n pos.y = maxy_1 + 1.0;\n }\n else\n {\n pos.y = min(min(from_1.y, ctrl_1.y), to_1.y) - 1.0;\n }\n vFrom = from_1 - pos;\n vCtrl = ctrl_1 - pos;\n vTo = to_1 - pos;\n pos = (pos * _16.transform.xy) + _16.transform.zw;\n gl_Position = vec4(pos, 1.0, 1.0);\n}\n\n", GLSL300ES: "#version 300 es\n\nlayout(std140) uniform Block\n{\n vec4 transform;\n vec2 pathOffset;\n} _16;\n\nlayout(location = 2) in vec2 from;\nlayout(location = 3) in vec2 ctrl;\nlayout(location = 4) in vec2 to;\nlayout(location = 1) in float maxy;\nlayout(location = 0) in ivec2 corner;\nout vec2 vFrom;\nout vec2 vCtrl;\nout vec2 vTo;\n\nvoid main()\n{\n vec2 from_1 = from + _16.pathOffset;\n vec2 ctrl_1 = ctrl + _16.pathOffset;\n vec2 to_1 = to + _16.pathOffset;\n float maxy_1 = maxy + _16.pathOffset.y;\n vec2 pos;\n if (corner.x > 0)\n {\n pos.x = max(max(from_1.x, ctrl_1.x), to_1.x) + 1.0;\n }\n else\n {\n pos.x = min(min(from_1.x, ctrl_1.x), to_1.x) - 1.0;\n }\n if (corner.y > 0)\n {\n pos.y = maxy_1 + 1.0;\n }\n else\n {\n pos.y = min(min(from_1.y, ctrl_1.y), to_1.y) - 1.0;\n }\n vFrom = from_1 - pos;\n vCtrl = ctrl_1 - pos;\n vTo = to_1 - pos;\n pos = (pos * _16.transform.xy) + _16.transform.zw;\n gl_Position = vec4(pos, 1.0, 1.0);\n}\n\n", + GLSL130: "#version 130\n\nstruct Block\n{\n vec4 transform;\n vec2 pathOffset;\n};\n\nuniform Block _16;\n\nin vec2 from;\nin vec2 ctrl;\nin vec2 to;\nin float maxy;\nin ivec2 corner;\nout vec2 vFrom;\nout vec2 vCtrl;\nout vec2 vTo;\n\nvoid main()\n{\n vec2 from_1 = from + _16.pathOffset;\n vec2 ctrl_1 = ctrl + _16.pathOffset;\n vec2 to_1 = to + _16.pathOffset;\n float maxy_1 = maxy + _16.pathOffset.y;\n vec2 pos;\n if (corner.x > 0)\n {\n pos.x = max(max(from_1.x, ctrl_1.x), to_1.x) + 1.0;\n }\n else\n {\n pos.x = min(min(from_1.x, ctrl_1.x), to_1.x) - 1.0;\n }\n if (corner.y > 0)\n {\n pos.y = maxy_1 + 1.0;\n }\n else\n {\n pos.y = min(min(from_1.y, ctrl_1.y), to_1.y) - 1.0;\n }\n vFrom = from_1 - pos;\n vCtrl = ctrl_1 - pos;\n vTo = to_1 - pos;\n pos = (pos * _16.transform.xy) + _16.transform.zw;\n gl_Position = vec4(pos, 1.0, 1.0);\n}\n\n", /* cbuffer Block : register(b0) { diff --git a/internal/cmd/convertshaders/main.go b/internal/cmd/convertshaders/main.go index 80907751..b44c2f8a 100644 --- a/internal/cmd/convertshaders/main.go +++ b/internal/cmd/convertshaders/main.go @@ -89,16 +89,18 @@ func generate() error { }, } for i := range args { - glsl100, reflect, err := convertShader(tmp, glslcc, shader, "gles", "100", &args[i], false) + glsl100es, reflect, err := convertShader(tmp, glslcc, shader, "gles", "100", &args[i], false) if err != nil { return err } - // Make the GL ES 2 source compatible with desktop GL 3. - glsl100 = "#version 100\n" + glsl100 if err := parseReflection(reflect, &variants[i].ShaderSources); err != nil { return err } - glsl300, _, err := convertShader(tmp, glslcc, shader, "gles", "300", &args[i], false) + glsl300es, _, err := convertShader(tmp, glslcc, shader, "gles", "300", &args[i], false) + if err != nil { + return err + } + glsl130, _, err := convertShader(tmp, glslcc, shader, "glsl", "130", &args[i], false) if err != nil { return err } @@ -122,8 +124,9 @@ func generate() error { return err } } - variants[i].GLSL100ES = glsl100 - variants[i].GLSL300ES = glsl300 + variants[i].GLSL100ES = glsl100es + variants[i].GLSL300ES = glsl300es + variants[i].GLSL130 = glsl130 variants[i].hlslSrc = hlsl variants[i].HLSL = hlslc } @@ -153,6 +156,7 @@ func generate() error { } fmt.Fprintf(&out, "GLSL100ES: %#v,\n", src.GLSL100ES) fmt.Fprintf(&out, "GLSL300ES: %#v,\n", src.GLSL300ES) + fmt.Fprintf(&out, "GLSL130: %#v,\n", src.GLSL130) fmt.Fprintf(&out, "/*\n%s\n*/\n", src.hlslSrc) fmt.Fprintf(&out, "HLSL: %#v,\n", src.HLSL) fmt.Fprintf(&out, "}")