2019-10-05 09:50:14 +00:00
|
|
|
/*
|
|
|
|
Created on: Oct 2, 2019
|
|
|
|
|
|
|
|
Copyright 2019 flyinghead
|
|
|
|
|
|
|
|
This file is part of Flycast.
|
|
|
|
|
|
|
|
Flycast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Flycast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "vulkan.h"
|
2020-07-10 16:50:53 +00:00
|
|
|
#include "vulkan_renderer.h"
|
2019-10-09 19:16:12 +00:00
|
|
|
#include "drawer.h"
|
2019-10-05 09:50:14 +00:00
|
|
|
#include "shaders.h"
|
|
|
|
|
2020-07-10 16:50:53 +00:00
|
|
|
class VulkanRenderer final : public BaseVulkanRenderer
|
2019-10-05 09:50:14 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool Init() override
|
|
|
|
{
|
2019-10-15 14:49:20 +00:00
|
|
|
DEBUG_LOG(RENDERER, "VulkanRenderer::Init");
|
2020-07-10 16:50:53 +00:00
|
|
|
BaseVulkanRenderer::Init();
|
2019-10-05 09:50:14 +00:00
|
|
|
|
2019-12-09 18:37:14 +00:00
|
|
|
textureDrawer.Init(&samplerManager, &shaderManager, &textureCache);
|
|
|
|
textureDrawer.SetCommandPool(&texCommandPool);
|
2019-10-21 14:39:16 +00:00
|
|
|
|
2019-10-09 19:16:12 +00:00
|
|
|
screenDrawer.Init(&samplerManager, &shaderManager);
|
2019-11-29 18:28:22 +00:00
|
|
|
screenDrawer.SetCommandPool(&texCommandPool);
|
2019-11-10 09:16:18 +00:00
|
|
|
|
2019-10-05 09:50:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Resize(int w, int h) override
|
|
|
|
{
|
2020-07-10 16:50:53 +00:00
|
|
|
BaseVulkanRenderer::Resize(w, h);
|
2019-10-12 11:47:25 +00:00
|
|
|
screenDrawer.Init(&samplerManager, &shaderManager);
|
2019-10-05 09:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Term() override
|
|
|
|
{
|
2019-10-15 14:49:20 +00:00
|
|
|
DEBUG_LOG(RENDERER, "VulkanRenderer::Term");
|
2019-10-05 09:50:14 +00:00
|
|
|
GetContext()->WaitIdle();
|
2020-07-10 16:50:53 +00:00
|
|
|
BaseVulkanRenderer::Term();
|
2019-10-05 09:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Render() override
|
|
|
|
{
|
2021-01-09 17:16:39 +00:00
|
|
|
try {
|
|
|
|
Drawer *drawer;
|
|
|
|
if (pvrrc.isRTT)
|
|
|
|
drawer = &textureDrawer;
|
|
|
|
else
|
|
|
|
drawer = &screenDrawer;
|
2019-10-21 14:39:16 +00:00
|
|
|
|
2021-01-09 17:16:39 +00:00
|
|
|
drawer->Draw(fogTexture.get(), paletteTexture.get());
|
2019-11-29 18:28:22 +00:00
|
|
|
|
2021-01-09 17:16:39 +00:00
|
|
|
drawer->EndRenderPass();
|
2019-10-21 14:39:16 +00:00
|
|
|
|
2021-01-09 17:16:39 +00:00
|
|
|
return !pvrrc.isRTT;
|
|
|
|
} catch (const vk::SystemError& e) {
|
|
|
|
// Sometimes happens when resizing the window
|
|
|
|
WARN_LOG(RENDERER, "Vulkan system error %s", e.what());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-05 09:50:14 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 14:09:42 +00:00
|
|
|
bool Present() override
|
|
|
|
{
|
|
|
|
return screenDrawer.PresentFrame();
|
|
|
|
}
|
|
|
|
|
2019-10-05 09:50:14 +00:00
|
|
|
private:
|
2019-10-09 19:16:12 +00:00
|
|
|
SamplerManager samplerManager;
|
|
|
|
ScreenDrawer screenDrawer;
|
2019-12-09 18:37:14 +00:00
|
|
|
TextureDrawer textureDrawer;
|
2019-10-05 09:50:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Renderer* rend_Vulkan()
|
|
|
|
{
|
|
|
|
return new VulkanRenderer();
|
|
|
|
}
|