diff --git a/src/main/java/electrosphere/renderer/OpenGLState.java b/src/main/java/electrosphere/renderer/OpenGLState.java index 62e96274..eacd4e36 100644 --- a/src/main/java/electrosphere/renderer/OpenGLState.java +++ b/src/main/java/electrosphere/renderer/OpenGLState.java @@ -125,6 +125,7 @@ public class OpenGLState { if(DISABLE_CACHING || this.activeTexture != texture){ this.activeTexture = texture; GL40.glActiveTexture(this.activeTexture); + Globals.renderingEngine.checkError(); } } @@ -148,6 +149,7 @@ public class OpenGLState { unitToPointerMap.put(textureUnit,texturePointer); this.glActiveTexture(textureUnit); GL40.glBindTexture(textureType,texturePointer); + Globals.renderingEngine.checkError(); } } diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index c33fc9b3..5cb2e750 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -330,7 +330,7 @@ public class RenderingEngine { defaultFramebuffer = new Framebuffer(0); //generate framebuffers - screenTextureColor = FramebufferUtils.generateScreenTextureColor(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + 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); @@ -368,7 +368,7 @@ public class RenderingEngine { static Framebuffer gameImageNormalsFramebuffer; static ShaderProgram renderNormalsShader; */ - gameImageNormalsTexture = FramebufferUtils.generateScreenTextureColor(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + 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/anime/renderNormals.vs", "Shaders/anime/renderNormals.fs"); diff --git a/src/main/java/electrosphere/renderer/framebuffer/Framebuffer.java b/src/main/java/electrosphere/renderer/framebuffer/Framebuffer.java index 2818103e..c82ac968 100644 --- a/src/main/java/electrosphere/renderer/framebuffer/Framebuffer.java +++ b/src/main/java/electrosphere/renderer/framebuffer/Framebuffer.java @@ -211,7 +211,6 @@ public class Framebuffer { throw new IllegalStateException("Trying to attach uninitialized image to frame buffer!"); } openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer); - texture.bind(openGLState); //texture must be bound at least once so that the object is created prior to attaching to framebuffer GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_COLOR_ATTACHMENT0 + attachmentNum, GL40.GL_TEXTURE_2D, texture.getTexturePointer(), 0); Globals.renderingEngine.checkError(); openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, 0); @@ -225,7 +224,6 @@ public class Framebuffer { public void setDepthAttachment(OpenGLState openGLState, Texture depthTexture){ openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, this.framebufferPointer); this.depthTexture = depthTexture; - depthTexture.bind(openGLState); //texture must be bound at least once so that the object is created prior to attaching to framebuffer GL40.glFramebufferTexture2D(GL40.GL_FRAMEBUFFER, GL40.GL_DEPTH_ATTACHMENT, GL40.GL_TEXTURE_2D, depthTexture.getTexturePointer(), 0); Globals.renderingEngine.checkError(); openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER, 0); diff --git a/src/main/java/electrosphere/renderer/framebuffer/FramebufferUtils.java b/src/main/java/electrosphere/renderer/framebuffer/FramebufferUtils.java index 1ab0a47b..688d6906 100644 --- a/src/main/java/electrosphere/renderer/framebuffer/FramebufferUtils.java +++ b/src/main/java/electrosphere/renderer/framebuffer/FramebufferUtils.java @@ -46,26 +46,34 @@ public class FramebufferUtils { public static Texture generateScreenTextureColor(OpenGLState openGLState, int width, int height){ Texture texture = new Texture(); - texture.glTexImage2D(openGLState, width, height, GL_RGB, GL_UNSIGNED_BYTE); + texture.glTexImage2D(openGLState, width, height, GL_RGB, GL40.GL_RGB32F, 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 texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.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) + texture.bind(openGLState); + openGLState.glBindTexture(GL40.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE); + texture.checkStatus(openGLState); return texture; } public static Texture generateScreenTextureColorAlpha(OpenGLState openGLState, int width, int height){ Texture texture = new Texture(); - texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE); + texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL40.GL_RGB32F, 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 texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.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) + texture.bind(openGLState); + openGLState.glBindTexture(GL40.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE); + texture.checkStatus(openGLState); return texture; } @@ -74,6 +82,10 @@ public class FramebufferUtils { Texture texture = new Texture(); texture.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) + texture.bind(openGLState); + openGLState.glBindTexture(GL40.GL_TEXTURE_2D, Texture.DEFAULT_TEXTURE); + texture.checkStatus(openGLState); return texture; } diff --git a/src/main/java/electrosphere/renderer/texture/Texture.java b/src/main/java/electrosphere/renderer/texture/Texture.java index cb126de2..dd38d428 100644 --- a/src/main/java/electrosphere/renderer/texture/Texture.java +++ b/src/main/java/electrosphere/renderer/texture/Texture.java @@ -34,6 +34,11 @@ public class Texture { */ public static final int UNINITIALIZED_TEXTURE = -1; + /** + * The texture name for the default texture (ie the screen) + */ + public static final int DEFAULT_TEXTURE = 0; + //the pointer for the texture int texturePointer = UNINITIALIZED_TEXTURE; //the width of the texture @@ -254,7 +259,7 @@ public class Texture { //buffer the texture information this.pixelFormat = GL_RED; this.datatype = GL_FLOAT; - GL40.glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, width, height, 0, GL_RED, GL_FLOAT, buffer); + this.glTexImage2D(openGlState, width, height, GL_RED, GL_FLOAT); //check build status String errorMessage = RenderingEngine.getErrorInEnglish(Globals.renderingEngine.getError()); if(errorMessage != null){ @@ -393,6 +398,29 @@ 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 @@ -489,6 +517,13 @@ public class Texture { LoggerInterface.loggerRenderer.ERROR("Texture is greater width than environment allows", new IllegalStateException("Texture is greater width than environment allows")); } } break; + case GL40.GL_INVALID_ENUM: { + + } break; + default: { + String message = "Texture undefined error status! " + errorCode; + LoggerInterface.loggerRenderer.ERROR(new IllegalStateException(message)); + } break; } } }