Opengl es WebGL读取模板缓冲区

Opengl es WebGL读取模板缓冲区,opengl-es,three.js,glsl,webgl,Opengl Es,Three.js,Glsl,Webgl,你好,我花了很多时间尝试在WebGL中进行简单的挑选。我在绘制每个对象之前使用: if(Window.stencilEnabled) gl.stencilFunc(gl.ALWAYS, mesh.pickingID, -1); 最后: mouse_x = this.lastPickingCoords.x; mouse_y = this.lastPickingCoords.y; var pixels = n

你好,我花了很多时间尝试在WebGL中进行简单的挑选。我在绘制每个对象之前使用:

if(Window.stencilEnabled)
                    gl.stencilFunc(gl.ALWAYS, mesh.pickingID, -1);
最后:

        mouse_x = this.lastPickingCoords.x;
        mouse_y = this.lastPickingCoords.y;

        var pixels = new Uint8Array(4);
        if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
            gl.readPixels(mouse_x, mouse_y, 1, 1, gl.STENCIL_INDEX, gl.UNSIGNED_BYTE, pixels);
        }else{
            console.log("Framebuffer error.");
        }
        oID = -1 + pixels[0];
        console.log("Picking object: " + oID + " at " + mouse_x + ":" + mouse_y);       

        if(this.mapArray[oID] != undefined){
            console.log("Object exists!");
            console.log(this.mapArray[oID]);
        }else{
            console.log("Object not found");
        }

        this.lastPickingCoords.x = 0;   
        this.lastPickingCoords.y = 0;

但从错误“WebGL:INVALID_ENUM:readPixels:INVALID format”看来,不允许读取模具缓冲区。。。是否有任何解决办法,扩展?如何在不编写拾取着色器的情况下以其他方式执行此操作?谢谢。

也许可以试试
gl.STENCIL\u INDEX8
?(注8)。很遗憾webGL不支持rendermode GL\u SELECT。。。也看到了,运气不好。gl.readPixels(鼠标x,鼠标y,1,1,gl.STENCIL_INDEX8,gl.UNSIGNED_BYTE,pixels)VM8709:2 WebGL:INVALID_ENUM:readPixels:INVALID formatAh,在那个问题中我链接了我看到了这个(改编):
gl.readPixels(鼠标x,鼠标y,1,1,gl.RGBA,gl.UNSIGNED_BYTE,pixels)但这只返回颜色信息,为此我必须为每种对象编写另一个着色器。无论如何我都得做。在webgl中似乎无法读取模具。无论如何,谢谢你。:)右-我看到的所有解决方案(解决方法)都对对象id使用颜色编码。我认为模具缓冲区仅用于将渲染限制在鼠标指针坐标周围的一个小区域。不客气!