SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLFrameBuffer Class Reference

#include <SLGLFrameBuffer.h>

Public Member Functions

 SLGLFrameBuffer (SLsizei rboWidth, SLsizei rboHeight)
 Constructor. More...
 
virtual ~SLGLFrameBuffer ()
 
void clear ()
 Calls delete and clears data. More...
 
void deleteGL ()
 Deletes this buffers. More...
 
void generate ()
 Generates the framebuffer. More...
 
void bind ()
 Binds the framebuffer and renderbuffer. More...
 
void unbind ()
 Unbinds the framebuffer and renderbuffer. More...
 
void bindAndSetBufferStorage (SLsizei width, SLsizei height)
 Sets the size of the buffer storage. More...
 
void attachTexture2D (SLenum attachment, SLenum target, SLGLTexture *texture, SLint level=0)
 Attaches texture image to framebuffer. More...
 
SLuint fboId ()
 
SLuint rboId ()
 
SLsizei rboWidth ()
 
SLsizei rboHeight ()
 

Static Public Attributes

static SLuint totalBufferCount = 0
 
static SLuint totalBufferSize = 0
 static total no. of buffers in use More...
 

Protected Attributes

SLuint _fboId
 static total size of all buffers in bytes More...
 
SLuint _prevFboId
 previously active frame buffer identifier More...
 
SLuint _rboId
 render buffer identifier More...
 
SLuint _sizeBytes
 size in bytes of this buffer More...
 
SLsizei _rboWidth
 width of the render buffer More...
 
SLsizei _rboHeight
 height of the render buffer More...
 

Detailed Description

The frame buffer class generates a frame buffer and a render buffer, with the default size of 512x512, this can also in run time be changed.

Definition at line 21 of file SLGLFrameBuffer.h.

Constructor & Destructor Documentation

◆ SLGLFrameBuffer()

SLGLFrameBuffer::SLGLFrameBuffer ( SLsizei  rboWidth,
SLsizei  rboHeight 
)

Constructor.

Definition at line 18 of file SLGLFrameBuffer.cpp.

20 {
21  _fboId = 0;
22  _rboId = 0;
23  _prevFboId = 0;
26 }
SLuint _prevFboId
previously active frame buffer identifier
SLsizei rboWidth()
SLsizei _rboHeight
height of the render buffer
SLuint _fboId
static total size of all buffers in bytes
SLsizei _rboWidth
width of the render buffer
SLuint _rboId
render buffer identifier
SLsizei rboHeight()

◆ ~SLGLFrameBuffer()

virtual SLGLFrameBuffer::~SLGLFrameBuffer ( )
inlinevirtual

Definition at line 25 of file SLGLFrameBuffer.h.

25 { clear(); }
void clear()
Calls delete and clears data.

Member Function Documentation

◆ attachTexture2D()

void SLGLFrameBuffer::attachTexture2D ( SLenum  attachment,
SLenum  target,
SLGLTexture texture,
SLint  level = 0 
)

Attaches texture image to framebuffer.

attach one 2D texture to the frame buffer

Definition at line 116 of file SLGLFrameBuffer.cpp.

120 {
121  assert(_fboId && _rboId);
122  glFramebufferTexture2D(GL_FRAMEBUFFER,
123  attachment,
124  target,
125  texture->texID(),
126  level);
127 }
SLuint texID() const
Definition: SLGLTexture.h:227

◆ bind()

void SLGLFrameBuffer::bind ( )

Binds the framebuffer and renderbuffer.

Definition at line 78 of file SLGLFrameBuffer.cpp.

79 {
80  assert(_fboId && "No framebuffer generated");
81 
82  // Keep the previous FB ID for later unbinding
83  SLint prevFboId;
84  glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFboId);
85  if (prevFboId != _fboId)
86  _prevFboId = prevFboId;
87 
88  glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
89 
90  assert(_rboId && "No renderbuffer generated");
91  glBindRenderbuffer(GL_RENDERBUFFER, _rboId);
92 }
int SLint
Definition: SL.h:170

◆ bindAndSetBufferStorage()

void SLGLFrameBuffer::bindAndSetBufferStorage ( SLsizei  width,
SLsizei  height 
)

Sets the size of the buffer storage.

change the render buffer size at will

Definition at line 103 of file SLGLFrameBuffer.cpp.

105 {
106  bind();
107  _rboWidth = width;
108  _rboHeight = height;
109  glRenderbufferStorage(GL_RENDERBUFFER,
110  GL_DEPTH_COMPONENT24,
111  width,
112  height);
113 }
void bind()
Binds the framebuffer and renderbuffer.

◆ clear()

void SLGLFrameBuffer::clear ( )

