diff --git a/dependencies.gradle b/dependencies.gradle index a3e23b51f..aa28f288d 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -72,7 +72,7 @@ dependencies { // Iris Shaders compileOnly('org.jetbrains:annotations:26.0.2') - api("com.github.GTNewHorizons:GTNHLib:0.9.33:dev") + api("com.github.GTNewHorizons:GTNHLib:0.9.36:dev") shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0 shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-26.g5ee7d96-GTNH") { diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaCylinder.java b/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaCylinder.java new file mode 100644 index 000000000..5063a98a0 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaCylinder.java @@ -0,0 +1,142 @@ +package com.gtnewhorizons.angelica.glsm.compat.lwjgl; + +import com.gtnewhorizons.angelica.glsm.GLStateManager; +import org.lwjgl.util.glu.Cylinder; + +import static org.lwjgl.opengl.GL11.GL_LINES; +import static org.lwjgl.opengl.GL11.GL_LINE_LOOP; +import static org.lwjgl.opengl.GL11.GL_POINTS; +import static org.lwjgl.opengl.GL11.GL_TRIANGLE_STRIP; +import static org.lwjgl.util.glu.GLU.GLU_FILL; +import static org.lwjgl.util.glu.GLU.GLU_INSIDE; +import static org.lwjgl.util.glu.GLU.GLU_LINE; +import static org.lwjgl.util.glu.GLU.GLU_POINT; +import static org.lwjgl.util.glu.GLU.GLU_SILHOUETTE; + +/** + * Core-profile compatible replacement for {@link Cylinder}. + */ +@SuppressWarnings("unused") +public class AngelicaCylinder extends Cylinder { + + private static final float PI = (float) Math.PI; + + private void emitNormal(float x, float y, float z) { + final float mag = (float) Math.sqrt(x * x + y * y + z * z); + if (mag > 0.00001F) { + x /= mag; + y /= mag; + z /= mag; + } + GLStateManager.glNormal3f(x, y, z); + } + + private void emitTexCoord(float x, float y) { + if (super.textureFlag) GLStateManager.glTexCoord2f(x, y); + } + + @Override + public void draw(float baseRadius, float topRadius, float height, int slices, int stacks) { + final float da, dr, dz, nz, nsign; + float r, x, y, z; + + nsign = (super.orientation == GLU_INSIDE) ? -1.0f : 1.0f; + + da = 2.0f * PI / slices; + dr = (topRadius - baseRadius) / stacks; + dz = height / stacks; + nz = (baseRadius - topRadius) / height; + + if (super.drawStyle == GLU_POINT) { + GLStateManager.glBegin(GL_POINTS); + for (int i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + emitNormal(x * nsign, y * nsign, nz * nsign); + + z = 0.0f; + r = baseRadius; + for (int j = 0; j <= stacks; j++) { + GLStateManager.glVertex3f(x * r, y * r, z); + z += dz; + r += dr; + } + } + GLStateManager.glEnd(); + } else if (super.drawStyle == GLU_LINE || super.drawStyle == GLU_SILHOUETTE) { + // Draw rings + if (super.drawStyle == GLU_LINE) { + z = 0.0f; + r = baseRadius; + for (int j = 0; j <= stacks; j++) { + GLStateManager.glBegin(GL_LINE_LOOP); + for (int i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + emitNormal(x * nsign, y * nsign, nz * nsign); + GLStateManager.glVertex3f(x * r, y * r, z); + } + GLStateManager.glEnd(); + z += dz; + r += dr; + } + } else { + // draw one ring at each end + if (baseRadius != 0.0) { + GLStateManager.glBegin(GL_LINE_LOOP); + for (int i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + emitNormal(x * nsign, y * nsign, nz * nsign); + GLStateManager.glVertex3f(x * baseRadius, y * baseRadius, 0.0f); + } + GLStateManager.glEnd(); + GLStateManager.glBegin(GL_LINE_LOOP); + for (int i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + emitNormal(x * nsign, y * nsign, nz * nsign); + GLStateManager.glVertex3f(x * topRadius, y * topRadius, height); + } + GLStateManager.glEnd(); + } + } + // draw length lines + GLStateManager.glBegin(GL_LINES); + for (int i = 0; i < slices; i++) { + x = cos(i * da); + y = sin(i * da); + emitNormal(x * nsign, y * nsign, nz * nsign); + GLStateManager.glVertex3f(x * baseRadius, y * baseRadius, 0.0f); + GLStateManager.glVertex3f(x * topRadius, y * topRadius, height); + } + GLStateManager.glEnd(); + } else if (super.drawStyle == GLU_FILL) { + final float ds = 1.0f / slices; + final float dt = 1.0f / stacks; + float t = 0.0f; + z = 0.0f; + r = baseRadius; + for (int j = 0; j < stacks; j++) { + float s = 0.0f; + GLStateManager.glBegin(GL_TRIANGLE_STRIP); + for (int i = 0; i <= slices; i++) { + final float angle = (i == slices) ? 0.0f : i * da; + x = sin(angle); + y = cos(angle); + emitNormal(x * nsign, y * nsign, nz * nsign); + emitTexCoord(s, t); + GLStateManager.glVertex3f(x * r, y * r, z); + emitNormal(x * nsign, y * nsign, nz * nsign); + emitTexCoord(s, t + dt); + GLStateManager.glVertex3f(x * (r + dr), y * (r + dr), z + dz); + s += ds; + } + GLStateManager.glEnd(); + r += dr; + t += dt; + z += dz; + } + } + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaDisk.java b/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaDisk.java new file mode 100644 index 000000000..1c6e59dd2 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaDisk.java @@ -0,0 +1,134 @@ +package com.gtnewhorizons.angelica.glsm.compat.lwjgl; + +import com.gtnewhorizons.angelica.glsm.GLStateManager; +import org.lwjgl.util.glu.Disk; + +import static org.lwjgl.opengl.GL11.GL_LINE_LOOP; +import static org.lwjgl.opengl.GL11.GL_LINE_STRIP; +import static org.lwjgl.opengl.GL11.GL_POINTS; +import static org.lwjgl.opengl.GL11.GL_TRIANGLE_STRIP; +import static org.lwjgl.util.glu.GLU.GLU_FILL; +import static org.lwjgl.util.glu.GLU.GLU_LINE; +import static org.lwjgl.util.glu.GLU.GLU_NONE; +import static org.lwjgl.util.glu.GLU.GLU_OUTSIDE; +import static org.lwjgl.util.glu.GLU.GLU_POINT; +import static org.lwjgl.util.glu.GLU.GLU_SILHOUETTE; + +/** + * Core-profile compatible replacement for {@link Disk}. + */ +@SuppressWarnings("unused") +public class AngelicaDisk extends Disk { + + private static final float PI = (float) Math.PI; + + private void emitTexCoord(float x, float y) { + if (super.textureFlag) GLStateManager.glTexCoord2f(x, y); + } + + @Override + public void draw(float innerRadius, float outerRadius, int slices, int loops) { + final float da, dr; + + if (super.normals != GLU_NONE) { + GLStateManager.glNormal3f(0.0f, 0.0f, (super.orientation == GLU_OUTSIDE) ? 1.0f : -1.0f); + } + + da = 2.0f * PI / slices; + dr = (outerRadius - innerRadius) / loops; + + switch (super.drawStyle) { + case GLU_FILL -> { + final float dtc = 2.0f * outerRadius; + float sa, ca; + float r1 = innerRadius; + for (int l = 0; l < loops; l++) { + final float r2 = r1 + dr; + if (super.orientation == GLU_OUTSIDE) { + GLStateManager.glBegin(GL_TRIANGLE_STRIP); + for (int s = 0; s <= slices; s++) { + final float a = (s == slices) ? 0.0f : s * da; + sa = sin(a); + ca = cos(a); + emitTexCoord(0.5f + sa * r2 / dtc, 0.5f + ca * r2 / dtc); + GLStateManager.glVertex2f(r2 * sa, r2 * ca); + emitTexCoord(0.5f + sa * r1 / dtc, 0.5f + ca * r1 / dtc); + GLStateManager.glVertex2f(r1 * sa, r1 * ca); + } + GLStateManager.glEnd(); + } else { + GLStateManager.glBegin(GL_TRIANGLE_STRIP); + for (int s = slices; s >= 0; s--) { + final float a = (s == slices) ? 0.0f : s * da; + sa = sin(a); + ca = cos(a); + emitTexCoord(0.5f - sa * r2 / dtc, 0.5f + ca * r2 / dtc); + GLStateManager.glVertex2f(r2 * sa, r2 * ca); + emitTexCoord(0.5f - sa * r1 / dtc, 0.5f + ca * r1 / dtc); + GLStateManager.glVertex2f(r1 * sa, r1 * ca); + } + GLStateManager.glEnd(); + } + r1 = r2; + } + } + case GLU_LINE -> { + /* draw loops */ + for (int l = 0; l <= loops; l++) { + final float r = innerRadius + l * dr; + GLStateManager.glBegin(GL_LINE_LOOP); + for (int s = 0; s < slices; s++) { + final float a = s * da; + GLStateManager.glVertex2f(r * sin(a), r * cos(a)); + } + GLStateManager.glEnd(); + } + /* draw spokes */ + for (int s = 0; s < slices; s++) { + final float a = s * da; + final float x = sin(a); + final float y = cos(a); + GLStateManager.glBegin(GL_LINE_STRIP); + for (int l = 0; l <= loops; l++) { + final float r = innerRadius + l * dr; + GLStateManager.glVertex2f(r * x, r * y); + } + GLStateManager.glEnd(); + } + } + case GLU_POINT -> { + GLStateManager.glBegin(GL_POINTS); + for (int s = 0; s < slices; s++) { + final float a = s * da; + final float x = sin(a); + final float y = cos(a); + for (int l = 0; l <= loops; l++) { + final float r = innerRadius * l * dr; + GLStateManager.glVertex2f(r * x, r * y); + } + } + GLStateManager.glEnd(); + } + case GLU_SILHOUETTE -> { + if (innerRadius != 0.0) { + GLStateManager.glBegin(GL_LINE_LOOP); + for (float a = 0.0f; a < 2.0 * PI; a += da) { + final float x = innerRadius * sin(a); + final float y = innerRadius * cos(a); + GLStateManager.glVertex2f(x, y); + } + GLStateManager.glEnd(); + } + GLStateManager.glBegin(GL_LINE_LOOP); + for (float a = 0; a < 2.0f * PI; a += da) { + final float x = outerRadius * sin(a); + final float y = outerRadius * cos(a); + GLStateManager.glVertex2f(x, y); + } + GLStateManager.glEnd(); + } + default -> { + } + } + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaPartialDisk.java b/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaPartialDisk.java new file mode 100644 index 000000000..e6b98e97a --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaPartialDisk.java @@ -0,0 +1,244 @@ +package com.gtnewhorizons.angelica.glsm.compat.lwjgl; + +import com.gtnewhorizons.angelica.glsm.GLStateManager; +import org.lwjgl.util.glu.PartialDisk; + +import static com.gtnewhorizons.angelica.loading.AngelicaTweaker.LOGGER; +import static org.lwjgl.opengl.GL11.GL_LINE_STRIP; +import static org.lwjgl.opengl.GL11.GL_POINTS; +import static org.lwjgl.opengl.GL11.GL_TRIANGLE_FAN; +import static org.lwjgl.opengl.GL11.GL_TRIANGLE_STRIP; +import static org.lwjgl.util.glu.GLU.GLU_FILL; +import static org.lwjgl.util.glu.GLU.GLU_FLAT; +import static org.lwjgl.util.glu.GLU.GLU_LINE; +import static org.lwjgl.util.glu.GLU.GLU_OUTSIDE; +import static org.lwjgl.util.glu.GLU.GLU_POINT; +import static org.lwjgl.util.glu.GLU.GLU_SILHOUETTE; +import static org.lwjgl.util.glu.GLU.GLU_SMOOTH; + +/** + * Core-profile compatible replacement for {@link PartialDisk}. + */ +@SuppressWarnings("unused") +public class AngelicaPartialDisk extends PartialDisk { + + private static final float PI = (float) Math.PI; + private static final int CACHE_SIZE = 240; + private final float[] sinCache = new float[CACHE_SIZE]; + private final float[] cosCache = new float[CACHE_SIZE]; + + @Override + public void draw(float innerRadius, float outerRadius, int slices, int loops, float startAngle, float sweepAngle) { + final float deltaRadius, angleOffset; + float angle, sintemp, costemp, radiusLow, radiusHigh, texLow = 0, texHigh = 0; + final int slices2, finish; + + if (slices >= CACHE_SIZE) slices = CACHE_SIZE - 1; + if (slices < 2 || loops < 1 || outerRadius <= 0.0f || innerRadius < 0.0f || innerRadius > outerRadius) { + LOGGER.warn("PartialDisk: GLU_INVALID_VALUE (slices={}, loops={}, innerRadius={}, outerRadius={})", slices, loops, innerRadius, outerRadius); + return; + } + + if (sweepAngle < -360.0f) sweepAngle = 360.0f; + if (sweepAngle > 360.0f) sweepAngle = 360.0f; + if (sweepAngle < 0) { + startAngle += sweepAngle; + sweepAngle = -sweepAngle; + } + + slices2 = (sweepAngle == 360.0f) ? slices : slices + 1; + + /* Compute length (needed for normal calculations) */ + deltaRadius = outerRadius - innerRadius; + + angleOffset = startAngle / 180.0f * PI; + for (int i = 0; i <= slices; i++) { + angle = angleOffset + ((PI * sweepAngle) / 180.0f) * i / slices; + sinCache[i] = sin(angle); + cosCache[i] = cos(angle); + } + + if (sweepAngle == 360.0f) { + sinCache[slices] = sinCache[0]; + cosCache[slices] = cosCache[0]; + } + + switch (super.normals) { + case GLU_FLAT, GLU_SMOOTH -> GLStateManager.glNormal3f(0.0f, 0.0f, (super.orientation == GLU_OUTSIDE) ? 1.0f : -1.0f); + default -> { + } + } + + switch (super.drawStyle) { + case GLU_FILL -> { + if (innerRadius == .0f) { + finish = loops - 1; + /* Triangle strip for inner polygons */ + GLStateManager.glBegin(GL_TRIANGLE_FAN); + if (super.textureFlag) { + GLStateManager.glTexCoord2f(0.5f, 0.5f); + } + GLStateManager.glVertex3f(0.0f, 0.0f, 0.0f); + radiusLow = outerRadius - deltaRadius * ((float) (loops - 1) / loops); + if (super.textureFlag) { + texLow = radiusLow / outerRadius / 2; + } + + if (super.orientation == GLU_OUTSIDE) { + for (int i = slices; i >= 0; i--) { + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + } else { + for (int i = 0; i <= slices; i++) { + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + } + GLStateManager.glEnd(); + } else { + finish = loops; + } + for (int j = 0; j < finish; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + radiusHigh = outerRadius - deltaRadius * ((float) (j + 1) / loops); + if (super.textureFlag) { + texLow = radiusLow / outerRadius / 2; + texHigh = radiusHigh / outerRadius / 2; + } + + GLStateManager.glBegin(GL_TRIANGLE_STRIP); + for (int i = 0; i <= slices; i++) { + if (super.orientation == GLU_OUTSIDE) { + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texHigh * sinCache[i] + 0.5f, texHigh * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusHigh * sinCache[i], radiusHigh * cosCache[i], 0.0f); + } else { + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texHigh * sinCache[i] + 0.5f, texHigh * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusHigh * sinCache[i], radiusHigh * cosCache[i], 0.0f); + + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + } + GLStateManager.glEnd(); + } + } + case GLU_POINT -> { + GLStateManager.glBegin(GL_POINTS); + for (int i = 0; i < slices2; i++) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + for (int j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + + if (super.textureFlag) { + texLow = radiusLow / outerRadius / 2; + + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); + } + } + GLStateManager.glEnd(); + } + case GLU_LINE -> { + if (innerRadius == outerRadius) { + GLStateManager.glBegin(GL_LINE_STRIP); + + for (int i = 0; i <= slices; i++) { + if (super.textureFlag) { + GLStateManager.glTexCoord2f(sinCache[i] / 2 + 0.5f, cosCache[i] / 2 + 0.5f); + } + GLStateManager.glVertex3f(innerRadius * sinCache[i], innerRadius * cosCache[i], 0.0f); + } + GLStateManager.glEnd(); + break; + } + for (int j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (super.textureFlag) { + texLow = radiusLow / outerRadius / 2; + } + + GLStateManager.glBegin(GL_LINE_STRIP); + for (int i = 0; i <= slices; i++) { + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + GLStateManager.glEnd(); + } + for (int i = 0; i < slices2; i++) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + GLStateManager.glBegin(GL_LINE_STRIP); + for (int j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (super.textureFlag) { + texLow = radiusLow / outerRadius / 2; + } + + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); + } + GLStateManager.glEnd(); + } + } + case GLU_SILHOUETTE -> { + if (sweepAngle < 360.0f) { + for (int i = 0; i <= slices; i += slices) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + GLStateManager.glBegin(GL_LINE_STRIP); + for (int j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + + if (super.textureFlag) { + texLow = radiusLow / outerRadius / 2; + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); + } + GLStateManager.glEnd(); + } + } + for (int j = 0; j <= loops; j += loops) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (super.textureFlag) { + texLow = radiusLow / outerRadius / 2; + } + + GLStateManager.glBegin(GL_LINE_STRIP); + for (int i = 0; i <= slices; i++) { + if (super.textureFlag) { + GLStateManager.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); + } + GLStateManager.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + } + GLStateManager.glEnd(); + if (innerRadius == outerRadius) break; + } + } + default -> { + } + } + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaSphere.java b/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaSphere.java new file mode 100644 index 000000000..deca48e9c --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/compat/lwjgl/AngelicaSphere.java @@ -0,0 +1,183 @@ +package com.gtnewhorizons.angelica.glsm.compat.lwjgl; + +import com.gtnewhorizons.angelica.glsm.GLStateManager; +import org.lwjgl.util.glu.Sphere; + +import static org.lwjgl.opengl.GL11.GL_LINE_LOOP; +import static org.lwjgl.opengl.GL11.GL_LINE_STRIP; +import static org.lwjgl.opengl.GL11.GL_POINTS; +import static org.lwjgl.opengl.GL11.GL_TRIANGLE_FAN; +import static org.lwjgl.opengl.GL11.GL_TRIANGLE_STRIP; +import static org.lwjgl.util.glu.GLU.GLU_FILL; +import static org.lwjgl.util.glu.GLU.GLU_INSIDE; +import static org.lwjgl.util.glu.GLU.GLU_LINE; +import static org.lwjgl.util.glu.GLU.GLU_NONE; +import static org.lwjgl.util.glu.GLU.GLU_POINT; +import static org.lwjgl.util.glu.GLU.GLU_SILHOUETTE; + +/** + * Core-profile compatible replacement for {@link Sphere}. + */ +@SuppressWarnings("unused") +public class AngelicaSphere extends Sphere { + + private static final float PI = (float) Math.PI; + + private void emitNormal(float x, float y, float z) { + final float mag = (float) Math.sqrt(x * x + y * y + z * z); + if (mag > 0.00001F) { + x /= mag; + y /= mag; + z /= mag; + } + GLStateManager.glNormal3f(x, y, z); + } + + private void emitTexCoord(float x, float y) { + if (super.textureFlag) GLStateManager.glTexCoord2f(x, y); + } + + @Override + public void draw(float radius, int slices, int stacks) { + final float drho, dtheta, ds, dt, nsign; + float rho, theta, x, y, z, s, t; + + final int imin, imax; + final boolean normals; + + normals = super.normals != GLU_NONE; + nsign = (super.orientation == GLU_INSIDE) ? -1.0f : 1.0f; + + drho = PI / stacks; + dtheta = 2.0f * PI / slices; + + if (super.drawStyle == GLU_FILL) { + if (!super.textureFlag) { + // draw +Z end as a triangle fan + GLStateManager.glBegin(GL_TRIANGLE_FAN); + GLStateManager.glNormal3f(0.0f, 0.0f, 1.0f); + GLStateManager.glVertex3f(0.0f, 0.0f, nsign * radius); + for (int j = 0; j <= slices; j++) { + theta = (j == slices) ? 0.0f : j * dtheta; + x = -sin(theta) * sin(drho); + y = cos(theta) * sin(drho); + z = nsign * cos(drho); + if (normals) { + emitNormal(x * nsign, y * nsign, z * nsign); + } + GLStateManager.glVertex3f(x * radius, y * radius, z * radius); + } + GLStateManager.glEnd(); + } + + ds = 1.0f / slices; + dt = 1.0f / stacks; + t = 1.0f; + if (super.textureFlag) { + imin = 0; + imax = stacks; + } else { + imin = 1; + imax = stacks - 1; + } + + // draw intermediate stacks as triangle strips (GL_QUAD_STRIP removed in core profile) + for (int i = imin; i < imax; i++) { + rho = i * drho; + GLStateManager.glBegin(GL_TRIANGLE_STRIP); + s = 0.0f; + for (int j = 0; j <= slices; j++) { + theta = (j == slices) ? 0.0f : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + if (normals) { + emitNormal(x * nsign, y * nsign, z * nsign); + } + emitTexCoord(s, t); + GLStateManager.glVertex3f(x * radius, y * radius, z * radius); + x = -sin(theta) * sin(rho + drho); + y = cos(theta) * sin(rho + drho); + z = nsign * cos(rho + drho); + if (normals) { + emitNormal(x * nsign, y * nsign, z * nsign); + } + emitTexCoord(s, t - dt); + s += ds; + GLStateManager.glVertex3f(x * radius, y * radius, z * radius); + } + GLStateManager.glEnd(); + t -= dt; + } + + if (!super.textureFlag) { + // draw -Z end as a triangle fan + GLStateManager.glBegin(GL_TRIANGLE_FAN); + GLStateManager.glNormal3f(0.0f, 0.0f, -1.0f); + GLStateManager.glVertex3f(0.0f, 0.0f, -radius * nsign); + rho = PI - drho; + s = 1.0f; + for (int j = slices; j >= 0; j--) { + theta = (j == slices) ? 0.0f : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + if (normals) emitNormal(x * nsign, y * nsign, z * nsign); + s -= ds; + GLStateManager.glVertex3f(x * radius, y * radius, z * radius); + } + GLStateManager.glEnd(); + } + } else if (super.drawStyle == GLU_LINE || super.drawStyle == GLU_SILHOUETTE) { + // draw stack lines + for (int i = 1; i < stacks; i++) { + rho = i * drho; + GLStateManager.glBegin(GL_LINE_LOOP); + for (int j = 0; j < slices; j++) { + theta = j * dtheta; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) emitNormal(x * nsign, y * nsign, z * nsign); + GLStateManager.glVertex3f(x * radius, y * radius, z * radius); + } + GLStateManager.glEnd(); + } + // draw slice lines + for (int j = 0; j < slices; j++) { + theta = j * dtheta; + GLStateManager.glBegin(GL_LINE_STRIP); + for (int i = 0; i <= stacks; i++) { + rho = i * drho; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) emitNormal(x * nsign, y * nsign, z * nsign); + GLStateManager.glVertex3f(x * radius, y * radius, z * radius); + } + GLStateManager.glEnd(); + } + } else if (super.drawStyle == GLU_POINT) { + // top and bottom-most points + GLStateManager.glBegin(GL_POINTS); + if (normals) GLStateManager.glNormal3f(0.0f, 0.0f, nsign); + GLStateManager.glVertex3f(0.0f, 0.0f, radius); + if (normals) GLStateManager.glNormal3f(0.0f, 0.0f, -nsign); + GLStateManager.glVertex3f(0.0f, 0.0f, -radius); + + // loop over stacks + for (int i = 1; i < stacks - 1; i++) { + rho = i * drho; + for (int j = 0; j < slices; j++) { + theta = j * dtheta; + x = cos(theta) * sin(rho); + y = sin(theta) * sin(rho); + z = cos(rho); + if (normals) emitNormal(x * nsign, y * nsign, z * nsign); + GLStateManager.glVertex3f(x * radius, y * radius, z * radius); + } + } + GLStateManager.glEnd(); + } + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/loading/AngelicaTweaker.java b/src/main/java/com/gtnewhorizons/angelica/loading/AngelicaTweaker.java index 8ea81bd00..ef767a0dd 100644 --- a/src/main/java/com/gtnewhorizons/angelica/loading/AngelicaTweaker.java +++ b/src/main/java/com/gtnewhorizons/angelica/loading/AngelicaTweaker.java @@ -81,6 +81,17 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader { throw new RuntimeException(e); } verifyDependencies(); + + // Register a scoped redirector early so classes prematurely loaded by other coremods during discovery/injectData + // (e.g. Mycelium using HookLoader.class.getName()) still get GL calls redirected to GLSM. Only targets specific mod + // packages to avoid interfering with mixin delegation on game classes. AngelicaLateTweaker removes this registration once + // mixins are setup. + if (FMLLaunchHandler.side().isClient()) { + final boolean rfbLoaded = Launch.blackboard.getOrDefault("angelica.rfbPluginLoaded", Boolean.FALSE) == Boolean.TRUE; + if (!rfbLoaded) { + Launch.classLoader.registerTransformer("com.gtnewhorizons.angelica.loading.fml.transformers.EarlyRedirectorTransformer"); + } + } } private static void verifyDependencies() { @@ -139,7 +150,7 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader { // specific IClassTransformers that will run last in the transformer chain. // If we were to register them normally in getASMTransformerClass(), // they would be sorted at index 0 which we do not want. - boolean rfbLoaded = Launch.blackboard.getOrDefault("angelica.rfbPluginLoaded", Boolean.FALSE) == Boolean.TRUE; + final boolean rfbLoaded = Launch.blackboard.getOrDefault("angelica.rfbPluginLoaded", Boolean.FALSE) == Boolean.TRUE; if (!rfbLoaded) { tweaks.add("com.gtnewhorizons.angelica.loading.fml.tweakers.AngelicaLateTweaker"); if (AngelicaConfig.enableCeleritas) { @@ -157,7 +168,7 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader { @Override public String getMixinConfig() { - int v = Runtime.version().feature(); + final int v = Runtime.version().feature(); if (v >= 21) return "mixins.angelica.early.j21.json"; if (v >= 17) return "mixins.angelica.early.j17.json"; return "mixins.angelica.early.json"; @@ -174,7 +185,7 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader { } private static void addLwjgl3ifyExclusions() { - var handle = SharedConfig.getRfbTransformers().stream() + final var handle = SharedConfig.getRfbTransformers().stream() .filter(transformer -> transformer.id().equals("lwjgl3ify:redirect")) .findFirst() .orElse(null); diff --git a/src/main/java/com/gtnewhorizons/angelica/loading/fml/transformers/EarlyRedirectorTransformer.java b/src/main/java/com/gtnewhorizons/angelica/loading/fml/transformers/EarlyRedirectorTransformer.java new file mode 100644 index 000000000..fd801190d --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/loading/fml/transformers/EarlyRedirectorTransformer.java @@ -0,0 +1,64 @@ +package com.gtnewhorizons.angelica.loading.fml.transformers; + +import com.gtnewhorizons.angelica.loading.shared.transformers.AngelicaRedirector; +import net.minecraft.launchwrapper.IClassTransformer; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.tree.ClassNode; + +/** + * A scoped redirector that only transforms classes from known-misbehaving (core)mod packages. + *
+ * Some mods prematurely load classes that call GL functions during coremod discovery/injectData. + * Those classes get missed by the late-registered {@link AngelicaRedirectorTransformer}, so their + * GL calls permanently bypass GLSM. + *
+ * This transformer is registered in the {@code AngelicaTweaker} constructor (before any + * coremod's {@code injectData}) and is removed by {@code AngelicaLateTweaker} once the + * full redirector is in its proper post-mixin position. + *
+ * The mixin service will add this to its delegation list, but it no-ops on game classes
+ * since it only targets specific mod packages.
+ */
+public class EarlyRedirectorTransformer implements IClassTransformer {
+
+ private static final String[] TARGET_PACKAGES = {
+ "cn.tesseract.mycelium.",
+ };
+
+ private final AngelicaRedirector inner = new AngelicaRedirector();
+ private final String[] exclusions = inner.getTransformerExclusions();
+
+ @Override
+ public byte[] transform(String name, String transformedName, byte[] basicClass) {
+ if (basicClass == null) return null;
+
+ boolean targeted = false;
+ for (String pkg : TARGET_PACKAGES) {
+ if (transformedName.startsWith(pkg)) {
+ targeted = true;
+ break;
+ }
+ }
+ if (!targeted) return basicClass;
+
+ for (String exclusion : exclusions) {
+ if (transformedName.startsWith(exclusion)) return basicClass;
+ }
+
+ if (!inner.shouldTransform(basicClass)) {
+ return basicClass;
+ }
+
+ final ClassReader cr = new ClassReader(basicClass);
+ final ClassNode cn = new ClassNode();
+ cr.accept(cn, 0);
+ final boolean changed = inner.transformClassNode(transformedName, cn);
+ if (changed) {
+ final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+ cn.accept(cw);
+ return cw.toByteArray();
+ }
+ return basicClass;
+ }
+}
diff --git a/src/main/java/com/gtnewhorizons/angelica/loading/fml/tweakers/AngelicaLateTweaker.java b/src/main/java/com/gtnewhorizons/angelica/loading/fml/tweakers/AngelicaLateTweaker.java
index 9e4cf253b..b34fdceed 100644
--- a/src/main/java/com/gtnewhorizons/angelica/loading/fml/tweakers/AngelicaLateTweaker.java
+++ b/src/main/java/com/gtnewhorizons/angelica/loading/fml/tweakers/AngelicaLateTweaker.java
@@ -1,6 +1,7 @@
package com.gtnewhorizons.angelica.loading.fml.tweakers;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
+import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
@@ -12,6 +13,8 @@ import java.util.Set;
public class AngelicaLateTweaker implements ITweaker {
+ private static final String EARLY_REDIRECTOR_CLASS = "com.gtnewhorizons.angelica.loading.fml.transformers.EarlyRedirectorTransformer";
+
@Override
public void acceptOptions(List