(Temp) UI only renders to backbuffer

This commit is contained in:
2023-05-10 12:48:33 -07:00
parent d643d5f220
commit cdf9b0a35d
6 changed files with 80 additions and 16 deletions

View File

@ -130,21 +130,23 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
}
// UI Elements
auto canvases = scene->findComponents<UICanvas>();
auto itCanvas = canvases.begin();
while(itCanvas != canvases.end()) {
auto canvas = *itCanvas;
glm::mat4 projection;
glm::mat4 view;
canvas->getProjectionAndView(&projection, &view);
if(renderTarget == this->renderManager->getBackBuffer()) {
auto canvases = scene->findComponents<UICanvas>();
auto itCanvas = canvases.begin();
while(itCanvas != canvases.end()) {
auto canvas = *itCanvas;
glm::mat4 projection;
glm::mat4 view;
canvas->getProjectionAndView(&projection, &view);
auto renderables = canvas->item->findChildrenDeep<UIComponentRenderable>();
auto itChild = renderables.begin();
while(itChild != renderables.end()) {
vectorAppend(&shaderPassItems,(*itChild)->getPassItems(projection, view));
++itChild;
auto renderables = canvas->item->findChildrenDeep<UIComponentRenderable>();
auto itChild = renderables.begin();
while(itChild != renderables.end()) {
vectorAppend(&shaderPassItems,(*itChild)->getPassItems(projection, view));
++itChild;
}
++itCanvas;
}
++itCanvas;
}
// Debug Lines

View File

@ -12,6 +12,7 @@ target_sources(${DAWN_TARGET_NAME}
PixelPerfectCamera.cpp
TiledSprite.cpp
SimpleRenderTargetQuad.cpp
CameraTexture.cpp
)
add_subdirectory(mesh)

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 "CameraTexture.hpp"
using namespace Dawn;
CameraTexture::CameraTexture(SceneItem *item) :
SceneItemComponent(item),
camera(nullptr),
renderTarget(32.0f, 32.0f)
{
}
void CameraTexture::onStart() {
if(this->camera == nullptr) this->camera = item->getComponent<Camera>();
useEffect([&]{
if(this->camera == nullptr) return;
this->camera->renderTarget = &this->renderTarget;
}, this->camera)();
}

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 "scene/components/display/Camera.hpp"
#include "display/TextureRenderTarget.hpp"
namespace Dawn {
class CameraTexture : public SceneItemComponent {
protected:
public:
StateProperty<Camera*> camera;
TextureRenderTarget renderTarget;
CameraTexture(SceneItem *item);
void onStart() override;
};
}

View File

@ -37,6 +37,8 @@ void UIComponent::updateAlignment() {
auto dimensional = this->getParentDimensional();
auto translate = this->transform->getLocalPosition();
assertNotNull(dimensional);
float_t parentWidth, parentHeight;
parentWidth = dimensional->getWidth();
parentHeight = dimensional->getHeight();

View File

@ -5,9 +5,11 @@
#pragma once
#include "scene/Scene.hpp"
#include "scene/components/display/Camera.hpp"
#include "scene/components/display/CameraTexture.hpp"
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "prefabs/VNTextbox.hpp"
#include "display/TextureRenderTarget.hpp"
#include "scene/components/ui/UIImage.hpp"
namespace Dawn {
class HelloWorldScene : public Scene {
@ -15,6 +17,7 @@ namespace Dawn {
Camera *camera;
Camera *camNew;
UICanvas *canvas;
TextureRenderTarget *renderTarget;
Texture text;
int32_t test = 0;
@ -24,17 +27,27 @@ namespace Dawn {
camera = Camera::create(this);
camera->fov = 0.436332f;
camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));
camera->transform->lookAt(glm::vec3(900, 900, 900), glm::vec3(800, 800, 800));
camNew = Camera::create(this);
auto camTexture = camNew->item->addComponent<CameraTexture>();
camNew->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));
camNew->renderTarget = nullptr;
camTexture->renderTarget.setSize(256, 256);
auto cube = SimpleSpinningCubePrefab::create(this);
auto textbox = VNTextbox::create(this);
textbox->transform.setParent(canvas->transform);
auto uiTest = this->createSceneItem();
uiTest->transform.setParent(canvas->transform);
auto image = uiTest->addComponent<UIImage>();
image->texture = camTexture->renderTarget.getTexture();
image->alignment = glm::vec4(0, 0, 50, 0);
image->alignX = UI_COMPONENT_ALIGN_START;
image->alignUnitRight = UI_COMPONENT_ALIGN_UNIT_PERCENT;
image->alignY = UI_COMPONENT_ALIGN_STRETCH;
struct Color colors[] = {
COLOR_BLUE, COLOR_MAGENTA, COLOR_WHITE,
COLOR_MAGENTA, COLOR_CORNFLOWER_BLUE, COLOR_MAGENTA,