Give each GL drawable its own GLSM context (#2142)

This commit is contained in:
Jason Mitchell authored and GitHub committed 2026-09-26 22:31:07 -07:00
1 parent 7c28a69bfe
commit a8c29fa3f9
67 files changed
+1817 -1009

No files matched your search

@@ -7,6 +7,7 @@ import com.gtnewhorizon.gtnhlib.util.font.FontRendering;
import com.gtnewhorizon.gtnhlib.util.font.GlyphReplacements;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.config.FontConfig;
import com.gtnewhorizons.angelica.glsm.GLContextState;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.glsm.StateSet;
import com.gtnewhorizons.angelica.glsm.ffp.FFPVertexLighting;
@@ -159,7 +160,6 @@ public class BatchingFontRenderer {
// OpenGL objects (static, can be used between multiple BatchingFontRenderer)
private static int fontVAO = 0;
private static int vbo;
private static IndexBuffer ebo;
private static int lightmapSamplerProgram;
@@ -169,6 +169,7 @@ public class BatchingFontRenderer {
private static boolean streamingInitialized;
private static int pendingBuffer;
private static int pendingBase;
private static GLContextState vaoContext;
private static int vaoBuffer = -1;
private static int vaoBase = -1;
@@ -219,7 +220,8 @@ public class BatchingFontRenderer {
float v = 0.0f;
int texture = 0;
if (active) {
scratchLightmapUv.set(GLSMConfig.lastBrightnessX, GLSMConfig.lastBrightnessY, 0.0f, 1.0f).mul(GLStateManager.getTextures().getTextureUnitMatrix(LIGHTMAP_TEX_UNIT));
final GLContextState glCtx = GLStateManager.ctx();
scratchLightmapUv.set(glCtx.lastBrightnessX, glCtx.lastBrightnessY, 0.0f, 1.0f).mul(GLStateManager.getTextures().getTextureUnitMatrix(LIGHTMAP_TEX_UNIT));
u = scratchLightmapUv.x;
v = scratchLightmapUv.y;
texture = unitBinding;
@@ -620,11 +622,16 @@ public class BatchingFontRenderer {
return;
}
GLStateManager.beginForeignDraw();
final boolean locked = GLStateManager.acquireDrawLock();
try {
flushDeferredTextInner();
GLStateManager.beginForeignDraw();
try {
flushDeferredTextInner();
} finally {
GLStateManager.endForeignDraw();
}
} finally {
GLStateManager.endForeignDraw();
if (locked) GLStateManager.releaseDrawLock();
}
}
@@ -859,8 +866,15 @@ public class BatchingFontRenderer {
lightmapSamplerProgram = fontShaderId;
}
final GLContextState glCtx = GLStateManager.ctx();
if (vaoContext != glCtx) {
vaoContext = glCtx;
vaoBuffer = -1;
}
int fontVAO = glCtx.fontVao;
if (fontVAO == 0) {
fontVAO = GLStateManager.glGenVertexArrays();
glCtx.fontVao = fontVAO;
GLStateManager.glBindVertexArray(fontVAO);
ebo.bind();
@@ -308,9 +308,9 @@ public final class WeatherRenderer {
WeatherInstancedAttribs.pointInstanceAttribs((long) first * WeatherInstancedAttribs.STRIDE);
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
VAOManager.setCurrentVertexFlags(WeatherQuadMesh.VERTEX_FLAGS);
if (deferred == null) GLStateManager.ffpInstancing = Instancing.WEATHER;
if (deferred == null) GLStateManager.setFfpInstancing(Instancing.WEATHER);
GLStateManager.glDrawArraysInstanced(GL11.GL_TRIANGLE_FAN, 0, WeatherQuadMesh.VERTEX_COUNT, count);
GLStateManager.ffpInstancing = Instancing.NONE;
GLStateManager.setFfpInstancing(Instancing.NONE);
GLStateManager.glBindVertexArray(0);
if (deferred != null) deferred.rebindCurrentPass();
@@ -333,7 +333,7 @@ public final class PlayerReflectionCapture {
GLStateManager.glColorMask(false, false, false, false);
GLStateManager.glDepthMask(false);
try {
QuadConverter.drawQuadsAsTriangles(0, VERTEX_COUNT);
QuadConverter.drawQuadsAsTriangles(GLStateManager.ctx(), 0, VERTEX_COUNT);
} finally {
GLStateManager.popStateTo(maskStateDepth);
GLStateManager.setModelViewMatrix(savedModelView);
@@ -345,11 +345,11 @@ public final class ParticleInstancer {
ParticleInstancedAttribs.pointInstanceAttribs(base);
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
try {
if (ffp) GLStateManager.ffpInstancing = Instancing.PARTICLE;
if (ffp) GLStateManager.setFfpInstancing(Instancing.PARTICLE);
GLStateManager.glDrawArraysInstanced(GL11.GL_QUADS, 0, ParticleQuadMesh.VERTEX_COUNT, count);
draws++;
} finally {
GLStateManager.ffpInstancing = Instancing.NONE;
GLStateManager.setFfpInstancing(Instancing.NONE);
GLStateManager.glBindVertexArray(0);
}
}
@@ -112,7 +112,7 @@ final class InstancedTemplateRenderer {
int draws = 0;
long recordOffset = ringBase;
neutralizeExtendedAttribs();
GLStateManager.ffpInstancing = Instancing.TEMPLATE;
GLStateManager.setFfpInstancing(Instancing.TEMPLATE);
for (int b = 0, n = liveBuckets.size(); b < n; b++) {
final Bucket bucket = liveBuckets.get(b);
final TemplateMesh mesh = bucket.mesh;
@@ -130,7 +130,7 @@ final class InstancedTemplateRenderer {
bucket.mesh = null;
bucketPool.add(bucket);
}
GLStateManager.ffpInstancing = Instancing.NONE;
GLStateManager.setFfpInstancing(Instancing.NONE);
GLStateManager.glBindVertexArray(0);
liveBuckets.clear();
return draws;
@@ -142,7 +142,7 @@ final class InstancedTemplateRenderer {
int redrawTemplates(TexRun base, int colorABGR) {
long recordOffset = base.uploadOffset;
neutralizeExtendedAttribs();
GLStateManager.ffpInstancing = Instancing.TEMPLATE;
GLStateManager.setFfpInstancing(Instancing.TEMPLATE);
for (int b = 0, n = base.uploadMeshes.size(); b < n; b++) {
final TemplateMesh mesh = (TemplateMesh) base.uploadMeshes.get(b);
final int count = base.uploadCounts.getInt(b);
@@ -154,7 +154,7 @@ final class InstancedTemplateRenderer {
GLStateManager.glEnableVertexAttribArray(InstancedAttribs.LOC_COLOR);
recordOffset += (long) count * InstancedAttribs.STRIDE;
}
GLStateManager.ffpInstancing = Instancing.NONE;
GLStateManager.setFfpInstancing(Instancing.NONE);
GLStateManager.glBindVertexArray(0);
return base.uploadMeshes.size();
}
@@ -195,9 +195,9 @@ final class InstancedTemplateRenderer {
bindRingTo(UnitCubeMesh.vao(), UnitCubeMesh.VERTEX_FLAGS);
CubeInstancedAttribs.pointInstanceAttribs(ringBase);
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GLStateManager.ffpInstancing = Instancing.CUBE;
GLStateManager.setFfpInstancing(Instancing.CUBE);
GLStateManager.glDrawArraysInstanced(GL11.GL_QUADS, 0, UnitCubeMesh.VERTEX_COUNT, run.instances);
GLStateManager.ffpInstancing = Instancing.NONE;
GLStateManager.setFfpInstancing(Instancing.NONE);
GLStateManager.glBindVertexArray(0);
return ringBase;
}
@@ -220,9 +220,9 @@ final class InstancedTemplateRenderer {
CubeInstancedAttribs.pointInstanceAttribs(offset);
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
setConstantColor(colorABGR);
GLStateManager.ffpInstancing = Instancing.CUBE;
GLStateManager.setFfpInstancing(Instancing.CUBE);
GLStateManager.glDrawArraysInstanced(GL11.GL_QUADS, 0, UnitCubeMesh.VERTEX_COUNT, instances);
GLStateManager.ffpInstancing = Instancing.NONE;
GLStateManager.setFfpInstancing(Instancing.NONE);
GLStateManager.glEnableVertexAttribArray(InstancedAttribs.LOC_COLOR);
GLStateManager.glBindVertexArray(0);
}