Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ gradle-app.setting

# Mesa EGL/GLES DLLs for the (deferred) JMH GL benchmark harness; not committed.
celeritas-common/jmh-natives/
/.tools/
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,38 @@ public static boolean glIsEnabled(int cap) {
};
}

/**
* Whether the pname is an enable capability tracked by {@link #glIsEnabled}. Compatibility
* GL allows querying enable caps through glGetInteger/glGetFloat, but the core-profile
* backend rejects them; legacy mods (e.g. OreLib OpenGlState, issue #41) query caps this
* way, so the glGet* variants answer from tracked state instead of forwarding.
*/
private static boolean isEnableCap(int pname) {
return switch (pname) {
case GL11.GL_ALPHA_TEST, GL11.GL_AUTO_NORMAL, GL11.GL_BLEND, GL11.GL_COLOR_MATERIAL,
GL11.GL_COLOR_LOGIC_OP, GL11.GL_CULL_FACE, GL11.GL_DEPTH_TEST, GL11.GL_DITHER,
GL11.GL_FOG, GL11.GL_INDEX_LOGIC_OP, GL11.GL_LIGHTING, GL11.GL_LIGHT0,
GL11.GL_LIGHT1, GL11.GL_LIGHT2, GL11.GL_LIGHT3, GL11.GL_LIGHT4, GL11.GL_LIGHT5,
GL11.GL_LIGHT6, GL11.GL_LIGHT7, GL11.GL_LINE_SMOOTH, GL11.GL_LINE_STIPPLE,
GL11.GL_MAP1_COLOR_4, GL11.GL_MAP1_INDEX, GL11.GL_MAP1_NORMAL,
GL11.GL_MAP1_TEXTURE_COORD_1, GL11.GL_MAP1_TEXTURE_COORD_2,
GL11.GL_MAP1_TEXTURE_COORD_3, GL11.GL_MAP1_TEXTURE_COORD_4,
GL11.GL_MAP1_VERTEX_3, GL11.GL_MAP1_VERTEX_4, GL11.GL_MAP2_COLOR_4,
GL11.GL_MAP2_INDEX, GL11.GL_MAP2_NORMAL, GL11.GL_MAP2_TEXTURE_COORD_1,
GL11.GL_MAP2_TEXTURE_COORD_2, GL11.GL_MAP2_TEXTURE_COORD_3,
GL11.GL_MAP2_TEXTURE_COORD_4, GL11.GL_MAP2_VERTEX_3, GL11.GL_MAP2_VERTEX_4,
GL13.GL_MULTISAMPLE, GL11.GL_NORMALIZE, GL11.GL_POINT_SMOOTH,
GL11.GL_POLYGON_OFFSET_POINT, GL11.GL_POLYGON_OFFSET_LINE,
GL11.GL_POLYGON_OFFSET_FILL, GL11.GL_POLYGON_SMOOTH, GL11.GL_POLYGON_STIPPLE,
GL12.GL_RESCALE_NORMAL, GL13.GL_SAMPLE_ALPHA_TO_COVERAGE,
GL13.GL_SAMPLE_ALPHA_TO_ONE, GL13.GL_SAMPLE_COVERAGE, GL11.GL_SCISSOR_TEST,
GL11.GL_STENCIL_TEST, GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_2D,
GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_GEN_S, GL11.GL_TEXTURE_GEN_T,
GL11.GL_TEXTURE_GEN_R, GL11.GL_TEXTURE_GEN_Q -> true;
default -> false;
};
}

