From d3591e3e7b1c26e1de19dfce70aaeaba5d9f648c Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 17 May 2021 23:13:08 +0100 Subject: [PATCH] Add VulkanImage stub, enable vulkan for Demo test Signed-off-by: falkTX --- dgl/Cairo.hpp | 4 ++- dgl/Vulkan.hpp | 66 +++++++++++++++++++++++++++++++++++++++++++++- dgl/src/Vulkan.cpp | 34 ++++++++++++++++++++++++ tests/Demo.cpp | 7 +++++ tests/Makefile | 1 + 5 files changed, 110 insertions(+), 2 deletions(-) diff --git a/dgl/Cairo.hpp b/dgl/Cairo.hpp index ba97dd4c..bb6f5538 100644 --- a/dgl/Cairo.hpp +++ b/dgl/Cairo.hpp @@ -91,8 +91,10 @@ public: CairoImage& operator=(const CairoImage& image) noexcept; // FIXME this should not be needed - inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format) + inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format = kImageFormatBGRA) { loadFromMemory(rawData, Size(w, h), format); }; + inline void draw(const GraphicsContext& context) + { drawAt(context, Point(0, 0)); }; inline void drawAt(const GraphicsContext& context, int x, int y) { drawAt(context, Point(x, y)); }; diff --git a/dgl/Vulkan.hpp b/dgl/Vulkan.hpp index c636a8a3..d7b73056 100644 --- a/dgl/Vulkan.hpp +++ b/dgl/Vulkan.hpp @@ -17,7 +17,7 @@ #ifndef DGL_VULKAN_HPP_INCLUDED #define DGL_VULKAN_HPP_INCLUDED -#include "Base.hpp" +#include "ImageBase.hpp" #include @@ -34,6 +34,70 @@ struct VulkanGraphicsContext : GraphicsContext // -------------------------------------------------------------------------------------------------------------------- +/** + Vulkan Image class. + + TODO ... + */ +class VulkanImage : public ImageBase +{ +public: + /** + Constructor for a null Image. + */ + VulkanImage(); + + /** + Constructor using raw image data. + @note @a rawData must remain valid for the lifetime of this Image. + */ + VulkanImage(const char* rawData, uint width, uint height, ImageFormat format); + + /** + Constructor using raw image data. + @note @a rawData must remain valid for the lifetime of this Image. + */ + VulkanImage(const char* rawData, const Size& size, ImageFormat format); + + /** + Constructor using another image data. + */ + VulkanImage(const VulkanImage& image); + + /** + Destructor. + */ + ~VulkanImage() override; + + /** + Load image data from memory. + @note @a rawData must remain valid for the lifetime of this Image. + */ + void loadFromMemory(const char* rawData, + const Size& size, + ImageFormat format = kImageFormatBGRA) noexcept override; + + /** + Draw this image at position @a pos using the graphics context @a context. + */ + void drawAt(const GraphicsContext& context, const Point& pos) override; + + /** + TODO document this. + */ + VulkanImage& operator=(const VulkanImage& image) noexcept; + + // FIXME this should not be needed + inline void loadFromMemory(const char* rawData, uint w, uint h, ImageFormat format = kImageFormatBGRA) + { loadFromMemory(rawData, Size(w, h), format); }; + inline void draw(const GraphicsContext& context) + { drawAt(context, Point(0, 0)); }; + inline void drawAt(const GraphicsContext& context, int x, int y) + { drawAt(context, Point(x, y)); }; +}; + +// -------------------------------------------------------------------------------------------------------------------- + END_NAMESPACE_DGL #endif diff --git a/dgl/src/Vulkan.cpp b/dgl/src/Vulkan.cpp index ed499222..7ec5db67 100644 --- a/dgl/src/Vulkan.cpp +++ b/dgl/src/Vulkan.cpp @@ -164,6 +164,40 @@ template class Rectangle; template class Rectangle; template class Rectangle; +// ----------------------------------------------------------------------- +// VulkanImage + +VulkanImage::VulkanImage() + : ImageBase() {} + +VulkanImage::VulkanImage(const char* const rawData, const uint width, const uint height, const ImageFormat format) + : ImageBase(rawData, width, height, format) {} + +VulkanImage::VulkanImage(const char* const rawData, const Size& size, const ImageFormat format) + : ImageBase(rawData, size, format) {} + +VulkanImage::VulkanImage(const VulkanImage& image) + : ImageBase(image.rawData, image.size, image.format) {} + +VulkanImage::~VulkanImage() {} + +void VulkanImage::loadFromMemory(const char* const rdata, const Size& s, const ImageFormat fmt) noexcept +{ + ImageBase::loadFromMemory(rdata, s, fmt); +} + +void VulkanImage::drawAt(const GraphicsContext&, const Point&) +{ +} + +VulkanImage& VulkanImage::operator=(const VulkanImage& image) noexcept +{ + rawData = image.rawData; + size = image.size; + format = image.format; + return *this; +} + // ----------------------------------------------------------------------- void SubWidget::PrivateData::display(const uint width, const uint height, const double autoScaleFactor) diff --git a/tests/Demo.cpp b/tests/Demo.cpp index e86abdcd..f5998fef 100644 --- a/tests/Demo.cpp +++ b/tests/Demo.cpp @@ -35,6 +35,10 @@ typedef DGL_NAMESPACE::CairoImage DemoImage; #include "../dgl/OpenGL.hpp" typedef DGL_NAMESPACE::OpenGLImage DemoImage; #endif +#ifdef DGL_VULKAN +#include "../dgl/Vulkan.hpp" +typedef DGL_NAMESPACE::VulkanImage DemoImage; +#endif START_NAMESPACE_DGL @@ -245,6 +249,9 @@ public: #ifdef DGL_OPENGL static constexpr const char* const kExampleWidgetName = "Demo - OpenGL"; #endif +#ifdef DGL_VULKAN + static constexpr const char* const kExampleWidgetName = "Demo - Vulkan"; +#endif DemoWindow(Application& app) : StandaloneWindow(app), diff --git a/tests/Makefile b/tests/Makefile index 24c9385b..dde5918d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -27,6 +27,7 @@ TESTS += Demo.opengl WTESTS += Window.opengl endif ifeq ($(HAVE_VULKAN),true) +TESTS += Demo.vulkan WTESTS = Window.vulkan endif