code review changes and fixes
This commit is contained in:
@@ -40,8 +40,9 @@ namespace OpenVulkano
|
||||
}
|
||||
}
|
||||
|
||||
Array<char> ResourceLoaderAppDirLinux::GetResource(const std::string& resourceName)
|
||||
Array<char> ResourceLoaderAppDirLinux::GetResource(const std::string& resourceName, std::string& resourcePath)
|
||||
{
|
||||
return Utils::ReadFile(GetAppDir() + resourceName, true);
|
||||
resourcePath = GetAppDir() + resourceName;
|
||||
return Utils::ReadFile(resourcePath, true);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ namespace OpenVulkano
|
||||
class ResourceLoaderAppDirLinux final : public ResourceLoader
|
||||
{
|
||||
public:
|
||||
Array<char> GetResource(const std::string& resourceName) override;
|
||||
Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) override;
|
||||
};
|
||||
}
|
||||
@@ -15,13 +15,13 @@ namespace OpenVulkano
|
||||
std::vector<std::unique_ptr<ResourceLoader>> m_loaders;
|
||||
|
||||
public:
|
||||
Array<char> GetResource(const std::string& resourceName) override
|
||||
Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) override
|
||||
{
|
||||
for(auto& loader : m_loaders)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto res = loader->GetResource(resourceName);
|
||||
auto res = loader->GetResource(resourceName, resourcePath);
|
||||
if (!res.Empty()) return res;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace OpenVulkano
|
||||
public:
|
||||
virtual ~ResourceLoader() = default;
|
||||
|
||||
virtual Array<char> GetResource(const std::string& resourceName) = 0;
|
||||
virtual Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) = 0;
|
||||
|
||||
static ResourceLoader& GetInstance();
|
||||
|
||||
|
||||
@@ -90,11 +90,12 @@ namespace OpenVulkano
|
||||
return Array<char>(buffer);
|
||||
}
|
||||
|
||||
Array<char> WebResourceLoader::GetResource(const std::string& resourceName)
|
||||
Array<char> WebResourceLoader::GetResource(const std::string& resourceName, std::string& resourcePath)
|
||||
{
|
||||
if (IsUrl(resourceName))
|
||||
{
|
||||
std::filesystem::path cacheFilePath = GetCacheFilePath(resourceName);
|
||||
resourcePath = resourceName;
|
||||
if (std::filesystem::exists(cacheFilePath)) { return Utils::ReadFile(cacheFilePath.string()); }
|
||||
else { return DownloadResource(resourceName); }
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@ namespace OpenVulkano
|
||||
|
||||
WebResourceLoader();
|
||||
~WebResourceLoader();
|
||||
Array<char> GetResource(const std::string& resourceName) override;
|
||||
Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) override;
|
||||
};
|
||||
}
|
||||
@@ -38,8 +38,9 @@ namespace OpenVulkano
|
||||
}
|
||||
}
|
||||
|
||||
Array<char> ResourceLoaderAppDirWindows::GetResource(const std::string& resourceName)
|
||||
Array<char> ResourceLoaderAppDirWindows::GetResource(const std::string& resourceName, std::string& resourcePath)
|
||||
{
|
||||
return Utils::ReadFile(GetAppDir() + resourceName);
|
||||
resourcePath = GetAppDir() + resourceName;
|
||||
return Utils::ReadFile(resourcePath);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ namespace OpenVulkano
|
||||
class ResourceLoaderAppDirWindows final : public ResourceLoader
|
||||
{
|
||||
public:
|
||||
Array<char> GetResource(const std::string& resourceName) override;
|
||||
Array<char> GetResource(const std::string& resourceName, std::string& resourcePath) override;
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "ImageLoaderJpeg.hpp"
|
||||
#include "Base/Utils.hpp"
|
||||
#include <Data/Containers/Array.hpp>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
@@ -20,10 +21,8 @@ namespace OpenVulkano::Image
|
||||
{
|
||||
std::unique_ptr<Image> ImageLoaderJpeg::loadFromFile(const std::string& filePath)
|
||||
{
|
||||
std::ifstream file(filePath, std::ios::binary);
|
||||
if (!file) { throw std::runtime_error("Could not open file: " + filePath); }
|
||||
std::vector<uint8_t> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
return loadJpeg(buffer.data(), buffer.size());
|
||||
Array<char> buffer = OpenVulkano::Utils::ReadFile(filePath);
|
||||
return loadJpeg(reinterpret_cast<uint8_t*>(buffer.Data()), buffer.Size());
|
||||
}
|
||||
|
||||
std::unique_ptr<Image> ImageLoaderJpeg::loadFromMemory(const std::vector<uint8_t>& buffer)
|
||||
@@ -59,7 +58,7 @@ namespace OpenVulkano::Image
|
||||
}
|
||||
#else
|
||||
{
|
||||
return loadData(data, static_cast<int>(size), 3);
|
||||
return loadData(data, static_cast<int>(size));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "ImageLoaderPng.hpp"
|
||||
#include "Base/Utils.hpp"
|
||||
#include <Data/Containers/Array.hpp>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
@@ -13,10 +14,8 @@ namespace OpenVulkano::Image
|
||||
{
|
||||
std::unique_ptr<Image> ImageLoaderPng::loadFromFile(const std::string& filePath)
|
||||
{
|
||||
std::ifstream file(filePath, std::ios::binary);
|
||||
if (!file) { throw std::runtime_error("Could not open file: " + filePath); }
|
||||
std::vector<uint8_t> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
return loadData(buffer.data(), static_cast<int>(buffer.size()));
|
||||
Array<char> buffer = OpenVulkano::Utils::ReadFile(filePath);
|
||||
return loadData(reinterpret_cast<uint8_t*>(buffer.Data()), static_cast<int>(buffer.Size()));
|
||||
}
|
||||
|
||||
std::unique_ptr<Image> ImageLoaderPng::loadFromMemory(const std::vector<uint8_t>& buffer)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenVulkano::Scene
|
||||
Scene* m_scene = nullptr;
|
||||
Shader* m_shader = nullptr;
|
||||
const DrawEncoder m_encoder;
|
||||
DrawPhase m_drawPhase;
|
||||
const DrawPhase m_drawPhase;
|
||||
|
||||
public:
|
||||
explicit Drawable(const DrawEncoder& encoder,
|
||||
@@ -45,8 +45,6 @@ namespace OpenVulkano::Scene
|
||||
|
||||
void SetShader(Shader* shader) { m_shader = shader; }
|
||||
|
||||
void SetDrawPhase(DrawPhase phase) { m_drawPhase = phase; }
|
||||
|
||||
[[nodiscard]] Scene* GetScene() const { return m_scene; }
|
||||
|
||||
[[nodiscard]] const auto& GetNodes() const { return m_nodes; }
|
||||
|
||||
@@ -17,10 +17,6 @@
|
||||
#endif
|
||||
#include <stdexcept>
|
||||
|
||||
#include "msdfgen.h"
|
||||
#include "msdfgen-ext.h"
|
||||
#include "msdf-atlas-gen/msdf-atlas-gen.h"
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
Geometry::Geometry(const Geometry& other)
|
||||
|
||||
@@ -24,12 +24,13 @@ namespace OpenVulkano::Scene
|
||||
|
||||
struct TextConfig
|
||||
{
|
||||
Math::Vector4f textColor = { 1, 1, 1, 0 }; // vec4 to match paddding (multiple of 16)
|
||||
Math::Vector3f borderColor = { 1, 0, 0 };
|
||||
Math::Vector4f textColor = { 1, 1, 1, 1 };
|
||||
Math::Vector4f borderColor = { 1, 0, 0, 1 };
|
||||
Math::Vector4f backgroundColor = { 0, 1, 0, 0 };
|
||||
float threshold = 0.4f;
|
||||
float borderSize = 0.05f;
|
||||
float smoothing = 1.f/32.f;
|
||||
bool applyBorder = false;
|
||||
uint32_t applyBorder = false;
|
||||
//bool sdfMultiChannel = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@ layout(set = 2, binding = 0) uniform sampler2D texSampler;
|
||||
|
||||
layout(set = 3, binding = 0) uniform TextConfig
|
||||
{
|
||||
vec3 textColor;
|
||||
vec3 borderColor;
|
||||
vec4 textColor;
|
||||
vec4 borderColor;
|
||||
vec4 backgroundColor;
|
||||
float threshold;
|
||||
float borderSize;
|
||||
float smoothing;
|
||||
@@ -24,10 +25,15 @@ void main()
|
||||
{
|
||||
float border = smoothstep(textConfig.threshold + textConfig.borderSize - textConfig.smoothing,
|
||||
textConfig.threshold + textConfig.borderSize + textConfig.smoothing, distance);
|
||||
outColor = vec4(mix(textConfig.borderColor, textConfig.textColor, border), 1) * alpha;
|
||||
outColor = mix(textConfig.borderColor, textConfig.textColor, border) * alpha;
|
||||
}
|
||||
else
|
||||
{
|
||||
outColor = vec4(textConfig.textColor, 1) * alpha;
|
||||
outColor = vec4(textConfig.textColor) * alpha;
|
||||
}
|
||||
|
||||
if (textConfig.backgroundColor.a != 0)
|
||||
{
|
||||
outColor = mix(textConfig.backgroundColor, outColor, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user