Add IDhApiRenderProxy for getting/setting framebuffers and textures

This commit is contained in:
James Seibel
2023-10-13 19:58:03 -05:00
parent c724c6211e
commit 4c2c89de57
2 changed files with 84 additions and 2 deletions
@@ -25,7 +25,7 @@ import com.seibel.distanthorizons.api.objects.DhApiResult;
* Used to interact with Distant Horizons' rendering system.
*
* @author James Seibel
* @version 2023-2-8
* @version 2023-10-13
* @since API 1.0.0
*/
public interface IDhApiRenderProxy
@@ -45,4 +45,34 @@ public interface IDhApiRenderProxy
*/
DhApiResult<Boolean> clearRenderDataCache();
/**
* Returns the name of Distant Horizons' FrameBuffer. <br>
* Will return {@link DhApiResult#success} = false and {@link DhApiResult#payload} = -1 if the FrameBuffer hasn't been created yet.
*/
DhApiResult<Integer> getDhFrameBufferId();
/**
* Sets the FrameBuffer name that Distant Horizons will draw to after it finishes generating a frame texture. <br>
* Setting this to -1 will cause Distant Horizons to use Minecraft's FrameBuffer. <br><br>
*
* Will return {@link DhApiResult#success} = false given name isn't a valid FrameBuffer.
*/
DhApiResult<Void> setTargetFrameBufferId(int frameBufferId);
/**
* Returns the FrameBuffer name that Distant Horizons will draw to after it finishes generating a frame texture. <br>
* By default this will be Minecraft's FrameBuffer.
*/
DhApiResult<Integer> getTargetFrameBufferId();
/**
* Returns the name of Distant Horizons' depth texture. <br>
* Will return {@link DhApiResult#success} = false and {@link DhApiResult#payload} = -1 if the texture hasn't been created yet.
*/
DhApiResult<Integer> getDhDepthTextureId();
/**
* Returns the name of Distant Horizons' color texture. <br>
* Will return {@link DhApiResult#success} = false and {@link DhApiResult#payload} = -1 if the texture hasn't been created yet.
*/
DhApiResult<Integer> getDhColorTextureId();
}
@@ -22,9 +22,13 @@ package com.seibel.distanthorizons.core.render;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderProxy;
import com.seibel.distanthorizons.api.objects.DhApiResult;
import com.seibel.distanthorizons.core.api.internal.SharedApi;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.level.IDhClientLevel;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
import com.seibel.distanthorizons.core.world.AbstractDhWorld;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import org.lwjgl.opengl.GL32;
/**
* Used to interact with Distant Horizons' rendering systems.
@@ -34,14 +38,26 @@ import com.seibel.distanthorizons.core.world.AbstractDhWorld;
*/
public class DhApiRenderProxy implements IDhApiRenderProxy
{
public static DhApiRenderProxy INSTANCE = new DhApiRenderProxy();
public static final DhApiRenderProxy INSTANCE = new DhApiRenderProxy();
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
public int targetFrameBufferOverride = -1;
//=============//
// constructor //
//=============//
private DhApiRenderProxy() { }
//=========//
// methods //
//=========//
public DhApiResult<Boolean> clearRenderDataCache()
{
// make sure this is a valid time to run the method
@@ -66,4 +82,40 @@ public class DhApiRenderProxy implements IDhApiRenderProxy
}
@Override
public DhApiResult<Integer> getDhFrameBufferId()
{
int activeFrameBuffer = LodRenderer.getActiveFramebufferId();
return (activeFrameBuffer == -1) ? DhApiResult.createFail("DH's FrameBuffer hasn't been created and/or bound yet.", -1) : DhApiResult.createSuccess(activeFrameBuffer);
}
@Override
public DhApiResult<Void> setTargetFrameBufferId(int frameBufferId)
{
if (frameBufferId != -1 && !GL32.glIsFramebuffer(frameBufferId))
{
return DhApiResult.createFail("FrameBufferID ["+frameBufferId+"] isn't a valid FrameBuffer ID.");
}
this.targetFrameBufferOverride = frameBufferId;
return DhApiResult.createSuccess();
}
@Override
public DhApiResult<Integer> getTargetFrameBufferId() { return (this.targetFrameBufferOverride == -1) ? DhApiResult.createSuccess("Default MC FrameBuffer in use.", MC_RENDER.getTargetFrameBuffer()) : DhApiResult.createSuccess("FrameBuffer override active.", this.targetFrameBufferOverride); }
@Override
public DhApiResult<Integer> getDhDepthTextureId()
{
int activeTexture = LodRenderer.getActiveDepthTextureId();
return (activeTexture == -1) ? DhApiResult.createFail("DH's depth texture hasn't been created and/or bound yet.", -1) : DhApiResult.createSuccess(activeTexture);
}
@Override
public DhApiResult<Integer> getDhColorTextureId()
{
int activeTexture = LodRenderer.getActiveColorTextureId();
return (activeTexture == -1) ? DhApiResult.createFail("DH's color texture hasn't been created and/or bound yet.", -1) : DhApiResult.createSuccess(activeTexture);
}
}