Updated core (i really need to add a subproject)
This commit is contained in:
@@ -162,6 +162,7 @@ import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
|
|||||||
public void generateLodNodeFromChunk(LodDimension lodDim, IChunkWrapper chunk, LodBuilderConfig config)
|
public void generateLodNodeFromChunk(LodDimension lodDim, IChunkWrapper chunk, LodBuilderConfig config)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
|
//long executeTime = System.currentTimeMillis();
|
||||||
if (chunk == null)
|
if (chunk == null)
|
||||||
throw new IllegalArgumentException("generateLodFromChunk given a null chunk");
|
throw new IllegalArgumentException("generateLodFromChunk given a null chunk");
|
||||||
|
|
||||||
@@ -209,6 +210,8 @@ import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lodDim.updateData(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().getX(), chunk.getPos().getZ());
|
lodDim.updateData(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().getX(), chunk.getPos().getZ());
|
||||||
|
//executeTime = System.currentTimeMillis() - executeTime;
|
||||||
|
//if (executeTime > 0) ClientApi.LOGGER.info("generateLodNodeFromChunk level: " + detailLevel + " time ms: " + executeTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** creates a vertical DataPoint */
|
/** creates a vertical DataPoint */
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package com.seibel.lod.core.render;
|
package com.seibel.lod.core.render;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
@@ -100,18 +99,16 @@ public class GLProxy
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// May throw IllegalStateException, RuntimeException, FileNotFoundException
|
||||||
private GLProxy()
|
private GLProxy()
|
||||||
{
|
{
|
||||||
ClientApi.LOGGER.error("Creating " + GLProxy.class.getSimpleName() + "... If this is the last message you see in the log there must have been a OpenGL error.");
|
ClientApi.LOGGER.info("Lod: Creating " + GLProxy.class.getSimpleName() + "...");
|
||||||
|
|
||||||
// getting Minecraft's context has to be done on the render thread,
|
// getting Minecraft's context has to be done on the render thread,
|
||||||
// where the GL context is
|
// where the GL context is
|
||||||
if (GLFW.glfwGetCurrentContext() == 0L)
|
if (GLFW.glfwGetCurrentContext() == 0L)
|
||||||
throw new IllegalStateException(GLProxy.class.getSimpleName() + " was created outside the render thread!");
|
throw new IllegalStateException(GLProxy.class.getSimpleName() + " was created outside the render thread!");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//============================//
|
//============================//
|
||||||
// create the builder context //
|
// create the builder context //
|
||||||
//============================//
|
//============================//
|
||||||
@@ -243,50 +240,45 @@ public class GLProxy
|
|||||||
|
|
||||||
|
|
||||||
// GLProxy creation success
|
// GLProxy creation success
|
||||||
ClientApi.LOGGER.error(GLProxy.class.getSimpleName() + " creation successful. OpenGL smiles upon you this day.");
|
ClientApi.LOGGER.info(GLProxy.class.getSimpleName() + " creation completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates all required shaders */
|
/** Creates all required shaders */
|
||||||
|
// May throw RuntimeException, FileNotFoundException
|
||||||
public void createShaderProgram()
|
public void createShaderProgram()
|
||||||
{
|
{
|
||||||
LodShader vertexShader = null;
|
LodShader vertexShader = null;
|
||||||
LodShader fragmentShader = null;
|
LodShader fragmentShader = null;
|
||||||
|
|
||||||
try
|
// get the shaders from the resource folder
|
||||||
{
|
// Use File.separator ONLY if the file is external (not in the resourse), otherwise use "/"
|
||||||
// get the shaders from the resource folder
|
vertexShader = LodShader.loadShader(GL20.GL_VERTEX_SHADER, "shaders/standard.vert", false);
|
||||||
vertexShader = LodShader.loadShader(GL20.GL_VERTEX_SHADER, "shaders" + File.separator + "standard.vert", false);
|
fragmentShader = LodShader.loadShader(GL20.GL_FRAGMENT_SHADER, "shaders/flat_shaded.frag", false);
|
||||||
fragmentShader = LodShader.loadShader(GL20.GL_FRAGMENT_SHADER, "shaders" + File.separator + "flat_shaded.frag", false);
|
|
||||||
|
|
||||||
// this can be used when testing shaders,
|
// this can be used when testing shaders,
|
||||||
// since we can't hot swap the files in the resource folder
|
// since we can't hot swap the files in the resource folder
|
||||||
// vertexShader = LodShader.loadShader(GL20.GL_VERTEX_SHADER, "C:/Users/James Seibel/Desktop/shaders/standard.vert", true);
|
// vertexShader = LodShader.loadShader(GL20.GL_VERTEX_SHADER, "C:/Users/James Seibel/Desktop/shaders/standard.vert", true);
|
||||||
// fragmentShader = LodShader.loadShader(GL20.GL_FRAGMENT_SHADER, "C:/Users/James Seibel/Desktop/shaders/flat_shaded.frag", true);
|
// fragmentShader = LodShader.loadShader(GL20.GL_FRAGMENT_SHADER, "C:/Users/James Seibel/Desktop/shaders/flat_shaded.frag", true);
|
||||||
|
|
||||||
|
|
||||||
// create the shaders
|
// create the shaders
|
||||||
|
lodShaderProgram = new LodShaderProgram();
|
||||||
|
|
||||||
lodShaderProgram = new LodShaderProgram();
|
// Attach the compiled shaders to the program, throws RuntimeException on link error
|
||||||
|
lodShaderProgram.attachShader(vertexShader);
|
||||||
|
lodShaderProgram.attachShader(fragmentShader);
|
||||||
|
|
||||||
// Attach the compiled shaders to the program
|
// activate the fragment shader output
|
||||||
lodShaderProgram.attachShader(vertexShader);
|
GL30.glBindFragDataLocation(lodShaderProgram.id, 0, "fragColor");
|
||||||
lodShaderProgram.attachShader(fragmentShader);
|
|
||||||
|
|
||||||
// activate the fragment shader output
|
// attach the shader program to the OpenGL context
|
||||||
GL30.glBindFragDataLocation(lodShaderProgram.id, 0, "fragColor");
|
lodShaderProgram.link();
|
||||||
|
|
||||||
// attach the shader program to the OpenGL context
|
// after the shaders have been attached to the program
|
||||||
lodShaderProgram.link();
|
// we don't need their OpenGL references anymore
|
||||||
|
GL20.glDeleteShader(vertexShader.id);
|
||||||
|
GL20.glDeleteShader(fragmentShader.id);
|
||||||
|
|
||||||
// after the shaders have been attached to the program
|
|
||||||
// we don't need their OpenGL references anymore
|
|
||||||
GL20.glDeleteShader(vertexShader.id);
|
|
||||||
GL20.glDeleteShader(fragmentShader.id);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
ClientApi.LOGGER.error("Unable to compile shaders. Error: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,13 @@ package com.seibel.lod.core.render.shader;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL20;
|
import org.lwjgl.opengl.GL20;
|
||||||
|
|
||||||
import com.seibel.lod.core.api.ClientApi;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This object holds a OpenGL reference to a shader
|
* This object holds a OpenGL reference to a shader
|
||||||
* and allows for reading in and compiling a shader file.
|
* and allows for reading in and compiling a shader file.
|
||||||
@@ -59,14 +58,23 @@ public class LodShader
|
|||||||
* @param absoluteFilePath If false the file path is relative to the resource jar folder.
|
* @param absoluteFilePath If false the file path is relative to the resource jar folder.
|
||||||
* @throws Exception if the shader fails to compile
|
* @throws Exception if the shader fails to compile
|
||||||
*/
|
*/
|
||||||
public static LodShader loadShader(int type, String path, boolean absoluteFilePath) throws Exception
|
public static LodShader loadShader(int type, String path, boolean absoluteFilePath)
|
||||||
{
|
{
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// open the file
|
// open the file
|
||||||
InputStream in = absoluteFilePath ? new FileInputStream(path) : LodShader.class.getClassLoader().getResourceAsStream(path);
|
InputStream in;
|
||||||
|
if (absoluteFilePath) {
|
||||||
|
// Throws FileNotFoundException
|
||||||
|
in = new FileInputStream(path); // Note: this should use OS path seperator
|
||||||
|
} else {
|
||||||
|
in = LodShader.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));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
|
||||||
// read in the file
|
// read in the file
|
||||||
@@ -76,7 +84,7 @@ public class LodShader
|
|||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
ClientApi.LOGGER.error("Unable to load shader from file [" + path + "]. Error: " + e.getMessage());
|
throw new RuntimeException("Unable to load shader from file [" + path + "]. Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
CharSequence shaderFileSource = stringBuilder.toString();
|
CharSequence shaderFileSource = stringBuilder.toString();
|
||||||
|
|
||||||
@@ -90,7 +98,7 @@ public class LodShader
|
|||||||
* @param source Source of the shader
|
* @param source Source of the shader
|
||||||
* @throws Exception if the shader fails to compile
|
* @throws Exception if the shader fails to compile
|
||||||
*/
|
*/
|
||||||
public static LodShader createShader(int type, CharSequence source) throws Exception
|
public static LodShader createShader(int type, CharSequence source)
|
||||||
{
|
{
|
||||||
LodShader shader = new LodShader(type);
|
LodShader shader = new LodShader(type);
|
||||||
GL20.glShaderSource(shader.id, source);
|
GL20.glShaderSource(shader.id, source);
|
||||||
@@ -103,14 +111,14 @@ public class LodShader
|
|||||||
* Compiles the shader and checks its status afterwards.
|
* Compiles the shader and checks its status afterwards.
|
||||||
* @throws Exception if the shader fails to compile
|
* @throws Exception if the shader fails to compile
|
||||||
*/
|
*/
|
||||||
public void compile() throws Exception
|
public void compile()
|
||||||
{
|
{
|
||||||
GL20.glCompileShader(id);
|
GL20.glCompileShader(id);
|
||||||
|
|
||||||
// check if the shader compiled
|
// check if the shader compiled
|
||||||
int status = GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS);
|
int status = GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS);
|
||||||
if (status != GL20.GL_TRUE)
|
if (status != GL20.GL_TRUE)
|
||||||
throw new Exception(GL20.glGetShaderInfoLog(id));
|
throw new RuntimeException("Shader compiler error. Details: "+GL20.glGetShaderInfoLog(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class LodShaderProgram
|
|||||||
* Links the shader program to the current OpenGL context.
|
* Links the shader program to the current OpenGL context.
|
||||||
* @throws Exception Exception if the program failed to link
|
* @throws Exception Exception if the program failed to link
|
||||||
*/
|
*/
|
||||||
public void link() throws Exception
|
public void link()
|
||||||
{
|
{
|
||||||
GL20.glLinkProgram(this.id);
|
GL20.glLinkProgram(this.id);
|
||||||
checkLinkStatus();
|
checkLinkStatus();
|
||||||
@@ -83,11 +83,11 @@ public class LodShaderProgram
|
|||||||
* Checks if the program was linked successfully.
|
* Checks if the program was linked successfully.
|
||||||
* @throws Exception if the program failed to link
|
* @throws Exception if the program failed to link
|
||||||
*/
|
*/
|
||||||
public void checkLinkStatus() throws Exception
|
public void checkLinkStatus()
|
||||||
{
|
{
|
||||||
int status = GL20.glGetProgrami(this.id, GL20.GL_LINK_STATUS);
|
int status = GL20.glGetProgrami(this.id, GL20.GL_LINK_STATUS);
|
||||||
if (status != GL20.GL_TRUE)
|
if (status != GL20.GL_TRUE)
|
||||||
throw new Exception(GL20.glGetProgramInfoLog(this.id));
|
throw new RuntimeException("Shader Link Error. Details: "+GL20.glGetProgramInfoLog(this.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user