diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2022-03-02 15:54:43 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2022-03-02 15:54:43 +0300 |
commit | 1ddde2d83c82d13f6c1400d2eddb3fa28d91f3e7 (patch) | |
tree | f9f5dac6e9f8b2f1cd1eff6c9368d81ec0ee1c60 /source/blender/imbuf/intern/rasterizer_target.hh | |
parent | 6afa238cedcd813c98c9ed3b918ddb3c8b4d90f3 (diff) |
Split rasterizer target to support other drawing targets.
Diffstat (limited to 'source/blender/imbuf/intern/rasterizer_target.hh')
-rw-r--r-- | source/blender/imbuf/intern/rasterizer_target.hh | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/imbuf/intern/rasterizer_target.hh b/source/blender/imbuf/intern/rasterizer_target.hh new file mode 100644 index 00000000000..25830b4006a --- /dev/null +++ b/source/blender/imbuf/intern/rasterizer_target.hh @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2022 Blender Foundation. All rights reserved. */ + +#pragma once + +/** \file + * \ingroup imbuf + * + * Rasterizer drawing target. + */ + +#include "BLI_sys_types.h" + +namespace blender::imbuf::rasterizer { + +/** + * An abstract implementation of a drawing target. Will make it possible to switch to other render + * targets then only ImBuf types. + */ +template<typename Inner> class AbstractDrawingTarget { + public: + using InnerType = Inner; + virtual uint64_t get_width() const = 0; + virtual uint64_t get_height() const = 0; + virtual float *get_pixel_ptr(uint64_t x, uint64_t y) = 0; + virtual int64_t get_pixel_stride() const = 0; + virtual bool has_active_target() const = 0; + virtual void activate(Inner *instance) = 0; + virtual void deactivate() = 0; +}; + +class ImageBufferDrawingTarget : public AbstractDrawingTarget<ImBuf> { + private: + ImBuf *image_buffer_ = nullptr; + + public: + bool has_active_target() const override + { + return image_buffer_ != nullptr; + } + + void activate(ImBuf *image_buffer) override + { + image_buffer_ = image_buffer; + } + + void deactivate() override + { + image_buffer_ = nullptr; + } + + uint64_t get_width() const override + { + return image_buffer_->x; + }; + + uint64_t get_height() const override + { + return image_buffer_->y; + } + + float *get_pixel_ptr(uint64_t x, uint64_t y) override + { + BLI_assert(has_active_target()); + uint64_t pixel_index = y * image_buffer_->x + x; + return &image_buffer_->rect_float[pixel_index * 4]; + } + int64_t get_pixel_stride() const override + { + return 4; + } +}; + +} // namespace blender::imbuf::rasterizer |