phantom = new PhantomReference<>(this, PHANTOM_REFERENCE_QUEUE);
- PHANTOM_TO_BUFFER_ID.put(phantom, this.id);
- BUFFER_ID_TO_PHANTOM.put(this.id, phantom);
-
- }
-
- protected void destroyAsync()
- {
- if (this.id == 0)
- {
- // the buffer has already been closed
- return;
- }
-
- destroyBufferIdAsync(this.id);
-
- this.id = 0;
- this.size = 0;
- }
- private static void destroyBufferIdAsync(int id)
- {
- // remove and clear the phantom reference if present
- if (BUFFER_ID_TO_PHANTOM.containsKey(id))
- {
- Reference extends GLBuffer> phantom = BUFFER_ID_TO_PHANTOM.get(id);
-
- // if we are manually closing this buffer, we don't want the phantom reference to accidentally close it again
- // this can cause a race condition were we accidentally delete an in-use buffer and cause NVIDIA
- // to throw an EXCEPTION_ACCESS_VIOLATION when we attempt to render it
- phantom.clear();
-
- PHANTOM_TO_BUFFER_ID.remove(phantom);
- BUFFER_ID_TO_PHANTOM.remove(id);
- }
-
- GLProxy.queueRunningOnRenderThread(() ->
- {
- // destroy the buffer if it exists,
- // the buffer may not exist if the destroy method is called twice
- if (GL32.glIsBuffer(id))
- {
- GLMC.glDeleteBuffers(id);
- bufferCount.decrementAndGet();
-
- if (Config.Client.Advanced.Debugging.logBufferGarbageCollection.get())
- {
- LOGGER.info("destroyed buffer [" + id + "], remaining: [" + BUFFER_ID_TO_PHANTOM.size() + "]");
- }
- }
- });
- }
-
-
-
- //==================//
- // buffer uploading //
- //==================//
-
- /**
- * Assumes the GL Context is already bound.
- * Will create the VBO if one exist.
- */
- public void uploadBuffer(ByteBuffer bb, EDhApiGpuUploadMethod uploadMethod, int maxExpansionSize, int bufferHint)
- {
- LodUtil.assertTrue(!uploadMethod.useEarlyMapping, "UploadMethod signal that this should use Mapping instead of uploadBuffer!");
- int bbSize = bb.limit() - bb.position();
- if (bbSize > maxExpansionSize)
- {
- LodUtil.assertNotReach("maxExpansionSize is [" + maxExpansionSize + "] but buffer size is [" + bbSize + "]!");
- }
-
- // Don't upload an empty buffer
- if (bbSize == 0)
- {
- return;
- }
-
- // make sure the buffer is ready for uploading
- this.createOrChangeBufferTypeForUpload(uploadMethod);
-
- switch (uploadMethod)
- {
- //case NONE:
- // return;
- case AUTO:
- LodUtil.assertNotReach("GpuUploadMethod AUTO must be resolved before call to uploadBuffer()!");
- case BUFFER_STORAGE:
- this.uploadBufferStorage(bb, bufferHint);
- break;
- case DATA:
- this.uploadBufferData(bb, bufferHint);
- break;
- case SUB_DATA:
- this.uploadSubData(bb, maxExpansionSize, bufferHint);
- break;
- default:
- LodUtil.assertNotReach("Unknown GpuUploadMethod!");
- }
- }
- /** Requires the buffer to be bound */
- protected void uploadBufferStorage(ByteBuffer bb, int bufferStorageHint)
- {
- LodUtil.assertTrue(this.bufferStorage, "Buffer is not bufferStorage but its trying to use bufferStorage upload method!");
-
- int bbSize = bb.limit() - bb.position();
- this.destroyAsync();
- this.create(true);
- this.bind();
- GL44.glBufferStorage(this.getBufferBindingTarget(), bb, 0);
- this.size = bbSize;
- }
- /** Requires the buffer to be bound */
- protected void uploadBufferData(ByteBuffer bb, int bufferDataHint)
- {
- LodUtil.assertTrue(!this.bufferStorage, "Buffer is bufferStorage but its trying to use bufferData upload method!");
-
- int bbSize = bb.limit() - bb.position();
- GL32.glBufferData(this.getBufferBindingTarget(), bb, bufferDataHint);
- this.size = bbSize;
- }
- /** Requires the buffer to be bound */
- protected void uploadSubData(ByteBuffer bb, int maxExpansionSize, int bufferDataHint)
- {
- LodUtil.assertTrue(!this.bufferStorage, "Buffer is bufferStorage but its trying to use subData upload method!");
-
- int bbSize = bb.limit() - bb.position();
- if (this.size < bbSize || this.size > bbSize * BUFFER_SHRINK_TRIGGER)
- {
- int newSize = (int) (bbSize * BUFFER_EXPANSION_MULTIPLIER);
- if (newSize > maxExpansionSize) newSize = maxExpansionSize;
- GL32.glBufferData(this.getBufferBindingTarget(), newSize, bufferDataHint);
- this.size = newSize;
- }
- GL32.glBufferSubData(this.getBufferBindingTarget(), 0, bb);
- }
-
-
-
- //===========//
- // overrides //
- //===========//
-
- @Override
- public void close() { this.destroyAsync(); }
-
- @Override
- public String toString()
- {
- return (this.bufferStorage ? "" : "Static-") + this.getClass().getSimpleName() +
- "[id:" + this.id + ",size:" + this.size + (this.isMapped ? ",MAPPED" : "") + "]";
- }
-
-
-
- //================//
- // helper methods //
- //================//
-
- /**
- * Makes sure the buffer exists and is of the correct format
- * before uploading.
- */
- private void createOrChangeBufferTypeForUpload(EDhApiGpuUploadMethod uploadMethod)
- {
- // create/change the buffer type if necessary
- if (uploadMethod.useBufferStorage != this.bufferStorage)
- {
- // recreate if the buffer storage type changed
- this.bind();
- this.destroyAsync();
- this.create(uploadMethod.useBufferStorage);
- this.bind();
- }
- else
- {
- // Prevent uploading to the null buffer (ID 0).
- // This can happen if the buffer was deleted previously.
- if (this.id == 0)
- {
- this.create(this.bufferStorage);
- }
-
- this.bind();
- }
- }
-
-
-
- //================//
- // static cleanup //
- //================//
-
- private static void runPhantomReferenceCleanupLoop()
- {
- while (true)
- {
- try
- {
- try
- {
- Thread.sleep(PHANTOM_REF_CHECK_TIME_IN_MS);
- }
- catch (InterruptedException ignore) { }
-
-
- Reference extends GLBuffer> phantomRef = PHANTOM_REFERENCE_QUEUE.poll();
- while (phantomRef != null)
- {
- // destroy the buffer if it hasn't been cleared yet
- if (PHANTOM_TO_BUFFER_ID.containsKey(phantomRef))
- {
- int id = PHANTOM_TO_BUFFER_ID.get(phantomRef);
- destroyBufferIdAsync(id);
- //LOGGER.warn("Buffer Phantom collected, ID: ["+id+"]");
- }
-
- phantomRef = PHANTOM_REFERENCE_QUEUE.poll();
- }
- }
- catch (Exception e)
- {
- LOGGER.error("Unexpected error in buffer cleanup thread: [" + e.getMessage() + "].", e);
- }
- }
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLElementBuffer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLElementBuffer.java
deleted file mode 100644
index 9ccd96baa..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLElementBuffer.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.buffer;
-
-import org.lwjgl.opengl.GL32;
-
-/**
- * This is a container for a OpenGL
- * VBO (Vertex Buffer Object).
- *
- * @author James Seibel
- * @version 11-20-2021
- */
-public class GLElementBuffer extends GLBuffer
-{
- /**
- * When uploading to a buffer that is too small, recreate it this many times
- * bigger than the upload payload
- */
- protected int indicesCount = 0;
- public int getIndicesCount() { return this.indicesCount; }
- protected int type = GL32.GL_UNSIGNED_INT;
- public int getType() { return type; }
-
- public GLElementBuffer(boolean isBufferStorage)
- {
- super(isBufferStorage);
- }
-
- @Override
- public void destroyAsync()
- {
- super.destroyAsync();
- this.indicesCount = 0;
- }
-
- @Override
- public int getBufferBindingTarget()
- {
- return GL32.GL_ELEMENT_ARRAY_BUFFER;
- }
-
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLVertexBuffer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLVertexBuffer.java
deleted file mode 100644
index aedb0fb4a..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/GLVertexBuffer.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.buffer;
-
-import java.nio.ByteBuffer;
-
-import org.lwjgl.opengl.GL32;
-
-import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
-
-/**
- * This is a container for a OpenGL
- * VBO (Vertex Buffer Object).
- *
- * @author James Seibel
- * @version 11-20-2021
- */
-public class GLVertexBuffer extends GLBuffer
-{
- /**
- * When uploading to a buffer that is too small, recreate it this many times
- * bigger than the upload payload
- */
- protected int vertexCount = 0;
- public int getVertexCount() { return this.vertexCount; }
- // FIXME: This setter is needed for premapping buffer to manually set the vertexCount. Fix this.
- public void setVertexCount(int vertexCount) { this.vertexCount = vertexCount; }
-
-
- public GLVertexBuffer(boolean isBufferStorage)
- {
- super(isBufferStorage);
- }
-
-
-
- @Override
- public void destroyAsync()
- {
- super.destroyAsync();
- this.vertexCount = 0;
- }
-
- @Override
- public int getBufferBindingTarget() { return GL32.GL_ARRAY_BUFFER; }
-
- /**
- * bufferSize is the number of shared verticies.
- * This number will be higher when actually rendered since each box's face needs 2 triangles
- * with 2 shared verticies.
- */
- public void uploadBuffer(ByteBuffer byteBuffer, int bufferSize, EDhApiGpuUploadMethod uploadMethod, int maxExpensionSize)
- {
- if (bufferSize < 0)
- {
- throw new IllegalArgumentException("VertCount is negative!");
- }
-
- // If size is zero, just ignore it.
- if (byteBuffer.limit() - byteBuffer.position() != 0)
- {
- boolean useBuffStorage = uploadMethod.useBufferStorage;
- super.uploadBuffer(byteBuffer, uploadMethod, maxExpensionSize, useBuffStorage ? 0 : GL32.GL_STATIC_DRAW);
- }
-
- // /4 to get the number of cubes
- // *6 to get the number of verticies (2 triangles, 3 verticies each)
- this.vertexCount = (bufferSize / 4) * 6;
- }
-
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/QuadElementBuffer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/QuadElementBuffer.java
deleted file mode 100644
index 52a5c5a87..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/buffer/QuadElementBuffer.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.buffer;
-
-import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.glObject.GLEnums;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import org.lwjgl.opengl.GL32;
-import org.lwjgl.system.MemoryUtil;
-
-import java.lang.invoke.MethodHandles;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-public class QuadElementBuffer extends GLElementBuffer
-{
- private static final DhLogger LOGGER = new DhLoggerBuilder().build();
-
-
-
- //=============//
- // constructor //
- //=============//
- //region
-
- public QuadElementBuffer() { super(false); }
-
- public void reserve(int quadCount)
- {
- if (quadCount < 0)
- {
- throw new IllegalArgumentException("quadCount must be greater than 0");
- }
- if (quadCount == 0)
- {
- // shouldn't happen, but just in case
- return;
- }
-
- this.indicesCount = quadCount * 6; // 2 triangles per quad
- if (this.indicesCount >= this.getCapacity()
- && this.indicesCount < this.getCapacity() * BUFFER_SHRINK_TRIGGER)
- {
- return;
- }
- int vertexCount = quadCount * 4; // 4 vertices per quad
-
- if (vertexCount < 255)
- {
- // Reserve 1 for the reset index
- this.type = GL32.GL_UNSIGNED_BYTE;
- }
- else if (vertexCount < 65535)
- {
- // Reserve 1 for the reset index
- this.type = GL32.GL_UNSIGNED_SHORT;
- }
- else
- {
- this.type = GL32.GL_UNSIGNED_INT;
- }
-
- ByteBuffer buffer = MemoryUtil.memAlloc(this.indicesCount * GLEnums.getTypeSize(this.type));
- buildBuffer(quadCount, buffer, this.type);
- this.bind();
- super.uploadBuffer(buffer, EDhApiGpuUploadMethod.DATA,
- this.indicesCount * GLEnums.getTypeSize(this.type), GL32.GL_STATIC_DRAW);
-
- MemoryUtil.memFree(buffer);
- }
-
- //endregion
-
-
-
- //=========//
- // getters //
- //=========//
- //region
-
- public int getCapacity() { return super.getSize() / GLEnums.getTypeSize(this.getType()); }
-
- //endregion
-
-
-
- //==========//
- // building //
- //==========//
- //region
-
- private static void buildBuffer(int quadCount, ByteBuffer buffer, int type)
- {
- switch (type)
- {
- case GL32.GL_UNSIGNED_BYTE:
- buildBufferByte(quadCount, buffer);
- break;
- case GL32.GL_UNSIGNED_SHORT:
- buildBufferShort(quadCount, buffer);
- break;
- case GL32.GL_UNSIGNED_INT:
- buildBufferInt(quadCount, buffer);
- break;
- default:
- throw new IllegalStateException("Unknown buffer type: [" + type + "].");
- }
- }
-
- private static void buildBufferByte(int quadCount, ByteBuffer buffer)
- {
- for (int i = 0; i < quadCount; i++)
- {
- int vIndex = i * 4;
- // First triangle
- buffer.put((byte) (vIndex));
- buffer.put((byte) (vIndex + 1));
- buffer.put((byte) (vIndex + 2));
- // Second triangle
- buffer.put((byte) (vIndex + 2));
- buffer.put((byte) (vIndex + 3));
- buffer.put((byte) (vIndex));
- }
- if (buffer.hasRemaining())
- {
- throw new IllegalStateException("QuadElementBuffer is not full somehow after building");
- }
- buffer.rewind();
- }
- private static void buildBufferShort(int quadCount, ByteBuffer buffer)
- {
- for (int i = 0; i < quadCount; i++)
- {
- int vIndex = i * 4;
- // First triangle
- buffer.putShort((short) (vIndex));
- buffer.putShort((short) (vIndex + 1));
- buffer.putShort((short) (vIndex + 2));
- // Second triangle
- buffer.putShort((short) (vIndex + 2));
- buffer.putShort((short) (vIndex + 3));
- buffer.putShort((short) (vIndex));
- }
- if (buffer.hasRemaining())
- {
- throw new IllegalStateException("QuadElementBuffer is not full somehow after building");
- }
- buffer.rewind();
- }
- private static void buildBufferInt(int quadCount, ByteBuffer buffer)
- {
- for (int i = 0; i < quadCount; i++)
- {
- int vIndex = i * 4;
- // First triangle
- buffer.putInt(vIndex);
- buffer.putInt(vIndex + 1);
- buffer.putInt(vIndex + 2);
- // Second triangle
- buffer.putInt(vIndex + 2);
- buffer.putInt(vIndex + 3);
- buffer.putInt(vIndex);
- }
- if (buffer.hasRemaining())
- {
- throw new IllegalStateException("QuadElementBuffer is not full somehow after building");
- }
- buffer.rewind();
- }
-
- //endregion
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/shader/Shader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/shader/Shader.java
deleted file mode 100644
index 7258cf4ee..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/shader/Shader.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.shader;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.ByteBuffer;
-
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
-import org.lwjgl.PointerBuffer;
-import org.lwjgl.opengl.GL32;
-import org.lwjgl.opengl.GL32C;
-import org.lwjgl.system.MemoryStack;
-import org.lwjgl.system.MemoryUtil;
-import org.lwjgl.system.NativeType;
-
-/**
- * This object holds a OpenGL reference to a shader
- * and allows for reading in and compiling a shader file.
- */
-public class Shader
-{
- private static final DhLogger LOGGER = new DhLoggerBuilder()
- .fileLevelConfig(Config.Common.Logging.logRendererGLEventToFile)
- .chatLevelConfig(Config.Common.Logging.logRendererGLEventToChat)
- .build();
-
-
- /** OpenGL shader ID */
- public final int id;
-
-
-
- //==============//
- // constructors //
- //==============//
- //region
-
- /**
- * Creates a shader with specified type.
- *
- * @param type Either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.
- * @param sourceString File path of the shader
- * @throws RuntimeException if the shader fails to compile
- */
- public Shader(int type, String sourceString)
- {
- LOGGER.info("Loading shader with type: ["+type+"]");
- LOGGER.debug("Source: \n["+sourceString+"]");
- if (sourceString == null || sourceString.isEmpty())
- {
- throw new IllegalArgumentException("No shader source given.");
- }
-
- // Create an empty shader object
- this.id = GL32.glCreateShader(type);
- if (this.id == 0)
- {
- throw new IllegalArgumentException("Failed to create shader with type ["+type+"] and Source: \n["+sourceString+"].");
- }
-
- safeShaderSource(this.id, sourceString);
- GL32.glCompileShader(this.id);
- // check if the shader compiled
- int status = GL32.glGetShaderi(this.id, GL32.GL_COMPILE_STATUS);
- if (status != GL32.GL_TRUE)
- {
-
- String message = "Shader compiler error. Details: [" + GL32.glGetShaderInfoLog(this.id) + "]\n";
- message += "Source: \n[" + sourceString + "]";
- this.free(); // important!
- throw new RuntimeException(message);
- }
- LOGGER.info("Shader loaded sucessfully.");
- }
-
- //endregion
-
-
-
- //=========//
- // helpers //
- //=========//
- //region
-
- /**
- * Identical in function to {@link GL32C#glShaderSource(int, CharSequence)} but
- * passes a null pointer for string length to force the driver to rely on the null
- * terminator for string length. This is a workaround for an apparent flaw with some
- * AMD drivers that don't receive or interpret the length correctly, resulting in
- * an access violation when the driver tries to read past the string memory.
- *
- * Hat tip to fewizz for the find and the fix.
- *
- *
Source: https://github.com/vram-guild/canvas/commit/820bf754092ccaf8d0c169620c2ff575722d7d96
- */
- private static void safeShaderSource(@NativeType("GLuint") int glId, @NativeType("GLchar const **") CharSequence source)
- {
- final MemoryStack stack = MemoryStack.stackGet();
- final int stackPointer = stack.getPointer();
-
- try
- {
- final ByteBuffer sourceBuffer = MemoryUtil.memUTF8(source, true);
- final PointerBuffer pointers = stack.mallocPointer(1);
- pointers.put(sourceBuffer);
-
- GL32.nglShaderSource(glId, 1, pointers.address0(), 0);
- org.lwjgl.system.APIUtil.apiArrayFree(pointers.address0(), 1);
- }
- finally
- {
- stack.setPointer(stackPointer);
- }
- }
-
- public void free() { GL32.glDeleteShader(this.id); }
-
- public static String loadFile(String path, boolean absoluteFilePath)
- {
- StringBuilder stringBuilder = new StringBuilder();
-
- try
- {
- // open the file
- InputStream in;
- if (absoluteFilePath)
- {
- // Throws FileNotFoundException
- in = new FileInputStream(path); // Note: this should use OS path seperator
- }
- else
- {
- in = Shader.class.getClassLoader().getResourceAsStream(path); // Note: path seperator should be '/'
- if (in == null)
- {
- throw new FileNotFoundException("Shader file not found in resource: " + path);
- }
- }
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-
- // read in the file
- String line;
- while ((line = reader.readLine()) != null)
- {
- stringBuilder.append(line).append("\n");
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("Unable to load shader from file [" + path + "]. Error: " + e.getMessage());
- }
-
- return stringBuilder.toString();
- }
-
- //endregion
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/shader/ShaderProgram.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/shader/ShaderProgram.java
deleted file mode 100644
index 08ea181dc..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/shader/ShaderProgram.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.shader;
-
-import java.awt.Color;
-import java.nio.FloatBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.Supplier;
-
-import com.seibel.distanthorizons.api.objects.math.DhApiVec3i;
-import org.lwjgl.opengl.GL32;
-import org.lwjgl.system.MemoryStack;
-
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.util.math.Vec3d;
-import com.seibel.distanthorizons.core.util.math.Vec3f;
-
-
-/**
- * This object holds the reference to a OpenGL shader program
- * and contains a few methods that can be used with OpenGL shader programs.
- * The reason for many of these simple wrapper methods is as reminders of what
- * can (and needs to be) done with a shader program.
- */
-public class ShaderProgram
-{
- /** Stores the handle of the program. */
- public final int id;
-
-
-
- //=============//
- // constructor //
- //=============//
- //region
-
- public ShaderProgram(String vertResourcePath, String fragResourcePath, String attribute) { this(vertResourcePath, fragResourcePath, new String[]{ attribute }); }
- /**
- * @param vertResourcePath the relative path the vertex shader should be found
- * @param fragResourcePath the relative path the fragment shader should be found
- */
- public ShaderProgram(String vertResourcePath, String fragResourcePath, String[] attributes)
- {
- this.id = GL32.glCreateProgram();
-
- {
- String shaderString = Shader.loadFile(vertResourcePath, false);
- Shader vertShader = new Shader(GL32.GL_VERTEX_SHADER, shaderString);
- GL32.glAttachShader(this.id, vertShader.id);
- vertShader.free();
- }
-
- {
- String shaderString = Shader.loadFile(fragResourcePath, false);
- Shader fragShader = new Shader(GL32.GL_FRAGMENT_SHADER, shaderString);
- GL32.glAttachShader(this.id, fragShader.id);
- fragShader.free();
- }
-
- for (int i = 0; i < attributes.length; i++)
- {
- GL32.glBindAttribLocation(this.id, i, attributes[i]);
- }
- GL32.glLinkProgram(this.id);
-
- int status = GL32.glGetProgrami(this.id, GL32.GL_LINK_STATUS);
- if (status != GL32.GL_TRUE)
- {
- String message = "Shader Link Error. Details: " + GL32.glGetProgramInfoLog(this.id);
- this.free(); // important!
- throw new RuntimeException(message);
- }
- GL32.glUseProgram(this.id); // This HAVE to be a direct call to prevent calling the overloaded version
- }
-
- //endregion
-
-
-
- //=========//
- // binding //
- //=========//
- //region
-
- public void bind() { GL32.glUseProgram(this.id); }
- public void unbind() { GL32.glUseProgram(0); }
-
- public void free() { GL32.glDeleteProgram(this.id); }
-
- //endregion
-
-
-
- //============//
- // attributes //
- //============//
- //region
-
- /**
- * WARNING: Slow native call! Cache it if possible!
- * Gets the location of an attribute variable with specified name.
- * Calls GL20.glGetAttribLocation(id, name)
- *
- * @param name Attribute name
- * @return Location of the attribute
- * @throws RuntimeException if attribute not found
- */
- public int getAttributeLocation(CharSequence name)
- {
- int i = GL32.glGetAttribLocation(id, name);
- if (i == -1) throw new RuntimeException("Attribute name not found: " + name);
- return i;
- }
- /**
- * Same as above but without throwing errors.
- * Returns -1 if the attribute doesn't exist or has been optimized out.
- */
- public int tryGetAttributeLocation(CharSequence name)
- { return GL32.glGetAttribLocation(this.id, name); }
-
- //endregion
-
-
-
- //==========//
- // uniforms //
- //==========//
- //region
-
- /**
- * WARNING: Slow native call! Cache it if possible!
- * Gets the location of a uniform variable with specified name.
- * Calls GL20.glGetUniformLocation(id, name)
- *
- * @param name Uniform name
- * @return Location of the Uniform
- * @throws RuntimeException if uniform not found
- */
- public int getUniformLocation(CharSequence name) throws RuntimeException
- {
- int i = GL32.glGetUniformLocation(id, name);
- if (i == -1)
- {
- throw new RuntimeException("Uniform name not found: " + name);
- }
- return i;
- }
-
- // Same as above but without throwing errors.
- // Return -1 if uniform doesn't exist or has been optimized out
- public int tryGetUniformLocation(CharSequence name)
- { return GL32.glGetUniformLocation(this.id, name); }
-
- /** Requires a bound ShaderProgram. */
- public void setUniform(int location, boolean value) { GL32.glUniform1i(location, value ? 1 : 0); }
- /** @see ShaderProgram#setUniform(int, boolean) */
- public void trySetUniform(int location, boolean value) { if (location != -1) { this.setUniform(location, value); } }
-
- /** Requires a bound ShaderProgram. */
- public void setUniform(int location, int value) { GL32.glUniform1i(location, value); }
- /** @see ShaderProgram#setUniform(int, int) */
- public void trySetUniform(int location, int value) { if (location != -1) { this.setUniform(location, value); } }
-
- /** Requires a bound ShaderProgram. */
- public void setUniform(int location, float value) { GL32.glUniform1f(location, value); }
- /** @see ShaderProgram#setUniform(int, float) */
- public void trySetUniform(int location, float value) { if (location != -1) { this.setUniform(location, value); } }
-
- /** Requires a bound ShaderProgram. */
- public void setUniform(int location, Vec3f value) { GL32.glUniform3f(location, value.x, value.y, value.z); }
- /** @see ShaderProgram#setUniform(int, Vec3f) */
- public void trySetUniform(int location, Vec3f value) { if (location != -1) { this.setUniform(location, value); } }
-
- /** Requires a bound ShaderProgram. */
- public void setUniform(int location, DhApiVec3i value) { GL32.glUniform3i(location, value.x, value.y, value.z); }
- /** @see ShaderProgram#setUniform(int, Mat4f) */
- public void trySetUniform(int location, DhApiVec3i value) { if (location != -1) { this.setUniform(location, value); } }
-
- /** Requires a bound ShaderProgram. */
- public void setUniform(int location, Mat4f value)
- {
- try (MemoryStack stack = MemoryStack.stackPush())
- {
- FloatBuffer buffer = stack.mallocFloat(4 * 4);
- value.store(buffer);
- GL32.glUniformMatrix4fv(location, false, buffer);
- }
- }
- /** @see ShaderProgram#setUniform(int, Mat4f) */
- public void trySetUniform(int location, Mat4f value) { if (location != -1) { this.setUniform(location, value); } }
-
- /**
- * Converts the color's RGBA values into values between 0 and 1.
- * Requires a bound ShaderProgram.
- */
- public void setUniform(int location, Color value)
- {
- GL32.glUniform4f(location,
- value.getRed() / 256.0f,
- value.getGreen() / 256.0f,
- value.getBlue() / 256.0f,
- value.getAlpha() / 256.0f);
- }
- /** @see ShaderProgram#setUniform(int, Color) */
- public void trySetUniform(int location, Color value) { if (location != -1) { this.setUniform(location, value); } }
-
- //endregion
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DHDepthTexture.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DHDepthTexture.java
deleted file mode 100644
index 865b95821..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DHDepthTexture.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.seibel.distanthorizons.core.render.glObject.texture;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import org.lwjgl.opengl.GL11C;
-import org.lwjgl.opengl.GL13C;
-import org.lwjgl.opengl.GL43C;
-
-import java.nio.ByteBuffer;
-
-public class DHDepthTexture
-{
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- private int id;
- public DHDepthTexture(int width, int height, EDhDepthBufferFormat format)
- {
- this.id = GL43C.glGenTextures();
-
- this.resize(width, height, format);
-
- GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, GL11C.GL_NEAREST);
- GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, GL11C.GL_NEAREST);
- GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_CLAMP_TO_EDGE);
- GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_T, GL13C.GL_CLAMP_TO_EDGE);
-
- // disable mip-mapping since DH is just going to draw straight to the screen
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_BASE_LEVEL, 0);
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_MAX_LEVEL, 0);
-
- GL43C.glBindTexture(GL43C.GL_TEXTURE_2D, 0);
- }
-
- // For internal use by Iris for copying data. Do not use this in DH.
- public DHDepthTexture(int id) { this.id = id; }
-
- public void resize(int width, int height, EDhDepthBufferFormat format)
- {
- GL43C.glBindTexture(GL43C.GL_TEXTURE_2D, this.getTextureId());
- GL43C.glTexImage2D(GL11C.GL_TEXTURE_2D, 0, format.getGlInternalFormat(), width, height, 0,
- format.getGlType(), format.getGlFormat(), (ByteBuffer) null);
- }
-
- public int getTextureId()
- {
- if (this.id == -1)
- {
- throw new IllegalStateException("Depth texture does not exist!");
- }
-
- return this.id;
- }
-
- public void destroy()
- {
- GLMC.glDeleteTextures(this.getTextureId());
- this.id = -1;
- }
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DhColorTexture.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DhColorTexture.java
deleted file mode 100644
index cbce810c1..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DhColorTexture.java
+++ /dev/null
@@ -1,184 +0,0 @@
-package com.seibel.distanthorizons.core.render.glObject.texture;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import org.joml.Vector2i;
-import org.lwjgl.opengl.GL11C;
-import org.lwjgl.opengl.GL13C;
-import org.lwjgl.opengl.GL43C;
-
-import java.nio.ByteBuffer;
-
-public class DhColorTexture
-{
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- private final EDhInternalTextureFormat internalFormat;
- private final EDhPixelFormat format;
- private final EDhPixelType type;
- private int width;
- private int height;
-
- private boolean isValid;
- /** AKA, the OpenGL name of this texture */
- private final int id;
-
- private static final ByteBuffer NULL_BUFFER = null;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- public DhColorTexture(Builder builder)
- {
- this.isValid = true;
-
- this.internalFormat = builder.internalFormat;
- this.format = builder.format;
- this.type = builder.type;
-
- this.width = builder.width;
- this.height = builder.height;
-
- this.id = GL43C.glGenTextures();
-
- boolean isPixelFormatInteger = builder.internalFormat.getPixelFormat().isInteger();
- this.setupTexture(this.id, builder.width, builder.height, !isPixelFormatInteger); // this binds the texture
-
- // Clean up after ourselves
- // This is strictly defensive to ensure that other buggy code doesn't tamper with our textures
- GL43C.glBindTexture(GL43C.GL_TEXTURE_2D, 0);
- }
-
-
-
- //=========//
- // methods //
- //=========//
-
- private void setupTexture(int id, int width, int height, boolean allowsLinear)
- {
- this.resizeTexture(id, width, height);
-
- GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, allowsLinear ? GL11C.GL_LINEAR : GL11C.GL_NEAREST);
- GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, allowsLinear ? GL11C.GL_LINEAR : GL11C.GL_NEAREST);
- GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_CLAMP_TO_EDGE);
- GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_T, GL13C.GL_CLAMP_TO_EDGE);
-
- // disable mip-mapping since DH is just going to draw straight to the screen
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_BASE_LEVEL, 0);
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_MAX_LEVEL, 0);
- }
-
- private void resizeTexture(int texture, int width, int height)
- {
- GL43C.glBindTexture(GL43C.GL_TEXTURE_2D, texture);
- GL43C.glTexImage2D(GL11C.GL_TEXTURE_2D, 0, this.internalFormat.getGlFormat(), width, height, 0, this.format.getGlFormat(), this.type.getGlFormat(), NULL_BUFFER);
- }
-
- void resize(Vector2i textureScaleOverride) { this.resize(textureScaleOverride.x, textureScaleOverride.y); }
-
- // Package private, call CompositeRenderTargets#resizeIfNeeded instead.
- public void resize(int width, int height)
- {
- this.throwIfInvalid();
-
- this.width = width;
- this.height = height;
-
- this.resizeTexture(this.id, width, height);
- }
-
- public EDhInternalTextureFormat getInternalFormat() { return this.internalFormat; }
-
- public int getTextureId()
- {
- this.throwIfInvalid();
- return this.id;
- }
-
- public int getWidth() { return this.width; }
-
- public int getHeight() { return this.height; }
-
- public void destroy()
- {
- this.throwIfInvalid();
- this.isValid = false;
-
- GLMC.glDeleteTextures(this.id);
- }
-
- /** @throws IllegalStateException if the texture isn't valid */
- private void throwIfInvalid()
- {
- if (!this.isValid)
- {
- throw new IllegalStateException("Attempted to use a deleted composite render target");
- }
- }
-
- public static Builder builder() { return new Builder(); }
-
-
-
- //================//
- // helper classes //
- //================//
-
- public static class Builder
- {
- private EDhInternalTextureFormat internalFormat = EDhInternalTextureFormat.RGBA8;
- private int width = 0;
- private int height = 0;
- private EDhPixelFormat format = EDhPixelFormat.RGBA;
- private EDhPixelType type = EDhPixelType.UNSIGNED_BYTE;
-
- private Builder()
- {
- // No-op
- }
-
- public Builder setInternalFormat(EDhInternalTextureFormat format)
- {
- this.internalFormat = format;
- return this;
- }
-
- public Builder setDimensions(int width, int height)
- {
- if (width <= 0)
- {
- throw new IllegalArgumentException("Width must be greater than zero");
- }
-
- if (height <= 0)
- {
- throw new IllegalArgumentException("Height must be greater than zero");
- }
-
- this.width = width;
- this.height = height;
-
- return this;
- }
-
- public Builder setPixelFormat(EDhPixelFormat pixelFormat)
- {
- this.format = pixelFormat;
- return this;
- }
-
- public Builder setPixelType(EDhPixelType pixelType)
- {
- this.type = pixelType;
- return this;
- }
-
- public DhColorTexture build() { return new DhColorTexture(this); }
-
- }
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DhFramebuffer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DhFramebuffer.java
deleted file mode 100644
index 2f40d9530..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/DhFramebuffer.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package com.seibel.distanthorizons.core.render.glObject.texture;
-
-import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiFramebuffer;
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
-import it.unimi.dsi.fastutil.ints.Int2IntMap;
-import org.lwjgl.opengl.GL32;
-
-public class DhFramebuffer implements IDhApiFramebuffer
-{
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
- private final Int2IntMap attachments;
- private final int maxDrawBuffers;
- private final int maxColorAttachments;
- private boolean hasDepthAttachment;
- private int id;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- public DhFramebuffer()
- {
- this.id = GL32.glGenFramebuffers();
-
- this.attachments = new Int2IntArrayMap();
- this.maxDrawBuffers = GL32.glGetInteger(GL32.GL_MAX_DRAW_BUFFERS);
- this.maxColorAttachments = GL32.glGetInteger(GL32.GL_MAX_COLOR_ATTACHMENTS);
- this.hasDepthAttachment = false;
- }
-
- /** For internal use by Iris, do not remove. */
- public DhFramebuffer(int id)
- {
- this.id = id;
-
- this.attachments = new Int2IntArrayMap();
- this.maxDrawBuffers = GL32.glGetInteger(GL32.GL_MAX_DRAW_BUFFERS);
- this.maxColorAttachments = GL32.glGetInteger(GL32.GL_MAX_COLOR_ATTACHMENTS);
- this.hasDepthAttachment = false;
- }
-
-
-
- //=========//
- // methods //
- //=========//
-
- @Override
- public void addDepthAttachment(int textureId, boolean isCombinedStencil)
- {
- this.bind();
-
- int depthAttachment = isCombinedStencil ? GL32.GL_DEPTH_STENCIL_ATTACHMENT : GL32.GL_DEPTH_ATTACHMENT;
- GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, depthAttachment, GL32.GL_TEXTURE_2D, textureId, 0);
-
- this.hasDepthAttachment = true;
- }
-
- @Override
- public void addColorAttachment(int textureIndex, int textureId)
- {
- this.bind();
-
- GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0 + textureIndex, GL32.GL_TEXTURE_2D, textureId, 0);
- this.attachments.put(textureIndex, textureId);
- }
-
- public void noDrawBuffers()
- {
- this.bind();
- GL32.glDrawBuffers(new int[]{GL32.GL_NONE});
- }
-
- public void drawBuffers(int[] buffers)
- {
- int[] glBuffers = new int[buffers.length];
- int index = 0;
-
- if (buffers.length > this.maxDrawBuffers)
- {
- throw new IllegalArgumentException("Cannot write to more than " + this.maxDrawBuffers + " draw buffers on this GPU");
- }
-
- for (int buffer : buffers)
- {
- if (buffer >= this.maxColorAttachments)
- {
- throw new IllegalArgumentException("Only " + this.maxColorAttachments + " color attachments are supported on this GPU, but an attempt was made to write to a color attachment with index " + buffer);
- }
-
- glBuffers[index++] = GL32.GL_COLOR_ATTACHMENT0 + buffer;
- }
-
- this.bind();
- GL32.glDrawBuffers(new int[]{GL32.GL_NONE});
- }
-
- public void readBuffer(int buffer)
- {
- this.bind();
- GL32.glReadBuffer(GL32.GL_COLOR_ATTACHMENT0 + buffer);
- }
-
- public int getColorAttachment(int index) { return this.attachments.get(index); }
-
- public boolean hasDepthAttachment() { return this.hasDepthAttachment; }
-
- @Override
- public void bind()
- {
- if (this.id == -1)
- {
- throw new IllegalStateException("Framebuffer does not exist!");
- }
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.id);
- }
-
- public void bindAsReadBuffer() { GLMC.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, this.id); }
-
- public void bindAsDrawBuffer() { GLMC.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, this.id); }
-
- @Override
- public void destroy()
- {
- GL32.glDeleteFramebuffers(this.id);
- this.id = -1;
- }
-
- @Override
- public int getStatus()
- {
- this.bind();
- int status = GL32.glCheckFramebufferStatus(GL32.GL_FRAMEBUFFER);
- return status;
- }
-
- @Override
- public int getId() { return this.id; }
-
-
-
- //=============//
- // API methods //
- //=============//
-
- public boolean overrideThisFrame() { return true; }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhDepthBufferFormat.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhDepthBufferFormat.java
deleted file mode 100644
index 537ea939a..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhDepthBufferFormat.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package com.seibel.distanthorizons.core.render.glObject.texture;
-
-import org.jetbrains.annotations.Nullable;
-import org.lwjgl.opengl.GL30C;
-import org.lwjgl.opengl.GL43C;
-
-public enum EDhDepthBufferFormat
-{
- DEPTH(false),
- DEPTH16(false),
- DEPTH24(false),
- DEPTH32(false),
- DEPTH32F(false),
- DEPTH_STENCIL(true),
- DEPTH24_STENCIL8(true),
- DEPTH32F_STENCIL8(true);
-
-
-
- private final boolean combinedStencil;
-
- EDhDepthBufferFormat(boolean combinedStencil) { this.combinedStencil = combinedStencil; }
-
-
-
- @Nullable
- public static EDhDepthBufferFormat fromGlEnum(int glenum)
- {
- switch (glenum)
- {
- case GL30C.GL_DEPTH_COMPONENT:
- return EDhDepthBufferFormat.DEPTH;
- case GL30C.GL_DEPTH_COMPONENT16:
- return EDhDepthBufferFormat.DEPTH16;
- case GL30C.GL_DEPTH_COMPONENT24:
- return EDhDepthBufferFormat.DEPTH24;
- case GL30C.GL_DEPTH_COMPONENT32:
- return EDhDepthBufferFormat.DEPTH32;
- case GL30C.GL_DEPTH_COMPONENT32F:
- return EDhDepthBufferFormat.DEPTH32F;
- case GL30C.GL_DEPTH_STENCIL:
- return EDhDepthBufferFormat.DEPTH_STENCIL;
- case GL30C.GL_DEPTH24_STENCIL8:
- return EDhDepthBufferFormat.DEPTH24_STENCIL8;
- case GL30C.GL_DEPTH32F_STENCIL8:
- return EDhDepthBufferFormat.DEPTH32F_STENCIL8;
- default:
- return null;
- }
- }
-
- public static EDhDepthBufferFormat fromGlEnumOrDefault(int glenum)
- {
- EDhDepthBufferFormat format = fromGlEnum(glenum);
- if (format == null)
- {
- // yolo, just assume it's GL_DEPTH_COMPONENT
- return EDhDepthBufferFormat.DEPTH;
- }
- return format;
- }
-
- public int getGlInternalFormat()
- {
- switch (this)
- {
- case DEPTH:
- return GL30C.GL_DEPTH_COMPONENT;
- case DEPTH16:
- return GL30C.GL_DEPTH_COMPONENT16;
- case DEPTH24:
- return GL30C.GL_DEPTH_COMPONENT24;
- case DEPTH32:
- return GL30C.GL_DEPTH_COMPONENT32;
- case DEPTH32F:
- return GL30C.GL_DEPTH_COMPONENT32F;
- case DEPTH_STENCIL:
- return GL30C.GL_DEPTH_STENCIL;
- case DEPTH24_STENCIL8:
- return GL30C.GL_DEPTH24_STENCIL8;
- case DEPTH32F_STENCIL8:
- return GL30C.GL_DEPTH32F_STENCIL8;
- }
-
- throw new AssertionError("unreachable");
- }
-
- public int getGlType() { return isCombinedStencil() ? GL30C.GL_DEPTH_STENCIL : GL30C.GL_DEPTH_COMPONENT; }
-
- public int getGlFormat()
- {
- switch (this)
- {
- case DEPTH:
- case DEPTH16:
- return GL43C.GL_UNSIGNED_SHORT;
- case DEPTH24:
- case DEPTH32:
- return GL43C.GL_UNSIGNED_INT;
- case DEPTH32F:
- return GL30C.GL_FLOAT;
- case DEPTH_STENCIL:
- case DEPTH24_STENCIL8:
- return GL30C.GL_UNSIGNED_INT_24_8;
- case DEPTH32F_STENCIL8:
- return GL30C.GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
- }
-
- throw new AssertionError("unreachable");
- }
-
- public boolean isCombinedStencil() { return combinedStencil; }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhInternalTextureFormat.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhInternalTextureFormat.java
deleted file mode 100644
index b307aafa6..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhInternalTextureFormat.java
+++ /dev/null
@@ -1,130 +0,0 @@
-package com.seibel.distanthorizons.core.render.glObject.texture;
-
-import org.lwjgl.opengl.GL11C;
-import org.lwjgl.opengl.GL30C;
-import org.lwjgl.opengl.GL31C;
-
-import java.util.Locale;
-import java.util.Optional;
-
-public enum EDhInternalTextureFormat
-{
- RGBA(GL11C.GL_RGBA, EGlVersion.GL_11, EDhPixelFormat.RGBA),
-
- // 8-bit normalized
- R8(GL30C.GL_R8, EGlVersion.GL_30, EDhPixelFormat.RED),
- RG8(GL30C.GL_RG8, EGlVersion.GL_30, EDhPixelFormat.RG),
- RGB8(GL11C.GL_RGB8, EGlVersion.GL_11, EDhPixelFormat.RGB),
- RGBA8(GL11C.GL_RGBA8, EGlVersion.GL_11, EDhPixelFormat.RGBA),
-
- // 8-bit signed normalized
- R8_SNORM(GL31C.GL_R8_SNORM, EGlVersion.GL_31, EDhPixelFormat.RED),
- RG8_SNORM(GL31C.GL_RG8_SNORM, EGlVersion.GL_31, EDhPixelFormat.RG),
- RGB8_SNORM(GL31C.GL_RGB8_SNORM, EGlVersion.GL_31, EDhPixelFormat.RGB),
- RGBA8_SNORM(GL31C.GL_RGBA8_SNORM, EGlVersion.GL_31, EDhPixelFormat.RGBA),
-
- // 16-bit normalized
- R16(GL30C.GL_R16, EGlVersion.GL_30, EDhPixelFormat.RED),
- RG16(GL30C.GL_RG16, EGlVersion.GL_30, EDhPixelFormat.RG),
- RGB16(GL11C.GL_RGB16, EGlVersion.GL_11, EDhPixelFormat.RGB),
- RGBA16(GL11C.GL_RGBA16, EGlVersion.GL_11, EDhPixelFormat.RGBA),
-
- // 16-bit signed normalized
- R16_SNORM(GL31C.GL_R16_SNORM, EGlVersion.GL_31, EDhPixelFormat.RED),
- RG16_SNORM(GL31C.GL_RG16_SNORM, EGlVersion.GL_31, EDhPixelFormat.RG),
- RGB16_SNORM(GL31C.GL_RGB16_SNORM, EGlVersion.GL_31, EDhPixelFormat.RGB),
- RGBA16_SNORM(GL31C.GL_RGBA16_SNORM, EGlVersion.GL_31, EDhPixelFormat.RGBA),
-
- // 16-bit float
- R16F(GL30C.GL_R16F, EGlVersion.GL_30, EDhPixelFormat.RED),
- RG16F(GL30C.GL_RG16F, EGlVersion.GL_30, EDhPixelFormat.RG),
- RGB16F(GL30C.GL_RGB16F, EGlVersion.GL_30, EDhPixelFormat.RGB),
- RGBA16F(GL30C.GL_RGBA16F, EGlVersion.GL_30, EDhPixelFormat.RGBA),
-
- // 32-bit float
- R32F(GL30C.GL_R32F, EGlVersion.GL_30, EDhPixelFormat.RED),
- RG32F(GL30C.GL_RG32F, EGlVersion.GL_30, EDhPixelFormat.RG),
- RGB32F(GL30C.GL_RGB32F, EGlVersion.GL_30, EDhPixelFormat.RGB),
- RGBA32F(GL30C.GL_RGBA32F, EGlVersion.GL_30, EDhPixelFormat.RGBA),
-
- // 8-bit integer
- R8I(GL30C.GL_R8I, EGlVersion.GL_30, EDhPixelFormat.RED_INTEGER),
- RG8I(GL30C.GL_RG8I, EGlVersion.GL_30, EDhPixelFormat.RG_INTEGER),
- RGB8I(GL30C.GL_RGB8I, EGlVersion.GL_30, EDhPixelFormat.RGB_INTEGER),
- RGBA8I(GL30C.GL_RGBA8I, EGlVersion.GL_30, EDhPixelFormat.RGBA_INTEGER),
-
- // 8-bit unsigned integer
- R8UI(GL30C.GL_R8UI, EGlVersion.GL_30, EDhPixelFormat.RED_INTEGER),
- RG8UI(GL30C.GL_RG8UI, EGlVersion.GL_30, EDhPixelFormat.RG_INTEGER),
- RGB8UI(GL30C.GL_RGB8UI, EGlVersion.GL_30, EDhPixelFormat.RGB_INTEGER),
- RGBA8UI(GL30C.GL_RGBA8UI, EGlVersion.GL_30, EDhPixelFormat.RGBA_INTEGER),
-
- // 16-bit integer
- R16I(GL30C.GL_R16I, EGlVersion.GL_30, EDhPixelFormat.RED_INTEGER),
- RG16I(GL30C.GL_RG16I, EGlVersion.GL_30, EDhPixelFormat.RG_INTEGER),
- RGB16I(GL30C.GL_RGB16I, EGlVersion.GL_30, EDhPixelFormat.RGB_INTEGER),
- RGBA16I(GL30C.GL_RGBA16I, EGlVersion.GL_30, EDhPixelFormat.RGBA_INTEGER),
-
- // 16-bit unsigned integer
- R16UI(GL30C.GL_R16UI, EGlVersion.GL_30, EDhPixelFormat.RED_INTEGER),
- RG16UI(GL30C.GL_RG16UI, EGlVersion.GL_30, EDhPixelFormat.RG_INTEGER),
- RGB16UI(GL30C.GL_RGB16UI, EGlVersion.GL_30, EDhPixelFormat.RGB_INTEGER),
- RGBA16UI(GL30C.GL_RGBA16UI, EGlVersion.GL_30, EDhPixelFormat.RGBA_INTEGER),
-
- // 32-bit integer
- R32I(GL30C.GL_R32I, EGlVersion.GL_30, EDhPixelFormat.RED_INTEGER),
- RG32I(GL30C.GL_RG32I, EGlVersion.GL_30, EDhPixelFormat.RG_INTEGER),
- RGB32I(GL30C.GL_RGB32I, EGlVersion.GL_30, EDhPixelFormat.RGB_INTEGER),
- RGBA32I(GL30C.GL_RGBA32I, EGlVersion.GL_30, EDhPixelFormat.RGBA_INTEGER),
-
- // 32-bit unsigned integer
- R32UI(GL30C.GL_R32UI, EGlVersion.GL_30, EDhPixelFormat.RED_INTEGER),
- RG32UI(GL30C.GL_RG32UI, EGlVersion.GL_30, EDhPixelFormat.RG_INTEGER),
- RGB32UI(GL30C.GL_RGB32UI, EGlVersion.GL_30, EDhPixelFormat.RGB_INTEGER),
- RGBA32UI(GL30C.GL_RGBA32UI, EGlVersion.GL_30, EDhPixelFormat.RGBA_INTEGER),
-
- // Mixed
- R3_G3_B2(GL11C.GL_R3_G3_B2, EGlVersion.GL_11, EDhPixelFormat.RGB),
- RGB5_A1(GL11C.GL_RGB5_A1, EGlVersion.GL_11, EDhPixelFormat.RGBA),
- RGB10_A2(GL11C.GL_RGB10_A2, EGlVersion.GL_11, EDhPixelFormat.RGBA),
- R11F_G11F_B10F(GL30C.GL_R11F_G11F_B10F, EGlVersion.GL_30, EDhPixelFormat.RGB),
- RGB9_E5(GL30C.GL_RGB9_E5, EGlVersion.GL_30, EDhPixelFormat.RGB);
-
-
-
- private final int glFormat;
- private final EGlVersion minimumGlVersion;
- private final EDhPixelFormat expectedPixelFormat;
-
-
-
- EDhInternalTextureFormat(int glFormat, EGlVersion minimumGlVersion, EDhPixelFormat expectedPixelFormat)
- {
- this.glFormat = glFormat;
- this.minimumGlVersion = minimumGlVersion;
- this.expectedPixelFormat = expectedPixelFormat;
- }
-
-
-
- public static Optional fromString(String name)
- {
- try
- {
- return Optional.of(EDhInternalTextureFormat.valueOf(name.toUpperCase(Locale.US)));
- }
- catch (IllegalArgumentException e)
- {
- return Optional.empty();
- }
- }
-
- public int getGlFormat() { return this.glFormat; }
-
- public EDhPixelFormat getPixelFormat() { return this.expectedPixelFormat; }
-
- public EGlVersion getMinimumGlVersion() { return this.minimumGlVersion; }
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhPixelFormat.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhPixelFormat.java
deleted file mode 100644
index a9bac119f..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhPixelFormat.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.seibel.distanthorizons.core.render.glObject.texture;
-
-import org.lwjgl.opengl.GL11C;
-import org.lwjgl.opengl.GL12C;
-import org.lwjgl.opengl.GL30C;
-
-import java.util.Locale;
-import java.util.Optional;
-
-public enum EDhPixelFormat
-{
- RED(GL11C.GL_RED, EGlVersion.GL_11, false),
- RG(GL30C.GL_RG, EGlVersion.GL_30, false),
- RGB(GL11C.GL_RGB, EGlVersion.GL_11, false),
- BGR(GL12C.GL_BGR, EGlVersion.GL_12, false),
- RGBA(GL11C.GL_RGBA, EGlVersion.GL_11, false),
- BGRA(GL12C.GL_BGRA, EGlVersion.GL_12, false),
- RED_INTEGER(GL30C.GL_RED_INTEGER, EGlVersion.GL_30, true),
- RG_INTEGER(GL30C.GL_RG_INTEGER, EGlVersion.GL_30, true),
- RGB_INTEGER(GL30C.GL_RGB_INTEGER, EGlVersion.GL_30, true),
- BGR_INTEGER(GL30C.GL_BGR_INTEGER, EGlVersion.GL_30, true),
- RGBA_INTEGER(GL30C.GL_RGBA_INTEGER, EGlVersion.GL_30, true),
- BGRA_INTEGER(GL30C.GL_BGRA_INTEGER, EGlVersion.GL_30, true);
-
-
-
- private final int glFormat;
- private final EGlVersion minimumGlVersion;
- private final boolean isInteger;
-
-
-
- EDhPixelFormat(int glFormat, EGlVersion minimumGlVersion, boolean isInteger)
- {
- this.glFormat = glFormat;
- this.minimumGlVersion = minimumGlVersion;
- this.isInteger = isInteger;
- }
-
-
-
- public static Optional fromString(String name)
- {
- try
- {
- return Optional.of(EDhPixelFormat.valueOf(name.toUpperCase(Locale.US)));
- }
- catch (IllegalArgumentException e)
- {
- return Optional.empty();
- }
- }
-
- public int getGlFormat() { return this.glFormat; }
-
- public EGlVersion getMinimumGlVersion() { return this.minimumGlVersion; }
-
- public boolean isInteger() { return this.isInteger; }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhPixelType.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhPixelType.java
deleted file mode 100644
index b2c00d748..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EDhPixelType.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.seibel.distanthorizons.core.render.glObject.texture;
-
-import org.lwjgl.opengl.GL11C;
-import org.lwjgl.opengl.GL12C;
-import org.lwjgl.opengl.GL30C;
-
-import java.util.Locale;
-import java.util.Optional;
-
-public enum EDhPixelType
-{
- BYTE(GL11C.GL_BYTE, EGlVersion.GL_11),
- SHORT(GL11C.GL_SHORT, EGlVersion.GL_11),
- INT(GL11C.GL_INT, EGlVersion.GL_11),
- HALF_FLOAT(GL30C.GL_HALF_FLOAT, EGlVersion.GL_30),
- FLOAT(GL11C.GL_FLOAT, EGlVersion.GL_11),
- UNSIGNED_BYTE(GL11C.GL_UNSIGNED_BYTE, EGlVersion.GL_11),
- UNSIGNED_BYTE_3_3_2(GL12C.GL_UNSIGNED_BYTE_3_3_2, EGlVersion.GL_12),
- UNSIGNED_BYTE_2_3_3_REV(GL12C.GL_UNSIGNED_BYTE_2_3_3_REV, EGlVersion.GL_12),
- UNSIGNED_SHORT(GL11C.GL_UNSIGNED_SHORT, EGlVersion.GL_11),
- UNSIGNED_SHORT_5_6_5(GL12C.GL_UNSIGNED_SHORT_5_6_5, EGlVersion.GL_12),
- UNSIGNED_SHORT_5_6_5_REV(GL12C.GL_UNSIGNED_SHORT_5_6_5_REV, EGlVersion.GL_12),
- UNSIGNED_SHORT_4_4_4_4(GL12C.GL_UNSIGNED_SHORT_4_4_4_4, EGlVersion.GL_12),
- UNSIGNED_SHORT_4_4_4_4_REV(GL12C.GL_UNSIGNED_SHORT_4_4_4_4_REV, EGlVersion.GL_12),
- UNSIGNED_SHORT_5_5_5_1(GL12C.GL_UNSIGNED_SHORT_5_5_5_1, EGlVersion.GL_12),
- UNSIGNED_SHORT_1_5_5_5_REV(GL12C.GL_UNSIGNED_SHORT_1_5_5_5_REV, EGlVersion.GL_12),
- UNSIGNED_INT(GL11C.GL_UNSIGNED_INT, EGlVersion.GL_11),
- UNSIGNED_INT_8_8_8_8(GL12C.GL_UNSIGNED_INT_8_8_8_8, EGlVersion.GL_12),
- UNSIGNED_INT_8_8_8_8_REV(GL12C.GL_UNSIGNED_INT_8_8_8_8_REV, EGlVersion.GL_12),
- UNSIGNED_INT_10_10_10_2(GL12C.GL_UNSIGNED_INT_10_10_10_2, EGlVersion.GL_12),
- UNSIGNED_INT_2_10_10_10_REV(GL12C.GL_UNSIGNED_INT_2_10_10_10_REV, EGlVersion.GL_12);
-
-
-
- private final int glFormat;
- private final EGlVersion minimumGlVersion;
-
-
-
- EDhPixelType(int glFormat, EGlVersion minimumGlVersion)
- {
- this.glFormat = glFormat;
- this.minimumGlVersion = minimumGlVersion;
- }
-
-
-
- public static Optional fromString(String name)
- {
- try
- {
- return Optional.of(EDhPixelType.valueOf(name.toUpperCase(Locale.US)));
- }
- catch (IllegalArgumentException e)
- {
- return Optional.empty();
- }
- }
-
- public int getGlFormat() { return glFormat; }
-
- public EGlVersion getMinimumGlVersion() { return minimumGlVersion; }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EGlVersion.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EGlVersion.java
deleted file mode 100644
index e705a1f86..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/texture/EGlVersion.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.seibel.distanthorizons.core.render.glObject.texture;
-
-public enum EGlVersion
-{
- GL_11,
- GL_12,
- GL_30,
- GL_31
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/AbstractVertexAttribute.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/AbstractVertexAttribute.java
deleted file mode 100644
index e4b90c99d..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/AbstractVertexAttribute.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.vertexAttribute;
-
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
-import org.lwjgl.opengl.GL32;
-
-/**
- * Base for binding/unbinding Vertex Attribute objects (VAO's).
- *
- * @see VertexAttributePostGL43
- * @see VertexAttributePreGL43
- */
-public abstract class AbstractVertexAttribute
-{
- /** Stores the handle of the AbstractVertexAttribute. */
- public final int id;
-
-
-
- //==============//
- // constructors //
- //==============//
-
- // This will bind AbstractVertexAttribute
- protected AbstractVertexAttribute()
- {
- this.id = GL32.glGenVertexArrays();
- GL32.glBindVertexArray(this.id);
- }
-
- public static AbstractVertexAttribute create()
- {
- if (GLProxy.getInstance().vertexAttributeBufferBindingSupported)
- {
- return new VertexAttributePostGL43();
- }
- else
- {
- return new VertexAttributePreGL43();
- }
- }
-
-
-
- //=========//
- // binding //
- //=========//
-
- public void bind() { GL32.glBindVertexArray(this.id); }
- public void unbind() { GL32.glBindVertexArray(0); }
-
- /** Always remember to always free your resources! */
- public void free() { GL32.glDeleteVertexArrays(this.id); }
-
-
-
- //==================//
- // abstract methods //
- //==================//
-
- /** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
- public abstract void bindBufferToAllBindingPoints(int buffer);
- /** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
- public abstract void bindBufferToBindingPoint(int buffer, int bindingPoint);
- /** Requires both AbstractVertexAttribute to be bound */
- public abstract void unbindBuffersFromAllBindingPoint();
- /** Requires both AbstractVertexAttribute to be bound */
- public abstract void unbindBuffersFromBindingPoint(int bindingPoint);
- /** Requires both AbstractVertexAttribute to be bound */
- public abstract void setVertexAttribute(int bindingPoint, int attributeIndex, VertexPointer attribute);
- /** Requires both AbstractVertexAttribute to be bound */
- public abstract void completeAndCheck(int expectedStrideSize);
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexAttributePostGL43.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexAttributePostGL43.java
deleted file mode 100644
index 658227d6b..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexAttributePostGL43.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.vertexAttribute;
-
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
-import org.lwjgl.opengl.GL43;
-
-/**
- * In OpenGL 4.3 and later, Vertex Attribute got a make-over.
- * Now it provides support for buffer binding points natively.
- * This means that setting up the VAO is just use ONE native call when
- * binding to a buffer.
- *
- * Since I no longer need to implement binding points, I also no
- * longer needs to keep track of Pointers.
- */
-public final class VertexAttributePostGL43 extends AbstractVertexAttribute
-{
- private static final DhLogger LOGGER = new DhLoggerBuilder()
- .fileLevelConfig(Config.Common.Logging.logRendererGLEventToFile)
- .chatLevelConfig(Config.Common.Logging.logRendererGLEventToChat)
- .build();
-
-
- int numberOfBindingPoints = 0;
- int strideSize = 0;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- /** This will bind the {@link AbstractVertexAttribute} */
- public VertexAttributePostGL43()
- {
- super(); // also bind AbstractVertexAttribute
- }
-
-
-
- //=========//
- // binding //
- //=========//
-
- /** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
- @Override
- public void bindBufferToAllBindingPoints(int buffer)
- {
- for (int i = 0; i < this.numberOfBindingPoints; i++)
- {
- GL43.glBindVertexBuffer(i, buffer, 0, this.strideSize);
- }
- }
-
- /** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
- @Override
- public void bindBufferToBindingPoint(int buffer, int bindingPoint)
- {
- GL43.glBindVertexBuffer(bindingPoint, buffer, 0, this.strideSize);
- }
-
-
-
- //===========//
- // unbinding //
- //===========//
-
- /** Requires AbstractVertexAttribute to be bound */
- @Override
- public void unbindBuffersFromAllBindingPoint()
- {
- for (int i = 0; i < this.numberOfBindingPoints; i++)
- {
- GL43.glBindVertexBuffer(i, 0, 0, 0);
- }
- }
-
- /** Requires AbstractVertexAttribute to be bound */
- @Override
- public void unbindBuffersFromBindingPoint(int bindingPoint)
- {
- GL43.glBindVertexBuffer(bindingPoint, 0, 0, 0);
- }
-
-
-
- //==========================//
- // manual attribute setting //
- //==========================//
-
- /** Requires AbstractVertexAttribute to be bound */
- @Override
- public void setVertexAttribute(int bindingPoint, int attributeIndex, VertexPointer attribute)
- {
- if (attribute.useInteger)
- {
- GL43.glVertexAttribIFormat(attributeIndex, attribute.elementCount, attribute.glType, this.strideSize);
- }
- else
- {
- GL43.glVertexAttribFormat(attributeIndex, attribute.elementCount, attribute.glType,
- attribute.normalized, this.strideSize); // Here strideSize is new attrib offset
- }
-
- this.strideSize += attribute.byteSize;
- if (this.numberOfBindingPoints <= bindingPoint)
- {
- this.numberOfBindingPoints = bindingPoint + 1;
- }
- GL43.glVertexAttribBinding(attributeIndex, bindingPoint);
- GL43.glEnableVertexAttribArray(attributeIndex);
- }
-
-
-
- //============//
- // validation //
- //============//
-
- /** Requires AbstractVertexAttribute to be bound */
- @Override
- public void completeAndCheck(int expectedStrideSize)
- {
- if (this.strideSize != expectedStrideSize)
- {
- LOGGER.error("Vertex Attribute calculated stride size " + this.strideSize +
- " does not match the provided expected stride size " + expectedStrideSize + "!");
- throw new IllegalArgumentException("Vertex Attribute Incorrect Format");
- }
-
- LOGGER.info("Vertex Attribute (GL43+) completed. It contains " + this.numberOfBindingPoints
- + " binding points and a stride size of " + this.strideSize);
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexAttributePreGL43.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexAttributePreGL43.java
deleted file mode 100644
index ac0bec5c5..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexAttributePreGL43.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.vertexAttribute;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
-import org.lwjgl.opengl.GL32;
-
-
-public final class VertexAttributePreGL43 extends AbstractVertexAttribute
-{
- private static final DhLogger LOGGER = new DhLoggerBuilder()
- .fileLevelConfig(Config.Common.Logging.logRendererGLEventToFile)
- .chatLevelConfig(Config.Common.Logging.logRendererGLEventToChat)
- .build();
-
-
- // I tried to use raw arrays as much as possible since those lookups
- // happen every frame, and the speed directly affects fps
- int strideSize = 0;
- int[][] bindingPointsToIndex;
- VertexPointer[] pointers;
- int[] pointersOffset;
-
- TreeMap> bindingPointsToIndexBuilder;
- ArrayList pointersBuilder;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- /** This will bind the {@link AbstractVertexAttribute} */
- public VertexAttributePreGL43()
- {
- super(); // also bind AbstractVertexAttribute
- this.bindingPointsToIndexBuilder = new TreeMap<>();
- this.pointersBuilder = new ArrayList<>();
- }
-
-
-
- //=========//
- // binding //
- //=========//
-
- /** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
- @Override
- public void bindBufferToAllBindingPoints(int buffer)
- {
- for (int i = 0; i < this.pointers.length; i++)
- {
- GL32.glEnableVertexAttribArray(i);
- }
-
- for (int i = 0; i < this.pointers.length; i++)
- {
- VertexPointer pointer = this.pointers[i];
- if (pointer == null)
- {
- continue;
- }
-
- if (pointer.useInteger)
- {
- GL32.glVertexAttribIPointer(i, pointer.elementCount, pointer.glType,
- this.strideSize, this.pointersOffset[i]);
- }
- else
- {
- GL32.glVertexAttribPointer(i, pointer.elementCount, pointer.glType,
- pointer.normalized, this.strideSize, this.pointersOffset[i]);
- }
- }
- }
-
- /** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
- @Override
- public void bindBufferToBindingPoint(int buffer, int bindingPoint)
- {
- int[] bindingPointIndexes = this.bindingPointsToIndex[bindingPoint];
-
- for (int bindingPointIndex : bindingPointIndexes)
- {
- GL32.glEnableVertexAttribArray(bindingPointIndex);
- }
-
- for (int bindingPointIndex : bindingPointIndexes)
- {
- VertexPointer pointer = this.pointers[bindingPointIndex];
- if (pointer == null)
- {
- continue;
- }
-
- if (pointer.useInteger)
- {
- GL32.glVertexAttribIPointer(bindingPointIndex, pointer.elementCount, pointer.glType,
- this.strideSize, this.pointersOffset[bindingPointIndex]);
- }
- else
- {
- GL32.glVertexAttribPointer(bindingPointIndex, pointer.elementCount, pointer.glType,
- pointer.normalized, this.strideSize, this.pointersOffset[bindingPointIndex]);
- }
- }
-
- }
-
-
-
- //===========//
- // unbinding //
- //===========//
-
- /** Requires AbstractVertexAttribute to be bound */
- @Override
- public void unbindBuffersFromAllBindingPoint()
- {
- for (int i = 0; i < this.pointers.length; i++)
- {
- GL32.glDisableVertexAttribArray(i);
- }
- }
-
- /** Requires AbstractVertexAttribute to be bound */
- @Override
- public void unbindBuffersFromBindingPoint(int bindingPoint)
- {
- int[] bindingPointIndexes = this.bindingPointsToIndex[bindingPoint];
- for (int bindingPointIndex : bindingPointIndexes)
- {
- GL32.glDisableVertexAttribArray(bindingPointIndex);
- }
- }
-
-
-
- //==========================//
- // manual attribute setting //
- //==========================//
-
- /** Requires AbstractVertexAttribute to be bound */
- @Override
- public void setVertexAttribute(int bindingPoint, int attributeIndex, VertexPointer attribute)
- {
- TreeSet intArray = this.bindingPointsToIndexBuilder.computeIfAbsent(bindingPoint, k -> new TreeSet<>());
- intArray.add(attributeIndex);
-
- while (this.pointersBuilder.size() <= attributeIndex)
- {
- // This is dumb, but ArrayList doesn't have a resize, And this code
- // should only be run when it's building the Vertex Attribute anyway.
- this.pointersBuilder.add(null);
- }
- this.pointersBuilder.set(attributeIndex, attribute);
- }
-
-
-
- //============//
- // validation //
- //============//
-
- /** Requires AbstractVertexAttribute to be bound */
- @Override
- public void completeAndCheck(int expectedStrideSize)
- {
- int maxBindPointNumber = this.bindingPointsToIndexBuilder.lastKey();
- this.bindingPointsToIndex = new int[maxBindPointNumber + 1][];
-
- this.bindingPointsToIndexBuilder.forEach((Integer i, TreeSet set) ->
- {
- this.bindingPointsToIndex[i] = new int[set.size()];
- Iterator iter = set.iterator();
- for (int j = 0; j < set.size(); j++)
- {
- this.bindingPointsToIndex[i][j] = iter.next();
- }
- });
-
- this.pointers = this.pointersBuilder.toArray(new VertexPointer[this.pointersBuilder.size()]);
- this.pointersOffset = new int[this.pointers.length];
- this.pointersBuilder = null; // Release the builder
- this.bindingPointsToIndexBuilder = null; // Release the builder
-
- // Check if all pointers are valid
- int currentOffset = 0;
- for (int i = 0; i < this.pointers.length; i++)
- {
- VertexPointer pointer = this.pointers[i];
- if (pointer == null)
- {
- LOGGER.warn("Vertex Attribute index " + i + " is not set! No index should be skipped normally!");
- continue;
- }
- this.pointersOffset[i] = currentOffset;
- currentOffset += pointer.byteSize;
- }
-
- if (currentOffset != expectedStrideSize)
- {
- LOGGER.error("Vertex Attribute calculated stride size " + currentOffset +
- " does not match the provided expected stride size " + expectedStrideSize + "!");
- throw new IllegalArgumentException("Vertex Attribute Incorrect Format");
- }
- this.strideSize = currentOffset;
- LOGGER.info("Vertex Attribute (pre GL43) completed.");
-
- // Debug logging
- LOGGER.debug("AttributeIndex: ElementCount, glType, normalized, strideSize, offset");
-
- for (int i = 0; i < this.pointers.length; i++)
- {
- VertexPointer pointer = this.pointers[i];
- if (pointer == null)
- {
- LOGGER.debug(i + ": Null!!!!");
- }
- else
- {
- LOGGER.debug(i + ": " + pointer.elementCount + ", " +
- pointer.glType + ", " + pointer.normalized + ", " + this.strideSize + ", " + this.pointersOffset[i]);
- }
- }
-
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexPointer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexPointer.java
deleted file mode 100644
index 061827aa3..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/glObject/vertexAttribute/VertexPointer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.glObject.vertexAttribute;
-
-import com.seibel.distanthorizons.coreapi.util.MathUtil;
-import org.lwjgl.opengl.GL32;
-
-public final class VertexPointer
-{
- public final int elementCount;
- public final int glType;
- public final boolean normalized;
- public final int byteSize;
- public final boolean useInteger;
-
-
-
- // basic constructors //
-
- public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize, boolean useInteger)
- {
- this.elementCount = elementCount;
- this.glType = glType;
- this.normalized = normalized;
- this.byteSize = byteSize;
- this.useInteger = useInteger;
- }
- public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize)
- {
- this(elementCount, glType, normalized, byteSize, false);
- }
- private static int _align(int bytes) { return MathUtil.ceilDiv(bytes, 4) * 4; }
-
-
-
- // named constructors //
-
- public static VertexPointer addFloatPointer(boolean normalized) { return new VertexPointer(1, GL32.GL_FLOAT, normalized, Float.BYTES); }
- public static VertexPointer addVec2Pointer(boolean normalized) { return new VertexPointer(2, GL32.GL_FLOAT, normalized, Float.BYTES * 2); }
- public static VertexPointer addVec3Pointer(boolean normalized) { return new VertexPointer(3, GL32.GL_FLOAT, normalized, Float.BYTES * 3); }
- public static VertexPointer addVec4Pointer(boolean normalized) { return new VertexPointer(4, GL32.GL_FLOAT, normalized, Float.BYTES * 4); }
- /** Always aligned to 4 bytes */
- public static VertexPointer addUnsignedBytePointer(boolean normalized, boolean useInteger) { return new VertexPointer(1, GL32.GL_UNSIGNED_BYTE, normalized, 4, useInteger); }
- /** aligned to 4 bytes */
- public static VertexPointer addUnsignedBytesPointer(int elementCount, boolean normalized, boolean useInteger)
- { return new VertexPointer(elementCount, GL32.GL_UNSIGNED_BYTE, normalized, _align(elementCount), useInteger); }
- public static VertexPointer addUnsignedShortsPointer(int elementCount, boolean normalized, boolean useInteger)
- { return new VertexPointer(elementCount, GL32.GL_UNSIGNED_SHORT, normalized, _align(elementCount * 2), useInteger); }
- public static VertexPointer addShortsPointer(int elementCount, boolean normalized, boolean useInteger) { return new VertexPointer(elementCount, GL32.GL_SHORT, normalized, _align(elementCount * 2), useInteger); }
- public static VertexPointer addIntPointer(boolean normalized, boolean useInteger) { return new VertexPointer(1, GL32.GL_INT, normalized, 4, useInteger); }
- public static VertexPointer addIVec2Pointer(boolean normalized, boolean useInteger) { return new VertexPointer(2, GL32.GL_INT, normalized, 8, useInteger); }
- public static VertexPointer addIVec3Pointer(boolean normalized, boolean useInteger) { return new VertexPointer(3, GL32.GL_INT, normalized, 12, useInteger); }
- public static VertexPointer addIVec4Pointer(boolean normalized, boolean useInteger) { return new VertexPointer(4, GL32.GL_INT, normalized, 16, useInteger); }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DebugRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/AbstractDebugWireframeRenderer.java
similarity index 53%
rename from core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DebugRenderer.java
rename to core/src/main/java/com/seibel/distanthorizons/core/render/renderer/AbstractDebugWireframeRenderer.java
index 0df411af5..3604c050e 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DebugRenderer.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/AbstractDebugWireframeRenderer.java
@@ -1,199 +1,42 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
package com.seibel.distanthorizons.core.render.renderer;
-import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLogger;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
-import com.seibel.distanthorizons.core.render.glObject.buffer.GLElementBuffer;
-import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
+import com.seibel.distanthorizons.core.render.RenderParams;
import com.seibel.distanthorizons.core.util.math.Mat4f;
import com.seibel.distanthorizons.core.util.math.Vec3d;
import com.seibel.distanthorizons.core.util.math.Vec3f;
+import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.lwjgl.opengl.GL32;
import java.awt.*;
import java.lang.ref.WeakReference;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
import java.util.concurrent.PriorityBlockingQueue;
-/**
- * Handles rendering the wireframe particles
- * that are used for seeing what the system's doing.
- */
-public class DebugRenderer
+public abstract class AbstractDebugWireframeRenderer implements IBindable
{
- public static DebugRenderer INSTANCE = new DebugRenderer();
+ protected static final DhLogger RATE_LIMITED_LOGGER = new DhLoggerBuilder()
+ .maxCountPerSecond(1)
+ .build();
- public static final DhLogger LOGGER = new DhLoggerBuilder().build();
- public static final DhLogger RATE_LIMITED_LOGGER = new DhLoggerBuilder()
- .maxCountPerSecond(1)
- .build();
-
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
+ protected static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
-
- // rendering setup
- private ShaderProgram basicShader;
- private GLVertexBuffer vertexBuffer;
- private GLElementBuffer outlineIndexBuffer;
- private AbstractVertexAttribute va;
- private boolean init = false;
+ protected final RendererLists rendererLists = new RendererLists();
+ protected final PriorityBlockingQueue particles = new PriorityBlockingQueue<>();
// used when rendering
- private Mat4f transformationMatrixThisFrame;
- private Vec3f camPosFloatThisFrame;
-
-
- private final RendererLists rendererLists = new RendererLists();
- private final PriorityBlockingQueue particles = new PriorityBlockingQueue<>();
-
-
-
- /** A box from 0,0,0 to 1,1,1 */
- private static final float[] BOX_VERTICES = {
- //region
- // Pos x y z
- 0, 0, 0,
- 1, 0, 0,
- 1, 1, 0,
- 0, 1, 0,
- 0, 0, 1,
- 1, 0, 1,
- 1, 1, 1,
- 0, 1, 1,
- //endregion
- };
-
- private static final int[] BOX_OUTLINE_INDICES = {
- //region
- 0, 1,
- 1, 2,
- 2, 3,
- 3, 0,
-
- 4, 5,
- 5, 6,
- 6, 7,
- 7, 4,
-
- 0, 4,
- 1, 5,
- 2, 6,
- 3, 7,
- //endregion
- };
-
-
-
- //=============//
- // constructor //
- //=============//
- //region
-
- private DebugRenderer() { }
-
- public void init()
- {
- if (this.init)
- {
- return;
- }
- this.init = true;
-
- this.va = AbstractVertexAttribute.create();
- this.va.bind();
- // Pos
- this.va.setVertexAttribute(0, 0, VertexPointer.addVec3Pointer(false));
- this.va.completeAndCheck(Float.BYTES * 3);
- this.basicShader = new ShaderProgram(
- "shaders/debug/vert.vert",
- "shaders/debug/frag.frag",
- "vPosition"
- );
- this.createBuffer();
- }
-
- private void createBuffer()
- {
- // box vertices
- ByteBuffer boxVerticesBuffer = ByteBuffer.allocateDirect(BOX_VERTICES.length * Float.BYTES);
- boxVerticesBuffer.order(ByteOrder.nativeOrder());
- boxVerticesBuffer.asFloatBuffer().put(BOX_VERTICES);
- boxVerticesBuffer.rewind();
- this.vertexBuffer = new GLVertexBuffer(false);
- this.vertexBuffer.bind();
- this.vertexBuffer.uploadBuffer(boxVerticesBuffer, 8, EDhApiGpuUploadMethod.DATA, BOX_VERTICES.length * Float.BYTES);
-
-
- // outline vertex indexes
- ByteBuffer boxOutlineBuffer = ByteBuffer.allocateDirect(BOX_OUTLINE_INDICES.length * Integer.BYTES);
- boxOutlineBuffer.order(ByteOrder.nativeOrder());
- boxOutlineBuffer.asIntBuffer().put(BOX_OUTLINE_INDICES);
- boxOutlineBuffer.rewind();
- this.outlineIndexBuffer = new GLElementBuffer(false);
- this.outlineIndexBuffer.uploadBuffer(boxOutlineBuffer, EDhApiGpuUploadMethod.DATA, BOX_OUTLINE_INDICES.length * Integer.BYTES, GL32.GL_STATIC_DRAW);
-
- }
-
- //endregion
-
-
-
- //==============//
- // registration //
- //==============//
- //region
-
- public static void makeParticle(BoxParticle particle)
- {
- if (INSTANCE != null && Config.Client.Advanced.Debugging.DebugWireframe.enableRendering.get())
- {
- INSTANCE.particles.add(particle);
- }
- }
-
- public static void register(IDebugRenderable renderable, ConfigEntry config) { if (INSTANCE != null) { INSTANCE.addRenderer(renderable, config); } }
- public void addRenderer(IDebugRenderable renderable, ConfigEntry config) { this.rendererLists.addRenderable(renderable, config); }
-
- public static void unregister(IDebugRenderable renderable, ConfigEntry config) { if (INSTANCE != null) { INSTANCE.removeRenderer(renderable, config); } }
- private void removeRenderer(IDebugRenderable renderable, ConfigEntry config) { this.rendererLists.removeRenderable(renderable, config); }
-
- public static void clearRenderables() { INSTANCE.rendererLists.clearRenderables(); }
-
- //endregion
+ protected Mat4f dhMvmProjMatrixThisFrame;
+ protected Vec3f camPosFloatThisFrame;
@@ -202,27 +45,17 @@ public class DebugRenderer
//===========//
//region
- public void render(Mat4f transform)
+ public void render(RenderParams renderParams)
{
- this.transformationMatrixThisFrame = transform;
+ this.dhMvmProjMatrixThisFrame = new Mat4f(renderParams.dhMvmProjMatrix);
Vec3d camPos = MC_RENDER.getCameraExactPosition();
this.camPosFloatThisFrame = new Vec3f((float) camPos.x, (float) camPos.y, (float) camPos.z);
- this.init();
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_LINE);
- GLMC.enableDepthTest();
-
- this.basicShader.bind();
- this.va.bind();
- this.va.bindBufferToAllBindingPoints(this.vertexBuffer.getId());
-
-
- this.outlineIndexBuffer.bind();
this.rendererLists.render(this);
- // particle rendering
+ // particle cleanup
BoxParticle head = null;
while ((head = this.particles.poll()) != null && head.isDead())
{ /* remove dead particles */ }
@@ -233,28 +66,41 @@ public class DebugRenderer
}
- // box rendering
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
+ // particle rendering
for (BoxParticle particle : this.particles)
{
// a new box is created each time since the height will be different based on the time it's lived
this.renderBox(particle.createNewRenderBox());
}
+
}
- public void renderBox(Box box)
+ public abstract void renderBox(Box box);
+
+ //endregion
+
+
+
+ //==============//
+ // registration //
+ //==============//
+ //region
+
+ public void makeParticle(BoxParticle particle)
{
- Mat4f boxTransform = Mat4f.createTranslateMatrix(box.minPos.x - this.camPosFloatThisFrame.x, box.minPos.y - this.camPosFloatThisFrame.y, box.minPos.z - this.camPosFloatThisFrame.z);
- boxTransform.multiply(Mat4f.createScaleMatrix(box.maxPos.x - box.minPos.x, box.maxPos.y - box.minPos.y, box.maxPos.z - box.minPos.z));
-
- Mat4f transformMatrix = this.transformationMatrixThisFrame.copy();
- transformMatrix.multiply(boxTransform);
- this.basicShader.setUniform(this.basicShader.getUniformLocation("uTransform"), transformMatrix);
-
- this.basicShader.setUniform(this.basicShader.getUniformLocation("uColor"), box.color);
-
- GL32.glDrawElements(GL32.GL_LINES, BOX_OUTLINE_INDICES.length, GL32.GL_UNSIGNED_INT, 0);
+ if (Config.Client.Advanced.Debugging.DebugWireframe.enableRendering.get())
+ {
+ this.particles.add(particle);
+ }
}
+
+ public void register(IDebugRenderable renderable, ConfigEntry config) { this.addRenderer(renderable, config); }
+ public void addRenderer(IDebugRenderable renderable, ConfigEntry config) { this.rendererLists.addRenderable(renderable, config); }
+
+ public void unregister(IDebugRenderable renderable, ConfigEntry config) { this.removeRenderer(renderable, config); }
+ public void removeRenderer(IDebugRenderable renderable, ConfigEntry config) { this.rendererLists.removeRenderable(renderable, config); }
+
+ public void clearRenderables() { this.rendererLists.clearRenderables(); }
//endregion
@@ -318,7 +164,7 @@ public class DebugRenderer
@Override
- public int compareTo(@NotNull DebugRenderer.BoxParticle particle)
+ public int compareTo(@NotNull BoxParticle particle)
{ return Long.compare(this.startMsTime + this.durationInMs, particle.startMsTime + particle.durationInMs); }
/** will change each time it's called based on the yChange value and time */
@@ -340,7 +186,7 @@ public class DebugRenderer
}
- private static class RendererLists
+ protected static class RendererLists
{
public final LinkedList> generalRenderableList = new LinkedList<>();
@@ -383,7 +229,7 @@ public class DebugRenderer
if (this.renderableListByConfig.containsKey(config))
{
LinkedList> renderableList = this.renderableListByConfig.get(config);
- this.removeRenderableFromInternalList(renderableList, renderable);
+ this.removeRenderableFromInternalList(renderableList, renderable);
}
}
else
@@ -433,7 +279,7 @@ public class DebugRenderer
//===========//
//region
- public void render(DebugRenderer debugRenderer)
+ public void render(AbstractDebugWireframeRenderer debugRenderer)
{
this.renderList(debugRenderer, this.generalRenderableList);
@@ -446,7 +292,7 @@ public class DebugRenderer
}
}
}
- private void renderList(DebugRenderer debugRenderer, LinkedList> rendererList)
+ private void renderList(AbstractDebugWireframeRenderer debugRenderer, LinkedList> rendererList)
{
synchronized (this)
{
@@ -478,4 +324,6 @@ public class DebugRenderer
//endregion
+
+
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/BeaconRenderHandler.java
similarity index 94%
rename from core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java
rename to core/src/main/java/com/seibel/distanthorizons/core/render/renderer/BeaconRenderHandler.java
index 61c325a9a..4acdc5d01 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/BeaconRenderHandler.java
@@ -17,9 +17,10 @@
* along with this program. If not, see .
*/
-package com.seibel.distanthorizons.core.render.renderer.generic;
+package com.seibel.distanthorizons.core.render.renderer;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
+import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderObjectFactory;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
@@ -36,6 +37,7 @@ import com.seibel.distanthorizons.core.util.RenderUtil;
import com.seibel.distanthorizons.core.util.math.Vec3d;
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhGenericRenderer;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.logging.DhLogger;
import org.jetbrains.annotations.NotNull;
@@ -50,6 +52,7 @@ public class BeaconRenderHandler
{
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
+ private static final IDhApiCustomRenderObjectFactory GENERIC_OBJECT_FACTORY = SingletonInjector.INSTANCE.get(IDhApiCustomRenderObjectFactory.class);
/** how often should we check if a beacon should be culled? */
private static final int MAX_CULLING_FREQUENCY_IN_MS = 1_000;
@@ -77,9 +80,9 @@ public class BeaconRenderHandler
//=============//
//region
- public BeaconRenderHandler(@NotNull GenericObjectRenderer renderer)
+ public BeaconRenderHandler(@NotNull IDhGenericRenderer renderer)
{
- this.activeBeaconBoxRenderGroup = GenericRenderObjectFactory.INSTANCE.createAbsolutePositionedGroup(ModInfo.NAME+":Beacons", new ArrayList<>(0));
+ this.activeBeaconBoxRenderGroup = GENERIC_OBJECT_FACTORY.createAbsolutePositionedGroup(ModInfo.NAME+":Beacons", new ArrayList<>(0));
this.activeBeaconBoxRenderGroup.setBlockLight(LodUtil.MAX_MC_LIGHT);
this.activeBeaconBoxRenderGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
this.activeBeaconBoxRenderGroup.setSsaoEnabled(false);
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/CloudRenderHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/CloudRenderHandler.java
similarity index 95%
rename from core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/CloudRenderHandler.java
rename to core/src/main/java/com/seibel/distanthorizons/core/render/renderer/CloudRenderHandler.java
index 5286f26e4..e37682b1d 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/CloudRenderHandler.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/CloudRenderHandler.java
@@ -17,9 +17,10 @@
* along with this program. If not, see .
*/
-package com.seibel.distanthorizons.core.render.renderer.generic;
+package com.seibel.distanthorizons.core.render.renderer;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
+import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderObjectFactory;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
@@ -33,6 +34,7 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.math.Vec3d;
import com.seibel.distanthorizons.core.util.math.Vec3f;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhGenericRenderer;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.logging.DhLogger;
@@ -49,6 +51,7 @@ public class CloudRenderHandler
{
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
+ private static final IDhApiCustomRenderObjectFactory GENERIC_OBJECT_FACTORY = SingletonInjector.INSTANCE.get(IDhApiCustomRenderObjectFactory.class);
private static final String CLOUD_RESOURCE_TEXTURE_PATH = "assets/distanthorizons/textures/clouds.png";
@@ -80,7 +83,7 @@ public class CloudRenderHandler
= new IDhApiRenderableBoxGroup[(CLOUD_INSTANCE_RADIUS_COUNT * 2) + 1][(CLOUD_INSTANCE_RADIUS_COUNT * 2) + 1];
private final IDhClientLevel level;
- private final GenericObjectRenderer renderer;
+ private final IDhGenericRenderer renderer;
/** cached array so we don't need to re-create it each frame for each cloud group */
private final Vec3d[] cullingCorners = new Vec3d[]
@@ -102,7 +105,7 @@ public class CloudRenderHandler
//=============//
//region
- public CloudRenderHandler(IDhClientLevel level, GenericObjectRenderer renderer)
+ public CloudRenderHandler(IDhClientLevel level, IDhGenericRenderer renderer)
{
this.level = level;
this.renderer = renderer;
@@ -270,7 +273,7 @@ public class CloudRenderHandler
{
for (int z = -CLOUD_INSTANCE_RADIUS_COUNT; z <= CLOUD_INSTANCE_RADIUS_COUNT; z++)
{
- IDhApiRenderableBoxGroup boxGroup = GenericRenderObjectFactory.INSTANCE.createRelativePositionedGroup(
+ IDhApiRenderableBoxGroup boxGroup = GENERIC_OBJECT_FACTORY.createRelativePositionedGroup(
ModInfo.NAME + ":Clouds",
new DhApiVec3d(0, 0, 0), // the offset will be set during rendering
boxList);
@@ -316,16 +319,16 @@ public class CloudRenderHandler
return;
}
- if (!this.renderer.getInstancedRenderingAvailable())
- {
- if (!this.disabledWarningLogged)
- {
- this.disabledWarningLogged = true;
- LOGGER.warn("Instanced rendering unavailable, cloud rendering disabled.");
- }
- boxGroup.setActive(false);
- return;
- }
+ //if (!this.renderer.getInstancedRenderingAvailable())
+ //{
+ // if (!this.disabledWarningLogged)
+ // {
+ // this.disabledWarningLogged = true;
+ // LOGGER.warn("Instanced rendering unavailable, cloud rendering disabled.");
+ // }
+ // boxGroup.setActive(false);
+ // return;
+ //}
IClientLevelWrapper clientLevelWrapper = this.level.getClientLevelWrapper();
if (clientLevelWrapper == null)
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhFadeRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhFadeRenderer.java
deleted file mode 100644
index ad0d1d298..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhFadeRenderer.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.renderer.shaders.DhFadeShader;
-import com.seibel.distanthorizons.core.render.renderer.shaders.FadeApplyShader;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
-import org.lwjgl.opengl.GL32;
-import org.lwjgl.opengl.GL43C;
-
-import java.nio.ByteBuffer;
-
-/**
- * Handles fading MC and DH together via {@link DhFadeShader} and {@link FadeApplyShader}.
- *
- * {@link DhFadeShader} - draws the Fade to a texture.
- * {@link FadeApplyShader} - draws the Fade texture to DH's framebuffer.
- */
-public class DhFadeRenderer
-{
-
- public static DhFadeRenderer INSTANCE = new DhFadeRenderer();
- private static final DhLogger LOGGER = new DhLoggerBuilder().build();
-
- private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- private boolean init = false;
-
- private int width = -1;
- private int height = -1;
- private int fadeFramebuffer = -1;
-
- private int fadeTexture = -1;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- private DhFadeRenderer() { }
-
- public void init()
- {
- if (this.init) return;
- this.init = true;
-
- DhFadeShader.INSTANCE.init();
- FadeApplyShader.INSTANCE.init();
- }
-
- private void createFramebuffer(int width, int height)
- {
- if (this.fadeFramebuffer != -1)
- {
- GL32.glDeleteFramebuffers(this.fadeFramebuffer);
- this.fadeFramebuffer = -1;
- }
-
- this.fadeFramebuffer = GL32.glGenFramebuffers();
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.fadeFramebuffer);
-
-
- if (this.fadeTexture != -1)
- {
- GLMC.glDeleteTextures(this.fadeTexture);
- this.fadeTexture = -1;
- }
-
- this.fadeTexture = GL32.glGenTextures();
- {
- GLMC.glBindTexture(this.fadeTexture);
- GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, GL32.GL_RGBA16, width, height, 0, GL32.GL_RGBA, GL32.GL_UNSIGNED_SHORT_4_4_4_4, (ByteBuffer) null);
- GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MIN_FILTER, GL32.GL_LINEAR);
- GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MAG_FILTER, GL32.GL_LINEAR);
-
- // disable mip-mapping since DH is just going to draw straight to the screen
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_BASE_LEVEL, 0);
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_MAX_LEVEL, 0);
- }
-
- GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.fadeTexture, 0);
-
- }
-
-
-
- //========//
- // render //
- //========//
-
- public void render(Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix, float partialTicks, IProfilerWrapper profiler)
- {
- try
- {
- profiler.push("Fade Generate");
-
- this.init();
-
- // resize the framebuffer if necessary
- int width = MC_RENDER.getTargetFramebufferViewportWidth();
- int height = MC_RENDER.getTargetFramebufferViewportHeight();
- if (this.width != width || this.height != height)
- {
- this.width = width;
- this.height = height;
- this.createFramebuffer(width, height);
- }
-
-
- DhFadeShader.INSTANCE.frameBuffer = this.fadeFramebuffer;
- DhFadeShader.INSTANCE.setProjectionMatrix(mcModelViewMatrix, mcProjectionMatrix);
- DhFadeShader.INSTANCE.render(partialTicks);
-
- // restored so we can write the fade texture to the main frame buffer
- //mcState.restore();
-
- profiler.popPush("Fade Apply");
-
- FadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
- FadeApplyShader.INSTANCE.readFramebuffer = DhFadeShader.INSTANCE.frameBuffer;
- FadeApplyShader.INSTANCE.drawFramebuffer = LodRenderer.INSTANCE.getActiveFramebufferId();
- FadeApplyShader.INSTANCE.render(partialTicks);
- }
- catch (Exception e)
- {
- LOGGER.error("Unexpected error during fade render, error: ["+e.getMessage()+"].", e);
- }
- finally
- {
- profiler.pop();
- }
- }
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhTerrainShaderProgram.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhTerrainShaderProgram.java
deleted file mode 100644
index 35298e10d..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhTerrainShaderProgram.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer;
-
-import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShaderProgram;
-import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
-import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodQuadBuilder;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
-import com.seibel.distanthorizons.core.render.glObject.shader.Shader;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttributePostGL43;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttributePreGL43;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
-import com.seibel.distanthorizons.core.util.LodUtil;
-import com.seibel.distanthorizons.core.util.RenderUtil;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.util.math.Vec3f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
-
-/**
- * Handles rendering the normal LOD terrain.
- * @see LodQuadBuilder
- */
-public class DhTerrainShaderProgram extends ShaderProgram implements IDhApiShaderProgram
-{
- public final AbstractVertexAttribute vao;
-
- // Uniforms
- public int uCombinedMatrix = -1;
- public int uModelOffset = -1;
- public int uWorldYOffset = -1;
-
- public int uMircoOffset = -1;
- public int uEarthRadius = -1;
- public int uLightMap = -1;
-
- // fragment shader uniforms
- public int uClipDistance = -1;
- public int uDitherDhRendering = -1;
-
- // Noise Uniforms
- public int uNoiseEnabled = -1;
- public int uNoiseSteps = -1;
- public int uNoiseIntensity = -1;
- public int uNoiseDropoff = -1;
-
- // Debug Uniform
- public int uIsWhiteWorld = -1;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- // This will bind AbstractVertexAttribute
- public DhTerrainShaderProgram()
- {
- super(
- "shaders/standard.vert",
- "shaders/flat_shaded.frag",
- new String[]{"vPosition", "color"}
- );
-
- this.uCombinedMatrix = this.getUniformLocation("uCombinedMatrix");
- this.uModelOffset = this.getUniformLocation("uModelOffset");
- this.uWorldYOffset = this.getUniformLocation("uWorldYOffset");
- this.uDitherDhRendering = this.getUniformLocation("uDitherDhRendering");
- this.uMircoOffset = this.getUniformLocation("uMircoOffset");
- this.uEarthRadius = this.getUniformLocation("uEarthRadius");
-
- this.uLightMap = this.getUniformLocation("uLightMap");
-
- // Fog/Clip Uniforms
- this.uClipDistance = this.getUniformLocation("uClipDistance");
-
- // Noise Uniforms
- this.uNoiseEnabled = this.getUniformLocation("uNoiseEnabled");
- this.uNoiseSteps = this.getUniformLocation("uNoiseSteps");
- this.uNoiseIntensity = this.getUniformLocation("uNoiseIntensity");
- this.uNoiseDropoff = this.getUniformLocation("uNoiseDropoff");
-
- // Debug Uniform
- this.uIsWhiteWorld = this.getUniformLocation("uIsWhiteWorld");
-
-
- if (GLProxy.getInstance().vertexAttributeBufferBindingSupported)
- {
- this.vao = new VertexAttributePostGL43(); // also binds AbstractVertexAttribute
- }
- else
- {
- this.vao = new VertexAttributePreGL43(); // also binds AbstractVertexAttribute
- }
- this.vao.bind();
-
- // short: x, y, z, meta
- // meta: byte skylight, byte blocklight, byte microOffset
- this.vao.setVertexAttribute(0, 0, VertexPointer.addUnsignedShortsPointer(4, false, true));
- // byte: r, g, b, a
- this.vao.setVertexAttribute(0, 1, VertexPointer.addUnsignedBytesPointer(4, true, false));
- // byte: iris material ID, normal index, 2 spacers
- this.vao.setVertexAttribute(0, 2, VertexPointer.addUnsignedBytesPointer(4, true, true));
-
- try
- {
- int vertexByteCount = LodUtil.DH_VERTEX_FORMAT.getByteSize();
- this.vao.completeAndCheck(vertexByteCount);
- }
- catch (RuntimeException e)
- {
- System.out.println(LodUtil.DH_VERTEX_FORMAT);
- throw e;
- }
-
- }
-
-
-
- //=========//
- // methods //
- //=========//
-
- @Override
- public void bind()
- {
- super.bind();
- this.vao.bind();
- }
- @Override
- public void unbind()
- {
- super.unbind();
- this.vao.unbind();
- }
-
- @Override
- public void free()
- {
- this.vao.free();
- super.free();
- }
-
- @Override
- public void bindVertexBuffer(int vbo) { this.vao.bindBufferToAllBindingPoints(vbo); }
-
- @Override
- public void fillUniformData(DhApiRenderParam renderParameters)
- {
- Mat4f combinedMatrix = new Mat4f(renderParameters.dhProjectionMatrix);
- combinedMatrix.multiply(renderParameters.dhModelViewMatrix);
-
- super.bind();
-
- // uniforms
- this.setUniform(this.uCombinedMatrix, combinedMatrix);
- this.setUniform(this.uMircoOffset, 0.01f); // 0.01 block offset
-
- this.setUniform(this.uLightMap, ILightMapWrapper.BOUND_INDEX);
-
- this.setUniform(this.uWorldYOffset, (float) renderParameters.worldYOffset);
-
- this.setUniform(this.uDitherDhRendering, Config.Client.Advanced.Graphics.Quality.ditherDhFade.get());
-
- float curveRatio = Config.Client.Advanced.Graphics.Experimental.earthCurveRatio.get();
- if (curveRatio < -1.0f || curveRatio > 1.0f)
- {
- curveRatio = /*6371KM*/ 6371000.0f / curveRatio;
- }
- else
- {
- // disable curvature if the config value is between -1 and 1
- curveRatio = 0.0f;
- }
- this.setUniform(this.uEarthRadius, curveRatio);
-
- // Noise Uniforms
- this.setUniform(this.uNoiseEnabled, Config.Client.Advanced.Graphics.NoiseTexture.enableNoiseTexture.get());
- this.setUniform(this.uNoiseSteps, Config.Client.Advanced.Graphics.NoiseTexture.noiseSteps.get());
- this.setUniform(this.uNoiseIntensity, Config.Client.Advanced.Graphics.NoiseTexture.noiseIntensity.get());
- this.setUniform(this.uNoiseDropoff, Config.Client.Advanced.Graphics.NoiseTexture.noiseDropoff.get());
-
- // Debug
- this.setUniform(this.uIsWhiteWorld, Config.Client.Advanced.Debugging.enableWhiteWorld.get());
-
- // Clip Uniform
- float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocks();
- if (!Config.Client.Advanced.Debugging.lodOnlyMode.get())
- {
- // this added value prevents the near clip plane and discard circle from touching, which looks bad
- dhNearClipDistance += 16f;
- }
- this.setUniform(this.uClipDistance, dhNearClipDistance);
- }
-
- @Override
- public void setModelOffsetPos(DhApiVec3f modelOffsetPos) { this.setUniform(this.uModelOffset, new Vec3f(modelOffsetPos)); }
-
- @Override
- public int getId() { return this.id; }
-
- /** The base DH render program should always render */
- @Override
- public boolean overrideThisFrame() { return true; }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/FogRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/FogRenderer.java
deleted file mode 100644
index f649b7a05..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/FogRenderer.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.GLState;
-import com.seibel.distanthorizons.core.render.renderer.shaders.FogApplyShader;
-import com.seibel.distanthorizons.core.render.renderer.shaders.FogShader;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import org.lwjgl.opengl.GL32;
-import org.lwjgl.opengl.GL43C;
-
-import java.nio.ByteBuffer;
-
-/**
- * Handles adding SSAO via {@link FogShader} and {@link FogApplyShader}.
- *
- * {@link FogShader} - draws the Fog to a texture.
- * {@link FogApplyShader} - draws the Fog texture to DH's FrameBuffer.
- */
-public class FogRenderer
-{
- public static FogRenderer INSTANCE = new FogRenderer();
-
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- private boolean init = false;
-
- private int width = -1;
- private int height = -1;
- private int fogFramebuffer = -1;
-
- private int fogTexture = -1;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- private FogRenderer() { }
-
- public void init()
- {
- if (this.init) return;
- this.init = true;
-
- FogShader.INSTANCE.init();
- FogApplyShader.INSTANCE.init();
- }
-
- private void createFramebuffer(int width, int height)
- {
- if (this.fogFramebuffer != -1)
- {
- GL32.glDeleteFramebuffers(this.fogFramebuffer);
- this.fogFramebuffer = -1;
- }
-
- if (this.fogTexture != -1)
- {
- GLMC.glDeleteTextures(this.fogTexture);
- this.fogTexture = -1;
- }
-
- this.fogFramebuffer = GL32.glGenFramebuffers();
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.fogFramebuffer);
-
- this.fogTexture = GLMC.glGenTextures();
- {
- GLMC.glBindTexture(this.fogTexture);
- GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, GL32.GL_RGBA16, width, height, 0, GL32.GL_RGBA, GL32.GL_UNSIGNED_SHORT_4_4_4_4, (ByteBuffer) null);
- GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MIN_FILTER, GL32.GL_LINEAR);
- GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MAG_FILTER, GL32.GL_LINEAR);
- GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.fogTexture, 0);
-
- // disable mip-mapping since DH is just going to draw straight to the screen
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_BASE_LEVEL, 0);
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_MAX_LEVEL, 0);
- }
- }
-
-
-
- //========//
- // render //
- //========//
-
- public void render(Mat4f modelViewProjectionMatrix, float partialTicks)
- {
- // GLState needed in MC 1.16.5 probably due to MC not manually setting each GL state they need before the next rendering step
- try (GLState state = new GLState())
- {
- this.init();
-
- // resize the framebuffer if necessary
- int width = MC_RENDER.getTargetFramebufferViewportWidth();
- int height = MC_RENDER.getTargetFramebufferViewportHeight();
- if (this.width != width || this.height != height)
- {
- this.width = width;
- this.height = height;
- this.createFramebuffer(width, height);
- }
-
- FogShader.INSTANCE.frameBuffer = this.fogFramebuffer;
- FogShader.INSTANCE.setProjectionMatrix(modelViewProjectionMatrix);
- FogShader.INSTANCE.render(partialTicks);
-
- FogApplyShader.INSTANCE.fogTexture = this.fogTexture;
- FogApplyShader.INSTANCE.render(partialTicks);
- }
- }
-
- public void free()
- {
- FogShader.INSTANCE.free();
- FogApplyShader.INSTANCE.free();
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericRenderObjectFactory.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/GenericRenderObjectFactory.java
similarity index 91%
rename from core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericRenderObjectFactory.java
rename to core/src/main/java/com/seibel/distanthorizons/core/render/renderer/GenericRenderObjectFactory.java
index 57d568880..3e503fbb8 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericRenderObjectFactory.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/GenericRenderObjectFactory.java
@@ -17,17 +17,14 @@
* along with this program. If not, see .
*/
-package com.seibel.distanthorizons.core.render.renderer.generic;
+package com.seibel.distanthorizons.core.render.renderer;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderObjectFactory;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderRegister;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
-import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.util.math.Vec3d;
-import com.seibel.distanthorizons.core.util.math.Vec3f;
import com.seibel.distanthorizons.core.logging.DhLogger;
import java.util.List;
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/IDebugRenderable.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/IDebugRenderable.java
index 30d45c4bc..05883941d 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/IDebugRenderable.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/IDebugRenderable.java
@@ -21,6 +21,6 @@ package com.seibel.distanthorizons.core.render.renderer;
public interface IDebugRenderable
{
- void debugRender(DebugRenderer r);
+ void debugRender(AbstractDebugWireframeRenderer r);
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java
index 7b08a6cff..44fb46f77 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java
@@ -19,43 +19,22 @@
package com.seibel.distanthorizons.core.render.renderer;
-import com.seibel.distanthorizons.api.enums.rendering.EDhApiRendererMode;
-import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiFramebuffer;
-import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShaderProgram;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
-import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
-import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam;
-import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLogger;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
import com.seibel.distanthorizons.core.render.DhApiRenderProxy;
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
-import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
-import com.seibel.distanthorizons.core.render.glObject.buffer.QuadElementBuffer;
-import com.seibel.distanthorizons.core.render.glObject.texture.*;
-import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
-import com.seibel.distanthorizons.core.render.renderer.shaders.*;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.util.math.Vec3d;
+import com.seibel.distanthorizons.core.render.RenderParams;
import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOptifineAccessor;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.*;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
-import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
-import com.seibel.distanthorizons.core.util.math.Vec3f;
-import org.jetbrains.annotations.Nullable;
-import org.lwjgl.opengl.GL32;
/**
* This is where all the magic happens.
@@ -73,46 +52,42 @@ public class LodRenderer
.build();
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
public static final LodRenderer INSTANCE = new LodRenderer();
+ private boolean vanillaSettingsOverridden = false;
+ private boolean renderersBound = false;
- // these ID's either what any render is currently using (since only one renderer can be active at a time), or just used previously
- private int activeFramebufferId = -1;
- private int activeColorTextureId = -1;
- private int activeDepthTextureId = -1;
- private int textureWidth;
- private int textureHeight;
-
-
- private IDhApiShaderProgram lodRenderProgram = null;
- public QuadElementBuffer quadIBO = null;
- private boolean renderObjectsCreated = false;
-
- // framebuffer and texture ID's for this renderer
- private IDhApiFramebuffer framebuffer;
- /** will be null if MC's framebuffer is being used since MC already has a color texture */
- @Nullable
- private DhColorTexture nullableColorTexture;
- private DHDepthTexture depthTexture;
- /**
- * If true the {@link LodRenderer#framebuffer} is the same as MC's.
- * This should only be true in the case of Optifine so LODs won't be overwritten when shaders are enabled.
- */
- private boolean usingMcFramebuffer = false;
+ private IDhMetaRenderer metaRenderer;
+ private IDhTerrainRenderer terrainRenderer;
+ private IDhSsaoRenderer ssaoRenderer;
+ private IDhFogRenderer fogRenderer;
+ private IDhFarFadeRenderer farFadeRenderer;
+ private AbstractDebugWireframeRenderer debugWireframeRenderer;
//=============//
// constructor //
//=============//
+ //region
private LodRenderer() { }
+ private void bindRenderers()
+ {
+ this.metaRenderer = SingletonInjector.INSTANCE.get(IDhMetaRenderer.class);
+ this.terrainRenderer = SingletonInjector.INSTANCE.get(IDhTerrainRenderer.class);
+ this.ssaoRenderer = SingletonInjector.INSTANCE.get(IDhSsaoRenderer.class);
+ this.fogRenderer = SingletonInjector.INSTANCE.get(IDhFogRenderer.class);
+ this.farFadeRenderer = SingletonInjector.INSTANCE.get(IDhFarFadeRenderer.class);
+ this.debugWireframeRenderer = SingletonInjector.INSTANCE.get(AbstractDebugWireframeRenderer.class);
+ }
+
+ //endregion
+
//===========//
@@ -142,6 +117,7 @@ public class LodRenderer
//====================//
// validate rendering //
//====================//
+ //region
boolean deferTransparentRendering = DhApiRenderProxy.INSTANCE.getDeferTransparentRendering();
if (runningDeferredPass
@@ -152,33 +128,37 @@ public class LodRenderer
boolean firstPass = !runningDeferredPass;
// RenderParams parameter validation should be done before this
- if (!renderParams.validationRun)
+ if (!renderParams.hasBeenValidated)
{
throw new IllegalArgumentException("Render parameters validation");
}
- RenderBufferHandler renderBufferHandler = renderParams.renderBufferHandler;
- GenericObjectRenderer genericRenderer = renderParams.genericRenderer;
- ILightMapWrapper lightmap = renderParams.lightmap;
+ //endregion
//=================//
// rendering setup //
//=================//
+ //region
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderSetupEvent.class, renderParams);
profiler.push("LOD GL setup");
- if (!this.renderObjectsCreated)
+ if (!this.renderersBound)
+ {
+ this.bindRenderers();
+ this.renderersBound = true;
+ }
+
+ RenderBufferHandler renderBufferHandler = renderParams.renderBufferHandler;
+ IDhGenericRenderer genericRenderer = renderParams.genericRenderer;
+
+
+ this.metaRenderer.runRenderPassSetup(renderParams);
+
+ if (!this.vanillaSettingsOverridden)
{
- boolean setupSuccess = this.createRenderObjects();
- if (!setupSuccess)
- {
- // shouldn't normally happen, but just in case
- return;
- }
-
// only do this once, that way they can still be reverted if desired
if (Config.Client.Advanced.Graphics.overrideVanillaGraphicsSettings.get())
{
@@ -189,27 +169,17 @@ public class LodRenderer
MC.disableFabulousTransparency();
}
- this.renderObjectsCreated = true;
+ this.vanillaSettingsOverridden = true;
}
- this.setGLState(renderParams, firstPass);
-
- lightmap.bind();
- this.quadIBO.bind();
-
if (firstPass)
{
- // we only need to sort/cull the LODs during the first frame
+ // we only need to sort/cull the LODs at the start of the frame
profiler.popPush("LOD build render list");
renderBufferHandler.buildRenderList(renderParams);
}
- IDhApiShaderProgram lodShaderProgram = this.lodRenderProgram;
- IDhApiShaderProgram lodShaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
- if (lodShaderProgramOverride != null && lodShaderProgram.overrideThisFrame())
- {
- lodShaderProgram = lodShaderProgramOverride;
- }
+ //endregion
@@ -219,6 +189,10 @@ public class LodRenderer
if (!runningDeferredPass)
{
+ this.metaRenderer.clearDhDepthAndColorTextures(renderParams);
+
+
+
//=========================//
// opaque and non-deferred //
// transparent rendering //
@@ -226,7 +200,8 @@ public class LodRenderer
// opaque LODs
profiler.popPush("LOD Opaque");
- this.renderLodPass(lodShaderProgram, renderBufferHandler, renderParams, /*opaquePass*/ true);
+
+ this.renderLodPass(this.terrainRenderer, renderBufferHandler, renderParams, /*opaquePass*/ true, profiler);
// custom objects with SSAO
if (Config.Client.Advanced.Graphics.GenericRendering.enableGenericRendering.get())
@@ -239,7 +214,7 @@ public class LodRenderer
if (Config.Client.Advanced.Graphics.Ssao.enableSsao.get())
{
profiler.popPush("LOD SSAO");
- SSAORenderer.INSTANCE.render(new Mat4f(renderParams.dhProjectionMatrix), renderParams.partialTicks);
+ this.ssaoRenderer.render(renderParams);
}
// custom objects without SSAO
@@ -254,19 +229,15 @@ public class LodRenderer
&& Config.Client.Advanced.Graphics.Quality.transparency.get().transparencyEnabled)
{
profiler.popPush("LOD Transparent");
- this.renderLodPass(lodShaderProgram, renderBufferHandler, renderParams, /*opaquePass*/ false);
+ this.renderLodPass(this.terrainRenderer, renderBufferHandler, renderParams, /*opaquePass*/ false, profiler);
}
// far plane clip fading
if (Config.Client.Advanced.Graphics.Quality.dhFadeFarClipPlane.get()
- // the fade shader messes with the GL state in a way Iris doesn't like,
- // so skip it if a shader is active
- && (IRIS_ACCESSOR == null || !IRIS_ACCESSOR.isShaderPackInUse()))
+ && IRIS_ACCESSOR == null)
{
profiler.popPush("Fade Far Clip Fade");
- DhFadeRenderer.INSTANCE.render(
- new Mat4f(renderParams.mcModelViewMatrix), new Mat4f(renderParams.mcProjectionMatrix),
- renderParams.partialTicks, profiler);
+ this.farFadeRenderer.render(renderParams);
}
// fog
@@ -275,11 +246,8 @@ public class LodRenderer
|| renderParams.vanillaFogEnabled)
{
profiler.popPush("LOD Fog");
-
- Mat4f combinedMatrix = new Mat4f(renderParams.dhProjectionMatrix);
- combinedMatrix.multiply(renderParams.dhModelViewMatrix);
-
- FogRenderer.INSTANCE.render(combinedMatrix, renderParams.partialTicks);
+
+ this.fogRenderer.render(renderParams);
}
@@ -291,25 +259,9 @@ public class LodRenderer
if (Config.Client.Advanced.Debugging.DebugWireframe.enableRendering.get())
{
profiler.popPush("Debug wireframes");
-
- Mat4f combinedMatrix = new Mat4f(renderParams.dhProjectionMatrix);
- combinedMatrix.multiply(renderParams.dhModelViewMatrix);
-
- // Note: this can be very slow if a lot of boxes are being rendered
- DebugRenderer.INSTANCE.render(combinedMatrix);
- }
-
-
-
- //===================//
- // optifine clean up //
- //===================//
-
- if (this.usingMcFramebuffer)
- {
- // If MC's framebuffer is being used the depth needs to be cleared to prevent rendering on top of MC.
- // This should only happen when Optifine shaders are being used.
- GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
+
+ // Note: this can be very slow if a lot of boxes are being rendered
+ this.debugWireframeRenderer.render(renderParams);
}
@@ -321,34 +273,30 @@ public class LodRenderer
boolean cancelApplyShader = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeApplyShaderRenderEvent.class, renderParams);
if (!cancelApplyShader)
{
- profiler.popPush("LOD Apply");
-
- // Copy the LOD framebuffer to Minecraft's framebuffer
- DhApplyShader.INSTANCE.render(renderParams.partialTicks);
+ profiler.popPush("Apply to MC");
+ this.metaRenderer.applyToMcTexture(renderParams);
}
+
}
else
{
//====================//
// deferred rendering //
//====================//
-
+
if (Config.Client.Advanced.Graphics.Quality.transparency.get().transparencyEnabled)
{
profiler.popPush("LOD Transparent");
- this.renderLodPass(lodShaderProgram, renderBufferHandler, renderParams, /*opaquePass*/ false);
-
-
+ this.renderLodPass(this.terrainRenderer, renderBufferHandler, renderParams, /*opaquePass*/ false, profiler);
+
+
if (Config.Client.Advanced.Graphics.Fog.enableDhFog.get()
// this is done to fix issues with: underwater fog, blindness effect, etc.
|| renderParams.vanillaFogEnabled)
{
profiler.popPush("LOD Fog");
-
- Mat4f combinedMatrix = new Mat4f(renderParams.dhProjectionMatrix);
- combinedMatrix.multiply(renderParams.dhModelViewMatrix);
-
- FogRenderer.INSTANCE.render(combinedMatrix, renderParams.partialTicks);
+
+ this.fogRenderer.render(renderParams);
}
}
}
@@ -362,9 +310,8 @@ public class LodRenderer
profiler.popPush("LOD cleanup");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderCleanupEvent.class, renderParams);
- lightmap.unbind();
- this.quadIBO.unbind();
- lodShaderProgram.unbind();
+ this.metaRenderer.runRenderPassCleanup(renderParams);
+
// end of internal LOD profiling
@@ -375,385 +322,26 @@ public class LodRenderer
- //=================//
- // Setup Functions //
- //=================//
- //region
-
- private void setGLState(
- DhApiRenderParam renderEventParam,
- boolean firstPass)
- {
- //===================//
- // framebuffer setup //
- //===================//
-
- // get the active framebuffer
- IDhApiFramebuffer framebuffer = this.framebuffer;
- IDhApiFramebuffer framebufferOverride = OverrideInjector.INSTANCE.get(IDhApiFramebuffer.class);
- if (framebufferOverride != null && framebufferOverride.overrideThisFrame())
- {
- framebuffer = framebufferOverride;
- }
- this.activeFramebufferId = framebuffer.getId();
- framebuffer.bind();
-
-
-
- //==========//
- // bindings //
- //==========//
-
- // by default draw everything as triangles
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
- GLMC.enableFaceCulling();
-
- GLMC.glBlendFunc(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA);
- GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ZERO);
-
- GL32.glDisable(GL32.GL_SCISSOR_TEST);
-
- // Enable depth test and depth mask
- GLMC.enableDepthTest();
- GLMC.glDepthFunc(GL32.GL_LESS);
- GLMC.enableDepthMask();
-
- // This is required for MC versions 1.21.5+
- // due to MC updating the lightmap by changing the viewport size
- GL32.glViewport(0, 0, this.textureWidth, this.textureHeight);
-
- this.lodRenderProgram.bind();
-
-
-
- //==========//
- // uniforms //
- //==========//
-
- IDhApiShaderProgram shaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
- if (shaderProgramOverride != null)
- {
- shaderProgramOverride.fillUniformData(renderEventParam);
- }
-
- this.lodRenderProgram.fillUniformData(renderEventParam);
-
-
-
-
- //===============//
- // texture setup //
- //===============//
-
- // resize the textures if needed
- if (MC_RENDER.getTargetFramebufferViewportWidth() != this.textureWidth
- || MC_RENDER.getTargetFramebufferViewportHeight() != this.textureHeight)
- {
- // just resizing the textures doesn't work when Optifine is present,
- // so recreate the textures with the new size instead
- this.createAndBindTextures();
- }
-
-
- // set the active textures
- this.activeDepthTextureId = this.depthTexture.getTextureId();
-
- if (this.nullableColorTexture != null)
- {
- this.activeColorTextureId = this.nullableColorTexture.getTextureId();
- }
- else
- {
- // get MC's color texture
- this.activeColorTextureId = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
- }
-
-
- // needs to be fired after all the textures have been created/bound
- boolean clearTextures = !ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeTextureClearEvent.class, renderEventParam);
- if (clearTextures)
- {
- GL32.glClearDepth(1.0);
-
- float[] clearColorValues = new float[4];
- GL32.glGetFloatv(GL32.GL_COLOR_CLEAR_VALUE, clearColorValues);
- GL32.glClearColor(clearColorValues[0], clearColorValues[1], clearColorValues[2], 1.0f);
-
- if (this.usingMcFramebuffer && framebufferOverride == null)
- {
- // Due to using MC/Optifine's framebuffer we need to re-bind the depth texture,
- // otherwise we'll be writing to MC/Optifine's depth texture which causes rendering issues
- framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
-
-
- // don't clear the color texture, that removes the sky
- GL32.glClear(GL32.GL_DEPTH_BUFFER_BIT);
- }
- else if (firstPass)
- {
- GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
- }
- }
-
-
- }
-
- private boolean createRenderObjects()
- {
- if (this.renderObjectsCreated)
- {
- LOGGER.warn("Renderer setup called but it has already completed setup!");
- return false;
- }
-
- // GLProxy should have already been created by this point, but just in case create it now
- GLProxy.getInstance();
-
-
-
- LOGGER.info("Setting up renderer");
- this.lodRenderProgram = new DhTerrainShaderProgram();
-
- this.quadIBO = new QuadElementBuffer();
- this.quadIBO.reserve(LodBufferContainer.MAX_QUADS_PER_BUFFER);
-
-
- // create or get the frame buffer
- if (AbstractOptifineAccessor.optifinePresent())
- {
- // use MC/Optifine's default Framebuffer so shaders won't remove the LODs
- int currentFramebufferId = MC_RENDER.getTargetFramebuffer();
- this.framebuffer = new DhFramebuffer(currentFramebufferId);
- this.usingMcFramebuffer = true;
- }
- else
- {
- // normal use case
- this.framebuffer = new DhFramebuffer();
- this.usingMcFramebuffer = false;
- }
-
- // create and bind the necessary textures
- this.createAndBindTextures();
-
- if(this.framebuffer.getStatus() != GL32.GL_FRAMEBUFFER_COMPLETE)
- {
- // This generally means something wasn't bound, IE missing either the color or depth texture
- LOGGER.warn("Framebuffer ["+this.framebuffer.getId()+"] isn't complete.");
- return false;
- }
-
-
-
- LOGGER.info("Renderer setup complete");
- return true;
- }
-
- @SuppressWarnings( "deprecation" ) // done to ignore DhApiColorDepthTextureCreatedEvent
- private void createAndBindTextures()
- {
- int oldWidth = this.textureWidth;
- int oldHeight = this.textureHeight;
- this.textureWidth = MC_RENDER.getTargetFramebufferViewportWidth();
- this.textureHeight = MC_RENDER.getTargetFramebufferViewportHeight();
-
- DhApiTextureCreatedParam textureCreatedParam = new DhApiTextureCreatedParam(
- oldWidth, oldHeight,
- this.textureWidth, this.textureHeight
- );
-
-
- // DhApiColorDepthTextureCreatedEvent needs to be kept around since old versions of Iris need it
- ApiEventInjector.INSTANCE.fireAllEvents(DhApiColorDepthTextureCreatedEvent.class, new DhApiColorDepthTextureCreatedEvent.EventParam(textureCreatedParam));
- ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeColorDepthTextureCreatedEvent.class, textureCreatedParam);
-
-
- // also update the framebuffer override if present
- IDhApiFramebuffer framebufferOverride = OverrideInjector.INSTANCE.get(IDhApiFramebuffer.class);
-
-
- this.depthTexture = new DHDepthTexture(this.textureWidth, this.textureHeight, EDhDepthBufferFormat.DEPTH32F);
- this.framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
- if (framebufferOverride != null)
- {
- framebufferOverride.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F.isCombinedStencil());
- }
-
- // if we are using MC's frame buffer, a color texture is already present and shouldn't need to be bound
- if (!this.usingMcFramebuffer)
- {
- this.nullableColorTexture = DhColorTexture.builder().setDimensions(this.textureWidth, this.textureHeight)
- .setInternalFormat(EDhInternalTextureFormat.RGBA8)
- .setPixelType(EDhPixelType.UNSIGNED_BYTE)
- .setPixelFormat(EDhPixelFormat.RGBA)
- .build();
-
- this.framebuffer.addColorAttachment(0, this.nullableColorTexture.getTextureId());
- if (framebufferOverride != null)
- {
- framebufferOverride.addColorAttachment(0, this.nullableColorTexture.getTextureId());
- }
- }
- else
- {
- this.nullableColorTexture = null;
- }
-
-
- ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterColorDepthTextureCreatedEvent.class, textureCreatedParam);
- }
-
- //endregion
-
-
-
//===============//
// LOD rendering //
//===============//
//region
- private void renderLodPass(IDhApiShaderProgram shaderProgram, RenderBufferHandler lodBufferHandler, RenderParams renderEventParam, boolean opaquePass)
+ private void renderLodPass(IDhTerrainRenderer lodRenderer, RenderBufferHandler lodBufferHandler, RenderParams renderEventParam, boolean opaquePass, IProfilerWrapper profilerWrapper)
{
- //=======================//
- // debug wireframe setup //
- //=======================//
-
- boolean renderWireframe = Config.Client.Advanced.Debugging.renderWireframe.get();
- if (renderWireframe)
- {
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_LINE);
- GLMC.disableFaceCulling();
- }
- else
- {
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
- GLMC.enableFaceCulling();
- }
-
- if (!opaquePass)
- {
- GLMC.enableBlend();
- GLMC.enableDepthTest();
- GL32.glBlendEquation(GL32.GL_FUNC_ADD);
- GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
- }
- else
- {
- GLMC.disableBlend();
- }
-
-
-
-
//===========//
// rendering //
//===========//
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
- if (IRIS_ACCESSOR != null)
+ SortedArraySet lodBufferContainer = lodBufferHandler.getColumnRenderBuffers();
+ if (lodBufferContainer != null)
{
- // done to fix a bug with Iris where face culling isn't properly set or reverted in the MC state manager
- // which causes Sodium to render some water chunks with their normal inverted
- // https://github.com/IrisShaders/Iris/issues/2582
- // https://github.com/IrisShaders/Iris/blob/1.21.9/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java#L346
- GLMC.enableFaceCulling();
+ lodRenderer.render(renderEventParam, opaquePass, lodBufferContainer, profilerWrapper);
}
-
- if (Config.Client.Advanced.Debugging.rendererMode.get() == EDhApiRendererMode.DEFAULT)
- {
- // Normal LOD rendering
-
- SortedArraySet lodBufferContainer = lodBufferHandler.getColumnRenderBuffers();
- if (lodBufferContainer != null)
- {
- for (int lodIndex = 0; lodIndex < lodBufferContainer.size(); lodIndex++)
- {
- LodBufferContainer bufferContainer = lodBufferContainer.get(lodIndex);
- this.setShaderProgramMvmOffset(bufferContainer.minCornerBlockPos, shaderProgram, renderEventParam);
-
- GLVertexBuffer[] vbos = opaquePass ? bufferContainer.vbos : bufferContainer.vbosTransparent;
- for (int vboIndex = 0; vboIndex < vbos.length; vboIndex++)
- {
- GLVertexBuffer vbo = vbos[vboIndex];
- if (vbo == null)
- {
- continue;
- }
-
- if (vbo.getVertexCount() == 0)
- {
- continue;
- }
-
- vbo.bind();
- shaderProgram.bindVertexBuffer(vbo.getId());
- GL32.glDrawElements(
- GL32.GL_TRIANGLES,
- vbo.getVertexCount(),
- this.quadIBO.getType(), 0);
- vbo.unbind();
- }
- }
- }
- }
- else
- {
- // basic quad rendering
-
- TestRenderer.INSTANCE.render();
- }
-
-
- //=========================//
- // debug wireframe cleanup //
- //=========================//
-
- if (renderWireframe)
- {
- // default back to GL_FILL since all other rendering uses it
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
- GLMC.enableFaceCulling();
- }
-
}
- /**
- * the MVM offset is needed so LODs can be rendered anywhere in the MC world
- * without running into floating point percision loss.
- */
- private void setShaderProgramMvmOffset(DhBlockPos pos, IDhApiShaderProgram shaderProgram, RenderParams renderEventParam) throws IllegalStateException
- {
- Vec3d camPos = renderEventParam.exactCameraPosition;
- Vec3f modelPos = new Vec3f(
- (float) (pos.getX() - camPos.x),
- (float) (pos.getY() - camPos.y),
- (float) (pos.getZ() - camPos.z));
-
- shaderProgram.bind();
- shaderProgram.setModelOffsetPos(modelPos);
-
- ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
- }
-
- //endregion
-
-
-
- //===============//
- // API functions //
- //===============//
- //region
-
- /** @return -1 if no frame buffer has been bound yet */
- public int getActiveFramebufferId() { return this.activeFramebufferId; }
-
- /** @return -1 if no texture has been bound yet */
- public int getActiveColorTextureId() { return this.activeColorTextureId; }
-
- /** @return -1 if no texture has been bound yet */
- public int getActiveDepthTextureId() { return this.activeDepthTextureId; }
-
//endregion
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/RenderableBoxGroup.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/RenderableBoxGroup.java
similarity index 83%
rename from core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/RenderableBoxGroup.java
rename to core/src/main/java/com/seibel/distanthorizons/core/render/renderer/RenderableBoxGroup.java
index 56f7a0d17..d935949cc 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/RenderableBoxGroup.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/RenderableBoxGroup.java
@@ -1,4 +1,4 @@
-package com.seibel.distanthorizons.core.render.renderer.generic;
+package com.seibel.distanthorizons.core.render.renderer;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
@@ -8,15 +8,15 @@ import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShad
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLogger;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
+import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.threading.PriorityTaskPicker;
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
+import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
import org.jetbrains.annotations.Nullable;
-import java.awt.*;
import java.io.Closeable;
import java.util.*;
import java.util.List;
@@ -33,8 +33,8 @@ public class RenderableBoxGroup
{
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
+ private static final IWrapperFactory WRAPPER_FACTORY = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
public static final AtomicInteger NEXT_ID_ATOMIC_INT = new AtomicInteger(0);
@@ -67,9 +67,9 @@ public class RenderableBoxGroup
public Consumer afterRenderFunc;
// instance data
- public InstancedVboContainer instancedVbos = new InstancedVboContainer();
+ public IDhGenericObjectVertexBufferContainer vertexBufferContainer = WRAPPER_FACTORY.createGenericObjectVboContainer();
/** double buffering for thread safety and to prevent locking the render thread during update */
- private InstancedVboContainer altInstancedVbos = new InstancedVboContainer();
+ private IDhGenericObjectVertexBufferContainer altVertexBufferContainer = WRAPPER_FACTORY.createGenericObjectVboContainer();
@@ -195,14 +195,14 @@ public class RenderableBoxGroup
public void tryUpdateInstancedDataAsync()
{
// if the alt container is done, swap it in
- if (this.altInstancedVbos.state == InstancedVboContainer.EState.READY_TO_UPLOAD)
+ if (this.altVertexBufferContainer.getState() == IDhGenericObjectVertexBufferContainer.EState.READY_TO_UPLOAD)
{
- this.altInstancedVbos.uploadDataToGpu();
+ this.altVertexBufferContainer.uploadDataToGpu();
// swap VBO references for rendering
- InstancedVboContainer temp = this.instancedVbos;
- this.instancedVbos = this.altInstancedVbos;
- this.altInstancedVbos = temp;
+ IDhGenericObjectVertexBufferContainer temp = this.vertexBufferContainer;
+ this.vertexBufferContainer = this.altVertexBufferContainer;
+ this.altVertexBufferContainer = temp;
this.vertexDataDirty = false;
@@ -224,15 +224,15 @@ public class RenderableBoxGroup
}
// if the alternate container is already updating, don't double-queue it
- if (this.altInstancedVbos.state == InstancedVboContainer.EState.UPDATING_DATA)
+ if (this.altVertexBufferContainer.getState() == IDhGenericObjectVertexBufferContainer.EState.UPDATING_DATA)
{
return;
}
- this.altInstancedVbos.state = InstancedVboContainer.EState.UPDATING_DATA;
+ this.altVertexBufferContainer.setState(IDhGenericObjectVertexBufferContainer.EState.UPDATING_DATA);
- this.altInstancedVbos.tryRunRenderThreadSetup();
+ //this.altInstancedVbos.tryRunRenderThreadSetup();
// copy over the box list so we can upload without concurrent modification issues
this.uploadBoxList.clear();
@@ -247,19 +247,19 @@ public class RenderableBoxGroup
{
try
{
- this.altInstancedVbos.updateVertexData(this.uploadBoxList);
+ this.altVertexBufferContainer.updateVertexData(this.uploadBoxList);
}
catch (Exception e)
{
LOGGER.error("Unexpected error updating instanced VBO data for: ["+this+"], error: ["+e.getMessage()+"].", e);
- this.altInstancedVbos.state = InstancedVboContainer.EState.ERROR;
+ this.altVertexBufferContainer.setState(IDhGenericObjectVertexBufferContainer.EState.ERROR);
}
});
}
catch (RejectedExecutionException ignore)
{
// the executor was shut down, it should be back up shortly and able to accept new jobs
- this.altInstancedVbos.state = InstancedVboContainer.EState.NEW;
+ this.altVertexBufferContainer.setState(IDhGenericObjectVertexBufferContainer.EState.NEW);
}
}
@@ -341,15 +341,15 @@ public class RenderableBoxGroup
//region
@Override
- public String toString() { return "["+this.resourceLocationNamespace+":"+this.resourceLocationPath+"] ID:["+this.id+"], pos:["+this.originBlockPos.x+","+this.originBlockPos.y+","+this.originBlockPos.z+"], size:["+this.size()+"], active:["+this.active+"]"; }
+ public String toString() { return "["+this.resourceLocationNamespace+":"+this.resourceLocationPath+"] ID:["+this.id+"], pos:[("+this.originBlockPos.x+", "+this.originBlockPos.y+", "+this.originBlockPos.z+")], size:["+this.size()+"], active:["+this.active+"]"; }
@Override
public void close()
{
- GLProxy.queueRunningOnRenderThread(() ->
+ RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread(() ->
{
- this.instancedVbos.close();
- this.altInstancedVbos.close();
+ this.vertexBufferContainer.close();
+ this.altVertexBufferContainer.close();
});
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/SSAORenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/SSAORenderer.java
deleted file mode 100644
index a74dabde3..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/SSAORenderer.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.GLState;
-import com.seibel.distanthorizons.core.render.renderer.shaders.SSAOApplyShader;
-import com.seibel.distanthorizons.core.render.renderer.shaders.SSAOShader;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import org.lwjgl.opengl.GL32;
-import org.lwjgl.opengl.GL43C;
-
-import java.nio.ByteBuffer;
-
-/**
- * Handles adding SSAO via {@link SSAOShader} and {@link SSAOApplyShader}.
- *
- * {@link SSAOShader} - draws the SSAO to a texture.
- * {@link SSAOApplyShader} - draws the SSAO texture to DH's FrameBuffer.
- */
-public class SSAORenderer
-{
- public static SSAORenderer INSTANCE = new SSAORenderer();
-
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- private boolean init = false;
-
- private int width = -1;
- private int height = -1;
- private int ssaoFramebuffer = -1;
-
- private int ssaoTexture = -1;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- private SSAORenderer() { }
-
- public void init()
- {
- if (this.init) return;
- this.init = true;
-
- SSAOShader.INSTANCE.init();
- SSAOApplyShader.INSTANCE.init();
- }
-
- private void createFramebuffer(int width, int height)
- {
- if (this.ssaoFramebuffer != -1)
- {
- GL32.glDeleteFramebuffers(this.ssaoFramebuffer);
- this.ssaoFramebuffer = -1;
- }
-
- if (this.ssaoTexture != -1)
- {
- GLMC.glDeleteTextures(this.ssaoTexture);
- this.ssaoTexture = -1;
- }
-
- this.ssaoFramebuffer = GL32.glGenFramebuffers();
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.ssaoFramebuffer);
-
- this.ssaoTexture = GLMC.glGenTextures();
- {
- GLMC.glBindTexture(this.ssaoTexture);
- GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, GL32.GL_R16F, width, height, 0, GL32.GL_RED, GL32.GL_HALF_FLOAT, (ByteBuffer) null);
- GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MIN_FILTER, GL32.GL_LINEAR);
- GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MAG_FILTER, GL32.GL_LINEAR);
-
- // disable mip-mapping since DH is just going to draw straight to the screen
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_BASE_LEVEL, 0);
- GL43C.glTexParameteri(GL43C.GL_TEXTURE_2D, GL43C.GL_TEXTURE_MAX_LEVEL, 0);
- }
-
- GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.ssaoTexture, 0);
- }
-
-
-
- //========//
- // render //
- //========//
-
- public void render(Mat4f projectionMatrix, float partialTicks)
- {
- try(GLState state = new GLState())
- {
- this.init();
-
- // resize the framebuffer if necessary
- int width = MC_RENDER.getTargetFramebufferViewportWidth();
- int height = MC_RENDER.getTargetFramebufferViewportHeight();
- if (this.width != width || this.height != height)
- {
- this.width = width;
- this.height = height;
- this.createFramebuffer(width, height);
- }
-
- SSAOShader.INSTANCE.frameBuffer = this.ssaoFramebuffer;
- SSAOShader.INSTANCE.setProjectionMatrix(projectionMatrix);
- SSAOShader.INSTANCE.render(partialTicks);
-
- SSAOApplyShader.INSTANCE.ssaoTexture = this.ssaoTexture;
- SSAOApplyShader.INSTANCE.render(partialTicks);
- }
- }
-
- public void free()
- {
- SSAOShader.INSTANCE.free();
- SSAOApplyShader.INSTANCE.free();
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/ScreenQuad.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/ScreenQuad.java
deleted file mode 100644
index 497e4b0de..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/ScreenQuad.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer;
-
-import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
-import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
-import org.lwjgl.opengl.GL32;
-import org.lwjgl.system.MemoryUtil;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * Renders a full-screen textured quad to the screen.
- * Used in composite / deferred rendering (IE fog).
- */
-public class ScreenQuad
-{
- public static ScreenQuad INSTANCE = new ScreenQuad();
-
- private static final float[] box_vertices = {
- -1, -1,
- 1, -1,
- 1, 1,
- -1, -1,
- 1, 1,
- -1, 1,
- };
-
- private GLVertexBuffer boxBuffer;
- private AbstractVertexAttribute va;
- private boolean init = false;
-
-
- //=============//
- // constructor //
- //=============//
-
- private ScreenQuad() { }
-
- public void init()
- {
- if (this.init) return;
- this.init = true;
-
- this.va = AbstractVertexAttribute.create();
- this.va.bind();
-
- // Pos
- this.va.setVertexAttribute(0, 0, VertexPointer.addVec2Pointer(false));
- this.va.completeAndCheck(Float.BYTES * 2);
-
- // Framebuffer
- this.createBuffer();
- }
-
- public void render()
- {
- this.init();
-
- this.boxBuffer.bind();
-
- this.va.bind();
- this.va.bindBufferToAllBindingPoints(this.boxBuffer.getId());
-
- GL32.glDrawArrays(GL32.GL_TRIANGLES, 0, 6);
- }
-
- private void createBuffer()
- {
- ByteBuffer buffer = MemoryUtil.memAlloc(box_vertices.length * Float.BYTES);
- buffer.asFloatBuffer().put(box_vertices);
- buffer.rewind();
-
- this.boxBuffer = new GLVertexBuffer(false);
- this.boxBuffer.bind();
- this.boxBuffer.uploadBuffer(buffer, box_vertices.length, EDhApiGpuUploadMethod.DATA, box_vertices.length * Float.BYTES);
- MemoryUtil.memFree(buffer);
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/TestRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/TestRenderer.java
deleted file mode 100644
index 0b55d611e..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/TestRenderer.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer;
-
-import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-
-import org.lwjgl.opengl.GL32;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * Renders a UV colored quad
- * to the center of the screen to confirm DH's
- * apply shader is running correctly
- */
-public class TestRenderer
-{
- public static final DhLogger LOGGER = new DhLoggerBuilder().build();
-
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
- public static final TestRenderer INSTANCE = new TestRenderer();
-
- // Render a square with uv color
- private static final float[] VERTICES = {
- // PosX,Y, ColorR,G,B,A
- -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
- 0.4f, -0.4f, 1.0f, 0.0f, 0.0f, 1.0f,
- 0.3f, 0.3f, 1.0f, 1.0f, 0.0f, 0.0f,
- -0.2f, 0.2f, 0.0f, 1.0f, 1.0f, 1.0f
- };
-
-
-
- ShaderProgram basicShader;
- GLVertexBuffer vbo;
- AbstractVertexAttribute va;
- boolean init = false;
-
-
-
- //=============//
- // constructor //
- //=============//
- //region
-
- private TestRenderer() { }
-
- public void init()
- {
- if (this.init)
- {
- return;
- }
-
- LOGGER.info("init");
- this.init = true;
- this.va = AbstractVertexAttribute.create();
- this.va.bind();
- // Pos
- this.va.setVertexAttribute(0, 0, VertexPointer.addVec2Pointer(false));
- // Color
- this.va.setVertexAttribute(0, 1, VertexPointer.addVec4Pointer(false));
- this.va.completeAndCheck(Float.BYTES * 6);
- this.basicShader = new ShaderProgram(
- "shaders/test/vert.vert",
- "shaders/test/frag.frag",
- new String[]{"vPosition", "color"});
-
- this.createBuffer();
- }
-
- private void createBuffer()
- {
- ByteBuffer buffer = ByteBuffer.allocateDirect(VERTICES.length * Float.BYTES);
- // Fill buffer with vertices.
- buffer.order(ByteOrder.nativeOrder());
- buffer.asFloatBuffer().put(VERTICES);
- buffer.rewind();
-
- this.vbo = new GLVertexBuffer(false);
- this.vbo.bind();
- this.vbo.uploadBuffer(buffer, 4, EDhApiGpuUploadMethod.DATA, VERTICES.length * Float.BYTES);
- }
-
- //endregion
-
-
-
- //========//
- // render //
- //========//
- //region
-
- public void render()
- {
- this.init();
-
- this.basicShader.bind();
- this.va.bind();
-
- this.vbo.bind();
- this.va.bindBufferToAllBindingPoints(this.vbo.getId());
-
- // Render the square
- GL32.glDrawArrays(GL32.GL_TRIANGLE_FAN, 0, 4);
- }
-
- //endregion
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/VanillaFadeRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/VanillaFadeRenderer.java
deleted file mode 100644
index f1c1d5a5a..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/VanillaFadeRenderer.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.glObject.GLState;
-import com.seibel.distanthorizons.core.render.renderer.shaders.DhFadeShader;
-import com.seibel.distanthorizons.core.render.renderer.shaders.FadeApplyShader;
-import com.seibel.distanthorizons.core.render.renderer.shaders.VanillaFadeShader;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import org.lwjgl.opengl.GL32;
-
-import java.nio.ByteBuffer;
-
-/**
- * Handles fading MC and DH together via {@link VanillaFadeShader} and {@link FadeApplyShader}.
- *
- * {@link VanillaFadeShader} - draws the Fade to a texture.
- * {@link FadeApplyShader} - draws the Fade texture to MC's FrameBuffer.
- */
-public class VanillaFadeRenderer
-{
- public static VanillaFadeRenderer INSTANCE = new VanillaFadeRenderer();
-
- private static final DhLogger LOGGER = new DhLoggerBuilder().build();
-
- private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- private boolean init = false;
-
- private int width = -1;
- private int height = -1;
- private int fadeFramebuffer = -1;
-
- private int fadeTexture = -1;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- private VanillaFadeRenderer() { }
-
- public void init()
- {
- if (this.init) return;
- this.init = true;
-
- VanillaFadeShader.INSTANCE.init();
- FadeApplyShader.INSTANCE.init();
- }
-
- private void createFramebuffer(int width, int height)
- {
- if (this.fadeFramebuffer != -1)
- {
- GL32.glDeleteFramebuffers(this.fadeFramebuffer);
- this.fadeFramebuffer = -1;
- }
-
- this.fadeFramebuffer = GL32.glGenFramebuffers();
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.fadeFramebuffer);
-
-
- // Applying the fade texture is only needed if MC is drawing to their own frame buffer,
- // otherwise we can directly render to their texture
- if (MC_RENDER.mcRendersToFrameBuffer())
- {
- if (this.fadeTexture != -1)
- {
- GLMC.glDeleteTextures(this.fadeTexture);
- this.fadeTexture = -1;
- }
-
- this.fadeTexture = GL32.glGenTextures();
- GLMC.glBindTexture(this.fadeTexture);
- GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, GL32.GL_RGBA16, width, height, 0, GL32.GL_RGBA, GL32.GL_UNSIGNED_SHORT_4_4_4_4, (ByteBuffer) null);
- GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MIN_FILTER, GL32.GL_LINEAR);
- GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MAG_FILTER, GL32.GL_LINEAR);
- GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.fadeTexture, 0);
- }
- else
- {
- GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, MC_RENDER.getColorTextureId(), 0);
- }
- }
-
-
-
- //========//
- // render //
- //========//
-
- public void render(Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix, float partialTicks, IClientLevelWrapper level)
- {
- int depthTextureId = LodRenderer.INSTANCE.getActiveDepthTextureId();
- if (depthTextureId == -1)
- {
- // the renderer hasn't been set up yet
- // trying to render fading may cause GL errors
- return;
- }
-
-
-
- IProfilerWrapper profiler = MC_CLIENT.getProfiler();
- profiler.pop(); // get out of "terrain"
- profiler.push("DH-Vanilla Fade");
-
-
- try(GLState mcState = new GLState())
- {
- profiler.push("Vanilla Fade Generate");
-
- this.init();
-
- // resize the framebuffer if necessary
- int width = MC_RENDER.getTargetFramebufferViewportWidth();
- int height = MC_RENDER.getTargetFramebufferViewportHeight();
- if (this.width != width || this.height != height)
- {
- this.width = width;
- this.height = height;
- this.createFramebuffer(width, height);
- }
-
-
- VanillaFadeShader.INSTANCE.frameBuffer = this.fadeFramebuffer;
- VanillaFadeShader.INSTANCE.setProjectionMatrix(mcModelViewMatrix, mcProjectionMatrix);
- VanillaFadeShader.INSTANCE.setLevelMaxHeight(level.getMaxHeight());
- VanillaFadeShader.INSTANCE.render(partialTicks);
-
- // Applying the fade texture is only needed if MC is drawing to their own frame buffer,
- // otherwise we can directly render to their texture
- if (MC_RENDER.mcRendersToFrameBuffer())
- {
- profiler.popPush("Vanilla Fade Apply");
-
- FadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
- FadeApplyShader.INSTANCE.readFramebuffer = DhFadeShader.INSTANCE.frameBuffer;
- FadeApplyShader.INSTANCE.drawFramebuffer = MC_RENDER.getTargetFramebuffer();
- FadeApplyShader.INSTANCE.render(partialTicks);
- }
-
- profiler.pop();
- }
- catch (Exception e)
- {
- LOGGER.error("Unexpected error during fade render, error: ["+e.getMessage()+"].", e);
- }
- }
-
- public void free()
- {
- VanillaFadeShader.INSTANCE.free();
- FadeApplyShader.INSTANCE.free();
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/DhFrustumBounds.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/cullingFrustum/DhFrustumBounds.java
similarity index 96%
rename from core/src/main/java/com/seibel/distanthorizons/core/render/DhFrustumBounds.java
rename to core/src/main/java/com/seibel/distanthorizons/core/render/renderer/cullingFrustum/DhFrustumBounds.java
index a4ca46ca2..5fe059b34 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/DhFrustumBounds.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/cullingFrustum/DhFrustumBounds.java
@@ -1,4 +1,4 @@
-package com.seibel.distanthorizons.core.render;
+package com.seibel.distanthorizons.core.render.renderer.cullingFrustum;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiCullingFrustum;
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/NeverCullFrustum.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/cullingFrustum/NeverCullFrustum.java
similarity index 91%
rename from core/src/main/java/com/seibel/distanthorizons/core/render/NeverCullFrustum.java
rename to core/src/main/java/com/seibel/distanthorizons/core/render/renderer/cullingFrustum/NeverCullFrustum.java
index 611aa0ad6..e6ca60d54 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/NeverCullFrustum.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/cullingFrustum/NeverCullFrustum.java
@@ -1,10 +1,9 @@
-package com.seibel.distanthorizons.core.render;
+package com.seibel.distanthorizons.core.render.renderer.cullingFrustum;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiCullingFrustum;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShadowCullingFrustum;
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IOverrideInjector;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
/**
* Dummy {@link IDhApiCullingFrustum} that allows everything through.
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java
deleted file mode 100644
index d93c2be8f..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectRenderer.java
+++ /dev/null
@@ -1,731 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.generic;
-
-import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
-import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
-import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiGenericObjectShaderProgram;
-import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
-import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderRegister;
-import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
-import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
-import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
-import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
-import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.jar.EPlatform;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.logging.f3.F3Screen;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
-import com.seibel.distanthorizons.core.render.glObject.buffer.GLElementBuffer;
-import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
-import com.seibel.distanthorizons.core.util.LodUtil;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
-import com.seibel.distanthorizons.core.util.math.Vec3d;
-import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
-import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
-import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
-import com.seibel.distanthorizons.coreapi.ModInfo;
-import org.lwjgl.opengl.ARBInstancedArrays;
-import org.lwjgl.opengl.GL32;
-import org.lwjgl.opengl.GL33;
-import org.lwjgl.system.MemoryUtil;
-
-import java.awt.*;
-import java.nio.ByteBuffer;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Handles rendering generic groups of {@link DhApiRenderableBox}.
- *
- * @see IDhApiCustomRenderRegister
- * @see DhApiRenderableBox
- */
-public class GenericObjectRenderer implements IDhApiCustomRenderRegister
-{
- private static final DhLogger LOGGER = new DhLoggerBuilder().build();
-
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final ISodiumAccessor SODIUM = ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
- private static final DhApiRenderableBoxGroupShading DEFAULT_SHADING = DhApiRenderableBoxGroupShading.getUnshaded();
-
- /**
- * Can be used to troubleshoot the renderer.
- * If enabled several debug objects will render around (0,150,0).
- */
- public static final boolean RENDER_DEBUG_OBJECTS = false;
-
-
- // rendering setup
- private boolean init = false;
-
- private IDhApiGenericObjectShaderProgram instancedShaderProgram;
- private IDhApiGenericObjectShaderProgram directShaderProgram;
- private GLVertexBuffer boxVertexBuffer;
- private GLElementBuffer boxIndexBuffer;
-
- private boolean instancedRenderingAvailable;
- private boolean vertexAttribDivisorSupported;
- private boolean instancedArraysSupported;
-
-
-
- private final ConcurrentHashMap boxGroupById = new ConcurrentHashMap<>();
-
-
-
- /** A box from 0,0,0 to 1,1,1 */
- private static final float[] BOX_VERTICES = {
- //region
- // Pos x y z
-
- // min X, vertical face
- 0, 0, 0,
- 1, 0, 0,
- 1, 1, 0,
- 0, 1, 0,
- // max X, vertical face
- 0, 1, 1,
- 1, 1, 1,
- 1, 0, 1,
- 0, 0, 1,
-
- // min Z, vertical face
- 0, 0, 1,
- 0, 0, 0,
- 0, 1, 0,
- 0, 1, 1,
- // max Z, vertical face
- 1, 0, 1,
- 1, 1, 1,
- 1, 1, 0,
- 1, 0, 0,
-
- // min Y, horizontal face
- 0, 0, 1,
- 1, 0, 1,
- 1, 0, 0,
- 0, 0, 0,
- // max Y, horizontal face
- 0, 1, 1,
- 1, 1, 1,
- 1, 1, 0,
- 0, 1, 0,
- //endregion
- };
-
-
- private static final int[] BOX_INDICES = {
- //region
- // min X, vertical face
- 2, 1, 0,
- 0, 3, 2,
- // max X, vertical face
- 6, 5, 4,
- 4, 7, 6,
-
- // min Z, vertical face
- 10, 9, 8,
- 8, 11, 10,
- // max Z, vertical face
- 14, 13, 12,
- 12, 15, 14,
-
- // min Y, horizontal face
- 18, 17, 16,
- 16, 19, 18,
- // max Y, horizontal face
- 20, 21, 22,
- 22, 23, 20,
- //endregion
- };
-
-
-
- //=============//
- // constructor //
- //=============//
- //region
-
- public GenericObjectRenderer() { }
-
- public void init()
- {
- if (this.init)
- {
- return;
- }
- this.init = true;
-
-
-
- //===================================//
- // is instanced rendering available? //
- //===================================//
-
- this.vertexAttribDivisorSupported = GLProxy.getInstance().vertexAttribDivisorSupported;
- this.instancedArraysSupported = GLProxy.getInstance().instancedArraysSupported;
- boolean isMac = (EPlatform.get() == EPlatform.MACOS);
- this.instancedRenderingAvailable = (this.vertexAttribDivisorSupported || this.instancedArraysSupported) && !isMac;
- if (!this.instancedRenderingAvailable)
- {
- LOGGER.warn("Instanced rendering not supported by this GPU, falling back to direct rendering. Generic object rendering will be slow and some effects may be disabled.");
- }
-
-
-
- //======================//
- // startup the renderer //
- //======================//
-
- this.instancedShaderProgram = new GenericObjectShaderProgram(true);
- this.directShaderProgram = new GenericObjectShaderProgram(false);
-
- this.createBuffers();
-
- if (RENDER_DEBUG_OBJECTS)
- {
- this.addGenericDebugObjects();
- }
- }
- private void createBuffers()
- {
- // box vertices
- ByteBuffer boxVerticesBuffer = MemoryUtil.memAlloc(BOX_VERTICES.length * Float.BYTES);
- boxVerticesBuffer.asFloatBuffer().put(BOX_VERTICES);
- boxVerticesBuffer.rewind();
- this.boxVertexBuffer = new GLVertexBuffer(false);
- this.boxVertexBuffer.bind();
- this.boxVertexBuffer.uploadBuffer(boxVerticesBuffer, 8, EDhApiGpuUploadMethod.DATA, BOX_VERTICES.length * Float.BYTES);
- MemoryUtil.memFree(boxVerticesBuffer);
-
- // box vertex indexes
- ByteBuffer solidIndexBuffer = MemoryUtil.memAlloc(BOX_INDICES.length * Integer.BYTES);
- solidIndexBuffer.asIntBuffer().put(BOX_INDICES);
- solidIndexBuffer.rewind();
- this.boxIndexBuffer = new GLElementBuffer(false);
- this.boxIndexBuffer.uploadBuffer(solidIndexBuffer, EDhApiGpuUploadMethod.DATA, BOX_INDICES.length * Integer.BYTES, GL32.GL_STATIC_DRAW);
- this.boxIndexBuffer.bind();
- MemoryUtil.memFree(solidIndexBuffer);
- }
- private void addGenericDebugObjects()
- {
- GenericRenderObjectFactory factory = GenericRenderObjectFactory.INSTANCE;
-
-
- // single giant box
- IDhApiRenderableBoxGroup singleGiantBoxGroup = factory.createForSingleBox(
- ModInfo.NAME + ":CyanChunkBox",
- new DhApiRenderableBox(
- new DhApiVec3d(0,0,0), new DhApiVec3d(16,190,16),
- new Color(Color.CYAN.getRed(), Color.CYAN.getGreen(), Color.CYAN.getBlue(), 125),
- EDhApiBlockMaterial.WATER)
- );
- singleGiantBoxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
- singleGiantBoxGroup.setBlockLight(LodUtil.MAX_MC_LIGHT);
- this.add(singleGiantBoxGroup);
-
-
- // single slender box
- IDhApiRenderableBoxGroup singleTallBoxGroup = factory.createForSingleBox(
- ModInfo.NAME + ":GreenBeacon",
- new DhApiRenderableBox(
- new DhApiVec3d(16,0,31), new DhApiVec3d(17,2000,32),
- new Color(Color.GREEN.getRed(), Color.GREEN.getGreen(), Color.GREEN.getBlue(), 125),
- EDhApiBlockMaterial.ILLUMINATED)
- );
- singleTallBoxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
- singleTallBoxGroup.setBlockLight(LodUtil.MAX_MC_LIGHT);
- this.add(singleTallBoxGroup);
-
-
- // absolute box group
- ArrayList absBoxList = new ArrayList<>();
- for (int i = 0; i < 18; i++)
- {
- absBoxList.add(new DhApiRenderableBox(
- new DhApiVec3d(i,150+i,24), new DhApiVec3d(1+i,151+i,25),
- new Color(Color.ORANGE.getRed(), Color.ORANGE.getGreen(), Color.ORANGE.getBlue()),
- EDhApiBlockMaterial.LAVA
- )
- );
- }
- IDhApiRenderableBoxGroup absolutePosBoxGroup = factory.createAbsolutePositionedGroup(ModInfo.NAME + ":OrangeStairs", absBoxList);
- this.add(absolutePosBoxGroup);
-
-
- // relative box group
- ArrayList relBoxList = new ArrayList<>();
- for (int i = 0; i < 8; i+=2)
- {
- relBoxList.add(new DhApiRenderableBox(
- new DhApiVec3d(0,i,0), new DhApiVec3d(1,1+i,1),
- new Color(Color.MAGENTA.getRed(), Color.MAGENTA.getGreen(), Color.MAGENTA.getBlue()),
- EDhApiBlockMaterial.METAL
- )
- );
- }
- IDhApiRenderableBoxGroup relativePosBoxGroup = factory.createRelativePositionedGroup(
- ModInfo.NAME + ":MovingMagentaGroup",
- new DhApiVec3d(24, 140, 24),
- relBoxList);
- relativePosBoxGroup.setPreRenderFunc((event) ->
- {
- DhApiVec3d pos = relativePosBoxGroup.getOriginBlockPos();
- pos.x += event.partialTicks / 2;
- pos.x %= 32;
- relativePosBoxGroup.setOriginBlockPos(pos);
- });
- this.add(relativePosBoxGroup);
-
-
- // massive relative box group
- ArrayList massRelBoxList = new ArrayList<>();
- for (int x = 0; x < 50*2; x+=2)
- {
- for (int z = 0; z < 50*2; z+=2)
- {
- massRelBoxList.add(new DhApiRenderableBox(
- new DhApiVec3d(-x, 0, -z), new DhApiVec3d(1-x, 1, 1-z),
- new Color(Color.RED.getRed(), Color.RED.getGreen(), Color.RED.getBlue()),
- EDhApiBlockMaterial.TERRACOTTA
- )
- );
- }
- }
- IDhApiRenderableBoxGroup massRelativePosBoxGroup = factory.createRelativePositionedGroup(
- ModInfo.NAME + ":MassRedGroup",
- new DhApiVec3d(-25, 140, 0),
- massRelBoxList);
- massRelativePosBoxGroup.setPreRenderFunc((event) ->
- {
- DhApiVec3d blockPos = massRelativePosBoxGroup.getOriginBlockPos();
- blockPos.y += event.partialTicks / 4;
- if (blockPos.y > 150f)
- {
- blockPos.y = 140f;
-
- Color newColor = (massRelativePosBoxGroup.get(0).color == Color.RED) ? Color.RED.darker() : Color.RED;
- massRelativePosBoxGroup.forEach((box) -> { box.color = newColor; });
- massRelativePosBoxGroup.triggerBoxChange();
- }
-
- massRelativePosBoxGroup.setOriginBlockPos(blockPos);
- });
- this.add(massRelativePosBoxGroup);
- }
-
- //endregion
-
-
-
- //==============//
- // registration //
- //==============//
- //region
-
- @Override
- public void add(IDhApiRenderableBoxGroup iBoxGroup) throws IllegalArgumentException
- {
- if (!(iBoxGroup instanceof RenderableBoxGroup))
- {
- throw new IllegalArgumentException("Box group must be of type ["+ RenderableBoxGroup.class.getSimpleName()+"], type received: ["+(iBoxGroup != null ? iBoxGroup.getClass() : "NULL")+"].");
- }
- RenderableBoxGroup boxGroup = (RenderableBoxGroup) iBoxGroup;
-
-
- long id = boxGroup.getId();
- if (this.boxGroupById.containsKey(id))
- {
- throw new IllegalArgumentException("A box group with the ID [" + id + "] is already present.");
- }
-
- this.boxGroupById.put(id, boxGroup);
- }
-
- @Override
- public IDhApiRenderableBoxGroup remove(long id) { return this.boxGroupById.remove(id); }
-
- public void clear() { this.boxGroupById.clear(); }
-
- //endregion
-
-
-
- //===========//
- // rendering //
- //===========//
- //region
-
- /**
- * @param renderingWithSsao
- * if true that means this render call is happening before the SSAO pass
- * and any objects rendered in this pass will have SSAO applied to them.
- */
- public void render(DhApiRenderParam renderEventParam, IProfilerWrapper profiler, boolean renderingWithSsao)
- {
- // render setup //
- profiler.push("setup");
-
- this.init();
-
- boolean useInstancedRendering = this.instancedRenderingAvailable
- && Config.Client.Advanced.Graphics.GenericRendering.enableInstancedRendering.get();
-
- ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderSetupEvent.class, renderEventParam);
-
-
- boolean renderWireframe = Config.Client.Advanced.Debugging.renderWireframe.get();
- if (renderWireframe)
- {
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_LINE);
- GLMC.disableFaceCulling();
- }
- else
- {
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
- GLMC.enableFaceCulling();
- }
-
- GLMC.enableBlend();
- GL32.glBlendEquation(GL32.GL_FUNC_ADD);
- GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
-
- IDhApiGenericObjectShaderProgram shaderProgram = useInstancedRendering ? this.instancedShaderProgram : this.directShaderProgram;
- IDhApiGenericObjectShaderProgram shaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiGenericObjectShaderProgram.class);
- if (shaderProgramOverride != null && shaderProgram.overrideThisFrame())
- {
- shaderProgram = shaderProgramOverride;
- }
-
- shaderProgram.bind(renderEventParam);
- shaderProgram.bindVertexBuffer(this.boxVertexBuffer.getId());
-
- this.boxIndexBuffer.bind();
-
- Vec3d camPos = MC_RENDER.getCameraExactPosition();
-
-
-
- // rendering //
-
- Collection boxList = this.boxGroupById.values();
- for (RenderableBoxGroup boxGroup : boxList)
- {
- // validation //
-
- // shouldn't happen, but just in case
- if (boxGroup == null)
- {
- continue;
- }
-
- // skip boxes that shouldn't render this pass
- if (boxGroup.ssaoEnabled != renderingWithSsao)
- {
- continue;
- }
-
- profiler.popPush("render prep");
- boxGroup.preRender(renderEventParam); // called even if the group is inactive, so the group can be activate if desired
-
- // ignore inactive groups
- if (!boxGroup.active)
- {
- continue;
- }
-
- // allow API users to cancel this object's rendering
- boolean cancelRendering = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericObjectRenderEvent.class, new DhApiBeforeGenericObjectRenderEvent.EventParam(renderEventParam, boxGroup));
- if (cancelRendering)
- {
- continue;
- }
-
- // update instanced data if needed
- if (useInstancedRendering)
- {
- boxGroup.tryUpdateInstancedDataAsync();
-
- // skip groups that haven't been uploaded yet
- if (boxGroup.instancedVbos.state != InstancedVboContainer.EState.RENDER)
- {
- continue;
- }
- }
-
-
-
- // render //
-
- profiler.popPush("rendering");
- profiler.push(boxGroup.getResourceLocationNamespace());
- profiler.push(boxGroup.getResourceLocationPath());
- if (useInstancedRendering)
- {
- this.renderBoxGroupInstanced(shaderProgram, renderEventParam, boxGroup, camPos, profiler);
- }
- else
- {
- this.renderBoxGroupDirect(shaderProgram, renderEventParam, boxGroup, camPos, profiler);
- }
- profiler.pop(); // resource path
- profiler.pop(); // resource namespace
-
- boxGroup.postRender(renderEventParam);
- }
-
-
- //==========//
- // clean up //
- //==========//
-
- profiler.popPush("cleanup");
-
- ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderCleanupEvent.class, renderEventParam);
-
- if (renderWireframe)
- {
- // default back to GL_FILL since all other rendering uses it
- GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, GL32.GL_FILL);
- GLMC.enableFaceCulling();
- }
-
- shaderProgram.unbind();
-
- profiler.pop();
- }
-
- //endregion
-
-
-
- //=====================//
- // instanced rendering //
- //=====================//
- //region
-
- private void renderBoxGroupInstanced(
- IDhApiGenericObjectShaderProgram shaderProgram, DhApiRenderParam renderEventParam,
- RenderableBoxGroup boxGroup, Vec3d camPos,
- IProfilerWrapper profiler)
- {
- // update instance data //
-
- profiler.push("vertex setup");
-
- DhApiRenderableBoxGroupShading shading = boxGroup.shading;
- if (shading == null)
- {
- shading = DEFAULT_SHADING;
- }
-
- shaderProgram.fillIndirectUniformData(
- renderEventParam,
- shading, boxGroup,
- camPos);
-
-
-
- // Bind instance data //
- profiler.popPush("binding");
-
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, boxGroup.instancedVbos.color);
- GL32.glEnableVertexAttribArray(1);
- GL32.glVertexAttribPointer(1, 4, GL32.GL_FLOAT, false, 4 * Float.BYTES, 0);
- this.vertexAttribDivisor(1, 1);
-
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, boxGroup.instancedVbos.scale);
- GL32.glEnableVertexAttribArray(2);
- this.vertexAttribDivisor(2, 1);
- GL32.glVertexAttribPointer(2, 3, GL32.GL_FLOAT, false, 3 * Float.BYTES, 0);
-
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, boxGroup.instancedVbos.chunkPos);
- GL32.glEnableVertexAttribArray(3);
- this.vertexAttribDivisor(3, 1);
- GL32.glVertexAttribIPointer(3, 3, GL32.GL_INT, 3 * Integer.BYTES, 0);
-
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, boxGroup.instancedVbos.subChunkPos);
- GL32.glEnableVertexAttribArray(4);
- this.vertexAttribDivisor(4, 1);
- GL32.glVertexAttribPointer(4, 3, GL32.GL_FLOAT, false, 3 * Float.BYTES, 0);
-
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, boxGroup.instancedVbos.material);
- GL32.glEnableVertexAttribArray(5);
- this.vertexAttribDivisor(5, 1);
- GL32.glVertexAttribIPointer(5, 1, GL32.GL_BYTE, Byte.BYTES, 0);
-
-
- // Draw instanced
- profiler.popPush("render");
- if (boxGroup.instancedVbos.uploadedBoxCount > 0)
- {
- GL32.glDrawElementsInstanced(GL32.GL_TRIANGLES, BOX_INDICES.length, GL32.GL_UNSIGNED_INT, 0, boxGroup.instancedVbos.uploadedBoxCount);
- }
-
-
- // Clean up
- profiler.popPush("cleanup");
-
- GL32.glDisableVertexAttribArray(1);
- GL32.glDisableVertexAttribArray(2);
- GL32.glDisableVertexAttribArray(3);
- GL32.glDisableVertexAttribArray(4);
- GL32.glDisableVertexAttribArray(5);
-
- profiler.pop();
- }
- /**
- * Clean way to handle both {@link GL33#glVertexAttribDivisor} and {@link ARBInstancedArrays#glVertexAttribDivisorARB}
- * based on which one is supported.
- */
- private void vertexAttribDivisor(int index, int divisor)
- {
- if (this.vertexAttribDivisorSupported)
- {
- GL33.glVertexAttribDivisor(index, divisor);
- }
- else if(this.instancedArraysSupported)
- {
- ARBInstancedArrays.glVertexAttribDivisorARB(index, divisor);
- }
- else
- {
- throw new IllegalStateException("Instanced rendering isn't supported by this machine. Direct rendering should have been used instead.");
- }
- }
-
- //endregion
-
-
-
- //==================//
- // direct rendering //
- //==================//
- //region
-
- private void renderBoxGroupDirect(
- IDhApiGenericObjectShaderProgram shaderProgram,
- DhApiRenderParam renderEventParam,
- RenderableBoxGroup boxGroup, Vec3d camPos,
- IProfilerWrapper profiler)
- {
- profiler.popPush("shared uniforms");
- DhApiRenderableBoxGroupShading shading = boxGroup.shading;
- if (shading == null)
- {
- shading = DhApiRenderableBoxGroupShading.getUnshaded();
- }
-
- shaderProgram.fillSharedDirectUniformData(renderEventParam, shading, boxGroup, camPos);
-
- for (int i = 0; i < boxGroup.size(); i++)
- {
- try
- {
- DhApiRenderableBox box = boxGroup.get(i);
- if (box != null)
- {
- profiler.popPush("direct uniforms");
- shaderProgram.fillDirectUniformData(renderEventParam, boxGroup, box, camPos);
-
- profiler.popPush("render");
- GL32.glDrawElements(GL32.GL_TRIANGLES, BOX_INDICES.length, GL32.GL_UNSIGNED_INT, 0);
- }
- }
- catch (IndexOutOfBoundsException e)
- {
- // Concurrency issue, the list was modified while rendering
- // this can probably be ignored.
- // However, if it does become a problem we can add locks to the box group.
- break;
- }
- }
-
- profiler.pop();
- }
-
- //endregion
-
-
-
- //=========//
- // getters //
- //=========//
- //region
-
- /** @throws IllegalStateException if {@link #init()} function hasn't been called yet */
- public boolean getInstancedRenderingAvailable() throws IllegalStateException
- {
- if (!this.init)
- {
- throw new IllegalStateException("GL initialization hasn't been completed.");
- }
-
- return this.instancedRenderingAvailable;
- }
-
- //endregion
-
-
-
- //=========//
- // F3 menu //
- //=========//
- //region
-
- public String getVboRenderDebugMenuString()
- {
- // get counts
- int totalGroupCount = this.boxGroupById.size();
- int totalBoxCount = 0;
-
- int activeGroupCount = 0;
- int activeBoxCount = 0;
-
- for (long key : this.boxGroupById.keySet())
- {
- RenderableBoxGroup renderGroup = this.boxGroupById.get(key);
- if (renderGroup.active)
- {
- activeGroupCount++;
- activeBoxCount += renderGroup.size();
- }
- totalBoxCount += renderGroup.size();
- }
-
-
- return "Generic Obj #: " + F3Screen.NUMBER_FORMAT.format(activeGroupCount) + "/" + F3Screen.NUMBER_FORMAT.format(totalGroupCount) + ", " +
- "Cube #: " + F3Screen.NUMBER_FORMAT.format(activeBoxCount) + "/" + F3Screen.NUMBER_FORMAT.format(totalBoxCount);
- }
-
- //endregion
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectShaderProgram.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectShaderProgram.java
deleted file mode 100644
index 572f5f8f2..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/GenericObjectShaderProgram.java
+++ /dev/null
@@ -1,231 +0,0 @@
-package com.seibel.distanthorizons.core.render.renderer.generic;
-
-import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiGenericObjectShaderProgram;
-import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
-import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
-import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
-import com.seibel.distanthorizons.api.objects.math.DhApiVec3i;
-import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
-import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
-import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
-import com.seibel.distanthorizons.core.util.LodUtil;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.util.math.Vec3f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
-
-public class GenericObjectShaderProgram extends ShaderProgram implements IDhApiGenericObjectShaderProgram
-{
- public static final String VERTEX_SHADER_INSTANCED_PATH = "shaders/genericObject/instanced/vert.vert";
- public static final String VERTEX_SHADER_DIRECT_PATH = "shaders/genericObject/direct/vert.vert";
- public static final String FRAGMENT_SHADER_INSTANCED_PATH = "shaders/genericObject/instanced/frag.frag";
- public static final String FRAGMENT_SHADER_DIRECT_PATH = "shaders/genericObject/direct/frag.frag";
-
- public final AbstractVertexAttribute va;
-
-
- // shader uniforms
- private final int directShaderTransformUniform;
- private final int directShaderColorUniform;
-
- private final int instancedShaderOffsetChunkUniform;
- private final int instancedShaderOffsetSubChunkUniform;
- private final int instancedShaderCameraChunkPosUniform;
- private final int instancedShaderCameraSubChunkPosUniform;
- private final int instancedShaderProjectionModelViewMatrixUniform;
-
- private final int lightMapUniform;
- private final int skyLightUniform;
- private final int blockLightUniform;
-
- private final int northShadingUniform;
- private final int southShadingUniform;
- private final int eastShadingUniform;
- private final int westShadingUniform;
- private final int topShadingUniform;
- private final int bottomShadingUniform;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- public GenericObjectShaderProgram(boolean useInstancedRendering)
- {
- super(
- useInstancedRendering ? VERTEX_SHADER_INSTANCED_PATH : VERTEX_SHADER_DIRECT_PATH,
- useInstancedRendering ? FRAGMENT_SHADER_INSTANCED_PATH : FRAGMENT_SHADER_DIRECT_PATH,
- "vPosition"
- );
-
- this.va = AbstractVertexAttribute.create();
- this.va.bind();
- // Pos
- this.va.setVertexAttribute(0, 0, VertexPointer.addVec3Pointer(false));
- this.va.completeAndCheck(Float.BYTES * 3);
-
- this.directShaderTransformUniform = this.tryGetUniformLocation("uTransform");
- this.directShaderColorUniform = this.tryGetUniformLocation("uColor");
-
- this.instancedShaderOffsetChunkUniform = this.tryGetUniformLocation("uOffsetChunk");
- this.instancedShaderOffsetSubChunkUniform = this.tryGetUniformLocation("uOffsetSubChunk");
- this.instancedShaderCameraChunkPosUniform = this.tryGetUniformLocation("uCameraPosChunk");
- this.instancedShaderCameraSubChunkPosUniform = this.tryGetUniformLocation("uCameraPosSubChunk");
- this.instancedShaderProjectionModelViewMatrixUniform = this.tryGetUniformLocation("uProjectionMvm");
-
- this.lightMapUniform = this.getUniformLocation("uLightMap");
- this.skyLightUniform = this.getUniformLocation("uSkyLight");
- this.blockLightUniform = this.getUniformLocation("uBlockLight");
- this.northShadingUniform = this.getUniformLocation("uNorthShading");
- this.southShadingUniform = this.getUniformLocation("uSouthShading");
- this.eastShadingUniform = this.getUniformLocation("uEastShading");
- this.westShadingUniform = this.getUniformLocation("uWestShading");
- this.topShadingUniform = this.getUniformLocation("uTopShading");
- this.bottomShadingUniform = this.getUniformLocation("uBottomShading");
-
- }
-
-
-
- //=========//
- // methods //
- //=========//
-
- @Override
- public void bind(DhApiRenderParam renderEventParam)
- {
- super.bind();
- this.va.bind();
- }
- @Override
- public void unbind()
- {
- super.unbind();
- this.va.unbind();
- }
-
- @Override
- public void free()
- {
- this.va.free();
- super.free();
- }
-
- @Override
- public void bindVertexBuffer(int vbo) { this.va.bindBufferToAllBindingPoints(vbo); }
-
- @Override
- public void fillIndirectUniformData(
- DhApiRenderParam renderParameters,
- DhApiRenderableBoxGroupShading shading, IDhApiRenderableBoxGroup boxGroup,
- DhApiVec3d camPos
- )
- {
- Mat4f projectionMvmMatrix = new Mat4f(renderParameters.dhProjectionMatrix);
- projectionMvmMatrix.multiply(renderParameters.dhModelViewMatrix);
-
- super.bind();
-
-
-
-
- this.setUniform(this.instancedShaderOffsetChunkUniform,
- new DhApiVec3i(
- LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().x),
- LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().y),
- LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().z)
- ));
- this.setUniform(this.instancedShaderOffsetSubChunkUniform,
- new Vec3f(
- LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().x),
- LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().y),
- LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().z)
- ));
-
- this.setUniform(this.instancedShaderCameraChunkPosUniform,
- new DhApiVec3i(
- LodUtil.getChunkPosFromDouble(camPos.x),
- LodUtil.getChunkPosFromDouble(camPos.y),
- LodUtil.getChunkPosFromDouble(camPos.z)
- ));
- this.setUniform(this.instancedShaderCameraSubChunkPosUniform,
- new Vec3f(
- LodUtil.getSubChunkPosFromDouble(camPos.x),
- LodUtil.getSubChunkPosFromDouble(camPos.y),
- LodUtil.getSubChunkPosFromDouble(camPos.z)
- ));
-
- this.setUniform(this.instancedShaderProjectionModelViewMatrixUniform, projectionMvmMatrix);
-
- this.setUniform(this.lightMapUniform, ILightMapWrapper.BOUND_INDEX);
- this.setUniform(this.skyLightUniform, boxGroup.getSkyLight());
- this.setUniform(this.blockLightUniform, boxGroup.getBlockLight());
-
-
- this.setUniform(this.northShadingUniform, shading.north);
- this.setUniform(this.southShadingUniform, shading.south);
- this.setUniform(this.eastShadingUniform, shading.east);
- this.setUniform(this.westShadingUniform, shading.west);
- this.setUniform(this.topShadingUniform, shading.top);
- this.setUniform(this.bottomShadingUniform, shading.bottom);
-
-
- }
-
-
- @Override
- public void fillSharedDirectUniformData(
- DhApiRenderParam renderParameters,
- DhApiRenderableBoxGroupShading shading, IDhApiRenderableBoxGroup boxGroup,
- DhApiVec3d camPos)
- {
-
- this.setUniform(this.lightMapUniform, ILightMapWrapper.BOUND_INDEX);
- this.setUniform(this.skyLightUniform, boxGroup.getSkyLight());
- this.setUniform(this.blockLightUniform, boxGroup.getBlockLight());
-
-
- this.setUniform(this.northShadingUniform, shading.north);
- this.setUniform(this.southShadingUniform, shading.south);
- this.setUniform(this.eastShadingUniform, shading.east);
- this.setUniform(this.westShadingUniform, shading.west);
- this.setUniform(this.topShadingUniform, shading.top);
- this.setUniform(this.bottomShadingUniform, shading.bottom);
-
- }
-
- public void fillDirectUniformData(
- DhApiRenderParam renderParameters,
- IDhApiRenderableBoxGroup boxGroup, DhApiRenderableBox box,
- DhApiVec3d camPos)
- {
- Mat4f projectionMvmMatrix = new Mat4f(renderParameters.dhProjectionMatrix);
- projectionMvmMatrix.multiply(renderParameters.dhModelViewMatrix);
-
- Mat4f boxTransform = Mat4f.createTranslateMatrix(
- (float) (box.minPos.x + boxGroup.getOriginBlockPos().x - camPos.x),
- (float) (box.minPos.y + boxGroup.getOriginBlockPos().y - camPos.y),
- (float) (box.minPos.z + boxGroup.getOriginBlockPos().z - camPos.z));
- boxTransform.multiply(Mat4f.createScaleMatrix(
- (float) (box.maxPos.x - box.minPos.x),
- (float) (box.maxPos.y - box.minPos.y),
- (float) (box.maxPos.z - box.minPos.z)));
- projectionMvmMatrix.multiply(boxTransform);
- this.setUniform(this.directShaderTransformUniform, projectionMvmMatrix);
-
- this.setUniform(this.directShaderColorUniform, box.color);
-
- }
-
-
-
- @Override
- public int getId() { return this.id; }
-
- /** The base DH render program should always render */
- @Override
- public boolean overrideThisFrame() { return true; }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/InstancedVboContainer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/InstancedVboContainer.java
deleted file mode 100644
index 744e3d64c..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/InstancedVboContainer.java
+++ /dev/null
@@ -1,193 +0,0 @@
-package com.seibel.distanthorizons.core.render.renderer.generic;
-
-import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.util.LodUtil;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import org.lwjgl.opengl.GL32;
-
-import java.awt.*;
-import java.util.List;
-
-/**
- * For use by {@link RenderableBoxGroup}
- *
- * @see RenderableBoxGroup
- */
-public class InstancedVboContainer implements AutoCloseable
-{
- private static final DhLogger LOGGER = new DhLoggerBuilder().build();
-
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
-
-
-
- public int chunkPos = 0;
- public int subChunkPos = 0;
- public int scale = 0;
- public int color = 0;
- public int material = 0;
-
- public int[] chunkPosData = new int[0];
- public float[] subChunkPosData = new float[0];
- public float[] scalingData = new float[0];
- public float[] colorData = new float[0];
- public int[] materialData = new int[0];
-
- public int uploadedBoxCount = 0;
-
- public EState state = EState.NEW;
-
-
-
- //===========================//
- // render building/uploading //
- //===========================//
- //region
-
- /** needs to be done on the render thread */
- public void tryRunRenderThreadSetup()
- {
- if (this.chunkPos == 0)
- {
- this.chunkPos = GLMC.glGenBuffers();
- this.subChunkPos = GLMC.glGenBuffers();
- this.scale = GLMC.glGenBuffers();
- this.color = GLMC.glGenBuffers();
- this.material = GLMC.glGenBuffers();
- }
- }
-
- public void updateVertexData(List uploadBoxList)
- {
- int boxCount = uploadBoxList.size();
-
-
- // recreate the data arrays if their size is different
- if (this.uploadedBoxCount != boxCount)
- {
- this.uploadedBoxCount = boxCount;
-
- this.chunkPosData = new int[boxCount * 3]; // 3 elements XYZ
- this.subChunkPosData = new float[boxCount * 3]; // 3 elements XYZ
- this.scalingData = new float[boxCount * 3]; // 3 elements XYZ
-
- this.colorData = new float[boxCount * 4]; // 4 elements, RGBA
- this.materialData = new int[boxCount];
- }
-
-
- // transformation / scaling //
- for (int i = 0; i < boxCount; i++)
- {
- DhApiRenderableBox box = uploadBoxList.get(i);
-
- int dataIndex = i * 3;
-
- this.chunkPosData[dataIndex] = LodUtil.getChunkPosFromDouble(box.minPos.x);
- this.chunkPosData[dataIndex + 1] = LodUtil.getChunkPosFromDouble(box.minPos.y);
- this.chunkPosData[dataIndex + 2] = LodUtil.getChunkPosFromDouble(box.minPos.z);
-
- this.subChunkPosData[dataIndex] = LodUtil.getSubChunkPosFromDouble(box.minPos.x);
- this.subChunkPosData[dataIndex + 1] = LodUtil.getSubChunkPosFromDouble(box.minPos.y);
- this.subChunkPosData[dataIndex + 2] = LodUtil.getSubChunkPosFromDouble(box.minPos.z);
-
- this.scalingData[dataIndex] = (float) (box.maxPos.x - box.minPos.x);
- this.scalingData[dataIndex + 1] = (float) (box.maxPos.y - box.minPos.y);
- this.scalingData[dataIndex + 2] = (float) (box.maxPos.z - box.minPos.z);
- }
-
-
- // colors/materials //
- for (int i = 0; i < boxCount; i++)
- {
- DhApiRenderableBox box = uploadBoxList.get(i);
- Color color = box.color;
- int colorIndex = i * 4;
- this.colorData[colorIndex] = color.getRed() / 255.0f;
- this.colorData[colorIndex + 1] = color.getGreen() / 255.0f;
- this.colorData[colorIndex + 2] = color.getBlue() / 255.0f;
- this.colorData[colorIndex + 3] = color.getAlpha() / 255.0f;
-
- this.materialData[i] = box.material;
- }
-
- this.state = InstancedVboContainer.EState.READY_TO_UPLOAD;
- }
-
- public void uploadDataToGpu()
- {
- // Upload transformation matrices
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.chunkPos);
- GL32.glBufferData(GL32.GL_ARRAY_BUFFER, this.chunkPosData, GL32.GL_DYNAMIC_DRAW);
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.subChunkPos);
- GL32.glBufferData(GL32.GL_ARRAY_BUFFER, this.subChunkPosData, GL32.GL_DYNAMIC_DRAW);
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.scale);
- GL32.glBufferData(GL32.GL_ARRAY_BUFFER, this.scalingData, GL32.GL_DYNAMIC_DRAW);
-
- // Upload colors
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.color);
- GL32.glBufferData(GL32.GL_ARRAY_BUFFER, this.colorData, GL32.GL_DYNAMIC_DRAW);
-
- // Upload materials
- GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.material);
- GL32.glBufferData(GL32.GL_ARRAY_BUFFER, this.materialData, GL32.GL_DYNAMIC_DRAW);
-
- this.state = EState.RENDER;
- }
-
- //endregion
-
-
-
- //================//
- // base overrides //
- //================//
- //region
-
- @Override
- public void close()
- {
- tryDeleteBuffer(this.chunkPos);
- tryDeleteBuffer(this.subChunkPos);
- tryDeleteBuffer(this.scale);
- tryDeleteBuffer(this.color);
- tryDeleteBuffer(this.material);
- }
- private static void tryDeleteBuffer(int bufferId)
- {
- // usually unnecessary, but just in case
- if (bufferId != 0)
- {
- GLMC.glDeleteBuffers(bufferId);
- }
- }
-
- //endregion
-
-
-
- //================//
- // helper classes //
- //================//
- //region
-
- public enum EState
- {
- NEW,
- UPDATING_DATA,
- READY_TO_UPLOAD,
- RENDER,
-
- ERROR,
- }
-
- //endregion
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/AbstractShaderRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/AbstractShaderRenderer.java
deleted file mode 100644
index 46ee19402..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/AbstractShaderRenderer.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import org.lwjgl.opengl.GL32;
-
-public abstract class AbstractShaderRenderer
-{
- protected static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
-
-
- protected ShaderProgram shader;
-
- protected boolean init = false;
-
-
- protected AbstractShaderRenderer() {}
-
- public void init()
- {
- if (this.init) return;
- this.init = true;
-
- this.onInit();
- }
-
- public void render(float partialTicks)
- {
- this.init();
-
- this.shader.bind();
-
- this.onApplyUniforms(partialTicks);
-
- int width = MC_RENDER.getTargetFramebufferViewportWidth();
- int height = MC_RENDER.getTargetFramebufferViewportHeight();
- GL32.glViewport(0, 0, width, height);
-
- this.onRender();
-
- this.shader.unbind();
- }
-
- public void free()
- {
- if (this.shader != null)
- {
- this.shader.free();
- }
- }
-
- protected void onInit() {}
-
- protected void onApplyUniforms(float partialTicks) {}
-
- protected void onRender() {}
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/DhApplyShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/DhApplyShader.java
deleted file mode 100644
index 95b0c8b05..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/DhApplyShader.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.glObject.GLState;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
-import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.logging.DhLogger;
-import org.lwjgl.opengl.GL32;
-
-/**
- * Copies {@link LodRenderer}'s currently active color and depth texture to Minecraft's framebuffer.
- */
-public class DhApplyShader extends AbstractShaderRenderer
-{
- public static DhApplyShader INSTANCE = new DhApplyShader();
-
- private static final DhLogger LOGGER = new DhLoggerBuilder().build();
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- // uniforms
- public int gDhColorTextureUniform;
- public int gDepthMapUniform;
-
-
-
- //=======//
- // setup //
- //=======//
- //region
-
- private DhApplyShader() { }
-
- @Override
- public void onInit()
- {
- this.shader = new ShaderProgram(
- "shaders/quadApply.vert",
- "shaders/apply.frag",
- "vPosition"
- );
-
- // uniform setup
- this.gDhColorTextureUniform = this.shader.getUniformLocation("gDhColorTexture");
- this.gDepthMapUniform = this.shader.getUniformLocation("gDhDepthTexture");
-
- }
-
- @Override
- protected void onApplyUniforms(float partialTicks) { }
-
- //endregion
-
-
-
- //========//
- // render //
- //========//
- //region
-
- @Override
- protected void onRender()
- {
- if (MC_RENDER.mcRendersToFrameBuffer())
- {
- this.renderToFrameBuffer();
- }
- else
- {
- this.renderToMcTexture();
- }
- }
- private void renderToFrameBuffer()
- {
- int targetFrameBuffer = MC_RENDER.getTargetFramebuffer();
- if (targetFrameBuffer == -1)
- {
- return;
- }
-
-
- try (GLState state = new GLState())
- {
-
- GLMC.disableDepthTest();
-
- // blending isn't needed, we're manually merging the MC and DH textures
- // Note: this prevents the sun/moon and stars from rendering through transparent LODs,
- // however this also fixes transparent LODs from glowing when rendered against the sky during the day
- GLMC.disableBlend();
-
- // old blending logic in case it's ever needed:
- //GLMC.enableBlend();
- //GL32.glBlendEquation(GL32.GL_FUNC_ADD);
- //GLMC.glBlendFunc(GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(LodRenderer.INSTANCE.getActiveColorTextureId());
- GL32.glUniform1i(this.gDhColorTextureUniform, 0);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE1);
- GLMC.glBindTexture(LodRenderer.INSTANCE.getActiveDepthTextureId());
- GL32.glUniform1i(this.gDepthMapUniform, 1);
-
- // Copy to MC's framebuffer
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, targetFrameBuffer);
-
- ScreenQuad.INSTANCE.render();
- }
- // everything's been restored, except at this point the MC framebuffer should now be used instead
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, targetFrameBuffer);
-
- }
- private void renderToMcTexture()
- {
- int targetColorTextureId = MC_RENDER.getColorTextureId();
- if (targetColorTextureId == -1)
- {
- return;
- }
-
- int dhFrameBufferId = LodRenderer.INSTANCE.getActiveFramebufferId();
- if (dhFrameBufferId == -1)
- {
- return;
- }
-
- int mcFrameBufferId = MC_RENDER.getTargetFramebuffer();
- if (mcFrameBufferId == -1)
- {
- return;
- }
-
-
-
- try (GLState state = new GLState())
- {
- GLMC.disableDepthTest();
-
- // blending isn't needed, we're just directly merging the MC and DH textures
- // Note: this prevents the sun/moon and stars from rendering through transparent LODs,
- // however this also fixes
- GLMC.disableBlend();
-
- // old blending logic in case it's ever needed:
- //GLMC.enableBlend();
- //GL32.glBlendEquation(GL32.GL_FUNC_ADD);
- //GLMC.glBlendFunc(GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(LodRenderer.INSTANCE.getActiveColorTextureId());
- GL32.glUniform1i(this.gDhColorTextureUniform, 0);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE1);
- GLMC.glBindTexture(LodRenderer.INSTANCE.getActiveDepthTextureId());
- GL32.glUniform1i(this.gDepthMapUniform, 1);
-
-
-
- GL32.glFramebufferTexture(GL32.GL_DRAW_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, targetColorTextureId, 0);
-
- // Copy to MC's texture via MC's framebuffer
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, dhFrameBufferId);
-
- ScreenQuad.INSTANCE.render();
- }
- // everything's been restored, except at this point the MC framebuffer should now be used instead
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, mcFrameBufferId);
-
- }
-
- //endregion
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/DhFadeShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/DhFadeShader.java
deleted file mode 100644
index 884aa8b1f..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/DhFadeShader.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
-import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
-import com.seibel.distanthorizons.core.util.RenderUtil;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import org.lwjgl.opengl.GL32;
-
-public class DhFadeShader extends AbstractShaderRenderer
-{
- public static DhFadeShader INSTANCE = new DhFadeShader();
-
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- public int frameBuffer = -1;
-
- private Mat4f inverseDhMvmProjMatrix;
-
-
- // Uniforms
-
- /** Inverted Model View Projection matrix */
- public int uDhInvMvmProj = -1;
-
- public int uDhDepthTexture = -1;
- public int uMcColorTexture = -1;
- public int uDhColorTexture = -1;
-
- public int uStartFadeBlockDistance = -1;
- public int uEndFadeBlockDistance = -1;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- public DhFadeShader() { }
-
- @Override
- public void onInit()
- {
- this.shader = new ShaderProgram(
- "shaders/quadApply.vert",
- "shaders/fade/dhFade.frag",
- "vPosition"
- );
-
- // all uniforms should be tryGet...
- // because disabling fade can cause the GLSL to optimize out most (if not all) uniforms
-
- // near fade
- this.uDhInvMvmProj = this.shader.tryGetUniformLocation("uDhInvMvmProj");
-
- this.uDhDepthTexture = this.shader.tryGetUniformLocation("uDhDepthTexture");
- this.uMcColorTexture = this.shader.tryGetUniformLocation("uMcColorTexture");
- this.uDhColorTexture = this.shader.tryGetUniformLocation("uDhColorTexture");
-
- this.uStartFadeBlockDistance = this.shader.tryGetUniformLocation("uStartFadeBlockDistance");
- this.uEndFadeBlockDistance = this.shader.tryGetUniformLocation("uEndFadeBlockDistance");
-
- }
-
-
-
- //=============//
- // render prep //
- //=============//
-
- @Override
- protected void onApplyUniforms(float partialTicks)
- {
- this.shader.setUniform(this.uDhInvMvmProj, this.inverseDhMvmProjMatrix);
-
-
- float dhFarClipDistance = RenderUtil.getFarClipPlaneDistanceInBlocks();
- float fadeStartDistance = dhFarClipDistance * 0.5f;
- float fadeEndDistance = dhFarClipDistance * 0.9f;
-
- this.shader.setUniform(this.uStartFadeBlockDistance, fadeStartDistance);
- this.shader.setUniform(this.uEndFadeBlockDistance, fadeEndDistance);
-
- }
-
- public void setProjectionMatrix(Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix)
- {
- Mat4f dhProjectionMatrix = RenderUtil.createLodProjectionMatrix(mcProjectionMatrix);
- Mat4f dhModelViewMatrix = RenderUtil.createLodModelViewMatrix(mcModelViewMatrix);
-
- Mat4f inverseDhModelViewProjectionMatrix = new Mat4f(dhProjectionMatrix);
- inverseDhModelViewProjectionMatrix.multiply(dhModelViewMatrix);
- inverseDhModelViewProjectionMatrix.invert();
- this.inverseDhMvmProjMatrix = inverseDhModelViewProjectionMatrix;
- }
-
-
- //========//
- // render //
- //========//
-
- @Override
- protected void onRender()
- {
- int depthTextureId = LodRenderer.INSTANCE.getActiveDepthTextureId();
- int colorTextureId = LodRenderer.INSTANCE.getActiveColorTextureId();
-
- if (depthTextureId == -1
- || colorTextureId == -1)
- {
- // the renderer is currently being re-built and/or inactive,
- // we don't need to/can't render fading
- return;
- }
-
-
-
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.frameBuffer);
- GLMC.disableScissorTest();
- GLMC.disableDepthTest();
- GLMC.disableBlend();
-
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(depthTextureId);
- GL32.glUniform1i(this.uDhDepthTexture, 0);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE1);
- GLMC.glBindTexture(MC_RENDER.getColorTextureId());
- GL32.glUniform1i(this.uMcColorTexture, 1);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE2);
- GLMC.glBindTexture(colorTextureId);
- GL32.glUniform1i(this.uDhColorTexture, 2);
-
-
- ScreenQuad.INSTANCE.render();
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeApplyShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeApplyShader.java
deleted file mode 100644
index e3940cafa..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeApplyShader.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.renderer.VanillaFadeRenderer;
-import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import org.lwjgl.opengl.GL32;
-
-/**
- * Draws the Fade texture onto Minecraft's FrameBuffer.
- *
- * See Also:
- * {@link VanillaFadeRenderer} - Parent to this shader.
- * {@link VanillaFadeShader} - draws the Fade texture.
- */
-public class FadeApplyShader extends AbstractShaderRenderer
-{
- public static FadeApplyShader INSTANCE = new FadeApplyShader();
-
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
-
- public int fadeTexture;
-
- public int readFramebuffer;
- public int drawFramebuffer;
-
- // uniforms
- public int uFadeColorTextureUniform = -1;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- @Override
- public void onInit()
- {
- this.shader = new ShaderProgram(
- "shaders/quadApply.vert",
- "shaders/fade/apply.frag",
- "vPosition"
- );
-
- // uniform setup
- this.uFadeColorTextureUniform = this.shader.getUniformLocation("uFadeColorTextureUniform");
-
- }
-
-
-
- //=============//
- // render prep //
- //=============//
-
- @Override
- protected void onApplyUniforms(float partialTicks)
- {
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(this.fadeTexture);
- GL32.glUniform1i(this.uFadeColorTextureUniform, 0);
-
- }
-
-
-
- //========//
- // render //
- //========//
-
- @Override
- protected void onRender()
- {
- GLMC.disableBlend();
-
- // Depth testing must be disabled otherwise this application shader won't apply anything.
- // setting this isn't necessary in vanilla, but some mods may change this, requiring it to be set manually,
- // it should be automatically restored after rendering is complete.
- GLMC.disableDepthTest();
-
-
- // apply the rendered Fade to Minecraft's framebuffer
- GLMC.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, this.readFramebuffer);
- GLMC.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, this.drawFramebuffer);
-
- ScreenQuad.INSTANCE.render();
-
- GLMC.enableDepthTest();
-
- }
-
-
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogApplyShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogApplyShader.java
deleted file mode 100644
index 3c90a17e7..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogApplyShader.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.renderer.FogRenderer;
-import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
-import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import org.lwjgl.opengl.GL32;
-
-/**
- * Draws the Fog texture onto DH's FrameBuffer.
- *
- * See Also:
- * {@link FogRenderer} - Parent to this shader.
- * {@link FogShader} - draws the Fog texture.
- */
-public class FogApplyShader extends AbstractShaderRenderer
-{
- public static FogApplyShader INSTANCE = new FogApplyShader();
-
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- public int fogTexture;
-
- // uniforms
- public int colorTextureUniform;
- public int depthTextureUniform;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- @Override
- public void onInit()
- {
- this.shader = new ShaderProgram(
- "shaders/quadApply.vert",
- "shaders/fog/apply.frag",
- "vPosition"
- );
-
- // uniform setup
- this.colorTextureUniform = this.shader.getUniformLocation("uColorTexture");
- this.depthTextureUniform = this.shader.getUniformLocation("uDepthTexture");
-
- }
-
-
-
- //=============//
- // render prep //
- //=============//
-
- @Override
- protected void onApplyUniforms(float partialTicks)
- {
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(this.fogTexture);
- GL32.glUniform1i(this.colorTextureUniform, 0);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE1);
- GLMC.glBindTexture(LodRenderer.INSTANCE.getActiveDepthTextureId());
- GL32.glUniform1i(this.depthTextureUniform, 1);
-
- }
-
-
-
- //========//
- // render //
- //========//
-
- @Override
- protected void onRender()
- {
- GLMC.enableBlend();
- GL32.glBlendEquation(GL32.GL_FUNC_ADD);
- GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
-
- // Depth testing must be disabled otherwise this application shader won't apply anything.
- // setting this isn't necessary in vanilla, but some mods may change this, requiring it to be set manually,
- // it should be automatically restored after rendering is complete.
- GLMC.disableDepthTest();
-
-
- // apply the rendered Fog to DH's framebuffer
- GLMC.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, FogShader.INSTANCE.frameBuffer);
- GLMC.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, LodRenderer.INSTANCE.getActiveFramebufferId());
-
- ScreenQuad.INSTANCE.render();
-
- GLMC.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, 0);
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogShader.java
deleted file mode 100644
index 028fb4d78..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogShader.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogColorMode;
-import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection;
-import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode;
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
-import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
-import com.seibel.distanthorizons.core.util.LodUtil;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import org.lwjgl.opengl.GL32;
-
-import java.awt.*;
-
-public class FogShader extends AbstractShaderRenderer
-{
- public static final FogShader INSTANCE = new FogShader();
-
- private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
-
-
-
- public int frameBuffer;
-
- private Mat4f inverseMvmProjMatrix;
-
-
-
- //==========//
- // Uniforms //
- //==========//
-
- public int uDepthMap;
- /** Inverted Model View Projection matrix */
- public int uInvMvmProj;
-
- // fog uniforms
- public int uFogColor;
- public int uFogScale;
- public int uFogVerticalScale;
- public int uFogDebugMode;
- public int uFogFalloffType;
-
- // far fog
- public int uFarFogStart;
- public int uFarFogLength;
- public int uFarFogMin;
- public int uFarFogRange;
- public int uFarFogDensity;
-
- // height fog
- public int uHeightFogStart;
- public int uHeightFogLength;
- public int uHeightFogMin;
- public int uHeightFogRange;
- public int uHeightFogDensity;
-
- public int uHeightFogEnabled;
- public int uHeightFogFalloffType;
- public int uHeightBasedOnCamera;
- public int uHeightFogBaseHeight;
- public int uHeightFogAppliesUp;
- public int uHeightFogAppliesDown;
- public int uUseSphericalFog;
- public int uHeightFogMixingMode;
- public int uCameraBlockYPos;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- public FogShader() { }
-
- @Override
- public void onInit()
- {
- this.shader = new ShaderProgram(
- "shaders/quadApply.vert",
- "shaders/fog/fog.frag",
- "vPosition"
- );
-
- // all uniforms should be tryGet...
- // because disabling fog can cause the GLSL to optimize out most (if not all) uniforms
-
- this.uDepthMap = this.shader.getUniformLocation("uDepthMap");
- this.uInvMvmProj = this.shader.getUniformLocation("uInvMvmProj");
-
- // Fog uniforms
- this.uFogScale = this.shader.getUniformLocation("uFogScale");
- this.uFogVerticalScale = this.shader.getUniformLocation("uFogVerticalScale");
- this.uFogColor = this.shader.getUniformLocation("uFogColor");
- this.uFogDebugMode = this.shader.getUniformLocation("uFogDebugMode");
- this.uFogFalloffType = this.shader.getUniformLocation("uFogFalloffType");
-
- // fog config
- this.uFarFogStart = this.shader.getUniformLocation("uFarFogStart");
- this.uFarFogLength = this.shader.getUniformLocation("uFarFogLength");
- this.uFarFogMin = this.shader.getUniformLocation("uFarFogMin");
- this.uFarFogRange = this.shader.getUniformLocation("uFarFogRange");
- this.uFarFogDensity = this.shader.getUniformLocation("uFarFogDensity");
-
- // height fog
- this.uHeightFogStart = this.shader.getUniformLocation("uHeightFogStart");
- this.uHeightFogLength = this.shader.getUniformLocation("uHeightFogLength");
- this.uHeightFogMin = this.shader.getUniformLocation("uHeightFogMin");
- this.uHeightFogRange = this.shader.getUniformLocation("uHeightFogRange");
- this.uHeightFogDensity = this.shader.getUniformLocation("uHeightFogDensity");
-
- this.uHeightFogEnabled = this.shader.getUniformLocation("uHeightFogEnabled");
- this.uHeightFogFalloffType = this.shader.getUniformLocation("uHeightFogFalloffType");
- this.uHeightBasedOnCamera = this.shader.getUniformLocation("uHeightBasedOnCamera");
- this.uHeightFogBaseHeight = this.shader.getUniformLocation("uHeightFogBaseHeight");
- this.uHeightFogAppliesUp = this.shader.getUniformLocation("uHeightFogAppliesUp");
- this.uHeightFogAppliesDown = this.shader.getUniformLocation("uHeightFogAppliesDown");
- this.uUseSphericalFog = this.shader.getUniformLocation("uUseSphericalFog");
- this.uHeightFogMixingMode = this.shader.getUniformLocation("uHeightFogMixingMode");
- this.uCameraBlockYPos = this.shader.getUniformLocation("uCameraBlockYPos");
-
- }
-
-
-
- //=============//
- // render prep //
- //=============//
-
- @Override
- protected void onApplyUniforms(float partialTicks)
- {
- int lodDrawDistance = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH;
-
-
-
- if (this.inverseMvmProjMatrix != null)
- {
- this.shader.setUniform(this.uInvMvmProj, this.inverseMvmProjMatrix);
- }
-
-
- // Fog uniforms
- this.shader.setUniform(this.uFogColor, this.getFogColor(partialTicks));
- this.shader.setUniform(this.uFogScale, 1.f / lodDrawDistance);
- this.shader.setUniform(this.uFogVerticalScale, 1.f / MC.getWrappedClientLevel().getMaxHeight());
- // only used for debugging
- this.shader.setUniform(this.uFogDebugMode, 0); // 1 = render everything with fog color // 7 = use debug rendering
- this.shader.setUniform(this.uFogFalloffType, Config.Client.Advanced.Graphics.Fog.farFogFalloff.get().value);
-
-
- // fog config
- float farFogStart = Config.Client.Advanced.Graphics.Fog.farFogStart.get();
- float farFogEnd = Config.Client.Advanced.Graphics.Fog.farFogEnd.get();
- float farFogMin = Config.Client.Advanced.Graphics.Fog.farFogMin.get();
- float farFogMax = Config.Client.Advanced.Graphics.Fog.farFogMax.get();
- float farFogDensity = Config.Client.Advanced.Graphics.Fog.farFogDensity.get();
-
- // override fog if underwater
- if (MC_RENDER.isFogStateSpecial())
- {
- // hide everything behind fog
- farFogStart = 0.0f;
- farFogEnd = 0.0f;
- }
-
- this.shader.setUniform(this.uFarFogStart, farFogStart);
- this.shader.setUniform(this.uFarFogLength, farFogEnd - farFogStart);
- this.shader.setUniform(this.uFarFogMin, farFogMin);
- this.shader.setUniform(this.uFarFogRange, farFogMax - farFogMin);
- this.shader.setUniform(this.uFarFogDensity, farFogDensity);
-
-
- // height config
- EDhApiHeightFogMixMode heightFogMixingMode = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMixMode.get();
- boolean heightFogEnabled = heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL && heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL;
- boolean useSphericalFog = heightFogMixingMode == EDhApiHeightFogMixMode.SPHERICAL;
- EDhApiHeightFogDirection heightFogCameraDirection = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDirection.get();
-
- float heightFogStart = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogStart.get();
- float heightFogEnd = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogEnd.get();
- float heightFogMin = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMin.get();
- float heightFogMax = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMax.get();
- float heightFogDensity = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDensity.get();
-
- this.shader.setUniform(this.uHeightFogStart, heightFogStart);
- this.shader.setUniform(this.uHeightFogLength, heightFogEnd - heightFogStart);
- this.shader.setUniform(this.uHeightFogMin, heightFogMin);
- this.shader.setUniform(this.uHeightFogRange, heightFogMax - heightFogMin);
- this.shader.setUniform(this.uHeightFogDensity, heightFogDensity);
-
-
- this.shader.setUniform(this.uHeightFogEnabled, heightFogEnabled);
- this.shader.setUniform(this.uHeightFogFalloffType, Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogFalloff.get().value);
- this.shader.setUniform(this.uHeightFogBaseHeight, Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogBaseHeight.get());
- this.shader.setUniform(this.uHeightBasedOnCamera, heightFogCameraDirection.basedOnCamera);
- this.shader.setUniform(this.uHeightFogAppliesUp, heightFogCameraDirection.fogAppliesUp);
- this.shader.setUniform(this.uHeightFogAppliesDown, heightFogCameraDirection.fogAppliesDown);
- this.shader.setUniform(this.uUseSphericalFog, useSphericalFog);
- this.shader.setUniform(this.uHeightFogMixingMode, heightFogMixingMode.value);
- this.shader.setUniform(this.uCameraBlockYPos, (float)MC_RENDER.getCameraExactPosition().y);
-
- }
- private Color getFogColor(float partialTicks)
- {
- Color fogColor;
-
- if (Config.Client.Advanced.Graphics.Fog.colorMode.get() == EDhApiFogColorMode.USE_SKY_COLOR)
- {
- fogColor = MC_RENDER.getSkyColor();
- }
- else
- {
- fogColor = MC_RENDER.getFogColor(partialTicks);
- }
-
- return fogColor;
- }
-
- public void setProjectionMatrix(Mat4f projectionMatrix)
- {
- this.inverseMvmProjMatrix = new Mat4f(projectionMatrix);
- this.inverseMvmProjMatrix.invert();
- }
-
-
-
- //========//
- // render //
- //========//
-
- @Override
- protected void onRender()
- {
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.frameBuffer);
- GLMC.disableScissorTest();
- GLMC.disableDepthTest();
- GLMC.disableBlend();
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(LodRenderer.INSTANCE.getActiveDepthTextureId());
- GL32.glUniform1i(this.uDepthMap, 0);
-
- // this is necessary for MC 1.16 (IE Legacy OpenGL)
- // otherwise the framebuffer isn't cleared correctly and the fog smears across the screen
- if (MC_RENDER.runningLegacyOpenGL())
- {
- // in another part of the DH code we set the fog color to opaque, here it needs to be transparent
- float[] clearColorValues = new float[4];
- GL32.glGetFloatv(GL32.GL_COLOR_CLEAR_VALUE, clearColorValues);
- GL32.glClearColor(clearColorValues[0], clearColorValues[1], clearColorValues[2], 0.0f);
-
- GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
- }
-
-
- ScreenQuad.INSTANCE.render();
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOApplyShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOApplyShader.java
deleted file mode 100644
index e2861d8cc..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOApplyShader.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
-import com.seibel.distanthorizons.core.render.renderer.SSAORenderer;
-import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
-import com.seibel.distanthorizons.core.util.RenderUtil;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import org.lwjgl.opengl.GL32;
-
-/**
- * Draws the SSAO texture onto DH's FrameBuffer.
- *
- * See Also:
- * {@link SSAORenderer} - Parent to this shader.
- * {@link SSAOShader} - draws the SSAO texture.
- */
-public class SSAOApplyShader extends AbstractShaderRenderer
-{
- public static SSAOApplyShader INSTANCE = new SSAOApplyShader();
-
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- public int ssaoTexture;
-
- // uniforms
- public int gSSAOMapUniform;
- public int gDepthMapUniform;
- public int gViewSizeUniform;
- public int gBlurRadiusUniform;
- public int gNearUniform;
- public int gFarUniform;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- @Override
- public void onInit()
- {
- this.shader = new ShaderProgram(
- "shaders/quadApply.vert",
- "shaders/ssao/apply.frag",
- "vPosition"
- );
-
- // uniform setup
- this.gSSAOMapUniform = this.shader.getUniformLocation("gSSAOMap");
- this.gDepthMapUniform = this.shader.getUniformLocation("gDepthMap");
- this.gViewSizeUniform = this.shader.tryGetUniformLocation("gViewSize");
- this.gBlurRadiusUniform = this.shader.tryGetUniformLocation("gBlurRadius");
- this.gNearUniform = this.shader.tryGetUniformLocation("gNear");
- this.gFarUniform = this.shader.tryGetUniformLocation("gFar");
- }
-
-
-
- //=============//
- // render prep //
- //=============//
-
- @Override
- protected void onApplyUniforms(float partialTicks)
- {
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(LodRenderer.INSTANCE.getActiveDepthTextureId());
- GL32.glUniform1i(this.gDepthMapUniform, 0);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE1);
- GLMC.glBindTexture(this.ssaoTexture);
- GL32.glUniform1i(this.gSSAOMapUniform, 1);
-
- GL32.glUniform1i(this.gBlurRadiusUniform, 2);
-
- if (this.gViewSizeUniform >= 0)
- {
- GL32.glUniform2f(this.gViewSizeUniform,
- MC_RENDER.getTargetFramebufferViewportWidth(),
- MC_RENDER.getTargetFramebufferViewportHeight());
- }
-
- if (this.gNearUniform >= 0)
- {
- GL32.glUniform1f(this.gNearUniform,
- RenderUtil.getNearClipPlaneInBlocks());
- }
-
- if (this.gFarUniform >= 0)
- {
- float farClipPlane = RenderUtil.getFarClipPlaneDistanceInBlocks();
- GL32.glUniform1f(this.gFarUniform, farClipPlane);
- }
- }
-
-
-
- //========//
- // render //
- //========//
-
- @Override
- protected void onRender()
- {
- GLMC.enableBlend();
- GL32.glBlendEquation(GL32.GL_FUNC_ADD);
- GLMC.glBlendFuncSeparate(GL32.GL_ZERO, GL32.GL_SRC_ALPHA, GL32.GL_ZERO, GL32.GL_ONE);
-
- // Depth testing must be disabled otherwise this application shader won't apply anything.
- // setting this isn't necessary in vanilla, but some mods may change this, requiring it to be set manually,
- // it should be automatically restored after rendering is complete.
- GLMC.disableDepthTest();
-
- // apply the rendered SSAO to the LODs
- GLMC.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, SSAOShader.INSTANCE.frameBuffer);
- GLMC.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, LodRenderer.INSTANCE.getActiveFramebufferId());
-
-
- ScreenQuad.INSTANCE.render();
-
- }
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java
deleted file mode 100644
index 3327f9e56..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
-import com.seibel.distanthorizons.core.render.renderer.SSAORenderer;
-import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
-import com.seibel.distanthorizons.core.util.NumberUtil;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.coreapi.util.MathUtil;
-import org.lwjgl.opengl.GL32;
-
-/**
- * Draws the SSAO to a texture.
- *
- * See Also:
- * {@link SSAORenderer} - Parent to this shader.
- * {@link SSAOApplyShader} - draws the SSAO texture to DH's FrameBuffer.
- */
-public class SSAOShader extends AbstractShaderRenderer
-{
- public static SSAOShader INSTANCE = new SSAOShader();
-
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- public int frameBuffer;
-
- private Mat4f projection;
- private Mat4f invertedProjection;
-
-
- // uniforms
- public int uProj;
- public int uInvProj;
- public int uSampleCount;
- public int uRadius;
- public int uStrength;
- public int uMinLight;
- public int uBias;
- public int uDepthMap;
- public int uFadeDistanceInBlocks;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- @Override
- public void onInit()
- {
- this.shader = new ShaderProgram(
- "shaders/quadApply.vert",
- "shaders/ssao/ao.frag",
- "vPosition"
- );
-
- // uniform setup
- this.uProj = this.shader.getUniformLocation("uProj");
- this.uInvProj = this.shader.getUniformLocation("uInvProj");
- this.uSampleCount = this.shader.getUniformLocation("uSampleCount");
- this.uRadius = this.shader.getUniformLocation("uRadius");
- this.uStrength = this.shader.getUniformLocation("uStrength");
- this.uMinLight = this.shader.getUniformLocation("uMinLight");
- this.uBias = this.shader.getUniformLocation("uBias");
- this.uDepthMap = this.shader.getUniformLocation("uDepthMap");
- this.uFadeDistanceInBlocks = this.shader.getUniformLocation("uFadeDistanceInBlocks");
- }
-
-
-
- //=============//
- // render prep //
- //=============//
-
- public void setProjectionMatrix(Mat4f projectionMatrix)
- {
- this.projection = projectionMatrix;
-
- this.invertedProjection = new Mat4f(projectionMatrix);
- this.invertedProjection.invert();
- }
-
- @Override
- protected void onApplyUniforms(float partialTicks)
- {
- this.shader.setUniform(this.uProj, this.projection);
-
- this.shader.setUniform(this.uInvProj, this.invertedProjection);
-
- this.shader.setUniform(this.uSampleCount, 6);
- this.shader.setUniform(this.uRadius, 4.0f);
- this.shader.setUniform(this.uStrength, 0.2f);
- this.shader.setUniform(this.uMinLight, 0.25f);
- this.shader.setUniform(this.uBias, 0.02f);
- this.shader.setUniform(this.uFadeDistanceInBlocks, 1_600.0f);
-
- GL32.glUniform1i(this.uDepthMap, 0);
-
- }
-
-
-
- //========//
- // render //
- //========//
-
- @Override
- protected void onRender()
- {
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.frameBuffer);
- GLMC.disableScissorTest();
- GLMC.disableDepthTest();
- GLMC.disableBlend();
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(LodRenderer.INSTANCE.getActiveDepthTextureId());
-
- ScreenQuad.INSTANCE.render();
- }
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/VanillaFadeShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/VanillaFadeShader.java
deleted file mode 100644
index 028eb8088..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/VanillaFadeShader.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.renderer.shaders;
-
-import com.seibel.distanthorizons.core.config.Config;
-import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
-import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
-import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
-import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
-import com.seibel.distanthorizons.core.util.RenderUtil;
-import com.seibel.distanthorizons.core.util.math.Mat4f;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
-import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
-import org.lwjgl.opengl.GL32;
-
-public class VanillaFadeShader extends AbstractShaderRenderer
-{
- public static VanillaFadeShader INSTANCE = new VanillaFadeShader();
-
- private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
- private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
-
-
- public int frameBuffer = -1;
-
- private Mat4f inverseMcMvmProjMatrix;
- private Mat4f inverseDhMvmProjMatrix;
- private float levelMaxHeight;
-
-
- // Uniforms
- public int uMcDepthTexture = -1;
- public int uDhDepthTexture = -1;
- public int uCombinedMcDhColorTexture = -1;
- public int uDhColorTexture = -1;
-
- /** Inverted Model View Projection matrix */
- public int uDhInvMvmProj = -1;
- public int uMcInvMvmProj = -1;
-
- public int uStartFadeBlockDistance = -1;
- public int uEndFadeBlockDistance = -1;
- public int uMaxLevelHeight = -1;
-
- public int uOnlyRenderLods = -1;
-
-
-
- //=============//
- // constructor //
- //=============//
-
- public VanillaFadeShader() { }
-
- @Override
- public void onInit()
- {
- this.shader = new ShaderProgram(
- "shaders/quadApply.vert",
- "shaders/fade/vanillaFade.frag",
- "vPosition"
- );
-
- // all uniforms should be tryGet...
- // because disabling fade can cause the GLSL to optimize out most (if not all) uniforms
-
- // near fade
- this.uDhInvMvmProj = this.shader.tryGetUniformLocation("uDhInvMvmProj");
- this.uMcInvMvmProj = this.shader.tryGetUniformLocation("uMcInvMvmProj");
-
- this.uMcDepthTexture = this.shader.tryGetUniformLocation("uMcDepthTexture");
- this.uDhDepthTexture = this.shader.tryGetUniformLocation("uDhDepthTexture");
- this.uCombinedMcDhColorTexture = this.shader.tryGetUniformLocation("uCombinedMcDhColorTexture");
- this.uDhColorTexture = this.shader.tryGetUniformLocation("uDhColorTexture");
-
- this.uStartFadeBlockDistance = this.shader.tryGetUniformLocation("uStartFadeBlockDistance");
- this.uEndFadeBlockDistance = this.shader.tryGetUniformLocation("uEndFadeBlockDistance");
- this.uMaxLevelHeight = this.shader.tryGetUniformLocation("uMaxLevelHeight");
-
- this.uOnlyRenderLods = this.shader.tryGetUniformLocation("uOnlyRenderLods");
-
- }
-
-
-
- //=============//
- // render prep //
- //=============//
-
- @Override
- protected void onApplyUniforms(float partialTicks)
- {
- this.shader.setUniform(this.uMcInvMvmProj, this.inverseMcMvmProjMatrix);
- this.shader.setUniform(this.uDhInvMvmProj, this.inverseDhMvmProjMatrix);
-
-
- float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocks();
- // this added value prevents the near clip plane and discard circle from touching, which looks bad
- dhNearClipDistance += 16f;
-
- // measured in blocks
- // these multipliers in James' tests should provide a fairly smooth transition
- // without having underdraw issues
- float fadeStartDistance = dhNearClipDistance * 1.5f;
- float fadeEndDistance = dhNearClipDistance * 1.9f;
-
- this.shader.setUniform(this.uStartFadeBlockDistance, fadeStartDistance);
- this.shader.setUniform(this.uEndFadeBlockDistance, fadeEndDistance);
-
- this.shader.setUniform(this.uMaxLevelHeight, this.levelMaxHeight);
-
- this.shader.setUniform(this.uOnlyRenderLods, Config.Client.Advanced.Debugging.lodOnlyMode.get());
- }
-
- public void setProjectionMatrix(Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix)
- {
- Mat4f inverseMcModelViewProjectionMatrix = new Mat4f(mcProjectionMatrix);
- inverseMcModelViewProjectionMatrix.multiply(mcModelViewMatrix);
- inverseMcModelViewProjectionMatrix.invert();
- this.inverseMcMvmProjMatrix = inverseMcModelViewProjectionMatrix;
-
-
- Mat4f dhProjectionMatrix = RenderUtil.createLodProjectionMatrix(mcProjectionMatrix);
- Mat4f dhModelViewMatrix = RenderUtil.createLodModelViewMatrix(mcModelViewMatrix);
-
- Mat4f inverseDhModelViewProjectionMatrix = new Mat4f(dhProjectionMatrix);
- inverseDhModelViewProjectionMatrix.multiply(dhModelViewMatrix);
- inverseDhModelViewProjectionMatrix.invert();
- this.inverseDhMvmProjMatrix = inverseDhModelViewProjectionMatrix;
- }
- public void setLevelMaxHeight(int levelMaxHeight) { this.levelMaxHeight = levelMaxHeight; }
-
-
-
- //========//
- // render //
- //========//
-
- @Override
- protected void onRender()
- {
- int depthTextureId = LodRenderer.INSTANCE.getActiveDepthTextureId();
- int colorTextureId = LodRenderer.INSTANCE.getActiveColorTextureId();
-
- if (depthTextureId == -1
- || colorTextureId == -1)
- {
- // the renderer is currently being re-built and/or inactive,
- // we don't need to/can't render fading
- return;
- }
-
-
-
- GLMC.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.frameBuffer);
- GLMC.disableScissorTest();
- GLMC.disableDepthTest();
- GLMC.disableBlend();
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE0);
- GLMC.glBindTexture(MC_RENDER.getDepthTextureId());
- GL32.glUniform1i(this.uMcDepthTexture, 0);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE1);
- GLMC.glBindTexture(depthTextureId);
- GL32.glUniform1i(this.uDhDepthTexture, 1);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE2);
- GLMC.glBindTexture(MC_RENDER.getColorTextureId());
- GL32.glUniform1i(this.uCombinedMcDhColorTexture, 2);
-
- GLMC.glActiveTexture(GL32.GL_TEXTURE3);
- GLMC.glBindTexture(colorTextureId);
- GL32.glUniform1i(this.uDhColorTexture, 3);
-
-
- ScreenQuad.INSTANCE.render();
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/LodVertexFormat.java b/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/LodVertexFormat.java
deleted file mode 100644
index 919ac68d9..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/LodVertexFormat.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.vertexFormat;
-
-import java.util.stream.Collectors;
-
-import com.google.common.collect.ImmutableList;
-
-import it.unimi.dsi.fastutil.ints.IntArrayList;
-import it.unimi.dsi.fastutil.ints.IntList;
-
-/**
- * This is used to represent a single vertex
- * stored in GPU memory,
- *
- * A (almost) exact copy of Minecraft's
- * VertexFormat class, several methods
- * were commented out since we didn't need them.
- *
- * @author James Seibel
- * @version 12-9-2021
- */
-public class LodVertexFormat
-{
- private final ImmutableList elements;
- private final IntList offsets = new IntArrayList();
- private final int byteSize;
-
- public LodVertexFormat(ImmutableList elementList)
- {
- this.elements = elementList;
- int i = 0;
-
- for (LodVertexFormatElement LodVertexFormatElement : elementList)
- {
- this.offsets.add(i);
- i += LodVertexFormatElement.getByteSize();
- }
-
- this.byteSize = i;
- }
-
- public int getByteSize()
- {
- return this.byteSize;
- }
-
- public ImmutableList getElements()
- {
- return this.elements;
- }
-
-
- // Forge added method
- public int getOffset(int index)
- {
- return offsets.getInt(index);
- }
-
-
-
- @Override
- public String toString()
- {
- return "format: " + this.elements.size() + " elements: " + this.elements.stream().map(Object::toString).collect(Collectors.joining(" "));
- }
-
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- else if (obj != null && this.getClass() == obj.getClass())
- {
- LodVertexFormat vertexFormat = (LodVertexFormat) obj;
- return this.byteSize == vertexFormat.byteSize && this.elements.equals(vertexFormat.elements);
- }
- else
- {
- return false;
- }
- }
-
- @Override
- public int hashCode()
- {
- return this.elements.hashCode();
- }
-
-
-
-
-
-
-
- /* not currently needed setupBufferState()
- public void setupBufferState(long p_227892_1_)
- {
- if (!RenderSystem.isOnRenderThread())
- {
- RenderSystem.recordRenderCall(() ->
- {
- this.setupBufferState(p_227892_1_);
- });
- }
- else
- {
- int i = this.getVertexSize();
- List list = this.getElements();
-
- for (int j = 0; j < list.size(); ++j)
- {
- list.get(j).setupBufferState(p_227892_1_ + this.offsets.getInt(j), i);
- }
-
- }
- }
- */
-
- /* not currently needed clearBufferState()
- public void clearBufferState()
- {
- if (!RenderSystem.isOnRenderThread())
- {
- RenderSystem.recordRenderCall(this::clearBufferState);
- }
- else
- {
- for (LodVertexFormatElement LodVertexFormatElement : this.getElements())
- {
- LodVertexFormatElement.clearBufferState();
- }
-
- }
- }
- */
-
-
- /* not currently needed has-Position/Normal/Color/UV
- public boolean hasPosition()
- {
- return elements.stream().anyMatch(e -> e.getUsage() == LodVertexFormatElement.Usage.POSITION);
- }
-
- public boolean hasNormal()
- {
- return elements.stream().anyMatch(e -> e.getUsage() == LodVertexFormatElement.Usage.NORMAL);
- }
-
- public boolean hasColor()
- {
- return elements.stream().anyMatch(e -> e.getUsage() == LodVertexFormatElement.Usage.COLOR);
- }
-
- public boolean hasUV(int which)
- {
- return elements.stream().anyMatch(e -> e.getUsage() == LodVertexFormatElement.Usage.UV && e.getIndex() == which);
- }
- */
-
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/LodVertexFormatElement.java b/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/LodVertexFormatElement.java
deleted file mode 100644
index 16d843f7a..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/LodVertexFormatElement.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.vertexFormat;
-
-import org.lwjgl.opengl.GL32;
-
-/**
- * This object is used to build LodVertexFormats.
- *
- * A (almost) exact copy of Minecraft's
- * VertexFormatElement class.
- * A number of things were removed from the original
- * object since we didn't need them, specifically "usage".
- *
- * @author James Seibel
- * @version 11-13-2021
- */
-public class LodVertexFormatElement
-{
- private final LodVertexFormatElement.DataType dataType;
- /** James isn't sure what index is for */
- private final int index;
- private final int count;
- private final int byteSize;
- private final boolean isPadding;
-
- public LodVertexFormatElement(int newIndex, LodVertexFormatElement.DataType newType, int newCount, boolean isPadding)
- {
- this.dataType = newType;
- this.index = newIndex;
- this.count = newCount;
- this.byteSize = newType.getSize() * this.count;
- this.isPadding = isPadding;
- }
-
- public final boolean getIsPadding()
- {
- return isPadding;
- }
-
- public final LodVertexFormatElement.DataType getType()
- {
- return this.dataType;
- }
-
- public final int getIndex()
- {
- return this.index;
- }
-
- public final int getByteSize()
- {
- return this.byteSize;
- }
-
- // added by Forge
- public int getElementCount()
- {
- return count;
- }
-
-
-
- public enum DataType
- {
- FLOAT(4, "Float", GL32.GL_FLOAT),
- UBYTE(1, "Unsigned Byte", GL32.GL_UNSIGNED_BYTE),
- BYTE(1, "Byte", GL32.GL_BYTE),
- USHORT(2, "Unsigned Short", GL32.GL_UNSIGNED_SHORT),
- SHORT(2, "Short", GL32.GL_SHORT),
- UINT(4, "Unsigned Int", GL32.GL_UNSIGNED_INT),
- INT(4, "Int", GL32.GL_INT);
-
- private final int size;
- private final String name;
- private final int glType;
-
- DataType(int sizeInBytes, String newName, int openGlDataType)
- {
- this.size = sizeInBytes;
- this.name = newName;
- this.glType = openGlDataType;
- }
-
- public int getSize()
- {
- return this.size;
- }
-
- public String getName()
- {
- return this.name;
- }
-
- public int getGlType()
- {
- return this.glType;
- }
- }
-
-
-
-
- @Override
- public int hashCode()
- {
- int i = this.dataType.hashCode();
- i = 31 * i + this.index;
- return 31 * i + this.count;
- }
-
- @Override
- public String toString()
- {
- return this.count + "," + this.dataType.getName();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- else if (obj != null && this.getClass() == obj.getClass())
- {
- LodVertexFormatElement LodVertexFormatElement = (LodVertexFormatElement) obj;
- if (this.count != LodVertexFormatElement.count)
- {
- return false;
- }
- else if (this.index != LodVertexFormatElement.index)
- {
- return false;
- }
- else if (this.dataType != LodVertexFormatElement.dataType)
- {
- return false;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
-
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/VertexFormats.java b/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/VertexFormats.java
deleted file mode 100644
index 8d6850734..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/render/vertexFormat/VertexFormats.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.render.vertexFormat;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * A (almost) exact copy of MC's
- * DefaultVertexFormats class.
- */
-public class VertexFormats
-{
- public static final LodVertexFormatElement ELEMENT_POSITION = new LodVertexFormatElement(3, LodVertexFormatElement.DataType.USHORT, 3, false);
- public static final LodVertexFormatElement ELEMENT_COLOR = new LodVertexFormatElement(0, LodVertexFormatElement.DataType.UBYTE, 4, false);
- public static final LodVertexFormatElement ELEMENT_BYTE_PADDING = new LodVertexFormatElement(0, LodVertexFormatElement.DataType.BYTE, 1, true);
-
- public static final LodVertexFormatElement ELEMENT_LIGHT = new LodVertexFormatElement(0, LodVertexFormatElement.DataType.UBYTE, 1, false);
- public static final LodVertexFormatElement ELEMENT_IRIS_MATERIAL_INDEX = new LodVertexFormatElement(0, LodVertexFormatElement.DataType.BYTE, 1, false);
- public static final LodVertexFormatElement ELEMENT_IRIS_NORMAL_INDEX = new LodVertexFormatElement(0, LodVertexFormatElement.DataType.BYTE, 1, false);
-
-
- public static final LodVertexFormat POSITION_COLOR_BLOCK_LIGHT_SKY_LIGHT_MATERIAL_ID_NORMAL_INDEX = new LodVertexFormat(ImmutableList.builder()
- .add(ELEMENT_POSITION)
- .add(ELEMENT_BYTE_PADDING)
- .add(ELEMENT_LIGHT)
- .add(ELEMENT_COLOR)
- .add(ELEMENT_IRIS_MATERIAL_INDEX)
- .add(ELEMENT_IRIS_NORMAL_INDEX)
- .add(ELEMENT_BYTE_PADDING)
- .add(ELEMENT_BYTE_PADDING) // padding is to make sure the format is a multiple of 4
- .build());
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java
index 92516bc46..5554fc005 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/util/LodUtil.java
@@ -20,8 +20,6 @@
package com.seibel.distanthorizons.core.util;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
-import com.seibel.distanthorizons.core.render.vertexFormat.VertexFormats;
-import com.seibel.distanthorizons.core.render.vertexFormat.LodVertexFormat;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.distanthorizons.core.logging.DhLogger;
@@ -108,9 +106,6 @@ public class LodUtil
*/
public static final int MAX_ALLOCATABLE_DIRECT_MEMORY = 64 * 1024 * 1024;
- /** the format of data stored in the GPU buffers */
- public static final LodVertexFormat DH_VERTEX_FORMAT = VertexFormats.POSITION_COLOR_BLOCK_LIGHT_SKY_LIGHT_MATERIAL_ID_NORMAL_INDEX;
-
//=========//
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java
index f05d6f9f1..bc9bc7799 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.core.util;
+import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
@@ -64,7 +65,7 @@ public class RenderUtil
*
* @param mcProjMat Minecraft's current projection matrix
*/
- public static Mat4f createLodProjectionMatrix(Mat4f mcProjMat)
+ public static Mat4f createLodProjectionMatrix(DhApiMat4f mcProjMat)
{
// in James' testing a near clip plane distance of 2 blocks is enough to allow the fragment
// culling to take effect instead of seeing the near clip plane.
@@ -81,18 +82,18 @@ public class RenderUtil
float farClipDist = (float) RenderUtil.getFarClipPlaneDistanceInBlocks();
// Create a copy of the current matrix, so it won't be modified.
- Mat4f lodProj = mcProjMat.copy();
+ Mat4f lodProj = new Mat4f(mcProjMat);
// Set new far and near clip plane values.
lodProj.setClipPlanes(nearClipDist, farClipDist);
return lodProj;
}
/** create and return a new projection matrix based on MC's modelView and projection matrices */
- public static Mat4f createLodModelViewMatrix(Mat4f mcModelViewMat)
+ public static Mat4f createLodModelViewMatrix(DhApiMat4f mcModelViewMat)
{
// nothing beyond copying needs to be done to MC's MVM currently,
// this method is just here in case that changes in the future
- return mcModelViewMat.copy();
+ return new Mat4f(mcModelViewMat);
}
//endregion
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IVersionConstants.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IVersionConstants.java
index 37ebd5910..9c71c8071 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IVersionConstants.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IVersionConstants.java
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.core.wrapperInterfaces;
+import com.seibel.distanthorizons.api.enums.config.EDhApiRenderApi;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
/**
@@ -33,4 +34,6 @@ public interface IVersionConstants extends IBindable
{
String getMinecraftVersion();
+ EDhApiRenderApi getDefaultRenderingApi();
+
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IWrapperFactory.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IWrapperFactory.java
index 13da93aed..d5daec17d 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IWrapperFactory.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IWrapperFactory.java
@@ -23,6 +23,10 @@ import com.seibel.distanthorizons.api.interfaces.factories.IDhApiWrapperFactory;
import com.seibel.distanthorizons.core.level.IDhLevel;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.ILodContainerUniformBufferWrapper;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhGenericRenderer;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.worldGeneration.IBatchGeneratorEnvironmentWrapper;
@@ -30,7 +34,6 @@ import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindab
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import java.io.IOException;
-import java.util.HashSet;
/**
* This handles creating abstract wrapper objects.
@@ -102,4 +105,13 @@ public interface IWrapperFactory extends IDhApiWrapperFactory, IBindable
*/
IChunkWrapper createChunkWrapper(Object[] objectArray) throws ClassCastException;
+
+
+ IVertexBufferWrapper createVboWrapper(String name);
+ ILodContainerUniformBufferWrapper createLodContainerUniformWrapper();
+
+ IDhGenericObjectVertexBufferContainer createGenericObjectVboContainer();
+
+ IDhGenericRenderer createGenericRenderer();
+
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftClientWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftClientWrapper.java
index 6df688cf8..092b98d5d 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftClientWrapper.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftClientWrapper.java
@@ -19,18 +19,10 @@
package com.seibel.distanthorizons.core.wrapperInterfaces.minecraft;
-import java.util.ArrayList;
-import java.util.UUID;
-
-import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
-import com.seibel.distanthorizons.core.render.glObject.GLProxy;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
-import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
-import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
-import org.apache.logging.log4j.Level;
public interface IMinecraftClientWrapper extends IBindable
{
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftGLWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftGLWrapper.java
deleted file mode 100644
index f4201e4f8..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftGLWrapper.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General License for more details.
- *
- * You should have received a copy of the GNU Lesser General License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.wrapperInterfaces.minecraft;
-
-import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
-import org.lwjgl.opengl.GL32;
-
-import java.util.ArrayList;
-import java.util.UUID;
-
-/**
- * Used to sync GL state changes between DH and MC.
- * This is specifically important for other mods that change MC's rendering like Iris.
- */
-public interface IMinecraftGLWrapper extends IBindable
-{
-
- // scissor //
-
- /** @see GL32#GL_SCISSOR_TEST */
- void enableScissorTest();
- /** @see GL32#GL_SCISSOR_TEST */
- void disableScissorTest();
-
-
- // stencil //
-
- ///** @see GL32#GL_SCISSOR_TEST */
- //void enableScissorTest() { GlStateManager._enableScissorTest(); }
- ///** @see GL32#GL_SCISSOR_TEST */
- //void disableScissorTest() { GlStateManager._disableScissorTest(); }
-
-
- // depth //
-
- /** @see GL32#GL_DEPTH_TEST */
- void enableDepthTest();
- /** @see GL32#GL_DEPTH_TEST */
- void disableDepthTest();
-
- /** @see GL32#glDepthFunc(int) */
- void glDepthFunc(int func);
-
- /** @see GL32#glDepthMask(boolean) */
- void enableDepthMask();
- /** @see GL32#glDepthMask(boolean) */
- void disableDepthMask();
-
-
-
- // blending //
-
- /** @see GL32#GL_BLEND */
- void enableBlend();
- /** @see GL32#GL_BLEND */
- void disableBlend();
-
- /** @see GL32#glBlendFunc */
- void glBlendFunc(int sfactor, int dfactor);
- /** @see GL32#glBlendFuncSeparate */
- void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dfactorAlpha);
-
-
- // frame buffers //
-
- /** @see GL32#glBindFramebuffer */
- void glBindFramebuffer(int target, int framebuffer);
-
-
- // buffers //
-
- /** @see GL32#glGenBuffers() */
- int glGenBuffers();
-
- /** @see GL32#glDeleteBuffers(int) */
- void glDeleteBuffers(int buffer);
-
-
-
- // culling //
-
- /** @see GL32#GL_CULL_FACE */
- void enableFaceCulling();
- /** @see GL32#GL_CULL_FACE */
- void disableFaceCulling();
-
-
- // textures //
-
- /** @see GL32#glGenTextures() */
- int glGenTextures();
- /** @see GL32#glDeleteTextures(int) */
- void glDeleteTextures(int texture);
-
- /** @see GL32#glActiveTexture(int) */
- void glActiveTexture(int textureId);
- /**
- * Only works for textures bound via this system.
- * Returns the bound {@link GL32#GL_TEXTURE_BINDING_2D}
- */
- int getActiveTexture();
-
- /**
- * Always binds to {@link GL32#GL_TEXTURE_2D}
- * @see GL32#glBindTexture(int, int)
- */
- void glBindTexture(int texture);
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/misc/ILightMapWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/misc/ILightMapWrapper.java
index a029bf1a9..06e237741 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/misc/ILightMapWrapper.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/misc/ILightMapWrapper.java
@@ -20,7 +20,6 @@
package com.seibel.distanthorizons.core.wrapperInterfaces.misc;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
-import org.lwjgl.opengl.GL32;
/**
* @author James Seibel
@@ -28,13 +27,5 @@ import org.lwjgl.opengl.GL32;
*/
public interface ILightMapWrapper extends IBindable
{
- /**
- * which texture index IE 0,1,2... the lightmap will be bound to.
- * Related to but different from {@link GL32#GL_TEXTURE0}.
- */
- int BOUND_INDEX = 0;
-
- void bind();
- void unbind();
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/AbstractDhRenderApiDefinition.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/AbstractDhRenderApiDefinition.java
new file mode 100644
index 000000000..1d77eb5dd
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/AbstractDhRenderApiDefinition.java
@@ -0,0 +1,78 @@
+package com.seibel.distanthorizons.core.wrapperInterfaces.render;
+
+import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
+import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.ILodContainerUniformBufferWrapper;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
+import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.*;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+public abstract class AbstractDhRenderApiDefinition implements IBindable
+{
+ //=========//
+ // getters //
+ //=========//
+ //region
+
+ /** Used for debugging */
+ public abstract String getApiName();
+
+ //endregion
+
+
+
+ //============//
+ // singletons //
+ //============//
+ //region
+
+ public abstract IDhMetaRenderer getMetaRenderer();
+ public abstract IDhTerrainRenderer getTerrainRenderer();
+ public abstract IDhSsaoRenderer getSsaoRenderer();
+ public abstract IDhFogRenderer getFogRenderer();
+ public abstract IDhFarFadeRenderer getFarFadeRenderer();
+ public abstract AbstractDebugWireframeRenderer getDebugWireframeRenderer();
+ public abstract IDhVanillaFadeRenderer getVanillaFadeRenderer();
+ public abstract IDhTestTriangleRenderer getTestTriangleRenderer();
+
+ public void bindRenderers()
+ {
+ SingletonInjector.INSTANCE.bind(AbstractDhRenderApiDefinition.class, this);
+
+ SingletonInjector.INSTANCE.bind(IDhMetaRenderer.class, this.getMetaRenderer());
+ SingletonInjector.INSTANCE.bind(IDhTerrainRenderer.class, this.getTerrainRenderer());
+ SingletonInjector.INSTANCE.bind(IDhSsaoRenderer.class, this.getSsaoRenderer());
+ SingletonInjector.INSTANCE.bind(IDhFogRenderer.class, this.getFogRenderer());
+ SingletonInjector.INSTANCE.bind(IDhFarFadeRenderer.class, this.getFarFadeRenderer());
+ SingletonInjector.INSTANCE.bind(AbstractDebugWireframeRenderer.class, this.getDebugWireframeRenderer());
+ SingletonInjector.INSTANCE.bind(IDhVanillaFadeRenderer.class, this.getVanillaFadeRenderer());
+ SingletonInjector.INSTANCE.bind(IDhTestTriangleRenderer.class, this.getTestTriangleRenderer());
+ }
+
+ //endregion
+
+
+
+ //===========//
+ // factories //
+ //===========//
+ //region
+
+ // these methods are used by WrapperFactory
+
+ /**
+ * Generic renderers are created for each level they're used in
+ * so we can't just define a single instance.
+ */
+ public abstract IDhGenericRenderer createGenericRenderer();
+
+ public abstract IVertexBufferWrapper createVboWrapper(String name);
+ public abstract ILodContainerUniformBufferWrapper createLodContainerUniformWrapper();
+ public abstract IDhGenericObjectVertexBufferContainer createGenericVboContainer();
+
+ //endregion
+
+
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IDhGenericObjectVertexBufferContainer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IDhGenericObjectVertexBufferContainer.java
new file mode 100644
index 000000000..9a940e7b3
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IDhGenericObjectVertexBufferContainer.java
@@ -0,0 +1,40 @@
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.objects;
+
+import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
+
+import java.util.List;
+
+public interface IDhGenericObjectVertexBufferContainer extends AutoCloseable
+{
+ void uploadDataToGpu();
+
+ void updateVertexData(List uploadBoxList);
+
+ EState getState();
+ void setState(EState state);
+
+ @Override
+ void close();
+
+
+
+ //================//
+ // helper classes //
+ //================//
+ //region
+
+ enum EState
+ {
+ NEW,
+ UPDATING_DATA,
+ READY_TO_UPLOAD,
+ RENDER,
+
+ ERROR,
+ }
+
+ //endregion
+
+
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/ILodContainerUniformBufferWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/ILodContainerUniformBufferWrapper.java
new file mode 100644
index 000000000..b6f0ed0ff
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/ILodContainerUniformBufferWrapper.java
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.objects;
+
+import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
+
+/**
+ * @see LodBufferContainer
+ */
+public interface ILodContainerUniformBufferWrapper extends IUniformBufferWrapper
+{
+
+ void createUniformData(LodBufferContainer bufferContainer);
+
+ void tryUpload();
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IUniformBufferWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IUniformBufferWrapper.java
new file mode 100644
index 000000000..3553675da
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IUniformBufferWrapper.java
@@ -0,0 +1,31 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.objects;
+
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+public interface IUniformBufferWrapper extends IBindable, AutoCloseable
+{
+ void upload();
+
+ @Override
+ void close();
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IVertexBufferWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IVertexBufferWrapper.java
new file mode 100644
index 000000000..b7b65b3e4
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/objects/IVertexBufferWrapper.java
@@ -0,0 +1,33 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.objects;
+
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+import java.nio.ByteBuffer;
+
+public interface IVertexBufferWrapper extends IBindable, AutoCloseable
+{
+ void upload(ByteBuffer buffer, int vertexCount);
+
+ @Override
+ void close();
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhFarFadeRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhFarFadeRenderer.java
new file mode 100644
index 000000000..7e0b4c23f
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhFarFadeRenderer.java
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass;
+
+import com.seibel.distanthorizons.core.render.RenderParams;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+public interface IDhFarFadeRenderer extends IBindable
+{
+
+ void render(RenderParams renderParams);
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhFogRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhFogRenderer.java
new file mode 100644
index 000000000..f3420ab9a
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhFogRenderer.java
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass;
+
+import com.seibel.distanthorizons.core.render.RenderParams;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+public interface IDhFogRenderer extends IBindable
+{
+
+ void render(RenderParams renderParams);
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhGenericRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhGenericRenderer.java
new file mode 100644
index 000000000..56f6cc6e5
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhGenericRenderer.java
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass;
+
+import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderRegister;
+import com.seibel.distanthorizons.core.render.RenderParams;
+import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
+
+public interface IDhGenericRenderer extends IDhApiCustomRenderRegister
+{
+ void render(RenderParams renderEventParam, IProfilerWrapper profiler, boolean renderingWithSsao);
+
+ String getVboRenderDebugMenuString();
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhMetaRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhMetaRenderer.java
new file mode 100644
index 000000000..9bae6f931
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhMetaRenderer.java
@@ -0,0 +1,17 @@
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass;
+
+import com.seibel.distanthorizons.core.render.RenderParams;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+/**
+ * Contains anything that's shared between
+ * render passes or doesn't cleanly fit into another render pass interface.
+ */
+public interface IDhMetaRenderer extends IBindable
+{
+ void runRenderPassSetup(RenderParams renderParams);
+ void runRenderPassCleanup(RenderParams renderParams);
+ void applyToMcTexture(RenderParams renderParams);
+ void clearDhDepthAndColorTextures(RenderParams renderParams);
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhSsaoRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhSsaoRenderer.java
new file mode 100644
index 000000000..f51e0e5ee
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhSsaoRenderer.java
@@ -0,0 +1,31 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass;
+
+import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
+import com.seibel.distanthorizons.core.render.RenderParams;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+public interface IDhSsaoRenderer extends IBindable
+{
+
+ void render(RenderParams renderParams);
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhTerrainRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhTerrainRenderer.java
new file mode 100644
index 000000000..e9b257f4e
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhTerrainRenderer.java
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass;
+
+import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
+import com.seibel.distanthorizons.core.render.RenderParams;
+import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
+import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+public interface IDhTerrainRenderer extends IBindable
+{
+ void render(
+ RenderParams renderEventParam, boolean opaquePass,
+ SortedArraySet bufferContainers,
+ IProfilerWrapper profiler);
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhTestTriangleRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhTestTriangleRenderer.java
new file mode 100644
index 000000000..ea2392432
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhTestTriangleRenderer.java
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass;
+
+import com.seibel.distanthorizons.core.render.RenderParams;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+public interface IDhTestTriangleRenderer extends IBindable
+{
+
+ void render(RenderParams renderParams);
+
+}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhVanillaFadeRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhVanillaFadeRenderer.java
new file mode 100644
index 000000000..7bb325a0c
--- /dev/null
+++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/render/renderPass/IDhVanillaFadeRenderer.java
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the Distant Horizons mod
+ * licensed under the GNU LGPL v3 License.
+ *
+ * Copyright (C) 2020 James Seibel
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass;
+
+import com.seibel.distanthorizons.core.render.RenderParams;
+import com.seibel.distanthorizons.core.util.math.Mat4f;
+import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
+import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
+
+public interface IDhVanillaFadeRenderer extends IBindable
+{
+
+ void render(RenderParams renderParams);
+
+}
diff --git a/core/src/main/resources/assets/distanthorizons/lang/en_us.json b/core/src/main/resources/assets/distanthorizons/lang/en_us.json
index 9ec5075d0..4a885828b 100644
--- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json
+++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json
@@ -415,7 +415,11 @@
"Ignored Dimension CSV",
"distanthorizons.config.client.advanced.graphics.experimental.ignoredDimensionCsv.@tooltip":
"A comma separated list of dimension resource locations where DH won't render. Example: \"minecraft:the_nether,minecraft:the_end\" \n\nNote: \nSome DH settings will be disabled and/or changed to improve \nvisuals when DH rendering is disabled.",
-
+ "distanthorizons.config.client.advanced.graphics.experimental.renderingApi":
+ "Rendering API",
+ "distanthorizons.config.client.advanced.graphics.experimental.renderingApi.@tooltip":
+ "Requires a restart to change.",
+
"distanthorizons.config.client.advanced.autoUpdater":
@@ -1040,7 +1044,7 @@
"distanthorizons.config.enum.EDhApiRendererMode.DEFAULT":
"Default",
"distanthorizons.config.enum.EDhApiRendererMode.DEBUG":
- "Debug",
+ "Debug Triangle",
"distanthorizons.config.enum.EDhApiRendererMode.DISABLED":
"Disabled",
@@ -1117,6 +1121,15 @@
"distanthorizons.config.enum.EDhApiGrassSideRendering.FADE_TO_DIRT":
"Fade To Dirt",
"distanthorizons.config.enum.EDhApiGrassSideRendering.AS_DIRT":
- "As Dirt"
+ "As Dirt",
+
+ "distanthorizons.config.enum.EDhApiRenderApi.AUTO":
+ "Auto",
+ "distanthorizons.config.enum.EDhApiRenderApi.OPEN_GL":
+ "OpenGL",
+ "distanthorizons.config.enum.EDhApiRenderApi.BLAZE_3D":
+ "Blaze3D"
+
+
}
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/apply/blaze/frag.fsh b/core/src/main/resources/assets/distanthorizons/shaders/apply/blaze/frag.fsh
new file mode 100644
index 000000000..2b0745aec
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/apply/blaze/frag.fsh
@@ -0,0 +1,27 @@
+#version 150 core
+
+in vec2 TexCoord;
+
+out vec4 fragColor;
+
+uniform sampler2D uSourceColorTexture;
+uniform sampler2D uSourceDepthTexture;
+
+// DH apply frag
+void main()
+{
+ fragColor = vec4(0.0);
+
+ // a fragment depth of "1" means the fragment wasn't drawn to,
+ // only update fragments that were drawn to
+ float fragmentDepth = texture(uSourceDepthTexture, TexCoord).r;
+ if (fragmentDepth != 1)
+ {
+ fragColor = texture(uSourceColorTexture, TexCoord);
+ }
+ else
+ {
+ // use the original MC texture if no LODs were drawn to this fragment
+ discard;
+ }
+}
\ No newline at end of file
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/apply/blaze/vert.vsh b/core/src/main/resources/assets/distanthorizons/shaders/apply/blaze/vert.vsh
new file mode 100644
index 000000000..f58a25234
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/apply/blaze/vert.vsh
@@ -0,0 +1,15 @@
+#version 150 core
+
+in vec2 vPosition;
+
+out vec2 TexCoord;
+
+/**
+ * This is specifically used by application shaders.
+ * IE post process or pixel transfer shaders, anything that is rendered using a single rectangle.
+ */
+void main()
+{
+ gl_Position = vec4(vPosition, 0.0, 1.0);
+ TexCoord = vPosition.xy * 0.5 + 0.5;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/copy/blaze/frag.fsh b/core/src/main/resources/assets/distanthorizons/shaders/copy/blaze/frag.fsh
new file mode 100644
index 000000000..9cbaf97f2
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/copy/blaze/frag.fsh
@@ -0,0 +1,13 @@
+#version 150 core
+
+in vec2 TexCoord;
+
+out vec4 fragColor;
+
+uniform sampler2D uCopyTexture;
+
+// DH copy frag
+void main()
+{
+ fragColor = texture(uCopyTexture, TexCoord);
+}
\ No newline at end of file
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/copy/blaze/vert.vsh b/core/src/main/resources/assets/distanthorizons/shaders/copy/blaze/vert.vsh
new file mode 100644
index 000000000..d9b009b3b
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/copy/blaze/vert.vsh
@@ -0,0 +1,12 @@
+#version 150 core
+
+in vec2 vPosition;
+
+out vec2 TexCoord;
+
+// DH copy
+void main()
+{
+ gl_Position = vec4(vPosition, 0.0, 1.0);
+ TexCoord = vPosition.xy * 0.5 + 0.5;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/debug/blaze/frag.fsh b/core/src/main/resources/assets/distanthorizons/shaders/debug/blaze/frag.fsh
new file mode 100644
index 000000000..253b92fd5
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/debug/blaze/frag.fsh
@@ -0,0 +1,14 @@
+#version 150 core
+
+layout (std140) uniform uniformBlock
+{
+ mat4 uTransform;
+ vec4 uColor;
+};
+
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = uColor;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/debug/blaze/vert.vsh b/core/src/main/resources/assets/distanthorizons/shaders/debug/blaze/vert.vsh
new file mode 100644
index 000000000..7ff5df869
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/debug/blaze/vert.vsh
@@ -0,0 +1,14 @@
+#version 150 core
+
+layout (std140) uniform uniformBlock
+{
+ mat4 uTransform;
+ vec4 uColor;
+};
+
+in vec3 vPosition;
+
+void main()
+{
+ gl_Position = uTransform * vec4(vPosition, 1.0);
+}
\ No newline at end of file
diff --git a/core/src/main/resources/shaders/debug/frag.frag b/core/src/main/resources/assets/distanthorizons/shaders/debug/gl/frag.frag
similarity index 100%
rename from core/src/main/resources/shaders/debug/frag.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/debug/gl/frag.frag
diff --git a/core/src/main/resources/shaders/debug/vert.vert b/core/src/main/resources/assets/distanthorizons/shaders/debug/gl/vert.vert
similarity index 100%
rename from core/src/main/resources/shaders/debug/vert.vert
rename to core/src/main/resources/assets/distanthorizons/shaders/debug/gl/vert.vert
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/dh_fade.fsh b/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/dh_fade.fsh
new file mode 100644
index 000000000..a88b324c5
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/dh_fade.fsh
@@ -0,0 +1,67 @@
+#version 150 core
+
+in vec2 TexCoord;
+
+out vec4 fragColor;
+
+layout (std140) uniform fragUniformBlock
+{
+ float uStartFadeBlockDistance;
+ float uEndFadeBlockDistance;
+
+ // inverted model view matrix and projection matrix
+ mat4 uDhInvMvmProj;
+};
+
+uniform sampler2D uMcColorTexture;
+uniform sampler2D uDhDepthTexture;
+uniform sampler2D uDhColorTexture;
+
+
+vec3 calcViewPosition(float fragmentDepth, mat4 invMvmProj)
+{
+ // normalized device coordinates
+ vec4 ndc = vec4(TexCoord.xy, fragmentDepth, 1.0);
+ ndc.xyz = ndc.xyz * 2.0 - 1.0;
+
+ vec4 eyeCoord = invMvmProj * ndc;
+ return eyeCoord.xyz / eyeCoord.w;
+}
+
+/**
+ * Used to fade out vanilla chunks so the transition
+ * between DH and vanilla is smoother.
+ */
+void main()
+{
+ // includes both the vanilla chunks as well as DH
+ vec4 combinedMcDhColor = texture(uMcColorTexture, TexCoord);
+ // just the DH render pass
+ vec4 dhColor = texture(uDhColorTexture, TexCoord);
+
+
+
+ // the DH texture will have white if nothing was written to that pixel.
+ if (dhColor == vec4(1))
+ {
+ // if not done vanilla clouds will render incorrectly at night
+ dhColor = combinedMcDhColor;
+ }
+
+
+ float dhFragmentDepth = texture(uDhDepthTexture, TexCoord).r;
+ vec3 dhVertexWorldPos = calcViewPosition(dhFragmentDepth, uDhInvMvmProj);
+ float dhFragmentDistance = length(dhVertexWorldPos.xzy);
+
+
+ float startFade = uEndFadeBlockDistance;
+ float endFade = uStartFadeBlockDistance;
+
+ // Smoothly transition between combinedMcDhColor and uDhColorTexture
+ // as the depth increases from the camera
+ float fadeStep = smoothstep(startFade, endFade, dhFragmentDistance);
+ fragColor = mix(combinedMcDhColor, dhColor, fadeStep);
+ fragColor.a = 1.0;
+
+}
+
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/vanilla_fade.fsh b/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/vanilla_fade.fsh
new file mode 100644
index 000000000..da8d123ae
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/vanilla_fade.fsh
@@ -0,0 +1,95 @@
+#version 150 core
+
+in vec2 TexCoord;
+
+out vec4 fragColor;
+
+uniform sampler2D uMcDepthTexture;
+uniform sampler2D uCombinedMcDhColorTexture;
+
+uniform sampler2D uDhDepthTexture;
+uniform sampler2D uDhColorTexture;
+
+layout (std140) uniform fragUniformBlock
+{
+ bool uOnlyRenderLods;
+
+ float uStartFadeBlockDistance;
+ float uEndFadeBlockDistance;
+ float uMaxLevelHeight;
+
+ // inverted model view matrix and projection matrix
+ mat4 uDhInvMvmProj;
+ mat4 uMcInvMvmProj;
+};
+
+
+
+vec3 calcViewPosition(float fragmentDepth, mat4 invMvmProj)
+{
+ // normalized device coordinates
+ vec4 ndc = vec4(TexCoord.xy, fragmentDepth, 1.0);
+ ndc.xyz = ndc.xyz * 2.0 - 1.0;
+
+ vec4 eyeCoord = invMvmProj * ndc;
+ return eyeCoord.xyz / eyeCoord.w;
+}
+
+/**
+ * Used to fade out vanilla chunks so the transition
+ * between DH and vanilla is smoother.
+ */
+void main()
+{
+ // includes both the vanilla chunks as well as DH
+ vec4 combinedMcDhColor = texture(uCombinedMcDhColorTexture, TexCoord);
+ // just the DH render pass
+ vec4 dhColor = texture(uDhColorTexture, TexCoord);
+
+ // completely remove the MC render pass to only show LODs
+ // useful for debugging/troubleshooting, but doesn't improve performance since MC is still rendering
+ if (uOnlyRenderLods)
+ {
+ fragColor = dhColor;
+ return;
+ }
+
+
+ // ignore anything that DH hasn't drawn to
+ // We don't use DH's depth here because it would prevent the fade from running before DH has loaded
+ if (dhColor == vec4(1))
+ {
+ // if not done vanilla clouds will render incorrectly at night
+ dhColor = combinedMcDhColor;
+ }
+
+ float mcFragmentDepth = texture(uMcDepthTexture, TexCoord).r;
+ float dhFragmentDepth = texture(uDhDepthTexture, TexCoord).r;
+ vec3 dhVertexWorldPos = calcViewPosition(dhFragmentDepth, uDhInvMvmProj);
+
+ // this is a work around to prevent MC clouds rendering behind DH clouds
+ if (dhVertexWorldPos.y > uMaxLevelHeight)
+ {
+ fragColor = vec4(combinedMcDhColor.rgb, 0.0);
+ }
+ // a fragment depth of "1" means the fragment wasn't drawn to,
+ // we only want to fade vanilla rendered objects, not to the sky or LODs
+ else if (mcFragmentDepth < 1.0)
+ {
+ // fade based on distance from the camera
+ vec3 mcVertexWorldPos = calcViewPosition(mcFragmentDepth, uMcInvMvmProj);
+ float mcFragmentDistance = length(mcVertexWorldPos.xzy);
+
+
+ // Smoothly transition between combinedMcDhColor and uDhColorTexture
+ // as the depth increases from the camera
+ float fadeStep = smoothstep(uStartFadeBlockDistance, uEndFadeBlockDistance, mcFragmentDistance);
+ fragColor = mix(combinedMcDhColor, dhColor, fadeStep);
+ fragColor.a = 1.0;
+ }
+ else
+ {
+ fragColor = vec4(combinedMcDhColor.rgb, 0.0);
+ }
+}
+
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/vert.vsh b/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/vert.vsh
new file mode 100644
index 000000000..d7f46cf36
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/fade/blaze/vert.vsh
@@ -0,0 +1,15 @@
+#version 150 core
+
+in vec2 vPosition;
+in vec4 vColor;
+
+out vec4 fColor;
+out vec2 TexCoord;
+
+// DH vert fade test
+void main()
+{
+ gl_Position = vec4(vPosition, 0.0, 1.0);
+ fColor = vec4(vPosition, 0.0, 1.0);
+ TexCoord = vPosition.xy * 0.5 + 0.5;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/shaders/fade/apply.frag b/core/src/main/resources/assets/distanthorizons/shaders/fade/gl/apply.frag
similarity index 100%
rename from core/src/main/resources/shaders/fade/apply.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/fade/gl/apply.frag
diff --git a/core/src/main/resources/shaders/fade/dhFade.frag b/core/src/main/resources/assets/distanthorizons/shaders/fade/gl/dhFade.frag
similarity index 100%
rename from core/src/main/resources/shaders/fade/dhFade.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/fade/gl/dhFade.frag
diff --git a/core/src/main/resources/shaders/fade/vanillaFade.frag b/core/src/main/resources/assets/distanthorizons/shaders/fade/gl/vanillaFade.frag
similarity index 100%
rename from core/src/main/resources/shaders/fade/vanillaFade.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/fade/gl/vanillaFade.frag
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/fog/blaze/frag.fsh b/core/src/main/resources/assets/distanthorizons/shaders/fog/blaze/frag.fsh
new file mode 100644
index 000000000..9b0614970
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/fog/blaze/frag.fsh
@@ -0,0 +1,299 @@
+#version 150 core
+
+in vec2 TexCoord;
+
+out vec4 fragColor;
+
+layout (std140) uniform fragUniformBlock
+{
+ // fog uniforms
+ vec4 uFogColor;
+ float uFogScale;
+ float uFogVerticalScale;
+ int uFogDebugMode;
+ int uFogFalloffType;
+
+ // fog config
+ float uFarFogStart;
+ float uFarFogLength;
+ float uFarFogMin;
+ float uFarFogRange;
+ float uFarFogDensity;
+
+ // height fog config
+ float uHeightFogStart;
+ float uHeightFogLength;
+ float uHeightFogMin;
+ float uHeightFogRange;
+ float uHeightFogDensity;
+
+ // ???
+ bool uHeightFogEnabled;
+ int uHeightFogFalloffType;
+ bool uHeightBasedOnCamera;
+ float uHeightFogBaseHeight;
+ bool uHeightFogAppliesUp;
+ bool uHeightFogAppliesDown;
+ bool uUseSphericalFog;
+ int uHeightFogMixingMode;
+ float uCameraBlockYPos;
+
+ // inverted model view matrix and projection matrix
+ mat4 uInvMvmProj;
+};
+
+uniform sampler2D uDhDepthTexture;
+
+
+
+//====================//
+// method definitions //
+//====================//
+
+vec3 calcViewPosition(float fragmentDepth);
+
+float getFarFogThickness(float dist);
+float getHeightFogThickness(float dist);
+float calculateHeightFogDepth(float worldYPos);
+float mixFogThickness(float far, float height);
+
+float linearFog(float worldDist, float fogStart, float fogLength, float fogMin, float fogRange);
+float exponentialFog(float x, float fogStart, float fogLength, float fogMin, float fogRange, float fogDensity);
+float exponentialSquaredFog(float x, float fogStart, float fogLength, float fogMin, float fogRange, float fogDensity);
+
+
+
+//======//
+// main //
+//======//
+
+/**
+ * Fragment shader for fog.
+ * This should be run last so it applies above other affects like Ambient Occlusioning
+ */
+void main()
+{
+ float fragmentDepth = texture(uDhDepthTexture, TexCoord).r;
+ fragColor = vec4(uFogColor.rgb, 0.0);
+
+ // a fragment depth of "1" means the fragment wasn't drawn to,
+ // we only want to apply Fog to LODs, not to the sky outside the LODs
+ if (fragmentDepth < 1.0)
+ {
+ int fogDebugMode = uFogDebugMode;
+ if (fogDebugMode == 0)
+ {
+ // render fog based on distance from the camera
+ vec3 vertexWorldPos = calcViewPosition(fragmentDepth);
+
+ float horizontalWorldDistance = length(vertexWorldPos.xz) * uFogScale;
+ float worldDistance = length(vertexWorldPos.xyz) * uFogScale;
+ float activeDistance = uUseSphericalFog ? worldDistance : horizontalWorldDistance;
+
+
+ // far fog
+ float farFogThickness = getFarFogThickness(activeDistance);
+
+ // height fog
+ float heightFogDepth = calculateHeightFogDepth(vertexWorldPos.y);
+ float heightFogThickness = getHeightFogThickness(heightFogDepth);
+
+ // combined fog
+ float mixedFogThickness = mixFogThickness(farFogThickness, heightFogThickness);
+ fragColor.a = clamp(mixedFogThickness, 0.0, 1.0);
+ }
+ else if (fogDebugMode == 1)
+ {
+ // test code
+
+ // render everything with the fog color
+ fragColor.a = 1.0;
+ }
+ else
+ {
+ // test code.
+
+ // this can be fired by manually changing the fullFogMode to a (normally)
+ // invalid value (like 7).
+ // By having a separate if statement defined by
+ // a uniform we don't have to worry about GLSL optimizing away different
+ // options when testing, causing a bunch of headaches if we just want to render the screen red.
+
+ float depthValue = textureLod(uDhDepthTexture, TexCoord, 0).r;
+ fragColor.rgb = vec3(depthValue); // Convert depth value to grayscale color
+ fragColor.a = 1.0;
+ }
+ }
+}
+
+
+
+//================//
+// helper methods //
+//================//
+
+vec3 calcViewPosition(float fragmentDepth)
+{
+ vec4 ndc = vec4(TexCoord.xy, fragmentDepth, 1.0);
+ ndc.xyz = ndc.xyz * 2.0 - 1.0;
+
+ vec4 eyeCoord = uInvMvmProj * ndc;
+ return eyeCoord.xyz / eyeCoord.w;
+}
+
+
+
+//=========//
+// far fog //
+//=========//
+
+float getFarFogThickness(float dist)
+{
+ if (uFogFalloffType == 0) // LINEAR
+ {
+ return linearFog(dist, uFarFogStart, uFarFogLength, uFarFogMin, uFarFogRange);
+ }
+ else if (uFogFalloffType == 1) // EXPONENTIAL
+ {
+ return exponentialFog(dist, uFarFogStart, uFarFogLength, uFarFogMin, uFarFogRange, uFarFogDensity);
+ }
+ else // EXPONENTIAL_SQUARED
+ {
+ return exponentialSquaredFog(dist, uFarFogStart, uFarFogLength, uFarFogMin, uFarFogRange, uFarFogDensity);
+ }
+}
+
+float getHeightFogThickness(float dist)
+{
+ if (!uHeightFogEnabled)
+ {
+ return 0.0;
+ }
+
+ if (uHeightFogFalloffType == 0) // LINEAR
+ {
+ return linearFog(dist, uHeightFogStart, uHeightFogLength, uHeightFogMin, uHeightFogRange);
+ }
+ else if (uHeightFogFalloffType == 1) // EXPONENTIAL
+ {
+ return exponentialFog(dist, uHeightFogStart, uHeightFogLength, uHeightFogMin, uHeightFogRange, uHeightFogDensity);
+ }
+ else // EXPONENTIAL_SQUARED
+ {
+ return exponentialSquaredFog(dist, uHeightFogStart, uHeightFogLength, uHeightFogMin, uHeightFogRange, uHeightFogDensity);
+ }
+}
+
+float linearFog(float worldDist, float fogStart, float fogLength, float fogMin, float fogRange)
+{
+ worldDist = (worldDist - fogStart) / fogLength;
+ worldDist = clamp(worldDist, 0.0, 1.0);
+ return fogMin + fogRange * worldDist;
+}
+
+float exponentialFog(
+ float x, float fogStart, float fogLength,
+ float fogMin, float fogRange, float fogDensity)
+{
+ x = max((x-fogStart)/fogLength, 0.0) * fogDensity;
+ return fogMin + fogRange - fogRange/exp(x);
+}
+
+float exponentialSquaredFog(
+ float x, float fogStart, float fogLength,
+ float fogMin, float fogRange, float fogDensity)
+{
+ x = max((x-fogStart)/fogLength, 0.0) * fogDensity;
+ return fogMin + fogRange - fogRange/exp(x*x);
+}
+
+
+
+//============//
+// height fog //
+//============//
+
+/** 1 = full fog, 0 = no fog */
+float calculateHeightFogDepth(float worldYPos)
+{
+ // worldYPos -65 - 384
+
+
+ //worldYPos = worldYPos * -1; // negative, fog below height; positive, fog above height
+ //return worldYPos * uFogVerticalScale; // "* uFogVerticalScale" is done to convert world position to a percent of the world height;
+
+ if (!uHeightFogEnabled)
+ {
+ // ignore the height
+ return 0.0;
+ }
+
+
+ if (!uHeightBasedOnCamera)
+ {
+ worldYPos -= (uHeightFogBaseHeight - uCameraBlockYPos);
+ }
+
+
+ if (uHeightFogAppliesDown && uHeightFogAppliesUp)
+ {
+ return abs(worldYPos) * uFogVerticalScale;
+ }
+ else if (uHeightFogAppliesDown)
+ {
+ // apploy fog below given height
+ return -worldYPos * uFogVerticalScale;
+ }
+ else if (uHeightFogAppliesUp)
+ {
+ // apply fog above given height
+ return worldYPos * uFogVerticalScale;
+ }
+ else
+ {
+ // shouldn't happen,
+ return 0.0;
+ }
+
+}
+
+float mixFogThickness(float far, float height)
+{
+ switch (uHeightFogMixingMode)
+ {
+ case 0: // BASIC
+ case 1: // IGNORE_HEIGHT
+ return far;
+
+ case 2: // MAX
+ return max(far, height);
+
+ case 3: // ADDITION
+ return (far + height);
+
+ case 4: // MULTIPLY
+ return far * height;
+
+ case 5: // INVERSE_MULTIPLY
+ return (1.0 - (1.0-far)*(1.0-height));
+
+ case 6: // LIMITED_ADDITION
+ return (far + max(far, height));
+
+ case 7: // MULTIPLY_ADDITION
+ return (far + far*height);
+
+ case 8: // INVERSE_MULTIPLY_ADDITION
+ return (far + 1.0 - (1.0-far)*(1.0-height));
+
+ case 9: // AVERAGE
+ return (far*0.5 + height*0.5);
+ }
+
+ // shouldn't happen, but default to BASIC / IGNORE_HEIGHT
+ // if an invalid option is selected
+ return far;
+}
+
+
+
diff --git a/core/src/main/resources/shaders/quadApply.vert b/core/src/main/resources/assets/distanthorizons/shaders/fog/blaze/vert.vsh
similarity index 100%
rename from core/src/main/resources/shaders/quadApply.vert
rename to core/src/main/resources/assets/distanthorizons/shaders/fog/blaze/vert.vsh
diff --git a/core/src/main/resources/shaders/fog/apply.frag b/core/src/main/resources/assets/distanthorizons/shaders/fog/gl/apply.frag
similarity index 100%
rename from core/src/main/resources/shaders/fog/apply.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/fog/gl/apply.frag
diff --git a/core/src/main/resources/shaders/fog/fog.frag b/core/src/main/resources/assets/distanthorizons/shaders/fog/gl/fog.frag
similarity index 100%
rename from core/src/main/resources/shaders/fog/fog.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/fog/gl/fog.frag
diff --git a/core/src/main/resources/shaders/genericObject/direct/frag.frag b/core/src/main/resources/assets/distanthorizons/shaders/generic/blaze/frag.fsh
similarity index 100%
rename from core/src/main/resources/shaders/genericObject/direct/frag.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/generic/blaze/frag.fsh
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/generic/blaze/vert.vsh b/core/src/main/resources/assets/distanthorizons/shaders/generic/blaze/vert.vsh
new file mode 100644
index 000000000..68931fe9a
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/generic/blaze/vert.vsh
@@ -0,0 +1,101 @@
+#version 330 core
+
+//layout (location = 1) in vec4 aColor; // RGBA_FLOAT_COLOR
+//layout (location = 2) in vec3 aScale; // VEC3_SCALE
+//layout (location = 3) in ivec3 aTranslateChunk; // IVEC3_SCALE
+//layout (location = 4) in vec3 aTranslateSubChunk; // VEC3_SCALE
+//layout (location = 5) in int aMaterial; // IRIS_MATERIAL
+
+//uniform sampler2D /*vec4*/ uColorMap;
+//uniform sampler2D /*vec3*/ uScaleMap;
+//uniform sampler2D /*int*/ uTranslateChunkXMap;
+//uniform sampler2D /*int*/ uTranslateChunkYMap;
+//uniform sampler2D /*int*/ uTranslateChunkZMap;
+//uniform sampler2D /*vec3*/ uTranslateSubChunkMap;
+//uniform sampler2D /*int*/ uMaterialMap;
+//
+//in vec3 vPosition;
+
+in vec3 vPosition;
+in vec4 aColor; // RGBA_FLOAT_COLOR
+in int aMaterial; // IRIS_MATERIAL
+
+layout (std140) uniform vertUniformBlock
+{
+ ivec3 uOffsetChunk;
+ vec3 uOffsetSubChunk;
+ ivec3 uCameraPosChunk;
+ vec3 uCameraPosSubChunk;
+
+ mat4 uProjectionMvm;
+ int uSkyLight;
+ int uBlockLight;
+
+ float uNorthShading;
+ float uSouthShading;
+ float uEastShading;
+ float uWestShading;
+ float uTopShading;
+ float uBottomShading;
+};
+
+uniform sampler2D uLightMap;
+
+out vec4 fColor;
+
+void main()
+{
+ vec3 aScale = vec3(1);
+
+ if (aMaterial == 999)
+ {
+ aScale = vec3(2);
+ }
+
+// vec4 aColor = texelFetch(uColorMap, ivec2(gl_InstanceID,0), 0);
+// vec3 aScale = texelFetch(uScaleMap, ivec2(gl_InstanceID,0), 0).xyz;
+//
+// float chunkX = int(texelFetch(uTranslateChunkXMap, ivec2(gl_InstanceID,0), 0).x);
+// float chunkY = int(texelFetch(uTranslateChunkYMap, ivec2(gl_InstanceID,0), 0).x);
+// float chunkZ = int(texelFetch(uTranslateChunkZMap, ivec2(gl_InstanceID,0), 0).x);
+// ivec3 aTranslateChunk = ivec3(chunkX, chunkY, chunkZ);
+//
+// vec3 aTranslateSubChunk = texelFetch(uTranslateSubChunkMap, ivec2(gl_InstanceID,0), 0).xyz;
+// int aMaterial = int(texelFetch(uMaterialMap, ivec2(gl_InstanceID,0), 0).x);
+
+ // aTranslate - moves the vertex to the boxGroup's relative position
+ // uOffset - moves the vertex to the boxGroup's world position
+ // uCameraPos - moves the vertex into camera space
+ vec3 trans = (uOffsetChunk - uCameraPosChunk) * 16.0f;
+ // separate float and int values are to fix percission loss at extreme distances from the origin (IE 10,000,000+)
+ // luckily large translate values minus large cameraPos generally equal values that cleanly fit in a float
+ trans += (uOffsetSubChunk - uCameraPosSubChunk);
+
+ // combination translation and scaling matrix
+ mat4 transform = mat4(
+ aScale.x, 0.0, 0.0, 0.0,
+ 0.0, aScale.y, 0.0, 0.0,
+ 0.0, 0.0, aScale.z, 0.0,
+ trans.x, trans.y, trans.z, 1.0
+ );
+
+ gl_Position = uProjectionMvm * transform * vec4(vPosition, 1.0);
+
+ float blockLight = (float(uBlockLight)+0.5) / 16.0;
+ float skyLight = (float(uSkyLight)+0.5) / 16.0;
+ vec4 lightColor = vec4(texture(uLightMap, vec2(blockLight, skyLight)).xyz, 1.0);
+
+
+ fColor = lightColor * aColor;
+
+ int vertexIndex = gl_VertexID % 24;
+
+ // apply directional shading
+ if (vertexIndex >= 0 && vertexIndex < 4) { fColor.rgb *= uNorthShading; }
+ else if (vertexIndex >= 4 && vertexIndex < 8) { fColor.rgb *= uSouthShading; }
+ else if (vertexIndex >= 8 && vertexIndex < 12) { fColor.rgb *= uWestShading; }
+ else if (vertexIndex >= 12 && vertexIndex < 16) { fColor.rgb *= uEastShading; }
+ else if (vertexIndex >= 16 && vertexIndex < 20) { fColor.rgb *= uBottomShading; }
+ else if (vertexIndex >= 20 && vertexIndex < 24) { fColor.rgb *= uTopShading; }
+
+}
diff --git a/core/src/main/resources/shaders/genericObject/instanced/frag.frag b/core/src/main/resources/assets/distanthorizons/shaders/generic/gl/direct/frag.frag
similarity index 100%
rename from core/src/main/resources/shaders/genericObject/instanced/frag.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/generic/gl/direct/frag.frag
diff --git a/core/src/main/resources/shaders/genericObject/direct/vert.vert b/core/src/main/resources/assets/distanthorizons/shaders/generic/gl/direct/vert.vert
similarity index 100%
rename from core/src/main/resources/shaders/genericObject/direct/vert.vert
rename to core/src/main/resources/assets/distanthorizons/shaders/generic/gl/direct/vert.vert
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/generic/gl/instanced/frag.frag b/core/src/main/resources/assets/distanthorizons/shaders/generic/gl/instanced/frag.frag
new file mode 100644
index 000000000..c3d2ac8c4
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/generic/gl/instanced/frag.frag
@@ -0,0 +1,10 @@
+#version 150 core
+
+in vec4 fColor;
+
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = fColor;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/shaders/genericObject/instanced/vert.vert b/core/src/main/resources/assets/distanthorizons/shaders/generic/gl/instanced/vert.vert
similarity index 100%
rename from core/src/main/resources/shaders/genericObject/instanced/vert.vert
rename to core/src/main/resources/assets/distanthorizons/shaders/generic/gl/instanced/vert.vert
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/lod/blaze/frag.fsh b/core/src/main/resources/assets/distanthorizons/shaders/lod/blaze/frag.fsh
new file mode 100644
index 000000000..86be28a6b
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/lod/blaze/frag.fsh
@@ -0,0 +1,125 @@
+#version 150
+
+in vec4 vertexColor;
+in vec3 vertexWorldPos;
+in vec3 vPos;
+in vec4 gl_FragCoord;
+
+out vec4 fragColor;
+
+layout (std140) uniform fragUniformBlock
+{
+ // Fade/Clip Uniforms
+ float uClipDistance;
+
+ // Noise Uniforms
+ float uNoiseIntensity;
+ int uNoiseSteps;
+ int uNoiseDropoff;
+ bool uDitherDhRendering;
+ bool uNoiseEnabled;
+};
+
+
+// The random functions for diffrent dimentions
+float rand(float co) { return fract(sin(co*(91.3458)) * 47453.5453); }
+float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }
+float rand(vec3 co) { return rand(co.xy + rand(co.z)); }
+
+// Puts steps in a float
+// EG. setting stepSize to 4 then this would be the result of this function
+// In: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, ..., 1.1, 1.2, 1.3
+// Out: 0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, ..., 1.0, 1.0, 1.25
+vec3 quantize(vec3 val, int stepSize)
+{
+ return floor(val * stepSize) / stepSize;
+}
+
+void applyNoise(inout vec4 fragColor, const in float viewDist)
+{
+ vec3 vertexNormal = normalize(cross(dFdy(vPos.xyz), dFdx(vPos.xyz)));
+ // This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable
+ vec3 fixedVPos = vPos.xyz + vertexNormal * 0.001;
+
+ float noiseAmplification = uNoiseIntensity;
+ float lum = (fragColor.r + fragColor.g + fragColor.b) / 3.0;
+ noiseAmplification = (1.0 - pow(lum * 2.0 - 1.0, 2.0)) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1
+ noiseAmplification *= fragColor.a; // The effect would lessen on transparent objects
+
+ // Random value for each position
+ float randomValue = rand(quantize(fixedVPos, uNoiseSteps))
+ * 2.0 * noiseAmplification - noiseAmplification;
+
+ // Modifies the color
+ // A value of 0 on the randomValue will result in the original color, while a value of 1 will result in a fully bright color
+ vec3 newCol = fragColor.rgb + (1.0 - fragColor.rgb) * randomValue;
+ newCol = clamp(newCol, 0.0, 1.0);
+
+ if (uNoiseDropoff != 0) {
+ float distF = min(viewDist / uNoiseDropoff, 1.0);
+ newCol = mix(newCol, fragColor.rgb, distF); // The further away it gets, the less noise gets applied
+ }
+
+ fragColor.rgb = newCol;
+}
+
+/** returns a normalized value between 0.0 and 1.0 */
+float bayerMatrix4x4(vec2 st)
+{
+ int x = int(mod(st.x, 4.0));
+ int y = int(mod(st.y, 4.0));
+
+ // Flattened 4x4 Bayer matrix
+ float bayer4x4[16] = float[16](
+ 0.0, 8.0, 2.0, 10.0,
+ 12.0, 4.0, 14.0, 6.0,
+ 3.0, 11.0, 1.0, 9.0,
+ 15.0, 7.0, 13.0, 5.0
+ );
+
+ // Calculate the 1D index from the 2D coordinates
+ int index = y * 4 + x;
+
+ // Return the Bayer value normalized between 0.0 and 1.0
+ return bayer4x4[index] / 16.0;
+}
+
+
+
+void main()
+{
+ fragColor = vertexColor;
+
+ float viewDist = length(vertexWorldPos);
+
+ if (uDitherDhRendering)
+ {
+ // Dither out the fragment based on distance and noise.
+ // Dithering is used since it works for both opaque and transparent rendering
+
+ // noise increases as the distance increases
+ // the fragCoord is used since it is stable and small so the dithering is cleaner
+ float worldNoise = bayerMatrix4x4(gl_FragCoord.xy);
+ // minor fudge factor to make sure all pixels fade out
+ // if not included 1 in 16 pixels would never fade away
+ worldNoise += 0.001;
+
+ float fadeStep = smoothstep(uClipDistance, uClipDistance * 1.5, viewDist);
+ if (fadeStep <= worldNoise)
+ {
+ discard;
+ }
+ }
+ else
+ {
+ if (viewDist < uClipDistance && uClipDistance > 0.0)
+ {
+ discard;
+ }
+ }
+
+ if (uNoiseEnabled)
+ {
+ applyNoise(fragColor, viewDist);
+ }
+}
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/lod/blaze/vert.vsh b/core/src/main/resources/assets/distanthorizons/shaders/lod/blaze/vert.vsh
new file mode 100644
index 000000000..e2eed781e
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/lod/blaze/vert.vsh
@@ -0,0 +1,81 @@
+#version 150
+
+in uvec3 vPosition;
+in uint meta; // contains light and micro-offset data
+in vec4 vColor;
+in int irisMaterial;
+in int irisNormal;
+
+out vec3 vPos;
+out vec4 vertexColor;
+out vec3 vertexWorldPos;
+out float vertexYPos;
+
+layout (std140) uniform vertUniqueUniformBlock
+{
+ vec3 uModelOffset;
+};
+
+layout (std140) uniform vertSharedUniformBlock
+{
+ bool uIsWhiteWorld;
+
+ float uWorldYOffset;
+ float uMircoOffset;
+ float uEarthRadius;
+
+ vec3 uCameraPos;
+ mat4 uCombinedMatrix;
+};
+
+uniform sampler2D uLightMap;
+
+/**
+ * LOD terrain Vertex Shader
+ */
+void main()
+{
+ vPos = vPosition; // This is so it can be passed to the fragment shader
+
+ vertexWorldPos = vPosition.xyz + (uModelOffset - uCameraPos);
+
+ vertexYPos = vPosition.y + uWorldYOffset;
+
+ uint mirco = (meta & 0xFF00u) >> 8u; // mirco offset which is a xyz 2bit value
+ // 0b00 = no offset
+ // 0b01 = positive offset
+ // 0b11 = negative offset
+ // format is: 0b00zzyyxx
+ float mx = (mirco & 1u)!=0u ? uMircoOffset : 0.0;
+ mx = (mirco & 2u)!=0u ? -mx : mx;
+ //float my = (mirco & 4u)!=0u ? uMircoOffset : 0.0;
+ //my = (mirco & 8u)!=0u ? -my : my;
+ float mz = (mirco & 16u)!=0u ? uMircoOffset : 0.0;
+ mz = (mirco & 32u)!=0u ? -mz : mz;
+
+ vertexWorldPos.x += mx;
+ //vertexWorldPos.y += my;
+ vertexWorldPos.z += mz;
+
+ // apply the earth curvature if needed
+ if (uEarthRadius < -1.0f || uEarthRadius > 1.0f)
+ {
+ // vertex transformation logic - stduhpf
+ float localRadius = uEarthRadius + vertexYPos;
+ float phi = length(vertexWorldPos.xz) / localRadius;
+ vertexWorldPos.y += (cos(phi) - 1.0) * localRadius;
+ vertexWorldPos.xz = vertexWorldPos.xz * sin(phi) / phi;
+ }
+
+ uint lights = meta & 0xFFu;
+ float skyLight = (float(lights/16u)+0.5) / 16.0;
+ float blockLight = (mod(float(lights), 16.0)+0.5) / 16.0;
+ vertexColor = vec4(texture(uLightMap, vec2(skyLight, blockLight)).xyz, 1.0);
+
+ if (!uIsWhiteWorld)
+ {
+ vertexColor *= vColor;
+ }
+
+ gl_Position = uCombinedMatrix * vec4(vertexWorldPos, 1.0);
+}
diff --git a/core/src/main/resources/shaders/apply.frag b/core/src/main/resources/assets/distanthorizons/shaders/shared/gl/apply.frag
similarity index 100%
rename from core/src/main/resources/shaders/apply.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/shared/gl/apply.frag
diff --git a/core/src/main/resources/shaders/flat_shaded.frag b/core/src/main/resources/assets/distanthorizons/shaders/shared/gl/flat_shaded.frag
similarity index 100%
rename from core/src/main/resources/shaders/flat_shaded.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/shared/gl/flat_shaded.frag
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/shared/gl/quadApply.vert b/core/src/main/resources/assets/distanthorizons/shaders/shared/gl/quadApply.vert
new file mode 100644
index 000000000..3f614c123
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/shared/gl/quadApply.vert
@@ -0,0 +1,15 @@
+#version 150 core
+
+in vec2 vPosition;
+
+out vec2 TexCoord;
+
+/**
+ * This is specifically used by application shaders.
+ * IE post process or pixel transfer shaders, anything that is rendered using a single rectangle.
+ */
+void main()
+{
+ gl_Position = vec4(vPosition, 1.0, 1.0);
+ TexCoord = vPosition.xy * 0.5 + 0.5;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/shaders/standard.vert b/core/src/main/resources/assets/distanthorizons/shaders/shared/gl/standard.vert
similarity index 100%
rename from core/src/main/resources/shaders/standard.vert
rename to core/src/main/resources/assets/distanthorizons/shaders/shared/gl/standard.vert
index f948f1708..1117af78e 100644
--- a/core/src/main/resources/shaders/standard.vert
+++ b/core/src/main/resources/assets/distanthorizons/shaders/shared/gl/standard.vert
@@ -1,9 +1,9 @@
#version 150 core
in uvec4 vPosition;
-out vec4 vPos;
in vec4 color;
+out vec4 vPos;
out vec4 vertexColor;
out vec3 vertexWorldPos;
out float vertexYPos;
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/apply.fsh b/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/apply.fsh
new file mode 100644
index 000000000..ecc9ba828
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/apply.fsh
@@ -0,0 +1,86 @@
+#version 150 core
+
+in vec2 TexCoord;
+
+out vec4 fragColor;
+
+uniform sampler2D uSourceColorTexture;
+uniform sampler2D uSourceDepthTexture;
+
+layout (std140) uniform applyFragUniformBlock
+{
+ vec2 uViewSize;
+ int uBlurRadius;
+ float uNearClipPlane; // in blocks
+ float uFarClipPlane; // in blocks
+};
+
+
+float linearizeDepth(const in float depth) { return (uNearClipPlane * uFarClipPlane) / (depth * (uNearClipPlane - uFarClipPlane) + uFarClipPlane); }
+
+float Gaussian(const in float sigma, const in float x) { return exp(-(x*x) / (2.0 * (sigma*sigma))); }
+
+float BilateralGaussianBlur(const in vec2 texcoord, const in float linearDepth, const in float g_sigmaV)
+{
+ float g_sigmaX = 1.6;
+ float g_sigmaY = 1.6;
+
+ int radius = clamp(uBlurRadius, 1, 3);
+
+ vec2 pixelSize = 1.0 / uViewSize;
+
+ float accum = 0.0;
+ float total = 0.0;
+ for (int iy = -radius; iy <= radius; iy++)
+ {
+ float fy = Gaussian(g_sigmaY, iy);
+
+ for (int ix = -radius; ix <= radius; ix++)
+ {
+ float fx = Gaussian(g_sigmaX, ix);
+
+ vec2 sampleTexCoord = texcoord + ivec2(ix, iy) * pixelSize;
+
+ float sampleValue = textureLod(uSourceColorTexture, sampleTexCoord, 0).r;
+
+ float sampleDepth = textureLod(uSourceDepthTexture, sampleTexCoord, 0).r;
+ float sampleLinearDepth = linearizeDepth(sampleDepth);
+
+ float depthDiff = abs(sampleLinearDepth - linearDepth);
+ float fv = Gaussian(g_sigmaV, depthDiff);
+
+ float weight = fx*fy*fv;
+ accum += weight * sampleValue;
+ total += weight;
+ }
+ }
+
+ if (total <= 1.e-4)
+ {
+ return 1.0;
+ }
+ return accum / total;
+}
+
+
+void main()
+{
+ fragColor = vec4(1.0);
+
+ float fragmentDepth = textureLod(uSourceDepthTexture, TexCoord, 0).r;
+
+ // a fragment depth of "1" means the fragment wasn't drawn to,
+ // we only want to apply SSAO to LODs, not to the sky outside the LODs
+ if (fragmentDepth < 1)
+ {
+ if (uBlurRadius > 0)
+ {
+ float fragmentDepthLinear = linearizeDepth(fragmentDepth);
+ fragColor.a = BilateralGaussianBlur(TexCoord, fragmentDepthLinear, 1.6);
+ }
+ else
+ {
+ fragColor.a = texelFetch(uSourceColorTexture, ivec2(gl_FragCoord.xy), 0).r;
+ }
+ }
+}
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/frag.fsh b/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/frag.fsh
new file mode 100644
index 000000000..517523342
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/frag.fsh
@@ -0,0 +1,137 @@
+#version 150 core
+#extension GL_ARB_derivative_control : enable
+
+#define SAMPLE_MAX 64
+
+#define saturate(x) (clamp((x), 0.0, 1.0))
+
+in vec2 TexCoord;
+
+out vec4 fragColor;
+
+
+layout (std140) uniform fragUniformBlock
+{
+ int uSampleCount;
+
+ float uRadius;
+ float uStrength;
+ float uMinLight;
+ float uBias;
+ float uFadeDistanceInBlocks;
+
+ mat4 uInvProj;
+ mat4 uProj;
+};
+
+uniform sampler2D uDhDepthTexture;
+
+const float EPSILON = 1.e-6;
+const float GOLDEN_ANGLE = 2.39996323;
+const vec3 MAGIC = vec3(0.06711056, 0.00583715, 52.9829189);
+const float PI = 3.1415926538;
+const float TAU = PI * 2.0;
+
+
+vec3 unproject(vec4 pos)
+{
+ return pos.xyz / pos.w;
+}
+
+float InterleavedGradientNoise(const in vec2 pixel)
+{
+ float x = dot(pixel, MAGIC.xy);
+ return fract(MAGIC.z * fract(x));
+}
+
+vec3 calcViewPosition(const in vec3 clipPos)
+{
+ vec4 viewPos = uInvProj * vec4(clipPos * 2.0 - 1.0, 1.0);
+ return viewPos.xyz / viewPos.w;
+}
+
+float GetSpiralOcclusion(const in vec2 uv, const in vec3 viewPos, const in vec3 viewNormal)
+{
+ float dither = InterleavedGradientNoise(gl_FragCoord.xy);
+ float rotatePhase = dither * TAU;
+ float rStep = uRadius / uSampleCount;
+
+ vec2 offset;
+
+ float ao = 0.0;
+ int sampleCount = 0;
+ float radius = rStep;
+ for (int i = 0; i < clamp(uSampleCount, 1, SAMPLE_MAX); i++) {
+ vec2 offset = vec2(
+ sin(rotatePhase),
+ cos(rotatePhase)
+ ) * radius;
+
+ radius += rStep;
+ rotatePhase += GOLDEN_ANGLE;
+
+ vec3 sampleViewPos = viewPos + vec3(offset, -0.1);
+ vec3 sampleClipPos = unproject(uProj * vec4(sampleViewPos, 1.0)) * 0.5 + 0.5;
+ sampleClipPos = saturate(sampleClipPos);
+
+ float sampleClipDepth = textureLod(uDhDepthTexture, sampleClipPos.xy, 0.0).r;
+ if (sampleClipDepth >= 1.0 - EPSILON) continue;
+
+ sampleClipPos.z = sampleClipDepth;
+ sampleViewPos = unproject(uInvProj * vec4(sampleClipPos * 2.0 - 1.0, 1.0));
+
+ vec3 diff = sampleViewPos - viewPos;
+ float sampleDist = length(diff);
+ vec3 sampleNormal = diff / sampleDist;
+
+ float sampleNoLm = max(dot(viewNormal, sampleNormal) - uBias, 0.0);
+ float aoF = 1.0 - saturate(sampleDist / uRadius);
+ ao += sampleNoLm * aoF;
+ sampleCount++;
+ }
+
+ ao /= max(sampleCount, 1);
+ ao = smoothstep(0.0, uStrength, ao);
+
+ return ao * (1.0 - uMinLight);
+}
+
+
+void main()
+{
+ float fragmentDepth = textureLod(uDhDepthTexture, TexCoord, 0).r;
+ float occlusion = 0.0;
+
+ // Do not apply to sky
+ if (fragmentDepth < 1.0)
+ {
+ vec3 viewPos = calcViewPosition(vec3(TexCoord, fragmentDepth));
+
+ // fading is done to prevent banding/noise
+ // at super far distance
+ float distanceFromCamera = length(viewPos);
+ float fadeDistance = uFadeDistanceInBlocks;
+ if (distanceFromCamera < fadeDistance)
+ {
+ #ifdef GL_ARB_derivative_control
+ // Get higher precision derivatives when available
+ vec3 viewNormal = cross(dFdxFine(viewPos.xyz), dFdyFine(viewPos.xyz));
+ #else
+ vec3 viewNormal = cross(dFdx(viewPos.xyz), dFdy(viewPos.xyz));
+ #endif
+
+ viewNormal = normalize(viewNormal);
+ occlusion = GetSpiralOcclusion(TexCoord, viewPos, viewNormal);
+
+ // linearly fade with distance
+ occlusion *= (fadeDistance - distanceFromCamera) / fadeDistance;
+ }
+ else
+ {
+ // we're out of range, no need to do any SSAO calculations
+ occlusion = 0.0;
+ }
+ }
+
+ fragColor = vec4(vec3(1.0 - occlusion), 1.0);
+}
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/vert.vsh b/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/vert.vsh
new file mode 100644
index 000000000..3f614c123
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/ssao/blaze/vert.vsh
@@ -0,0 +1,15 @@
+#version 150 core
+
+in vec2 vPosition;
+
+out vec2 TexCoord;
+
+/**
+ * This is specifically used by application shaders.
+ * IE post process or pixel transfer shaders, anything that is rendered using a single rectangle.
+ */
+void main()
+{
+ gl_Position = vec4(vPosition, 1.0, 1.0);
+ TexCoord = vPosition.xy * 0.5 + 0.5;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/shaders/ssao/ao.frag b/core/src/main/resources/assets/distanthorizons/shaders/ssao/gl/ao.frag
similarity index 100%
rename from core/src/main/resources/shaders/ssao/ao.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/ssao/gl/ao.frag
diff --git a/core/src/main/resources/shaders/ssao/apply.frag b/core/src/main/resources/assets/distanthorizons/shaders/ssao/gl/apply.frag
similarity index 100%
rename from core/src/main/resources/shaders/ssao/apply.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/ssao/gl/apply.frag
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/test/blaze/frag.fsh b/core/src/main/resources/assets/distanthorizons/shaders/test/blaze/frag.fsh
new file mode 100644
index 000000000..3fd25f9db
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/test/blaze/frag.fsh
@@ -0,0 +1,10 @@
+#version 150 core
+
+in vec4 fColor;
+out vec4 fragColor;
+
+// DH frag test
+void main()
+{
+ fragColor = fColor;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/assets/distanthorizons/shaders/test/blaze/vert.vsh b/core/src/main/resources/assets/distanthorizons/shaders/test/blaze/vert.vsh
new file mode 100644
index 000000000..2887fea56
--- /dev/null
+++ b/core/src/main/resources/assets/distanthorizons/shaders/test/blaze/vert.vsh
@@ -0,0 +1,13 @@
+#version 150 core
+
+in vec2 vPosition;
+in vec4 vColor;
+
+out vec4 fColor;
+
+// DH vert test
+void main()
+{
+ gl_Position = vec4(vPosition, 0.0, 1.0);
+ fColor = vColor;
+}
\ No newline at end of file
diff --git a/core/src/main/resources/shaders/test/frag.frag b/core/src/main/resources/assets/distanthorizons/shaders/test/gl/frag.frag
similarity index 100%
rename from core/src/main/resources/shaders/test/frag.frag
rename to core/src/main/resources/assets/distanthorizons/shaders/test/gl/frag.frag
diff --git a/core/src/main/resources/shaders/test/vert.vert b/core/src/main/resources/assets/distanthorizons/shaders/test/gl/vert.vert
similarity index 100%
rename from core/src/main/resources/shaders/test/vert.vert
rename to core/src/main/resources/assets/distanthorizons/shaders/test/gl/vert.vert
diff --git a/core/src/main/resources/shaders/noise/noise.frag b/core/src/main/resources/shaders/noise/noise.frag
deleted file mode 100644
index 6d39b6253..000000000
--- a/core/src/main/resources/shaders/noise/noise.frag
+++ /dev/null
@@ -1,74 +0,0 @@
-#version 150 core
-
-in vec4 vertexColor;
-in vec4 vPos;
-in vec3 vertexWorldPos;
-out vec4 fragColor;
-
-uniform float distanceScale;
-
-uniform int uNoiseSteps;
-uniform float uNoiseIntensity;
-uniform float uNoiseDropoff;
-
-
-
-// The random functions for diffrent dimentions
-float rand(float co) { return fract(sin(co*(91.3458)) * 47453.5453); }
-float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }
-float rand(vec3 co){ return rand(co.xy+rand(co.z)); }
-
-// Puts steps in a float
-// EG. setting stepSize to 4 then this would be the result of this function
-// In: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, ..., 1.1, 1.2, 1.3
-// Out: 0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, ..., 1.0, 1.0, 1.25
-float quantize(float val, int stepSize) {
- return floor(val*stepSize)/stepSize;
-}
-
-vec3 quantize(vec3 val, int stepSize) {
- return floor(val*stepSize)/stepSize;
-}
-
-
-/**
- * Fragment shader for adding noise to lods.
- * This should be passed close to first as it affects the base color of the lod
- *
- * version: 2023-6-21
- */
-void main() {
- // This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable
- vec3 vertexNormal = normalize(cross(dFdx(vPos.xyz), dFdy(vPos.xyz)));
- vec3 fixedVPos = vPos.xyz - vertexNormal * 0.001;
-
-
- float noiseAmplification = uNoiseIntensity;
- noiseAmplification = (-1 * pow(2*((vertexColor.x + vertexColor.y + vertexColor.z) / 3) - 1, 2) + 1) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1
- noiseAmplification *= vertexColor.w; // The effect would lessen on transparent objects
-
- // Random value for each position
- float randomValue = rand(quantize(fixedVPos.xyz, uNoiseSteps))
- * 2.0 * noiseAmplification - noiseAmplification;
-
-
- // Modifies the color
- // A value of 0 on the randomValue will result in the original color, while a value of 1 will result in a fully bright color
- vec3 newCol = (1.0 - vertexColor.rgb) * randomValue;
-
- // Clamps it and turns it back into a vec4
- float distA = length(vertexWorldPos) * distanceScale * uNoiseDropoff;
- fragColor = clamp(vec4(newCol.rgb, distA), 0.0, 1.0); // The further away it gets, the less noise gets applied
-
- // The further away it gets, the less noise gets applied
- fragColor = vec4(0.0, 0.0, 0.0, randomValue);
-
- // For testing
-// if (vertexColor.r != 69420.) {
-// fragColor = vec4(
-// mod(fixedVPos.x, 1),
-// mod(fixedVPos.y, 1),
-// mod(fixedVPos.z, 1),
-// 1f);
-// }
-}
\ No newline at end of file
diff --git a/core/src/main/resources/shaders/test/dark.frag b/core/src/main/resources/shaders/test/dark.frag
deleted file mode 100644
index ab99d05ce..000000000
--- a/core/src/main/resources/shaders/test/dark.frag
+++ /dev/null
@@ -1,9 +0,0 @@
-#version 150 core
-
-out vec4 fragColor;
-
-// A test shader that makes everything darker
-void main()
-{
- fragColor = vec4(0., 0., 1., 0.5);
-}
\ No newline at end of file