Allow camera render target to be null

This commit is contained in:
2023-05-10 07:43:02 -07:00
parent fb53330105
commit d643d5f220
5 changed files with 17 additions and 9 deletions

View File

@ -60,7 +60,10 @@ void RenderPipeline::renderScene(Scene *scene) {
// Leave the backbuffer camera(s) to last, so we skip them. we do this so
// that children framebuffers contain the CURRENT frame, not LAST frame.
if(cameraTarget == backBuffer) {
if(cameraTarget == nullptr) {
++it;
continue;
} else if(cameraTarget == backBuffer) {
backBufferCamera = *it;
} else {
this->renderSceneCamera(scene, *it);

View File

@ -10,7 +10,7 @@ using namespace Dawn;
Camera::Camera(SceneItem *item) :
SceneItemComponent(item),
renderTarget(nullptr),
renderTarget(item->scene->game->renderManager.getBackBuffer()),
fov(0.785398f),// 45 degrees,
type(CAMERA_TYPE_PERSPECTIVE),
orthoLeft(0.0f),
@ -52,10 +52,6 @@ glm::mat4 Camera::getProjection() {
}
RenderTarget * Camera::getRenderTarget() {
auto v = this->renderTarget;
if(this->renderTarget == nullptr) {
return this->getGame()->renderManager.getBackBuffer();
}
return (RenderTarget*)this->renderTarget;
}
@ -80,6 +76,11 @@ void Camera::onStart() {
useEffectWithTeardown([&]{
auto rt = this->getRenderTarget();
this->projectionNeedsUpdating = true;
if(rt == nullptr) {
return evtResized = [&]{
};
}
this->eventRenderTargetResized.invoke(rt->getWidth(), rt->getHeight());
// Subscribe to new render target resized.
@ -100,6 +101,7 @@ void Camera::onStart() {
// Sub to evt legacy, we don't invoke the useTeardown to avoid invoking
// the state event for this camera when we don't need to.
if(!this->getRenderTarget()) return;
evtResized = useEventLegacy([&](RenderTarget *rt, float_t w, float_t h){
this->projectionNeedsUpdating = true;
this->eventRenderTargetResized.invoke(w, h);

View File

@ -53,8 +53,6 @@ void UIBorder::onStart() {
UIComponent::onStart();
auto rebufferQuad = [&] {
std::cout << "W" << this->getWidth() << std::endl;
std::cout << "H" << this->getHeight() << std::endl;
glm::vec2 tSize = glm::vec2(1, 1) / 3.0f;
glm::vec2 bSize = (glm::vec2)borderSize;
glm::vec2 iSize = glm::vec2(this->getWidth(), this->getHeight()) - ( bSize * 2.0f );

View File

@ -13,7 +13,7 @@ UILabel::UILabel(SceneItem *item) :
text(""),
fontSize(10.0f),
font(&item->scene->game->renderManager.defaultFont),
maxWidth(UI_LABEL_MAX_WIDTH_NONE)
maxWidth(UI_LABEL_MAX_WIDTH_ALIGN)
{
}

View File

@ -13,6 +13,7 @@ namespace Dawn {
class HelloWorldScene : public Scene {
protected:
Camera *camera;
Camera *camNew;
UICanvas *canvas;
Texture text;
@ -25,6 +26,10 @@ namespace Dawn {
camera->fov = 0.436332f;
camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));
camNew = Camera::create(this);
camNew->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));
camNew->renderTarget = nullptr;
auto cube = SimpleSpinningCubePrefab::create(this);
auto textbox = VNTextbox::create(this);