The correct sequence when creating multiple textures with GL_TEXTURE_EXTERNAL_OES

Hi All,

I made a NV12 textures, one is Y texture and the other is UV texture.

This is my problem code snippet:

///
glGenTextures(2, texid);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texid[0]);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texid[1]);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

/* Y plane texture Part */
img_y = eglCreateImageKHR(m_EGLDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr_y);
if (!img_y)
        printf( "eglCreateImageKHR() failed (error 0x%x)\n", eglGetError() );

glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)img_y);

eglDestroyImageKHR(m_EGLDisplay, img_y);

/* UV plane texture Part */
img_uv = eglCreateImageKHR(m_EGLDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr_uv);
if (!img_uv)
        printf( "eglCreateImageKHR() failed (error 0x%x)\n", eglGetError() );

glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)img_uv);

eglDestroyImageKHR(m_EGLDisplay, img_uv);
///

The rendering result shown only UV texture, there was no Y texture.

So I changed the sequence:

///
glGenTextures(2, texid);

/* Y plane texture Part */
img_y = eglCreateImageKHR(m_EGLDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr_y);
if (!img_y)
        printf( "eglCreateImageKHR() failed (error 0x%x)\n", eglGetError() );

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texid[0]);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)img_y);

eglDestroyImageKHR(m_EGLDisplay, img_y);

/* UV plane texture Part */
img_uv = eglCreateImageKHR(m_EGLDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr_uv);
if (!img_uv)
        printf( "eglCreateImageKHR() failed (error 0x%x)\n", eglGetError() );

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texid[1]);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)img_uv);

eglDestroyImageKHR(m_EGLDisplay, img_uv);
///

The result was expected rendering using Y and UV textures.
So I think,
Problem sequence:

- glGenTextures(), glBindTexture() // two textures
- eglCreateImageKHR() // Make a Y texture
- eglCreateImageKHR() // Make an UV texture
- glEGLImageTargetTexture2DOES() // Y
- glEGLImageTargetTexture2DOES() // UV
- eglDestroyImageKHR() // Y
- eglDestroyImageKHR() // UV
=> only UV texture uploaded to GPU. The Y texture was disappeared.

Correct sequence:
- glGenTextures() // two textures
- eglCreateImageKHR() // Make a Y texture
- glBindTexture()
- glEGLImageTargetTexture2DOES()
- eglDestroyImageKHR()
- eglCreateImageKHR() // Make an UV texture
- glBindTexture()
- glEGLImageTargetTexture2DOES()
- eglDestroyImageKHR()
=> Both Y and UV textures uploaded to GPU

Is my assumption correct? I would like to know if there are any restrictions.

Thanks.

I’ve found the root cause.
The glBindTexture() API affects only current bound texture. The problem sequence texture-1 was bounded so the texture-0(Y) was disappeared.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.