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
|
||||
Fix virtual scrollable mouse alignment for events
|
||||
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(MENU_SCROLL, new Control(ControlType.MOUSE_SCROLL,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,"",""));
|
||||
}
|
||||
|
||||
|
||||
@ -115,6 +115,7 @@ public class OpenGLState {
|
||||
viewport.x = x;
|
||||
viewport.y = 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 verticalFOV = 90.0f;
|
||||
|
||||
//the current state of the rendering pipeline
|
||||
/**
|
||||
* the current state of the rendering pipeline
|
||||
*/
|
||||
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
|
||||
|
||||
@ -20,7 +20,6 @@ import org.lwjgl.opengl.GL45;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Framebuffer object
|
||||
@ -88,7 +87,7 @@ public class Framebuffer {
|
||||
* @param openGLState The opengl state
|
||||
*/
|
||||
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){
|
||||
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
|
||||
*/
|
||||
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 {
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
} catch (InterruptedException ex) {
|
||||
@ -172,7 +171,7 @@ public class Framebuffer {
|
||||
* @return The status
|
||||
*/
|
||||
public String getStatus(){
|
||||
switch(glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER)){
|
||||
switch(GL45.glCheckNamedFramebufferStatus(this.framebufferPointer,GL40.GL_FRAMEBUFFER)){
|
||||
case GL40.GL_FRAMEBUFFER_UNDEFINED: {
|
||||
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);
|
||||
GL40.glReadBuffer(GL40.GL_COLOR_ATTACHMENT0);
|
||||
if(this.framebufferPointer == 0){
|
||||
if(this.framebufferPointer == Framebuffer.DEFAULT_FRAMEBUFFER_POINTER){
|
||||
//this is the default framebuffer, read from backbuffer because it is default
|
||||
GL40.glReadBuffer(GL40.GL_BACK);
|
||||
|
||||
//set viewport
|
||||
openGLState.glViewport(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
} 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);
|
||||
width = texture.getWidth();
|
||||
height = texture.getHeight();
|
||||
openGLState.glViewport(width, height);
|
||||
} 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
|
||||
@ -314,13 +320,12 @@ public class Framebuffer {
|
||||
|
||||
//get pixel data
|
||||
try {
|
||||
int bytesPerPixel = pixelFormatToBytes(pixelFormat,type);
|
||||
int bytesPerPixel = Framebuffer.pixelFormatToBytes(pixelFormat,type);
|
||||
int bufferSize = width * height * bytesPerPixel;
|
||||
ByteBuffer buffer = BufferUtils.createByteBuffer(bufferSize);
|
||||
if(buffer == null || buffer.limit() < bufferSize){
|
||||
throw new Error("Failed to create buffer!");
|
||||
}
|
||||
openGLState.glViewport(width, height);
|
||||
GL40.glReadPixels(offsetX, offsetY, width, height, pixelFormat, type, buffer);
|
||||
Globals.renderingEngine.checkError();
|
||||
//convert to a buffered images
|
||||
|
||||
Loading…
Reference in New Issue
Block a user