public static boolean glGetBoolean(int pname) {
if (shouldBypassCache()) {
return RENDER_BACKEND.getBoolean(pname);
Expand Down Expand Up @@ -1036,6 +1068,10 @@ public static int glGetInteger(int pname) {
return RENDER_BACKEND.getInteger(pname);
}

if (isEnableCap(pname)) {
return glIsEnabled(pname) ? GL11.GL_TRUE : GL11.GL_FALSE;
}

return switch (pname) {
case GL11.GL_ALPHA_TEST_FUNC -> alphaState.getFunction();
case GL11.GL_DEPTH_FUNC -> depthState.getFunc();
Expand All @@ -1061,6 +1097,11 @@ public static int glGetInteger(int pname) {
case GL14.GL_BLEND_EQUATION -> blendState.getEquationRgb();
case GL20.GL_BLEND_EQUATION_ALPHA -> blendState.getEquationAlpha();

// Legacy blend-factor aliases (GL_BLEND_SRC/GL_BLEND_DST) differ from the GL14 RGB
// tokens and are rejected by the core-profile backend; map to the RGB factors.
case GL11.GL_BLEND_SRC -> blendState.getSrcRgb();
case GL11.GL_BLEND_DST -> blendState.getDstRgb();

case GL11.GL_LOGIC_OP_MODE -> logicOpMode.getValue();
case GL11.GL_DRAW_BUFFER -> drawBuffer.getValue();

Expand Down Expand Up @@ -1211,6 +1252,10 @@ public static void glGetFloat(int pname, FloatBuffer params) {
}

public static float glGetFloat(int pname) {
if (isEnableCap(pname)) {
return glIsEnabled(pname) ? 1.0F : 0.0F;
}

return switch (pname) {
case GL11.GL_ALPHA_TEST_REF -> alphaState.getReference();
case GL11.GL_FOG_DENSITY -> fogState.getDensity();
Expand Down Expand Up @@ -2237,6 +2282,20 @@ public static void disableTexture() {
textures.getTextureUnitStates(textureUnit).disable();
}

/**
* Force-syncs a texture unit's GL_TEXTURE_2D enable state and notifies TEXTURE_UNIT_STATE
* listeners. For render paths that restore captured state (e.g. DeferredDrawBatcher) where
* setting the state directly would silently desync Iris pipeline input tracking (issue #41).
*/
public static void setTexture2DEnabled(int textureUnit, boolean enabled) {
final TextureUnitBooleanStateStack state = textures.getTextureUnitStates(textureUnit);
if (!shouldBypassCache() && state.isEnabled() == enabled) {
return;
}
postTextureUnitState(textureUnit, enabled);
state.setEnabled(enabled);
}

private static void postTextureUnitState(int textureUnit, boolean enabled) {
if (!GLSMHooks.TEXTURE_UNIT_STATE.hasListeners()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public final class GLSMDebug {
private static final Logger LOGGER = LogManager.getLogger("GLSMDebug");
private static final boolean ENABLE_VERBOSE_DRAW_LOGS = Boolean.getBoolean("actinium.glsm.verboseDrawLogs");
private static final boolean ENABLE_GL_DEBUG_SYS_PROP = Boolean.getBoolean("actinium.glDebug");
private static final long OPTION_REFRESH_NS = 500_000_000L;
private static final int STREAM_LIMIT = 128;
private static final int QUAD_LIMIT = 512;
Expand All @@ -29,6 +30,7 @@ public final class GLSMDebug {
private static final int CLIENT_ARRAY_LIMIT = 64;
private static final int BUFFER_BUILDER_LIMIT = 512;
private static final int VERTEX_BUFFER_LIMIT = 256;
private static final int PROGRAM_DRAW_LIMIT = 1024;

private static final AtomicInteger streamCount = new AtomicInteger();
private static final AtomicInteger quadCount = new AtomicInteger();
Expand All @@ -37,6 +39,7 @@ public final class GLSMDebug {
private static final AtomicInteger clientArrayCount = new AtomicInteger();
private static final AtomicInteger bufferBuilderCount = new AtomicInteger();
private static final AtomicInteger vertexBufferCount = new AtomicInteger();
private static final AtomicInteger programDrawCount = new AtomicInteger();

private static long lastOptionRefresh;
private static boolean cachedEnabled;
Expand Down Expand Up @@ -255,6 +258,26 @@ public static void logVertexBufferDraw(String format, int drawMode, int vertexFl
format);
}

/**
* Logs an immediate-mode/streaming draw that lands on a non-zero (shader pipeline) program.
* Used to diagnose mod content (e.g. Dynamic Surroundings popoffs) rendering through Iris passes.
*/
public static void logDrawOnActiveProgram(String path, int drawMode, int flags, int vertexCount, int program) {
if (!shouldLogWorldRender()) return;
final int count = programDrawCount.incrementAndGet();
if (count > PROGRAM_DRAW_LIMIT) return;

LOGGER.info(
"program-draw #{} path={} program={} mode={} flags=0x{} vertices={} attribs=[{}]",
count,
path,
program,
drawModeName(drawMode),
Integer.toHexString(flags),
vertexCount,
attributeSummary());
}

public static boolean forceOrphanStreaming() {
return isEnabled();
}
Expand All @@ -280,7 +303,7 @@ private static boolean readCeleritasDebugOption() {
}

private static boolean shouldLogWorldRender() {
return ENABLE_VERBOSE_DRAW_LOGS && isEnabled() && "Client thread".equals(Thread.currentThread().getName()) && isWorldLoaded();
return ENABLE_VERBOSE_DRAW_LOGS && (isEnabled() || ENABLE_GL_DEBUG_SYS_PROP) && "Client thread".equals(Thread.currentThread().getName()) && isWorldLoaded();
}

private static boolean isWorldLoaded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ private static void uploadAndDraw(
packed);
}
GLStateManager.prepareWideLineEmulation(drawMode);
if (DEBUG_STREAMING_DRAWS) {
final int activeProgram = GLStateManager.getActiveProgram();
if (activeProgram != 0) {
GLSMDebug.logDrawOnActiveProgram("stream", drawMode, flags, vertexCount, activeProgram);
}
}
final long preDrawStart = perfSampled ? GLSMPerfDebug.now() : 0L;
ShaderManager.getInstance().preDraw(flags);
if (perfSampled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,10 @@ static void applyStateKey(long key) {
boolean tex0Enabled = unpackTex0Enabled(key);
boolean tex1Enabled = unpackTex1Enabled(key);

GLStateManager.getTextures().getTextureUnitStates(0).setEnabled(tex0Enabled);
GLStateManager.getTextures().getTextureUnitStates(1).setEnabled(tex1Enabled);
// Route through GLStateManager so texture-unit enable changes post TEXTURE_UNIT_STATE;
// bypassing the event silently desyncs Iris pipeline input tracking (issue #41).
GLStateManager.setTexture2DEnabled(0, tex0Enabled);
GLStateManager.setTexture2DEnabled(1, tex1Enabled);
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
GLStateManager.glBlendFunc(srcRgb, dstRgb);
if (blendEnabled) {
Expand Down