Merge remote-tracking branch 'origin/master' into threaded_tex_loader

This commit is contained in:
Benau 2017-03-11 13:55:18 +08:00
commit ab673fc03b
12 changed files with 134 additions and 70 deletions

View File

@ -37,7 +37,7 @@ vec4 renderSolid()
if(uTextureUsage0)
Color *= texture2D(uTextureUnit0, varTexCoord0);
Color.a = 1.0;
//Color.a = 1.0;
return Color;
}

View File

@ -67,15 +67,12 @@ void COGLES2FixedPipelineRenderer::OnSetMaterial(const video::SMaterial& materia
}
else if (Blending)
{
//E_BLEND_FACTOR srcFact,dstFact;
//E_MODULATE_FUNC modulate;
//u32 alphaSource;
//unpack_textureBlendFunc(srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam);
E_BLEND_FACTOR srcFact,dstFact;
E_MODULATE_FUNC modulate;
u32 alphaSource;
unpack_textureBlendFunc(srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam);
//Driver->getBridgeCalls()->setBlendFunc(Driver->getGLBlend(srcFact), Driver->getGLBlend(dstFact));
//Driver->getBridgeCalls()->setBlend(true);
Driver->getBridgeCalls()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
Driver->getBridgeCalls()->setBlendFunc(Driver->getGLBlend(srcFact), Driver->getGLBlend(dstFact));
Driver->getBridgeCalls()->setBlend(true);
}
else

View File

@ -1653,7 +1653,12 @@ void IrrDriver::onUnloadWorld()
void IrrDriver::setAmbientLight(const video::SColorf &light, bool force_SH_computation)
{
#ifndef SERVER_ONLY
m_scene_manager->setAmbientLight(light);
video::SColorf color = light;
color.r = powf(color.r, 1.0f / 2.2f);
color.g = powf(color.g, 1.0f / 2.2f);
color.b = powf(color.b, 1.0f / 2.2f);
m_scene_manager->setAmbientLight(color);
m_renderer->setAmbientLight(light, force_SH_computation);
#endif
} // setAmbientLight
@ -2060,7 +2065,7 @@ scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos,
{
scene::ILightSceneNode* light = m_scene_manager
->addLightSceneNode(m_scene_manager->getRootSceneNode(),
pos, video::SColorf(1.0f, r, g, b));
pos, video::SColorf(r, g, b, 1.0f));
light->setRadius(radius);
return light;
}

View File

