1
\$\begingroup\$

After context lost, I have to rebind all my textures. I want to it the correct way, so I check each handle for availability. It's done by calling unloadFromVram(), and then loadToVram()

first unload:

public final void unloadFromVram()
{
    GLContextState.forgetTexture(handle); // invalidate cache

    if (glIsTexture(handle)) // check whether handle is still a texture instance.
    {
        glDeleteTexture(handle); // delete handle if it is a texture instance.
        handle = GL_NONE;
    }
}

upload again:

public final void loadToVram()
{
    handle = glGenTexture();

    GLESContextState.activateTextureInSlot(0, handle); // GL.glActiveTexture(glSlot) and GL.glBindTexture(GL.GL_TEXTURE_2D, texture);

    if (owner.isCompressed())
    {
        glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, textureData.getWidth(), textureData.getHeight(), 0, textureData.bytes);
    }
    else
    {
        glTexImage2D(GL_TEXTURE_2D, 0, format,textureData.getWidth(), textureData.getHeight(), 0, format, type, textureData.bytes);
    }
}

What have I investigated:

  1. After doing so, most of my textures appears black or have invalid content (perhaps from other textures, or content which was bound to this handle before suspend).
  2. If glIsTexture(handle) fails, and the handle has not to be deleted - the texture behaves just fine.
  3. If I comment the whole check and deletion in unloadFromVram() - everything works just fine.

I suppose, if I won't delete bound handle - it will cause a memory leak, due to texture's data is still in memory, so I have to avoid it. What do I have to do with this?

\$\endgroup\$
  • \$\begingroup\$ glDeleteTexture is not valid OpenGL ES which suggests that the code you've posted is not your actual code. Can you please update this question with the code you're actually using. \$\endgroup\$ – Maximus Minimus Aug 5 '16 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.