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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ jobs:
cmake --build cmake-build-release --config Release
binary: cmake-build-release\bin\cae.exe
build_test: |
cmake -S . -G "Ninja" -B cmake-build-tests -DBUILD_CAE_TESTS=ON
cmake --build cmake-build-tests
binary_test: cmake-build-tests\bin\cae-tests.exe
cmake -S . -G "Ninja" -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -DBUILD_CAE_TESTS=ON
cmake --build cmake-build-release --config Release
binary_test: cmake-build-release\bin\cae-tests.exe
deps: choco install cmake -y

runs-on: ${{ matrix.os }}
Expand Down
15 changes: 15 additions & 0 deletions assets/shaders/animated.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 450 core

layout(location = 0) out vec4 FragColor;

layout(binding = 1) uniform TimeColor {
float time;
} uTime;

void main()
{
float r = 0.5 + 0.5 * sin(uTime.time);
float g = 0.5 + 0.5 * sin(uTime.time * 1.3);
float b = 0.5 + 0.5 * sin(uTime.time * 2.1);
FragColor = vec4(r, g, b, 1.0);
}
13 changes: 13 additions & 0 deletions assets/shaders/animated.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 450 core

layout(location = 0) in vec2 aPos;

layout(binding = 0) uniform TimeData {
float time;
} uTime;

void main()
{
float scale = 0.5 + 0.5 * sin(uTime.time);
gl_Position = vec4(aPos * scale, 0.0, 1.0);
}
9 changes: 9 additions & 0 deletions assets/shaders/basic_color.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 450 core

layout(location = 0) in vec3 vColor;
layout(location = 0) out vec4 FragColor;

void main()
{
FragColor = vec4(vColor, 1.0);
}
12 changes: 12 additions & 0 deletions assets/shaders/basic_color.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450 core

layout(location = 0) in vec2 aPos;
layout(location = 1) in vec3 aColor;

layout(location = 0) out vec3 vColor;

void main()
{
gl_Position = vec4(aPos, 0.0, 1.0);
vColor = aColor;
}
12 changes: 12 additions & 0 deletions assets/shaders/texture.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450 core

layout(location = 0) in vec2 vUV;
layout(location = 0) out vec4 FragColor;

layout(binding = 0) uniform sampler2D uTexture;

void main()
{
// Même sans texture bindée, ça se compile.
FragColor = texture(uTexture, vUV);
}
12 changes: 12 additions & 0 deletions assets/shaders/texture.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450 core

layout(location = 0) in vec2 aPos;
layout(location = 1) in vec2 aUV;

layout(location = 0) out vec2 vUV;

void main()
{
gl_Position = vec4(aPos, 0.0, 1.0);
vUV = aUV;
}
9 changes: 9 additions & 0 deletions assets/shaders/transform.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 450 core

layout(location = 0) in vec3 vColor;
layout(location = 0) out vec4 FragColor;

void main()
{
FragColor = vec4(vColor, 1.0);
}
18 changes: 18 additions & 0 deletions assets/shaders/transform.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#version 450 core

layout(location = 0) in vec2 aPos;
layout(location = 1) in vec3 aColor;

layout(location = 0) out vec3 vColor;

layout(binding = 0) uniform Matrices {
mat4 model;
mat4 view;
mat4 proj;
} uMVP;

void main()
{
gl_Position = uMVP.proj * uMVP.view * uMVP.model * vec4(aPos, 0.0, 1.0);
vColor = aColor;
}
12 changes: 12 additions & 0 deletions assets/shaders/uniform_color.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450 core

layout(location = 0) out vec4 FragColor;

layout(binding = 0) uniform ColorData {
vec3 color;
} uColor;

void main()
{
FragColor = vec4(uColor.color, 1.0);
}
8 changes: 8 additions & 0 deletions assets/shaders/uniform_color.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 450 core

layout(location = 0) in vec2 aPos;

void main()
{
gl_Position = vec4(aPos, 0.0, 1.0);
}
2 changes: 1 addition & 1 deletion include/CAE/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace cae
void stop();

private:
void setupEngine(const std::string &rendererName, const std::string &windowName);
void setupEngine(const std::string &rendererName, const std::string &windowName, const std::string &shaderName);

static EngineConfig parseEngineConf(const std::string &path);

Expand Down
2 changes: 2 additions & 0 deletions include/CAE/Engine/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace cae
const std::function<std::shared_ptr<IInput>()> &inputFactory,
const std::function<std::shared_ptr<INetwork>()> &networkFactory,
const std::function<std::shared_ptr<IRenderer>()> &rendererFactory,
const std::function<std::shared_ptr<IShader>()> &shaderFactory,
const std::function<std::shared_ptr<IWindow>()> &windowFactory);
~Engine() = default;

