GL: Allow clearing of 3D texture using the framebuffer workaround

There was no actual issue when binding the whole texture as
layers. Cleanup the implementation and remove the assert.

Pull Request: https://projects.blender.org/blender/blender/pulls/113897
This commit is contained in:
Clément Foucault
2023-10-18 17:56:38 +02:00
committed by Clément Foucault
parent ba83825cfa
commit 5d1489c61d
3 changed files with 14 additions and 15 deletions

View File

@@ -779,7 +779,7 @@ void GPU_texture_update_mipmap(GPUTexture *texture,
/**
* Fills the whole texture with the same data for all pixels.
* \warning Only work for 2D texture for now.
* \warning Only works for 2D and 3D textures.
* \warning Only clears the MIP 0 of the texture.
* \param data_format: data format of the pixel data.
* \note The format is float for UNORM textures.

View File

@@ -40,7 +40,7 @@ GLTexture::GLTexture(const char *name) : Texture(name)
GLTexture::~GLTexture()
{
if (framebuffer_) {
GPU_framebuffer_free(framebuffer_);
GPU_framebuffer_free(wrap(framebuffer_));
}
GLContext *ctx = GLContext::get();
if (ctx != nullptr && is_bound_) {
@@ -400,7 +400,7 @@ void GLTexture::clear(eGPUDataFormat data_format, const void *data)
/* Fallback for older GL. */
GPUFrameBuffer *prev_fb = GPU_framebuffer_active_get();
FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(this->framebuffer_get());
FrameBuffer *fb = this->framebuffer_get();
fb->bind(true);
fb->clear_attachment(this->attachment_type(0), data_format, data);
@@ -431,8 +431,11 @@ void GLTexture::copy_to(Texture *dst_)
}
else {
/* Fallback for older GL. */
GPU_framebuffer_blit(
src->framebuffer_get(), 0, dst->framebuffer_get(), 0, to_framebuffer_bits(format_));
GPU_framebuffer_blit(wrap(src->framebuffer_get()),
0,
wrap(dst->framebuffer_get()),
0,
to_framebuffer_bits(format_));
}
has_pixels_ = true;
@@ -528,16 +531,14 @@ void GLTexture::mip_range_set(int min, int max)
}
}
GPUFrameBuffer *GLTexture::framebuffer_get()
FrameBuffer *GLTexture::framebuffer_get()
{
if (framebuffer_) {
return framebuffer_;
}
BLI_assert(!(type_ & (GPU_TEXTURE_ARRAY | GPU_TEXTURE_CUBE | GPU_TEXTURE_1D | GPU_TEXTURE_3D)));
/* TODO(fclem): cleanup this. Don't use GPU object but blender::gpu ones. */
GPUTexture *gputex = reinterpret_cast<GPUTexture *>(static_cast<Texture *>(this));
framebuffer_ = GPU_framebuffer_create(name_);
GPU_framebuffer_texture_attach(framebuffer_, gputex, 0, 0);
BLI_assert(!(type_ & GPU_TEXTURE_1D));
framebuffer_ = unwrap(GPU_framebuffer_create(name_));
framebuffer_->attachment_set(this->attachment_type(0), GPU_ATTACHMENT_TEXTURE(wrap(this)));
has_pixels_ = true;
return framebuffer_;
}

View File

@@ -14,8 +14,6 @@
#include "gpu_texture_private.hh"
struct GPUFrameBuffer;
namespace blender {
namespace gpu {
@@ -47,7 +45,7 @@ class GLTexture : public Texture {
/** opengl identifier for texture. */
GLuint tex_id_ = 0;
/** Legacy workaround for texture copy. Created when using framebuffer_get(). */
GPUFrameBuffer *framebuffer_ = nullptr;
FrameBuffer *framebuffer_ = nullptr;
/** True if this texture is bound to at least one texture unit. */
/* TODO(fclem): How do we ensure thread safety here? */
bool is_bound_ = false;
@@ -124,7 +122,7 @@ class GLTexture : public Texture {
void stencil_texture_mode_set(bool use_stencil);
void update_sub_direct_state_access(
int mip, int offset[3], int extent[3], GLenum gl_format, GLenum gl_type, const void *data);
GPUFrameBuffer *framebuffer_get();
FrameBuffer *framebuffer_get();
MEM_CXX_CLASS_ALLOC_FUNCS("GLTexture")
};