@ -72,7 +72,19 @@ Material::Material(const XMLNode *node, bool deprecated)
if (relativePath.size() == 0)
Log::warn("Material", "Cannot determine texture full path : <%s>", m_texname.c_str());
else
m_full_path = file_manager->getFileSystem()->getAbsolutePath(relativePath.c_str()).c_str();
m_full_path = m_original_full_path = file_manager->getFileSystem()->getAbsolutePath(relativePath.c_str()).c_str();
core::stringc texfname(m_texname.c_str());
texfname.make_lower();
m_texname = texfname.c_str();
if (m_full_path.size() > 0)
{
core::stringc texfname2(m_full_path.c_str());
texfname2.make_lower();
m_full_path = texfname2.c_str();
}
init();
bool b = false;
@ -423,15 +435,23 @@ Material::Material(const std::string& fname, bool is_full_path,
if (is_full_path)
{
m_texname = StringUtils::getBasename(fname);
m_full_path = fname;
m_full_path = m_original_full_path = fname;
}
else
{
m_texname = fname;
m_full_path = file_manager->getFileSystem()->getAbsolutePath(
m_full_path = m_original_full_path = file_manager->getFileSystem()->getAbsolutePath(
file_manager->searchTexture(m_texname).c_str()).c_str();
}
core::stringc texfname(m_texname.c_str());
texfname.make_lower();
m_texname = texfname.c_str();
core::stringc texfname2(m_full_path.c_str());
texfname2.make_lower();
m_full_path = texfname2.c_str();
m_complain_if_not_found = complain_if_not_found;
if (load_texture)
@ -507,7 +527,7 @@ void Material::install(bool srgb, bool premul_alpha)
else
{
m_texture = STKTexManager::getInstance()->getTexture
(m_full_path, srgb, premul_alpha, false/*set_material*/,
(m_original_full_path, srgb, premul_alpha, false/*set_material*/,
srgb/*mesh_tex*/);
}
@ -516,6 +536,10 @@ void Material::install(bool srgb, bool premul_alpha)
// now set the name to the basename, so that all tests work as expected
m_texname = StringUtils::getBasename(m_texname);
core::stringc texfname(m_texname.c_str());
texfname.make_lower();
m_texname = texfname.c_str();
m_texture->grab();
} // install

View File

@ -92,6 +92,8 @@ private:
std::string m_full_path;
std::string m_original_full_path;
/** Name of a special sfx to play when a kart is on this terrain, or
* "" if no special sfx exists. */
std::string m_sfx_name;

View File

@ -80,17 +80,14 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t,
//-----------------------------------------------------------------------------
Material* MaterialManager::getMaterialFor(video::ITexture* t)
{
core::stringc img_path = core::stringc(t->getName());
img_path.make_lower();
const io::path& img_path = t->getName().getInternalName();
if (!img_path.empty() && (img_path.findFirst('/') != -1 || img_path.findFirst('\\') != -1))
{
// Search backward so that temporary (track) textures are found first
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
{
core::stringc fullpath = core::stringc(m_materials[i]->getTexFullPath().c_str());
fullpath.make_lower();
if (fullpath == img_path.c_str())
if (m_materials[i]->getTexFullPath() == img_path.c_str())
{
return m_materials[i];
}
@ -103,9 +100,7 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t)
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
{
core::stringc texfname(m_materials[i]->getTexFname().c_str());
texfname.make_lower();
if (texfname == image)
if (m_materials[i]->getTexFname() == image.c_str())
{
return m_materials[i];
}
@ -361,9 +356,7 @@ Material *MaterialManager::getMaterial(const std::string& fname,
// Search backward so that temporary (track) textures are found first
for (int i = (int)m_materials.size()-1; i>=0; i-- )
{
core::stringc fname(m_materials[i]->getTexFname().c_str());
fname.make_lower();
if (fname == basename_lower)
if (m_materials[i]->getTexFname() == basename_lower.c_str())
return m_materials[i];
}

View File

@ -470,8 +470,12 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
if (m_is_glsl)
{
bool additive = (type->getMaterial()->getShaderType() == Material::SHADERTYPE_ADDITIVE);
static_cast<ParticleSystemProxy *>(m_node)->setAlphaAdditive(additive);
Material* material = type->getMaterial();
if (material != nullptr)
{
bool additive = (material->getShaderType() == Material::SHADERTYPE_ADDITIVE);
static_cast<ParticleSystemProxy *>(m_node)->setAlphaAdditive(additive);
}
}
}

View File

@ -130,6 +130,10 @@ ParticleKind::ParticleKind(const std::string &file)
{
material->get("file", &m_material_file);
core::stringc tmp(m_material_file.c_str());
tmp.make_lower();
m_material_file = tmp.c_str();
if (m_material_file.size() == 0)
{
delete xml;
@ -257,7 +261,7 @@ Material* ParticleKind::getMaterial() const
if (material_manager->hasMaterial(m_material_file))
{
Material* material = material_manager->getMaterial(m_material_file);
if (material->getTexture(true/*srgb*/, true/*premul_alpha*/) == NULL)
if (material == NULL || material->getTexture(true/*srgb*/, true/*premul_alpha*/) == NULL)
{
throw std::runtime_error("[ParticleKind] Cannot locate file " + m_material_file);
}

View File

@ -273,17 +273,17 @@ KartModel::~KartModel()
for (size_t i = 0; i < m_headlight_objects.size(); i++)
{
HeadlightObject& obj = m_headlight_objects[i];
obj.m_node = NULL;
if (obj.m_node)
obj.setNode(NULL);
if (obj.getNode())
{
// Master KartModels should never have a speed weighted object attached.
// Master KartModels should never have a headlight attached.
assert(!m_is_master);
obj.m_node->drop();
obj.getNode()->drop();
}
if (m_is_master && obj.m_model)
if (m_is_master && obj.getModel())
{
irr_driver->dropAllTextures(obj.m_model);
irr_driver->removeMeshFromCache(obj.m_model);
irr_driver->dropAllTextures(obj.getModel());
irr_driver->removeMeshFromCache(obj.getModel());
}
}
@ -368,8 +368,8 @@ KartModel* KartModel::makeCopy(KartRenderType krt)
km->m_headlight_objects.resize(m_headlight_objects.size());
for (size_t i = 0; i<m_headlight_objects.size(); i++)
{
// Master should not have any speed weighted nodes.
assert(!m_headlight_objects[i].m_node);
// Master should not have any headlight nodes.
assert(!m_headlight_objects[i].getNode());
km->m_headlight_objects[i] = m_headlight_objects[i];
}
@ -448,8 +448,8 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim
for (size_t i = 0; i<m_headlight_objects.size(); i++)
{
if (!m_headlight_objects[i].m_node) continue;
m_headlight_objects[i].m_node->setParent(lod_node);
if (!m_headlight_objects[i].getNode()) continue;
m_headlight_objects[i].getNode()->setParent(lod_node);
}
#ifndef SERVER_ONLY
@ -530,20 +530,23 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim
}
}
for (unsigned i = 0; i < m_headlight_objects.size(); i++)
for (unsigned int i = 0; i < m_headlight_objects.size(); i++)
{
HeadlightObject& obj = m_headlight_objects[i];
obj.m_node = NULL;
if (obj.m_model)
obj.setNode(NULL);
if (obj.getModel())
{
obj.m_node = irr_driver->addMesh(obj.m_model, "kart_headlight", node, getRenderInfo());
obj.m_node->grab();
obj.m_node->setPosition(obj.getPosition());
scene::ISceneNode *new_node =
irr_driver->addMesh(obj.getModel(), "kart_headlight",
node, getRenderInfo() );
new_node->grab();
obj.setNode(new_node);
Track* track = Track::getCurrentTrack();
if (track == NULL || track->getIsDuringDay())
obj.m_node->setVisible(false);
obj.getNode()->setVisible(false);
}
}
@ -642,12 +645,12 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
kart_max.max(obj_max);
}
for (unsigned i = 0; i < m_headlight_objects.size(); i++)
for (unsigned int i = 0; i < m_headlight_objects.size(); i++)
{
HeadlightObject& obj = m_headlight_objects[i];
std::string full_name = kart_properties.getKartDir() + obj.getFilename();
obj.m_model = irr_driver->getMesh(full_name);
irr_driver->grabAllTextures(obj.m_model);
obj.setModel(irr_driver->getMesh(full_name));
irr_driver->grabAllTextures(obj.getModel());
}
Vec3 size = kart_max-kart_min;
@ -722,7 +725,8 @@ void KartModel::loadNitroEmitterInfo(const XMLNode &node,
// ----------------------------------------------------------------------------
/** Loads a single speed weighted node. */
void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node, const SpeedWeightedObject::Properties& fallback_properties)
void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node,
const SpeedWeightedObject::Properties& fallback_properties)
{
SpeedWeightedObject obj;
obj.m_properties = fallback_properties;
@ -778,7 +782,7 @@ void KartModel::loadHeadlights(const XMLNode &node)
Log::warn("KartModel", "Unknown XML node in the headlights section");
}
}
}
} // loadHeadlights
// ----------------------------------------------------------------------------
/** Resets the kart model. It stops animation from being played and resets

View File

@ -84,33 +84,64 @@ struct SpeedWeightedObject
};
typedef std::vector<SpeedWeightedObject> SpeedWeightedObjectList;
// ============================================================================
/** A class to store the headlights of a kart.
*/
class HeadlightObject
{
private:
/** The filename of the headlight model. */
std::string m_filename;
/** The position relative to the parent kart scene node where the
* headlight mesh is attached to. */
core::vector3df m_position;
/** The mesh for the headlight. */
scene::IMesh* m_model;
/** The scene node of the headlight. */
scene::ISceneNode* m_node;
public:
scene::IMesh* m_model;
scene::ISceneNode* m_node;
HeadlightObject()
{
m_model = NULL;
m_node = NULL;
}
HeadlightObject(const std::string& filename, core::vector3df pos)
m_model = NULL;
m_node = NULL;
m_filename = "";
m_position.set(0, 0, 0);
} // HeadlightObject
// ------------------------------------------------------------------------
HeadlightObject(const std::string& filename, core::vector3df &pos)
{
m_filename = filename;
m_position = pos;
m_model = NULL;
m_node = NULL;
}
m_model = NULL;
m_node = NULL;
} // HeadlightObjects
// ------------------------------------------------------------------------
const std::string& getFilename() const { return m_filename; }
const core::vector3df getPosition() const { return m_position; }
};
// ------------------------------------------------------------------------
/** Sets the mesh for this headlight object. */
void setModel(scene::IMesh *mesh) { m_model = mesh; }
// ------------------------------------------------------------------------
/** Sets the node of the headlight, and (if not NULL) also sets the
* position of this scene node to be the position of the headlight. */
void setNode(scene::ISceneNode *node)
{
m_node = node;
if (m_node) m_node->setPosition(m_position);
} // setNode
// ------------------------------------------------------------------------
const scene::ISceneNode *getNode() const { return m_node; }
// ------------------------------------------------------------------------
scene::ISceneNode *getNode() { return m_node; }
// ------------------------------------------------------------------------
const scene::IMesh *getModel() const { return m_model; }
// ------------------------------------------------------------------------
scene::IMesh *getModel() { return m_model; }
// ------------------------------------------------------------------------
}; // class HeadlightObject
// ============================================================================
/**
* \brief This class stores a 3D kart model.

View File

@ -87,14 +87,14 @@ void MainMenuScreen::loadedFromFile()
LabelWidget* w = getWidget<LabelWidget>("info_addons");
w->setScrollSpeed(15);
IconButtonWidget* iw = getWidget<IconButtonWidget>("story");
assert(iw != NULL);
RibbonWidget* rw_top = getWidget<RibbonWidget>("menu_toprow");
assert(rw_top != NULL);
if (track_manager->getTrack("overworld") == NULL ||
track_manager->getTrack("introcutscene") == NULL ||
track_manager->getTrack("introcutscene2") == NULL)
{
iw->setVisible(false);
rw_top->removeChildNamed("story");
}
#if DEBUG_MENU_ITEM != 1

View File

@ -123,7 +123,7 @@ RaceGUIOverworld::RaceGUIOverworld()
{
m_map_left = (int)((irr_driver->getActualScreenSize().Width -
m_map_width) * 0.9f);
m_map_bottom = m_map_height + 10 * scaling;
m_map_bottom = m_map_height + int(10 * scaling);
}
m_speed_meter_icon = material_manager->getMaterial("speedback.png");