VIZ++ Class: OpenGLFrameBuffers
|
Source code
/*
* OpenGLFrameBuffers.h
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
#pragma once
#ifdef GL_ARB_framebuffer_object
#include <viz++/opengl/OpenGLObject.h>
namespace VIZ {
class OpenGLFrameBuffers :public OpenGLObject {
private:
GLsizei size;
GLuint* buffers;
protected:
void generate(GLsizei size, GLuint* buffers)
{
static PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = NULL;
if (glGenFramebuffers == NULL) {
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)load("glGenFramebuffers");
}
glGenFramebuffers(size, buffers);
}
void bind(GLenum target, GLuint buffer)
{
static PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = NULL;
if (glBindFramebuffer == NULL) {
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)load("glBindFramebuffer");
}
glBindFramebuffer(target, buffer);
}
void destroy()
{
static PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = NULL;
if (glDeleteFramebuffers == NULL) {
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)load("glDeleteFramebuffers");
}
glDeleteFramebuffers(size, buffers);
}
public:
OpenGLFrameBuffers(GLsizei n)
:OpenGLObject(),
size(n),
buffers(NULL)
{
if (size <= 0) {
throw IException("Invalid size parameter. size=%d", size);
}
buffers = new GLuint[size];
generate(size, buffers);
}
~OpenGLFrameBuffers()
{
destroy();
delete [] buffers;
buffers = NULL;
}
void blit(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0,
GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
{
static PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer = NULL;
if (glBlitFramebuffer == NULL) {
glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)load("glBlitFramebuffer");
}
glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
dstX1, dstY1, mask, filter);
}
GLenum check(GLenum target)
{
static PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = NULL;
if (glCheckFramebufferStatus == NULL) {
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)load("glCheckFramebufferStatus");
}
return glCheckFramebufferStatus(target);
}
void attachRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
{
static PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = NULL;
if (glFramebufferRenderbuffer == NULL) {
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)load("glFramebufferRenderbuffer");
}
glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
}
void detachRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget)
{
attachRenderbuffer(target, attachment, renderbuffertarget, 0);
}
void texture1D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
static PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D = NULL;
if (glFramebufferTexture1D == NULL) {
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)load("glFramebufferTexture1D");
}
glFramebufferTexture1D(target, attachment, textarget, texture, level);
}
void texture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
static PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = NULL;
if (glFramebufferTexture2D == NULL) {
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)load("glFramebufferTexture2D");
}
glFramebufferTexture2D(target, attachment, textarget, texture, level);
}
void texture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset)
{
static PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D = NULL;
if (glFramebufferTexture3D == NULL) {
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)load("glFramebufferTexture3D");
}
glFramebufferTexture3D(target, attachment, textarget, texture,level, zoffset);
}
void getAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
{
static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv = NULL;
if (glGetFramebufferAttachmentParameteriv == NULL) {
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)load("glGetFramebufferAttachmentParameteriv");
}
glGetFramebufferAttachmentParameteriv(target, attachment, pname, params);
}
GLboolean isFramebuffer(GLuint buffer)
{
static PFNGLISFRAMEBUFFERPROC glIsFramebuffer = NULL;
if (glIsFramebuffer == NULL) {
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)load("glIsFramebuffer");
}
return glIsFramebuffer(buffer);
}
GLuint getNth(int n)
{
if (n >= 0 && n < size) {
return buffers[n];
} else {
throw IException("Invalid index %d", n);
}
}
void bindNth(GLenum target, int n)
{
if (n >= 0 && n < size) {
bind(target, buffers[n]);
} else {
throw IException("Invalid index %d", n);
}
}
};
}
#endif
Last modified: 10 Feb 2017
Copyright (c) 2009-2017 Antillia.com ALL RIGHTS RESERVED.