Calls delete and clears data.

clear delete buffers and respectively adjust the stats variables

Definition at line 29 of file SLGLFrameBuffer.cpp.

30 {
31  deleteGL();
34 }
static SLuint totalBufferCount
static SLuint totalBufferSize
static total no. of buffers in use
SLuint _sizeBytes
size in bytes of this buffer
void deleteGL()
Deletes this buffers.

◆ deleteGL()

void SLGLFrameBuffer::deleteGL ( )

Deletes this buffers.

calls the delete functions only if the buffers exist

Definition at line 37 of file SLGLFrameBuffer.cpp.

38 {
39  unbind();
40 
41  if (_fboId)
42  {
43  glDeleteBuffers(1, &_fboId);
44  _fboId = 0;
45  }
46 
47  if (_rboId)
48  {
49  glDeleteBuffers(1, &_rboId);
50  _rboId = 0;
51  }
52 }
void unbind()
Unbinds the framebuffer and renderbuffer.

◆ fboId()

SLuint SLGLFrameBuffer::fboId ( )
inline

Definition at line 53 of file SLGLFrameBuffer.h.

53 { return this->_fboId; }

◆ generate()

void SLGLFrameBuffer::generate ( )

Generates the framebuffer.

generate the frame buffer and the render buffer if wanted

Definition at line 55 of file SLGLFrameBuffer.cpp.

56 {
57  if (_fboId == 0)
58  {
59  glGenFramebuffers(1, &_fboId);
60  glGenRenderbuffers(1, &_rboId);
62  glFramebufferRenderbuffer(GL_FRAMEBUFFER,
63  GL_DEPTH_ATTACHMENT,
64  GL_RENDERBUFFER,
65  _rboId);
66 
67  // test if the generated fbo is valid
68  if ((glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE)
69  SL_EXIT_MSG("Frame buffer creation failed!");
70 
71  unbind();
73 
75  }
76 }
#define SL_EXIT_MSG(message)
Definition: SL.h:240
#define GET_GL_ERROR
Definition: SLGLState.h:56
void bindAndSetBufferStorage(SLsizei width, SLsizei height)
Sets the size of the buffer storage.

◆ rboHeight()

SLsizei SLGLFrameBuffer::rboHeight ( )
inline

Definition at line 56 of file SLGLFrameBuffer.h.

56 { return this->_rboHeight; }

◆ rboId()

SLuint SLGLFrameBuffer::rboId ( )
inline

Definition at line 54 of file SLGLFrameBuffer.h.

54 { return this->_rboId; }

◆ rboWidth()

SLsizei SLGLFrameBuffer::rboWidth ( )
inline

Definition at line 55 of file SLGLFrameBuffer.h.

55 { return this->_rboWidth; }

◆ unbind()

void SLGLFrameBuffer::unbind ( )

Unbinds the framebuffer and renderbuffer.

Definition at line 94 of file SLGLFrameBuffer.cpp.

95 {
96  // iOS does not allow binding to 0. That's why we keep the previous FB ID
97  glBindFramebuffer(GL_FRAMEBUFFER, _prevFboId);
98 
99  glBindRenderbuffer(GL_RENDERBUFFER, 0);
100 }

Member Data Documentation

◆ _fboId

SLuint SLGLFrameBuffer::_fboId
protected

static total size of all buffers in bytes

frame buffer identifier

Definition at line 63 of file SLGLFrameBuffer.h.

◆ _prevFboId

SLuint SLGLFrameBuffer::_prevFboId
protected

previously active frame buffer identifier

Definition at line 64 of file SLGLFrameBuffer.h.

◆ _rboHeight

SLsizei SLGLFrameBuffer::_rboHeight
protected

height of the render buffer

Definition at line 68 of file SLGLFrameBuffer.h.

◆ _rboId

SLuint SLGLFrameBuffer::_rboId
protected

render buffer identifier

Definition at line 65 of file SLGLFrameBuffer.h.

◆ _rboWidth

SLsizei SLGLFrameBuffer::_rboWidth
protected

width of the render buffer

Definition at line 67 of file SLGLFrameBuffer.h.

◆ _sizeBytes

SLuint SLGLFrameBuffer::_sizeBytes
protected

size in bytes of this buffer

Definition at line 66 of file SLGLFrameBuffer.h.

◆ totalBufferCount

SLuint SLGLFrameBuffer::totalBufferCount = 0
static

Definition at line 59 of file SLGLFrameBuffer.h.

◆ totalBufferSize

SLuint SLGLFrameBuffer::totalBufferSize = 0
static

static total no. of buffers in use

Definition at line 60 of file SLGLFrameBuffer.h.


The documentation for this class was generated from the following files: