diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd66ab8c..b1328f4c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,9 @@ if(DEFINED DAWN_BUILDING) add_subdirectory(${DAWN_BUILDING}) endif() +# Definitions +add_subdirectory(dawndefs) + # Validate game project includes the target name if(DEFINED DAWN_TARGET_NAME) # Add in base library diff --git a/src/dawn/scene/components/ui/UICanvas.cpp b/src/dawn/scene/components/ui/UICanvas.cpp index e27c1447..e2e05951 100644 --- a/src/dawn/scene/components/ui/UICanvas.cpp +++ b/src/dawn/scene/components/ui/UICanvas.cpp @@ -21,7 +21,7 @@ UICanvas::UICanvas(SceneItem *item) : } void UICanvas::rebufferShaderParameters() { - struct UICanvasShaderParameterBufferData data; + struct UICanvasShaderBufferData data; switch(this->drawType) { case UI_DRAW_TYPE_WORLD_ABSOLUTE: diff --git a/src/dawn/scene/components/ui/UICanvas.hpp b/src/dawn/scene/components/ui/UICanvas.hpp index ccc50fb6..4de514c5 100644 --- a/src/dawn/scene/components/ui/UICanvas.hpp +++ b/src/dawn/scene/components/ui/UICanvas.hpp @@ -74,7 +74,7 @@ namespace Dawn { void rebufferShaderParameters(); public: - UICanvasShaderParameterBuffer shaderBuffer; + UICanvasShaderBuffer shaderBuffer; /** * Creates a UI Canvas Scene Item Element, and attaches it to the provided diff --git a/src/dawndefs/CMakeLists.txt b/src/dawndefs/CMakeLists.txt new file mode 100644 index 00000000..a9d12f25 --- /dev/null +++ b/src/dawndefs/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2023 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +if(DAWN_TARGET_WIN32 AND DAWN_TARGET_GLFW) + add_subdirectory(opengl-win32) +endif() + +if(DAWN_TARGET_OSX AND DAWN_TARGET_GLFW) +endif() \ No newline at end of file diff --git a/src/dawndefs/opengl-osx/CMakeLists.txt b/src/dawndefs/opengl-osx/CMakeLists.txt new file mode 100644 index 00000000..aec30d83 --- /dev/null +++ b/src/dawndefs/opengl-osx/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +target_compile_definitions(${DAWN_TARGET_NAME} + PUBLIC + DAWN_OPENGL_SHADER_BUFFER_INTEGER_PADDING=3 +) \ No newline at end of file diff --git a/src/dawndefs/opengl-win32/CMakeLists.txt b/src/dawndefs/opengl-win32/CMakeLists.txt new file mode 100644 index 00000000..aec30d83 --- /dev/null +++ b/src/dawndefs/opengl-win32/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +target_compile_definitions(${DAWN_TARGET_NAME} + PUBLIC + DAWN_OPENGL_SHADER_BUFFER_INTEGER_PADDING=3 +) \ No newline at end of file diff --git a/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp b/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp index ac36995c..f4672ca3 100644 --- a/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp +++ b/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp @@ -4,22 +4,13 @@ // https://opensource.org/licenses/MIT #pragma once -#include "assert/assertgl.hpp" #include "dawnopengl.hpp" #include "display/shader/_ShaderParameterBuffer.hpp" +#include "ShaderParameterBufferTypes.hpp" namespace Dawn { typedef GLuint shaderbufferslot_t; typedef GLuint shaderbufferlocation_t; - - struct ShaderParameterBufferArrayInteger { - int32_t value; - #if _MSC_VER - int32_t padding[3]; - #elif APPLE - int32_t padding[1]; - #endif - }; template class ShaderParameterBuffer : public IShaderParameterBuffer { diff --git a/src/dawnopengl/display/shader/ShaderParameterBufferTypes.hpp b/src/dawnopengl/display/shader/ShaderParameterBufferTypes.hpp new file mode 100644 index 00000000..1d200a68 --- /dev/null +++ b/src/dawnopengl/display/shader/ShaderParameterBufferTypes.hpp @@ -0,0 +1,47 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "assert/assertgl.hpp" +#include "util/macro.hpp" + +// Definition Helpers +#define SHADER_PARAMETER_BUFFER_ARRAY_DEFINE(name, size, contents) \ + struct MACRO_JOIN(name, _struct) { \ + contents \ + }; \ + struct MACRO_JOIN(name, _struct) name[size]; + +#define SHADER_PARAMETER_BUFFER_DEFINE(name, structure) \ + struct MACRO_JOIN(name, Data) {\ + structure; \ + }; \ + class name : public ShaderParameterBuffer { }; + + +// Integer and Integer Arrays +#ifdef DAWN_OPENGL_SHADER_BUFFER_INTEGER_PADDING + #define SHADER_PARAMETER_BUFFER_INTEGER(name, i) \ + int32_t name; \ + int32_t MACRO_JOIN(padding, i)[DAWN_OPENGL_SHADER_BUFFER_INTEGER_PADDING]; +#else + #define SHADER_PARAMETER_BUFFER_INTEGER(name, i) int32_t name; +#endif + +#define SHADER_PARAMETER_BUFFER_INTEGER_ARRAY(name, size) SHADER_PARAMETER_BUFFER_ARRAY_DEFINE(name, size, SHADER_PARAMETER_BUFFER_INTEGER(value, 0)) + +// Color and Color Arrays +#define SHADER_PARAMETER_BUFFER_COLOR(name) \ + struct Color name; + +#define SHADER_PARAMETER_BUFFER_COLOR_ARRAY(name, size) \ + struct Color name[size]; + +// MAT4 +#define SHADER_PARAMETER_BUFFER_MAT4(name) \ + glm::mat4 name; + +// EOF Fix +#define NOTHING "Fixes an error with EOF" \ No newline at end of file diff --git a/src/dawnopengl/display/shader/buffers/RenderPipelineShaderBuffer.hpp b/src/dawnopengl/display/shader/buffers/RenderPipelineShaderBuffer.hpp index 662dac52..b7f5e9f5 100644 --- a/src/dawnopengl/display/shader/buffers/RenderPipelineShaderBuffer.hpp +++ b/src/dawnopengl/display/shader/buffers/RenderPipelineShaderBuffer.hpp @@ -8,8 +8,8 @@ namespace Dawn { struct RenderPipelineShaderBufferData { - glm::mat4 view; - glm::mat4 projection; + SHADER_PARAMETER_BUFFER_MAT4(view); + SHADER_PARAMETER_BUFFER_MAT4(projection); }; class RenderPipelineShaderBuffer : public ShaderParameterBuffer { diff --git a/src/dawnopengl/display/shader/shaders/FontShader.hpp b/src/dawnopengl/display/shader/shaders/FontShader.hpp index ad4af40f..66eb90b0 100644 --- a/src/dawnopengl/display/shader/shaders/FontShader.hpp +++ b/src/dawnopengl/display/shader/shaders/FontShader.hpp @@ -12,15 +12,11 @@ #define FONT_SHADER_TEXTURE_MAX 4 namespace Dawn { - struct FontShaderBufferData { - struct Color colors[FONT_SHADER_PARTS_MAX]; - struct ShaderParameterBufferArrayInteger textures[FONT_SHADER_PARTS_MAX]; - struct ShaderParameterBufferArrayInteger quadMappings[FONT_SHADER_QUADS_MAX]; - }; - - class FontShaderBuffer : public ShaderParameterBuffer { - - }; + SHADER_PARAMETER_BUFFER_DEFINE(FontShaderBuffer, \ + SHADER_PARAMETER_BUFFER_COLOR_ARRAY(colors, FONT_SHADER_PARTS_MAX); + SHADER_PARAMETER_BUFFER_INTEGER_ARRAY(textures, FONT_SHADER_PARTS_MAX); + SHADER_PARAMETER_BUFFER_INTEGER_ARRAY(quadMappings, FONT_SHADER_QUADS_MAX); + ); class FontShader : public Shader { public: diff --git a/src/dawnopengl/display/shader/shaders/UIShader.hpp b/src/dawnopengl/display/shader/shaders/UIShader.hpp index 99aa4e44..b7460f66 100644 --- a/src/dawnopengl/display/shader/shaders/UIShader.hpp +++ b/src/dawnopengl/display/shader/shaders/UIShader.hpp @@ -10,15 +10,10 @@ #define UI_SHADER_PROGRAM_PRIORITY 1000 namespace Dawn { - struct UICanvasShaderParameterBufferData { - glm::mat4 projection; - glm::mat4 view; - }; - - class UICanvasShaderParameterBuffer : - public ShaderParameterBuffer - { - }; + SHADER_PARAMETER_BUFFER_DEFINE(UICanvasShaderBuffer, \ + SHADER_PARAMETER_BUFFER_MAT4(projection); + SHADER_PARAMETER_BUFFER_MAT4(view); + ); class UIShader : public Shader { public: diff --git a/src/dawnshared/util/macro.hpp b/src/dawnshared/util/macro.hpp index 29ddfdc8..bcfb26e8 100644 --- a/src/dawnshared/util/macro.hpp +++ b/src/dawnshared/util/macro.hpp @@ -6,4 +6,6 @@ #pragma once #define MACRO_STRINGIFY_RAW(x) #x -#define MACRO_STRINGIFY(x) MACRO_STRINGIFY_RAW(x) \ No newline at end of file +#define MACRO_STRINGIFY(x) MACRO_STRINGIFY_RAW(x) + +#define MACRO_JOIN(x, y) x ## y \ No newline at end of file