Implement draw2DRectangle for GEVulkanDriver

This commit is contained in:
Benau 2022-03-23 10:53:00 +08:00
parent 9e50c8a71f
commit 23cd67f45c
2 changed files with 42 additions and 1 deletions

View File

@ -144,7 +144,11 @@ namespace GE
//!Draws an 2d rectangle with a gradient. //!Draws an 2d rectangle with a gradient.
virtual void draw2DRectangle(const core::rect<s32>& pos, virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const core::rect<s32>* clip) {} const core::rect<s32>* clip)
{
SColor color[4] = { colorLeftUp, colorLeftDown, colorRightDown, colorRightUp };
draw2DImage(m_white_texture, pos, core::recti(0, 0, 2, 2), clip, color, true);
}
//! Draws a 2d line. //! Draws a 2d line.
virtual void draw2DLine(const core::position2d<s32>& start, virtual void draw2DLine(const core::position2d<s32>& start,
@ -311,6 +315,9 @@ namespace GE
constexpr static unsigned getMaxFrameInFlight() { return 2; } constexpr static unsigned getMaxFrameInFlight() { return 2; }
video::SColor getClearColor() const { return m_clear_color; } video::SColor getClearColor() const { return m_clear_color; }
const core::rect<s32>& getCurrentClip() const { return m_clip; } const core::rect<s32>& getCurrentClip() const { return m_clip; }
video::ITexture* getWhiteTexture() const { return m_white_texture; }
video::ITexture* getTransparentTexture() const
{ return m_transparent_texture; }
private: private:
struct SwapChainSupportDetails struct SwapChainSupportDetails
{ {
@ -426,6 +433,9 @@ namespace GE
video::SColor m_clear_color; video::SColor m_clear_color;
core::rect<s32> m_clip; core::rect<s32> m_clip;
video::ITexture* m_white_texture;
video::ITexture* m_transparent_texture;
void createInstance(SDL_Window* window); void createInstance(SDL_Window* window);
void findPhysicalDevice(); void findPhysicalDevice();
bool checkDeviceExtensions(VkPhysicalDevice device); bool checkDeviceExtensions(VkPhysicalDevice device);
@ -442,6 +452,7 @@ namespace GE
void createSamplers(); void createSamplers();
void createRenderPass(); void createRenderPass();
void createFramebuffers(); void createFramebuffers();
void createUnicolorTextures();
std::string getVulkanVersionString() const; std::string getVulkanVersionString() const;
std::string getDriverVersionString() const; std::string getDriverVersionString() const;
}; };

View File

@ -459,6 +459,7 @@ GEVulkanDriver::GEVulkanDriver(const SIrrlichtCreationParameters& params,
m_current_frame = 0; m_current_frame = 0;
m_image_index = 0; m_image_index = 0;
m_clear_color = video::SColor(0); m_clear_color = video::SColor(0);
m_white_texture = NULL;
createInstance(window); createInstance(window);
@ -507,6 +508,7 @@ GEVulkanDriver::GEVulkanDriver(const SIrrlichtCreationParameters& params,
// For GEVulkanDynamicBuffer // For GEVulkanDynamicBuffer
GE::setVideoDriver(this); GE::setVideoDriver(this);
GEVulkan2dRenderer::init(this); GEVulkan2dRenderer::init(this);
createUnicolorTextures();
os::Printer::log("Vulkan version", getVulkanVersionString().c_str()); os::Printer::log("Vulkan version", getVulkanVersionString().c_str());
os::Printer::log("Vulkan vendor", getVendorInfo().c_str()); os::Printer::log("Vulkan vendor", getVendorInfo().c_str());
os::Printer::log("Vulkan renderer", m_properties.deviceName); os::Printer::log("Vulkan renderer", m_properties.deviceName);
@ -524,12 +526,40 @@ GEVulkanDriver::~GEVulkanDriver()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void GEVulkanDriver::destroyVulkan() void GEVulkanDriver::destroyVulkan()
{ {
if (m_white_texture)
{
m_white_texture->drop();
m_white_texture = NULL;
}
if (m_transparent_texture)
{
m_transparent_texture->drop();
m_transparent_texture = NULL;
}
GEVulkan2dRenderer::destroy(); GEVulkan2dRenderer::destroy();
GEVulkanShaderManager::destroy(); GEVulkanShaderManager::destroy();
delete m_vk.get(); delete m_vk.get();
m_vk.release(); m_vk.release();
} // destroyVulkan } // destroyVulkan
// ----------------------------------------------------------------------------
void GEVulkanDriver::createUnicolorTextures()
{
constexpr unsigned size = 2;
std::array<uint8_t, size * size * 4> data;
data.fill(255);
video::IImage* img = createImageFromData(video::ECF_A8R8G8B8,
core::dimension2d<u32>(size, size), data.data(),
/*ownForeignMemory*/true, /*deleteMemory*/false);
m_white_texture = new GEVulkanTexture(img, "unicolor_white");
data.fill(0);
img = createImageFromData(video::ECF_A8R8G8B8,
core::dimension2d<u32>(size, size), data.data(),
/*ownForeignMemory*/true, /*deleteMemory*/false);
m_transparent_texture = new GEVulkanTexture(img, "unicolor_transparent");
} // createUnicolorTextures
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void GEVulkanDriver::createInstance(SDL_Window* window) void GEVulkanDriver::createInstance(SDL_Window* window)
{ {