63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "UICanvas.hpp"
|
|
#include "display/pass/RenderPass.hpp"
|
|
#include "display/shader/UIShader.hpp"
|
|
|
|
#include "display/mesh/QuadMesh.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
void UICanvas::onInit() {
|
|
|
|
}
|
|
|
|
void UICanvas::onDispose() {
|
|
|
|
}
|
|
|
|
std::vector<std::shared_ptr<IRenderPass>> UICanvas::getPasses(
|
|
struct RenderPassContext &ctx
|
|
) {
|
|
std::vector<std::shared_ptr<IRenderPass>> passes;
|
|
|
|
auto selfTransform = this->getItem()->getWorldTransform();
|
|
|
|
auto mesh = std::make_shared<Mesh>();
|
|
mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
|
|
QuadMesh::buffer(mesh, glm::vec4(0, 0, 32, 32), glm::vec4(0, 0, 1, 1), 0, 0);
|
|
UIShaderData data = {
|
|
.projection = ctx.camera->getProjection(),
|
|
.view = ctx.camera->getItem()->getWorldTransform(),
|
|
.model = selfTransform
|
|
};
|
|
|
|
data.test.first = COLOR_RED;
|
|
data.test.random = glm::vec3(0, 1, 0);
|
|
data.test.second = COLOR_BLUE;
|
|
|
|
auto pass = createRenderPass<UIShader, UIShaderData>(
|
|
std::ref(*this),
|
|
data,
|
|
std::unordered_map<shadertexturebinding_t, std::shared_ptr<Texture>>(),
|
|
mesh,
|
|
MeshDrawMode::TRIANGLES,
|
|
0, -1
|
|
);
|
|
passes.push_back(pass);
|
|
|
|
auto itComponents = components.begin();
|
|
while(itComponents != components.end()) {
|
|
auto component = *itComponents;
|
|
|
|
// Get this components' quads.
|
|
auto quads = component->getQuads(selfTransform);
|
|
|
|
++itComponents;
|
|
}
|
|
|
|
return passes;
|
|
} |