gpu/backend: add support for GLSL 1.50

Apple's OpenGL 3.2 Core implementation doesn't accept 1.30.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-02-27 19:56:35 +01:00
parent dd6a247326
commit 3043c4243a
5 changed files with 30 additions and 7 deletions
+3
View File
@@ -10,6 +10,7 @@ var (
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",
GLSL150: "#version 150\n\nin vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n",
/*
static float4 gl_Position;
static float4 position;
@@ -45,6 +46,7 @@ var (
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",
GLSL150: "#version 150\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;
@@ -73,6 +75,7 @@ var (
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",
GLSL150: "#version 150\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;
+1
View File
@@ -50,6 +50,7 @@ type ShaderSources struct {
GLSL100ES string
GLSL300ES string
GLSL130 string
GLSL150 string
HLSL []byte
Uniforms UniformsReflection
Inputs []InputLocation
+11 -7
View File
@@ -19,7 +19,7 @@ type Backend struct {
state glstate
gl3 bool
glver [2]int
gles bool
ubo bool
feats backend.Caps
@@ -131,10 +131,9 @@ func NewBackend(f Functions) (*Backend, error) {
if err != nil {
return nil, err
}
gl3 := ver[0] >= 3
ubo := gl3 && gles
ubo := ver[0] >= 3 && gles
b := &Backend{
gl3: gl3,
glver: ver,
gles: gles,
ubo: ubo,
funcs: f,
@@ -437,10 +436,15 @@ func (b *Backend) NewProgram(vertShader, fragShader backend.ShaderSources) (back
attr[inp.Location] = inp.Name
}
vsrc, fsrc := vertShader.GLSL100ES, fragShader.GLSL100ES
if b.gl3 {
if b.gles {
if b.glver[0] >= 3 {
// OpenGL (ES) 3.0.
switch {
case b.gles:
vsrc, fsrc = vertShader.GLSL300ES, fragShader.GLSL300ES
} else {
case b.glver[0] >= 4 || b.glver[1] >= 2:
// OpenGL 3.2 Core only accepts glsl 1.50 or newer.
vsrc, fsrc = vertShader.GLSL150, fragShader.GLSL150
default:
vsrc, fsrc = vertShader.GLSL130, fragShader.GLSL130
}
}
+10
View File
@@ -15,6 +15,7 @@ var (
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",
GLSL150: "#version 150\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)
{
@@ -57,6 +58,7 @@ var (
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",
GLSL150: "#version 150\n\nuniform sampler2D tex;\n\nout vec4 fragColor;\nin vec2 vUV;\n\nvoid main()\n{\n fragColor = texture(tex, vUV);\n}\n\n",
/*
Texture2D<float4> tex : register(t0);
SamplerState _tex_sampler : register(s0);
@@ -102,6 +104,7 @@ var (
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",
GLSL150: "#version 150\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)
{
@@ -166,6 +169,7 @@ var (
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",
GLSL150: "#version 150\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)
{
@@ -215,6 +219,7 @@ var (
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",
GLSL150: "#version 150\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<float4> tex : register(t0);
SamplerState _tex_sampler : register(s0);
@@ -267,6 +272,7 @@ var (
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",
GLSL150: "#version 150\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)
{
@@ -348,6 +354,7 @@ var (
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",
GLSL150: "#version 150\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<float4> cover : register(t0);
SamplerState _cover_sampler : register(s0);
@@ -393,6 +400,7 @@ var (
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",
GLSL150: "#version 150\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)
{
@@ -443,6 +451,7 @@ var (
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",
GLSL150: "#version 150\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;
@@ -515,6 +524,7 @@ var (
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",
GLSL150: "#version 150\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)
{
+5
View File
@@ -124,9 +124,13 @@ func generate() error {
return err
}
}
// OpenGL 3.2 Core only accepts GLSL version 1.50, but is
// otherwise compatible with version 1.30.
glsl150 := strings.Replace(glsl130, "#version 130", "#version 150", 1)
variants[i].GLSL100ES = glsl100es
variants[i].GLSL300ES = glsl300es
variants[i].GLSL130 = glsl130
variants[i].GLSL150 = glsl150
variants[i].hlslSrc = hlsl
variants[i].HLSL = hlslc
}
@@ -157,6 +161,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, "GLSL150: %#v,\n", src.GLSL150)
fmt.Fprintf(&out, "/*\n%s\n*/\n", src.hlslSrc)
fmt.Fprintf(&out, "HLSL: %#v,\n", src.HLSL)
fmt.Fprintf(&out, "}")