JavaEar 专注于收集分享传播有价值的技术资料

WebGL最大分辨率? gl.readPixels返回空像素 (WebGL maximum resolution? gl.readPixels returning empty pixels)

I'm using headless-gl together with node to render a high-res generated WebGL image on the server-side. This works fine depending on the chosen resolution.

'use strict';

const Gl = require('gl');
const width   = 7200;
const height  = 10800;

// Setup renderer using headless-gl
const gl = Gl(width, height, { preserveDrawingBuffer: true })

// Clear screen to red
gl.clearColor(1, 0, 0, 1)
gl.clear(gl.COLOR_BUFFER_BIT)

// Get pixels
const pixels = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

// Is first color indeed red?
if (pixels[0] === 255) {
   console.log('OK'); 
}

process.exit();

After some point of increasing the width/height values the pixels array is filled with only zero values for the rgba pixels. I'm guessing that I'm hitting a memory/buffer limit somewhere but I'm not sure which one. According to nvidia-smi the GPU memory (12GB) is nowhere near depletion when running this.

What is the theoretical maximum resolution for webgl and what is it dependent on?

1个回答

    最佳答案

  1. 英文原文

    There is a maximum viewport size, that is independent of the amount of GPU memory.

    You can see the limits using gl.getParameter:

    console.log(gl.getParameter(gl.MAX_VIEWPORT_DIMS))
    console.log(gl.getParameter(gl.MAX_RENDERBUFFER_SIZE))
    

    My guess is that you're hitting the MAX_VIEWPORT_DIMS limitation.


    中文翻译

    最大视口大小与GPU内存量无关。

    您可以使用 gl.getParameter

    查看限制
     的console.log(gl.getParameter(gl.MAX_VIEWPORT_DIMS))
    的console.log(gl.getParameter(gl.MAX_RENDERBUFFER_SIZE))
     

    我的猜测是你正在达到 MAX_VIEWPORT_DIMS 限制。

    There is a maximum viewport size, that is independent of the amount of GPU memory.

    You can see the limits using gl.getParameter:

    console.log(gl.getParameter(gl.MAX_VIEWPORT_DIMS))
    console.log(gl.getParameter(gl.MAX_RENDERBUFFER_SIZE))
    

    My guess is that you're hitting the MAX_VIEWPORT_DIMS limitation.

    最大视口大小与GPU内存量无关。

    您可以使用 gl.getParameter

    查看限制
     的console.log(gl.getParameter(gl.MAX_VIEWPORT_DIMS))
    的console.log(gl.getParameter(gl.MAX_RENDERBUFFER_SIZE))
     

    我的猜测是你正在达到 MAX_VIEWPORT_DIMS 限制。