oframe / ogl

Minimal WebGL Library
https://oframe.github.io/ogl/examples
3.77k stars 213 forks source link

Can't make the OES_standard_derivatives extension be supported #125

Closed AslanGM closed 2 years ago

AslanGM commented 2 years ago

Hi there, I've just started to learn WebGL using your library, and I have a question about extensions. I want to use fwidth() in my fragment shader, so I added:#extension GL_OES_standard_derivatives : enable

But I get the error Uncaught TypeError: Cannot read properties of undefined (reading 'forEach') and the warning WARNING: 0:1: 'GL_OES_standard_derivatives' : extension is not supported.

So I need to get this extension from Renderer. I'm doing this:

const renderer = new Renderer({
        alpha: true,
        width: _w,
        height: _h,
})
const gl = renderer.gl
gl.getExtension('OES_standard_derivatives')

But I received the same error and the same warning. So I need to make the extension supported, but I can't understand what I'm doing wrong. Can you help me, please?

hansagames commented 2 years ago

Hi, check what webgl version you are using, as webgl 2.0 can throw such thing (happens for me on chrome) as its not needed there anymore as webgl 2.0 have all standard extensions built in, just need to have es 300 shader

AslanGM commented 2 years ago

@hansagames hi, Thanks for your answer! I checked I have webgl 2.0, and I'm using chrome. So as I understand, I need to add #version 300 es in my fragment shader and change the syntax of all variables?

hansagames commented 2 years ago

@AslanGoat Yes you need to writte #version 300 es shader and you dont need to add any extra extensions as it will work out of box, just remeber that shader syntax is a bit different for 300 versus 100.

If you want to support both webgl 1 and 2 then need to write 2 shaders at the moment and then use them based on engine version. I havent found better way at them moment

AslanGM commented 2 years ago

@hansagames Thanks a lot, mate! You saved me so much time. I made the 300 version, and now everything is working. I'll do two versions as you advised.