VIZ++ Class: OpenGLFrameBuffersExt

 VIZ++ Class Library  VIZ++ Samples  VIZ++ ClassTree 

Source code

/*
 * OpenGLFrameBuffersExt.h 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



#pragma once

#ifdef GL_EXT_framebuffer_object

#include <viz++/opengl/OpenGLObject.h>

namespace VIZ {

class OpenGLFrameBuffersEXT :public OpenGLObject {

private:
  GLsizei size;
  GLuint* buffers;
  
protected:
  void generate(GLsizei size, GLuint* buffers)
  {
    static PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT = NULL;
    if (glGenFramebuffersEXT == NULL) {
      glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)load("glGenFramebuffersEXT");
    }
    glGenFramebuffersEXT(size, buffers);
  }
  
  void bind(GLenum target, GLuint buffer)
  {
    static PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT = NULL;
    if (glBindFramebufferEXT == NULL) {
      glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)load("glBindFramebufferEXT");
    }
    glBindFramebufferEXT(target, buffer);
  }
  
  void destroy()
  {
    static PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT = NULL;
    if (glDeleteFramebuffersEXT == NULL) {
      glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)load("glDeleteFramebuffersEXT");
    }
    glDeleteFramebuffersEXT(size, buffers);  
  }

public:
  OpenGLFrameBuffersEXT(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);
  }
  
  ~OpenGLFrameBuffersEXT()
  {
    destroy();
    delete [] buffers;
    buffers = NULL;
  }
  
  GLenum check(GLenum target)
  {
    static PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT = NULL;
    if (glCheckFramebufferStatusEXT == NULL) {
      glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)load("glCheckFramebufferStatusEXT");
    }
    return glCheckFramebufferStatusEXT(target);
  }

  //Modified method name to be attachRenderBuffer
  void attachRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
  {
    static PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT = NULL;
    if (glFramebufferRenderbufferEXT == NULL) {
      glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)load("glFramebufferRenderbufferEXT");
    }
    glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer);
  }
  
  //2016/07/15
  void detachRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget)
  {
    static PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT = NULL;
    if (glFramebufferRenderbufferEXT == NULL) {
      glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)load("glFramebufferRenderbufferEXT");
    }
    glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, 0);
  }
  
  void texture1D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
  {
    static PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT = NULL;
    if (glFramebufferTexture1DEXT == NULL) {
      glFramebufferTexture1DEXT = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC)load("glFramebufferRenderbufferEXT");
    }
    glFramebufferTexture1DEXT(target, attachment, textarget, texture, level);
  }

  void texture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
  {
    static PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT = NULL;
    if (glFramebufferTexture2DEXT = NULL) {
      glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)load("glFramebufferTexture2DEXT"); 
    }
    glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
  }
    
  void texture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset)
  {
    static PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT = NULL;
    if (glFramebufferTexture3DEXT = NULL) {
      glFramebufferTexture3DEXT = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC)load("glFramebufferTexture3DEXT");
    }
    glFramebufferTexture3DEXT(target, attachment, textarget, texture,level, zoffset);
  }
    

  void getAttachmentParameterivEXT(GLenum target, GLenum attachment, GLenum pname, GLint* params)
  {
    static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT = NULL;
    if (glGetFramebufferAttachmentParameterivEXT == NULL) {
      glGetFramebufferAttachmentParameterivEXT = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC)load("glGetFramebufferAttachmentParameterivEXT");
    }
    glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params);
  }
    
  GLboolean isFramebuffer(GLuint buffer)
  {
    static PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT = NULL;
    if (glIsFramebufferEXT == NULL) {
      glIsFramebufferEXT = (PFNGLISFRAMEBUFFEREXTPROC)load("glIsFramebufferEXT");  
    }
    return glIsFramebufferEXT(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.