New textures
This commit is contained in:
@ -10,34 +10,15 @@ using namespace Dawn;
|
||||
CameraTexture::CameraTexture(SceneItem *item) :
|
||||
SceneItemComponent(item),
|
||||
camera(nullptr),
|
||||
renderTarget(32.0f, 32.0f),
|
||||
updateOrtho(true)
|
||||
renderTarget(32.0f, 32.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void CameraTexture::onStart() {
|
||||
if(this->camera == nullptr) this->camera = item->getComponent<Camera>();
|
||||
|
||||
auto effectCamera = [&]{
|
||||
if(this->camera == nullptr) return teardown = [&]{};
|
||||
useEffect([&]{
|
||||
if(this->camera == nullptr) return;
|
||||
this->camera->renderTarget = &this->renderTarget;
|
||||
|
||||
if(!this->updateOrtho) return teardown = [&]{};
|
||||
|
||||
this->updateOrthoValues();
|
||||
return teardown = useEvent([&](float_t w, float_t h){
|
||||
this->updateOrthoValues();
|
||||
}, this->camera->eventRenderTargetResized);
|
||||
};
|
||||
|
||||
useEffectWithTeardown(effectCamera, this->camera);
|
||||
useEffectWithTeardown(effectCamera, this->updateOrtho)();
|
||||
}
|
||||
|
||||
void CameraTexture::updateOrthoValues() {
|
||||
assertNotNull(this->camera);
|
||||
float_t wr = this->camera->renderTarget->getWidth() / this->camera->renderTarget->getHeight();
|
||||
wr *= 0.5f;//TODO: allow this to be editable
|
||||
this->camera->orthoLeft = -wr;
|
||||
this->camera->orthoRight = wr;
|
||||
}, camera)();
|
||||
}
|
@ -9,22 +9,12 @@
|
||||
|
||||
namespace Dawn {
|
||||
class CameraTexture : public SceneItemComponent {
|
||||
protected:
|
||||
std::function<void()> teardown;
|
||||
|
||||
void updateOrthoValues();
|
||||
|
||||
public:
|
||||
// @optional
|
||||
StateProperty<Camera*> camera;
|
||||
|
||||
// @optional
|
||||
StateProperty<bool_t> updateOrtho;
|
||||
|
||||
TextureRenderTarget renderTarget;
|
||||
|
||||
CameraTexture(SceneItem *item);
|
||||
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
@ -10,20 +10,16 @@ using namespace Dawn;
|
||||
|
||||
PixelPerfectCamera::PixelPerfectCamera(SceneItem *i) :
|
||||
SceneItemComponent(i),
|
||||
scale(1.0f)
|
||||
scale(1.0f),
|
||||
camera(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::vector<SceneItemComponent*> PixelPerfectCamera::getDependencies() {
|
||||
return std::vector<SceneItemComponent*>{
|
||||
(this->camera = this->item->getComponent<Camera>())
|
||||
};
|
||||
}
|
||||
|
||||
void PixelPerfectCamera::updateDimensions() {
|
||||
if(this->camera == nullptr) return;
|
||||
|
||||
float_t w, h;
|
||||
assertNotNull(this->camera);
|
||||
|
||||
auto target = this->camera->getRenderTarget();
|
||||
switch(this->camera->type) {
|
||||
@ -52,14 +48,23 @@ void PixelPerfectCamera::updateDimensions() {
|
||||
}
|
||||
|
||||
void PixelPerfectCamera::onStart() {
|
||||
assertNotNull(this->camera);
|
||||
this->updateDimensions();
|
||||
|
||||
useEvent([&](float_t w, float_t h){
|
||||
this->updateDimensions();
|
||||
}, this->camera->eventRenderTargetResized);
|
||||
|
||||
if(camera == nullptr) camera = item->getComponent<Camera>();
|
||||
|
||||
useEffect([&]{
|
||||
this->updateDimensions();
|
||||
}, scale);
|
||||
|
||||
useEffectWithTeardown([&]{
|
||||
if(!camera) {
|
||||
return teardown = [&]{};
|
||||
}
|
||||
|
||||
this->updateDimensions();
|
||||
|
||||
return teardown = [&]{
|
||||
useEvent([&](float_t w, float_t h){
|
||||
this->updateDimensions();
|
||||
}, this->camera->eventRenderTargetResized);
|
||||
};
|
||||
}, camera)();
|
||||
}
|
@ -9,14 +9,17 @@
|
||||
namespace Dawn {
|
||||
class PixelPerfectCamera : public SceneItemComponent {
|
||||
protected:
|
||||
Camera *camera = nullptr;
|
||||
|
||||
std::function<void()> teardown;
|
||||
|
||||
/**
|
||||
* Updates the underlying camera's projection information.
|
||||
*/
|
||||
void updateDimensions();
|
||||
|
||||
public:
|
||||
// @optional
|
||||
StateProperty<Camera*> camera;
|
||||
|
||||
// @optional
|
||||
StateProperty<float_t> scale;
|
||||
|
||||
@ -27,7 +30,6 @@ namespace Dawn {
|
||||
*/
|
||||
PixelPerfectCamera(SceneItem *item);
|
||||
|
||||
std::vector<SceneItemComponent*> getDependencies() override;
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user