Skip to content

Commit

Permalink
ctx ref + terrain shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
hotstreams committed Jun 7, 2024
1 parent a4801b6 commit 058c106
Show file tree
Hide file tree
Showing 107 changed files with 1,824 additions and 872 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(ENGINE_CORE
src/limitless/core/context_initializer.cpp
src/limitless/core/context_state.cpp
src/limitless/core/context.cpp
src/limitless/core/window_hints.cpp
src/limitless/core/context_observer.cpp
src/limitless/core/state_query.cpp
src/limitless/core/profiler.cpp
Expand Down Expand Up @@ -76,6 +77,7 @@ set(ENGINE_INSTANCES
src/limitless/instances/instance_builder.cpp
src/limitless/instances/decal_instance.cpp
src/limitless/instances/instanced_instance.cpp
src/limitless/instances/terrain_instance.cpp
)

set(ENGINE_LIGHTING
Expand Down Expand Up @@ -169,6 +171,7 @@ set(ENGINE_PIPELINE
src/limitless/pipeline/forward/postprocessing.cpp
src/limitless/renderer/renderer.cpp
src/limitless/renderer/render_settings_shader_definer.cpp
src/limitless/renderer/renderer_settings.cpp
src/limitless/pipeline/common/scene_data.cpp
src/limitless/pipeline/deferred/effectupdate_pass.cpp
src/limitless/pipeline/deferred/deferred_framebuffer_pass.cpp
Expand Down Expand Up @@ -256,8 +259,8 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()

if (CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_options(limitless-engine PRIVATE -Wpedantic -Wextra -Wall -Wunused -Wno-attributes -Werror -O3)
# target_compile_options(limitless-engine PUBLIC -Wpedantic -Wextra -Wall -Wunused -Wno-attributes -O3)
# target_compile_options(limitless-engine PRIVATE -Wpedantic -Wextra -Wall -Wunused -Wno-attributes -Werror -O3)
target_compile_options(limitless-engine PRIVATE -Wpedantic -Wextra -Wall -Wunused -Wno-attributes -O3)
endif()

if (OPENGL_DEBUG)
Expand Down
18 changes: 9 additions & 9 deletions include/limitless/assets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Limitless {
class Skybox;
class FontAtlas;
class Context;
class RenderSettings;
class RendererSettings;

/**
* Assets is a class that contains a set of resources
Expand All @@ -38,7 +38,7 @@ namespace Limitless {
*/
class Assets {
private:
static ShaderTypes getRequiredPassShaders(const RenderSettings& settings);
static ShaderTypes getRequiredPassShaders(const RendererSettings& settings);

protected:
fs::path base_dir;
Expand Down Expand Up @@ -77,28 +77,28 @@ namespace Limitless {
/**
*
*/
virtual void initialize(Context& ctx, const RenderSettings& settings);
virtual void initialize(Context& ctx, const RendererSettings& settings);

/**
* Compiles shader for specified Material with passed RenderSettings if not already compiled
*
* adds created shader/shaders to shader storage
*/
void compileMaterial(Context& ctx, const RenderSettings& settings, const std::shared_ptr<ms::Material>& material);
void compileMaterial(Context& ctx, const RendererSettings& settings, const std::shared_ptr<ms::Material>& material);

/**
* Compiles shader for specified Effect with passed RenderSettings if not already compiled
*
* adds created shader/shaders to shader storage
*/
void compileEffect(Context& ctx, const RenderSettings& settings, const std::shared_ptr<EffectInstance>& effect);
void compileEffect(Context& ctx, const RendererSettings& settings, const std::shared_ptr<EffectInstance>& effect);

/**
* Compiles shader for specified Skybox with passed RenderSettings if not already compiled
*
* adds created shader/shaders to shader storage
*/
void compileSkybox(Context& ctx, const RenderSettings& settings, const std::shared_ptr<Skybox>& skybox);
void compileSkybox(Context& ctx, const RendererSettings& settings, const std::shared_ptr<Skybox>& skybox);

/**
* Recompiles shader for specified Material with passed RenderSettings
Expand All @@ -109,17 +109,17 @@ namespace Limitless {
*
* If you updated your material, you should use compileMaterial
*/
void recompileMaterial(Context& ctx, const RenderSettings& settings, const std::shared_ptr<ms::Material>& material);
void recompileMaterial(Context& ctx, const RendererSettings& settings, const std::shared_ptr<ms::Material>& material);

/**
* Compiles all assets
*/
virtual void compileAssets(Context& ctx, const RenderSettings& settings);
virtual void compileAssets(Context& ctx, const RendererSettings& settings);

/**
*
*/
void recompileAssets(Context& ctx, const RenderSettings& settings);
void recompileAssets(Context& ctx, const RendererSettings& settings);

/**
*
Expand Down
135 changes: 119 additions & 16 deletions include/limitless/core/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,54 @@

#include <limitless/core/context_initializer.hpp>
#include <limitless/core/context_state.hpp>
#include <limitless/core/context_observer.hpp>
#include <limitless/core/window_hints.hpp>

#include <stdexcept>
#include <optional>

namespace Limitless {
enum class CursorMode { Normal = GLFW_CURSOR_NORMAL, Hidden = GLFW_CURSOR_HIDDEN, Disabled = GLFW_CURSOR_DISABLED };

enum class WindowHint {
Resizable = GLFW_RESIZABLE,
Visible = GLFW_VISIBLE,
Decorated = GLFW_DECORATED,
Focused = GLFW_FOCUSED,
AutoIconify = GLFW_AUTO_ICONIFY,
Maximized = GLFW_MAXIMIZED,
Samples = GLFW_SAMPLES
enum class CursorMode {
Normal = GLFW_CURSOR_NORMAL,
Hidden = GLFW_CURSOR_HIDDEN,
Disabled = GLFW_CURSOR_DISABLED
};
using WindowHints = std::vector<std::pair<WindowHint, int>>;

struct context_error : public std::runtime_error {
explicit context_error(const char* error) noexcept : runtime_error{error} {}
};

class Context : public ContextInitializer, public ContextState {
protected:
class Context final : public ContextInitializer, public ContextState {
private:
static inline std::unordered_map<GLFWwindow*, Context*> contexts;

GLFWwindow* window {};

std::optional<GLFWmonitor*> monitor;
glm::uvec2 size {1, 1};

Context() = default;
FramebufferCallback framebuffer_callback;
MouseClickCallback mouseclick_callback;
MouseMoveCallback mousemove_callback;
ScrollCallback scroll_callback;
CharCallback char_callback;
KeyCallback key_callback;

void registerCallbacks() noexcept;
void registerContext() noexcept;
void unregisterContext() noexcept;

static void framebufferCallback(GLFWwindow* win, int w, int h);
static void mouseclickCallback(GLFWwindow* win, int button, int action, int modifiers);
static void mousemoveCallback(GLFWwindow* win, double x, double y);
static void keyboardCallback(GLFWwindow* win, int key, int scancode, int action, int modifiers);
static void scrollCallback(GLFWwindow* win, double x, double y);
static void charCallback(GLFWwindow* win, uint32_t utf);

Context(const std::string& title, glm::uvec2 size, const Context* shared, const WindowHints& hints);

friend void swap(Context& lhs, Context& rhs) noexcept;
public:
Context(std::string_view title, glm::uvec2 size, const WindowHints& hints = WindowHints{});
Context(std::string_view title, glm::uvec2 size, const Context& shared, const WindowHints& hints = WindowHints{});
~Context() override;

Context(const Context&) = delete;
Expand All @@ -44,6 +59,7 @@ namespace Limitless {
Context& operator=(Context&&) noexcept;

operator GLFWwindow*() const noexcept;
GLFWwindow* getWindow() const noexcept;

void makeCurrent() const noexcept;
void swapBuffers() const noexcept;
Expand Down Expand Up @@ -71,6 +87,93 @@ namespace Limitless {
[[nodiscard]] glm::uvec2 getSize() const noexcept;
[[nodiscard]] glm::vec2 getCursorPos() const noexcept;
[[nodiscard]] bool isFocused() const noexcept;

void setStickyMouseButtons(bool value) const noexcept;
void setStickyKeys(bool value) const noexcept;

InputState getKey(int key) const noexcept;
bool isPressed(int key) const noexcept;

InputState getMouseButton(MouseButton button);

void doOnFramebufferChange(FramebufferCallback callback);
void doOnMouseClick(MouseClickCallback callback);
void doOnMouseMove(MouseMoveCallback callback);
void doOnKeyPress(KeyCallback callback);
void doOnCharPress(CharCallback callback);
void doOnScroll(ScrollCallback callback);

void onFramebufferChange(glm::uvec2 size);
void onMouseClick(glm::dvec2 pos, MouseButton button, InputState state, Modifier modifier) const;
void onMouseMove(glm::dvec2 pos) const;
void onKey(int key, int scancode, InputState state, Modifier modifier) const;
void onScroll(glm::dvec2 pos) const;
void onChar(uint32_t utf8) const;

static Context* getCurrentContext() noexcept;

/**
* Invokes specified function for the current context if present
*/
static void apply(const std::function<void(Context&)>& function);

class Builder {
private:
std::string ctx_title;
glm::uvec2 ctx_size {640, 480};
Context* ctx_shared {};
WindowHints ctx_hints;
uint32_t ctx_interval {};
std::function<GLFWimage()> ctx_icon;
CursorMode ctx_cursor {CursorMode::Normal};
bool ctx_sticky_keys {false};

FramebufferCallback framebuffer_callback;
MouseClickCallback mouseclick_callback;
MouseMoveCallback mousemove_callback;
ScrollCallback scroll_callback;
CharCallback char_callback;
KeyCallback key_callback;
public:
Builder& title(const std::string& title);
Builder& size(glm::uvec2 size);
Builder& shared(Context* shared);
Builder& hints(const WindowHints& hints);

Builder& resizeable();
Builder& not_resizeable();

Builder& visible();
Builder& not_visible();

Builder& decorated();
Builder& not_decorated();

Builder& focused();
Builder& not_focused();

Builder& maximized();
Builder& not_maximized();

Builder& swap_interval(uint32_t interval);

Builder& icon(const std::function<GLFWimage()>& icon_load);

Builder& cursor(CursorMode cursor);

Builder& sticky_keys();

Builder& on_framebuffer_change(FramebufferCallback callback);
Builder& on_mouse_click(MouseClickCallback callback);
Builder& on_mouse_move(MouseMoveCallback callback);
Builder& on_key_press(KeyCallback callback);
Builder& on_char_press(CharCallback callback);
Builder& on_scroll(ScrollCallback callback);

Context build();
};

static Builder builder();
};

void swap(Context& lhs, Context& rhs) noexcept;
Expand Down
Loading

0 comments on commit 058c106

Please sign in to comment.