
com.flowpowered.caustic.lwjgl.gl20.GL20RenderBuffer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of caustic-lwjgl Show documentation
Show all versions of caustic-lwjgl Show documentation
LWJGL implementation of the Caustic rendering library API.
The newest version!
/*
* This file is part of Caustic LWJGL, licensed under the MIT License (MIT).
*
* Copyright (c) 2013 Flow Powered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.flowpowered.caustic.lwjgl.gl20;
import org.lwjgl.opengl.EXTFramebufferObject;
import org.lwjgl.opengl.GLContext;
import com.flowpowered.caustic.api.gl.RenderBuffer;
import com.flowpowered.caustic.api.gl.Texture.InternalFormat;
import com.flowpowered.caustic.lwjgl.LWJGLUtil;
/**
* An OpenGL 2.0 implementation of {@link RenderBuffer} using EXT.
*
* @see RenderBuffer
*/
public class GL20RenderBuffer extends RenderBuffer {
// The render buffer storage format
private InternalFormat format;
// The storage dimensions
private int width = 1;
private int height = 1;
/**
* Constructs a new render buffer for OpenGL 2.0. If no EXT extension for render buffers is available, an exception is thrown.
*
* @throws UnsupportedOperationException If the hardware doesn't support EXT render buffers.
*/
public GL20RenderBuffer() {
if (!GLContext.getCapabilities().GL_EXT_framebuffer_object) {
throw new UnsupportedOperationException("Render buffers are not supported by this hardware");
}
}
@Override
public void create() {
checkNotCreated();
// Generate the render buffer
id = EXTFramebufferObject.glGenRenderbuffersEXT();
// Update the state
super.create();
// Check for errors
LWJGLUtil.checkForGLError();
}
@Override
public void destroy() {
checkCreated();
// Delete the render buffer
EXTFramebufferObject.glDeleteRenderbuffersEXT(id);
// Update state
super.destroy();
// Check for errors
LWJGLUtil.checkForGLError();
}
@Override
public void setStorage(InternalFormat format, int width, int height) {
checkCreated();
if (format == null) {
throw new IllegalArgumentException("Format cannot be null");
}
if (width <= 0) {
throw new IllegalArgumentException("Width must be greater than zero");
}
if (height <= 0) {
throw new IllegalArgumentException("Height must be greater than zero");
}
this.format = format;
this.width = width;
this.height = height;
// Bind the render buffer
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, id);
// Set the storage format and size
EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, format.getGLConstant(), width, height);
// Unbind the render buffer
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);
// Check for errors
LWJGLUtil.checkForGLError();
}
@Override
public InternalFormat getFormat() {
return format;
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public void bind() {
checkCreated();
// Unbind the render buffer
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, id);
// Check for errors
LWJGLUtil.checkForGLError();
}
@Override
public void unbind() {
checkCreated();
// Bind the render buffer
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);
// Check for errors
LWJGLUtil.checkForGLError();
}
@Override
public GLVersion getGLVersion() {
return GLVersion.GL20;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy