Example #1
0
	TextureAsset *Assets::RequestTexture(const std::string &filename, FilterType filter, bool repeatX, bool repeatY)
	{
		TextureAsset *asset = NULL;
		std::string fullFilename = instance->contentPath + filename;

		//Debug::Log("instance->contentPath + filename: " + fullFilename);

		// check to see if we have one stored already
		asset = (TextureAsset*)instance->GetAssetByFilename(fullFilename);

		// if not, load it and store it
		if (!asset)
		{
			asset = new TextureAsset();
			asset->Load(fullFilename, filter, repeatX, repeatY);
			instance->StoreAsset((Asset*)asset);
		}

		if (asset)
		{
			asset->AddReference();
		}

		// return whatever we found
		return asset;
	}
Example #2
0
TextureAsset* AssetManager::RequestTexture(const std::string &filename, D3DCOLOR colorKey) {
    assert(filename.c_str());
    TextureAsset* asset = static_cast<TextureAsset*>(GetAssetByFilename(filename));

    if (!asset) {
        asset = new TextureAsset();
        bool result = false;
        switch (mMethod) {
        case AssetLoadingMethod::LoadFromFile:
            result = asset->Load(filename, colorKey);
            break;
        case AssetLoadingMethod::LoadFromBinary:
            result = asset->LoadBinary(filename, colorKey);
            break;
        }

        if (result) {
            StoreAsset(asset);
        }
        else {
            printIn("%s: Failed to load\n", asset->mName.c_str());
            SAFE_DELETE(asset);
        }
    }

    if (asset) {
        asset->AddReference();
        printIn("%s: RefCount (%d)\n", asset->mName.c_str(), asset->mRefCount);
    }

    return asset;
}
Example #3
0
	TextureAsset *Assets::RequestTexture(const std::string &filename)
	{
		TextureAsset *asset = NULL;
		std::string name = GetContentPath() + filename;
		asset = (TextureAsset *)GetAssetByFilename(name);

		if (!asset)
		{
			asset = new TextureAsset();
			if (asset->Load(name))
			{
				StoreAsset(asset);
				std::cout << asset->m_filename << ": Load" << std::endl;
			}
			else
			{
				SDELETE(asset);
			}
		}

		if (asset)
		{
			asset->AddReference();
			std::cout << asset->m_filename << ": RefCount (" << asset->m_iRefCount << ")" << std::endl;
		}

		return asset;
	}
Example #4
0
	void MaterialAsset::__loadTextureToGFXCard( void )
	{
		if ( !__isTextureLoaded )
		{
			Resources* r = DWIngine::singleton()->resources();

			TextureAsset* tex = r->getTexture( __textureUniqueName );

			

			GLuint textureID;
			glGenTextures( 1, &textureID );

			glBindTexture( GL_TEXTURE_2D, textureID );

			unsigned char * data = new unsigned char [tex->width() * tex->height() * 3];

			data = &tex->imageData()[ 68 ];

			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex->width(), tex->height(), 0, GL_BGR, GL_UNSIGNED_BYTE, data );
			//glTexImage2D( GL_TEXTURE_2D, 0, GL_BGR, tex->width(), tex->height(), 0, GL_RGB, GL_UNSIGNED_BYTE, data );

			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
			glGenerateMipmap( GL_TEXTURE_2D );

			__texture = textureID;

			__isTextureLoaded = !__isTextureLoaded;
		}
	}
