diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-02-16 00:20:25 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-02-16 00:20:49 +0300 |
commit | d3b1cce4000b4b530d3ac8e2aa6b86b79b94cca0 (patch) | |
tree | f905a28a8d4c3683a1a42d88d047bf2c9bd567a8 /source/blender/gpu | |
parent | cbdd57864049f6f300494d56b623934a4134fa2b (diff) |
GPUTexture: Add dimensions getter
Pretty straight forward. Returns the texture dimensions count. This is
different from the size.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_texture.h | 6 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.cc | 19 |
2 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h index 9472aed79a5..d689fbe14b5 100644 --- a/source/blender/gpu/GPU_texture.h +++ b/source/blender/gpu/GPU_texture.h @@ -287,6 +287,12 @@ void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter); void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp); void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4]); +/** + * Return the number of dimensions of the texture ignoring dimension of layers (1, 2 or 3). + * Cube textures are considered 2D. + */ +int GPU_texture_dimensions(const GPUTexture *tex); + int GPU_texture_width(const GPUTexture *tex); int GPU_texture_height(const GPUTexture *tex); int GPU_texture_orig_width(const GPUTexture *tex); diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc index 19c7c5d78ff..da5f08f003e 100644 --- a/source/blender/gpu/intern/gpu_texture.cc +++ b/source/blender/gpu/intern/gpu_texture.cc @@ -507,6 +507,25 @@ void GPU_texture_ref(GPUTexture *tex) reinterpret_cast<Texture *>(tex)->refcount++; } +int GPU_texture_dimensions(const GPUTexture *tex_) +{ + eGPUTextureType type = reinterpret_cast<const Texture *>(tex_)->type_get(); + if (type & GPU_TEXTURE_1D) { + return 1; + } + else if (type & GPU_TEXTURE_2D) { + return 2; + } + else if (type & GPU_TEXTURE_3D) { + return 3; + } + else if (type & GPU_TEXTURE_CUBE) { + return 2; + } + /* GPU_TEXTURE_BUFFER */ + return 1; +} + int GPU_texture_width(const GPUTexture *tex) { return reinterpret_cast<const Texture *>(tex)->width_get(); |