diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-07-30 18:43:56 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-08-02 22:53:17 +0300 |
commit | 22143b351f9bfe39acda9f5c3287405e6a6851de (patch) | |
tree | 9d244fae5f59ad9c06a8e61c23fdaffa786cea13 /source/blender/draw | |
parent | 04160ffd12fe0cd3e2241ea9c9e683b40ba5219e (diff) |
DRW: GPU wrapper: Make SwapChain renference work
This make using texture reference easier. But now, it makes it mandatory
for the wrapped type to implement the `swap()` static method.
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/intern/DRW_gpu_wrapper.hh | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh index 210b18c1234..368b9e5ff56 100644 --- a/source/blender/draw/intern/DRW_gpu_wrapper.hh +++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh @@ -806,6 +806,15 @@ class TextureFromPool : public Texture, NonMovable { this->tx_ = nullptr; } + /** + * Swap the GPUTexture pointers of the two texture. + */ + static void swap(TextureFromPool &a, TextureFromPool &b) + { + SWAP(GPUTexture *, a.tx_, b.tx_); + SWAP(const char *, a.name_, b.name_); + } + /** Remove methods that are forbidden with this type of textures. */ bool ensure_1d(int, int, eGPUTextureFormat, float *) = delete; bool ensure_1d_array(int, int, int, eGPUTextureFormat, float *) = delete; @@ -890,45 +899,47 @@ class Framebuffer : NonCopyable { template<typename T, int64_t len> class SwapChain { private: + BLI_STATIC_ASSERT(len > 1, "A swap-chain needs more than 1 unit in length."); std::array<T, len> chain_; - int64_t index_ = 0; public: void swap() { - index_ = (index_ + 1) % len; + for (auto i : IndexRange(len - 1)) { + T::swap(chain_[i], chain_[(i + 1) % len]); + } } T ¤t() { - return chain_[index_]; + return chain_[0]; } T &previous() { /* Avoid modulo operation with negative numbers. */ - return chain_[(index_ + len - 1) % len]; + return chain_[(0 + len - 1) % len]; } T &next() { - return chain_[(index_ + 1) % len]; + return chain_[(0 + 1) % len]; } const T ¤t() const { - return chain_[index_]; + return chain_[0]; } const T &previous() const { /* Avoid modulo operation with negative numbers. */ - return chain_[(index_ + len - 1) % len]; + return chain_[(0 + len - 1) % len]; } const T &next() const { - return chain_[(index_ + 1) % len]; + return chain_[(0 + 1) % len]; } }; |