Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Sources/Overload/OvEditor/src/OvEditor/Panels/AssetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,15 @@ namespace

auto& compileAction = CreateWidget<OvUI::Widgets::Menu::MenuItem>("Compile");

compileAction.ClickedEvent += [this]
{
compileAction.ClickedEvent += [this] {
using namespace OvRendering::Resources::Loaders;
auto& shaderManager = OVSERVICE(OvCore::ResourceManagement::ShaderManager);
const std::string resourcePath = EDITOR_EXEC(GetResourcePath(filePath, m_protected));
const auto previousLoggingSettings = ShaderLoader::GetLoggingSettings();
auto newLoggingSettings = previousLoggingSettings;
newLoggingSettings.summary = true; // Force enable summary logging
ShaderLoader::SetLoggingSettings(newLoggingSettings);

if (shaderManager.IsResourceRegistered(resourcePath))
{
// Trying to recompile
Expand All @@ -630,12 +635,10 @@ namespace
else
{
// Trying to compile
auto shader = OVSERVICE(OvCore::ResourceManagement::ShaderManager)[resourcePath];
if (shader)
{
OVLOG_INFO("[COMPILE] \"" + filePath + "\": Success!");
}
OVSERVICE(OvCore::ResourceManagement::ShaderManager).LoadResource(resourcePath);
}

ShaderLoader::SetLoggingSettings(previousLoggingSettings);
};
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <functional>

#include "OvRendering/Resources/Shader.h"
#include <OvRendering/Resources/Shader.h>

namespace OvRendering::Resources::Loaders
{
Expand All @@ -18,6 +18,18 @@ namespace OvRendering::Resources::Loaders
class ShaderLoader
{
public:
/**
* Logging settings for the ShaderLoader
*/
struct LoggingSettings
{
bool summary : 1;
bool linkingErrors : 1;
bool linkingSuccess : 1;
bool compilationErrors : 1;
bool compilationSuccess : 1;
};

using FilePathParserCallback = std::function<std::string(const std::string&)>;

/**
Expand All @@ -26,31 +38,43 @@ namespace OvRendering::Resources::Loaders
ShaderLoader() = delete;

/**
* Create a shader
* Returns the current logging settings
*/
static LoggingSettings GetLoggingSettings();

/**
* Sets logging settings for the ShaderLoader
* @param p_settings
*/
static void SetLoggingSettings(LoggingSettings p_settings);

/**
* Creates a shader from a file
* @param p_filePath
* @param p_pathParser
*/
static Shader* Create(const std::string& p_filePath, FilePathParserCallback p_pathParser = nullptr);

/**
* Create a shader from source
* Creates a shader from vertex and fragment source code
* @param p_vertexShader
* @param p_fragmentShader
* @note Doesn't support path parsing/resolving
* @note Doesn't support parsing (no include, no features)
*/
static Shader* CreateFromSource(const std::string& p_vertexShader, const std::string& p_fragmentShader);

/**
* Recompile a shader
* Recompiles a shader
* @param p_shader
* @param p_filePath
* @param p_pathParser
*/
static void Recompile(Shader& p_shader, const std::string& p_filePath, FilePathParserCallback p_pathParser = nullptr);

/**
* Destroy a shader
* Destroys a shader
* @param p_shader
*/
static bool Destroy(Shader*& p_shader);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <string>
#include <memory>
#include <unordered_set>
#include <unordered_map>

#include <OvRendering/HAL/ShaderProgram.h>

Expand All @@ -24,20 +26,50 @@ namespace OvRendering::Resources
friend class Loaders::ShaderLoader;

public:
using FeatureSet = std::unordered_set<std::string>;

struct FeatureSetHash
{
size_t operator()(const FeatureSet& fs) const;
};

struct FeatureSetEqual
{
bool operator()(const FeatureSet& lhs, const FeatureSet& rhs) const;
};

using ProgramVariants = std::unordered_map<
FeatureSet,
std::unique_ptr<HAL::ShaderProgram>,
FeatureSetHash,
FeatureSetEqual
>;

/**
* Returns the associated shader program
* Returns the associated shader program for a given feature set
* @param p_featureSet (optional) The feature set to use. If not provided, the default program will be used.
*/
HAL::ShaderProgram& GetProgram() const;
HAL::ShaderProgram& GetProgram(const FeatureSet& p_featureSet = {});

/**
* Returns supported features
*/
const FeatureSet& GetFeatures() const;

private:
Shader(const std::string p_path, std::unique_ptr<HAL::ShaderProgram>&& p_program);
Shader(
const std::string p_path,
ProgramVariants&& p_programs
);

~Shader() = default;
void SetProgram(std::unique_ptr<HAL::ShaderProgram>&& p_program);
void SetPrograms(ProgramVariants&& p_programs);

public:
const std::string path;

private:
std::unique_ptr<HAL::ShaderProgram> m_program;
FeatureSet m_features;
ProgramVariants m_programs;
};
}
Loading