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

#include <SLGLFbo.h>

Public Member Functions

 SLGLFbo (SLuint w, SLuint h, SLenum magFilter=GL_NEAREST, SLenum minFilter=GL_NEAREST, SLint internalFormat=GL_RGB16F, SLint format=GL_FLOAT, SLint wrap=GL_REPEAT)
 
 ~SLGLFbo ()
 
void activateAsTexture (int progId, const SLstring &samplerName, int textureUnit=0)
 

Public Attributes

SLuint width
 
SLuint height
 
SLuint attachment
 
SLuint fboID
 
SLuint texID
 
SLuint rboID
 

Detailed Description

Definition at line 17 of file SLGLFbo.h.

Constructor & Destructor Documentation

◆ SLGLFbo()

SLGLFbo::SLGLFbo ( SLuint  w,
SLuint  h,
SLenum  magFilter = GL_NEAREST,
SLenum  minFilter = GL_NEAREST,
SLint  internalFormat = GL_RGB16F,
SLint  format = GL_FLOAT,
SLint  wrap = GL_REPEAT 
)

Definition at line 15 of file SLGLFbo.cpp.

21  : width(w), height(h)
22 {
23  GLint previousFrameBuffer;
24  glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFrameBuffer);
25 
26  // Init framebuffer.
27  glGenFramebuffers(1, &fboID);
28  glBindFramebuffer(GL_FRAMEBUFFER, fboID);
29 
30  glGenTextures(1, &texID);
31  glBindTexture(GL_TEXTURE_2D, texID);
32 
33  // Texture parameters.
34  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
35  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
36  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
37  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
38 
39  glTexImage2D(GL_TEXTURE_2D,
40  0,
41  internalFormat,
42  w,
43  h,
44  0,
45  GL_RGBA,
46  format,
47  nullptr);
48 
49  glFramebufferTexture2D(GL_FRAMEBUFFER,
50  GL_COLOR_ATTACHMENT0,
51  GL_TEXTURE_2D,
52  texID,
53  0);
54 
55  glGenRenderbuffers(1, &rboID);
56  glBindRenderbuffer(GL_RENDERBUFFER, rboID);
57 
58  // Use a single rbo for both depth and stencil buffer
59  glRenderbufferStorage(GL_RENDERBUFFER,
60  GL_DEPTH_COMPONENT24,
61  w,
62  h);
63 
64  glFramebufferRenderbuffer(GL_FRAMEBUFFER,
65  GL_DEPTH_ATTACHMENT,
66  GL_RENDERBUFFER,
67  rboID);
68 
69  glBindRenderbuffer(GL_RENDERBUFFER, 0);
70  glBindFramebuffer(GL_FRAMEBUFFER,
71  previousFrameBuffer);
72 
73  if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
74  std::cerr << "FBO failed to initialize correctly." << std::endl;
75 }
SLuint texID
Definition: SLGLFbo.h:38
SLuint height
Definition: SLGLFbo.h:35
SLuint fboID
Definition: SLGLFbo.h:37
SLuint rboID
Definition: SLGLFbo.h:39
SLuint width
Definition: SLGLFbo.h:34

◆ ~SLGLFbo()

SLGLFbo::~SLGLFbo ( )

Definition at line 77 of file SLGLFbo.cpp.

78 {
79  glDeleteTextures(1, &texID);
80  glDeleteFramebuffers(1, &fboID);
81 }

Member Function Documentation

◆ activateAsTexture()

void SLGLFbo::activateAsTexture ( int  progId,
const SLstring samplerName,
int  textureUnit = 0 
)

Definition at line 83 of file SLGLFbo.cpp.

86 {
87  glActiveTexture(GL_TEXTURE0 + textureUnit);
88  glBindTexture(GL_TEXTURE_2D, texID);
89  glUniform1i(glGetUniformLocation(progId,
90  glSamplerName.c_str()),
91  textureUnit);
92 }

Member Data Documentation

◆ attachment

SLuint SLGLFbo::attachment

Definition at line 36 of file SLGLFbo.h.

◆ fboID

SLuint SLGLFbo::fboID

Definition at line 37 of file SLGLFbo.h.

◆ height

SLuint SLGLFbo::height

Definition at line 35 of file SLGLFbo.h.

◆ rboID

SLuint SLGLFbo::rboID

Definition at line 39 of file SLGLFbo.h.

◆ texID

SLuint SLGLFbo::texID

Definition at line 38 of file SLGLFbo.h.

◆ width

SLuint SLGLFbo::width

Definition at line 34 of file SLGLFbo.h.


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