WebGL EXT_frag_depth extension does not define GL_EXT_frag_depth macro in the vertex shader

Issue #12120362 • Assigned to wptcomptri@microsoft.com

Details

Author
Daniel B.
Created
May 24, 2017
Privacy
This issue is public.
Found in
  • Microsoft Edge
Found in build #
15.15063
Reports
Reported by 2 people

Sign in to watch or report this issue.

Steps to reproduce

When the EXT_frag_depth WebGL extension is supported, the GL_EXT_frag_depth macro should be defined in both the vertex and fragment shader. Here is an example where the shader program should link successfully:

<html>
<head>
    <title>Example</title>
</head>
<body>
<script type="text/javascript">
    function execute() {
        if (typeof WebGLRenderingContext === 'undefined') {
            throw 'The browser does not support WebGL.  Visit http://get.webgl.org.';
        }

        var canvas = document.getElementById('webgl');
        var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl') || undefined;
        if (!gl) {
            throw 'The browser supports WebGL, but initialization failed.';
        }

        var fragDepth = !!gl.getExtension('EXT_frag_depth');
        if (!fragDepth) {
            throw 'The EXT_frag_depth extension is required to reproduce this bug.';
        }

        gl.clearColor(0, 0, 0, 1);
        gl.clear(gl.COLOR_BUFFER_BIT);

        var vsSource =
            '#ifdef GL_EXT_frag_depth\n' +
            'varying float v_z;\n' +
            '#endif\n' +
            'void main() {\n' +
            '#ifdef GL_EXT_frag_depth\n' +
            '    v_z = 0.5;\n' +
            '#endif\n' +
            '    gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n' +
            '}\n';

        var fsSource =
            'precision highp float;\n' +
            '#ifdef GL_EXT_frag_depth\n' +
            '#extension GL_EXT_frag_depth : enable\n' +
            'varying float v_z;\n' +
            '#endif\n' +
            'void main() {\n' +
            '#ifdef GL_EXT_frag_depth\n' +
            '    gl_FragDepthEXT = v_z;\n' +
            '#endif\n' +
            '    gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n' +
            '}\n';

        var program = gl.createProgram();

        var vs = gl.createShader(gl.VERTEX_SHADER);
        gl.shaderSource(vs, vsSource);
        gl.compileShader(vs);
        if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS)) {
            throw 'Could not compile vertex shader: ' + gl.getShaderInfoLog(vs);
        }

        var fs = gl.createShader(gl.FRAGMENT_SHADER);
        gl.shaderSource(fs, fsSource);
        gl.compileShader(fs);
        if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS)) {
            throw 'Could not compile fragment shader: ' + gl.getShaderInfoLog(fs);
        }

        gl.attachShader(program, vs);
        gl.attachShader(program, fs);

        gl.deleteShader(vs);
        gl.deleteShader(fs);

        gl.linkProgram(program);
        if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
            throw 'Could not link the shader: ' + gl.getProgramInfoLog(program);
        }
    }

    function init() {
        try {
            execute();
        } catch (e) {
            alert('Error: ' + e);
        }
    }
    setTimeout(init, 100);

</script>
<canvas id="webgl" width="640" height="480"></canvas>
</body>
</html>

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Steven K.”

      Changed Assigned To to “wptcomptri@microsoft.com”

    You need to sign in to your Microsoft account to add a comment.

    Sign in