DH API does not notify of texture change

Binding textures returned by the DH API as usual* results in broken code.
(usual* = how you'ld usually do it in MC modding)
DhApiResult<Integer> depthId = DhApi.Delayed.renderProxy.getDhDepthTextureId();
if(depthId.success) {
    RenderSystem.activeTexture(GL_TEXTURE6);
    RenderSystem.bindTexture(depthId.payload);
}

The issue here is that DH doesn't use Minecraft's built-in GL State manager RenderSystem (yarn mappings). The problem only becomes apparent when DH reinitializes the LODRenderer.
This action will:
  1. glDeleteTextures the old texture
  2. glGenTextures a new texture
  3. On some systems the old and new texture will have the same id (valid by OpenGL Spec)
  4. Call RenderSystem.bindTexture with the same texture id.
  5. RenderSystemwill not call glBindTexture because it thinks the same old texture is still bound.
  6. A deleted texture is now bound to GL_TEXTURE6
I hope my description was clear enough.

The DH API does not provide a way to notice this texture change.

Probably the only way to circumvent this issue is on my side is to do this:
RenderSystem.bindTexture(depthId.payload);
GL11.glBindTexture(GL_TEXTURE6, depthId.payload);

This will keep MC's state management and the "real" state "in sync", but results in wasted performance and is generally not a nice solution,
Was this page helpful?