From 79fbf0faf74b580e185c20ae8ee93bbc8f31d396 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 25 Mar 2014 10:32:34 +0100 Subject: [PATCH] Support drawing textures without doing any clipping. --- src/character.cpp | 2 +- src/texture.cpp | 30 ++++++++++++++++++++++++------ src/texture.hpp | 4 ++-- src/tiledwallpaper.cpp | 3 ++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index aa3250e..0e763a1 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -68,6 +68,6 @@ namespace cloonel { ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- void Character::Draw() const { - m_texture->Render(GetPos(), WidthHeight(), m_screenRatio.Ratio()); + m_texture->Render(GetPos(), WidthHeight(), m_screenRatio.Ratio(), true); } } //namespace cloonel diff --git a/src/texture.cpp b/src/texture.cpp index 5d3379b..443b30c 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -107,6 +107,9 @@ namespace cloonel { GraphicFormat GuessGraphicFormatFromName (const std::string& parPath) __attribute__((pure)); bool ClipRect ( RectFloat& parSrc, RectFloat& parDest, const RectFloat& parClip ); +#if !defined(NDEBUG) + bool IsRectCompletelyInsideRect ( const RectFloat& parInner, const RectFloat& parOuter ) __attribute__((pure)); +#endif ///---------------------------------------------------------------------- ///---------------------------------------------------------------------- @@ -288,6 +291,14 @@ namespace cloonel { assert(parDest.IsValid()); return true; } + +#if !defined(NDEBUG) + ///---------------------------------------------------------------------- + ///---------------------------------------------------------------------- + bool IsRectCompletelyInsideRect (const RectFloat& parInner, const RectFloat& parOuter) { + return parInner.from >= parOuter.from and parInner.to <= parOuter.to; + } +#endif } //unnamed namespace ///-------------------------------------------------------------------------- @@ -347,7 +358,7 @@ namespace cloonel { ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- - void Texture::Render (const float2& parPos, const float2& parSize, const float2& parScaling) const { + void Texture::Render (const float2& parPos, const float2& parSize, const float2& parScaling, bool parClip) const { assert(IsLoaded()); const float2 pos(parPos * parScaling); @@ -355,13 +366,20 @@ namespace cloonel { RectFloat dest(pos, pos + siz); RectFloat src(float2(0.0f), m_size); - const RectFloat clip(float2(0.0f), static_cast(m_sdlmain->WidthHeight())); - const bool visible = ClipRect(src, dest, clip); - if (not visible) - return; + if (parClip) { + const RectFloat clip(float2(0.0f), static_cast(m_sdlmain->WidthHeight())); + const bool visible = ClipRect(src, dest, clip); + if (not visible) + return; + } +#if !defined(NDEBUG) + else { + const RectFloat clip(float2(0.0f), static_cast(m_sdlmain->WidthHeight())); + assert(IsRectCompletelyInsideRect(dest, clip)); + } +#endif const SDL_Rect sdlsrc(src); - //std::cout << "src = " << src.from << " - " << src.to << ", size is " << m_size << "\n"; SDL_Rect sdldst(dest); sdldst.y = m_sdlmain->WidthHeight().y() - sdldst.y - sdldst.h; diff --git a/src/texture.hpp b/src/texture.hpp index 4c1477e..73534b5 100644 --- a/src/texture.hpp +++ b/src/texture.hpp @@ -36,8 +36,8 @@ namespace cloonel { void Reload ( void ); void Destroy ( void ) noexcept; bool IsLoaded ( void ) const { return nullptr != m_texture; } - void Render ( const float2& parPos, const float2& parScaling ) const { Render(parPos, m_size, parScaling); } - void Render ( const float2& parPos, const float2& parSize, const float2& parScaling ) const; + void Render ( const float2& parPos, const float2& parScaling, bool parClip ) const { Render(parPos, m_size, parScaling, parClip); } + void Render ( const float2& parPos, const float2& parSize, const float2& parScaling, bool parClip ) const; const SDLMain* SDLObject ( void ) const { return m_sdlmain; } private: diff --git a/src/tiledwallpaper.cpp b/src/tiledwallpaper.cpp index cd92b3b..21c13f3 100644 --- a/src/tiledwallpaper.cpp +++ b/src/tiledwallpaper.cpp @@ -67,12 +67,13 @@ namespace cloonel { const ushort2 grid(static_cast(m_tileCount.tileCount())); const float2& sz = m_tileCount.tileSize(); + //TODO: add code to tell the renderer if the current tile will need clipping or not float2 dest; dest.y() = 0.0f; for (uint16_t y = 0; y < grid.y(); ++y) { dest.x() = 0.0f; for (uint16_t x = 0; x < grid.x(); ++x) { - m_tile->Render(dest, sz, float2(1.0f)); + m_tile->Render(dest, sz, float2(1.0f), true); dest.x() += sz.x(); } dest.y() += sz.y();