Exemplo n.º 1
0
//-------------------------------------------------------------------------
// @brief 
//-------------------------------------------------------------------------
Material::TextureSlotMapping TextureManager::deserialise( const DeviceManager& deviceManager, const tinyxml2::XMLElement* node )
{
    (void*)node;
    const char* fileName = node->Attribute("file_name");
    if (fileName)
    {
        addLoad(deviceManager, fileName);
        Material::TextureSlotMapping::TextureSlot textureSlot = Material::TextureSlotMapping::Diffuse0;
        const tinyxml2::XMLAttribute* attribute = node->FindAttribute("texture_slot");
        if (attribute != nullptr)
        {
            textureSlot = static_cast<Material::TextureSlotMapping::TextureSlot>(attribute->UnsignedValue());
        }
        return Material::TextureSlotMapping(hashString(getTextureNameFromFileName(fileName)), textureSlot);
    }

    return Material::TextureSlotMapping(hashString(""), Material::TextureSlotMapping::Invalid);
}
Exemplo n.º 2
0
void TextureManager::addLoad(const DeviceManager& deviceManager, const std::string& filename)
{
	assert (!filename.empty());

    //Extract filename if file name contains a path as well, this is not always true need to deal with relative paths here too
    std::string texureName = getTextureNameFromFileName(filename);

	if (find(texureName))
	{
		//MSG_TRACE_CHANNEL("", "Texture: " << filename << " was already loaded. Skipping the loading of the second instance of this texture" << std::endl;
        return;
	}

	MSG_TRACE_CHANNEL("TEXTUREMANAGER", "Attempting to read in texture: %s", filename.c_str());
	Texture tex;
    if (!tex.loadTextureFromFile(deviceManager, filename))
	{
        MSG_TRACE_CHANNEL("ERROR", "Texture cannot be loaded: %s", filename.c_str());
    }

    unsigned int textureFileNameHash = hashString(texureName);
	m_textures.insert(std::make_pair(textureFileNameHash, tex));
}
Exemplo n.º 3
0
//-------------------------------------------------------------------------
// @brief 
//-------------------------------------------------------------------------
const ShaderInstance Core::deserialise( const tinyxml2::XMLElement* element)
{
    ShaderInstance shaderInstance;
    
    const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name");
    if (attribute != nullptr)
    {
        m_name = attribute->Value();
    }

    for (const tinyxml2::XMLElement* childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement())
    {
        unsigned int childElementHash = hashString(childElement->Value());
        if (childElementHash == Material::m_hash)
        {
            const tinyxml2::XMLAttribute* nameAttribute = childElement->FindAttribute("name"); //This material needs a name to distinguish between normal and glowing versions of the material
            if (nameAttribute)
            {
                if (strICmp(nameAttribute->Value(), "CoreMaterialNormal"))
                {
                    m_forcefieldmatnormal.deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                    shaderInstance.getMaterial().deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                    shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString("cube_player_forcefield"), Material::TextureSlotMapping::Diffuse0));
                }
                else if( strICmp(nameAttribute->Value(), "CoreMaterialNormalGlow") )
                {
                    m_forcefieldmatglowing.deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                }
            }
        }
        else if (childElementHash == hashString("Model"))
        {
            attribute = childElement->FindAttribute("file_name");
            if (attribute != nullptr)
            {
                //Heavily relies on the shader instance existing before we load the model, might be better to put the model construction in initialise instead
                m_drawableObject = getWriteableGameResource().getModelManager().LoadModel(m_resource, shaderInstance, attribute->Value());
                m_drawableObject->setDirty();
            }
        }
    }

    //Get texture strings and load textures
    const SettingsManager& sm = getGameResource().getSettingsManager();
    TextureManager& tm = getWriteableGameResource().getTextureManager();
    const ISetting<std::string>* textureString = sm.getSetting<std::string>("Core");
    if (textureString)
    {
        tm.addLoad(getGameResource().getDeviceManager(), textureString->getData());
        shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString(getTextureNameFromFileName(textureString->getData())), Material::TextureSlotMapping::Diffuse0));
    }
    textureString = sm.getSetting<std::string>("ForceFieldCore");
    if (textureString)
    {
        tm.addLoad(getGameResource().getDeviceManager(), textureString->getData());
        shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString(getTextureNameFromFileName(textureString->getData())), Material::TextureSlotMapping::Diffuse0));
    }

    return shaderInstance;
}