Add ManualResourceLoader for character previews (Fixes #1752)

deque
scrawl 11 years ago
parent 0b1e997bdd
commit c6bf9dfbfb

@ -91,6 +91,13 @@ namespace MWGui
mTradeModel = new TradeItemModel(new InventoryItemModel(mPtr), MWWorld::Ptr());
mSortModel = new SortFilterItemModel(mTradeModel);
mItemView->setModel(mSortModel);
mPreview.reset(NULL);
mAvatarImage->setImageTexture("");
MyGUI::ITexture* tex = MyGUI::RenderManager::getInstance().getTexture("CharacterPreview");
if (tex)
MyGUI::RenderManager::getInstance().destroyTexture(tex);
mPreview.reset(new MWRender::InventoryPreview(mPtr));
mPreview->setup();
}

@ -83,19 +83,10 @@ namespace MWRender
mCamera->setNearClipDistance (0.01);
mCamera->setFarClipDistance (1000);
mTexture = Ogre::TextureManager::getSingleton().getByName (mName);
if (mTexture.isNull ())
mTexture = Ogre::TextureManager::getSingleton().createManual(mName,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mSizeX, mSizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
mTexture = Ogre::TextureManager::getSingleton().createManual(mName,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mSizeX, mSizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET, this);
mRenderTarget = mTexture->getBuffer()->getRenderTarget();
mRenderTarget->removeAllViewports ();
mViewport = mRenderTarget->addViewport(mCamera);
mViewport->setOverlaysEnabled(false);
mViewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0));
mViewport->setShadowsEnabled(false);
mRenderTarget->setActive(true);
mRenderTarget->setAutoUpdated (false);
setupRenderTarget();
onSetup ();
}
@ -107,6 +98,7 @@ namespace MWRender
mSceneMgr->destroyAllCameras();
delete mAnimation;
Ogre::Root::getSingleton().destroySceneManager(mSceneMgr);
Ogre::TextureManager::getSingleton().remove(mName);
}
}
@ -127,12 +119,39 @@ namespace MWRender
onSetup();
}
void CharacterPreview::loadResource(Ogre::Resource *resource)
{
Ogre::Texture* tex = dynamic_cast<Ogre::Texture*>(resource);
if (!tex)
return;
tex->createInternalResources();
setupRenderTarget();
mRenderTarget->update();
}
void CharacterPreview::setupRenderTarget()
{
mRenderTarget = mTexture->getBuffer()->getRenderTarget();
mRenderTarget->removeAllViewports ();
mViewport = mRenderTarget->addViewport(mCamera);
mViewport->setOverlaysEnabled(false);
mViewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0));
mViewport->setShadowsEnabled(false);
mRenderTarget->setActive(true);
mRenderTarget->setAutoUpdated (false);
}
// --------------------------------------------------------------------------------------------------
InventoryPreview::InventoryPreview(MWWorld::Ptr character)
: CharacterPreview(character, 512, 1024, "CharacterPreview", Ogre::Vector3(0, 65, -180), Ogre::Vector3(0,65,0))
, mSelectionBuffer(NULL)
, mSizeX(0)
, mSizeY(0)
{
}
@ -143,6 +162,9 @@ namespace MWRender
void InventoryPreview::update(int sizeX, int sizeY)
{
mSizeX = sizeX;
mSizeY = sizeY;
mAnimation->updateParts();
MWWorld::InventoryStore &inv = mCharacter.getClass().getInventoryStore(mCharacter);
@ -197,15 +219,21 @@ namespace MWRender
mAnimation->runAnimation(0.0f);
mViewport->setDimensions (0, 0, std::min(1.f, float(sizeX) / float(512)), std::min(1.f, float(sizeY) / float(1024)));
mNode->setOrientation (Ogre::Quaternion::IDENTITY);
mViewport->setDimensions (0, 0, std::min(1.f, float(mSizeX) / float(512)), std::min(1.f, float(mSizeY) / float(1024)));
mTexture->load();
mRenderTarget->update();
mSelectionBuffer->update();
}
void InventoryPreview::setupRenderTarget()
{
CharacterPreview::setupRenderTarget();
mViewport->setDimensions (0, 0, std::min(1.f, float(mSizeX) / float(512)), std::min(1.f, float(mSizeY) / float(1024)));
}
int InventoryPreview::getSlotSelected (int posX, int posY)
{
return mSelectionBuffer->getSelected (posX, posY);
@ -243,6 +271,7 @@ namespace MWRender
void RaceSelectionPreview::render()
{
mTexture->load();
mRenderTarget->update();
}

@ -22,7 +22,7 @@ namespace MWRender
class NpcAnimation;
class CharacterPreview
class CharacterPreview : public Ogre::ManualResourceLoader
{
public:
CharacterPreview(MWWorld::Ptr character, int sizeX, int sizeY, const std::string& name,
@ -34,6 +34,8 @@ namespace MWRender
virtual void rebuild();
void loadResource(Ogre::Resource *resource);
private:
CharacterPreview(const CharacterPreview&);
CharacterPreview& operator=(const CharacterPreview&);
@ -41,6 +43,8 @@ namespace MWRender
protected:
virtual bool renderHeadOnly() { return false; }
virtual void setupRenderTarget();
Ogre::TexturePtr mTexture;
Ogre::RenderTarget* mRenderTarget;
Ogre::Viewport* mViewport;
@ -76,7 +80,12 @@ namespace MWRender
int getSlotSelected(int posX, int posY);
protected:
virtual void setupRenderTarget();
private:
int mSizeX;
int mSizeY;
OEngine::Render::SelectionBuffer* mSelectionBuffer;
};

@ -18,22 +18,42 @@ namespace Render
{
SelectionBuffer::SelectionBuffer(Ogre::Camera *camera, int sizeX, int sizeY, int visibilityFlags)
: mCamera(camera)
, mVisibilityFlags(visibilityFlags)
{
mTexture = Ogre::TextureManager::getSingleton().createManual("SelectionBuffer",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, sizeX, sizeY, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, sizeX, sizeY, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET, this);
setupRenderTarget();
mCurrentColour = Ogre::ColourValue(0.3, 0.3, 0.3);
}
void SelectionBuffer::setupRenderTarget()
{
mRenderTarget = mTexture->getBuffer()->getRenderTarget();
Ogre::Viewport* vp = mRenderTarget->addViewport(camera);
Ogre::Viewport* vp = mRenderTarget->addViewport(mCamera);
vp->setOverlaysEnabled(false);
vp->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0));
vp->setShadowsEnabled(false);
vp->setMaterialScheme("selectionbuffer");
if (visibilityFlags != 0)
vp->setVisibilityMask (visibilityFlags);
if (mVisibilityFlags != 0)
vp->setVisibilityMask (mVisibilityFlags);
mRenderTarget->setActive(true);
mRenderTarget->setAutoUpdated (false);
}
mCurrentColour = Ogre::ColourValue(0.3, 0.3, 0.3);
void SelectionBuffer::loadResource(Ogre::Resource *resource)
{
Ogre::Texture* tex = dynamic_cast<Ogre::Texture*>(resource);
if (!tex)
return;
tex->createInternalResources();
setupRenderTarget();
mRenderTarget->update();
}
SelectionBuffer::~SelectionBuffer()

@ -20,7 +20,7 @@ namespace Render
}
};
class SelectionBuffer : public Ogre::MaterialManager::Listener
class SelectionBuffer : public Ogre::MaterialManager::Listener, public Ogre::ManualResourceLoader
{
public:
SelectionBuffer(Ogre::Camera* camera, int sizeX, int sizeY, int visibilityFlags);
@ -31,6 +31,8 @@ namespace Render
void update();
virtual void loadResource(Ogre::Resource* resource);
virtual Ogre::Technique* handleSchemeNotFound (
unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial,
unsigned short lodIndex, const Ogre::Renderable *rend);
@ -46,7 +48,12 @@ namespace Render
Ogre::ColourValue mCurrentColour;
Ogre::Camera* mCamera;
int mVisibilityFlags;
void getNextColour();
void setupRenderTarget();
};
}

Loading…
Cancel
Save