mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-21 12:52:19 +00:00
Target OpenGL 3.3 core profile (#1412)
This commit is contained in:
1 parent
cf9993fce4
commit
d7d2228a6c
151 files changed
+11747
-1673
No files matched your search
@@ -4,9 +4,11 @@ package net.coderbot.iris.postprocess;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.DefaultVertexFormat;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
@@ -15,11 +17,18 @@ import java.nio.FloatBuffer;
|
||||
*/
|
||||
public class FullScreenQuadRenderer {
|
||||
private final int quadBuffer;
|
||||
private final int vao;
|
||||
|
||||
public static final FullScreenQuadRenderer INSTANCE = new FullScreenQuadRenderer();
|
||||
|
||||
private FullScreenQuadRenderer() {
|
||||
this.vao = org.lwjgl.opengl.GL30.glGenVertexArrays();
|
||||
GLStateManager.glBindVertexArray(vao);
|
||||
this.quadBuffer = createQuad();
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, quadBuffer);
|
||||
DefaultVertexFormat.POSITION_TEXTURE.setupBufferState(0L);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
GLStateManager.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
public void render() {
|
||||
@@ -33,21 +42,20 @@ public class FullScreenQuadRenderer {
|
||||
public void begin() {
|
||||
GLStateManager.disableDepthTest();
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glLoadIdentity();
|
||||
GLStateManager.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GLStateManager.glPushMatrix();
|
||||
GLStateManager.glLoadIdentity();
|
||||
// scale the quad from [0, 1] to [-1, 1]
|
||||
GL11.glTranslatef(-1.0F, -1.0F, 0.0F);
|
||||
GL11.glScalef(2.0F, 2.0F, 0.0F);
|
||||
GLStateManager.glTranslatef(-1.0F, -1.0F, 0.0F);
|
||||
GLStateManager.glScalef(2.0F, 2.0F, 1.0F);
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glLoadIdentity();
|
||||
GLStateManager.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GLStateManager.glPushMatrix();
|
||||
GLStateManager.glLoadIdentity();
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GLStateManager.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, quadBuffer);
|
||||
DefaultVertexFormat.POSITION_TEXTURE.setupBufferState(0L);
|
||||
GLStateManager.glBindVertexArray(vao);
|
||||
}
|
||||
|
||||
public void renderQuad() {
|
||||
@@ -55,15 +63,45 @@ public class FullScreenQuadRenderer {
|
||||
}
|
||||
|
||||
public static void end() {
|
||||
DefaultVertexFormat.POSITION_TEXTURE.clearBufferState();
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
GLStateManager.glBindVertexArray(0);
|
||||
|
||||
GLStateManager.enableDepthTest();
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glPopMatrix();
|
||||
GLStateManager.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GLStateManager.glPopMatrix();
|
||||
GLStateManager.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GLStateManager.glPopMatrix();
|
||||
}
|
||||
|
||||
private static final FloatBuffer matBuf = BufferUtils.createFloatBuffer(16);
|
||||
|
||||
/** Per-program cached uniform locations: [mvLoc, projLoc]. Populated on first miss. */
|
||||
private static final Int2ObjectOpenHashMap<int[]> compositeLocCache = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
public static void uploadCompositeMatrices() {
|
||||
final int program = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM);
|
||||
if (program == 0) return;
|
||||
|
||||
int[] locs = compositeLocCache.get(program);
|
||||
if (locs == null) {
|
||||
locs = new int[] {
|
||||
GL20.glGetUniformLocation(program, "iris_ModelViewMatrix"),
|
||||
GL20.glGetUniformLocation(program, "iris_ProjectionMatrix")
|
||||
};
|
||||
compositeLocCache.put(program, locs);
|
||||
}
|
||||
|
||||
if (locs[0] != -1) {
|
||||
GLStateManager.getModelViewMatrix().get(matBuf);
|
||||
matBuf.rewind();
|
||||
GL20.glUniformMatrix4(locs[0], false, matBuf);
|
||||
}
|
||||
|
||||
if (locs[1] != -1) {
|
||||
GLStateManager.getProjectionMatrix().get(matBuf);
|
||||
matBuf.rewind();
|
||||
GL20.glUniformMatrix4(locs[1], false, matBuf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user