tests, datastructure, debug work
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
09341af70c
commit
73a5d79bc2
@ -693,6 +693,16 @@ Update human collidable data
|
||||
(09/05/2024)
|
||||
Fix AI tracking deleted entity
|
||||
|
||||
(09/06/2024)
|
||||
work on debugging framebuffer bug
|
||||
|
||||
(09/07/2024)
|
||||
par_shapes integration
|
||||
|
||||
(09/08/2024)
|
||||
Directed graph datastructure
|
||||
Framebuffer + RenderingEngine tests
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
|
||||
@ -42,7 +42,6 @@ import org.lwjgl.opengl.GL45;
|
||||
import org.lwjgl.opengl.GLCapabilities;
|
||||
import org.lwjgl.opengl.GLDebugMessageCallback;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.NativeType;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
@ -322,8 +321,12 @@ public class RenderingEngine {
|
||||
RenderingEngine.screenTextureColor = screenTextureColor;
|
||||
Texture screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
RenderingEngine.screenTextureDepth = screenTextureDepth;
|
||||
Framebuffer screenFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, screenTextureColor, screenTextureDepth);
|
||||
RenderingEngine.screenFramebuffer = screenFramebuffer;
|
||||
try {
|
||||
Framebuffer screenFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, screenTextureColor, screenTextureDepth);
|
||||
RenderingEngine.screenFramebuffer = screenFramebuffer;
|
||||
} catch (Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
|
||||
defaultFramebuffer.bind(openGLState);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, GL_DEFAULT_RENDERBUFFER);
|
||||
@ -339,8 +342,12 @@ public class RenderingEngine {
|
||||
//
|
||||
lightDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/core/lightDepth/lightDepth.vs", "/Shaders/core/lightDepth/lightDepth.fs");
|
||||
Globals.depthMapShaderProgramLoc = lightDepthShaderProgram.getShaderId();
|
||||
Framebuffer lightDepthBuffer = FramebufferUtils.generateDepthBuffer(openGLState);
|
||||
RenderingEngine.lightDepthBuffer = lightDepthBuffer;
|
||||
try {
|
||||
Framebuffer lightDepthBuffer = FramebufferUtils.generateDepthBuffer(openGLState);
|
||||
RenderingEngine.lightDepthBuffer = lightDepthBuffer;
|
||||
} catch(Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
Texture lightBufferDepthTexture = lightDepthBuffer.getDepthTexture();
|
||||
RenderingEngine.lightBufferDepthTexture = lightBufferDepthTexture;
|
||||
// glEnable(GL_CULL_FACE); // enabled for shadow mapping
|
||||
@ -348,11 +355,15 @@ public class RenderingEngine {
|
||||
//
|
||||
//create volume depth framebuffer/shader for volumetric rendering
|
||||
//
|
||||
volumeDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/core/volumeBuffer/volumetric.vs", "/Shaders/core/volumeBuffer/volumetric.fs");
|
||||
volumeDepthBackfaceTexture = FramebufferUtils.generateDepthBufferTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
volumeDepthBackfaceFramebuffer = FramebufferUtils.generateDepthBuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), volumeDepthBackfaceTexture);
|
||||
volumeDepthFrontfaceTexture = FramebufferUtils.generateDepthBufferTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
volumeDepthFrontfaceFramebuffer = FramebufferUtils.generateDepthBuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), volumeDepthFrontfaceTexture);
|
||||
try {
|
||||
volumeDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/core/volumeBuffer/volumetric.vs", "/Shaders/core/volumeBuffer/volumetric.fs");
|
||||
volumeDepthBackfaceTexture = FramebufferUtils.generateDepthBufferTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
volumeDepthBackfaceFramebuffer = FramebufferUtils.generateDepthBuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), volumeDepthBackfaceTexture);
|
||||
volumeDepthFrontfaceTexture = FramebufferUtils.generateDepthBufferTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
volumeDepthFrontfaceFramebuffer = FramebufferUtils.generateDepthBuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), volumeDepthFrontfaceTexture);
|
||||
} catch(Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
|
||||
//
|
||||
//Game normals
|
||||
@ -362,20 +373,28 @@ public class RenderingEngine {
|
||||
static Framebuffer gameImageNormalsFramebuffer;
|
||||
static ShaderProgram renderNormalsShader;
|
||||
*/
|
||||
gameImageNormalsTexture = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
Texture gameImageNormalsDepthTexture = FramebufferUtils.generateScreenTextureDepth(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
gameImageNormalsFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), gameImageNormalsTexture, gameImageNormalsDepthTexture);
|
||||
renderNormalsShader = ShaderProgram.loadSpecificShader("Shaders/core/anime/renderNormals.vs", "Shaders/core/anime/renderNormals.fs");
|
||||
try {
|
||||
gameImageNormalsTexture = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
Texture gameImageNormalsDepthTexture = FramebufferUtils.generateScreenTextureDepth(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
gameImageNormalsFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), gameImageNormalsTexture, gameImageNormalsDepthTexture);
|
||||
renderNormalsShader = ShaderProgram.loadSpecificShader("Shaders/core/anime/renderNormals.vs", "Shaders/core/anime/renderNormals.fs");
|
||||
} catch(Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
|
||||
//
|
||||
//Transparency framebuffers
|
||||
//
|
||||
transparencyAccumulatorClear = new float[]{0.0f, 0.0f, 0.0f, 0.0f};
|
||||
transparencyAccumulatorTexture = FramebufferUtils.generateOITAccumulatorTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
transparencyRevealageClear = new float[]{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
transparencyRevealageTexture = FramebufferUtils.generateOITRevealageTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
transparencyBuffer = FramebufferUtils.generateOITFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), transparencyAccumulatorTexture, transparencyRevealageTexture, screenTextureDepth);
|
||||
oitCompositeProgram = ShaderProgram.loadSpecificShader("Shaders/core/oit/composite.vs", "Shaders/core/oit/composite.fs");
|
||||
try {
|
||||
transparencyAccumulatorClear = new float[]{0.0f, 0.0f, 0.0f, 0.0f};
|
||||
transparencyAccumulatorTexture = FramebufferUtils.generateOITAccumulatorTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
transparencyRevealageClear = new float[]{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
transparencyRevealageTexture = FramebufferUtils.generateOITRevealageTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
transparencyBuffer = FramebufferUtils.generateOITFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), transparencyAccumulatorTexture, transparencyRevealageTexture, screenTextureDepth);
|
||||
oitCompositeProgram = ShaderProgram.loadSpecificShader("Shaders/core/oit/composite.vs", "Shaders/core/oit/composite.fs");
|
||||
} catch(Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
|
||||
//projection matrices
|
||||
nearVolumeProjectionMatrix.setPerspective((float)(Globals.verticalFOV * Math.PI /180.0f), (float)Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT, 0.1f, 100);
|
||||
@ -388,10 +407,14 @@ public class RenderingEngine {
|
||||
static Framebuffer normalsOutlineFrambuffer;
|
||||
static ShaderProgram normalsOutlineShader;
|
||||
*/
|
||||
normalsOutlineTexture = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
normalsOutlineFrambuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), normalsOutlineTexture);
|
||||
// normalsOutlineShader = ShaderProgram.loadSpecificShader("Shaders/anime/outlineNormals.vs", "Shaders/anime/outlineNormals.fs");
|
||||
Globals.assetManager.addShaderToQueue("Shaders/core/anime/outlineNormals.vs", "Shaders/core/anime/outlineNormals.fs");
|
||||
try {
|
||||
normalsOutlineTexture = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
normalsOutlineFrambuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), normalsOutlineTexture);
|
||||
// normalsOutlineShader = ShaderProgram.loadSpecificShader("Shaders/anime/outlineNormals.vs", "Shaders/anime/outlineNormals.fs");
|
||||
Globals.assetManager.addShaderToQueue("Shaders/core/anime/outlineNormals.vs", "Shaders/core/anime/outlineNormals.fs");
|
||||
} catch(Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
|
||||
//
|
||||
//Compositing shaders
|
||||
|
||||
@ -106,8 +106,9 @@ public class Framebuffer {
|
||||
/**
|
||||
* Checks the status of the framebuffer
|
||||
* @param openGLState The opengl state
|
||||
* @throws Exception
|
||||
*/
|
||||
public void shouldBeComplete(OpenGLState openGLState){
|
||||
public void shouldBeComplete(OpenGLState openGLState) throws Exception{
|
||||
if(!this.isComplete(openGLState)){
|
||||
int colorAttach0 = GL45.glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL45.GL_COLOR_ATTACHMENT0, GL45.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
|
||||
String attach0Type = "";
|
||||
@ -134,7 +135,7 @@ public class Framebuffer {
|
||||
"attach0 Dims: " + width + "," + height + "\n" +
|
||||
"Depth: " + this.depthTexture + "\n"
|
||||
;
|
||||
LoggerInterface.loggerEngine.ERROR(new Exception(message));
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,6 @@ import org.lwjgl.opengl.GL45;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_COMPONENT;
|
||||
import static org.lwjgl.opengl.GL11.GL_FLOAT;
|
||||
import static org.lwjgl.opengl.GL11.GL_FRONT;
|
||||
import static org.lwjgl.opengl.GL11.GL_LINEAR;
|
||||
import static org.lwjgl.opengl.GL11.GL_NEAREST;
|
||||
import static org.lwjgl.opengl.GL11.GL_NONE;
|
||||
@ -24,7 +23,6 @@ import static org.lwjgl.opengl.GL11.GL_SHORT;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T;
|
||||
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
|
||||
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_INT;
|
||||
import static org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE;
|
||||
import static org.lwjgl.opengl.GL13.GL_CLAMP_TO_BORDER;
|
||||
import static org.lwjgl.opengl.GL30.GL_COLOR_ATTACHMENT0;
|
||||
@ -38,8 +36,6 @@ import static org.lwjgl.opengl.GL30.glBindRenderbuffer;
|
||||
import static org.lwjgl.opengl.GL30.glFramebufferRenderbuffer;
|
||||
import static org.lwjgl.opengl.GL30.glGenRenderbuffers;
|
||||
import static org.lwjgl.opengl.GL30.glRenderbufferStorage;
|
||||
import static org.lwjgl.opengl.GL40.GL_DEPTH_COMPONENT;
|
||||
import static org.lwjgl.opengl.GL40.GL_FLOAT;
|
||||
import static org.lwjgl.opengl.GL45.glNamedFramebufferDrawBuffer;
|
||||
import static org.lwjgl.opengl.GL45.glNamedFramebufferDrawBuffers;
|
||||
import static org.lwjgl.opengl.GL45.glNamedFramebufferReadBuffer;
|
||||
@ -81,7 +77,7 @@ public class FramebufferUtils {
|
||||
|
||||
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
|
||||
texture.bind(openGLState);
|
||||
openGLState.glBindTextureUnitForce(0, Texture.DEFAULT_TEXTURE, GL40.GL_TEXTURE_2D);
|
||||
openGLState.glBindTextureUnitForce(GL45.GL_TEXTURE0, Texture.DEFAULT_TEXTURE, GL40.GL_TEXTURE_2D);
|
||||
|
||||
texture.checkStatus(openGLState);
|
||||
return texture;
|
||||
@ -101,14 +97,14 @@ public class FramebufferUtils {
|
||||
|
||||
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
|
||||
texture.bind(openGLState);
|
||||
openGLState.glBindTextureUnitForce(0, Texture.DEFAULT_TEXTURE, GL40.GL_TEXTURE_2D);
|
||||
openGLState.glBindTextureUnitForce(GL45.GL_TEXTURE0, Texture.DEFAULT_TEXTURE, GL40.GL_TEXTURE_2D);
|
||||
|
||||
texture.checkStatus(openGLState);
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
||||
public static Framebuffer generateScreenTextureFramebuffer(OpenGLState openGLState, int width, int height, Texture colorTexture, Texture depthTexture){
|
||||
public static Framebuffer generateScreenTextureFramebuffer(OpenGLState openGLState, int width, int height, Texture colorTexture, Texture depthTexture) throws Exception {
|
||||
Framebuffer buffer = new Framebuffer();
|
||||
//bind texture to fbo
|
||||
buffer.setMipMapLevel(0);
|
||||
@ -122,7 +118,7 @@ public class FramebufferUtils {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static Framebuffer generateScreenTextureFramebuffer(OpenGLState openGLState, int width, int height, Texture colorTexture){
|
||||
public static Framebuffer generateScreenTextureFramebuffer(OpenGLState openGLState, int width, int height, Texture colorTexture) throws Exception {
|
||||
Framebuffer buffer = new Framebuffer();
|
||||
//bind texture to fbo
|
||||
buffer.setMipMapLevel(0);
|
||||
@ -132,7 +128,7 @@ public class FramebufferUtils {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static Framebuffer generateScreensizeTextureFramebuffer(OpenGLState openGLState){
|
||||
public static Framebuffer generateScreensizeTextureFramebuffer(OpenGLState openGLState) throws Exception {
|
||||
Framebuffer buffer = new Framebuffer();
|
||||
buffer.bind(openGLState);
|
||||
//texture
|
||||
@ -162,7 +158,7 @@ public class FramebufferUtils {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static Framebuffer generateTextureFramebuffer(OpenGLState openGLState, int width, int height){
|
||||
public static Framebuffer generateTextureFramebuffer(OpenGLState openGLState, int width, int height) throws Exception {
|
||||
Framebuffer buffer = new Framebuffer();
|
||||
buffer.bind(openGLState);
|
||||
//texture
|
||||
@ -207,7 +203,7 @@ public class FramebufferUtils {
|
||||
}
|
||||
|
||||
|
||||
public static Framebuffer generateDepthBuffer(OpenGLState openGLState){
|
||||
public static Framebuffer generateDepthBuffer(OpenGLState openGLState) throws Exception {
|
||||
Framebuffer buffer = new Framebuffer();
|
||||
buffer.bind(openGLState);
|
||||
|
||||
@ -251,7 +247,7 @@ public class FramebufferUtils {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static Framebuffer generateDepthBuffer(OpenGLState openGLState, int width, int height, Texture texture){
|
||||
public static Framebuffer generateDepthBuffer(OpenGLState openGLState, int width, int height, Texture texture) throws Exception {
|
||||
Framebuffer buffer = new Framebuffer();
|
||||
buffer.bind(openGLState);
|
||||
|
||||
@ -290,7 +286,7 @@ public class FramebufferUtils {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static Framebuffer generateOITFramebuffer(OpenGLState openGLState, int width, int height, Texture accumulatorTex, Texture revealageTex, Texture depthTexture){
|
||||
public static Framebuffer generateOITFramebuffer(OpenGLState openGLState, int width, int height, Texture accumulatorTex, Texture revealageTex, Texture depthTexture) throws Exception {
|
||||
Framebuffer buffer = new Framebuffer();
|
||||
buffer.bind(openGLState);
|
||||
|
||||
|
||||
@ -58,7 +58,11 @@ public class ActorPanel extends StandardElement implements DrawableElement, Drag
|
||||
|
||||
public ActorPanel(OpenGLState openGLState, int x, int y, int width, int height, Actor actor){
|
||||
super();
|
||||
elementBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
|
||||
try {
|
||||
elementBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
|
||||
} catch(Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
customMat.setTexturePointer(elementBuffer.getTexture().getTexturePointer());
|
||||
this.actor = actor;
|
||||
this.internalPositionX = x;
|
||||
|
||||
@ -37,7 +37,11 @@ public class ScrollableContainer extends StandardContainerElement implements Dra
|
||||
|
||||
public ScrollableContainer(OpenGLState openGLState, int positionX, int positionY, int width, int height){
|
||||
super();
|
||||
widgetBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
|
||||
try {
|
||||
widgetBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
|
||||
} catch(Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
// widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
|
||||
customMat.setTexturePointer(widgetBuffer.getTexture().getTexturePointer());
|
||||
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer());
|
||||
|
||||
@ -71,7 +71,11 @@ public class Window implements DrawableElement, ContainerElement, NavigableEleme
|
||||
* @param height
|
||||
*/
|
||||
public Window(OpenGLState openGLState, int positionX, int positionY, int width, int height, boolean showDecorations){
|
||||
widgetBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
|
||||
try {
|
||||
widgetBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
|
||||
} catch(Exception e){
|
||||
LoggerInterface.loggerRenderer.ERROR(e);
|
||||
}
|
||||
customMat.setTexturePointer(widgetBuffer.getTexture().getTexturePointer());
|
||||
float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
|
||||
float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
|
||||
|
||||
10
src/main/java/electrosphere/server/gen/DungeonGen.java
Normal file
10
src/main/java/electrosphere/server/gen/DungeonGen.java
Normal file
@ -0,0 +1,10 @@
|
||||
package electrosphere.server.gen;
|
||||
|
||||
/**
|
||||
* Generates dungeons
|
||||
*/
|
||||
public class DungeonGen {
|
||||
|
||||
|
||||
|
||||
}
|
||||
161
src/main/java/electrosphere/util/ds/DirectedGraph.java
Normal file
161
src/main/java/electrosphere/util/ds/DirectedGraph.java
Normal file
@ -0,0 +1,161 @@
|
||||
package electrosphere.util.ds;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A directed graph
|
||||
*/
|
||||
public class DirectedGraph {
|
||||
|
||||
/**
|
||||
* The list of nodes in the graph
|
||||
*/
|
||||
List<GraphNode> nodes;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public DirectedGraph(){
|
||||
this.nodes = new LinkedList<GraphNode>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a node in the graph
|
||||
* @param data The data in the node
|
||||
* @return The node
|
||||
*/
|
||||
public GraphNode createNode(Object data){
|
||||
GraphNode rVal = new GraphNode();
|
||||
this.nodes.add(rVal);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds direction as a neighbor of source. Does not create a connection from direction to source
|
||||
* @param source The source node
|
||||
* @param direction The destination node
|
||||
*/
|
||||
public void pointNode(GraphNode source, GraphNode direction){
|
||||
if(!source.containsNeighbor(direction)){
|
||||
source.addNeighbor(direction);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutually connects two nodes
|
||||
* @param node1 Node 1
|
||||
* @param node2 Node 2
|
||||
*/
|
||||
public void connectNodes(GraphNode node1, GraphNode node2){
|
||||
if(!node1.containsNeighbor(node2)){
|
||||
node1.addNeighbor(node2);
|
||||
}
|
||||
if(!node2.containsNeighbor(node1)){
|
||||
node2.addNeighbor(node1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a node
|
||||
* @param node The node to destroy
|
||||
*/
|
||||
public void destroyNode(GraphNode node){
|
||||
for(GraphNode toEval : this.nodes){
|
||||
if(toEval != node){
|
||||
if(toEval.containsNeighbor(node)){
|
||||
toEval.removeNeighbor(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.nodes.remove(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nodes in the graph
|
||||
* @return The list of all nodes in the graph
|
||||
*/
|
||||
public List<GraphNode> getNodes(){
|
||||
return Collections.unmodifiableList(this.nodes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A node in a graph
|
||||
*/
|
||||
public static class GraphNode {
|
||||
|
||||
/**
|
||||
* The data at the node
|
||||
*/
|
||||
Object data;
|
||||
|
||||
/**
|
||||
* The neighbors of this graph node
|
||||
*/
|
||||
List<GraphNode> neighbors;
|
||||
|
||||
/**
|
||||
* Creates a graph node
|
||||
* @param data The data to put in the node
|
||||
*/
|
||||
public GraphNode(Object data){
|
||||
this.data = data;
|
||||
this.neighbors = new LinkedList<GraphNode>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty graph node
|
||||
*/
|
||||
public GraphNode(){
|
||||
this.data = null;
|
||||
this.neighbors = new LinkedList<GraphNode>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data at this node
|
||||
* @return The data
|
||||
*/
|
||||
public Object getData(){
|
||||
return this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the neighbors of this node
|
||||
* @return The list of neighbors
|
||||
*/
|
||||
public List<GraphNode> getNeighbors(){
|
||||
return this.neighbors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a neighbor to this node
|
||||
* @param neighbor The neighbor
|
||||
*/
|
||||
public void addNeighbor(GraphNode neighbor){
|
||||
this.neighbors.add(neighbor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a neighbor from this node
|
||||
* @param neighbor THe neighbor
|
||||
*/
|
||||
public void removeNeighbor(GraphNode neighbor){
|
||||
this.neighbors.remove(neighbor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this node contains a given node as a neighbor
|
||||
* @param node The potential neighbor to check
|
||||
* @return true if the node is a neighbor, false otherwise
|
||||
*/
|
||||
public boolean containsNeighbor(GraphNode node){
|
||||
return this.neighbors.contains(node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package electrosphere.renderer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.test.template.extensions.StateCleanupCheckerExtension;
|
||||
|
||||
/**
|
||||
* Tests for the core rendering engine
|
||||
*/
|
||||
@ExtendWith(StateCleanupCheckerExtension.class)
|
||||
public class RenderingEngineTests {
|
||||
|
||||
@Test
|
||||
public void testRenderingEngineResetsAllState(){
|
||||
assertDoesNotThrow(() -> {
|
||||
for(int i = 0; i < 5; i++){
|
||||
Globals.initGlobals();
|
||||
Globals.renderingEngine = new RenderingEngine();
|
||||
Globals.renderingEngine.createOpenglContext();
|
||||
Globals.renderingEngine.destroy();
|
||||
Globals.resetGlobals();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package electrosphere.renderer.framebuffer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.renderer.RenderingEngine;
|
||||
import electrosphere.renderer.texture.Texture;
|
||||
import electrosphere.test.template.extensions.StateCleanupCheckerExtension;
|
||||
|
||||
/**
|
||||
* Tests for framebuffer creation utilities
|
||||
*/
|
||||
@ExtendWith(StateCleanupCheckerExtension.class)
|
||||
public class FramebufferUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testCreateScreenFramebuffer(){
|
||||
Globals.initGlobals();
|
||||
Globals.renderingEngine = new RenderingEngine();
|
||||
Globals.renderingEngine.createOpenglContext();
|
||||
assertDoesNotThrow(() -> {
|
||||
Texture screenTextureColor = FramebufferUtils.generateScreenTextureColorAlpha(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
RenderingEngine.screenTextureColor = screenTextureColor;
|
||||
Texture screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
RenderingEngine.screenTextureDepth = screenTextureDepth;
|
||||
Framebuffer screenFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, screenTextureColor, screenTextureDepth);
|
||||
RenderingEngine.screenFramebuffer = screenFramebuffer;
|
||||
});
|
||||
Globals.renderingEngine.destroy();
|
||||
Globals.resetGlobals();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateScreenFramebufferRepeat(){
|
||||
assertDoesNotThrow(() -> {
|
||||
Globals.initGlobals();
|
||||
Globals.renderingEngine = new RenderingEngine();
|
||||
Globals.renderingEngine.createOpenglContext();
|
||||
Texture screenTextureColor = FramebufferUtils.generateScreenTextureColorAlpha(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
Texture screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
FramebufferUtils.generateScreenTextureFramebuffer(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, screenTextureColor, screenTextureDepth);
|
||||
Globals.renderingEngine.destroy();
|
||||
Globals.resetGlobals();
|
||||
|
||||
Globals.initGlobals();
|
||||
Globals.renderingEngine = new RenderingEngine();
|
||||
Globals.renderingEngine.createOpenglContext();
|
||||
screenTextureColor = FramebufferUtils.generateScreenTextureColorAlpha(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
FramebufferUtils.generateScreenTextureFramebuffer(Globals.renderingEngine.getOpenGLState(), Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, screenTextureColor, screenTextureDepth);
|
||||
Globals.renderingEngine.destroy();
|
||||
Globals.resetGlobals();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
115
src/test/java/electrosphere/util/ds/DirectedGraphUnitTests.java
Normal file
115
src/test/java/electrosphere/util/ds/DirectedGraphUnitTests.java
Normal file
@ -0,0 +1,115 @@
|
||||
package electrosphere.util.ds;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import electrosphere.test.annotations.FastTest;
|
||||
import electrosphere.test.annotations.UnitTest;
|
||||
import electrosphere.util.ds.DirectedGraph.GraphNode;
|
||||
|
||||
/**
|
||||
* Unit tests for the directed graph implementation
|
||||
*/
|
||||
public class DirectedGraphUnitTests {
|
||||
|
||||
|
||||
//
|
||||
//Graph-specific tests
|
||||
//
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testCreateGraph(){
|
||||
DirectedGraph graph = new DirectedGraph();
|
||||
assertNotNull(graph);
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testCreateEntry(){
|
||||
DirectedGraph graph = new DirectedGraph();
|
||||
GraphNode node = graph.createNode(null);
|
||||
assertNotNull(node);
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testContainsEntryNotNull(){
|
||||
DirectedGraph graph = new DirectedGraph();
|
||||
graph.createNode(null);
|
||||
assertNotNull(graph.getNodes());
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testContainsEntryHasEntry(){
|
||||
DirectedGraph graph = new DirectedGraph();
|
||||
graph.createNode(null);
|
||||
assertEquals(1,graph.getNodes().size());
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testDeleteNode(){
|
||||
DirectedGraph graph = new DirectedGraph();
|
||||
GraphNode node = graph.createNode(null);
|
||||
graph.destroyNode(node);
|
||||
assertEquals(0,graph.getNodes().size());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Node-specific tests
|
||||
//
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testCreateNode(){
|
||||
GraphNode node = new GraphNode();
|
||||
assertNotNull(node);
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testNodeGetData(){
|
||||
GraphNode node = new GraphNode("some data");
|
||||
assertEquals("some data", node.getData());
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testAddNeighbor(){
|
||||
GraphNode node = new GraphNode();
|
||||
GraphNode neighbor = new GraphNode();
|
||||
node.addNeighbor(neighbor);
|
||||
assertEquals(neighbor, node.getNeighbors().get(0));
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testRemoveNeighbor(){
|
||||
GraphNode node = new GraphNode();
|
||||
GraphNode neighbor = new GraphNode();
|
||||
node.addNeighbor(neighbor);
|
||||
node.removeNeighbor(neighbor);
|
||||
assertEquals(0, node.getNeighbors().size());
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testGetNeighbors(){
|
||||
GraphNode node = new GraphNode();
|
||||
GraphNode neighbor = new GraphNode();
|
||||
node.addNeighbor(neighbor);
|
||||
assertEquals(1, node.getNeighbors().size());
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void testContainsNeighbor(){
|
||||
GraphNode node = new GraphNode();
|
||||
GraphNode neighbor = new GraphNode();
|
||||
node.addNeighbor(neighbor);
|
||||
assertEquals(true, node.containsNeighbor(neighbor));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user