mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-20 20:32:14 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34b6efde7b | ||
|
|
86edb721da | ||
|
|
39c5f4bf7b |
No files matched your search
@@ -43,6 +43,20 @@ public class Feature {
|
||||
}
|
||||
|
||||
private static final Map<Integer, Set<IStateStack<?>>> attribToFeatures = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Helper method to add all texture gen states (S, T, R, Q) for all texture units to a collection.
|
||||
* Used by both GL_ENABLE_BIT and GL_TEXTURE_BIT.
|
||||
*/
|
||||
private static void addTextureGenStates(Set<IStateStack<?>> collection) {
|
||||
for(int i = 0 ; i < GLStateManager.MAX_TEXTURE_UNITS; i++) {
|
||||
collection.add(GLStateManager.textures.getTexGenSStates(i));
|
||||
collection.add(GLStateManager.textures.getTexGenTStates(i));
|
||||
collection.add(GLStateManager.textures.getTexGenRStates(i));
|
||||
collection.add(GLStateManager.textures.getTexGenQStates(i));
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
attribToFeatures.put(GL11.GL_COLOR_BUFFER_BIT, ImmutableSet.of(
|
||||
GLStateManager.alphaTest // GL_ALPHA_TEST enable bit
|
||||
@@ -51,10 +65,10 @@ public class Feature {
|
||||
, GLStateManager.blendState // Blending source and destination functions
|
||||
// Constant blend color
|
||||
// Blending equation
|
||||
// GL_DITHER enable bit
|
||||
// GL_DRAW_BUFFER setting
|
||||
// GL_COLOR_LOGIC_OP enable bit
|
||||
// GL_INDEX_LOGIC_OP enable bit
|
||||
, GLStateManager.colorLogicOpState // GL_COLOR_LOGIC_OP enable bit
|
||||
, GLStateManager.ditherState // GL_DITHER enable bit
|
||||
, GLStateManager.drawBuffer // GL_DRAW_BUFFER setting
|
||||
, GLStateManager.indexLogicOpState // GL_INDEX_LOGIC_OP enable bit
|
||||
// Logic op function
|
||||
, GLStateManager.colorMask // Color-mode and index-mode writemasks
|
||||
, GLStateManager.clearColor // Color-mode and index-mode clear values
|
||||
@@ -80,14 +94,15 @@ public class Feature {
|
||||
|
||||
final HashSet<IStateStack<?>> enableBits = new HashSet<>(ImmutableSet.of(
|
||||
GLStateManager.alphaTest // GL_ALPHA_TEST flag
|
||||
// GL_AUTO_NORMAL flag
|
||||
, GLStateManager.autoNormalState // GL_AUTO_NORMAL flag
|
||||
, GLStateManager.blendMode // GL_BLEND flag
|
||||
// Enable bits for the user-definable clipping planes
|
||||
, GLStateManager.colorLogicOpState // GL_COLOR_LOGIC_OP flag
|
||||
, GLStateManager.colorMaterial // GL_COLOR_MATERIAL
|
||||
, GLStateManager.cullState // GL_CULL_FACE flag
|
||||
, GLStateManager.depthTest // GL_DEPTH_TEST flag
|
||||
// GL_DITHER flag
|
||||
, GLStateManager.ditherState // GL_DITHER flag
|
||||
, GLStateManager.fogMode // GL_FOG flag
|
||||
, GLStateManager.indexLogicOpState // GL_INDEX_LOGIC_OP flag
|
||||
, GLStateManager.lightStates[0] // GL_LIGHT0
|
||||
, GLStateManager.lightStates[1] // GL_LIGHT1
|
||||
, GLStateManager.lightStates[2] // GL_LIGHT2
|
||||
@@ -97,36 +112,57 @@ public class Feature {
|
||||
, GLStateManager.lightStates[6] // GL_LIGHT6
|
||||
, GLStateManager.lightStates[7] // GL_LIGHT7
|
||||
, GLStateManager.lightingState // GL_LIGHTING flag
|
||||
// GL_LINE_SMOOTH flag
|
||||
// GL_LINE_STIPPLE flag
|
||||
// GL_INDEX_LOGIC_OP flag
|
||||
// GL_COLOR_LOGIC_OP flag
|
||||
// GL_MAP1_x where x is a map type
|
||||
// GL_MAP2_x where x is a map type
|
||||
// GL_MULTISAMPLE flag
|
||||
// GL_NORMALIZE flag
|
||||
// GL_POINT_SMOOTH flag
|
||||
// GL_POLYGON_OFFSET_LINE flag
|
||||
// GL_POLYGON_OFFSET_FILL flag
|
||||
// GL_POLYGON_OFFSET_POINT flag
|
||||
// GL_POLYGON_SMOOTH flag
|
||||
// GL_POLYGON_STIPPLE flag
|
||||
// GL_SAMPLE_ALPHA_TO_COVERAGE flag
|
||||
// GL_SAMPLE_ALPHA_TO_ONE flag
|
||||
// GL_SAMPLE_COVERAGE flag
|
||||
, GLStateManager.lineSmoothState // GL_LINE_SMOOTH flag
|
||||
, GLStateManager.lineStippleState // GL_LINE_STIPPLE flag
|
||||
, GLStateManager.map1Color4State // GL_MAP1_COLOR_4
|
||||
, GLStateManager.map1IndexState // GL_MAP1_INDEX
|
||||
, GLStateManager.map1NormalState // GL_MAP1_NORMAL
|
||||
, GLStateManager.map1TextureCoord1State // GL_MAP1_TEXTURE_COORD_1
|
||||
, GLStateManager.map1TextureCoord2State // GL_MAP1_TEXTURE_COORD_2
|
||||
, GLStateManager.map1TextureCoord3State // GL_MAP1_TEXTURE_COORD_3
|
||||
, GLStateManager.map1TextureCoord4State // GL_MAP1_TEXTURE_COORD_4
|
||||
, GLStateManager.map1Vertex3State // GL_MAP1_VERTEX_3
|
||||
, GLStateManager.map1Vertex4State // GL_MAP1_VERTEX_4
|
||||
, GLStateManager.map2Color4State // GL_MAP2_COLOR_4
|
||||
, GLStateManager.map2IndexState // GL_MAP2_INDEX
|
||||
, GLStateManager.map2NormalState // GL_MAP2_NORMAL
|
||||
, GLStateManager.map2TextureCoord1State // GL_MAP2_TEXTURE_COORD_1
|
||||
, GLStateManager.map2TextureCoord2State // GL_MAP2_TEXTURE_COORD_2
|
||||
, GLStateManager.map2TextureCoord3State // GL_MAP2_TEXTURE_COORD_3
|
||||
, GLStateManager.map2TextureCoord4State // GL_MAP2_TEXTURE_COORD_4
|
||||
, GLStateManager.map2Vertex3State // GL_MAP2_VERTEX_3
|
||||
, GLStateManager.map2Vertex4State // GL_MAP2_VERTEX_4
|
||||
, GLStateManager.multisampleState // GL_MULTISAMPLE flag
|
||||
, GLStateManager.normalizeState // GL_NORMALIZE flag
|
||||
, GLStateManager.pointSmoothState // GL_POINT_SMOOTH flag
|
||||
, GLStateManager.polygonOffsetPointState // GL_POLYGON_OFFSET_POINT flag
|
||||
, GLStateManager.polygonOffsetLineState // GL_POLYGON_OFFSET_LINE flag
|
||||
, GLStateManager.polygonOffsetFillState // GL_POLYGON_OFFSET_FILL flag
|
||||
, GLStateManager.polygonSmoothState // GL_POLYGON_SMOOTH flag
|
||||
, GLStateManager.polygonStippleState // GL_POLYGON_STIPPLE flag
|
||||
, GLStateManager.rescaleNormalState // GL_RESCALE_NORMAL flag
|
||||
, GLStateManager.sampleAlphaToCoverageState // GL_SAMPLE_ALPHA_TO_COVERAGE flag
|
||||
, GLStateManager.sampleAlphaToOneState // GL_SAMPLE_ALPHA_TO_ONE flag
|
||||
, GLStateManager.sampleCoverageState // GL_SAMPLE_COVERAGE flag
|
||||
, GLStateManager.scissorTest // GL_SCISSOR_TEST flag
|
||||
// GL_STENCIL_TEST flag
|
||||
// GL_TEXTURE_1D flag
|
||||
// GL_TEXTURE_2D flag - Below
|
||||
// GL_TEXTURE_3D flag
|
||||
// Flags GL_TEXTURE_GEN_x where x is S, T, R, or Q
|
||||
, GLStateManager.stencilTest // GL_STENCIL_TEST flag
|
||||
));
|
||||
|
||||
// GL_TEXTURE_2D flag
|
||||
for(int i = 0 ; i < GLStateManager.MAX_TEXTURE_UNITS; i++) {
|
||||
enableBits.add(GLStateManager.textures.getTextureUnitStates(i));
|
||||
// Enable bits for the user-definable clipping planes
|
||||
for(int i = 0; i < GLStateManager.clipPlaneStates.length; i++) {
|
||||
enableBits.add(GLStateManager.clipPlaneStates[i]);
|
||||
}
|
||||
|
||||
// GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D flags
|
||||
for(int i = 0 ; i < GLStateManager.MAX_TEXTURE_UNITS; i++) {
|
||||
enableBits.add(GLStateManager.textures.getTexture1DStates(i));
|
||||
enableBits.add(GLStateManager.textures.getTextureUnitStates(i));
|
||||
enableBits.add(GLStateManager.textures.getTexture3DStates(i));
|
||||
}
|
||||
|
||||
// Flags GL_TEXTURE_GEN_x where x is S, T, R, or Q
|
||||
addTextureGenStates(enableBits);
|
||||
|
||||
attribToFeatures.put(GL11.GL_ENABLE_BIT, enableBits);
|
||||
attribToFeatures.put(GL11.GL_EVAL_BIT, ImmutableSet.of(
|
||||
// GL_MAP1_x enable bits, where x is a map type
|
||||
@@ -268,13 +304,16 @@ public class Feature {
|
||||
// textureAttribs.add(GLStateManager.textures.getInfo(i))
|
||||
}
|
||||
|
||||
// Enable bits GL_TEXTURE_GEN_x where x is S, T, R, or Q
|
||||
addTextureGenStates(textureAttribs);
|
||||
|
||||
attribToFeatures.put(GL11.GL_TEXTURE_BIT, textureAttribs);
|
||||
|
||||
attribToFeatures.put(GL11.GL_TRANSFORM_BIT, ImmutableSet.of(
|
||||
// Coefficients of the six clipping planes
|
||||
// Enable bits for the user-definable clipping planes
|
||||
GLStateManager.matrixMode
|
||||
// GL_NORMALIZE flag
|
||||
, GLStateManager.normalizeState // GL_NORMALIZE flag
|
||||
, GLStateManager.rescaleNormalState // GL_RESCALE_NORMAL flag
|
||||
));
|
||||
attribToFeatures.put(GL11.GL_VIEWPORT_BIT, ImmutableSet.of(
|
||||
|
||||
@@ -83,6 +83,17 @@ import java.util.function.IntSupplier;
|
||||
|
||||
import static com.gtnewhorizons.angelica.loading.AngelicaTweaker.LOGGER;
|
||||
|
||||
/**
|
||||
* OpenGL State Manager - Provides cached state tracking and management for OpenGL operations.
|
||||
*
|
||||
* <p><b>IMPORTANT INITIALIZATION ORDER:</b></p>
|
||||
* <ul>
|
||||
* <li>This class performs GL queries in static initializers (MAX_CLIP_PLANES, MAX_TEXTURE_UNITS, etc.)</li>
|
||||
* <li>The class MUST NOT be loaded until after the GL context has been created and made current</li>
|
||||
* <li>Violating this requirement will cause crashes with "No current context" or return invalid values</li>
|
||||
* <li>Call {@link #preInit()} after GL context creation to initialize runtime state</li>
|
||||
* </ul>
|
||||
*/
|
||||
@SuppressWarnings("unused") // Used in ASM
|
||||
public class GLStateManager {
|
||||
public static ContextCapabilities capabilities;
|
||||
@@ -94,6 +105,7 @@ public class GLStateManager {
|
||||
public static final int MAX_PROJECTION_STACK_DEPTH = GL11.glGetInteger(GL11.GL_MAX_PROJECTION_STACK_DEPTH);
|
||||
public static final int MAX_TEXTURE_STACK_DEPTH = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_STACK_DEPTH);
|
||||
public static final int MAX_TEXTURE_UNITS = GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS);
|
||||
public static final int MAX_CLIP_PLANES = GL11.glGetInteger(GL11.GL_MAX_CLIP_PLANES);
|
||||
|
||||
public static final GLFeatureSet HAS_MULTIPLE_SET = new GLFeatureSet();
|
||||
|
||||
@@ -119,12 +131,58 @@ public class GLStateManager {
|
||||
@Getter protected static final Color4Stack color = new Color4Stack();
|
||||
@Getter protected static final Color4Stack clearColor = new Color4Stack(new Color4(0.0F, 0.0F, 0.0F, 0.0F));
|
||||
@Getter protected static final ColorMaskStack colorMask = new ColorMaskStack();
|
||||
@Getter protected static IntegerStateStack drawBuffer; // Initialized in preInit() based on driver default
|
||||
@Getter protected static final BooleanStateStack cullState = new BooleanStateStack(GL11.GL_CULL_FACE);
|
||||
@Getter protected static final AlphaStateStack alphaState = new AlphaStateStack();
|
||||
@Getter protected static final BooleanStateStack alphaTest = new BooleanStateStack(GL11.GL_ALPHA_TEST);
|
||||
|
||||
@Getter protected static final BooleanStateStack lightingState = new BooleanStateStack(GL11.GL_LIGHTING);
|
||||
@Getter protected static final BooleanStateStack rescaleNormalState = new BooleanStateStack(GL12.GL_RESCALE_NORMAL);
|
||||
@Getter protected static final BooleanStateStack normalizeState = new BooleanStateStack(GL11.GL_NORMALIZE);
|
||||
|
||||
// Additional enable bit states tracked by GL_ENABLE_BIT
|
||||
@Getter protected static final BooleanStateStack ditherState = new BooleanStateStack(GL11.GL_DITHER, true); // Defaults to true per OpenGL spec
|
||||
@Getter protected static final BooleanStateStack stencilTest = new BooleanStateStack(GL11.GL_STENCIL_TEST);
|
||||
@Getter protected static final BooleanStateStack lineSmoothState = new BooleanStateStack(GL11.GL_LINE_SMOOTH);
|
||||
@Getter protected static final BooleanStateStack lineStippleState = new BooleanStateStack(GL11.GL_LINE_STIPPLE);
|
||||
@Getter protected static final BooleanStateStack pointSmoothState = new BooleanStateStack(GL11.GL_POINT_SMOOTH);
|
||||
@Getter protected static final BooleanStateStack polygonSmoothState = new BooleanStateStack(GL11.GL_POLYGON_SMOOTH);
|
||||
@Getter protected static final BooleanStateStack polygonStippleState = new BooleanStateStack(GL11.GL_POLYGON_STIPPLE);
|
||||
@Getter protected static final BooleanStateStack multisampleState = new BooleanStateStack(GL13.GL_MULTISAMPLE, true); // Defaults to true per OpenGL spec
|
||||
@Getter protected static final BooleanStateStack sampleAlphaToCoverageState = new BooleanStateStack(GL13.GL_SAMPLE_ALPHA_TO_COVERAGE);
|
||||
@Getter protected static final BooleanStateStack sampleAlphaToOneState = new BooleanStateStack(GL13.GL_SAMPLE_ALPHA_TO_ONE);
|
||||
@Getter protected static final BooleanStateStack sampleCoverageState = new BooleanStateStack(GL13.GL_SAMPLE_COVERAGE);
|
||||
@Getter protected static final BooleanStateStack colorLogicOpState = new BooleanStateStack(GL11.GL_COLOR_LOGIC_OP);
|
||||
@Getter protected static final BooleanStateStack indexLogicOpState = new BooleanStateStack(GL11.GL_INDEX_LOGIC_OP);
|
||||
|
||||
// Polygon offset states
|
||||
@Getter protected static final BooleanStateStack polygonOffsetPointState = new BooleanStateStack(GL11.GL_POLYGON_OFFSET_POINT);
|
||||
@Getter protected static final BooleanStateStack polygonOffsetLineState = new BooleanStateStack(GL11.GL_POLYGON_OFFSET_LINE);
|
||||
@Getter protected static final BooleanStateStack polygonOffsetFillState = new BooleanStateStack(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
// Evaluator states
|
||||
@Getter protected static final BooleanStateStack autoNormalState = new BooleanStateStack(GL11.GL_AUTO_NORMAL);
|
||||
@Getter protected static final BooleanStateStack map1Color4State = new BooleanStateStack(GL11.GL_MAP1_COLOR_4);
|
||||
@Getter protected static final BooleanStateStack map1IndexState = new BooleanStateStack(GL11.GL_MAP1_INDEX);
|
||||
@Getter protected static final BooleanStateStack map1NormalState = new BooleanStateStack(GL11.GL_MAP1_NORMAL);
|
||||
@Getter protected static final BooleanStateStack map1TextureCoord1State = new BooleanStateStack(GL11.GL_MAP1_TEXTURE_COORD_1);
|
||||
@Getter protected static final BooleanStateStack map1TextureCoord2State = new BooleanStateStack(GL11.GL_MAP1_TEXTURE_COORD_2);
|
||||
@Getter protected static final BooleanStateStack map1TextureCoord3State = new BooleanStateStack(GL11.GL_MAP1_TEXTURE_COORD_3);
|
||||
@Getter protected static final BooleanStateStack map1TextureCoord4State = new BooleanStateStack(GL11.GL_MAP1_TEXTURE_COORD_4);
|
||||
@Getter protected static final BooleanStateStack map1Vertex3State = new BooleanStateStack(GL11.GL_MAP1_VERTEX_3);
|
||||
@Getter protected static final BooleanStateStack map1Vertex4State = new BooleanStateStack(GL11.GL_MAP1_VERTEX_4);
|
||||
@Getter protected static final BooleanStateStack map2Color4State = new BooleanStateStack(GL11.GL_MAP2_COLOR_4);
|
||||
@Getter protected static final BooleanStateStack map2IndexState = new BooleanStateStack(GL11.GL_MAP2_INDEX);
|
||||
@Getter protected static final BooleanStateStack map2NormalState = new BooleanStateStack(GL11.GL_MAP2_NORMAL);
|
||||
@Getter protected static final BooleanStateStack map2TextureCoord1State = new BooleanStateStack(GL11.GL_MAP2_TEXTURE_COORD_1);
|
||||
@Getter protected static final BooleanStateStack map2TextureCoord2State = new BooleanStateStack(GL11.GL_MAP2_TEXTURE_COORD_2);
|
||||
@Getter protected static final BooleanStateStack map2TextureCoord3State = new BooleanStateStack(GL11.GL_MAP2_TEXTURE_COORD_3);
|
||||
@Getter protected static final BooleanStateStack map2TextureCoord4State = new BooleanStateStack(GL11.GL_MAP2_TEXTURE_COORD_4);
|
||||
@Getter protected static final BooleanStateStack map2Vertex3State = new BooleanStateStack(GL11.GL_MAP2_VERTEX_3);
|
||||
@Getter protected static final BooleanStateStack map2Vertex4State = new BooleanStateStack(GL11.GL_MAP2_VERTEX_4);
|
||||
|
||||
// Clip plane states
|
||||
@Getter protected static final BooleanStateStack[] clipPlaneStates = new BooleanStateStack[MAX_CLIP_PLANES];
|
||||
|
||||
@Getter protected static final MatrixModeStack matrixMode = new MatrixModeStack();
|
||||
@Getter protected static final Matrix4fStack modelViewMatrix = new Matrix4fStack(MAX_MODELVIEW_STACK_DEPTH);
|
||||
@@ -148,8 +206,12 @@ public class GLStateManager {
|
||||
lightDataStates[i] = new LightStateStack(GL11.GL_LIGHT0 + i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_CLIP_PLANES; i++) {
|
||||
clipPlaneStates[i] = new BooleanStateStack(GL11.GL_CLIP_PLANE0 + i);
|
||||
}
|
||||
|
||||
try {
|
||||
Field curr = ReflectionHelper.findField(Matrix4fStack.class, "curr");
|
||||
final Field curr = ReflectionHelper.findField(Matrix4fStack.class, "curr");
|
||||
curr.setAccessible(true);
|
||||
MAT4_STACK_CURR_DEPTH = MethodHandles.lookup().unreflectGetter(curr);
|
||||
} catch (IllegalAccessException e) {
|
||||
@@ -167,11 +229,11 @@ public class GLStateManager {
|
||||
attribs.popInt();
|
||||
}
|
||||
|
||||
List<IStateStack<?>> stacks = Feature.maskToFeatures(GL11.GL_ALL_ATTRIB_BITS);
|
||||
int size = stacks.size();
|
||||
final List<IStateStack<?>> stacks = Feature.maskToFeatures(GL11.GL_ALL_ATTRIB_BITS);
|
||||
final int size = stacks.size();
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
IStateStack<?> stack = stacks.get(i);
|
||||
final IStateStack<?> stack = stacks.get(i);
|
||||
|
||||
while(!stack.isEmpty()) {
|
||||
stack.pop();
|
||||
@@ -255,6 +317,9 @@ public class GLStateManager {
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
}
|
||||
|
||||
// Initialize GL_DRAW_BUFFER based on vendor
|
||||
// Intel integrated graphics defaults to GL_FRONT (single-buffered), others use GL_BACK (double-buffered)
|
||||
drawBuffer = new IntegerStateStack(INTEL ? GL11.GL_FRONT : GL11.GL_BACK);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
@@ -300,12 +365,23 @@ public class GLStateManager {
|
||||
|
||||
// LWJGL Overrides
|
||||
public static void glEnable(int cap) {
|
||||
// Handle clip planes dynamically (supports up to MAX_CLIP_PLANES)
|
||||
if (cap >= GL11.GL_CLIP_PLANE0 && cap < GL11.GL_CLIP_PLANE0 + MAX_CLIP_PLANES) {
|
||||
clipPlaneStates[cap - GL11.GL_CLIP_PLANE0].enable();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cap) {
|
||||
case GL11.GL_ALPHA_TEST -> enableAlphaTest();
|
||||
case GL11.GL_AUTO_NORMAL -> autoNormalState.enable();
|
||||
case GL11.GL_BLEND -> enableBlend();
|
||||
case GL11.GL_COLOR_MATERIAL -> enableColorMaterial();
|
||||
case GL11.GL_COLOR_LOGIC_OP -> colorLogicOpState.enable();
|
||||
case GL11.GL_CULL_FACE -> enableCull();
|
||||
case GL11.GL_DEPTH_TEST -> enableDepthTest();
|
||||
case GL11.GL_DITHER -> ditherState.enable();
|
||||
case GL11.GL_FOG -> enableFog();
|
||||
case GL11.GL_INDEX_LOGIC_OP -> indexLogicOpState.enable();
|
||||
case GL11.GL_LIGHTING -> enableLighting();
|
||||
case GL11.GL_LIGHT0 -> enableLight(0);
|
||||
case GL11.GL_LIGHT1 -> enableLight(1);
|
||||
@@ -315,21 +391,69 @@ public class GLStateManager {
|
||||
case GL11.GL_LIGHT5 -> enableLight(5);
|
||||
case GL11.GL_LIGHT6 -> enableLight(6);
|
||||
case GL11.GL_LIGHT7 -> enableLight(7);
|
||||
case GL11.GL_COLOR_MATERIAL -> enableColorMaterial();
|
||||
case GL11.GL_SCISSOR_TEST -> enableScissorTest();
|
||||
case GL11.GL_TEXTURE_2D -> enableTexture();
|
||||
case GL11.GL_LINE_SMOOTH -> lineSmoothState.enable();
|
||||
case GL11.GL_LINE_STIPPLE -> lineStippleState.enable();
|
||||
case GL11.GL_MAP1_COLOR_4 -> map1Color4State.enable();
|
||||
case GL11.GL_MAP1_INDEX -> map1IndexState.enable();
|
||||
case GL11.GL_MAP1_NORMAL -> map1NormalState.enable();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_1 -> map1TextureCoord1State.enable();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_2 -> map1TextureCoord2State.enable();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_3 -> map1TextureCoord3State.enable();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_4 -> map1TextureCoord4State.enable();
|
||||
case GL11.GL_MAP1_VERTEX_3 -> map1Vertex3State.enable();
|
||||
case GL11.GL_MAP1_VERTEX_4 -> map1Vertex4State.enable();
|
||||
case GL11.GL_MAP2_COLOR_4 -> map2Color4State.enable();
|
||||
case GL11.GL_MAP2_INDEX -> map2IndexState.enable();
|
||||
case GL11.GL_MAP2_NORMAL -> map2NormalState.enable();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_1 -> map2TextureCoord1State.enable();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_2 -> map2TextureCoord2State.enable();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_3 -> map2TextureCoord3State.enable();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_4 -> map2TextureCoord4State.enable();
|
||||
case GL11.GL_MAP2_VERTEX_3 -> map2Vertex3State.enable();
|
||||
case GL11.GL_MAP2_VERTEX_4 -> map2Vertex4State.enable();
|
||||
case GL13.GL_MULTISAMPLE -> multisampleState.enable();
|
||||
case GL11.GL_NORMALIZE -> normalizeState.enable();
|
||||
case GL11.GL_POINT_SMOOTH -> pointSmoothState.enable();
|
||||
case GL11.GL_POLYGON_OFFSET_POINT -> polygonOffsetPointState.enable();
|
||||
case GL11.GL_POLYGON_OFFSET_LINE -> polygonOffsetLineState.enable();
|
||||
case GL11.GL_POLYGON_OFFSET_FILL -> polygonOffsetFillState.enable();
|
||||
case GL11.GL_POLYGON_SMOOTH -> polygonSmoothState.enable();
|
||||
case GL11.GL_POLYGON_STIPPLE -> polygonStippleState.enable();
|
||||
case GL12.GL_RESCALE_NORMAL -> enableRescaleNormal();
|
||||
case GL13.GL_SAMPLE_ALPHA_TO_COVERAGE -> sampleAlphaToCoverageState.enable();
|
||||
case GL13.GL_SAMPLE_ALPHA_TO_ONE -> sampleAlphaToOneState.enable();
|
||||
case GL13.GL_SAMPLE_COVERAGE -> sampleCoverageState.enable();
|
||||
case GL11.GL_SCISSOR_TEST -> enableScissorTest();
|
||||
case GL11.GL_STENCIL_TEST -> stencilTest.enable();
|
||||
case GL11.GL_TEXTURE_1D -> textures.getTexture1DStates(activeTextureUnit.getValue()).enable();
|
||||
case GL11.GL_TEXTURE_2D -> enableTexture();
|
||||
case GL12.GL_TEXTURE_3D -> textures.getTexture3DStates(activeTextureUnit.getValue()).enable();
|
||||
case GL11.GL_TEXTURE_GEN_S -> textures.getTexGenSStates(activeTextureUnit.getValue()).enable();
|
||||
case GL11.GL_TEXTURE_GEN_T -> textures.getTexGenTStates(activeTextureUnit.getValue()).enable();
|
||||
case GL11.GL_TEXTURE_GEN_R -> textures.getTexGenRStates(activeTextureUnit.getValue()).enable();
|
||||
case GL11.GL_TEXTURE_GEN_Q -> textures.getTexGenQStates(activeTextureUnit.getValue()).enable();
|
||||
default -> GL11.glEnable(cap);
|
||||
}
|
||||
}
|
||||
|
||||
public static void glDisable(int cap) {
|
||||
// Handle clip planes dynamically (supports up to MAX_CLIP_PLANES)
|
||||
if (cap >= GL11.GL_CLIP_PLANE0 && cap < GL11.GL_CLIP_PLANE0 + MAX_CLIP_PLANES) {
|
||||
clipPlaneStates[cap - GL11.GL_CLIP_PLANE0].disable();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cap) {
|
||||
case GL11.GL_ALPHA_TEST -> disableAlphaTest();
|
||||
case GL11.GL_AUTO_NORMAL -> autoNormalState.disable();
|
||||
case GL11.GL_BLEND -> disableBlend();
|
||||
case GL11.GL_COLOR_MATERIAL -> disableColorMaterial();
|
||||
case GL11.GL_COLOR_LOGIC_OP -> colorLogicOpState.disable();
|
||||
case GL11.GL_CULL_FACE -> disableCull();
|
||||
case GL11.GL_DEPTH_TEST -> disableDepthTest();
|
||||
case GL11.GL_DITHER -> ditherState.disable();
|
||||
case GL11.GL_FOG -> disableFog();
|
||||
case GL11.GL_INDEX_LOGIC_OP -> indexLogicOpState.disable();
|
||||
case GL11.GL_LIGHTING -> disableLighting();
|
||||
case GL11.GL_LIGHT0 -> disableLight(0);
|
||||
case GL11.GL_LIGHT1 -> disableLight(1);
|
||||
@@ -339,10 +463,47 @@ public class GLStateManager {
|
||||
case GL11.GL_LIGHT5 -> disableLight(5);
|
||||
case GL11.GL_LIGHT6 -> disableLight(6);
|
||||
case GL11.GL_LIGHT7 -> disableLight(7);
|
||||
case GL11.GL_COLOR_MATERIAL -> disableColorMaterial();
|
||||
case GL11.GL_SCISSOR_TEST -> disableScissorTest();
|
||||
case GL11.GL_TEXTURE_2D -> disableTexture();
|
||||
case GL11.GL_LINE_SMOOTH -> lineSmoothState.disable();
|
||||
case GL11.GL_LINE_STIPPLE -> lineStippleState.disable();
|
||||
case GL11.GL_MAP1_COLOR_4 -> map1Color4State.disable();
|
||||
case GL11.GL_MAP1_INDEX -> map1IndexState.disable();
|
||||
case GL11.GL_MAP1_NORMAL -> map1NormalState.disable();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_1 -> map1TextureCoord1State.disable();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_2 -> map1TextureCoord2State.disable();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_3 -> map1TextureCoord3State.disable();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_4 -> map1TextureCoord4State.disable();
|
||||
case GL11.GL_MAP1_VERTEX_3 -> map1Vertex3State.disable();
|
||||
case GL11.GL_MAP1_VERTEX_4 -> map1Vertex4State.disable();
|
||||
case GL11.GL_MAP2_COLOR_4 -> map2Color4State.disable();
|
||||
case GL11.GL_MAP2_INDEX -> map2IndexState.disable();
|
||||
case GL11.GL_MAP2_NORMAL -> map2NormalState.disable();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_1 -> map2TextureCoord1State.disable();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_2 -> map2TextureCoord2State.disable();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_3 -> map2TextureCoord3State.disable();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_4 -> map2TextureCoord4State.disable();
|
||||
case GL11.GL_MAP2_VERTEX_3 -> map2Vertex3State.disable();
|
||||
case GL11.GL_MAP2_VERTEX_4 -> map2Vertex4State.disable();
|
||||
case GL13.GL_MULTISAMPLE -> multisampleState.disable();
|
||||
case GL11.GL_NORMALIZE -> normalizeState.disable();
|
||||
case GL11.GL_POINT_SMOOTH -> pointSmoothState.disable();
|
||||
case GL11.GL_POLYGON_OFFSET_POINT -> polygonOffsetPointState.disable();
|
||||
case GL11.GL_POLYGON_OFFSET_LINE -> polygonOffsetLineState.disable();
|
||||
case GL11.GL_POLYGON_OFFSET_FILL -> polygonOffsetFillState.disable();
|
||||
case GL11.GL_POLYGON_SMOOTH -> polygonSmoothState.disable();
|
||||
case GL11.GL_POLYGON_STIPPLE -> polygonStippleState.disable();
|
||||
case GL12.GL_RESCALE_NORMAL -> disableRescaleNormal();
|
||||
case GL13.GL_SAMPLE_ALPHA_TO_COVERAGE -> sampleAlphaToCoverageState.disable();
|
||||
case GL13.GL_SAMPLE_ALPHA_TO_ONE -> sampleAlphaToOneState.disable();
|
||||
case GL13.GL_SAMPLE_COVERAGE -> sampleCoverageState.disable();
|
||||
case GL11.GL_SCISSOR_TEST -> disableScissorTest();
|
||||
case GL11.GL_STENCIL_TEST -> stencilTest.disable();
|
||||
case GL11.GL_TEXTURE_1D -> textures.getTexture1DStates(activeTextureUnit.getValue()).disable();
|
||||
case GL11.GL_TEXTURE_2D -> disableTexture();
|
||||
case GL12.GL_TEXTURE_3D -> textures.getTexture3DStates(activeTextureUnit.getValue()).disable();
|
||||
case GL11.GL_TEXTURE_GEN_S -> textures.getTexGenSStates(activeTextureUnit.getValue()).disable();
|
||||
case GL11.GL_TEXTURE_GEN_T -> textures.getTexGenTStates(activeTextureUnit.getValue()).disable();
|
||||
case GL11.GL_TEXTURE_GEN_R -> textures.getTexGenRStates(activeTextureUnit.getValue()).disable();
|
||||
case GL11.GL_TEXTURE_GEN_Q -> textures.getTexGenQStates(activeTextureUnit.getValue()).disable();
|
||||
default -> GL11.glDisable(cap);
|
||||
}
|
||||
}
|
||||
@@ -351,12 +512,22 @@ public class GLStateManager {
|
||||
if(shouldBypassCache()) {
|
||||
return GL11.glIsEnabled(cap);
|
||||
}
|
||||
// Handle clip planes dynamically (supports up to MAX_CLIP_PLANES)
|
||||
if (cap >= GL11.GL_CLIP_PLANE0 && cap < GL11.GL_CLIP_PLANE0 + MAX_CLIP_PLANES) {
|
||||
return clipPlaneStates[cap - GL11.GL_CLIP_PLANE0].isEnabled();
|
||||
}
|
||||
|
||||
return switch (cap) {
|
||||
case GL11.GL_ALPHA_TEST -> alphaTest.isEnabled();
|
||||
case GL11.GL_AUTO_NORMAL -> autoNormalState.isEnabled();
|
||||
case GL11.GL_BLEND -> blendMode.isEnabled();
|
||||
case GL11.GL_COLOR_MATERIAL -> colorMaterial.isEnabled();
|
||||
case GL11.GL_COLOR_LOGIC_OP -> colorLogicOpState.isEnabled();
|
||||
case GL11.GL_CULL_FACE -> cullState.isEnabled();
|
||||
case GL11.GL_DEPTH_TEST -> depthTest.isEnabled();
|
||||
case GL11.GL_DITHER -> ditherState.isEnabled();
|
||||
case GL11.GL_FOG -> fogMode.isEnabled();
|
||||
case GL11.GL_INDEX_LOGIC_OP -> indexLogicOpState.isEnabled();
|
||||
case GL11.GL_LIGHTING -> lightingState.isEnabled();
|
||||
case GL11.GL_LIGHT0 -> lightStates[0].isEnabled();
|
||||
case GL11.GL_LIGHT1 -> lightStates[1].isEnabled();
|
||||
@@ -366,10 +537,47 @@ public class GLStateManager {
|
||||
case GL11.GL_LIGHT5 -> lightStates[5].isEnabled();
|
||||
case GL11.GL_LIGHT6 -> lightStates[6].isEnabled();
|
||||
case GL11.GL_LIGHT7 -> lightStates[7].isEnabled();
|
||||
case GL11.GL_COLOR_MATERIAL -> colorMaterial.isEnabled();
|
||||
case GL11.GL_SCISSOR_TEST -> scissorTest.isEnabled();
|
||||
case GL11.GL_TEXTURE_2D -> textures.getTextureUnitStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_LINE_SMOOTH -> lineSmoothState.isEnabled();
|
||||
case GL11.GL_LINE_STIPPLE -> lineStippleState.isEnabled();
|
||||
case GL11.GL_MAP1_COLOR_4 -> map1Color4State.isEnabled();
|
||||
case GL11.GL_MAP1_INDEX -> map1IndexState.isEnabled();
|
||||
case GL11.GL_MAP1_NORMAL -> map1NormalState.isEnabled();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_1 -> map1TextureCoord1State.isEnabled();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_2 -> map1TextureCoord2State.isEnabled();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_3 -> map1TextureCoord3State.isEnabled();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_4 -> map1TextureCoord4State.isEnabled();
|
||||
case GL11.GL_MAP1_VERTEX_3 -> map1Vertex3State.isEnabled();
|
||||
case GL11.GL_MAP1_VERTEX_4 -> map1Vertex4State.isEnabled();
|
||||
case GL11.GL_MAP2_COLOR_4 -> map2Color4State.isEnabled();
|
||||
case GL11.GL_MAP2_INDEX -> map2IndexState.isEnabled();
|
||||
case GL11.GL_MAP2_NORMAL -> map2NormalState.isEnabled();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_1 -> map2TextureCoord1State.isEnabled();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_2 -> map2TextureCoord2State.isEnabled();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_3 -> map2TextureCoord3State.isEnabled();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_4 -> map2TextureCoord4State.isEnabled();
|
||||
case GL11.GL_MAP2_VERTEX_3 -> map2Vertex3State.isEnabled();
|
||||
case GL11.GL_MAP2_VERTEX_4 -> map2Vertex4State.isEnabled();
|
||||
case GL13.GL_MULTISAMPLE -> multisampleState.isEnabled();
|
||||
case GL11.GL_NORMALIZE -> normalizeState.isEnabled();
|
||||
case GL11.GL_POINT_SMOOTH -> pointSmoothState.isEnabled();
|
||||
case GL11.GL_POLYGON_OFFSET_POINT -> polygonOffsetPointState.isEnabled();
|
||||
case GL11.GL_POLYGON_OFFSET_LINE -> polygonOffsetLineState.isEnabled();
|
||||
case GL11.GL_POLYGON_OFFSET_FILL -> polygonOffsetFillState.isEnabled();
|
||||
case GL11.GL_POLYGON_SMOOTH -> polygonSmoothState.isEnabled();
|
||||
case GL11.GL_POLYGON_STIPPLE -> polygonStippleState.isEnabled();
|
||||
case GL12.GL_RESCALE_NORMAL -> rescaleNormalState.isEnabled();
|
||||
case GL13.GL_SAMPLE_ALPHA_TO_COVERAGE -> sampleAlphaToCoverageState.isEnabled();
|
||||
case GL13.GL_SAMPLE_ALPHA_TO_ONE -> sampleAlphaToOneState.isEnabled();
|
||||
case GL13.GL_SAMPLE_COVERAGE -> sampleCoverageState.isEnabled();
|
||||
case GL11.GL_SCISSOR_TEST -> scissorTest.isEnabled();
|
||||
case GL11.GL_STENCIL_TEST -> stencilTest.isEnabled();
|
||||
case GL11.GL_TEXTURE_1D -> textures.getTexture1DStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_2D -> textures.getTextureUnitStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL12.GL_TEXTURE_3D -> textures.getTexture3DStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_GEN_S -> textures.getTexGenSStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_GEN_T -> textures.getTexGenTStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_GEN_R -> textures.getTexGenRStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_GEN_Q -> textures.getTexGenQStates(activeTextureUnit.getValue()).isEnabled();
|
||||
default -> GL11.glIsEnabled(cap);
|
||||
};
|
||||
}
|
||||
@@ -378,13 +586,23 @@ public class GLStateManager {
|
||||
if(shouldBypassCache()) {
|
||||
return GL11.glGetBoolean(pname);
|
||||
}
|
||||
// Handle clip planes dynamically (supports up to MAX_CLIP_PLANES)
|
||||
if (pname >= GL11.GL_CLIP_PLANE0 && pname < GL11.GL_CLIP_PLANE0 + MAX_CLIP_PLANES) {
|
||||
return clipPlaneStates[pname - GL11.GL_CLIP_PLANE0].isEnabled();
|
||||
}
|
||||
|
||||
return switch (pname) {
|
||||
case GL11.GL_ALPHA_TEST -> alphaTest.isEnabled();
|
||||
case GL11.GL_AUTO_NORMAL -> autoNormalState.isEnabled();
|
||||
case GL11.GL_BLEND -> blendMode.isEnabled();
|
||||
case GL11.GL_COLOR_MATERIAL -> colorMaterial.isEnabled();
|
||||
case GL11.GL_COLOR_LOGIC_OP -> colorLogicOpState.isEnabled();
|
||||
case GL11.GL_CULL_FACE -> cullState.isEnabled();
|
||||
case GL11.GL_DEPTH_TEST -> depthTest.isEnabled();
|
||||
case GL11.GL_DEPTH_WRITEMASK -> depthState.isEnabled();
|
||||
case GL11.GL_DITHER -> ditherState.isEnabled();
|
||||
case GL11.GL_FOG -> fogMode.isEnabled();
|
||||
case GL11.GL_INDEX_LOGIC_OP -> indexLogicOpState.isEnabled();
|
||||
case GL11.GL_LIGHTING -> lightingState.isEnabled();
|
||||
case GL11.GL_LIGHT0 -> lightStates[0].isEnabled();
|
||||
case GL11.GL_LIGHT1 -> lightStates[1].isEnabled();
|
||||
@@ -394,10 +612,47 @@ public class GLStateManager {
|
||||
case GL11.GL_LIGHT5 -> lightStates[5].isEnabled();
|
||||
case GL11.GL_LIGHT6 -> lightStates[6].isEnabled();
|
||||
case GL11.GL_LIGHT7 -> lightStates[7].isEnabled();
|
||||
case GL11.GL_COLOR_MATERIAL -> colorMaterial.isEnabled();
|
||||
case GL11.GL_SCISSOR_TEST -> scissorTest.isEnabled();
|
||||
case GL11.GL_TEXTURE_2D -> textures.getTextureUnitStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_LINE_SMOOTH -> lineSmoothState.isEnabled();
|
||||
case GL11.GL_LINE_STIPPLE -> lineStippleState.isEnabled();
|
||||
case GL11.GL_MAP1_COLOR_4 -> map1Color4State.isEnabled();
|
||||
case GL11.GL_MAP1_INDEX -> map1IndexState.isEnabled();
|
||||
case GL11.GL_MAP1_NORMAL -> map1NormalState.isEnabled();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_1 -> map1TextureCoord1State.isEnabled();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_2 -> map1TextureCoord2State.isEnabled();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_3 -> map1TextureCoord3State.isEnabled();
|
||||
case GL11.GL_MAP1_TEXTURE_COORD_4 -> map1TextureCoord4State.isEnabled();
|
||||
case GL11.GL_MAP1_VERTEX_3 -> map1Vertex3State.isEnabled();
|
||||
case GL11.GL_MAP1_VERTEX_4 -> map1Vertex4State.isEnabled();
|
||||
case GL11.GL_MAP2_COLOR_4 -> map2Color4State.isEnabled();
|
||||
case GL11.GL_MAP2_INDEX -> map2IndexState.isEnabled();
|
||||
case GL11.GL_MAP2_NORMAL -> map2NormalState.isEnabled();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_1 -> map2TextureCoord1State.isEnabled();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_2 -> map2TextureCoord2State.isEnabled();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_3 -> map2TextureCoord3State.isEnabled();
|
||||
case GL11.GL_MAP2_TEXTURE_COORD_4 -> map2TextureCoord4State.isEnabled();
|
||||
case GL11.GL_MAP2_VERTEX_3 -> map2Vertex3State.isEnabled();
|
||||
case GL11.GL_MAP2_VERTEX_4 -> map2Vertex4State.isEnabled();
|
||||
case GL13.GL_MULTISAMPLE -> multisampleState.isEnabled();
|
||||
case GL11.GL_NORMALIZE -> normalizeState.isEnabled();
|
||||
case GL11.GL_POINT_SMOOTH -> pointSmoothState.isEnabled();
|
||||
case GL11.GL_POLYGON_OFFSET_POINT -> polygonOffsetPointState.isEnabled();
|
||||
case GL11.GL_POLYGON_OFFSET_LINE -> polygonOffsetLineState.isEnabled();
|
||||
case GL11.GL_POLYGON_OFFSET_FILL -> polygonOffsetFillState.isEnabled();
|
||||
case GL11.GL_POLYGON_SMOOTH -> polygonSmoothState.isEnabled();
|
||||
case GL11.GL_POLYGON_STIPPLE -> polygonStippleState.isEnabled();
|
||||
case GL12.GL_RESCALE_NORMAL -> rescaleNormalState.isEnabled();
|
||||
case GL13.GL_SAMPLE_ALPHA_TO_COVERAGE -> sampleAlphaToCoverageState.isEnabled();
|
||||
case GL13.GL_SAMPLE_ALPHA_TO_ONE -> sampleAlphaToOneState.isEnabled();
|
||||
case GL13.GL_SAMPLE_COVERAGE -> sampleCoverageState.isEnabled();
|
||||
case GL11.GL_SCISSOR_TEST -> scissorTest.isEnabled();
|
||||
case GL11.GL_STENCIL_TEST -> stencilTest.isEnabled();
|
||||
case GL11.GL_TEXTURE_1D -> textures.getTexture1DStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_2D -> textures.getTextureUnitStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL12.GL_TEXTURE_3D -> textures.getTexture3DStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_GEN_S -> textures.getTexGenSStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_GEN_T -> textures.getTexGenTStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_GEN_R -> textures.getTexGenRStates(activeTextureUnit.getValue()).isEnabled();
|
||||
case GL11.GL_TEXTURE_GEN_Q -> textures.getTexGenQStates(activeTextureUnit.getValue()).isEnabled();
|
||||
default -> GL11.glGetBoolean(pname);
|
||||
};
|
||||
}
|
||||
@@ -997,7 +1252,7 @@ public class GLStateManager {
|
||||
i = mipmap ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_LINEAR;
|
||||
j = GL11.GL_LINEAR;
|
||||
} else {
|
||||
i = mipmap ? GL11.GL_NEAREST_MIPMAP_LINEAR : GL11.GL_NEAREST;
|
||||
i = mipmap ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_NEAREST;
|
||||
j = GL11.GL_NEAREST;
|
||||
}
|
||||
glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, i);
|
||||
|
||||
@@ -12,7 +12,20 @@ public class BooleanStateStack extends BooleanState implements IStateStack<Boole
|
||||
protected int pointer;
|
||||
|
||||
public BooleanStateStack(int glCap) {
|
||||
// Most booleans default to false
|
||||
this(glCap, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BooleanStateStack with a custom initial state.
|
||||
* Useful for GL states that default to true (e.g., GL_DITHER, GL_MULTISAMPLE).
|
||||
*
|
||||
* @param glCap GL capability constant
|
||||
* @param initialState initial enabled state
|
||||
*/
|
||||
public BooleanStateStack(int glCap, boolean initialState) {
|
||||
super(glCap);
|
||||
this.enabled = initialState;
|
||||
stack = new BooleanState[GLStateManager.MAX_ATTRIB_STACK_DEPTH];
|
||||
for (int i = 0; i < GLStateManager.MAX_ATTRIB_STACK_DEPTH; i++) {
|
||||
stack[i] = new BooleanState(glCap);
|
||||
|
||||
@@ -6,21 +6,40 @@ import com.gtnewhorizons.angelica.glsm.stacks.TextureBindingStack;
|
||||
import lombok.Getter;
|
||||
import org.joml.Matrix4fStack;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
public class TextureUnitArray {
|
||||
private final TextureBindingStack[] bindings;
|
||||
private final BooleanStateStack[] states;
|
||||
private final BooleanStateStack[] texture1DStates;
|
||||
private final BooleanStateStack[] texture3DStates;
|
||||
private final BooleanStateStack[] texGenSStates;
|
||||
private final BooleanStateStack[] texGenTStates;
|
||||
private final BooleanStateStack[] texGenRStates;
|
||||
private final BooleanStateStack[] texGenQStates;
|
||||
@Getter
|
||||
public final Matrix4fStack[] textureMatricies;
|
||||
|
||||
public TextureUnitArray() {
|
||||
bindings = new TextureBindingStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
states = new BooleanStateStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
texture1DStates = new BooleanStateStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
texture3DStates = new BooleanStateStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
texGenSStates = new BooleanStateStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
texGenTStates = new BooleanStateStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
texGenRStates = new BooleanStateStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
texGenQStates = new BooleanStateStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
textureMatricies = new Matrix4fStack[GLStateManager.MAX_TEXTURE_UNITS];
|
||||
|
||||
for (int i = 0; i < GLStateManager.MAX_TEXTURE_UNITS; i++) {
|
||||
bindings[i] = new TextureBindingStack();
|
||||
states[i] = new BooleanStateStack(GL11.GL_TEXTURE_2D);
|
||||
texture1DStates[i] = new BooleanStateStack(GL11.GL_TEXTURE_1D);
|
||||
texture3DStates[i] = new BooleanStateStack(GL12.GL_TEXTURE_3D);
|
||||
texGenSStates[i] = new BooleanStateStack(GL11.GL_TEXTURE_GEN_S);
|
||||
texGenTStates[i] = new BooleanStateStack(GL11.GL_TEXTURE_GEN_T);
|
||||
texGenRStates[i] = new BooleanStateStack(GL11.GL_TEXTURE_GEN_R);
|
||||
texGenQStates[i] = new BooleanStateStack(GL11.GL_TEXTURE_GEN_Q);
|
||||
textureMatricies[i] = new Matrix4fStack(GLStateManager.MAX_TEXTURE_STACK_DEPTH);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +52,30 @@ public class TextureUnitArray {
|
||||
return states[index];
|
||||
}
|
||||
|
||||
public BooleanStateStack getTexture1DStates(int index) {
|
||||
return texture1DStates[index];
|
||||
}
|
||||
|
||||
public BooleanStateStack getTexture3DStates(int index) {
|
||||
return texture3DStates[index];
|
||||
}
|
||||
|
||||
public BooleanStateStack getTexGenSStates(int index) {
|
||||
return texGenSStates[index];
|
||||
}
|
||||
|
||||
public BooleanStateStack getTexGenTStates(int index) {
|
||||
return texGenTStates[index];
|
||||
}
|
||||
|
||||
public BooleanStateStack getTexGenRStates(int index) {
|
||||
return texGenRStates[index];
|
||||
}
|
||||
|
||||
public BooleanStateStack getTexGenQStates(int index) {
|
||||
return texGenQStates[index];
|
||||
}
|
||||
|
||||
public Matrix4fStack getTextureUnitMatrix(int index) {
|
||||
return textureMatricies[index];
|
||||
}
|
||||
@@ -44,6 +87,12 @@ public class TextureUnitArray {
|
||||
for (int i = 0; i < GLStateManager.MAX_TEXTURE_UNITS; i++) {
|
||||
if (!bindings[i].sameAs(textureUnitArray.bindings[i])) return false;
|
||||
if (!states[i].sameAs(textureUnitArray.states[i])) return false;
|
||||
if (!texture1DStates[i].sameAs(textureUnitArray.texture1DStates[i])) return false;
|
||||
if (!texture3DStates[i].sameAs(textureUnitArray.texture3DStates[i])) return false;
|
||||
if (!texGenSStates[i].sameAs(textureUnitArray.texGenSStates[i])) return false;
|
||||
if (!texGenTStates[i].sameAs(textureUnitArray.texGenTStates[i])) return false;
|
||||
if (!texGenRStates[i].sameAs(textureUnitArray.texGenRStates[i])) return false;
|
||||
if (!texGenQStates[i].sameAs(textureUnitArray.texGenQStates[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class TextureInfo {
|
||||
protected int width = -1;
|
||||
protected int height = -1;
|
||||
|
||||
@Getter @Setter protected int minFilter = GL11.GL_NEAREST_MIPMAP_LINEAR;
|
||||
@Getter @Setter protected int minFilter = GL11.GL_LINEAR_MIPMAP_LINEAR;
|
||||
@Getter @Setter protected int magFilter = GL11.GL_LINEAR;
|
||||
@Getter @Setter protected int wrapS = GL11.GL_REPEAT;
|
||||
@Getter @Setter protected int wrapT = GL11.GL_REPEAT;
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public final class AngelicaRedirector {
|
||||
"net/minecraft/block/material/"
|
||||
};
|
||||
|
||||
private static final ClassConstantPoolParser cstPoolParser = new ClassConstantPoolParser(GL11, GL13, GL14, OpenGlHelper, EXTBlendFunc, ARBMultiTexture, BlockPackage, Project);
|
||||
private static final ClassConstantPoolParser cstPoolParser = new ClassConstantPoolParser(GL11, GL13, GL14, GL20, OpenGlHelper, EXTBlendFunc, ARBMultiTexture, BlockPackage, Project);
|
||||
private static final Map<String, Map<String, String>> methodRedirects = new HashMap<>();
|
||||
private static final Map<Integer, String> glCapRedirects = new HashMap<>();
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public class MipmapHelper {
|
||||
int mipmaps = useMipmapsForTexture(textureName) ? getMipmapLevels(width, height, 1) : 0;
|
||||
logger.finer("setupTexture(%s) %dx%d %d mipmaps", textureName, width, height, mipmaps);
|
||||
int magFilter = blur ? GL11.GL_LINEAR : GL11.GL_NEAREST;
|
||||
int minFilter = mipmaps > 0 ? GL11.GL_NEAREST_MIPMAP_LINEAR : magFilter;
|
||||
int minFilter = mipmaps > 0 ? GL11.GL_LINEAR_MIPMAP_LINEAR : magFilter;
|
||||
int wrap = clamp ? GL11.GL_CLAMP : GL11.GL_REPEAT;
|
||||
if (mipmaps > 0) {
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, mipmaps);
|
||||
|
||||
@@ -222,6 +222,10 @@ public class ShaderTransformer {
|
||||
for (var entry : types.entrySet()) {
|
||||
String formattedShader = getFormattedShader(entry.getValue(), prepatched.get(entry.getKey()));
|
||||
|
||||
// Restore identifiers that were temporarily renamed to dodge GLSL reserved keywords.
|
||||
formattedShader = formattedShader.replace("iris_renamed_texture", "texture");
|
||||
formattedShader = formattedShader.replace("iris_renamed_sample", "sample");
|
||||
|
||||
// Please don't mind the entire rest of this loop basically, we're doing awful fragile regex on the transformed
|
||||
// shader output to do things that I can't figure out with AST because I'm bad at it
|
||||
|
||||
|
||||
@@ -13,6 +13,13 @@ public class BufferFlipper {
|
||||
}
|
||||
|
||||
public void flip(int target) {
|
||||
// colortex6 carries material/mask data that the gbuffer populates every frame.
|
||||
// If we allow it to flip, the alternate texture remains empty and later copy-back
|
||||
// wipes the fresh mask, breaking TAA mask lookups (notably on foliage/transparents).
|
||||
if (target == 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!flippedBuffers.remove(target)) {
|
||||
// If the target wasn't in the set, add it to the set.
|
||||
flippedBuffers.add(target);
|
||||
|
||||
@@ -49,6 +49,7 @@ public class FinalPassRenderer {
|
||||
@Nullable
|
||||
private final Pass finalPass;
|
||||
private final ImmutableList<SwapPass> swapPasses;
|
||||
private final ImmutableSet<Integer> flippedBuffers;
|
||||
private final GlFramebuffer baseline;
|
||||
private final GlFramebuffer colorHolder;
|
||||
private int lastColorTextureId;
|
||||
@@ -72,6 +73,7 @@ public class FinalPassRenderer {
|
||||
|
||||
this.noiseTexture = noiseTexture;
|
||||
this.renderTargets = renderTargets;
|
||||
this.flippedBuffers = flippedBuffers;
|
||||
this.customUniforms = customUniforms;
|
||||
this.finalPass = pack.getCompositeFinal().map(source -> {
|
||||
Pass pass = new Pass();
|
||||
@@ -101,23 +103,37 @@ public class FinalPassRenderer {
|
||||
// TODO: We don't actually fully swap the content, we merely copy it from alt to main
|
||||
// This works for the most part, but it's not perfect. A better approach would be creating secondary
|
||||
// framebuffers for every other frame, but that would be a lot more complex...
|
||||
ImmutableList.Builder<SwapPass> swapPasses = ImmutableList.builder();
|
||||
final ImmutableList.Builder<SwapPass> swapPasses = ImmutableList.builder();
|
||||
|
||||
flippedBuffers.forEach(i -> {
|
||||
int target = i;
|
||||
// BUG FIX: Swap passes are only needed for NON-flipped buffers that might flip in the future.
|
||||
// Flipped buffers use ping-pong mechanism - no swap needed.
|
||||
// Original code created swaps for ALL flippedAtLeastOnce buffers and copied ALT→MAIN,
|
||||
// which destroyed fresh data in MAIN for currently-flipped buffers (breaking TAA).
|
||||
// Fixed: Only create swaps for buffers that are in flippedAtLeastOnce but NOT currently flipped.
|
||||
flippedAtLeastOnce.forEach(i -> {
|
||||
final int target = i;
|
||||
|
||||
// Skip buffer 6 (material mask) - gbuffers always write to MAIN, never flipped
|
||||
if (target == 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip buffers that are currently flipped - they use ping-pong, no swap needed
|
||||
if (flippedBuffers.contains(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffersToBeCleared.contains(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SwapPass swap = new SwapPass();
|
||||
RenderTarget target1 = renderTargets.get(target);
|
||||
final SwapPass swap = new SwapPass();
|
||||
final RenderTarget target1 = renderTargets.get(target);
|
||||
swap.target = target;
|
||||
swap.width = target1.getWidth();
|
||||
swap.height = target1.getHeight();
|
||||
// Non-flipped buffers write to ALT, copy ALT→MAIN to preserve data
|
||||
swap.from = renderTargets.createColorFramebuffer(ImmutableSet.of(), new int[] {target});
|
||||
// NB: This is handled in RenderTargets now.
|
||||
//swap.from.readBuffer(target);
|
||||
swap.targetTexture = renderTargets.get(target).getMainTexture();
|
||||
|
||||
swapPasses.add(swap);
|
||||
@@ -264,8 +280,10 @@ public class FinalPassRenderer {
|
||||
|
||||
public void recalculateSwapPassSize() {
|
||||
for (SwapPass swapPass : swapPasses) {
|
||||
RenderTarget target = renderTargets.get(swapPass.target);
|
||||
final RenderTarget target = renderTargets.get(swapPass.target);
|
||||
renderTargets.destroyFramebuffer(swapPass.from);
|
||||
// Match constructor logic - swap passes are only for non-flipped buffers
|
||||
// Copy ALT→MAIN to preserve data written to ALT
|
||||
swapPass.from = renderTargets.createColorFramebuffer(ImmutableSet.of(), new int[] {swapPass.target});
|
||||
swapPass.width = target.getWidth();
|
||||
swapPass.height = target.getHeight();
|
||||
@@ -274,7 +292,7 @@ public class FinalPassRenderer {
|
||||
}
|
||||
|
||||
private static void setupMipmapping(RenderTarget target, boolean readFromAlt) {
|
||||
int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();
|
||||
final int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();
|
||||
|
||||
// TODO: Only generate the mipmap if a valid mipmap hasn't been generated or if we've written to the buffer
|
||||
// (since the last mipmap was generated)
|
||||
@@ -319,13 +337,13 @@ public class FinalPassRenderer {
|
||||
source.getVertexSource().orElseThrow(NullPointerException::new),
|
||||
source.getGeometrySource().orElse(null),
|
||||
source.getFragmentSource().orElseThrow(NullPointerException::new));
|
||||
String vertex = transformed.get(PatchShaderType.VERTEX);
|
||||
String geometry = transformed.get(PatchShaderType.GEOMETRY);
|
||||
String fragment = transformed.get(PatchShaderType.FRAGMENT);
|
||||
final String vertex = transformed.get(PatchShaderType.VERTEX);
|
||||
final String geometry = transformed.get(PatchShaderType.GEOMETRY);
|
||||
final String fragment = transformed.get(PatchShaderType.FRAGMENT);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment);
|
||||
|
||||
Objects.requireNonNull(flipped);
|
||||
ProgramBuilder builder;
|
||||
final ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment,
|
||||
@@ -337,7 +355,7 @@ public class FinalPassRenderer {
|
||||
|
||||
this.customUniforms.assignTo(builder);
|
||||
|
||||
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
|
||||
final ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder);
|
||||
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flipped, renderTargets, true);
|
||||
@@ -361,15 +379,15 @@ public class FinalPassRenderer {
|
||||
}
|
||||
|
||||
private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot, Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
|
||||
ComputeProgram[] programs = new ComputeProgram[compute.length];
|
||||
final ComputeProgram[] programs = new ComputeProgram[compute.length];
|
||||
for (int i = 0; i < programs.length; i++) {
|
||||
ComputeSource source = compute[i];
|
||||
final ComputeSource source = compute[i];
|
||||
if (source == null || !source.getSource().isPresent()) {
|
||||
continue;
|
||||
} else {
|
||||
// TODO: Properly handle empty shaders
|
||||
Objects.requireNonNull(flipped);
|
||||
ProgramBuilder builder;
|
||||
final ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), source.getSource().orElse(null), IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import com.gtnewhorizons.angelica.AngelicaExtension;
|
||||
import com.gtnewhorizons.angelica.util.GLBit;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.lwjgl.BufferUtils;
|
||||
@@ -14,6 +16,7 @@ import org.lwjgl.opengl.GL20;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.gtnewhorizons.angelica.util.GLSMUtil.resetGLState;
|
||||
import static com.gtnewhorizons.angelica.util.GLSMUtil.verifyIsEnabled;
|
||||
import static com.gtnewhorizons.angelica.util.GLSMUtil.verifyLightState;
|
||||
import static com.gtnewhorizons.angelica.util.GLSMUtil.verifyNotDefaultState;
|
||||
@@ -22,6 +25,18 @@ import static com.gtnewhorizons.angelica.util.GLSMUtil.verifyState;
|
||||
@ExtendWith(AngelicaExtension.class)
|
||||
class GLSM_PushPop_UnitTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
// Reset GL state before each test to ensure clean starting point
|
||||
resetGLState();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
// Reset GL state after each test to prevent contamination
|
||||
resetGLState();
|
||||
}
|
||||
|
||||
public static final boolean[] BOOLEAN_ARRAY_4_TRUE = { true, true, true, true };
|
||||
public static final boolean[] BOOLEAN_ARRAY_4_FALSE = { false, false, false, false };
|
||||
public static final float[] FLOAT_ARRAY_3_001 = { 0f, 0f, 1f };
|
||||
@@ -110,10 +125,6 @@ class GLSM_PushPop_UnitTest {
|
||||
verifyState(GL11.GL_CURRENT_COLOR, FLOAT_ARRAY_4_POINT_5, "Current Color - (Not) Reset"); // This does not get reset
|
||||
verifyState(GL11.GL_COLOR_WRITEMASK, BOOLEAN_ARRAY_4_TRUE, "Color Write Mask - Reset");
|
||||
verifyState(GL11.GL_COLOR_CLEAR_VALUE, FLOAT_ARRAY_4_0, "Color Clear Value - Reset");
|
||||
|
||||
// Reset State
|
||||
GLStateManager.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,6 +255,7 @@ class GLSM_PushPop_UnitTest {
|
||||
bits.add(new GLBit(GL11.GL_POLYGON_OFFSET_POINT, "Polygon Offset Point", false));
|
||||
bits.add(new GLBit(GL11.GL_POLYGON_SMOOTH, "Polygon Smooth", false));
|
||||
bits.add(new GLBit(GL11.GL_POLYGON_STIPPLE, "Polygon Stipple", false));
|
||||
bits.add(new GLBit(GL12.GL_RESCALE_NORMAL, "Rescale Normal", false));
|
||||
bits.add(new GLBit(GL13.GL_SAMPLE_ALPHA_TO_COVERAGE, "Sample Alpha To Coverage", false));
|
||||
bits.add(new GLBit(GL13.GL_SAMPLE_ALPHA_TO_ONE, "Sample Alpha To One", false));
|
||||
bits.add(new GLBit(GL13.GL_SAMPLE_COVERAGE, "Sample Coverage", false));
|
||||
@@ -270,17 +282,7 @@ class GLSM_PushPop_UnitTest {
|
||||
|
||||
GLStateManager.glPopAttrib();
|
||||
|
||||
//glEnable(GL_COLOR_MATERIAL) changes the material color state when it is triggered. We need to reset that
|
||||
//here to not mess up the default state for other tests. We're not resetting with glPush/PopAttrib because
|
||||
//we're specifically trying to test GL_ENABLE_BIT here.
|
||||
FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(16);
|
||||
floatBuffer.put(0.2F).put(0.2F).put(0.2F).put(1.0F).flip();
|
||||
GLStateManager.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT, floatBuffer);
|
||||
floatBuffer.put(0.8F).put(0.8F).put(0.8F).put(1.0F).flip();
|
||||
GLStateManager.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_DIFFUSE, floatBuffer);
|
||||
|
||||
bits.forEach(bit -> verifyState(bit.glEnum(), bit.initial(), bit.name() + " Reset State"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.gtnewhorizons.angelica.util;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
@@ -15,6 +17,27 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
public class GLSMUtil {
|
||||
|
||||
// Cached GL limits (queried once at class load time)
|
||||
private static final int MAX_CLIP_PLANES = GL11.glGetInteger(GL11.GL_MAX_CLIP_PLANES);
|
||||
private static final int MAX_LIGHTS = GL11.glGetInteger(GL11.GL_MAX_LIGHTS);
|
||||
private static final int MAX_TEXTURE_UNITS = GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS);
|
||||
|
||||
// MAP1 evaluator constants for DRY loops
|
||||
private static final int[] MAP1_STATES = {
|
||||
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
|
||||
};
|
||||
|
||||
// MAP2 evaluator constants for DRY loops
|
||||
private static final int[] MAP2_STATES = {
|
||||
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
|
||||
};
|
||||
|
||||
public static void verifyIsEnabled(int glCap, boolean expected) {
|
||||
verifyIsEnabled(glCap, expected, "Is Enabled Mismatch");
|
||||
}
|
||||
@@ -133,4 +156,99 @@ public class GLSMUtil {
|
||||
() -> assertEquals(expected[i], glsmFloatBuffer.get(i), 0.0001f, "GLSM State Mismatch: " + i)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all GL state to known defaults to prevent test contamination.
|
||||
* This should be called at the end of tests that modify a lot of state.
|
||||
*/
|
||||
public static void resetGLState() {
|
||||
// Disable all enable/disable states (except those with non-false defaults)
|
||||
GLStateManager.disableAlphaTest();
|
||||
GLStateManager.glDisable(GL11.GL_AUTO_NORMAL);
|
||||
GLStateManager.disableBlend();
|
||||
|
||||
// Disable all clip planes (using cached MAX_CLIP_PLANES)
|
||||
for(int i = 0; i < MAX_CLIP_PLANES; i++) {
|
||||
GLStateManager.glDisable(GL11.GL_CLIP_PLANE0 + i);
|
||||
}
|
||||
|
||||
GLStateManager.disableColorMaterial();
|
||||
GLStateManager.glDisable(GL11.GL_COLOR_LOGIC_OP);
|
||||
GLStateManager.disableCull();
|
||||
GLStateManager.disableDepthTest();
|
||||
// GL_DITHER defaults to true
|
||||
GLStateManager.glEnable(GL11.GL_DITHER);
|
||||
GLStateManager.disableFog();
|
||||
GLStateManager.glDisable(GL11.GL_INDEX_LOGIC_OP);
|
||||
GLStateManager.disableLighting();
|
||||
|
||||
// Disable all lights (using cached MAX_LIGHTS)
|
||||
for(int i = 0; i < MAX_LIGHTS; i++) {
|
||||
GLStateManager.disableLight(i);
|
||||
}
|
||||
|
||||
GLStateManager.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
GLStateManager.glDisable(GL11.GL_LINE_STIPPLE);
|
||||
|
||||
// Disable all MAP1 evaluators (DRY loop)
|
||||
for(int state : MAP1_STATES) {
|
||||
GLStateManager.glDisable(state);
|
||||
}
|
||||
|
||||
// Disable all MAP2 evaluators (DRY loop)
|
||||
for(int state : MAP2_STATES) {
|
||||
GLStateManager.glDisable(state);
|
||||
}
|
||||
|
||||
// GL_MULTISAMPLE defaults to true (but may vary by driver)
|
||||
// We'll query the actual default rather than assume
|
||||
if(GL11.glIsEnabled(GL13.GL_MULTISAMPLE)) {
|
||||
GLStateManager.glEnable(GL13.GL_MULTISAMPLE);
|
||||
} else {
|
||||
GLStateManager.glDisable(GL13.GL_MULTISAMPLE);
|
||||
}
|
||||
|
||||
GLStateManager.glDisable(GL11.GL_NORMALIZE);
|
||||
GLStateManager.glDisable(GL11.GL_POINT_SMOOTH);
|
||||
GLStateManager.glDisable(GL11.GL_POLYGON_OFFSET_POINT);
|
||||
GLStateManager.glDisable(GL11.GL_POLYGON_OFFSET_LINE);
|
||||
GLStateManager.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
GLStateManager.glDisable(GL11.GL_POLYGON_SMOOTH);
|
||||
GLStateManager.glDisable(GL11.GL_POLYGON_STIPPLE);
|
||||
GLStateManager.disableRescaleNormal();
|
||||
GLStateManager.glDisable(GL13.GL_SAMPLE_ALPHA_TO_COVERAGE);
|
||||
GLStateManager.glDisable(GL13.GL_SAMPLE_ALPHA_TO_ONE);
|
||||
GLStateManager.glDisable(GL13.GL_SAMPLE_COVERAGE);
|
||||
GLStateManager.disableScissorTest();
|
||||
GLStateManager.glDisable(GL11.GL_STENCIL_TEST);
|
||||
|
||||
// Reset texture state for all units (using cached MAX_TEXTURE_UNITS)
|
||||
for(int i = 0; i < MAX_TEXTURE_UNITS; i++) {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + i);
|
||||
GLStateManager.glDisable(GL11.GL_TEXTURE_1D);
|
||||
GLStateManager.disableTexture(); // GL_TEXTURE_2D
|
||||
GLStateManager.glDisable(GL12.GL_TEXTURE_3D);
|
||||
GLStateManager.glDisable(GL11.GL_TEXTURE_GEN_S);
|
||||
GLStateManager.glDisable(GL11.GL_TEXTURE_GEN_T);
|
||||
GLStateManager.glDisable(GL11.GL_TEXTURE_GEN_R);
|
||||
GLStateManager.glDisable(GL11.GL_TEXTURE_GEN_Q);
|
||||
}
|
||||
|
||||
// Reset to texture unit 0
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
|
||||
// Reset matrix mode to default
|
||||
GLStateManager.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
|
||||
// Reset color to white
|
||||
GLStateManager.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
// Reset material colors to defaults (fixes GL_COLOR_MATERIAL side effects)
|
||||
FloatBuffer materialBuffer = BufferUtils.createFloatBuffer(4);
|
||||
materialBuffer.put(0.2F).put(0.2F).put(0.2F).put(1.0F).flip();
|
||||
GLStateManager.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT, materialBuffer);
|
||||
materialBuffer.clear();
|
||||
materialBuffer.put(0.8F).put(0.8F).put(0.8F).put(1.0F).flip();
|
||||
GLStateManager.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_DIFFUSE, materialBuffer);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user