I am using inbuilt opengl function - [ "ivec2 textureSize(`|gsampler2D sampler, int lod ) "
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/textureSize.xhtml ] to compute the size of texel as follows in my fragment shader :
vec2 texMapScale = vec2(1.)/textureSize(OMap,0);
However I am getting the following complilation error:
ERROR: 0:114: ‘textureSize’ : no matching overloaded function found.
I cannot find the reason for the error.
Web GL is based on GLES, not Open GL, so I don’t believe you have access to textureSize as you linked. If you know the texture size ahead of time. If you’re using the GPU Compute Renderer extension, I believe it has the variable,
Built in for this, but otherwise, you’ll have to pass that in yourself as a uniform probably.
BTW, what is your ultimate goal that you’re trying to achieve. Perhaps you don’t need the texture size.
Web GL is based on GLES
It’s more correct to say it is based on
OpenGL ES which stands for Open Graphics Library for Embedded Systems.
textureSize() should be available in WebGL 2. More information here:
When using the latest version of
WebGLRenderer automatically uses a WebGL 2 rendering context.
@Mugen87 I am using version 117. Do I need to switch to 118?
I have followed the webgl2 tutorial you have shared. And I have also checked that textureSize() is available in WebGL2 but I am still getting the error.
Full working example:
Edit fiddle - JSFiddle - Code Playground
If you increase the second argument of
textureSize(), you will see that the plane becomes darker since the resolution of the mipmaps get smaller.
I am using version 117.
You can also use this version but then you have to create a custom WebGL 2 rendering context and pass it to the renderer.
@Mugen87 Creating a custom WebGL2 rendering context solved the issue. Thank you for helping me resolve the error I was stuck on for hours.