Uniform arrays working.

This commit is contained in:
2023-12-11 23:54:52 -06:00
parent 81adf91816
commit 0fa08a1c92
18 changed files with 447 additions and 23 deletions

View File

@ -0,0 +1,10 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DAWN_TARGET_NAME}
PRIVATE
UIComponent.cpp
UIRectangle.cpp
)

13
src/dawn/ui/UIAlign.hpp Normal file
View File

@ -0,0 +1,13 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct UIAlign {
glm::vec2 position;
};
}

View File

@ -0,0 +1,37 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIComponent.hpp"
using namespace Dawn;
std::vector<std::shared_ptr<UIComponent>> UIComponent::getChildren() {
return {};
}
std::vector<struct UIQuad> UIComponent::getQuads(
const glm::mat4 parent
) {
// Get self transform
glm::mat4 transform = glm::translate(
glm::mat4(1.0f), glm::vec3(position, 0.0f)
);
// Add parent transform
transform = parent * transform;
// Get self quads and insert new transform.
std::vector<struct UIQuad> quads;
auto selfQuads = this->getSelfQuads(transform);
// Get children
auto children = getChildren();
for(auto &c : children) {
auto childQuads = c->getQuads(transform);
quads.insert(quads.end(), childQuads.begin(), childQuads.end());
}
return quads;
}

View File

@ -0,0 +1,30 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "ui/UIAlign.hpp"
#include "ui/UIQuad.hpp"
namespace Dawn {
class UICanvas;
class UIComponent {
protected:
virtual std::vector<struct UIQuad> getSelfQuads(
const glm::mat4 transform
) = 0;
virtual std::vector<std::shared_ptr<UIComponent>> getChildren();
std::vector<struct UIQuad> getQuads(
const glm::mat4 parent
);
public:
glm::vec2 position;
friend class UICanvas;
};
}

34
src/dawn/ui/UIQuad.hpp Normal file
View File

@ -0,0 +1,34 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/Color.hpp"
#include "display/Texture.hpp"
namespace Dawn {
struct UIQuad {
glm::mat4 transform;
glm::vec4 quad;
glm::vec4 uv;
struct Color color;
std::shared_ptr<Texture> texture;
UIQuad(
const glm::mat4 transform,
const glm::vec4 quad,
const glm::vec4 uv,
const struct Color color,
const std::shared_ptr<Texture> texture
) :
transform(transform),
quad(quad),
uv(uv),
color(color),
texture(texture)
{
}
};
}

View File

@ -0,0 +1,24 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIRectangle.hpp"
using namespace Dawn;
std::vector<struct UIQuad> UIRectangle::getSelfQuads(
const glm::mat4 transform
) {
std::vector<struct UIQuad> quads;
quads.push_back(UIQuad(
transform,
glm::vec4(0,0,size.x,size.y),
uv,
color,
texture
));
return quads;
}

View File

@ -0,0 +1,22 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "ui/UIComponent.hpp"
namespace Dawn {
class UIRectangle final : public UIComponent {
protected:
std::vector<struct UIQuad> getSelfQuads(
const glm::mat4 transform
) override;
public:
struct Color color = COLOR_WHITE;
std::shared_ptr<Texture> texture = nullptr;
glm::vec2 size = glm::vec2(32, 32);
glm::vec4 uv = glm::vec4(0,0,1,1);
};
}