Pass STK Material objet to MapMaterial functions

This commit is contained in:
Marianne Gagnon 2014-09-27 18:51:10 -04:00
parent 544f15d693
commit 906b7e8c51
5 changed files with 22 additions and 11 deletions

View File

@ -66,7 +66,9 @@ MaterialManager::~MaterialManager()
Material* MaterialManager::getMaterialFor(video::ITexture* t,
scene::IMeshBuffer *mb)
{
assert(t != NULL);
if (t == NULL)
return m_default_material;
const std::string image = StringUtils::getBasename(core::stringc(t->getName()).c_str());
// Search backward so that temporary (track) textures are found first
for(int i = (int)m_materials.size()-1; i>=0; i-- )

View File

@ -4,6 +4,7 @@
#include <IMaterialRenderer.h>
#include <ISkinnedMesh.h>
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "config/user_config.hpp"
#include "modes/world.hpp"
#include "tracks/track.hpp"
@ -95,14 +96,16 @@ void STKAnimatedMesh::updateNoGL()
continue;
}
GLMesh &mesh = GLmeshes[i];
Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
if (rnd->isTransparent())
{
TransparentMaterial TranspMat = MaterialTypeToTransparentMaterial(type, MaterialTypeParam);
TransparentMaterial TranspMat = MaterialTypeToTransparentMaterial(type, MaterialTypeParam, material);
TransparentMesh[TranspMat].push_back(&mesh);
}
else
{
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType());
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType(), material);
MeshSolidMaterial[MatType].push_back(&mesh);
}
}
@ -138,7 +141,8 @@ void STKAnimatedMesh::updateGL()
if (!rnd->isTransparent())
{
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType());
Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType(), material);
InitTextures(mesh, MatType);
}

View File

@ -10,7 +10,7 @@
#include "graphics/camera.hpp"
#include "modes/world.hpp"
MeshMaterial MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE MaterialType, video::E_VERTEX_TYPE tp)
MeshMaterial MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE MaterialType, video::E_VERTEX_TYPE tp, Material* material)
{
if (MaterialType == irr_driver->getShader(ES_SPHERE_MAP))
return MAT_SPHEREMAP;
@ -29,7 +29,7 @@ MeshMaterial MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE MaterialType, vid
return MAT_DEFAULT;
}
TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE type, f32 MaterialTypeParam)
TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE type, f32 MaterialTypeParam, Material* material)
{
if (type == irr_driver->getShader(ES_DISPLACE))
return TM_DISPLACEMENT;

View File

@ -10,6 +10,8 @@
#include <vector>
class Material;
enum MeshMaterial
{
MAT_DEFAULT,
@ -188,8 +190,8 @@ class ListInstancedGlow : public Singleton<ListInstancedGlow>, public std::vecto
// Forward pass (for transparents meshes)
void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
MeshMaterial MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE, video::E_VERTEX_TYPE);
TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE, f32 MaterialTypeParam);
MeshMaterial MaterialTypeToMeshMaterial(video::E_MATERIAL_TYPE, video::E_VERTEX_TYPE, Material* material);
TransparentMaterial MaterialTypeToTransparentMaterial(video::E_MATERIAL_TYPE, f32 MaterialTypeParam, Material* material);
void InitTextures(GLMesh &mesh, MeshMaterial);

View File

@ -8,6 +8,7 @@
#include "config/user_config.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/camera.hpp"
#include "graphics/material_manager.hpp"
#include "modes/world.hpp"
#include "utils/helpers.hpp"
#include "utils/tuple.hpp"
@ -132,16 +133,17 @@ void STKMeshSceneNode::updateNoGL()
}
GLMesh &mesh = GLmeshes[i];
Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
if (rnd->isTransparent())
{
TransparentMaterial TranspMat = MaterialTypeToTransparentMaterial(type, MaterialTypeParam);
TransparentMaterial TranspMat = MaterialTypeToTransparentMaterial(type, MaterialTypeParam, material);
if (!immediate_draw)
TransparentMesh[TranspMat].push_back(&mesh);
}
else
{
assert(!isDisplacement);
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType());
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType(), material);
if (!immediate_draw)
MeshSolidMaterial[MatType].push_back(&mesh);
}
@ -176,7 +178,8 @@ void STKMeshSceneNode::updateGL()
if (!rnd->isTransparent())
{
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType());
Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType(), material);
if (!immediate_draw)
InitTextures(mesh, MatType);
}