56 lines
1.5 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIMesh.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
UIMesh::UIMesh(std::weak_ptr<SceneItem> i) :
texture(nullptr),
UIComponentRenderable(i)
{
}
float_t UIMesh::getContentWidth() {
if(this->texture != nullptr) return this->texture->getWidth();
return this->width;
}
float_t UIMesh::getContentHeight() {
if(this->texture != nullptr) return this->texture->getHeight();
return this->height;
}
std::vector<struct ShaderPassItem> UIMesh::getUIRenderPasses() {
struct ShaderPassItem shaderItem;
auto shader = getGame()->renderManager->uiShader;
shaderItem.shader = shader;
shaderItem.colorValues[shader->paramColor] = this->color;
shaderItem.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
shaderItem.matrixValues[shader->paramModel] = item.lock()->getWorldTransform();
if(this->texture == nullptr) {
shaderItem.boolValues[shader->paramHasTexture] = false;
} else {
shaderItem.boolValues[shader->paramHasTexture] = true;
shaderItem.textureSlots[0] = this->texture;
shaderItem.textureValues[shader->paramTexture] = 0;
}
shaderItem.w = item.lock()->getWorldPosition().z;
shaderItem.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
shaderItem.mesh = &mesh;
return { shaderItem };
}
void UIMesh::onStart() {
useEffect([&]{
}, this->positions)();
useEffect([&]{
}, this->uvs)();
}