linearize screen framebuffer creation
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
4691df3921
commit
ee3d31abe1
@ -159,12 +159,12 @@ public class OpenGLState {
|
||||
* @param framebufferPointer the pointer to the framebuffer
|
||||
*/
|
||||
public void glBindFramebuffer(int framebufferType, int framebufferPointer){
|
||||
// if(DISABLE_CACHING || this.framebufferType != framebufferType || this.framebufferPointer != framebufferPointer){
|
||||
if(DISABLE_CACHING || this.framebufferType != framebufferType || this.framebufferPointer != framebufferPointer){
|
||||
this.framebufferType = framebufferType;
|
||||
this.framebufferPointer = framebufferPointer;
|
||||
GL40.glBindFramebuffer(this.framebufferType,this.framebufferPointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -327,13 +327,15 @@ public class RenderingEngine {
|
||||
// screenTextureShaders = ShaderProgram.loadSpecificShader("/Shaders/screentexture/drawDepthBuffer/drawDepthBuffer.vs", "/Shaders/screentexture/drawDepthBuffer/drawDepthBuffer.fs");
|
||||
|
||||
//default framebuffer
|
||||
defaultFramebuffer = new Framebuffer(0);
|
||||
defaultFramebuffer = new Framebuffer(GL_DEFAULT_FRAMEBUFFER);
|
||||
|
||||
FramebufferUtils.framebufferUtilsTest();
|
||||
|
||||
//generate framebuffers
|
||||
screenTextureColor = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
|
||||
screenFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), screenTextureColor, screenTextureDepth);
|
||||
openGLState.glBindFramebuffer(GL_FRAMEBUFFER, GL_DEFAULT_FRAMEBUFFER);
|
||||
screenTextureColor = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
||||
screenFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, screenTextureColor, screenTextureDepth);
|
||||
defaultFramebuffer.bind(openGLState);
|
||||
// glBindRenderbuffer(GL_RENDERBUFFER, GL_DEFAULT_RENDERBUFFER);
|
||||
Globals.renderingEngine.checkError();
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package electrosphere.renderer.framebuffer;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.renderer.OpenGLState;
|
||||
import electrosphere.renderer.RenderingEngine;
|
||||
import electrosphere.renderer.texture.Texture;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
@ -44,9 +43,56 @@ import static org.lwjgl.opengl.GL45.glNamedFramebufferReadBuffer;
|
||||
*/
|
||||
public class FramebufferUtils {
|
||||
|
||||
public static void framebufferUtilsTest(){
|
||||
OpenGLState openGLState = Globals.renderingEngine.getOpenGLState();
|
||||
int width = Globals.WINDOW_WIDTH;
|
||||
int height = Globals.WINDOW_HEIGHT;
|
||||
|
||||
//
|
||||
//Texture 1
|
||||
//
|
||||
Texture screenTextureColor = new Texture();
|
||||
screenTextureColor.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE);
|
||||
screenTextureColor.setMinFilter(openGLState, GL_LINEAR);
|
||||
screenTextureColor.setMagFilter(openGLState, GL_LINEAR);
|
||||
//these make sure the texture actually clamps to the borders of the quad
|
||||
screenTextureColor.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
screenTextureColor.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
|
||||
screenTextureColor.bind(openGLState);
|
||||
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE);
|
||||
|
||||
screenTextureColor.checkStatus(openGLState);
|
||||
|
||||
//
|
||||
//Texture 2
|
||||
//
|
||||
Texture screenTextureDepth = new Texture();
|
||||
screenTextureDepth.glTexImage2D(openGLState, width, height, GL_DEPTH_COMPONENT, GL_FLOAT);
|
||||
|
||||
//guarantees that the texture object has actually been created (calling gen buffers does not guarantee object creation)
|
||||
screenTextureDepth.bind(openGLState);
|
||||
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE);
|
||||
|
||||
screenTextureDepth.checkStatus(openGLState);
|
||||
|
||||
|
||||
//
|
||||
//Franebuffer
|
||||
//
|
||||
Framebuffer screenFramebuffer = new Framebuffer();
|
||||
//bind texture to fbo
|
||||
screenFramebuffer.setMipMapLevel(0);
|
||||
screenFramebuffer.attachTexture(openGLState,screenTextureColor);
|
||||
screenFramebuffer.setDepthAttachment(openGLState,screenTextureDepth);
|
||||
//check make sure compiled
|
||||
screenFramebuffer.checkStatus();
|
||||
}
|
||||
|
||||
public static Texture generateScreenTextureColor(OpenGLState openGLState, int width, int height){
|
||||
Texture texture = new Texture();
|
||||
texture.glTexImage2D(openGLState, width, height, GL_RGB, GL40.GL_RGB32F, GL_UNSIGNED_BYTE);
|
||||
texture.glTexImage2D(openGLState, width, height, GL_RGB, GL_UNSIGNED_BYTE);
|
||||
texture.setMinFilter(openGLState, GL_LINEAR);
|
||||
texture.setMagFilter(openGLState, GL_LINEAR);
|
||||
//these make sure the texture actually clamps to the borders of the quad
|
||||
@ -63,7 +109,7 @@ public class FramebufferUtils {
|
||||
|
||||
public static Texture generateScreenTextureColorAlpha(OpenGLState openGLState, int width, int height){
|
||||
Texture texture = new Texture();
|
||||
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL40.GL_RGB32F, GL_UNSIGNED_BYTE);
|
||||
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE);
|
||||
texture.setMinFilter(openGLState, GL_LINEAR);
|
||||
texture.setMagFilter(openGLState, GL_LINEAR);
|
||||
//these make sure the texture actually clamps to the borders of the quad
|
||||
|
||||
@ -398,29 +398,6 @@ public class Texture {
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a 2d image
|
||||
* @param width The width of the image
|
||||
* @param height The height of the image
|
||||
* @param format The format of the pixels (ie GL_RGB, GL_RGBA, etc)
|
||||
* @param internalformat The specific format type (ie GL_RGB32F, GL_RGBA32F, GL_R8, etc)
|
||||
* @param datatype The data type of a single component of a pixel (ie GL_BYTE, GL_UNSIGNED_INT, etc)
|
||||
*/
|
||||
public void glTexImage2D(OpenGLState openGLState, int width, int height, int format, int internalformat, int datatype){
|
||||
//store provided values
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.pixelFormat = format;
|
||||
this.datatype = datatype;
|
||||
//static values going into call
|
||||
int level = 0;
|
||||
int border = 0; //this must be 0 according to docs
|
||||
openGLState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
GL40.glTexImage2D(GL_TEXTURE_2D, level, internalformat, width, height, border, format, datatype, MemoryUtil.NULL);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a 2d image
|
||||
* @param width The width of the image
|
||||
|
||||
Loading…
Reference in New Issue
Block a user