cocos creator 3.7.4下调用renderTexture.readPixels()时在部分安卓手机上报GL error: 0x506的问题

发布于:2025-06-20 ⋅ 阅读:(24) ⋅ 点赞:(0)

f报错内容:
[ERROR] file /Applications/Cocos/Creator/3.7.4/CocosCreator.app/Contents/Resources/resources/3d/engine/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp: line 3205
[ERROR]: glReadPixels(region.texOffset.x, region.texOffset.y, region.texExtent.width, region.texExtent.height, glFormat, glType, copyDst) returned GL error: 0x506

部分openGl es 3.0的安卓机会报错。在start方法的下一帧设置gfx.ColorAttachment参数就可以了

protected start() {
        if(sys.platform == sys.Platform.ANDROID) {
            this._bgNode.setScale(v3(1,-1,1)); 
        }

        this.scheduleOnce(()=>{
            if(sys.platform == sys.Platform.ANDROID) {
                const gfxAPI = director.root.pipeline.device.gfxAPI;

                this.screenShotRT = new RenderTexture();    

                const colorAttachment = new gfx.ColorAttachment(
                    gfx.Format.RGBA8,      // 颜色格式
                    gfx.SampleCount.ONE,    // 采样数
                    gfx.LoadOp.CLEAR,      // 加载操作:清除
                    gfx.StoreOp.STORE,     // 存储操作:保存
                    null,                  // 通用屏障(可选)
                    false                  // 是否使用通用布局
                );

                const passInfo = new gfx.RenderPassInfo(
                    [colorAttachment],             // 颜色附件数组
                    null
                );

                this.screenShotRT.reset({
                    name: 'CustomRenderTexture',
                    width:750,
                    height:1650,
                    passInfo:passInfo
                });

                this._camera.targetTexture = this.screenShotRT
                this._camera.clearFlags = gfx.ClearFlagBit.COLOR;
                this._camera.clearColor = new Color(0, 0, 0, 0); 
            }
        });
    }
screenShotAndSave(shareScene: WXScene) {
    this.scheduleOnce(()=>{
        let pixelData = this.screenShotRT.readPixels();
        ......
    });
}


网站公告

今日签到

点亮在社区的每一天
去签到