package openonyx.render; import java.nio.FloatBuffer; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; public final class ScissorStack { private static final float[] D; private static final int[] c; private static final FloatBuffer FLOAT_BUFFER = BufferUtils.createFloatBuffer(16); private static float k; private static float g; private static final float[] M; private static boolean L; private static final float j = 1.0E-4F; private static final float[] m; private static boolean h; private static final float[] l; private static final FloatBuffer FLOAT_BUFFER2 = BufferUtils.createFloatBuffer(16); private static final float[] d; private static float i; private static final float[] f; private static float H; private static final float[] e; static { float[] fx = new float[6]; boolean bl = true; fx[0] = -1.8F; fx[1] = -1.8F; fx[2] = -1.8F; fx[3] = 1.8F; fx[4] = 1.8F; fx[5] = 1.8F; e = fx; fx = new float[6]; bl = true; fx[0] = -0.62F; fx[1] = -0.12F; fx[2] = -0.25F; fx[3] = -0.13F; fx[4] = 0.87F; fx[5] = 0.25F; d = fx; fx = new float[6]; bl = true; fx[0] = -0.62F; fx[1] = -0.58F; fx[2] = -0.6F; fx[3] = -0.13F; fx[4] = 0.83F; fx[5] = 0.6F; m = fx; int[] ix = new int[24]; bl = true; ix[0] = 0; ix[1] = 1; ix[2] = 2; ix[3] = 3; ix[4] = 4; ix[5] = 5; ix[6] = 6; ix[7] = 7; ix[8] = 0; ix[9] = 2; ix[10] = 1; ix[11] = 3; ix[12] = 4; ix[13] = 6; ix[14] = 5; ix[15] = 7; ix[16] = 0; ix[17] = 4; ix[18] = 1; ix[19] = 5; ix[20] = 2; ix[21] = 6; ix[22] = 3; ix[23] = 7; c = ix; fx = new float[8]; bl = true; f = fx; fx = new float[8]; bl = true; M = fx; fx = new float[8]; bl = true; D = fx; fx = new float[8]; bl = true; l = fx; } private static void L(float[] f) { float[] gx = fx; FLOAT_BUFFER2.clear(); FLOAT_BUFFER.clear(); GL11.glGetFloat(2982, FLOAT_BUFFER2); GL11.glGetFloat(2983, FLOAT_BUFFER); int o = 0; for (int u = o; u < 8; u = o) { float hx = gx[(o & 1) == 0 ? 0 : 3]; float ix = gx[(o & 2) == 0 ? 1 : 4]; float jx = gx[(o & 4) == 0 ? 2 : 5]; float kx = FLOAT_BUFFER2.get(0) * hx + FLOAT_BUFFER2.get(4) * ix + FLOAT_BUFFER2.get(8) * jx + FLOAT_BUFFER2.get(12); float lx = FLOAT_BUFFER2.get(1) * hx + FLOAT_BUFFER2.get(5) * ix + FLOAT_BUFFER2.get(9) * jx + FLOAT_BUFFER2.get(13); float mx = FLOAT_BUFFER2.get(2) * hx + FLOAT_BUFFER2.get(6) * ix + FLOAT_BUFFER2.get(10) * jx + FLOAT_BUFFER2.get(14); f[o] = FLOAT_BUFFER.get(0) * kx + FLOAT_BUFFER.get(4) * lx + FLOAT_BUFFER.get(8) * mx + FLOAT_BUFFER.get(12); M[o] = FLOAT_BUFFER.get(1) * kx + FLOAT_BUFFER.get(5) * lx + FLOAT_BUFFER.get(9) * mx + FLOAT_BUFFER.get(13); float n = FLOAT_BUFFER.get(2) * kx + FLOAT_BUFFER.get(6) * lx + FLOAT_BUFFER.get(10) * mx + FLOAT_BUFFER.get(14); D[o] = FLOAT_BUFFER.get(3) * kx + FLOAT_BUFFER.get(7) * lx + FLOAT_BUFFER.get(11) * mx + FLOAT_BUFFER.get(15); int v = o; float w = n + D[o]; o++; l[v] = w; } for (int t = p = 0; t < 8; t = ++p) { if (l[p] >= 0.0F) { L(f[p], M[p], D[p]); } } for (byte cx = b = 0; cx < c.length; cx = b) { int q = c[b]; int r = c[b + 1]; if (l[q] >= 0.0F != l[r] >= 0.0F) { float s = l[q] / (l[q] - l[r]); L(f[q] + (f[r] - f[q]) * s, M[q] + (M[r] - M[q]) * s, D[q] + (D[r] - D[q]) * s); } b += 2; } } public static void D() { h = false; } public static void d() { if (L) { L = false; GL11.glDisable(3089); } } public static void L(float f, int i, int j) { if (h) { int lx = Math.clamp((int)Math.floor(k * ix - fx), 0, ix); int kx = Math.clamp((int)Math.floor(i * jx - fx), 0, jx); ix = Math.clamp((int)Math.ceil(g * ix + fx), lx, ix); jx = Math.clamp((int)Math.ceil(H * jx + fx), kx, jx); if (ix > lx && jx > kx) { GL11.glEnable(3089); GL11.glScissor(lx, kx, ix - lx, jx - kx); L = true; } } } private static void L(float f, float g, float h) { if (hx > 1.0E-4F) { float ix = fx / hx * 0.5F + 0.5F; gx = gx / hx * 0.5F + 0.5F; if (Float.isFinite(ix) && Float.isFinite(gx)) { if (h) { k = Math.min(k, ix); i = Math.min(i, gx); g = Math.max(g, ix); H = Math.max(H, gx); } else { k = ix; i = gx; g = ix; H = gx; h = true; } } } } public static void L() { L(e); } private ScissorStack() { } public static boolean L() { return h; } public static void L(boolean bl) { L(bl ? m : d); } }