diff options
-rw-r--r-- | source/blender/draw/intern/DRW_gpu_wrapper.hh | 14 | ||||
-rw-r--r-- | source/blender/gpu/GPU_texture.h | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.cc | 12 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture_private.hh | 3 |
4 files changed, 22 insertions, 11 deletions
diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh index 46d4b651330..bb9d24f5045 100644 --- a/source/blender/draw/intern/DRW_gpu_wrapper.hh +++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh @@ -514,7 +514,7 @@ class Texture : NonCopyable { * Ensure the availability of mipmap views. * Mip view covers all layers of array textures. */ - bool ensure_mip_views() + bool ensure_mip_views(bool cube_as_array = false) { int mip_len = GPU_texture_mip_count(tx_); if (mip_views_.size() != mip_len) { @@ -523,7 +523,8 @@ class Texture : NonCopyable { } eGPUTextureFormat format = GPU_texture_format(tx_); for (auto i : IndexRange(mip_len)) { - mip_views_.append(GPU_texture_create_view(name_, tx_, format, i, 1, 0, 9999)); + mip_views_.append( + GPU_texture_create_view(name_, tx_, format, i, 1, 0, 9999, cube_as_array)); } return true; } @@ -539,7 +540,7 @@ class Texture : NonCopyable { * Ensure the availability of mipmap views. * Layer views covers all layers of array textures. */ - bool ensure_layer_views() + bool ensure_layer_views(bool cube_as_array = false) { int layer_len = GPU_texture_layer_count(tx_); if (layer_views_.size() != layer_len) { @@ -548,7 +549,8 @@ class Texture : NonCopyable { } eGPUTextureFormat format = GPU_texture_format(tx_); for (auto i : IndexRange(layer_len)) { - layer_views_.append(GPU_texture_create_view(name_, tx_, format, 0, 9999, i, 1)); + layer_views_.append( + GPU_texture_create_view(name_, tx_, format, 0, 9999, i, 1, cube_as_array)); } return true; } @@ -560,11 +562,11 @@ class Texture : NonCopyable { return layer_views_[layer]; } - GPUTexture *stencil_view() + GPUTexture *stencil_view(bool cube_as_array = false) { if (stencil_view_ == nullptr) { eGPUTextureFormat format = GPU_texture_format(tx_); - stencil_view_ = GPU_texture_create_view(name_, tx_, format, 0, 9999, 0, 9999); + stencil_view_ = GPU_texture_create_view(name_, tx_, format, 0, 9999, 0, 9999, cube_as_array); GPU_texture_stencil_texture_mode_set(stencil_view_, true); } return stencil_view_; diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h index 4dbcd84672c..37edc2abeb2 100644 --- a/source/blender/gpu/GPU_texture.h +++ b/source/blender/gpu/GPU_texture.h @@ -230,6 +230,7 @@ GPUTexture *GPU_texture_create_error(int dimension, bool array); * Create an alias of the source texture data. * If \a src is freed, the texture view will continue to be valid. * If \a mip_start or \a mip_len is bigger than available mips they will be clamped. + * If \a cube_as_array is true, then the texture cube (array) becomes a 2D array texture. * TODO(@fclem): Target conversion is not implemented yet. */ GPUTexture *GPU_texture_create_view(const char *name, @@ -238,7 +239,8 @@ GPUTexture *GPU_texture_create_view(const char *name, int mip_start, int mip_len, int layer_start, - int layer_len); + int layer_len, + bool cube_as_array); void GPU_texture_update_mipmap(GPUTexture *tex, int miplvl, diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc index 0d2ec43533f..b41193f12fa 100644 --- a/source/blender/gpu/intern/gpu_texture.cc +++ b/source/blender/gpu/intern/gpu_texture.cc @@ -136,7 +136,8 @@ bool Texture::init_view(const GPUTexture *src_, int mip_start, int mip_len, int layer_start, - int layer_len) + int layer_len, + bool cube_as_array) { const Texture *src = unwrap(src_); w_ = src->w_; @@ -165,6 +166,10 @@ bool Texture::init_view(const GPUTexture *src_, format_flag_ = to_format_flag(format); /* For now always copy the target. Target aliasing could be exposed later. */ type_ = src->type_; + if (cube_as_array) { + BLI_assert(type_ & GPU_TEXTURE_CUBE); + type_ = (type_ & ~GPU_TEXTURE_CUBE) | GPU_TEXTURE_2D_ARRAY; + } sampler_state = src->sampler_state; return this->init_internal(src_, mip_start, layer_start); } @@ -387,12 +392,13 @@ GPUTexture *GPU_texture_create_view(const char *name, int mip_start, int mip_len, int layer_start, - int layer_len) + int layer_len, + bool cube_as_array) { BLI_assert(mip_len > 0); BLI_assert(layer_len > 0); Texture *view = GPUBackend::get()->texture_alloc(name); - view->init_view(src, format, mip_start, mip_len, layer_start, layer_len); + view->init_view(src, format, mip_start, mip_len, layer_start, layer_len, cube_as_array); return wrap(view); } diff --git a/source/blender/gpu/intern/gpu_texture_private.hh b/source/blender/gpu/intern/gpu_texture_private.hh index 1e81980e95f..109e60e19a6 100644 --- a/source/blender/gpu/intern/gpu_texture_private.hh +++ b/source/blender/gpu/intern/gpu_texture_private.hh @@ -111,7 +111,8 @@ class Texture { int mip_start, int mip_len, int layer_start, - int layer_len); + int layer_len, + bool cube_as_array); virtual void generate_mipmap() = 0; virtual void copy_to(Texture *tex) = 0; |