work on fixing framebuffer bugs
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
5b9b4bd048
commit
2cefc2e228
@ -1787,6 +1787,7 @@ Grid alignment offsets work
|
|||||||
Inventory state in non-creatures actually saves/loads to/from disk
|
Inventory state in non-creatures actually saves/loads to/from disk
|
||||||
Fix virtual scrollable mouse alignment for events
|
Fix virtual scrollable mouse alignment for events
|
||||||
Remove warnings for fast loading
|
Remove warnings for fast loading
|
||||||
|
Work on debugging framebuffers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public class ControlCategoryMenuNav {
|
|||||||
handler.addControl(INPUT_CODE_MENU_MOUSE_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_LEFT,false,"Mouse primary",""));
|
handler.addControl(INPUT_CODE_MENU_MOUSE_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_LEFT,false,"Mouse primary",""));
|
||||||
handler.addControl(MENU_SCROLL, new Control(ControlType.MOUSE_SCROLL,0,false,"",""));
|
handler.addControl(MENU_SCROLL, new Control(ControlType.MOUSE_SCROLL,0,false,"",""));
|
||||||
handler.addControl(MENU_DRAG_START, new Control(ControlType.MOUSE_MOVEMENT,0,false,"",""));
|
handler.addControl(MENU_DRAG_START, new Control(ControlType.MOUSE_MOVEMENT,0,false,"",""));
|
||||||
handler.addControl(MENU_CAPTURE_SCREEN, new Control(ControlType.KEY,GLFW.GLFW_KEY_F4,true,"Screenshot","Takes a screenshot of the engine"));
|
handler.addControl(MENU_CAPTURE_SCREEN, new Control(ControlType.KEY,GLFW.GLFW_KEY_F12,true,"Screenshot","Takes a screenshot of the engine"));
|
||||||
handler.addControl(MENU_DRAG_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_1,false,"",""));
|
handler.addControl(MENU_DRAG_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_1,false,"",""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -115,6 +115,7 @@ public class OpenGLState {
|
|||||||
viewport.x = x;
|
viewport.x = x;
|
||||||
viewport.y = y;
|
viewport.y = y;
|
||||||
GL40.glViewport(0, 0, viewport.x, viewport.y);
|
GL40.glViewport(0, 0, viewport.x, viewport.y);
|
||||||
|
Globals.renderingEngine.checkError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -144,11 +144,15 @@ public class RenderingEngine {
|
|||||||
static float aspectRatio = 1.0f;
|
static float aspectRatio = 1.0f;
|
||||||
static float verticalFOV = 90.0f;
|
static float verticalFOV = 90.0f;
|
||||||
|
|
||||||
//the current state of the rendering pipeline
|
/**
|
||||||
|
* the current state of the rendering pipeline
|
||||||
|
*/
|
||||||
static RenderPipelineState renderPipelineState = new RenderPipelineState();
|
static RenderPipelineState renderPipelineState = new RenderPipelineState();
|
||||||
|
|
||||||
//the opengl state
|
/**
|
||||||
static OpenGLState openGLState = new OpenGLState();
|
* the opengl state
|
||||||
|
*/
|
||||||
|
OpenGLState openGLState = new OpenGLState();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The opengl context the rendering engine is running within
|
* The opengl context the rendering engine is running within
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import org.lwjgl.opengl.GL45;
|
|||||||
import static org.lwjgl.opengl.GL11.GL_NONE;
|
import static org.lwjgl.opengl.GL11.GL_NONE;
|
||||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE;
|
import static org.lwjgl.opengl.GL11.GL_TEXTURE;
|
||||||
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
|
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
|
||||||
import static org.lwjgl.opengl.GL45.glCheckNamedFramebufferStatus;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Framebuffer object
|
* Framebuffer object
|
||||||
@ -88,7 +87,7 @@ public class Framebuffer {
|
|||||||
* @param openGLState The opengl state
|
* @param openGLState The opengl state
|
||||||
*/
|
*/
|
||||||
public void bind(OpenGLState openGLState){
|
public void bind(OpenGLState openGLState){
|
||||||
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, framebufferPointer);
|
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,7 +98,7 @@ public class Framebuffer {
|
|||||||
if(this.framebufferPointer == DEFAULT_FRAMEBUFFER_POINTER){
|
if(this.framebufferPointer == DEFAULT_FRAMEBUFFER_POINTER){
|
||||||
throw new Error("Pointer is the default framebuffer!");
|
throw new Error("Pointer is the default framebuffer!");
|
||||||
}
|
}
|
||||||
return glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER) == GL40.GL_FRAMEBUFFER_COMPLETE;
|
return GL45.glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER) == GL40.GL_FRAMEBUFFER_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -158,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(this.framebufferPointer,GL40.GL_FRAMEBUFFER) != GL40.GL_FRAMEBUFFER_UNDEFINED){
|
while(GL45.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) {
|
||||||
@ -172,7 +171,7 @@ public class Framebuffer {
|
|||||||
* @return The status
|
* @return The status
|
||||||
*/
|
*/
|
||||||
public String getStatus(){
|
public String getStatus(){
|
||||||
switch(glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER)){
|
switch(GL45.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.";
|
||||||
}
|
}
|
||||||
@ -292,16 +291,23 @@ public class Framebuffer {
|
|||||||
|
|
||||||
|
|
||||||
this.bind(openGLState);
|
this.bind(openGLState);
|
||||||
GL40.glReadBuffer(GL40.GL_COLOR_ATTACHMENT0);
|
if(this.framebufferPointer == Framebuffer.DEFAULT_FRAMEBUFFER_POINTER){
|
||||||
if(this.framebufferPointer == 0){
|
|
||||||
//this is the default framebuffer, read from backbuffer because it is default
|
//this is the default framebuffer, read from backbuffer because it is default
|
||||||
GL40.glReadBuffer(GL40.GL_BACK);
|
GL40.glReadBuffer(GL40.GL_BACK);
|
||||||
|
|
||||||
|
//set viewport
|
||||||
|
openGLState.glViewport(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||||
} else if(attachTextureMap.containsKey(0)){
|
} else if(attachTextureMap.containsKey(0)){
|
||||||
|
//this is NOT the default framebuffer, read from the first color attachment
|
||||||
|
GL40.glReadBuffer(GL40.GL_COLOR_ATTACHMENT0);
|
||||||
|
|
||||||
|
//set viewport
|
||||||
Texture texture = attachTextureMap.get(0);
|
Texture texture = attachTextureMap.get(0);
|
||||||
width = texture.getWidth();
|
width = texture.getWidth();
|
||||||
height = texture.getHeight();
|
height = texture.getHeight();
|
||||||
|
openGLState.glViewport(width, height);
|
||||||
} else {
|
} else {
|
||||||
LoggerInterface.loggerRenderer.ERROR(new IllegalStateException("Tried to get pixels from a framebuffer that does not have a texture attached to attachment point 0."));
|
LoggerInterface.loggerRenderer.ERROR(new Error("Tried to get pixels from a framebuffer that does not have a texture attached to attachment point 0."));
|
||||||
}
|
}
|
||||||
|
|
||||||
//error check
|
//error check
|
||||||
@ -314,13 +320,12 @@ public class Framebuffer {
|
|||||||
|
|
||||||
//get pixel data
|
//get pixel data
|
||||||
try {
|
try {
|
||||||
int bytesPerPixel = pixelFormatToBytes(pixelFormat,type);
|
int bytesPerPixel = Framebuffer.pixelFormatToBytes(pixelFormat,type);
|
||||||
int bufferSize = width * height * bytesPerPixel;
|
int bufferSize = width * height * bytesPerPixel;
|
||||||
ByteBuffer buffer = BufferUtils.createByteBuffer(bufferSize);
|
ByteBuffer buffer = BufferUtils.createByteBuffer(bufferSize);
|
||||||
if(buffer == null || buffer.limit() < bufferSize){
|
if(buffer == null || buffer.limit() < bufferSize){
|
||||||
throw new Error("Failed to create buffer!");
|
throw new Error("Failed to create buffer!");
|
||||||
}
|
}
|
||||||
openGLState.glViewport(width, height);
|
|
||||||
GL40.glReadPixels(offsetX, offsetY, width, height, pixelFormat, type, buffer);
|
GL40.glReadPixels(offsetX, offsetY, width, height, pixelFormat, type, buffer);
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
//convert to a buffered images
|
//convert to a buffered images
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user