Skip to content

Commit

Permalink
Support 3D texture attachments
Browse files Browse the repository at this point in the history
BUGS=[365833134]
  • Loading branch information
pixelflinger committed Sep 12, 2024
1 parent 351d77f commit d4bb6b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 7 additions & 4 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ void OpenGLDriver::framebufferTexture(TargetBufferInfo const& binfo,
if (any(t->usage & TextureUsage::SAMPLEABLE)) {
switch (t->target) {
case SamplerType::SAMPLER_2D:
case SamplerType::SAMPLER_3D:
case SamplerType::SAMPLER_2D_ARRAY:
case SamplerType::SAMPLER_CUBEMAP_ARRAY:
// this could be GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_ARRAY
Expand All @@ -1158,7 +1159,9 @@ void OpenGLDriver::framebufferTexture(TargetBufferInfo const& binfo,
target = getCubemapTarget(binfo.layer);
// note: cubemaps can't be multi-sampled
break;
default:
case SamplerType::SAMPLER_EXTERNAL:
// This is an error. We have asserted in debug build.
target = t->gl.target;
break;
}
}
Expand All @@ -1176,7 +1179,7 @@ void OpenGLDriver::framebufferTexture(TargetBufferInfo const& binfo,

if (rt->gl.samples <= 1 ||
(rt->gl.samples > 1 && t->samples > 1 && gl.features.multisample_texture)) {
// on GL3.2 / GLES3.1 and above multisample is handled when creating the texture.
// On GL3.2 / GLES3.1 and above multisample is handled when creating the texture.
// If multisampled textures are not supported and we end-up here, things should
// still work, albeit without MSAA.
gl.bindFramebuffer(GL_FRAMEBUFFER, rt->gl.fbo);
Expand All @@ -1200,6 +1203,7 @@ void OpenGLDriver::framebufferTexture(TargetBufferInfo const& binfo,
GL_RENDERBUFFER, t->gl.id);
}
break;
case GL_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
case GL_TEXTURE_CUBE_MAP_ARRAY:
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
Expand Down Expand Up @@ -1313,6 +1317,7 @@ void OpenGLDriver::framebufferTexture(TargetBufferInfo const& binfo,
GL_RENDERBUFFER, t->gl.id);
}
break;
case GL_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
case GL_TEXTURE_CUBE_MAP_ARRAY:
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
Expand Down Expand Up @@ -2379,9 +2384,7 @@ void OpenGLDriver::updateSamplerGroup(Handle<HwSamplerGroup> sbh,
GLSamplerGroup* const sb = handle_cast<GLSamplerGroup *>(sbh);
assert_invariant(sb->textureUnitEntries.size() == data.size / sizeof(SamplerDescriptor));

#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
bool const es2 = context.isES2();
#endif

auto const* const pSamplers = (SamplerDescriptor const*)data.buffer;
for (size_t i = 0, c = sb->textureUnitEntries.size(); i < c; i++) {
Expand Down
16 changes: 15 additions & 1 deletion filament/src/details/RenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@

#include "FilamentAPI-impl.h"

#include <utils/Panic.h>
#include <filament/RenderTarget.h>

#include <utils/compiler.h>
#include <utils/BitmaskEnum.h>
#include <utils/Panic.h>

#include <algorithm>
#include <iterator>
#include <limits>

#include <stdint.h>
#include <stddef.h>


namespace filament {

Expand Down Expand Up @@ -73,11 +83,15 @@ RenderTarget* RenderTarget::Builder::build(Engine& engine) {
if (color.texture) {
FILAMENT_CHECK_PRECONDITION(color.texture->getUsage() & TextureUsage::COLOR_ATTACHMENT)
<< "Texture usage must contain COLOR_ATTACHMENT";
FILAMENT_CHECK_PRECONDITION(color.texture->getTarget() != Texture::Sampler::SAMPLER_EXTERNAL)
<< "Color attachment can't be an external texture";
}

if (depth.texture) {
FILAMENT_CHECK_PRECONDITION(depth.texture->getUsage() & TextureUsage::DEPTH_ATTACHMENT)
<< "Texture usage must contain DEPTH_ATTACHMENT";
FILAMENT_CHECK_PRECONDITION(depth.texture->getTarget() != Texture::Sampler::SAMPLER_EXTERNAL)
<< "Depth attachment can't be an external texture";
}

const size_t maxDrawBuffers = downcast(engine).getDriverApi().getMaxDrawBuffers();
Expand Down

0 comments on commit d4bb6b8

Please sign in to comment.