如何在Android中使用GLES11Ext.glEGLImageTargetTexture2DOES或者说EGLImage直接纹理,0x502错误?

时间:2016-11-04 05:18:59

标签: android opengl-es opengl-es-2.0

我想在Android中使用glEGLImageTargetTexture2DOES替换glTexImage2D。我已经阅读了一些有关如何使用EGLImage或在Android中直接描述纹理的信息。
我找到this API in SDK。当我在演示中尝试它时遇到了一些问题,当我使用这种方法时,我得到了一个0x502错误。 我在活动中使用了一个简单的GLSurfaceView,并在创建纹理时尝试在onSurfaceCreated中加载位图.BTW,我使用google的grafika的一些代码。
这是初始代码。

GLSurfaceView glSV = (GLSurfaceView) findViewById(R.id.gl_sv);
glSV.setEGLContextClientVersion(2);
DTSurfaceRender dtSurfaceRender = new DTSurfaceRender();
glSV.setRenderer(dtSurfaceRender);
glSV.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

这是渲染代码

class DTSurfaceRender implements GLSurfaceView.Renderer {

    private FullFrameRect mFullScreen;

    private final float[] mSTMatrix = new float[16];
    private int mTextureId;

    public DTSurfaceRender() {
        Matrix.setIdentityM(mSTMatrix, 0);
    }

    @Override
    public void onDrawFrame(GL10 gl10) {
        mFullScreen.drawFrame(mTextureId, mSTMatrix);
    }

    @Override
    public void onSurfaceChanged(GL10 gl10, int i, int i1) {

    }

    @Override
    public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
        mFullScreen = new FullFrameRect(new Texture2dProgram(
                Texture2dProgram.ProgramType.TEXTURE_EXT));
        ByteBuffer data = ByteBuffer.allocate(mWidth * mHeight * 4);
        patternPixelSource(data, 1);
        mTextureId = mFullScreen.createImageTexture(data, mWidth, mHeight, GLES20.GL_RGBA);
    }
}

这是 createImageTexture 代码

public int createImageTexture(ByteBuffer data, int width, int height, int format) {
    int[] textureHandles = new int[1];
    int textureHandle;

    GLES20.glGenTextures(1, textureHandles, 0);
    textureHandle = textureHandles[0];
    GlUtil.checkGlError("glGenTextures");

    GLES20.glBindTexture(mTextureTarget, textureHandle);

    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER,
            GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER,
            GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S,
            GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T,
            GLES20.GL_CLAMP_TO_EDGE);
    GlUtil.checkGlError("glTexParameter");
    GLES11Ext.glEGLImageTargetTexture2DOES(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, data);
    GlUtil.checkGlError("eglTargetTexture");

    return textureHandle;
}

事实上,关于纹理tartget类型,无论我使用TEXTURE_2D还是TEXTURE_EXT都是0x502错误。

0 个答案:

没有答案