34 _dimensions(dimensions),
39 assert(
target == GL_TEXTURE_2D ||
target == GL_TEXTURE_CUBE_MAP);
43 glGenFramebuffers(1, &
_fboID);
53 glTexParameteri(
target, GL_TEXTURE_MIN_FILTER, minFilter);
54 glTexParameteri(
target, GL_TEXTURE_MAG_FILTER, magFilter);
55 glTexParameteri(
target, GL_TEXTURE_WRAP_S, wrap);
56 glTexParameteri(
target, GL_TEXTURE_WRAP_T, wrap);
59 if (borderColor !=
nullptr)
60 glTexParameterfv(
target, GL_TEXTURE_BORDER_COLOR, borderColor);
65 if (
target == GL_TEXTURE_2D)
67 glTexImage2D(GL_TEXTURE_2D,
69 GL_DEPTH_COMPONENT32F,
79 glFramebufferTexture2D(GL_FRAMEBUFFER,
88 for (
SLint i = 0; i < 6; ++i)
90 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
92 GL_DEPTH_COMPONENT32F,
102 glFramebufferTexture2D(GL_FRAMEBUFFER,
104 GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
112 glDrawBuffer(GL_NONE);
116 glReadBuffer(GL_NONE);
121 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
122 SL_LOG(
"FBO failed to initialize correctly.");
129 glDeleteTextures(1, &
_texID);
132 glDeleteFramebuffers(1, &
_fboID);
171 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &
_prevFboID);
172 glBindFramebuffer(GL_FRAMEBUFFER,
_fboID);
181 glBindFramebuffer(GL_FRAMEBUFFER,
_prevFboID);
189 assert(
_target == GL_TEXTURE_CUBE_MAP);
190 assert(face >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
191 face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
193 glFramebufferTexture2D(GL_FRAMEBUFFER,
#define PROFILE_FUNCTION()
Uses an OpenGL framebuffer object as a depth-buffer.
Singleton class for global render state.
void bindActive(SLuint texUnit) const
Sets the active texture unit within the shader and binds the texture.
void bindFace(SLenum face) const
Binds a specific texture face of a cube map depth buffer.
SLuint _fboID
ID of the FB object.
SLint _prevFboID
ID of the previously bound FB.
SLenum _target
GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
SLVec2i _dimensions
Size of the texture.
void bind()
Binds the OpenGL frame buffer object for the depth buffer.
SLuint _texID
ID of the texture.
void unbind()
Ends the usage of the depth buffer frame buffer.
SLfloat * readPixels() const
SLGLDepthBuffer(const SLVec2i &dimensions, SLenum magFilter=GL_NEAREST, SLenum minFilter=GL_NEAREST, SLint wrap=GL_REPEAT, SLfloat borderColor[]=nullptr, SLenum target=GL_TEXTURE_2D, SLstring name="SM-DepthBuffer")
Singleton class holding all OpenGL states.
void activeTexture(SLenum textureUnit)
static SLGLState * instance()
Public static instance getter for singleton pattern.
void bindTexture(SLenum target, SLuint textureID)
Base class for all other classes.