Standardizing Shader Buffers a bit more

This commit is contained in:
2023-07-23 22:28:50 -07:00
parent 427be68e63
commit 34ff460343
12 changed files with 96 additions and 33 deletions

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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()

View File

@ -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
)

View File

@ -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
)

View File

@ -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<typename T>
class ShaderParameterBuffer : public IShaderParameterBuffer<shaderbufferslot_t> {

View File

@ -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<struct MACRO_JOIN(name, Data)> { };
// 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"

View File

@ -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<struct RenderPipelineShaderBufferData> {

View File

@ -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<struct FontShaderBufferData> {
};
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:

View File

@ -10,15 +10,10 @@
#define UI_SHADER_PROGRAM_PRIORITY 1000
namespace Dawn {
struct UICanvasShaderParameterBufferData {
glm::mat4 projection;
glm::mat4 view;
};
class UICanvasShaderParameterBuffer :
public ShaderParameterBuffer<struct UICanvasShaderParameterBufferData>
{
};
SHADER_PARAMETER_BUFFER_DEFINE(UICanvasShaderBuffer, \
SHADER_PARAMETER_BUFFER_MAT4(projection);
SHADER_PARAMETER_BUFFER_MAT4(view);
);
class UIShader : public Shader {
public:

View File

@ -6,4 +6,6 @@
#pragma once
#define MACRO_STRINGIFY_RAW(x) #x
#define MACRO_STRINGIFY(x) MACRO_STRINGIFY_RAW(x)
#define MACRO_STRINGIFY(x) MACRO_STRINGIFY_RAW(x)
#define MACRO_JOIN(x, y) x ## y