Skip to content

Instantly share code, notes, and snippets.

@Cadiboo
Created January 6, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cadiboo/d57e1146e9c1904906e711dbc76e22aa to your computer and use it in GitHub Desktop.
Save Cadiboo/d57e1146e9c1904906e711dbc76e22aa to your computer and use it in GitHub Desktop.
Rendering Debugging helper
public class FieldDebug {
/**
* Call this code from a debugger evaluation from some working code and some code that
* doesn't work then compare the two dumps. Comparing the two will allow you to see the
* differences and change your code to eliminate the differences by invoking methods on
* the RenderSystem.
*/
public static void printGlStateManager() throws IllegalAccessException {
final StringBuilder stringBuilder = new StringBuilder();
appendClassFields(stringBuilder, GlStateManager.class, null, 15, 0);
System.out.println(stringBuilder.toString());
}
public static void appendClassFields(StringBuilder stringBuilder, Class<?> clazz, Object instance, int maxIterations, int currentIteration) throws IllegalAccessException {
if (maxIterations <= currentIteration) {
return;
}
for (final Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
for (int i = 0; i < currentIteration; ++i) {
stringBuilder.append(" ");
}
if (field.getType().isPrimitive())
stringBuilder
.append(field.getName())
.append(": ")
.append(field.get(instance))
.append("\n");
else {
stringBuilder
.append(field.getName())
.append(": ")
.append(field.getType().getSimpleName())
.append("\n");
appendClassFields(stringBuilder, field.getType(), field.get(instance), maxIterations, currentIteration + 1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment