diff --git a/src/dawn/scene/components/display/CameraTexture.cpp b/src/dawn/scene/components/display/CameraTexture.cpp index 15a28d91..cdbf4437 100644 --- a/src/dawn/scene/components/display/CameraTexture.cpp +++ b/src/dawn/scene/components/display/CameraTexture.cpp @@ -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(); - 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)(); } \ No newline at end of file diff --git a/src/dawn/scene/components/display/CameraTexture.hpp b/src/dawn/scene/components/display/CameraTexture.hpp index 3a92ced0..42e01275 100644 --- a/src/dawn/scene/components/display/CameraTexture.hpp +++ b/src/dawn/scene/components/display/CameraTexture.hpp @@ -9,22 +9,12 @@ namespace Dawn { class CameraTexture : public SceneItemComponent { - protected: - std::function teardown; - - void updateOrthoValues(); - public: // @optional StateProperty camera; - - // @optional - StateProperty updateOrtho; - TextureRenderTarget renderTarget; CameraTexture(SceneItem *item); - void onStart() override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/display/PixelPerfectCamera.cpp b/src/dawn/scene/components/display/PixelPerfectCamera.cpp index afba4121..ab0ccfb2 100644 --- a/src/dawn/scene/components/display/PixelPerfectCamera.cpp +++ b/src/dawn/scene/components/display/PixelPerfectCamera.cpp @@ -10,20 +10,16 @@ using namespace Dawn; PixelPerfectCamera::PixelPerfectCamera(SceneItem *i) : SceneItemComponent(i), - scale(1.0f) + scale(1.0f), + camera(nullptr) { } -std::vector PixelPerfectCamera::getDependencies() { - return std::vector{ - (this->camera = this->item->getComponent()) - }; -} - 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(); + 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)(); } \ No newline at end of file diff --git a/src/dawn/scene/components/display/PixelPerfectCamera.hpp b/src/dawn/scene/components/display/PixelPerfectCamera.hpp index e8949af0..6ba7ee59 100644 --- a/src/dawn/scene/components/display/PixelPerfectCamera.hpp +++ b/src/dawn/scene/components/display/PixelPerfectCamera.hpp @@ -9,14 +9,17 @@ namespace Dawn { class PixelPerfectCamera : public SceneItemComponent { protected: - Camera *camera = nullptr; - + std::function teardown; + /** * Updates the underlying camera's projection information. */ void updateDimensions(); public: + // @optional + StateProperty camera; + // @optional StateProperty scale; @@ -27,7 +30,6 @@ namespace Dawn { */ PixelPerfectCamera(SceneItem *item); - std::vector getDependencies() override; void onStart() override; }; } \ No newline at end of file diff --git a/src/dawnopengl/display/Texture.cpp b/src/dawnopengl/display/Texture.cpp index 64f3c1e6..40a7fc2a 100644 --- a/src/dawnopengl/display/Texture.cpp +++ b/src/dawnopengl/display/Texture.cpp @@ -122,34 +122,36 @@ void Texture::updateTextureProperties() { ) { switch(filter) { case TEXTURE_FILTER_MODE_NEAREST: { - switch(mapFilterMode) { - case TEXTURE_FILTER_MODE_NEAREST: - glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST_MIPMAP_NEAREST); - break; + glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST); + // switch(mapFilterMode) { + // case TEXTURE_FILTER_MODE_NEAREST: + // glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST_MIPMAP_NEAREST); + // break; - case TEXTURE_FILTER_MODE_LINEAR: - glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR_MIPMAP_NEAREST); - break; + // case TEXTURE_FILTER_MODE_LINEAR: + // glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR_MIPMAP_NEAREST); + // break; - default: - assertUnreachable(); - } + // default: + // assertUnreachable(); + // } break; } case TEXTURE_FILTER_MODE_LINEAR: { - switch(mapFilterMode) { - case TEXTURE_FILTER_MODE_NEAREST: - glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST_MIPMAP_LINEAR); - break; + glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR); + // switch(mapFilterMode) { + // case TEXTURE_FILTER_MODE_NEAREST: + // glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST_MIPMAP_LINEAR); + // break; - case TEXTURE_FILTER_MODE_LINEAR: - glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR_MIPMAP_LINEAR); - break; + // case TEXTURE_FILTER_MODE_LINEAR: + // glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR_MIPMAP_LINEAR); + // break; - default: - assertUnreachable(); - } + // default: + // assertUnreachable(); + // } break; } diff --git a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp index 801eeaa6..f74235bd 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp +++ b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp @@ -38,7 +38,6 @@ std::vector SimpleTexturedMaterial::getRenderPasses(IRend onlyPass.renderFlags = ( RENDER_MANAGER_RENDER_FLAG_BLEND - // RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST ); if(this->texture != nullptr) { diff --git a/src/dawntools/texturetool/TextureTool.cpp b/src/dawntools/texturetool/TextureTool.cpp index 7d129010..a01da438 100644 --- a/src/dawntools/texturetool/TextureTool.cpp +++ b/src/dawntools/texturetool/TextureTool.cpp @@ -17,7 +17,11 @@ std::map TextureTool::getOptionalFlags() { { "wrapY", "clamp" }, { "filterMin", "linear" }, { "filterMax", "linear" }, - { "scale", "" } + { "scale", "" }, + { "scaleWrapX", "clamp" }, + { "scaleWrapY", "clamp" }, + { "scaleFilterX", "nearest" }, + { "scaleFilterY", "nearest" } }; } @@ -45,11 +49,22 @@ int32_t TextureTool::start() { size_t len = STBI_rgb_alpha * w * h; uint8_t *dataImage = (uint8_t*)malloc(sizeof(uint8_t) * len); + float_t scale = 1; if(!flags["scale"].empty()) { - float_t scale = std::stof(flags["scale"]); - stbir_resize_uint8(imageRaw, w, h, 0, dataImage, w * scale, h * scale, 0, STBI_rgb_alpha); + scale = std::stof(flags["scale"]); + } + + if(scale != 1) { + stbir_resize_uint8_generic( + imageRaw, w, h, 0, + dataImage, w * scale, h * scale, 0, + STBI_rgb_alpha, -1, 0, + STBIR_EDGE_CLAMP, STBIR_FILTER_TRIANGLE, STBIR_COLORSPACE_LINEAR, + NULL + ); w = w * scale; h = h * scale; + printf("Changing size to %ix%i\n", w, h); } else { memcpy(dataImage, imageRaw, len); } diff --git a/src/dawntools/util/CodeGen.cpp b/src/dawntools/util/CodeGen.cpp index a0d90dc6..5ea6518f 100644 --- a/src/dawntools/util/CodeGen.cpp +++ b/src/dawntools/util/CodeGen.cpp @@ -55,6 +55,11 @@ void CodeGen::classGen( } line(out, "namespace Dawn {", ""); + auto itTemplates = info.classTemplates.begin(); + while(itTemplates != info.classTemplates.end()) { + line(out, "template<" + itTemplates->second + " " + itTemplates->first + ">", " "); + ++itTemplates; + } line(out, "class " + info.clazz + (info.extend.size() == 0 ? "{" : " : public " + info.extend + " {" ), " "); if(info.protectedCode.size() > 0) { line(out, "protected:", " "); diff --git a/src/dawntools/util/CodeGen.hpp b/src/dawntools/util/CodeGen.hpp index 1bcc454c..1dcf9861 100644 --- a/src/dawntools/util/CodeGen.hpp +++ b/src/dawntools/util/CodeGen.hpp @@ -14,6 +14,8 @@ namespace Dawn { std::string constructorArgs = ""; std::string extendArgs = ""; + std::map classTemplates; + std::vector constructorCode; std::vector protectedCode;