Example #5
0
ParticleComponent::ParticleComponent(const std::string &assetid) :
	m_shaderAsset(NULL)
{
	m_componentOrder = 40;

	TextureAsset* asset = Asset::getTexture(assetid);
	m_particleSystem.reset(new thor::ParticleSystem(asset->getAsset()));

	/*m_emitter = thor::UniversalEmitter::create();

	m_emitter->setEmissionRate(10.f);
	m_emitter->setParticleLifetime(sf::seconds(3));
	m_emitter->setParticleRotation(thor::Distributions::uniform(0.f, 360.f));
	m_emitter->setParticleVelocity(thor::Distributions::circle(sf::Vector2f(), 350.f));
	
	m_particleSystem->addEmitter(m_emitter);*/

	createEmitter();

	//m_particleSystem->addAffector(thor::AnimationAffector::create(thor::FadeAnimation(0.05f, 0.8f)));
	//m_particleSystem->addAffector(thor::ScaleAffector::create(sf::Vector2f(-0.2f, 1.f)));
}
Example #6
0
void Sky::Update()
{
    if (!urhoNode_)
        return;

    Urho3D::ResourceCache* cache = GetSubsystem<Urho3D::ResourceCache>();

    if (material_ != nullptr && textureRefListListener_->Assets().Size() < 6)
    {
        // Use material as is

        ///\todo Remove diff color setting once DefaultOgreMaterialProcessor sets it properly.
        material_->UrhoMaterial()->SetShaderParameter("MatDiffColor", Urho3D::Vector4(1, 1, 1, 1));
        material_->UrhoMaterial()->SetCullMode(Urho3D::CULL_NONE);
        urhoNode_->GetComponent<Urho3D::Skybox>()->SetMaterial(material_->UrhoMaterial());
        return;
    }

    Vector<SharedPtr<Urho3D::Image> > images(6);
    Vector<AssetPtr> textureAssets = textureRefListListener_->Assets();
    int numLoadedImages = 0;
    for(uint mi=0; mi<textureAssets.Size(); ++mi)
    {
        AssetPtr &TextureAssetPtr = textureAssets[mi];
        BinaryAsset *binaryAsset = dynamic_cast<BinaryAsset*>(TextureAssetPtr.Get());
        TextureAsset *textureAsset = dynamic_cast<TextureAsset*>(TextureAssetPtr.Get());
        if ((textureAsset || binaryAsset) && TextureAssetPtr->IsLoaded())
        {
            SharedPtr<Urho3D::Image> image = SharedPtr<Urho3D::Image>(new Urho3D::Image(GetContext()));
            Vector<u8> data;
            if (binaryAsset)
                data = binaryAsset->data;
            ///\todo Loading raw image data from disksource leaves an extra GPU texture resource unused.
            else if (!LoadFileToVector(textureAsset->DiskSource(), data))
                continue;

            Urho3D::MemoryBuffer imageBuffer(&data[0], data.Size());
            if (!image->Load(imageBuffer))
                continue;

            images[mi] = image;
            numLoadedImages++;
        }
    }

    if (numLoadedImages == 6)
    {
        // Reuse the previous cube texture if possible
        SharedPtr<Urho3D::TextureCube> textureCube = (cubeTexture_.Get() == nullptr) ? SharedPtr<Urho3D::TextureCube>(new Urho3D::TextureCube(GetContext())) : cubeTexture_.Lock();

        const Urho3D::CubeMapFace faces[6] = { Urho3D::FACE_POSITIVE_X, Urho3D::FACE_NEGATIVE_X, Urho3D::FACE_POSITIVE_Y, Urho3D::FACE_NEGATIVE_Y, Urho3D::FACE_POSITIVE_Z, Urho3D::FACE_NEGATIVE_Z };
        const int faceOrder[6] = { 3, 2, 4, 5, 0, 1 };

        for (size_t i=0 ; i<images.Size() ; ++i)
            if (images[faceOrder[i]] != nullptr)
                textureCube->SetData(faces[i], images[faceOrder[i]]);

        // Remember the created texture for tracking device loss
        cubeTexture_ = textureCube;
        SubscribeToEvent(Urho3D::E_DEVICERESET, URHO3D_HANDLER(Sky, HandleDeviceReset));

        SharedPtr<Urho3D::Material> material;
        if (material_)
            material = material_->UrhoMaterial()->Clone();
        else
            material = SharedPtr<Urho3D::Material>(new Urho3D::Material(GetContext()));
        material->SetCullMode(Urho3D::CULL_NONE);
        material->SetTechnique(0, cache->GetResource<Urho3D::Technique>("Techniques/DiffSkybox.xml"));
        material->SetTexture(Urho3D::TU_DIFFUSE, textureCube);
        ///\todo Remove diff color setting once DefaultOgreMaterialProcessor sets it properly.
        material->SetShaderParameter("MatDiffColor", Urho3D::Vector4(1, 1, 1, 1));
    
        urhoNode_->GetComponent<Urho3D::Skybox>()->SetMaterial(material);
    } 
    else
    {
        if (GetFramework()->HasCommandLineParameter("--useErrorAsset"))
        {
            urhoNode_->GetComponent<Urho3D::Skybox>()->SetMaterial(cache->GetResource<Urho3D::Material>("Materials/AssetLoadError.xml"));
        }
    }
}
Example #7
0
void ParticleComponent::parsePrefab(json::Value& val)
{
	if(val.isMember("texture"))
	{
		const std::string assetid = val["texture"].asString();
		TextureAsset* asset = Asset::getTexture(assetid);

		if(asset)
		{
			//m_particleTexture.reset(new sf::Texture(*asset->getAsset()));

			m_particleSystem.reset(new thor::ParticleSystem(asset->getAsset()));

			createEmitter();
		}
		else
		{
			szerr << "Prefab particle texture '" << assetid << "' could not be retrieved." << ErrorStream::error;
		}
	}

	if(val.isMember("emissionrate"))
	{
		setEmissionRate(static_cast<float>(val["emissionrate"].asDouble()));
	}
	
	if(val.isMember("lifetime"))
	{
		if(val["lifetime"].isArray() && val["lifetime"].size() == 2)
		{
			setLifetime(
				static_cast<float>(val["lifetime"][0U].asDouble()),
				static_cast<float>(val["lifetime"][1U].asDouble())
			);
		}
		else if(val["lifetime"].isArray() && val["lifetime"].size() == 1)
		{
			setLifetime(
				static_cast<float>(val["lifetime"][0U].asDouble())
			);
		}
		else if(!val["lifetime"].isArray())
		{
			setLifetime(static_cast<float>(val["lifetime"].asDouble()));
		}
		else
		{
			szerr << "Invalid particle lifetime value in prefab." << ErrorStream::error;
		}
	}

	if(val.isMember("velocity"))
	{
		if(val["velocity"].isArray() && val["velocity"].size() == 2)
		{
			setVelocity(sf::Vector2f(
				static_cast<float>(val["velocity"][0U].asDouble()),
				static_cast<float>(val["velocity"][1U].asDouble())
			));
		}
	}

	if(val.isMember("rotation"))
	{
		if(val["rotation"].isArray() && val["rotation"].size() == 2)
		{
			setRotation(
				static_cast<float>(val["rotation"][0U].asDouble()),
				static_cast<float>(val["rotation"][1U].asDouble())
			);
		}
		else if(val["rotation"].isArray() && val["rotation"].size() == 1)
		{
			setRotation(
				static_cast<float>(val["rotation"][0U].asDouble())
			);
		}
		else if(!val["rotation"].isArray())
		{
			setRotation(static_cast<float>(val["rotation"].asDouble()));
		}
		else
		{
			szerr << "Invalid particle rotation value in prefab." << ErrorStream::error;
		}
	}

	if(val.isMember("scale"))
	{
		if(val["scale"].isArray() && val["scale"].size() == 2)
		{
			setScale(
				static_cast<float>(val["scale"][0U].asDouble()),
				static_cast<float>(val["scale"][1U].asDouble())
			);
		}
		else if(val["scale"].isArray() && val["scale"].size() == 1)
		{
			setScale(
				static_cast<float>(val["scale"][0U].asDouble())
			);
		}
		else if(!val["scale"].isArray())
		{
			setScale(static_cast<float>(val["scale"].asDouble()));
		}
		else
		{
			szerr << "Invalid particle scale value in prefab." << ErrorStream::error;
		}
	}

	if(val.isMember("rotationspeed"))
	{
		if(val["rotationspeed"].isArray() && val["rotationspeed"].size() == 2)
		{
			setRotationSpeed(
				static_cast<float>(val["rotationspeed"][0U].asDouble()),
				static_cast<float>(val["rotationspeed"][1U].asDouble())
			);
		}
		else if(val["rotationspeed"].isArray() && val["rotationspeed"].size() == 1)
		{
			setRotationSpeed(
				static_cast<float>(val["rotationspeed"][0U].asDouble())
			);
		}
		else if(!val["rotationspeed"].isArray())
		{
			setRotationSpeed(static_cast<float>(val["rotationspeed"].asDouble()));
		}
		else
		{
			szerr << "Invalid particle rotationspeed value in prefab." << ErrorStream::error;
		}
	}

	if(val.isMember("affectors"))
	{
		json::Value affectors = val["affectors"];

		for(json::Value::iterator it = affectors.begin(); it != affectors.end(); ++it)
		{
			const std::string affector = it.memberName();

			if(affector == "fade")
			{
				addFadeAffector(
					static_cast<float>((*it)[0U].asDouble()),
					static_cast<float>((*it)[1U].asDouble())
				);
			}
			else if(affector == "scale")
			{
				addScaleAffector(
					static_cast<float>((*it)[0U].asDouble()),
					static_cast<float>((*it)[1U].asDouble())
				);
			}
			else if(affector == "force")
			{
				addForceAffector(
					static_cast<float>((*it)[0U].asDouble()),
					static_cast<float>((*it)[1U].asDouble())
				);
			}
		}
	}

	if(val.get("prewarm", 0).asBool())
	{
		prewarm();
	}

	if(val.isMember("shader"))
	{
		json::Value shader = val["shader"];

		if(shader.isConvertibleTo(json::stringValue))
		{
			setShader(shader.asString());
		}
		else if(shader.isObject())
		{
			setShader(shader["asset"].asString());

			if(shader.isMember("param") && !shader["param"].empty())
			{
				json::Value parameters = shader["param"];

				for(json::Value::iterator it = parameters.begin(); it != parameters.end(); ++it)
				{
					const std::string name = it.memberName();

					json::Value v = *it;
					if(v.isArray())
					{
						switch(v.size())
						{
						case 1:
							m_shaderAsset->getAsset()->setParameter(name,
								(float)v[0U].asDouble());
							break;

						case 2:
							m_shaderAsset->getAsset()->setParameter(name,
								(float)v[0U].asDouble(),
								(float)v[1U].asDouble());
							break;

						case 3:
							m_shaderAsset->getAsset()->setParameter(name,
								(float)v[0U].asDouble(),
								(float)v[1U].asDouble(),
								(float)v[2U].asDouble());
							break;

						case 4:
							{
								m_shaderAsset->getAsset()->setParameter(name,
									(float)v[0U].asDouble(),
									(float)v[1U].asDouble(),
									(float)v[2U].asDouble(),
									(float)v[3U].asDouble());
								break;
							}

						default:
							szerr << "Incorrect amount of parameter arguments in prefab." << ErrorStream::error;
							break;
						}
					}
					else if(v.isConvertibleTo(json::realValue))
					{
						m_shaderAsset->getAsset()->setParameter(name,
							(float)v.asDouble());
					}
				}
			}
		}
	}

	if(val.isMember("color"))
	{
		sf::Uint32 size = val["color"].size();
		if(size == 3 || size == 4)
		{
			sf::Color color;

			color.r = static_cast<sf::Uint8>(val["color"][0U].asUInt());
			color.g = static_cast<sf::Uint8>(val["color"][1U].asUInt());
			color.b = static_cast<sf::Uint8>(val["color"][2U].asUInt());

			if(size == 4)
			{
				color.a = static_cast<sf::Uint8>(val["color"][3U].asUInt());
			}

			setColor(color);
		}
	}
	
	const std::string blend = val.get("blendmode", "alpha").asString();

	if(blend == "alpha")
	{
		m_renderStates.blendMode = sf::BlendAlpha;
	}
	else if(blend == "additive")
	{
		m_renderStates.blendMode = sf::BlendAdd;
	}
	else if(blend == "multiply")
	{
		m_renderStates.blendMode = sf::BlendMultiply;
	}
	else if(blend == "none")
	{
		m_renderStates.blendMode = sf::BlendNone;
	}
}