-
Creator 版本: 2.4.10
-
目标平台:原生,window/android
-
重现方式:该函数传入对应参数
-
重现概率: 100
想读取纹理对应区域的像素数据
let _rt: cc.RenderTexture;
const data = new Uint8Array(2048 * 2048 * 4);
function readData1(texture, sx: number, sy: number, sw: number, sh: number): Uint8ClampedArray | Uint8Array {
let rt: any = _rt;
if (!rt) {
rt = _rt = new RenderTexture();
_rt.initWithSize(2048, 2048, RenderTexture.DepthStencilFormat.RB_FMT_S8);
}
let gl = cc.game._renderContext;
let oldFBO = gl.getParameter(gl.FRAMEBUFFER_BINDING);
gl.bindFramebuffer(gl.FRAMEBUFFER, rt._framebuffer.getHandle());
//@ts-ignore
let glID, id, _texture = texture._texture;
if (CC_JSB) {
glID = _texture.getHandle();
id = _texture._id;
_texture._id = glID;
glID = _texture;
} else {
glID = _texture._glID
}
gl.framebufferTexture2D(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D,
glID,
0
);
if (CC_JSB) {
_texture._id = id;
}
gl.readPixels(sx, sy, sw, sh, gl.RGBA, gl.UNSIGNED_BYTE, data);
gl.bindFramebuffer(gl.FRAMEBUFFER, oldFBO);
return data;
}
web正常,原生能正常读取,但是原来纹理的数据会出现被覆盖的情况。有了解情况的吗?
