Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-02-25 03:06:09 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-03-18 22:53:41 +0300
commit0f08453ea9216c3cd957c17278a7158c98525219 (patch)
tree0b251a92e950aa62254c3d84093d7afa812f7153
parent3b75ca2f60f43d7450f5b1570bfedea4d1ed4b1a (diff)
DRW: Add simple texture view wrappers to draw::Texture
-rw-r--r--source/blender/draw/intern/DRW_gpu_wrapper.hh59
1 files changed, 59 insertions, 0 deletions
diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh
index 947ad6edc38..a69df8ac297 100644
--- a/source/blender/draw/intern/DRW_gpu_wrapper.hh
+++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh
@@ -358,6 +358,8 @@ class StorageBuffer : public T, public detail::StorageCommon<T, 1, device_only>
class Texture : NonCopyable {
protected:
GPUTexture *tx_ = nullptr;
+ Vector<GPUTexture *, 0> mip_views_;
+ Vector<GPUTexture *, 0> layer_views_;
const char *name_;
public:
@@ -508,6 +510,56 @@ class Texture : NonCopyable {
}
/**
+ * Ensure the availability of mipmap views.
+ * Mip view covers all layers of array textures.
+ */
+ bool ensure_mip_views()
+ {
+ int mip_len = GPU_texture_mip_count(tx_);
+ if (mip_views_.size() != mip_len) {
+ for (GPUTexture *&view : mip_views_) {
+ GPU_TEXTURE_FREE_SAFE(view);
+ }
+ 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));
+ }
+ return true;
+ }
+ return false;
+ }
+
+ GPUTexture *mip_view(int miplvl)
+ {
+ return mip_views_[miplvl];
+ }
+
+ /**
+ * Ensure the availability of mipmap views.
+ * Layer views covers all layers of array textures.
+ */
+ bool ensure_layer_views()
+ {
+ int layer_len = GPU_texture_layer_count(tx_);
+ if (layer_views_.size() != layer_len) {
+ for (GPUTexture *&view : layer_views_) {
+ GPU_TEXTURE_FREE_SAFE(view);
+ }
+ 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));
+ }
+ return true;
+ }
+ return false;
+ }
+
+ GPUTexture *layer_view(int layer)
+ {
+ return layer_views_[layer];
+ }
+
+ /**
* Returns true if the texture has been allocated or acquired from the pool.
*/
bool is_valid(void) const
@@ -601,6 +653,13 @@ class Texture : NonCopyable {
void free()
{
GPU_TEXTURE_FREE_SAFE(tx_);
+ for (GPUTexture *&view : mip_views_) {
+ GPU_TEXTURE_FREE_SAFE(view);
+ }
+ for (GPUTexture *&view : layer_views_) {
+ GPU_TEXTURE_FREE_SAFE(view);
+ }
+ mip_views_.clear();
}
/**