'safe to replace EglImage with new EglImage using glEGLImageTargetTexture2DOES?

The code I'm working with destroys and then creates a new texture before setting a new eglImage as the texture's target:

    glDeleteTextures(1, &m_tex);
    eglDestroyImageKHR(display, m_eglImage);

    glGenTextures(1, &m_tex);
    glBindTexture(GL_TEXTURE_2D, m_tex);

    m_eglImage = newEglImage;
    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage);

However there is an issue with a shared egl context referring to the original texture or an fbo with the original texture attached (haven't found the culprit yet).

I'd like to confirm if it's valid/correct to leave the original texture and simply set a new EglImage target, replacing an existing one? like this:

    eglDestroyImageKHR(display, m_eglImage);
    m_eglImage = newEglImage;

    glBindTexture(GL_TEXTURE_2D, m_tex);
    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage);

I've tried this and it works on my platform and works around the issue, but I'm looking for assurances that it is valid and will work on all platforms, not just a fluke of my gpu driver?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source