首页 > 解决方案 > 使用 EGL 和 openGL 渲染到大型 ImageReader 表面,无法渲染出 GL_MAX_VIEWPORT_DIMS 范围

问题描述

我正在尝试在 Imagereader 的表面上使用 OpenGL ES 绘制一些东西。我为它创建了 EGL 上下文和表面。一切正常,当图像阅读器尺寸小于 GL_MAX_VIEWPORT_DIMS(我的设备上为 8192)时。我可以从它那里得到一张好照片。

但是当尺寸大于 8192 时,比如 8224,输出图像仍然留下一些填充无法绘制。这是输出图像。

即使我尝试使用 glViewport(0, 32, width, 8192),渲染结果也会向上偏移,但仍然不能超过 padding(8192~8224)。但是 glclear 命令可以使背景清晰到目标颜色(在我的例子中,它是红色)。

有没有办法在表面的填充部分绘制?

这是我的代码:


                mImageReader = ImageReader.newInstance(
                        size.getWidth(),
                        size.getHeight(),
                        PixelFormat.RGBA_8888,
//                        PixelFormat.RGB_888,
//                        ImageFormat.JPEG,
                        1);
//                mReaderSurface = new EglWindowSurface(core, mImageReader.getSurface(), null);
                mReaderSurface = core.createWindowSurface2(mImageReader.getSurface());


    public EGLSurface createWindowSurface2(Object surface) {
        if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture)) {
            throw new RuntimeException("invalid surface: " + surface);
        }

        // Create a window surface, and attach it to the Surface we received.
        int[] surfaceAttribs = {
                EGL14.EGL_NONE
        };

        int[] attribList = {
                EGL14.EGL_RED_SIZE, 8,
                EGL14.EGL_GREEN_SIZE, 8,
                EGL14.EGL_BLUE_SIZE, 8,
                EGL14.EGL_ALPHA_SIZE, 8,
                EGL14.EGL_DEPTH_SIZE, 16,
                EGL14.EGL_NONE
        };
        EGLConfig[] configs = new EGLConfig[1];
        int[] numConfigs = new int[1];
        if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
                numConfigs, 0)) {
            Log.e(TAG, "createWindowSurface2: ");
            return null;
        }

        EGLSurface eglSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, configs[0], surface,
                surfaceAttribs, 0);
        checkEglError("eglCreateWindowSurface");
        if (eglSurface == null) {
            throw new RuntimeException("surface was null");
        }
        return eglSurface;
    }

从 imagereader 表面读取的输出图片

标签: androidopengl-eseglimage-reader

解决方案


推荐阅读