Expand All @@ -73,6 +74,7 @@ namespace cae
std::shared_ptr<IInput> m_inputPlugin = nullptr;
std::shared_ptr<INetwork> m_networkPlugin = nullptr;
std::shared_ptr<IRenderer> m_rendererPlugin = nullptr;
std::shared_ptr<IShader> m_shaderPlugin = nullptr;
std::shared_ptr<IWindow> m_windowPlugin = nullptr;

std::unique_ptr<utl::Clock> m_clock = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace cae
{

enum KeyState : std::uint8_t
enum class KeyState : std::uint8_t
{
Pressed = 0,
Released = 1,
Expand Down
39 changes: 39 additions & 0 deletions modules/Interfaces/include/Interfaces/Renderer/ARenderer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
///
/// @file ARenderer.hpp
/// @brief This file contains the Renderer abstract class
/// @namespace cae
///

#pragma once

#include "Interfaces/Renderer/IRenderer.hpp"

#include <memory>

namespace cae
{

///
/// @interface ARenderer
/// @brief Abstract class for renderer
/// @namespace cae
///
class ARenderer : public IRenderer
{

public:
~ARenderer() override = default;

std::shared_ptr<IShader> getShader() const override { return m_shader; }
std::shared_ptr<IModel> getModel() const override { return m_model; }

void setShader(const std::shared_ptr<IShader> shader) override { m_shader = shader; }
void setModel(const std::shared_ptr<IModel> model) override { m_model = model; }

protected:
std::shared_ptr<IShader> m_shader;
std::shared_ptr<IModel> m_model;

}; // interface ARenderer

} // namespace cae
12 changes: 11 additions & 1 deletion modules/Interfaces/include/Interfaces/Renderer/IRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#pragma once

#include "Interfaces/Renderer/IModel.hpp"
#include "Interfaces/Renderer/IShader.hpp"
#include "Interfaces/IWindow.hpp"

namespace cae
Expand All @@ -22,7 +24,15 @@ namespace cae
public:
~IRenderer() override = default;

virtual void initialize(const NativeWindowHandle &nativeWindowHandle) = 0;
virtual std::shared_ptr<IShader> getShader() const = 0;
virtual std::shared_ptr<IModel> getModel() const = 0;

virtual void setShader(std::shared_ptr<IShader> shader) = 0;
virtual void setModel(std::shared_ptr<IModel> model) = 0;

virtual void initialize(const NativeWindowHandle &nativeWindowHandle, std::shared_ptr<IShader> shader) = 0;
virtual void createPipeline(const ShaderPipelineDesc& pipeline) = 0;

virtual void draw(const WindowSize &windowSize) = 0;

virtual void setVSyncEnabled(bool enabled) = 0;
Expand Down
51 changes: 51 additions & 0 deletions modules/Interfaces/include/Interfaces/Renderer/IShader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,54 @@

#pragma once

#include <vector>

#include "Utils/Interfaces/IPlugin.hpp"

using ShaderID = std::string;

enum class ShaderSourceType : uint8_t
{
GLSL,
HLSL,
SPIRV,
MSL,
WGSL,
UNDEFINED = 255
};

enum class ShaderStage : uint8_t
{
VERTEX,
FRAGMENT,
GEOMETRY,
COMPUTE,
UNDEFINED = 255
};

struct ShaderModuleDesc
{
// ShaderSourceType type;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 19 days ago

To fix the problem, simply remove the commented-out code on line 36: // ShaderSourceType type;. This will make the code cleaner, less confusing, and prevent the risk of misleading developers or creating unnecessary clutter. Only edit the affected region, leaving the remainder of the struct and file unchanged. No further changes, imports, methods, or definitions are necessary.

Suggested changeset 1
modules/Interfaces/include/Interfaces/Renderer/IShader.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/Interfaces/include/Interfaces/Renderer/IShader.hpp b/modules/Interfaces/include/Interfaces/Renderer/IShader.hpp
--- a/modules/Interfaces/include/Interfaces/Renderer/IShader.hpp
+++ b/modules/Interfaces/include/Interfaces/Renderer/IShader.hpp
@@ -33,7 +33,6 @@
 
 struct ShaderModuleDesc
 {
-    // ShaderSourceType type;
     ShaderID id;
     std::string source;
     ShaderStage stage;
EOF
@@ -33,7 +33,6 @@

struct ShaderModuleDesc
{
// ShaderSourceType type;
ShaderID id;
std::string source;
ShaderStage stage;
Copilot is powered by AI and may make mistakes. Always verify output.
ShaderID id;
std::string source;
ShaderStage stage;
};

struct ShaderPipelineDesc
{
ShaderID id;
ShaderID vertex;
ShaderID fragment;
};

struct ShaderData {
ShaderSourceType type;
std::string source; // GLSL/HLSL/etc. pour debug/fallback
std::vector<uint32_t> spirv; // SPIR-V compilé
ShaderStage stage;
std::string entryPoint = "main";
};

namespace cae
{

Expand All @@ -22,6 +68,11 @@
public:
~IShader() override = default;

virtual void addShader(const ShaderModuleDesc& pipelineDesc) = 0;
virtual bool compileAll() = 0;
virtual const ShaderData& getShader(const ShaderID& name) const = 0;
virtual bool isCompiled(const ShaderID& name) const = 0;

}; // interface IShader

} // namespace cae
5 changes: 3 additions & 2 deletions modules/utils/include/Utils/Interfaces/IPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ namespace utl
AUDIO = 0,
NETWORK = 1,
RENDERER = 2,
WINDOW = 3,
SHADER = 3,
WINDOW = 4,
UNDEFINED = 255,
};

enum PluginPlatform : uint8_t
enum class PluginPlatform : uint8_t
{
LINUX = 0,
MACOSX = 1,
Expand Down
26 changes: 16 additions & 10 deletions modules/utils/include/Utils/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ namespace utl
class Logger
{

private:
template<typename E>
static constexpr auto to_underlying(E e) noexcept {
return static_cast<std::underlying_type_t<E>>(e);
}

public:
Logger(const Logger &) = delete;
Logger &operator=(const Logger &) = delete;
Expand All @@ -45,22 +51,22 @@ namespace utl

std::cout << getColorForDuration(duration)
<< formatLogMessage(LogLevel::INFO, message + " took " + std::to_string(duration) + " ms")
<< LOG_LEVEL_COLOR[COLOR_RESET];
<< LOG_LEVEL_COLOR[to_underlying(ColorIndex::COLOR_RESET)];
}

static void log(const std::string &message, const LogLevel &logLevel)
{
std::cout << (logLevel == LogLevel::INFO ? LOG_LEVEL_COLOR[COLOR_INFO] : LOG_LEVEL_COLOR[COLOR_WARNING])
<< formatLogMessage(logLevel, message) << LOG_LEVEL_COLOR[COLOR_RESET];
std::cout << (logLevel == LogLevel::INFO ? LOG_LEVEL_COLOR[to_underlying(ColorIndex::COLOR_INFO)] : LOG_LEVEL_COLOR[to_underlying(ColorIndex::COLOR_WARNING)])
<< formatLogMessage(logLevel, message) << LOG_LEVEL_COLOR[to_underlying(ColorIndex::COLOR_RESET)];
}

private:
enum ColorIndex : uint8_t
enum class ColorIndex : uint8_t
{
COLOR_ERROR,
COLOR_INFO,
COLOR_WARNING,
COLOR_RESET
COLOR_ERROR = 0,
COLOR_INFO = 1,
COLOR_WARNING = 2,
COLOR_RESET = 3
};

static constexpr std::array<const char *, 4> LOG_LEVEL_COLOR = {
Expand All @@ -78,8 +84,8 @@ namespace utl
[[nodiscard]] static const char *getColorForDuration(const float duration)
{
return duration < 20.0F
? LOG_LEVEL_COLOR[COLOR_INFO]
: (duration < 90.0F ? LOG_LEVEL_COLOR[COLOR_WARNING] : LOG_LEVEL_COLOR[COLOR_ERROR]);
? LOG_LEVEL_COLOR[to_underlying(ColorIndex::COLOR_INFO)]
: (duration < 90.0F ? LOG_LEVEL_COLOR[to_underlying(ColorIndex::COLOR_WARNING)] : LOG_LEVEL_COLOR[to_underlying(ColorIndex::COLOR_ERROR)]);
}

[[nodiscard]] static std::string formatLogMessage(LogLevel level, const std::string &message)
Expand Down
4 changes: 3 additions & 1 deletion modules/utils/include/Utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

#pragma once

#include <filesystem>
#include <vector>

namespace utl
{
[[nodiscard]] std::vector<char> readFile(const std::string &filename);
[[nodiscard]] std::vector<char> fileToVector(const std::filesystem::path& path);
[[nodiscard]] std::string fileToString(const std::filesystem::path& path);
} // namespace utl
Loading
Loading