From 8fc7942d643f5ed67226406634f6a77cb4024de4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 1 Mar 2017 18:57:51 +0100 Subject: [PATCH] Refactor osgMyGUI::OSGTexture to store width/height inside the object --- components/myguiplatform/myguitexture.cpp | 20 ++++++++++++++------ components/myguiplatform/myguitexture.hpp | 3 +++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/components/myguiplatform/myguitexture.cpp b/components/myguiplatform/myguitexture.cpp index 85ff3e3b5..e8fd81bfe 100644 --- a/components/myguiplatform/myguitexture.cpp +++ b/components/myguiplatform/myguitexture.cpp @@ -16,6 +16,8 @@ namespace osgMyGUI , mFormat(MyGUI::PixelFormat::Unknow) , mUsage(MyGUI::TextureUsage::Default) , mNumElemBytes(0) + , mWidth(0) + , mHeight(0) { } @@ -25,6 +27,8 @@ namespace osgMyGUI , mFormat(MyGUI::PixelFormat::Unknow) , mUsage(MyGUI::TextureUsage::Default) , mNumElemBytes(0) + , mWidth(texture->getTextureWidth()) + , mHeight(texture->getTextureHeight()) { } @@ -63,6 +67,9 @@ namespace osgMyGUI mTexture->setSourceFormat(glfmt); mTexture->setSourceType(GL_UNSIGNED_BYTE); + mWidth = width; + mHeight = height; + mTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); mTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); mTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); @@ -79,6 +86,8 @@ namespace osgMyGUI mFormat = MyGUI::PixelFormat::Unknow; mUsage = MyGUI::TextureUsage::Default; mNumElemBytes = 0; + mWidth = 0; + mHeight = 0; } void OSGTexture::loadFromFile(const std::string &fname) @@ -95,6 +104,9 @@ namespace osgMyGUI // disable mip-maps mTexture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); + mWidth = image->s(); + mHeight = image->t(); + // FIXME mFormat = MyGUI::PixelFormat::R8G8B8; mUsage = MyGUI::TextureUsage::Static | MyGUI::TextureUsage::Write; @@ -108,16 +120,12 @@ namespace osgMyGUI int OSGTexture::getWidth() { - if(!mTexture.valid()) - return 0; - return mTexture->getTextureWidth(); + return mWidth; } int OSGTexture::getHeight() { - if(!mTexture.valid()) - return 0; - return mTexture->getTextureHeight(); + return mHeight; } void *OSGTexture::lock(MyGUI::TextureUsage /*access*/) diff --git a/components/myguiplatform/myguitexture.hpp b/components/myguiplatform/myguitexture.hpp index 101e2135b..48f2ed265 100644 --- a/components/myguiplatform/myguitexture.hpp +++ b/components/myguiplatform/myguitexture.hpp @@ -29,6 +29,9 @@ namespace osgMyGUI MyGUI::TextureUsage mUsage; size_t mNumElemBytes; + int mWidth; + int mHeight; + public: OSGTexture(const std::string &name, Resource::ImageManager* imageManager); OSGTexture(osg::Texture2D* texture);