Canvas icon indicating copy to clipboard operation
Canvas copied to clipboard

Question: how can I check if creating a program shader failed?

Open CodeWithMichal opened this issue 5 years ago • 2 comments

Hi,

I am trying to rewrite some examples from webgl documentation and seems like I fail at the very beginning :) I am trying to check whether creating a program shader failed or not. The example JS code should looke similar to:

if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
   alert('An error occurred compiling the shaders: ' + gl.getShaderInfoLog(shader));
 }

But in your C# implementation of GetShaderParameterAsync it require generic parameter and I can't figure out what it should be. Could someone explain?

CodeWithMichal avatar Dec 21 '19 15:12 CodeWithMichal

The generic parameter should be the type you expect the method to return. As you can see here the method returns a bool when you pass COMPILE_STATUS.

jorolf avatar Dec 23 '19 20:12 jorolf

In Blazor you can use something like:

        bool status = await _context.GetShaderParameterAsync<bool>(shader, ShaderParameter.COMPILE_STATUS);
        if (status == false)
        {
            throw new Exception(await _context.GetShaderInfoLogAsync(shader));
        }

aykay76 avatar Dec 27 '20 16:12 aykay76