OffscreenRenderTarget.cpp
OffscreenRenderTarget.cpp
CPP1/* Copyright Statement:2 *3 * (C) 2021-2024 Cubios Inc. All rights reserved.4 */56#include "OffscreenRenderTarget.h"7#include "SceneObject.h"89namespace Cubios10{11namespace Gfx12{13int16_t OffscreenRenderTarget::rtc = 0;1415OffscreenRenderTarget::OffscreenRenderTarget(u32_t w, u32_t h, Cubios::GFX_PixelFormat_t f):inBegin(false),width(w),height(h),format(f)16{17 this->rtID = this->getNextID();18 this->Color.Set(255,0,255);19 this->nullScreen = new Cubios::Screen(0);20}2122OffscreenRenderTarget::~OffscreenRenderTarget()23{24 if(this->nullScreen)25 {26 delete this->nullScreen;27 Cubios::GFX_removeBakedImage(this->rtID);28 }29}3031Cubios::SceneObject* OffscreenRenderTarget::Add(Cubios::SceneObject* obj)32{33 if(!this->inBegin)34 {35 LOG_w("OffscreenRenderTarget:Scene objects can only be added within Begin/End block!\n");36 obj->Parent = nullptr;37 return obj;38 }39 if(!obj->Visible) return obj;4041 obj->Parent = this->nullScreen;42 obj->InBegin = this->inBegin;4344 obj->ScreenAngle = 0;4546 this->objects.push_back(obj);4748 return obj;49}5051SceneObject* OffscreenRenderTarget::AddCopy(SceneObject* obj)52{53 SceneObject* object = this->Add(obj);5455 if(object!=nullptr)56 {57 this->copies.push_back(object);58 }5960 return object;61}6263void OffscreenRenderTarget::Begin(bool overwrite)64{65 this->inBegin = true;66 this->objects.clear();6768 Cubios::GFX_bakeImage(this->rtID, this->width, this->height, this->format, (u32_t)overwrite);69}7071void OffscreenRenderTarget::End()72{73 this->inBegin = false;74 this->present();7576 for(size_t i=0;i<this->copies.size();i++)77 {78 delete this->copies[i];79 }80 this->copies.clear();81}8283void OffscreenRenderTarget::present()84{85 this->RenderLayer(renderLayerOrder_t::BeforeQueue);8687 for(auto obj: objects)88 {89 obj->Render();90 obj->InBegin = this->inBegin;91 }9293 this->RenderLayer(renderLayerOrder_t::AfterQueue);9495 Cubios::GFX_render();96}9798void OffscreenRenderTarget::Render()99{100 Math::Vec2 pos = this->ScreenPosition();101 Cubios::GFX_drawBakedImage(pos.X, pos.Y, Color.A(), Color.Value(), Transform.ScaleX, Transform.ScaleY, Transform.SafeRotation()+ScreenAngle, Transform.Mirroring, this->rtID);102}103}104}105
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.