From dcbfd5cc35f9e767ae29b3f77e42df7b5b5c05bb Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Tue, 10 Oct 2017 18:28:09 +0200 Subject: [PATCH] Add a method to create an empty texture --- src/pixmap.cxx | 47 +++++++++++++++++++++++++++++++++++++++++++++-- src/pixmap.h | 1 + 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/pixmap.cxx b/src/pixmap.cxx index ae9f029..3f01276 100644 --- a/src/pixmap.cxx +++ b/src/pixmap.cxx @@ -212,14 +212,57 @@ CPixmap::ReloadTargetTextures () if (!tex.second.target) continue; - if (!Cache ( - tex.first, tex.second.file, tex.second.dimTotal, tex.second.dimIcon)) + if (tex.second.file.empty ()) + { + if (!Cache (tex.first, tex.second.dimTotal)) + return false; + } + else if (!Cache ( + tex.first, tex.second.file, tex.second.dimTotal, + tex.second.dimIcon)) return false; } return true; } +bool +CPixmap::Cache (size_t channel, Point totalDim) +{ + if (m_SDLTextureInfo.find (channel) == m_SDLTextureInfo.end ()) + { + m_SDLTextureInfo[channel].texture = SDL_CreateTexture ( + g_renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, totalDim.x, + totalDim.y); + + if (!m_SDLTextureInfo[channel].texture) + { + SDL_LogError ( + SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s", + SDL_GetError ()); + return false; + } + + SDL_SetTextureBlendMode ( + m_SDLTextureInfo[channel].texture, SDL_BLENDMODE_BLEND); + } + else + { + SDL_SetRenderTarget (g_renderer, m_SDLTextureInfo[channel].texture); + SDL_SetRenderDrawColor (g_renderer, 0, 0, 0, 0); + SDL_RenderClear (g_renderer); + SDL_SetRenderTarget (g_renderer, nullptr); + } + + m_SDLTextureInfo[channel].texMask = nullptr; + m_SDLTextureInfo[channel].target = true; + m_SDLTextureInfo[channel].dimIcon = Point{0, 0}; + m_SDLTextureInfo[channel].dimTotal = totalDim; + m_SDLTextureInfo[channel].file = ""; + + return true; +} + // Cache une image contenant des ic�nes. bool diff --git a/src/pixmap.h b/src/pixmap.h index 0777281..758f210 100644 --- a/src/pixmap.h +++ b/src/pixmap.h @@ -56,6 +56,7 @@ public: bool Create (Point dim); bool ReloadTargetTextures (); + bool Cache (size_t channel, Point totalDim); bool Cache ( size_t channel, const std::string & pFilename, Point totalDim, Point iconDim);