microsoft / angle

ANGLE: OpenGL ES to DirectX translation
Other
615 stars 166 forks source link

How to enable ES 3.0 in angle? #48

Closed zhaijialong closed 9 years ago

zhaijialong commented 9 years ago

Hi, I tried to use es 3.0 in the template sample on Win10 desktop. I set the EGL_CONTEXT_CLIENT_VERSION to 3 and changed the shader using in/out instead of attribute/varying, but I got the error Shader compilation failed: ERROR: 0:1: 'in' : storage qualifier supported in GLSL ES 3.00 only. And adding #version 300 es to the shader will result other parser errors.

austinkinross commented 9 years ago

Hi zhaijialong,

Adding EGL_CONTEXT_CLIENT_VERSION is correct and adding `#version 300 es' to the shaders is also correct.

However, #version 300 es must go on its own line in the shader source given to glShaderSource, but the STRING macro used in our templates doesn't automatically add newline characters. Therefore, you must manually add a \n to the shader source like this:

// Vertex Shader source
const std::string vs = STRING
(   #version 300 es\n
    uniform mat4 uModelMatrix;
    uniform mat4 uViewMatrix;
    uniform mat4 uProjMatrix;
    in vec4 aPosition;
    in vec4 aColor;
    out vec4 vColor;
    void main()
    {
        gl_Position = uProjMatrix * uViewMatrix * uModelMatrix * aPosition;
        vColor = aColor;
    }
);

// Fragment Shader source
const std::string fs = STRING
(   #version 300 es\n
    precision mediump float;
    in vec4 vColor;
    out vec4 fragmentColor;
    void main()
    {
        fragmentColor = vColor;
    }
);

These shaders should compile, and the spinning cube should be drawn using ES 3.0.

Alternatively you could remove the 'STRING' macro and load the shader source code using a different method (e.g. from a file).

Hope this helps! Austin

zhaijialong commented 9 years ago

It works. Thank you. : )