Skip to content

Commit

Permalink
GRAPHICS: Clean up the MaterialManager a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Feb 11, 2014
1 parent fbb7318 commit 5ea8094
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 107 deletions.
6 changes: 3 additions & 3 deletions src/engines/nwn/gui/widgets/portrait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void Portrait::create(const Common::UString &name) {
_height = kHeight[_size];


_materialBorder = MaterialMan.createDynamic();
_materialBorder = MaterialMan.create();
MaterialMan.setColorModifier(_materialBorder, _bR, _bG, _bB, _bA);

setPortrait(name);
Expand Down Expand Up @@ -175,7 +175,7 @@ void Portrait::setPortrait(const Common::UString &name) {
}

if (!texture.isNull()) {
_materialPortrait = MaterialMan.createDynamic();
_materialPortrait = MaterialMan.create();

Ogre::TextureUnitState *texState = _materialPortrait->getTechnique(0)->getPass(0)->createTextureUnitState();

Expand All @@ -185,7 +185,7 @@ void Portrait::setPortrait(const Common::UString &name) {
_materialPortrait->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
_materialPortrait->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
} else
_materialPortrait = MaterialMan.getSolidColor(0.0, 0.0, 0.0, 1.0, true);
_materialPortrait = MaterialMan.create(0.0, 0.0, 0.0, 1.0, true);

if (_entityPortrait)
_entityPortrait->setMaterial(_materialPortrait);
Expand Down
13 changes: 1 addition & 12 deletions src/engines/nwn/gui/widgets/scrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ using Graphics::Aurora::kSelectableNone;
Scrollbar::Scrollbar(Type type) : Graphics::Renderable("gui"), _type(type),
_nodeCapLT(0), _nodeCapRB(0), _nodeBar(0), _entityCapLT(0), _entityCapRB(0), _entityBar(0), _length(16.0) {

_material = MaterialMan.get("gui_scrollbar");
_material = MaterialMan.create("gui_scrollbar");

create();
}
Expand Down Expand Up @@ -233,17 +233,6 @@ void Scrollbar::setSelectable(bool selectable) {
}

void Scrollbar::collectMaterials(std::list<Ogre::MaterialPtr> &materials, bool makeDynamic, bool makeTransparent) {
if (makeDynamic) {
_material = MaterialMan.makeDynamic(_material);

if (_entityCapLT)
_entityCapLT->setMaterial(_material);
if (_entityCapRB)
_entityCapRB->setMaterial(_material);
if (_entityBar)
_entityBar->setMaterial(_material);
}

if (makeTransparent)
MaterialMan.setTransparent(_material, true);

Expand Down
2 changes: 1 addition & 1 deletion src/graphics/aurora/abcfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Ogre::Entity *ABCFont::createCharacter(uint32 c, float &width, float &height, co
width = cC.spaceL + cC.width + cC.spaceR;
height = getHeight();

Ogre::MaterialPtr material = MaterialMan.createDynamic();
Ogre::MaterialPtr material = MaterialMan.create();

Ogre::TextureUnitState *texState = material->getTechnique(0)->getPass(0)->createTextureUnitState();

Expand Down
4 changes: 1 addition & 3 deletions src/graphics/aurora/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Cube::Cube(const Common::UString &texture, const Common::UString &scene) : Rende

_entity->getUserObjectBindings().setUserAny("renderable", Ogre::Any((Renderable *) this));

Ogre::MaterialPtr material = MaterialMan.get(texture);
Ogre::MaterialPtr material = MaterialMan.create(texture, true);

_entity->setMaterial(material);

Expand Down Expand Up @@ -189,8 +189,6 @@ void Cube::setSelectable(bool selectable) {

void Cube::collectMaterials(std::list<Ogre::MaterialPtr> &materials, bool makeDynamic, bool makeTransparent) {
Ogre::MaterialPtr material = _entity->getSubEntity(0)->getMaterial();
if (makeDynamic)
_entity->setMaterial((material = MaterialMan.makeDynamic(material)));

if (makeTransparent)
MaterialMan.setTransparent(material, true);
Expand Down
11 changes: 3 additions & 8 deletions src/graphics/aurora/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,8 @@ void Model::showBoundingBox(bool show) {
}

void Model::collectMaterials(std::list<Ogre::MaterialPtr> &materials, bool makeDynamic, bool makeTransparent) {
for (EntityList::iterator e = _entities.begin(); e != _entities.end(); ++e) {
Ogre::MaterialPtr material = (*e)->getSubEntity(0)->getMaterial();
if (makeDynamic)
(*e)->setMaterial((material = MaterialMan.makeDynamic(material)));

materials.push_back(material);
}
for (EntityList::iterator e = _entities.begin(); e != _entities.end(); ++e)
materials.push_back((*e)->getSubEntity(0)->getMaterial());
}

void Model::createNode(NodeEntity *&nodeEntity, State *state, Common::UString name, Ogre::SceneNode *parent) {
Expand Down Expand Up @@ -347,7 +342,7 @@ Ogre::Entity *Model::createEntity(const VertexDeclaration &vertexDecl, const Ogr
entity->getUserObjectBindings().setUserAny("renderable", Ogre::Any((Renderable *) this));

// Assign the material to the entity
entity->setMaterial(material.isNull() ? MaterialMan.getSolidColor(0.0, 0.0, 0.0, 0.0) : material);
entity->setMaterial(material.isNull() ? MaterialMan.create(0.0, 0.0, 0.0, 0.0) : material);

return entity;
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/aurora/model_kotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void Model_KotOR::readMesh(ParserContext &ctx) {
if (textureCount == 0)
ctx.nodeEntity->dontRender = true;

Ogre::MaterialPtr material = MaterialMan.get(ctx.material);
Ogre::MaterialPtr material = MaterialMan.create(ctx.material);

uint32 endPos = ctx.mdl->pos();

Expand Down
4 changes: 2 additions & 2 deletions src/graphics/aurora/model_nwn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void Model_NWN::readBinaryMesh(ParserContext &ctx) {
if (textureCount == 0)
ctx.nodeEntity->dontRender = true;

Ogre::MaterialPtr material = MaterialMan.get(ctx.material);
Ogre::MaterialPtr material = MaterialMan.create(ctx.material);

uint32 endPos = ctx.mdl->pos();

Expand Down Expand Up @@ -1151,7 +1151,7 @@ void Model_NWN::processASCIIMesh(ParserContext &ctx, MeshASCII &mesh) {
if (textureCount == 0)
ctx.nodeEntity->dontRender = true;

Ogre::MaterialPtr material = MaterialMan.get(ctx.material);
Ogre::MaterialPtr material = MaterialMan.create(ctx.material);

VertexDeclaration vertexDecl(mesh.faceCount, 0, textureCount);

Expand Down
4 changes: 2 additions & 2 deletions src/graphics/aurora/model_nwn2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void Model_NWN2::loadRigid(ParserContext &ctx, Ogre::SceneNode *parent) {
ctx.material.textures.push_back(diffuseMap);
uint32 textureCount = ctx.material.textures.size();

Ogre::MaterialPtr material = MaterialMan.get(ctx.material);
Ogre::MaterialPtr material = MaterialMan.create(ctx.material);


// Read vertices
Expand Down Expand Up @@ -282,7 +282,7 @@ void Model_NWN2::loadSkin(ParserContext &ctx, Ogre::SceneNode *parent) {
ctx.material.textures.push_back(diffuseMap);
uint32 textureCount = ctx.material.textures.size();

Ogre::MaterialPtr material = MaterialMan.get(ctx.material);
Ogre::MaterialPtr material = MaterialMan.create(ctx.material);


// Read vertices
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/aurora/model_witcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void Model_Witcher::readMesh(ParserContext &ctx) {
if (textureCount == 0)
ctx.nodeEntity->dontRender = true;

Ogre::MaterialPtr material = MaterialMan.get(ctx.material);
Ogre::MaterialPtr material = MaterialMan.create(ctx.material);


// Read vertices
Expand Down
5 changes: 1 addition & 4 deletions src/graphics/aurora/quad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void Quad::update() {
}
}

_material = MaterialMan.createDynamic();
_material = MaterialMan.create();

if (!_texture.isNull()) {
Ogre::TextureUnitState *texState = _material->getTechnique(0)->getPass(0)->createTextureUnitState();
Expand Down Expand Up @@ -361,9 +361,6 @@ void Quad::update() {
}

void Quad::collectMaterials(std::list<Ogre::MaterialPtr> &materials, bool makeDynamic, bool makeTransparent) {
if (makeDynamic)
_entity->setMaterial((_material = MaterialMan.makeDynamic(_material)));

if (makeTransparent)
MaterialMan.setTransparent(_material, true);

Expand Down
4 changes: 2 additions & 2 deletions src/graphics/aurora/texturefont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Ogre::Entity *TextureFont::createMissing(float &width, float &height, const Comm
width = getWidth('m') - _spaceR;
height = getHeight();

Ogre::MaterialPtr material = MaterialMan.makeDynamic(MaterialMan.getSolidColor(0.0, 0.0, 0.0, 0.0));
Ogre::MaterialPtr material = MaterialMan.create(0.0, 0.0, 0.0, 0.0, true);

return createQuadEntity(width, height, material, 0.0, 0.0, 0.0, 0.0, scene);
}
Expand All @@ -139,7 +139,7 @@ Ogre::Entity *TextureFont::createCharacter(uint32 c, float &width, float &height
width = cC.width + _spaceR;
height = getHeight();

Ogre::MaterialPtr material = MaterialMan.createDynamic();
Ogre::MaterialPtr material = MaterialMan.create();

Ogre::TextureUnitState *texState = material->getTechnique(0)->getPass(0)->createTextureUnitState();

Expand Down
4 changes: 2 additions & 2 deletions src/graphics/aurora/ttffont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Ogre::Entity *TTFFont::createMissing(float &width, float &height, const Common::
width = _missingWidth;
height = getHeight();

Ogre::MaterialPtr material = MaterialMan.makeDynamic(MaterialMan.getSolidColor(0.0, 0.0, 0.0, 0.0));
Ogre::MaterialPtr material = MaterialMan.create(0.0, 0.0, 0.0, 0.0, true);

return createQuadEntity(width, height, material, 0.0, 0.0, 0.0, 0.0, scene);
}
Expand All @@ -240,7 +240,7 @@ Ogre::Entity *TTFFont::createCharacter(uint32 c, float &width, float &height, co
width = cC->second.width;
height = getHeight();

Ogre::MaterialPtr material = MaterialMan.createDynamic();
Ogre::MaterialPtr material = MaterialMan.create();

Ogre::TextureUnitState *texState = material->getTechnique(0)->getPass(0)->createTextureUnitState();

Expand Down
2 changes: 1 addition & 1 deletion src/graphics/cursorman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void CursorManager::init() {
if (_ready)
return;

_material = MaterialMan.createDynamic();
_material = MaterialMan.create();
_material->getTechnique(0)->getPass(0)->createTextureUnitState();

_container = (Ogre::OverlayContainer *) Ogre::OverlayManager::getSingletonPtr()->createOverlayElement("Panel", "xoreos/MouseCursor");
Expand Down

0 comments on commit 5ea8094

Please sign in to comment.