Skip to content

Commit

Permalink
remove unused DepthTexture (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren authored Oct 10, 2024
1 parent 8cb9c0f commit 3723552
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 86 deletions.
1 change: 0 additions & 1 deletion include/threepp/renderers/GLRenderTarget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace threepp {
bool generateMipmaps{false};
bool depthBuffer{true};
bool stencilBuffer{false};
std::shared_ptr<DepthTexture> depthTexture;

Options() = default;
};
Expand Down
24 changes: 0 additions & 24 deletions include/threepp/textures/DepthTexture.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ set(publicHeaders
"threepp/textures/CubeTexture.hpp"
"threepp/textures/DataTexture.hpp"
"threepp/textures/DataTexture3D.hpp"
"threepp/textures/DepthTexture.hpp"
"threepp/textures/Image.hpp"
"threepp/textures/Texture.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/threepp/renderers/GLRenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GLRenderTarget::GLRenderTarget(unsigned int width, unsigned int height, const Op
width(width), height(height),
scissor(0.f, 0.f, static_cast<float>(width), static_cast<float>(height)),
viewport(0.f, 0.f, static_cast<float>(width), static_cast<float>(height)),
depthBuffer(options.depthBuffer), stencilBuffer(options.stencilBuffer), depthTexture(options.depthTexture),
depthBuffer(options.depthBuffer), stencilBuffer(options.stencilBuffer),
texture(Texture::create({Image({}, width, height)})) {

if (options.mapping) texture->mapping = *options.mapping;
Expand Down
62 changes: 6 additions & 56 deletions src/threepp/renderers/gl/GLTextures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "threepp/renderers/gl/GLUtils.hpp"

#include "threepp/textures/DataTexture3D.hpp"
#include "threepp/textures/DepthTexture.hpp"

#if EMSCRIPTEN
#include <GLES3/gl32.h>
Expand Down Expand Up @@ -248,11 +247,6 @@ void gl::GLTextures::deallocateRenderTarget(GLRenderTarget* renderTarget) {
info->memory.textures--;
}

if (renderTarget->depthTexture) {

renderTarget->depthTexture->dispose();
}

glDeleteFramebuffers(1, &renderTargetProperties->glFramebuffer.value());
if (renderTargetProperties->glDepthbuffer) glDeleteRenderbuffers(1, &renderTargetProperties->glDepthbuffer.value());

Expand Down Expand Up @@ -437,59 +431,15 @@ void gl::GLTextures::setupRenderBufferStorage(unsigned int renderbuffer, GLRende
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}

void gl::GLTextures::setupDepthTexture(unsigned int framebuffer, GLRenderTarget* renderTarget) {

state->bindFramebuffer(GL_FRAMEBUFFER, framebuffer);

if (!(renderTarget->depthTexture && renderTarget->depthTexture)) {

throw std::runtime_error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");
}

// upload an empty depth texture with framebuffer size
if (!properties->textureProperties.get(renderTarget->depthTexture.get())->glTexture ||
renderTarget->depthTexture->image().width != renderTarget->width ||
renderTarget->depthTexture->image().height != renderTarget->height) {

renderTarget->depthTexture->image().width = renderTarget->width;
renderTarget->depthTexture->image().height = renderTarget->height;
renderTarget->depthTexture->needsUpdate();
}

setTexture2D(*renderTarget->depthTexture, 0);

const auto glDepthTexture = properties->textureProperties.get(renderTarget->depthTexture.get())->glTexture;

if (renderTarget->depthTexture->format == Format::Depth) {

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, *glDepthTexture, 0);

} else if (renderTarget->depthTexture->format == Format::DepthStencil) {

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, *glDepthTexture, 0);

} else {

throw std::runtime_error("Unknown depthTexture format");
}
}

void gl::GLTextures::setupDepthRenderbuffer(GLRenderTarget* renderTarget) {

auto renderTargetProperties = properties->renderTargetProperties.get(renderTarget);

if (renderTarget->depthTexture) {

setupDepthTexture(*renderTargetProperties->glFramebuffer, renderTarget);
const auto renderTargetProperties = properties->renderTargetProperties.get(renderTarget);

} else {

state->bindFramebuffer(GL_FRAMEBUFFER, renderTargetProperties->glFramebuffer.value());
GLuint glDepthbuffer;
glGenRenderbuffers(1, &glDepthbuffer);
renderTargetProperties->glDepthbuffer = glDepthbuffer;
setupRenderBufferStorage(*renderTargetProperties->glDepthbuffer, renderTarget);
}
state->bindFramebuffer(GL_FRAMEBUFFER, renderTargetProperties->glFramebuffer.value());
GLuint glDepthbuffer;
glGenRenderbuffers(1, &glDepthbuffer);
renderTargetProperties->glDepthbuffer = glDepthbuffer;
setupRenderBufferStorage(*renderTargetProperties->glDepthbuffer, renderTarget);

state->bindFramebuffer(GL_FRAMEBUFFER, 0);
}
Expand Down
3 changes: 0 additions & 3 deletions src/threepp/renderers/gl/GLTextures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ namespace threepp::gl {

void setupRenderBufferStorage(unsigned int renderbuffer, GLRenderTarget* renderTarget);

// Setup resources for a Depth Texture for a FBO (needs an extension)
void setupDepthTexture(unsigned int framebuffer, GLRenderTarget* renderTarget);

// Setup GL resources for a non-texture depth buffer
void setupDepthRenderbuffer(GLRenderTarget* renderTarget);

Expand Down

0 comments on commit 3723552

Please sign in to comment.