(Temp) UI only renders to backbuffer
This commit is contained in:
@ -130,6 +130,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UI Elements
|
// UI Elements
|
||||||
|
if(renderTarget == this->renderManager->getBackBuffer()) {
|
||||||
auto canvases = scene->findComponents<UICanvas>();
|
auto canvases = scene->findComponents<UICanvas>();
|
||||||
auto itCanvas = canvases.begin();
|
auto itCanvas = canvases.begin();
|
||||||
while(itCanvas != canvases.end()) {
|
while(itCanvas != canvases.end()) {
|
||||||
@ -146,6 +147,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
|||||||
}
|
}
|
||||||
++itCanvas;
|
++itCanvas;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Debug Lines
|
// Debug Lines
|
||||||
#if DAWN_DEBUG_BUILD
|
#if DAWN_DEBUG_BUILD
|
||||||
|
@ -12,6 +12,7 @@ target_sources(${DAWN_TARGET_NAME}
|
|||||||
PixelPerfectCamera.cpp
|
PixelPerfectCamera.cpp
|
||||||
TiledSprite.cpp
|
TiledSprite.cpp
|
||||||
SimpleRenderTargetQuad.cpp
|
SimpleRenderTargetQuad.cpp
|
||||||
|
CameraTexture.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(mesh)
|
add_subdirectory(mesh)
|
24
src/dawn/scene/components/display/CameraTexture.cpp
Normal file
24
src/dawn/scene/components/display/CameraTexture.cpp
Normal 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)();
|
||||||
|
}
|
22
src/dawn/scene/components/display/CameraTexture.hpp
Normal file
22
src/dawn/scene/components/display/CameraTexture.hpp
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
@ -37,6 +37,8 @@ void UIComponent::updateAlignment() {
|
|||||||
auto dimensional = this->getParentDimensional();
|
auto dimensional = this->getParentDimensional();
|
||||||
auto translate = this->transform->getLocalPosition();
|
auto translate = this->transform->getLocalPosition();
|
||||||
|
|
||||||
|
assertNotNull(dimensional);
|
||||||
|
|
||||||
float_t parentWidth, parentHeight;
|
float_t parentWidth, parentHeight;
|
||||||
parentWidth = dimensional->getWidth();
|
parentWidth = dimensional->getWidth();
|
||||||
parentHeight = dimensional->getHeight();
|
parentHeight = dimensional->getHeight();
|
||||||
|
@ -5,9 +5,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "scene/Scene.hpp"
|
#include "scene/Scene.hpp"
|
||||||
#include "scene/components/display/Camera.hpp"
|
#include "scene/components/display/CameraTexture.hpp"
|
||||||
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
||||||
#include "prefabs/VNTextbox.hpp"
|
#include "prefabs/VNTextbox.hpp"
|
||||||
|
#include "display/TextureRenderTarget.hpp"
|
||||||
|
#include "scene/components/ui/UIImage.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class HelloWorldScene : public Scene {
|
class HelloWorldScene : public Scene {
|
||||||
@ -15,6 +17,7 @@ namespace Dawn {
|
|||||||
Camera *camera;
|
Camera *camera;
|
||||||
Camera *camNew;
|
Camera *camNew;
|
||||||
UICanvas *canvas;
|
UICanvas *canvas;
|
||||||
|
TextureRenderTarget *renderTarget;
|
||||||
Texture text;
|
Texture text;
|
||||||
|
|
||||||
int32_t test = 0;
|
int32_t test = 0;
|
||||||
@ -24,17 +27,27 @@ namespace Dawn {
|
|||||||
|
|
||||||
camera = Camera::create(this);
|
camera = Camera::create(this);
|
||||||
camera->fov = 0.436332f;
|
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);
|
camNew = Camera::create(this);
|
||||||
|
auto camTexture = camNew->item->addComponent<CameraTexture>();
|
||||||
camNew->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));
|
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 cube = SimpleSpinningCubePrefab::create(this);
|
||||||
|
|
||||||
auto textbox = VNTextbox::create(this);
|
auto textbox = VNTextbox::create(this);
|
||||||
textbox->transform.setParent(canvas->transform);
|
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[] = {
|
struct Color colors[] = {
|
||||||
COLOR_BLUE, COLOR_MAGENTA, COLOR_WHITE,
|
COLOR_BLUE, COLOR_MAGENTA, COLOR_WHITE,
|
||||||
COLOR_MAGENTA, COLOR_CORNFLOWER_BLUE, COLOR_MAGENTA,
|
COLOR_MAGENTA, COLOR_CORNFLOWER_BLUE, COLOR_MAGENTA,
|
||||||
|
Reference in New Issue
Block a user