mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-25 22:54:28 +00:00
Split up GLStateManager and add public GLState API (#2305)
This commit is contained in:
1 parent
9bbb0537ee
commit
91e67f8d5d
494 files changed
+22968
-20523
No files matched your search
@@ -14,6 +14,15 @@ import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix3f;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4fc;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMBlend;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMCurrentAttribs;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMDepthStencilAlpha;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMEnable;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMFog;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMFramebuffer;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMPrograms;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMRasterizer;
|
||||
import com.gtnewhorizons.angelica.glsm.GLSMTextures;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import com.gtnewhorizons.angelica.glsm.ffp.Instancing;
|
||||
@@ -258,10 +267,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
final long _t0 = System.nanoTime();
|
||||
long _tLast = _t0;
|
||||
|
||||
final int entryTextureUnit = GLStateManager.getActiveTextureUnit();
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE2);
|
||||
final int entryTextureUnit = GLSMTextures.getActiveTextureUnit();
|
||||
GLSMTextures.glActiveTexture(GL13.GL_TEXTURE2);
|
||||
customTextureManager = new CustomTextureManager(programs.getPackDirectives(), programs.getPack().getCustomTextureDataMap(), programs.getPack().getIrisCustomTextureDataMap(), programs.getPack().getCustomNoiseTexture());
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + entryTextureUnit);
|
||||
GLSMTextures.glActiveTexture(GL13.GL_TEXTURE0 + entryTextureUnit);
|
||||
|
||||
final Map<Integer, CompletableFuture<Map<PatchShaderType, String>>> prepareTransformFutures =
|
||||
submitCompositeTransforms(programs.getPrepare(), TextureStage.PREPARE, programs.getPackDirectives().getTextureMap());
|
||||
@@ -392,7 +401,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
updatePbrSamplers(TextureFormatLoader.getFormat(), SodiumGameOptions.resolvedAnisotropicFiltering());
|
||||
|
||||
// Don't clobber anything in texture unit 0. It probably won't cause issues, but we're just being cautious here.
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE2);
|
||||
GLSMTextures.glActiveTexture(GL13.GL_TEXTURE2);
|
||||
|
||||
whitePixel = new NativeImageBackedSingleColorTexture(255, 255, 255, 255);
|
||||
|
||||
@@ -428,7 +437,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
this.ssboHolder = null;
|
||||
}
|
||||
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GLSMTextures.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
|
||||
BufferFlipper flipper = new BufferFlipper();
|
||||
|
||||
@@ -1125,14 +1134,14 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
GLSMHooks.resolvePendingProgram();
|
||||
final Pass pass = this.current;
|
||||
if (pass == null) {
|
||||
if (GLStateManager.getActiveProgram() == 0) {
|
||||
if (GLSMPrograms.getActiveProgram() == 0) {
|
||||
matchPass();
|
||||
}
|
||||
return;
|
||||
}
|
||||
final Program program = pass.getProgram();
|
||||
final GlFramebuffer expected = isBeforeTranslucent ? pass.framebufferBeforeTranslucents : pass.framebufferAfterTranslucents;
|
||||
if (program != null && GLStateManager.getActiveProgram() == program.getProgramId() && GLStateManager.getDrawFramebuffer() == expected.getId()) {
|
||||
if (program != null && GLSMPrograms.getActiveProgram() == program.getProgramId() && GLSMFramebuffer.getDrawFramebuffer() == expected.getId()) {
|
||||
return;
|
||||
}
|
||||
pass.use();
|
||||
@@ -1476,10 +1485,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
|
||||
if (shadowViewport) {
|
||||
GLStateManager.glViewport(0, 0, shadowMapResolution, shadowMapResolution);
|
||||
GLSMRasterizer.glViewport(0, 0, shadowMapResolution, shadowMapResolution);
|
||||
} else {
|
||||
final Framebuffer main = Minecraft.getMinecraft().getFramebuffer();
|
||||
GLStateManager.glViewport(0, 0, main.framebufferWidth, main.framebufferHeight);
|
||||
GLSMRasterizer.glViewport(0, 0, main.framebufferWidth, main.framebufferHeight);
|
||||
}
|
||||
|
||||
// Apply state overrides before program.use() so that uniforms (e.g. iris_currentAlphaTest)
|
||||
@@ -1627,7 +1636,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
|
||||
private boolean usesImage(@Nullable Program program, String image) {
|
||||
return program != null && (GLStateManager.glGetUniformLocation(program.getProgramId(), image) != -1 || vertexWriteReplays.writesImage(program, image));
|
||||
return program != null && (GLSMPrograms.glGetUniformLocation(program.getProgramId(), image) != -1 || vertexWriteReplays.writesImage(program, image));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1673,7 +1682,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
vertexWriteReplays.attach(name, program, transformed, (samplers, images) -> wireGbufferResources(samplers, images, availability, shadow));
|
||||
this.customUniforms.mapholderToPass(builder, program);
|
||||
final int id = program.getProgramId();
|
||||
return new WideLineProgram(program, GLStateManager.glGetUniformLocation(id, "iris_LineWidth"), GLStateManager.glGetUniformLocation(id, "iris_ScreenSize"));
|
||||
return new WideLineProgram(program, GLSMPrograms.glGetUniformLocation(id, "iris_LineWidth"), GLSMPrograms.glGetUniformLocation(id, "iris_ScreenSize"));
|
||||
} catch (Exception e) {
|
||||
Iris.logger.warn("Wide line program link failed for {}; lines there stay 1 px wide", sourceName, e);
|
||||
return null;
|
||||
@@ -1690,7 +1699,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
GLSMHooks.resolvePendingProgram();
|
||||
final Pass pass = current;
|
||||
if (pass == null || pass.getProgram() == null || activeInstancing != Instancing.NONE
|
||||
|| GLStateManager.getActiveProgram() != pass.getProgram().getProgramId()) {
|
||||
|| GLSMPrograms.getActiveProgram() != pass.getProgram().getProgramId()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1712,8 +1721,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
if (wide != null) {
|
||||
wide.program().use();
|
||||
this.customUniforms.push(wide.program());
|
||||
final var viewport = GLStateManager.getViewportState();
|
||||
RenderSystem.uniform1f(wide.lineWidthLocation(), GLStateManager.getLineState().getWidth());
|
||||
final var viewport = GLSMRasterizer.getViewportState();
|
||||
RenderSystem.uniform1f(wide.lineWidthLocation(), GLSMRasterizer.getLineState().getWidth());
|
||||
RenderSystem.uniform2f(wide.screenSizeLocation(), viewport.width, viewport.height);
|
||||
}
|
||||
return true;
|
||||
@@ -1746,9 +1755,9 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
DepthColorStorage.unlockDepthColor();
|
||||
BlendModeOverride.restore();
|
||||
AlphaTestOverride.restore();
|
||||
GLStateManager.enableAlphaTest();
|
||||
GLStateManager.glAlphaFunc(GL11.GL_GREATER, 0.1f);
|
||||
GLStateManager.glDepthFunc(GL11.GL_LEQUAL);
|
||||
GLSMDepthStencilAlpha.enableAlphaTest();
|
||||
GLSMDepthStencilAlpha.glAlphaFunc(GL11.GL_GREATER, 0.1f);
|
||||
GLSMDepthStencilAlpha.glDepthFunc(GL11.GL_LEQUAL);
|
||||
GLStateManager.incrementFragmentGeneration();
|
||||
|
||||
FullScreenQuadRenderer.clearLocCache();
|
||||
@@ -1867,7 +1876,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
private void prepareRenderTargets() {
|
||||
parityState.onFrameStart();
|
||||
// Make sure we're using texture unit 0 for this.
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GLSMTextures.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
|
||||
if (shadowRenderTargets != null) {
|
||||
profiler.startSection("iris_shadow_clear");
|
||||
@@ -1881,7 +1890,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
} else {
|
||||
// Clear depth first, regardless of any color clearing.
|
||||
shadowRenderTargets.getDepthSourceFb().bind();
|
||||
GLStateManager.glClear(GL11.GL_DEPTH_BUFFER_BIT);
|
||||
GLSMFramebuffer.glClear(GL11.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
ImmutableList<ClearPass> passes;
|
||||
|
||||
@@ -1968,7 +1977,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
passes = clearPasses;
|
||||
}
|
||||
|
||||
final Vector3d fogColor3 = GLStateManager.getFogColor();
|
||||
final Vector3d fogColor3 = GLSMFog.getFogColor();
|
||||
|
||||
// NB: The alpha value must be 1.0 here, or else you will get a bunch of bugs. Sildur's Vibrant Shaders
|
||||
// will give you pink reflections and other weirdness if this is zero.
|
||||
@@ -2034,8 +2043,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
private void bindVoxelizationMatrixUniforms() {
|
||||
if (shadowVoxelizationCompute == null) return;
|
||||
final int id = shadowVoxelizationCompute.getProgramId();
|
||||
final int modelView = GLStateManager.glGetUniformLocation(id, "iris_ModelViewMatrix");
|
||||
final int normal = GLStateManager.glGetUniformLocation(id, "iris_NormalMatrix");
|
||||
final int modelView = GLSMPrograms.glGetUniformLocation(id, "iris_ModelViewMatrix");
|
||||
final int normal = GLSMPrograms.glGetUniformLocation(id, "iris_NormalMatrix");
|
||||
this.voxelizationModelView = modelView >= 0 ? new GlUniformMatrix4f(modelView) : null;
|
||||
this.voxelizationNormalMatrix = normal >= 0 ? new GlUniformMatrix3f(normal) : null;
|
||||
}
|
||||
@@ -2214,8 +2223,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
profiler.endSection();
|
||||
}
|
||||
|
||||
GLStateManager.enableBlend();
|
||||
GLStateManager.enableAlphaTest();
|
||||
GLSMBlend.enableBlend();
|
||||
GLSMDepthStencilAlpha.enableAlphaTest();
|
||||
|
||||
// note: we are careful not to touch the lightmap texture unit or overlay color texture unit here,
|
||||
// so we don't need to do anything to restore them if needed.
|
||||
@@ -2374,16 +2383,16 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
|
||||
if (true/*skyType == DimensionSpecialEffects.SkyType.NORMAL*/) {
|
||||
profiler.startSection("iris_horizon");
|
||||
GLStateManager.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GLStateManager.glDepthMask(false);
|
||||
GLSMEnable.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GLSMDepthStencilAlpha.glDepthMask(false);
|
||||
|
||||
final Vector3d fogColor = GLStateManager.getFogColor();
|
||||
GLStateManager.glColor4f((float) fogColor.x, (float) fogColor.y, (float) fogColor.z, 1.0F);
|
||||
final Vector3d fogColor = GLSMFog.getFogColor();
|
||||
GLSMCurrentAttribs.glColor4f((float) fogColor.x, (float) fogColor.y, (float) fogColor.z, 1.0F);
|
||||
|
||||
horizonRenderer.renderHorizon(RenderingState.INSTANCE.getModelViewBuffer());
|
||||
|
||||
GLStateManager.glDepthMask(true);
|
||||
GLStateManager.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GLSMDepthStencilAlpha.glDepthMask(true);
|
||||
GLSMEnable.glEnable(GL11.GL_TEXTURE_2D);
|
||||
profiler.endSection();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user