Added texture data format support
This commit is contained in:
@ -13,10 +13,10 @@ Camera::Camera(SceneItem *item) :
|
||||
renderTarget(item->scene->game->renderManager.getBackBuffer()),
|
||||
fov(0.785398f),// 45 degrees,
|
||||
type(CAMERA_TYPE_PERSPECTIVE),
|
||||
orthoLeft(0.0f),
|
||||
orthoRight(1.0f),
|
||||
orthoBottom(0.0f),
|
||||
orthoTop(1.0f),
|
||||
orthoLeft(-0.5f),
|
||||
orthoRight(0.5f),
|
||||
orthoBottom(-0.5f),
|
||||
orthoTop(0.5f),
|
||||
clipNear(0.001f),
|
||||
clipFar(1000.0f)
|
||||
{
|
||||
|
@ -10,15 +10,34 @@ using namespace Dawn;
|
||||
CameraTexture::CameraTexture(SceneItem *item) :
|
||||
SceneItemComponent(item),
|
||||
camera(nullptr),
|
||||
renderTarget(32.0f, 32.0f)
|
||||
renderTarget(32.0f, 32.0f),
|
||||
updateOrtho(true)
|
||||
{
|
||||
}
|
||||
|
||||
void CameraTexture::onStart() {
|
||||
if(this->camera == nullptr) this->camera = item->getComponent<Camera>();
|
||||
|
||||
useEffect([&]{
|
||||
if(this->camera == nullptr) return;
|
||||
auto effectCamera = [&]{
|
||||
if(this->camera == nullptr) return teardown = [&]{};
|
||||
this->camera->renderTarget = &this->renderTarget;
|
||||
}, this->camera)();
|
||||
|
||||
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;
|
||||
}
|
@ -10,9 +10,17 @@
|
||||
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);
|
||||
|
@ -55,11 +55,11 @@ void TiledSprite::onStart() {
|
||||
if(this->meshHost == nullptr || this->tileset == nullptr) return;
|
||||
auto tile = this->tileset->getTile(this->tile);
|
||||
|
||||
glm::vec2 size;
|
||||
glm::vec2 quadSize;
|
||||
|
||||
switch(this->sizeType) {
|
||||
case TILED_SPRITE_SIZE_TYPE_SCALE: {
|
||||
size = glm::vec2(
|
||||
quadSize = glm::vec2(
|
||||
this->tileset->getTileWidth(this->tile),
|
||||
this->tileset->getTileHeight(this->tile)
|
||||
) * (float_t)this->size;
|
||||
@ -68,15 +68,15 @@ void TiledSprite::onStart() {
|
||||
|
||||
case TILED_SPRITE_SIZE_TYPE_WIDTH_RATIO: {
|
||||
float_t rw = this->tileset->getTileHeight(this->tile) / this->tileset->getTileWidth(this->tile);
|
||||
size.x = (float_t)this->size;
|
||||
size.y = size.x * rw;
|
||||
quadSize.x = (float_t)this->size;
|
||||
quadSize.y = quadSize.x * rw;
|
||||
break;
|
||||
}
|
||||
|
||||
case TILED_SPRITE_SIZE_TYPE_HEIGHT_RATIO: {
|
||||
float_t rh = this->tileset->getTileWidth(this->tile) / this->tileset->getTileHeight(this->tile);
|
||||
size.y = (float_t)this->size;
|
||||
size.x = size.y * rh;
|
||||
quadSize.y = (float_t)this->size;
|
||||
quadSize.x = quadSize.y * rh;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -84,8 +84,8 @@ void TiledSprite::onStart() {
|
||||
assertUnreachable();
|
||||
}
|
||||
|
||||
this->meshHost->xy0 = -size;
|
||||
this->meshHost->xy1 = size;
|
||||
this->meshHost->xy0 = -quadSize;
|
||||
this->meshHost->xy1 = quadSize;
|
||||
}, {
|
||||
&this->tile,
|
||||
&this->meshHost,
|
||||
|
Reference in New Issue
Block a user