framebuffer bug hunt 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
5cce5e5ac1
commit
df3010f38a
@ -434,8 +434,6 @@ public class Main {
|
|||||||
//
|
//
|
||||||
//Terminate the program.
|
//Terminate the program.
|
||||||
if(Globals.renderingEngine != null){
|
if(Globals.renderingEngine != null){
|
||||||
glfwTerminate();
|
|
||||||
Globals.renderingEngine.clearGlobalState();
|
|
||||||
Globals.renderingEngine.destroy();
|
Globals.renderingEngine.destroy();
|
||||||
}
|
}
|
||||||
//used to signal threads to stop
|
//used to signal threads to stop
|
||||||
|
|||||||
@ -153,6 +153,21 @@ public class OpenGLState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a texture to a given texture unit if the texture hasn't already been bound to that unit
|
||||||
|
* @param textureUnit The texture unit
|
||||||
|
* @param texturePointer The texture pointer
|
||||||
|
* @param textureType the type of texture (2d, 3d, etc)
|
||||||
|
*/
|
||||||
|
public void glBindTextureUnitForce(int textureUnit, int texturePointer, int textureType){
|
||||||
|
unitToPointerMap.put(textureUnit,texturePointer);
|
||||||
|
this.activeTexture = textureUnit;
|
||||||
|
GL40.glActiveTexture(this.activeTexture);
|
||||||
|
Globals.renderingEngine.checkError();
|
||||||
|
GL40.glBindTexture(textureType,texturePointer);
|
||||||
|
Globals.renderingEngine.checkError();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds a framebuffer
|
* Binds a framebuffer
|
||||||
* @param framebufferType the type of framebuffer (vanilla, renderbuffer, etc)
|
* @param framebufferType the type of framebuffer (vanilla, renderbuffer, etc)
|
||||||
|
|||||||
@ -38,6 +38,11 @@ import org.lwjgl.glfw.GLFWErrorCallback;
|
|||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.lwjgl.opengl.GL30;
|
import org.lwjgl.opengl.GL30;
|
||||||
|
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.engine.Globals;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
@ -186,12 +191,18 @@ public class RenderingEngine {
|
|||||||
|
|
||||||
//
|
//
|
||||||
//set error callback
|
//set error callback
|
||||||
GLFW.glfwSetErrorCallback(GLFWErrorCallback.createThrow());
|
// GLFWErrorCallback
|
||||||
|
GLFW.glfwSetErrorCallback((int error, long descriptionPtr) -> {
|
||||||
|
String description = GLFWErrorCallback.getDescription(descriptionPtr);
|
||||||
|
System.err.println(description);
|
||||||
|
});
|
||||||
|
|
||||||
//Initializes opengl
|
//Initializes opengl
|
||||||
boolean glfwInited = glfwInit();
|
boolean glfwInited = glfwInit();
|
||||||
if(!glfwInited){
|
if(!glfwInited){
|
||||||
throw new IllegalStateException("Failed to initialize glfw!");
|
String message = "Failed to initialize glfw!\n" +
|
||||||
|
"Error code: " + this.getGLFWErrorMessage(this.getGLFWError());
|
||||||
|
throw new IllegalStateException(message);
|
||||||
}
|
}
|
||||||
//Gives hints to glfw to control how opengl will be used
|
//Gives hints to glfw to control how opengl will be used
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||||
@ -216,9 +227,13 @@ public class RenderingEngine {
|
|||||||
}
|
}
|
||||||
// Errors for failure to create window (IE: No GUI mode on linux ?)
|
// Errors for failure to create window (IE: No GUI mode on linux ?)
|
||||||
if (Globals.window == NULL) {
|
if (Globals.window == NULL) {
|
||||||
LoggerInterface.loggerEngine.ERROR("Failed to make window.", new Exception("Renderer Creation Failure"));
|
String message = "Failed to create window!\n" +
|
||||||
|
"Error code: " + this.getGLFWErrorMessage(this.getGLFWError());
|
||||||
|
;
|
||||||
|
LoggerInterface.loggerEngine.ERROR(new Exception(message));
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
//set resize callback
|
//set resize callback
|
||||||
GLFW.glfwSetWindowSizeCallback(Globals.window, (long window, int width, int height) -> {
|
GLFW.glfwSetWindowSizeCallback(Globals.window, (long window, int width, int height) -> {
|
||||||
Globals.WINDOW_HEIGHT = height;
|
Globals.WINDOW_HEIGHT = height;
|
||||||
@ -228,6 +243,7 @@ public class RenderingEngine {
|
|||||||
glfwMakeContextCurrent(Globals.window);
|
glfwMakeContextCurrent(Globals.window);
|
||||||
//Maximize it
|
//Maximize it
|
||||||
glfwMaximizeWindow(Globals.window);
|
glfwMaximizeWindow(Globals.window);
|
||||||
|
GLFW.glfwPollEvents();
|
||||||
//grab actual framebuffer
|
//grab actual framebuffer
|
||||||
IntBuffer xBuffer = BufferUtils.createIntBuffer(1);
|
IntBuffer xBuffer = BufferUtils.createIntBuffer(1);
|
||||||
IntBuffer yBuffer = BufferUtils.createIntBuffer(1);
|
IntBuffer yBuffer = BufferUtils.createIntBuffer(1);
|
||||||
@ -255,8 +271,17 @@ public class RenderingEngine {
|
|||||||
//get title bar dimensions
|
//get title bar dimensions
|
||||||
// setTitleBarDimensions();
|
// setTitleBarDimensions();
|
||||||
|
|
||||||
//Creates the OpenGL capabilities for the program.
|
//Creates the OpenGL capabilities for the program.)
|
||||||
GL.createCapabilities();
|
GLCapabilities glCapabilities = GL.createCapabilities();
|
||||||
|
|
||||||
|
GL45.glEnable(GL45.GL_DEBUG_OUTPUT);
|
||||||
|
//register error callback
|
||||||
|
GL45.glDebugMessageCallback((int source, int type, int id, int severity, int length, long messagePtr, long userParam) -> {
|
||||||
|
if(type == GL45.GL_DEBUG_TYPE_ERROR){
|
||||||
|
String message = GLDebugMessageCallback.getMessage(length, messagePtr);
|
||||||
|
System.err.println(message);
|
||||||
|
}
|
||||||
|
}, bufferHeight);
|
||||||
|
|
||||||
//get environment constraints
|
//get environment constraints
|
||||||
openGLState.storeCurrentEnvironmentContraints();
|
openGLState.storeCurrentEnvironmentContraints();
|
||||||
@ -290,11 +315,16 @@ public class RenderingEngine {
|
|||||||
|
|
||||||
//default framebuffer
|
//default framebuffer
|
||||||
defaultFramebuffer = new Framebuffer(GL_DEFAULT_FRAMEBUFFER);
|
defaultFramebuffer = new Framebuffer(GL_DEFAULT_FRAMEBUFFER);
|
||||||
|
defaultFramebuffer.bind(openGLState);
|
||||||
|
|
||||||
//generate framebuffers
|
//generate framebuffers
|
||||||
screenTextureColor = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
Texture screenTextureColor = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||||
screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
RenderingEngine.screenTextureColor = screenTextureColor;
|
||||||
screenFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, screenTextureColor, screenTextureDepth);
|
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;
|
||||||
|
|
||||||
defaultFramebuffer.bind(openGLState);
|
defaultFramebuffer.bind(openGLState);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, GL_DEFAULT_RENDERBUFFER);
|
glBindRenderbuffer(GL_RENDERBUFFER, GL_DEFAULT_RENDERBUFFER);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
@ -309,8 +339,10 @@ public class RenderingEngine {
|
|||||||
//
|
//
|
||||||
lightDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/core/lightDepth/lightDepth.vs", "/Shaders/core/lightDepth/lightDepth.fs");
|
lightDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/core/lightDepth/lightDepth.vs", "/Shaders/core/lightDepth/lightDepth.fs");
|
||||||
Globals.depthMapShaderProgramLoc = lightDepthShaderProgram.getShaderId();
|
Globals.depthMapShaderProgramLoc = lightDepthShaderProgram.getShaderId();
|
||||||
lightDepthBuffer = FramebufferUtils.generateDepthBuffer(openGLState);
|
Framebuffer lightDepthBuffer = FramebufferUtils.generateDepthBuffer(openGLState);
|
||||||
lightBufferDepthTexture = lightDepthBuffer.getDepthTexture();
|
RenderingEngine.lightDepthBuffer = lightDepthBuffer;
|
||||||
|
Texture lightBufferDepthTexture = lightDepthBuffer.getDepthTexture();
|
||||||
|
RenderingEngine.lightBufferDepthTexture = lightBufferDepthTexture;
|
||||||
// glEnable(GL_CULL_FACE); // enabled for shadow mapping
|
// glEnable(GL_CULL_FACE); // enabled for shadow mapping
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -409,15 +441,6 @@ public class RenderingEngine {
|
|||||||
Globals.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
|
Globals.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
|
||||||
Globals.viewMatrix.translation(new Vector3f(0.0f,0.0f,-3.0f));
|
Globals.viewMatrix.translation(new Vector3f(0.0f,0.0f,-3.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears global, static state
|
|
||||||
*/
|
|
||||||
public void clearGlobalState(){
|
|
||||||
screenTextureColor = null;
|
|
||||||
screenTextureDepth = null;
|
|
||||||
screenFramebuffer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -656,6 +679,34 @@ public class RenderingEngine {
|
|||||||
return lastCode;
|
return lastCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the most recent GLFW Error
|
||||||
|
* @return The most recent GLFW error
|
||||||
|
*/
|
||||||
|
public int getGLFWError(){
|
||||||
|
int lastCode = 0;
|
||||||
|
try (MemoryStack stack = MemoryStack.stackPush()){
|
||||||
|
lastCode = GLFW.glfwGetError(stack.callocPointer(1));
|
||||||
|
}
|
||||||
|
return lastCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the glfw error code
|
||||||
|
* @param code The code
|
||||||
|
* @return The decoded message
|
||||||
|
*/
|
||||||
|
public String getGLFWErrorMessage(int code){
|
||||||
|
switch(code){
|
||||||
|
case GLFW.GLFW_INVALID_ENUM:
|
||||||
|
return "GLFW_INVALID_ENUM";
|
||||||
|
case GLFW.GLFW_INVALID_VALUE:
|
||||||
|
return "GLFW_INVALID_VALUE";
|
||||||
|
default:
|
||||||
|
return "Unhandled value!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if pipelines should run
|
* Checks if pipelines should run
|
||||||
* @return true if should render, false otherwise
|
* @return true if should render, false otherwise
|
||||||
@ -671,7 +722,83 @@ public class RenderingEngine {
|
|||||||
* Destroys the rendering engine
|
* Destroys the rendering engine
|
||||||
*/
|
*/
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
|
|
||||||
|
//free framebuffers
|
||||||
|
if(screenFramebuffer != null){
|
||||||
|
screenFramebuffer.free();
|
||||||
|
}
|
||||||
|
if(screenRenderbuffer != null){
|
||||||
|
screenRenderbuffer.free();
|
||||||
|
}
|
||||||
|
if(gameImageNormalsFramebuffer != null){
|
||||||
|
gameImageNormalsFramebuffer.free();
|
||||||
|
}
|
||||||
|
if(lightDepthBuffer != null){
|
||||||
|
lightDepthBuffer.free();
|
||||||
|
}
|
||||||
|
if(transparencyBuffer != null){
|
||||||
|
transparencyBuffer.free();
|
||||||
|
}
|
||||||
|
if(volumeDepthBackfaceFramebuffer != null){
|
||||||
|
volumeDepthBackfaceFramebuffer.free();
|
||||||
|
}
|
||||||
|
if(volumeDepthFrontfaceFramebuffer != null){
|
||||||
|
volumeDepthFrontfaceFramebuffer.free();
|
||||||
|
}
|
||||||
|
if(normalsOutlineFrambuffer != null){
|
||||||
|
normalsOutlineFrambuffer.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
//null out
|
||||||
|
screenFramebuffer = null;
|
||||||
|
screenRenderbuffer = null;
|
||||||
|
gameImageNormalsFramebuffer = null;
|
||||||
|
lightDepthBuffer = null;
|
||||||
|
transparencyBuffer = null;
|
||||||
|
volumeDepthBackfaceFramebuffer = null;
|
||||||
|
volumeDepthFrontfaceFramebuffer = null;
|
||||||
|
normalsOutlineFrambuffer = null;
|
||||||
|
|
||||||
|
|
||||||
|
//free textures
|
||||||
|
if(screenTextureColor != null){
|
||||||
|
screenTextureColor.free();
|
||||||
|
}
|
||||||
|
if(screenTextureDepth != null){
|
||||||
|
screenTextureDepth.free();
|
||||||
|
}
|
||||||
|
if(gameImageNormalsTexture != null){
|
||||||
|
gameImageNormalsTexture.free();
|
||||||
|
}
|
||||||
|
if(lightBufferDepthTexture != null){
|
||||||
|
lightBufferDepthTexture.free();
|
||||||
|
}
|
||||||
|
if(transparencyRevealageTexture != null){
|
||||||
|
transparencyRevealageTexture.free();
|
||||||
|
}
|
||||||
|
if(volumeDepthBackfaceTexture != null){
|
||||||
|
volumeDepthBackfaceTexture.free();
|
||||||
|
}
|
||||||
|
if(volumeDepthFrontfaceTexture != null){
|
||||||
|
volumeDepthFrontfaceTexture.free();
|
||||||
|
}
|
||||||
|
if(normalsOutlineTexture != null){
|
||||||
|
normalsOutlineTexture.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
//null out
|
||||||
|
screenTextureColor = null;
|
||||||
|
screenTextureDepth = null;
|
||||||
|
gameImageNormalsTexture = null;
|
||||||
|
lightBufferDepthTexture = null;
|
||||||
|
transparencyRevealageTexture = null;
|
||||||
|
volumeDepthBackfaceTexture = null;
|
||||||
|
volumeDepthFrontfaceTexture = null;
|
||||||
|
normalsOutlineTexture = null;
|
||||||
|
|
||||||
|
//end glfw
|
||||||
|
GLFW.glfwDestroyWindow(Globals.window);
|
||||||
|
GLFW.glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -14,8 +14,12 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL40;
|
import org.lwjgl.opengl.GL40;
|
||||||
|
import org.lwjgl.opengl.GL45;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_NONE;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_TEXTURE;
|
||||||
|
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
|
||||||
import static org.lwjgl.opengl.GL45.glCheckNamedFramebufferStatus;
|
import static org.lwjgl.opengl.GL45.glCheckNamedFramebufferStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,29 +95,46 @@ public class Framebuffer {
|
|||||||
* Checks if the framebuffer compiled correctly
|
* Checks if the framebuffer compiled correctly
|
||||||
* @return true if compiled correctly, false otherwise
|
* @return true if compiled correctly, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isComplete(){
|
public boolean isComplete(OpenGLState openGLState){
|
||||||
return glCheckNamedFramebufferStatus(framebufferPointer,GL40.GL_FRAMEBUFFER) == GL40.GL_FRAMEBUFFER_COMPLETE;
|
if(this.framebufferPointer == DEFAULT_FRAMEBUFFER_POINTER){
|
||||||
|
throw new Error("Pointer is the default framebuffer!");
|
||||||
|
}
|
||||||
|
return glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER) == GL40.GL_FRAMEBUFFER_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the framebuffer has an error
|
|
||||||
* @return true if error, false otherwise
|
|
||||||
*/
|
|
||||||
public boolean isError(){
|
|
||||||
return glCheckNamedFramebufferStatus(framebufferPointer,GL40.GL_FRAMEBUFFER) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the status of the framebuffer
|
* Checks the status of the framebuffer
|
||||||
|
* @param openGLState The opengl state
|
||||||
*/
|
*/
|
||||||
public void checkStatus(){
|
public void shouldBeComplete(OpenGLState openGLState){
|
||||||
if(this.isError()){
|
if(!this.isComplete(openGLState)){
|
||||||
LoggerInterface.loggerRenderer.WARNING("Framebuffer [glError] - " + RenderingEngine.getErrorInEnglish(Globals.renderingEngine.getError()));
|
int colorAttach0 = GL45.glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL45.GL_COLOR_ATTACHMENT0, GL45.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
|
||||||
LoggerInterface.loggerRenderer.WARNING("Framebuffer [status] - " + this.getStatus());
|
String attach0Type = "";
|
||||||
} else if(!this.isComplete()){
|
switch(colorAttach0){
|
||||||
LoggerInterface.loggerRenderer.WARNING("Framebuffer [glError] - " + RenderingEngine.getErrorInEnglish(Globals.renderingEngine.getError()));
|
case GL_NONE: {
|
||||||
LoggerInterface.loggerRenderer.WARNING("Framebuffer [status] - " + this.getStatus());
|
attach0Type = "GL_NONE";
|
||||||
LoggerInterface.loggerRenderer.ERROR("Failed to build framebuffer", new IllegalStateException("Framebuffer failed to build."));
|
} break;
|
||||||
|
case GL_TEXTURE: {
|
||||||
|
attach0Type = " GL_TEXTURE";
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
this.texture.bind(openGLState);
|
||||||
|
int[] storage = new int[1];
|
||||||
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
|
GL45.glGetTexLevelParameteriv(GL45.GL_TEXTURE_2D, 0, GL45.GL_TEXTURE_WIDTH, storage);
|
||||||
|
width = storage[0];
|
||||||
|
GL45.glGetTexLevelParameteriv(GL45.GL_TEXTURE_2D, 0, GL45.GL_TEXTURE_HEIGHT, storage);
|
||||||
|
height = storage[0];
|
||||||
|
String message = "Framebuffer failed to build.\n" +
|
||||||
|
"Framebuffer [status] - " + this.getStatus() + "\n" +
|
||||||
|
"Texture: " + this.texture + "\n" +
|
||||||
|
"attach0Type: " + attach0Type + "\n" +
|
||||||
|
"attach0 Dims: " + width + "," + height + "\n" +
|
||||||
|
"Depth: " + this.depthTexture + "\n"
|
||||||
|
;
|
||||||
|
LoggerInterface.loggerEngine.ERROR(new Exception(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +157,7 @@ public class Framebuffer {
|
|||||||
* Blocks the thread until the framebuffer has compiled
|
* Blocks the thread until the framebuffer has compiled
|
||||||
*/
|
*/
|
||||||
public void blockUntilCompiled(){
|
public void blockUntilCompiled(){
|
||||||
while(glCheckNamedFramebufferStatus(framebufferPointer,GL40.GL_FRAMEBUFFER) != GL40.GL_FRAMEBUFFER_UNDEFINED){
|
while(glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER) != GL40.GL_FRAMEBUFFER_UNDEFINED){
|
||||||
try {
|
try {
|
||||||
TimeUnit.MILLISECONDS.sleep(1);
|
TimeUnit.MILLISECONDS.sleep(1);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
@ -150,7 +171,7 @@ public class Framebuffer {
|
|||||||
* @return The status
|
* @return The status
|
||||||
*/
|
*/
|
||||||
public String getStatus(){
|
public String getStatus(){
|
||||||
switch(glCheckNamedFramebufferStatus(framebufferPointer,GL40.GL_FRAMEBUFFER)){
|
switch(glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER)){
|
||||||
case GL40.GL_FRAMEBUFFER_UNDEFINED: {
|
case GL40.GL_FRAMEBUFFER_UNDEFINED: {
|
||||||
return "The specified framebuffer is the default read or draw framebuffer, but the default framebuffer does not exist.";
|
return "The specified framebuffer is the default read or draw framebuffer, but the default framebuffer does not exist.";
|
||||||
}
|
}
|
||||||
@ -220,6 +241,15 @@ public class Framebuffer {
|
|||||||
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer);
|
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer);
|
||||||
GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_COLOR_ATTACHMENT0 + attachmentNum, GL40.GL_TEXTURE_2D, texture.getTexturePointer(), 0);
|
GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_COLOR_ATTACHMENT0 + attachmentNum, GL40.GL_TEXTURE_2D, texture.getTexturePointer(), 0);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
|
// check the attachment slot
|
||||||
|
int colorAttach0 = GL45.glGetFramebufferAttachmentParameteri(GL40.GL_FRAMEBUFFER, GL45.GL_COLOR_ATTACHMENT0 + attachmentNum, GL45.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
|
||||||
|
switch(colorAttach0){
|
||||||
|
case GL_NONE: {
|
||||||
|
throw new Error("Failed to attach!");
|
||||||
|
}
|
||||||
|
case GL_TEXTURE: {
|
||||||
|
} break;
|
||||||
|
}
|
||||||
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,9 +9,11 @@ import java.nio.IntBuffer;
|
|||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
import org.lwjgl.opengl.GL40;
|
import org.lwjgl.opengl.GL40;
|
||||||
|
import org.lwjgl.opengl.GL45;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_COMPONENT;
|
import static org.lwjgl.opengl.GL11.GL_DEPTH_COMPONENT;
|
||||||
import static org.lwjgl.opengl.GL11.GL_FLOAT;
|
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_LINEAR;
|
||||||
import static org.lwjgl.opengl.GL11.GL_NEAREST;
|
import static org.lwjgl.opengl.GL11.GL_NEAREST;
|
||||||
import static org.lwjgl.opengl.GL11.GL_NONE;
|
import static org.lwjgl.opengl.GL11.GL_NONE;
|
||||||
@ -22,6 +24,7 @@ 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_S;
|
||||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T;
|
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_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.GL12.GL_CLAMP_TO_EDGE;
|
||||||
import static org.lwjgl.opengl.GL13.GL_CLAMP_TO_BORDER;
|
import static org.lwjgl.opengl.GL13.GL_CLAMP_TO_BORDER;
|
||||||
import static org.lwjgl.opengl.GL30.GL_COLOR_ATTACHMENT0;
|
import static org.lwjgl.opengl.GL30.GL_COLOR_ATTACHMENT0;
|
||||||
@ -35,6 +38,8 @@ import static org.lwjgl.opengl.GL30.glBindRenderbuffer;
|
|||||||
import static org.lwjgl.opengl.GL30.glFramebufferRenderbuffer;
|
import static org.lwjgl.opengl.GL30.glFramebufferRenderbuffer;
|
||||||
import static org.lwjgl.opengl.GL30.glGenRenderbuffers;
|
import static org.lwjgl.opengl.GL30.glGenRenderbuffers;
|
||||||
import static org.lwjgl.opengl.GL30.glRenderbufferStorage;
|
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.glNamedFramebufferDrawBuffer;
|
||||||
import static org.lwjgl.opengl.GL45.glNamedFramebufferDrawBuffers;
|
import static org.lwjgl.opengl.GL45.glNamedFramebufferDrawBuffers;
|
||||||
import static org.lwjgl.opengl.GL45.glNamedFramebufferReadBuffer;
|
import static org.lwjgl.opengl.GL45.glNamedFramebufferReadBuffer;
|
||||||
@ -46,6 +51,7 @@ public class FramebufferUtils {
|
|||||||
|
|
||||||
public static Texture generateScreenTextureColor(OpenGLState openGLState, int width, int height){
|
public static Texture generateScreenTextureColor(OpenGLState openGLState, int width, int height){
|
||||||
Texture texture = new Texture();
|
Texture texture = new Texture();
|
||||||
|
texture.bind(openGLState);
|
||||||
texture.glTexImage2D(openGLState, width, height, GL_RGB, GL_UNSIGNED_BYTE);
|
texture.glTexImage2D(openGLState, width, height, GL_RGB, GL_UNSIGNED_BYTE);
|
||||||
texture.setMinFilter(openGLState, GL_LINEAR);
|
texture.setMinFilter(openGLState, GL_LINEAR);
|
||||||
texture.setMagFilter(openGLState, GL_LINEAR);
|
texture.setMagFilter(openGLState, GL_LINEAR);
|
||||||
@ -64,7 +70,8 @@ public class FramebufferUtils {
|
|||||||
|
|
||||||
public static Texture generateScreenTextureColorAlpha(OpenGLState openGLState, int width, int height){
|
public static Texture generateScreenTextureColorAlpha(OpenGLState openGLState, int width, int height){
|
||||||
Texture texture = new Texture();
|
Texture texture = new Texture();
|
||||||
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE);
|
texture.bind(openGLState);
|
||||||
|
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL45.GL_UNSIGNED_INT_8_8_8_8);
|
||||||
texture.setMinFilter(openGLState, GL_LINEAR);
|
texture.setMinFilter(openGLState, GL_LINEAR);
|
||||||
texture.setMagFilter(openGLState, GL_LINEAR);
|
texture.setMagFilter(openGLState, GL_LINEAR);
|
||||||
//these make sure the texture actually clamps to the borders of the quad
|
//these make sure the texture actually clamps to the borders of the quad
|
||||||
@ -74,7 +81,7 @@ public class FramebufferUtils {
|
|||||||
|
|
||||||
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
|
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
|
||||||
texture.bind(openGLState);
|
texture.bind(openGLState);
|
||||||
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE);
|
openGLState.glBindTextureUnitForce(0, Texture.DEFAULT_TEXTURE, GL40.GL_TEXTURE_2D);
|
||||||
|
|
||||||
texture.checkStatus(openGLState);
|
texture.checkStatus(openGLState);
|
||||||
return texture;
|
return texture;
|
||||||
@ -82,6 +89,7 @@ public class FramebufferUtils {
|
|||||||
|
|
||||||
public static Texture generateScreenTextureDepth(OpenGLState openGLState, int width, int height){
|
public static Texture generateScreenTextureDepth(OpenGLState openGLState, int width, int height){
|
||||||
Texture texture = new Texture();
|
Texture texture = new Texture();
|
||||||
|
texture.bind(openGLState);
|
||||||
texture.glTexImage2D(openGLState, width, height, GL_DEPTH_COMPONENT, GL_FLOAT);
|
texture.glTexImage2D(openGLState, width, height, GL_DEPTH_COMPONENT, GL_FLOAT);
|
||||||
|
|
||||||
texture.setMinFilter(openGLState, GL_LINEAR);
|
texture.setMinFilter(openGLState, GL_LINEAR);
|
||||||
@ -93,7 +101,7 @@ public class FramebufferUtils {
|
|||||||
|
|
||||||
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
|
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
|
||||||
texture.bind(openGLState);
|
texture.bind(openGLState);
|
||||||
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE);
|
openGLState.glBindTextureUnitForce(0, Texture.DEFAULT_TEXTURE, GL40.GL_TEXTURE_2D);
|
||||||
|
|
||||||
texture.checkStatus(openGLState);
|
texture.checkStatus(openGLState);
|
||||||
return texture;
|
return texture;
|
||||||
@ -106,8 +114,10 @@ public class FramebufferUtils {
|
|||||||
buffer.setMipMapLevel(0);
|
buffer.setMipMapLevel(0);
|
||||||
buffer.attachTexture(openGLState,colorTexture);
|
buffer.attachTexture(openGLState,colorTexture);
|
||||||
buffer.setDepthAttachment(openGLState,depthTexture);
|
buffer.setDepthAttachment(openGLState,depthTexture);
|
||||||
|
buffer.bind(openGLState);
|
||||||
|
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
||||||
//check make sure compiled
|
//check make sure compiled
|
||||||
buffer.checkStatus();
|
buffer.shouldBeComplete(openGLState);
|
||||||
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@ -118,7 +128,7 @@ public class FramebufferUtils {
|
|||||||
buffer.setMipMapLevel(0);
|
buffer.setMipMapLevel(0);
|
||||||
buffer.attachTexture(openGLState,colorTexture);
|
buffer.attachTexture(openGLState,colorTexture);
|
||||||
//check make sure compiled
|
//check make sure compiled
|
||||||
buffer.checkStatus();
|
buffer.shouldBeComplete(openGLState);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +157,7 @@ public class FramebufferUtils {
|
|||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
//check make sure compiled
|
//check make sure compiled
|
||||||
buffer.checkStatus();
|
buffer.shouldBeComplete(openGLState);
|
||||||
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@ -178,7 +188,7 @@ public class FramebufferUtils {
|
|||||||
GL40.glFramebufferRenderbuffer(GL40.GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer);
|
GL40.glFramebufferRenderbuffer(GL40.GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
//check make sure compiled
|
//check make sure compiled
|
||||||
buffer.checkStatus();
|
buffer.shouldBeComplete(openGLState);
|
||||||
//re-bind default buffer
|
//re-bind default buffer
|
||||||
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
||||||
return buffer;
|
return buffer;
|
||||||
@ -223,7 +233,7 @@ public class FramebufferUtils {
|
|||||||
|
|
||||||
|
|
||||||
//check make sure compiled
|
//check make sure compiled
|
||||||
buffer.checkStatus();
|
buffer.shouldBeComplete(openGLState);
|
||||||
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@ -257,7 +267,7 @@ public class FramebufferUtils {
|
|||||||
|
|
||||||
|
|
||||||
//check make sure compiled
|
//check make sure compiled
|
||||||
buffer.checkStatus();
|
buffer.shouldBeComplete(openGLState);
|
||||||
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@ -301,7 +311,7 @@ public class FramebufferUtils {
|
|||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
|
|
||||||
//check make sure compiled
|
//check make sure compiled
|
||||||
buffer.checkStatus();
|
buffer.shouldBeComplete(openGLState);
|
||||||
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
Globals.renderingEngine.defaultFramebuffer.bind(openGLState);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -390,13 +390,27 @@ public class Texture {
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
this.pixelFormat = format;
|
this.pixelFormat = format;
|
||||||
this.datatype = datatype;
|
this.datatype = datatype;
|
||||||
|
int internalFormat = format;
|
||||||
|
if(internalFormat == GL45.GL_DEPTH_COMPONENT){
|
||||||
|
internalFormat = GL45.GL_DEPTH_COMPONENT24;
|
||||||
|
}
|
||||||
//static values going into call
|
//static values going into call
|
||||||
int level = 0;
|
int level = 0;
|
||||||
int border = 0; //this must be 0 according to docs
|
int border = 0; //this must be 0 according to docs
|
||||||
openGLState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
openGLState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
GL40.glTexImage2D(GL_TEXTURE_2D, level, format, width, height, border, format, datatype, MemoryUtil.NULL);
|
GL40.glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, border, format, datatype, MemoryUtil.NULL);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
|
int[] storage = new int[1];
|
||||||
|
int discoveredWidth = 0;
|
||||||
|
int discoveredHeight = 0;
|
||||||
|
GL45.glGetTexLevelParameteriv(GL45.GL_TEXTURE_2D, 0, GL45.GL_TEXTURE_WIDTH, storage);
|
||||||
|
discoveredWidth = storage[0];
|
||||||
|
GL45.glGetTexLevelParameteriv(GL45.GL_TEXTURE_2D, 0, GL45.GL_TEXTURE_HEIGHT, storage);
|
||||||
|
discoveredHeight = storage[0];
|
||||||
|
if(width != discoveredWidth || height != discoveredHeight){
|
||||||
|
throw new Error("Found dims aren't the same! " + width + "," + height + " vs " + discoveredWidth + "," + discoveredHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -528,6 +542,13 @@ public class Texture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the texture
|
||||||
|
*/
|
||||||
|
public void free(){
|
||||||
|
GL40.glDeleteTextures(this.texturePointer);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
String rVal = "" +
|
String rVal = "" +
|
||||||
|
|||||||
@ -10,8 +10,6 @@ import electrosphere.engine.loadingthreads.LoadingThread;
|
|||||||
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
|
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
|
||||||
import electrosphere.engine.profiler.Profiler;
|
import electrosphere.engine.profiler.Profiler;
|
||||||
import electrosphere.net.NetUtils;
|
import electrosphere.net.NetUtils;
|
||||||
import electrosphere.renderer.ui.elementtypes.DrawableElement;
|
|
||||||
import electrosphere.renderer.ui.elementtypes.Element;
|
|
||||||
|
|
||||||
public class EngineInit {
|
public class EngineInit {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user