- 当前 Bug 的表现(可附上截图)
注:目前只有华为的手机和平板会有这个问题。其他手机:Android,iOS都正常表现。
用离屏的webgl canvas渲染到上屏的canvas 2D环境,只有在华为的android手机上,看不到webgl的内容。
下图中,彩色的三角形和四边形,就是用webgl渲染的;但是看不到;
- 预期表现
- 复现路径
https://developers.weixin.qq.com/s/L4gO2NmP7d6B
- 提供一个最简复现 Demo
https://developers.weixin.qq.com/s/L4gO2NmP7d6B
重点代码在最后几行。
function tick() { requestAnimationFrame(tick); drawScene();
contextMain .clearRect(0 ,0, canvasMain.width, canvasMain.height); contextMain.drawImage(canvas3D, 0, 0); contextMain.fillStyle = "#FFFFFF" contextMain.fillRect(0, 0, 100, 100); } let contextMain = undefined; let canvasMain = undefined; let canvas3D = undefined; function webGLStart(canvas) {
canvas3D = wx.createCanvas(); canvas3D.width = canvasMain.width; canvas3D.height = canvasMain.height initGL(canvas3D); initShaders(); initBuffers(); gl.clearColor(0.0, 0.0, 0.0, 1.0); gl.enable(gl.DEPTH_TEST); tick(); } GameGlobal.alert = (...msg) => console.log( "alert" , ...msg); webGLStart(wx.createCanvas()); |
请给一下华为的具体机型?
我们测试了三个 Honor 7x, Honor v20, BTV-DL09(平板),这三个都是相同的问题
并且不只是2.6.2这个基础库有问题,2.3.0试了也是相同的问题
renderer = new THREE.WebGLRenderer();
let target = new THREE.WebGLRenderTarget(
sysInfo.screenWidth*sysInfo.pixelRatio,
(sysInfo.screenHeight-c_toolbarHeight)*sysInfo.pixelRatio);
renderer.setRenderTarget(target);
var canvas_huawei=wx.createCanvas();
canvas_huawei.width=sysInfo.screenWidth*sysInfo.pixelRatio;
canvas_huawei.height=(sysInfo.screenHeight-c_toolbarHeight)*sysInfo.pixelRatio;
var ctx_huawei=canvas_huawei.getContext('2d');
var canvas_huawei2=wx.createCanvas();
canvas_huawei2.width=sysInfo.screenWidth*sysInfo.pixelRatio;
canvas_huawei2.height=(sysInfo.screenHeight-c_toolbarHeight)*sysInfo.pixelRatio;
var ctx_huawei2=canvas_huawei2.getContext('2d');
var imageData = ctx_huawei.createImageData(
sysInfo.screenWidth*sysInfo.pixelRatio,
(sysInfo.screenHeight-c_toolbarHeight)*sysInfo.pixelRatio);
var pixels = new Uint8Array(imageData.data.length);
renderer.render(scene, camera);
gl.readPixels(
0,
0,
gl.drawingBufferWidth,
gl.drawingBufferHeight,
gl.RGBA,gl.UNSIGNED_BYTE,pixels);
imageData.data.set(pixels);
ctx_huawei.putImageData(imageData,0,0);
//清除 ctx_huawei2.clearRect(0,0,canvas_huawei2.width,canvas_huawei2.height);
//上下镜像翻转
ctx_huawei2.translate(0,canvas_huawei2.height);
ctx_huawei2.scale(1, -1);
ctx_huawei2.drawImage(canvas_huawei,0,0);
//恢复
ctx_huawei2.translate(0,canvas_huawei2.height);
ctx_huawei2.scale(1, -1);
wx.tmGlobal.ctx_bkg.drawImage(canvas_huawei2,
0,c_toolbarHeight*sysInfo.pixelRatio);
我的华为p10 plus(VKY-AL00)真机也是遇到这个问题。有解决方案了吗?
vivo和iphone都是OK的。