Fixed non-power-of-2 images in SatCom (closes #634); fixed not unloading textures on SatCom close

master
krzys-h 2016-04-10 13:53:34 +02:00
parent dd8a324f9b
commit 952a5423fd
2 changed files with 23 additions and 20 deletions

View File

@ -1127,25 +1127,41 @@ void CEdit::Draw()
// Draw an image part. // Draw an image part.
std::string PrepareImageFilename(std::string name)
{
std::string filename;
filename = name + ".png";
filename = InjectLevelPathsForCurrentLevel(filename, "icons");
boost::replace_all(filename, "\\", "/"); // TODO: Fix this in files
return filename;
}
void CEdit::DrawImage(Math::Point pos, std::string name, float width, void CEdit::DrawImage(Math::Point pos, std::string name, float width,
float offset, float height, int nbLine) float offset, float height, int nbLine)
{ {
Math::Point uv1, uv2, dim; Math::Point uv1, uv2, dim;
float dp; float dp;
std::string filename;
filename = name + ".png";
filename = InjectLevelPathsForCurrentLevel(filename, "icons");
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
m_engine->SetTexture(filename);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
Gfx::TextureCreateParams params;
params.format = Gfx::TEX_IMG_AUTO;
params.filter = Gfx::TEX_FILTER_BILINEAR;
params.padToNearestPowerOfTwo = true;
Gfx::Texture tex = m_engine->LoadTexture(PrepareImageFilename(name), params);
m_engine->SetTexture(tex);
uv1.x = 0.0f; uv1.x = 0.0f;
uv2.x = 1.0f; uv2.x = 1.0f;
uv1.y = offset; uv1.y = offset;
uv2.y = offset+height; uv2.y = offset+height;
uv1.x *= static_cast<float>(tex.originalSize.x) / static_cast<float>(tex.size.x);
uv2.x *= static_cast<float>(tex.originalSize.x) / static_cast<float>(tex.size.x);
uv1.y *= static_cast<float>(tex.originalSize.y) / static_cast<float>(tex.size.y);
uv2.y *= static_cast<float>(tex.originalSize.y) / static_cast<float>(tex.size.y);
dp = 0.5f/256.0f; dp = 0.5f/256.0f;
uv1.x += dp; uv1.x += dp;
uv1.y += dp; uv1.y += dp;
@ -1415,21 +1431,10 @@ void CEdit::FreeImage()
{ {
for (auto& image : m_image) for (auto& image : m_image)
{ {
m_engine->DeleteTexture(image.name + ".png"); m_engine->DeleteTexture(PrepareImageFilename(image.name));
} }
} }
// Reads the texture of an image.
void CEdit::LoadImage(std::string name)
{
std::string filename;
filename = name + ".png";
filename = InjectLevelPathsForCurrentLevel(filename, "icons");
boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
m_engine->LoadTexture(filename);
}
// Read from a text file. // Read from a text file.
bool CEdit::ReadText(std::string filename, int addSize) bool CEdit::ReadText(std::string filename, int addSize)
@ -1632,7 +1637,6 @@ bool CEdit::ReadText(std::string filename, int addSize)
iWidth = static_cast<float>(GetValueParam(buffer.data()+i+7, 1)); iWidth = static_cast<float>(GetValueParam(buffer.data()+i+7, 1));
iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL); iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL);
iLines = GetValueParam(buffer.data()+i+7, 2); iLines = GetValueParam(buffer.data()+i+7, 2);
LoadImage(std::string(iName));
// A part of image per line of text. // A part of image per line of text.
for ( iCount=0 ; iCount<iLines ; iCount++ ) for ( iCount=0 ; iCount<iLines ; iCount++ )

View File

@ -201,7 +201,6 @@ protected:
void DrawColor(Math::Point pos, Math::Point dim, Gfx::Color color); void DrawColor(Math::Point pos, Math::Point dim, Gfx::Color color);
void FreeImage(); void FreeImage();
void LoadImage(std::string name);
void Scroll(int pos, bool bAdjustCursor); void Scroll(int pos, bool bAdjustCursor);
void Scroll(); void Scroll();
void MoveChar(int move, bool bWord, bool bSelect); void MoveChar(int move, bool bWord, bool bSelect);