mirror of
https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java.git
synced 2026-11-28 14:38:08 -08:00
47 lines
1.3 KiB
Java
47 lines
1.3 KiB
Java
package renderer;
|
|
|
|
import static org.lwjgl.opengl.GL30.glGenFramebuffers;
|
|
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
|
|
import static org.lwjgl.opengl.GL30.glBindFramebuffer;
|
|
import static org.lwjgl.opengl.GL30.*;
|
|
|
|
public class FrameBuffer {
|
|
private int fboID = 0;
|
|
private Texture texture = null;
|
|
|
|
public FrameBuffer(int width, int height) {
|
|
fboID = glGenFramebuffers();
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
|
|
|
|
this.texture = new Texture(width, height);
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this.texture.getId(), 0);
|
|
|
|
int rboID = glGenRenderbuffers();
|
|
glBindRenderbuffer(GL_RENDERBUFFER, rboID);
|
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, width, height);
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID);
|
|
|
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
|
assert false : "Error: Framebuffer is not complete";
|
|
}
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
}
|
|
|
|
public void bind() {
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
|
|
}
|
|
|
|
public void unbind() {
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
}
|
|
|
|
public int getFboID() {
|
|
return fboID;
|
|
}
|
|
|
|
public int getTextureId() {
|
|
return texture.getId();
|
|
}
|
|
}
|