reformat DhColorTexture, DhFramebuffer, and LodRenderer
This commit is contained in:
+21
-20
@@ -16,7 +16,8 @@ public class DhColorTexture
|
||||
private int height;
|
||||
|
||||
private boolean isValid;
|
||||
private final int texture;
|
||||
/** AKA, the OpenGL name of this texture */
|
||||
private final int id;
|
||||
|
||||
private static final ByteBuffer NULL_BUFFER = null;
|
||||
|
||||
@@ -37,10 +38,10 @@ public class DhColorTexture
|
||||
this.width = builder.width;
|
||||
this.height = builder.height;
|
||||
|
||||
this.texture = GL43C.glGenTextures();
|
||||
this.id = GL43C.glGenTextures();
|
||||
|
||||
boolean isPixelFormatInteger = builder.internalFormat.getPixelFormat().isInteger();
|
||||
setupTexture(texture, builder.width, builder.height, !isPixelFormatInteger);
|
||||
this.setupTexture(this.id, builder.width, builder.height, !isPixelFormatInteger);
|
||||
|
||||
// Clean up after ourselves
|
||||
// This is strictly defensive to ensure that other buggy code doesn't tamper with our textures
|
||||
@@ -53,9 +54,9 @@ public class DhColorTexture
|
||||
// methods //
|
||||
//=========//
|
||||
|
||||
private void setupTexture(int texture, int width, int height, boolean allowsLinear)
|
||||
private void setupTexture(int id, int width, int height, boolean allowsLinear)
|
||||
{
|
||||
resizeTexture(texture, width, height);
|
||||
this.resizeTexture(id, width, height);
|
||||
|
||||
GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, allowsLinear ? GL11C.GL_LINEAR : GL11C.GL_NEAREST);
|
||||
GL43C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, allowsLinear ? GL11C.GL_LINEAR : GL11C.GL_NEAREST);
|
||||
@@ -66,7 +67,7 @@ public class DhColorTexture
|
||||
private void resizeTexture(int texture, int width, int height)
|
||||
{
|
||||
GL43C.glBindTexture(GL43C.GL_TEXTURE_2D, texture);
|
||||
GL43C.glTexImage2D(GL11C.GL_TEXTURE_2D, 0, internalFormat.getGlFormat(), width, height, 0, format.getGlFormat(), type.getGlFormat(), NULL_BUFFER);
|
||||
GL43C.glTexImage2D(GL11C.GL_TEXTURE_2D, 0, this.internalFormat.getGlFormat(), width, height, 0, this.format.getGlFormat(), this.type.getGlFormat(), NULL_BUFFER);
|
||||
}
|
||||
|
||||
void resize(Vector2i textureScaleOverride) { this.resize(textureScaleOverride.x, textureScaleOverride.y); }
|
||||
@@ -74,38 +75,38 @@ public class DhColorTexture
|
||||
// Package private, call CompositeRenderTargets#resizeIfNeeded instead.
|
||||
public void resize(int width, int height)
|
||||
{
|
||||
requireValid();
|
||||
this.throwIfInvalid();
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
resizeTexture(texture, width, height);
|
||||
this.resizeTexture(this.id, width, height);
|
||||
}
|
||||
|
||||
public EDhInternalTextureFormat getInternalFormat() { return internalFormat; }
|
||||
public EDhInternalTextureFormat getInternalFormat() { return this.internalFormat; }
|
||||
|
||||
public int getTexture()
|
||||
public int getTextureId()
|
||||
{
|
||||
requireValid();
|
||||
|
||||
return texture;
|
||||
this.throwIfInvalid();
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int getWidth() { return width; }
|
||||
public int getWidth() { return this.width; }
|
||||
|
||||
public int getHeight() { return height; }
|
||||
public int getHeight() { return this.height; }
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
requireValid();
|
||||
isValid = false;
|
||||
this.throwIfInvalid();
|
||||
this.isValid = false;
|
||||
|
||||
GL43C.glDeleteTextures(texture);
|
||||
GL43C.glDeleteTextures(this.id);
|
||||
}
|
||||
|
||||
private void requireValid()
|
||||
/** @throws IllegalStateException if the texture isn't valid */
|
||||
private void throwIfInvalid()
|
||||
{
|
||||
if (!isValid)
|
||||
if (!this.isValid)
|
||||
{
|
||||
throw new IllegalStateException("Attempted to use a deleted composite render target");
|
||||
}
|
||||
|
||||
+18
-19
@@ -2,8 +2,7 @@ package com.seibel.distanthorizons.core.render.glObject.texture;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import org.lwjgl.opengl.GL30C;
|
||||
import org.lwjgl.opengl.GL43C;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
// TODO lowercase
|
||||
public class DhFramebuffer
|
||||
@@ -22,11 +21,11 @@ public class DhFramebuffer
|
||||
|
||||
public DhFramebuffer()
|
||||
{
|
||||
this.id = GL43C.glGenFramebuffers();
|
||||
this.id = GL32.glGenFramebuffers();
|
||||
|
||||
this.attachments = new Int2IntArrayMap();
|
||||
this.maxDrawBuffers = GL43C.glGetInteger(GL30C.GL_MAX_DRAW_BUFFERS);
|
||||
this.maxColorAttachments = GL43C.glGetInteger(GL30C.GL_MAX_COLOR_ATTACHMENTS);
|
||||
this.maxDrawBuffers = GL32.glGetInteger(GL32.GL_MAX_DRAW_BUFFERS);
|
||||
this.maxColorAttachments = GL32.glGetInteger(GL32.GL_MAX_COLOR_ATTACHMENTS);
|
||||
this.hasDepthAttachment = false;
|
||||
}
|
||||
|
||||
@@ -36,8 +35,8 @@ public class DhFramebuffer
|
||||
this.id = id;
|
||||
|
||||
this.attachments = new Int2IntArrayMap();
|
||||
this.maxDrawBuffers = GL43C.glGetInteger(GL30C.GL_MAX_DRAW_BUFFERS);
|
||||
this.maxColorAttachments = GL43C.glGetInteger(GL30C.GL_MAX_COLOR_ATTACHMENTS);
|
||||
this.maxDrawBuffers = GL32.glGetInteger(GL32.GL_MAX_DRAW_BUFFERS);
|
||||
this.maxColorAttachments = GL32.glGetInteger(GL32.GL_MAX_COLOR_ATTACHMENTS);
|
||||
this.hasDepthAttachment = false;
|
||||
}
|
||||
|
||||
@@ -53,11 +52,11 @@ public class DhFramebuffer
|
||||
|
||||
if (depthBufferFormat.isCombinedStencil())
|
||||
{
|
||||
GL43C.glFramebufferTexture2D(GL30C.GL_FRAMEBUFFER, GL30C.GL_DEPTH_STENCIL_ATTACHMENT, GL30C.GL_TEXTURE_2D, texture, 0);
|
||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_STENCIL_ATTACHMENT, GL32.GL_TEXTURE_2D, texture, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
GL43C.glFramebufferTexture2D(GL30C.GL_FRAMEBUFFER, GL30C.GL_DEPTH_ATTACHMENT, GL30C.GL_TEXTURE_2D, texture, 0);
|
||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_TEXTURE_2D, texture, 0);
|
||||
}
|
||||
|
||||
this.hasDepthAttachment = true;
|
||||
@@ -68,14 +67,14 @@ public class DhFramebuffer
|
||||
int fb = id;
|
||||
bind();
|
||||
|
||||
GL43C.glFramebufferTexture2D(GL30C.GL_FRAMEBUFFER, GL30C.GL_COLOR_ATTACHMENT0 + index, GL30C.GL_TEXTURE_2D, texture, 0);
|
||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0 + index, GL32.GL_TEXTURE_2D, texture, 0);
|
||||
attachments.put(index, texture);
|
||||
}
|
||||
|
||||
public void noDrawBuffers()
|
||||
{
|
||||
bind();
|
||||
GL43C.glDrawBuffers(new int[]{GL30C.GL_NONE});
|
||||
GL32.glDrawBuffers(new int[]{GL32.GL_NONE});
|
||||
}
|
||||
|
||||
public void drawBuffers(int[] buffers)
|
||||
@@ -94,17 +93,17 @@ public class DhFramebuffer
|
||||
throw new IllegalArgumentException("Only " + maxColorAttachments + " color attachments are supported on this GPU, but an attempt was made to write to a color attachment with index " + buffer);
|
||||
}
|
||||
|
||||
glBuffers[index++] = GL30C.GL_COLOR_ATTACHMENT0 + buffer;
|
||||
glBuffers[index++] = GL32.GL_COLOR_ATTACHMENT0 + buffer;
|
||||
}
|
||||
|
||||
bind();
|
||||
GL43C.glDrawBuffers(new int[]{GL30C.GL_NONE});
|
||||
GL32.glDrawBuffers(new int[]{GL32.GL_NONE});
|
||||
}
|
||||
|
||||
public void readBuffer(int buffer)
|
||||
{
|
||||
bind();
|
||||
GL43C.glReadBuffer(GL30C.GL_COLOR_ATTACHMENT0 + buffer);
|
||||
GL32.glReadBuffer(GL32.GL_COLOR_ATTACHMENT0 + buffer);
|
||||
}
|
||||
|
||||
public int getColorAttachment(int index) { return attachments.get(index); }
|
||||
@@ -117,23 +116,23 @@ public class DhFramebuffer
|
||||
{
|
||||
throw new IllegalStateException("Framebuffer does not exist!");
|
||||
}
|
||||
GL43C.glBindFramebuffer(GL30C.GL_FRAMEBUFFER, id);
|
||||
GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, id);
|
||||
}
|
||||
|
||||
public void bindAsReadBuffer() { GL43C.glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, id); }
|
||||
public void bindAsReadBuffer() { GL32.glBindFramebuffer(GL32.GL_READ_FRAMEBUFFER, id); }
|
||||
|
||||
public void bindAsDrawBuffer() { GL43C.glBindFramebuffer(GL30C.GL_DRAW_FRAMEBUFFER, id); }
|
||||
public void bindAsDrawBuffer() { GL32.glBindFramebuffer(GL32.GL_DRAW_FRAMEBUFFER, id); }
|
||||
|
||||
public void destroyInternal()
|
||||
{
|
||||
GL43C.glDeleteFramebuffers(id);
|
||||
GL32.glDeleteFramebuffers(id);
|
||||
this.id = -1;
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
{
|
||||
bind();
|
||||
int status = GL43C.glCheckFramebufferStatus(GL30C.GL_FRAMEBUFFER);
|
||||
int status = GL32.glCheckFramebufferStatus(GL32.GL_FRAMEBUFFER);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
+11
-9
@@ -212,9 +212,10 @@ public class LodRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public void resize(int width, int height) {
|
||||
colorTexture.resize(width, height);
|
||||
depthTexture.resize(width, height, EDhDepthBufferFormat.DEPTH32F);
|
||||
public void resize(int width, int height)
|
||||
{
|
||||
this.colorTexture.resize(width, height);
|
||||
this.depthTexture.resize(width, height, EDhDepthBufferFormat.DEPTH32F);
|
||||
}
|
||||
|
||||
|
||||
@@ -292,15 +293,16 @@ public class LodRenderer
|
||||
}
|
||||
}
|
||||
|
||||
if (MC_RENDER.getTargetFrameBufferViewportWidth() != cachedWidth || MC_RENDER.getTargetFrameBufferViewportHeight() != cachedHeight) {
|
||||
if (MC_RENDER.getTargetFrameBufferViewportWidth() != this.cachedWidth || MC_RENDER.getTargetFrameBufferViewportHeight() != this.cachedHeight)
|
||||
{
|
||||
this.cachedWidth = MC_RENDER.getTargetFrameBufferViewportWidth();
|
||||
this.cachedHeight = MC_RENDER.getTargetFrameBufferViewportHeight();
|
||||
resize(cachedWidth, cachedHeight);
|
||||
this.resize(this.cachedWidth, this.cachedHeight);
|
||||
}
|
||||
|
||||
this.setActiveFramebufferId(framebuffer.getId());
|
||||
this.setActiveDepthTextureId(depthTexture.getTextureId());
|
||||
this.setActiveColorTextureId(colorTexture.getTexture());
|
||||
this.setActiveColorTextureId(colorTexture.getTextureId());
|
||||
// Bind LOD frame buffer
|
||||
this.framebuffer.bind();
|
||||
|
||||
@@ -548,13 +550,13 @@ public class LodRenderer
|
||||
.build();
|
||||
this.depthTexture = new DHDepthTexture(MC_RENDER.getTargetFrameBufferViewportWidth(), MC_RENDER.getTargetFrameBufferViewportHeight(), EDhDepthBufferFormat.DEPTH32F);
|
||||
|
||||
this.framebuffer.addDepthAttachment(depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F);
|
||||
this.framebuffer.addColorAttachment(0, colorTexture.getTexture());
|
||||
this.framebuffer.addDepthAttachment(this.depthTexture.getTextureId(), EDhDepthBufferFormat.DEPTH32F);
|
||||
this.framebuffer.addColorAttachment(0, this.colorTexture.getTextureId());
|
||||
|
||||
this.cachedWidth = MC_RENDER.getTargetFrameBufferViewportWidth();
|
||||
this.cachedHeight = MC_RENDER.getTargetFrameBufferViewportHeight();
|
||||
|
||||
if(framebuffer.getStatus() != GL32.GL_FRAMEBUFFER_COMPLETE)
|
||||
if(this.framebuffer.getStatus() != GL32.GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
// This generally means something wasn't bound, IE missing either the color or depth texture
|
||||
tickLogger.warn("FrameBuffer ["+this.framebuffer.getId()+"] isn't complete.");
|
||||
|
||||
Reference in New Issue
Block a user