テクスチャをフレームバッファに貼り付けてから、フレームバッファでreadPixelsを呼び出すことができます。形式= gl.RGBAのテクスチャの
INIT時
// make a framebuffer
fb = gl.createFramebuffer();
// make this the current frame buffer
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
// attach the texture to the framebuffer.
gl.framebufferTexture2D(
gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D, texture, 0);
// check if you can read from this type of texture.
bool canRead = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE);
// Unbind the framebuffer
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
読み出し時
if (canRead) {
// bind the framebuffer
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
// read the pixels
gl.readPixels(......);
// Unbind the framebuffer
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
、タイプ= gl.UNSIGNED_BYTE canReadは常に真でなければなりません。他の形式と型の場合、canReadはfalseかもしれません。
いいアイデア!ありがとう!! :) – Andy
私が理解するように、gl.framebufferTexture2Dはlevel = 0を必要とするので、これはlevel = 0のテクスチャに対してのみ機能します。ゼロ以外のレベルも処理する方法はありますか? – Andy
シェーダー内のtexture2DLodを使って別のテクスチャのレベル0に特定のレベルをレンダリングし、それを読み取ることができます。 – gman