Search code examples
javascriptwebgltextures

How to find out Max Texture Size for WebGL on my system


I am working on an application where I apply filters on HD images using WebGL. The problem that I am facing is that when I apply the filters using WebGL image gets cut away which is because of the limitation on part of WebGL in my system.

So my question is How do i find out the max texture size of WebGL on my system. Currently I know for sure that its set to 2048. as the images of 2048 x 2048 work perfectly fine and images greater than that are causing issues.


Solution

  • The maximum texture size of a WebGLRenderingContext is returned by gl.getParameter(gl.MAX_TEXTURE_SIZE).
    See the answer to the question "Is it possible to use WebGL max texture size?".

    function getMaxTextureSize() {
        var gl = document.getElementById( "my-canvas").getContext( "experimental-webgl" );
        if ( !gl )
          return;
        document.getElementById( "textureSize" ).innerHTML = gl.getParameter(gl.MAX_TEXTURE_SIZE)
    }
    <body onload="getMaxTextureSize();">
        MAX_TEXTURE_SIZE : <span id="textureSize">0</span>
        <canvas id="my-canvas" style="border: none;" width="64" height="64"></canvas>
    </body>