Exemple #1
0
 //-----------------------------------------------------------------------------   
 void Texture::copyToTexture( TexturePtr& target )
 {
     if(target->getNumFaces() != getNumFaces())
     {
         OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
             "Texture types must match",
             "Texture::copyToTexture");
     }
     size_t numMips = std::min(getNumMipmaps(), target->getNumMipmaps());
     if((mUsage & TU_AUTOMIPMAP) || (target->getUsage()&TU_AUTOMIPMAP))
         numMips = 0;
     for(unsigned int face=0; face<getNumFaces(); face++)
     {
         for(unsigned int mip=0; mip<=numMips; mip++)
         {
             target->getBuffer(face, mip)->blit(getBuffer(face, mip));
         }
     }
 }
	//-----------------------------------------------------------------------------------
	void PbsMaterial::setTexture(SamplerType samplerType, TexturePtr tex, TextureAddressing textureAddr,
		float blendFactor1, float blendFactor2, BlendFunction blendFunc, float intensityFactor)
	{
		SamplerContainer& s = _samplers[samplerType];
		if (s.status == SS_ACTIVE && tex == s.tex && s.blendFunc == blendFunc && s.blendFactor1 == blendFactor1 && s.blendFactor2 == blendFactor2 &&
			s.intensity == intensityFactor && s.textureAddressing == textureAddr)
			return;
		if (s.status == SS_NOT_ACTIVE && tex.isNull())
			return;

		if (!tex.isNull())
		{
			// Ensure that the texture in the shader is in linear space
			tex->setHardwareGammaEnabled(mCanHardwareGamma && s.needsGammaCorrection);

			if (s.status == SS_NOT_ACTIVE) s.status = SS_ADDED;
			else if (s.status == SS_ACTIVE) s.status = SS_UPDATED;
			else if (s.status == SS_UPDATED) s.status = SS_UPDATED;
			else if (s.status == SS_ADDED) s.status = SS_ADDED;
			else if (s.status == SS_REMOVED) s.status = SS_UPDATED;
		}
		else
		{
			if (s.status == SS_NOT_ACTIVE) s.status = SS_NOT_ACTIVE;
			else if (s.status == SS_ACTIVE) s.status = SS_REMOVED;
			else if (s.status == SS_UPDATED) s.status = SS_REMOVED;
			else if (s.status == SS_ADDED) s.status = SS_NOT_ACTIVE;
			else if (s.status == SS_REMOVED) s.status = SS_REMOVED;
		}

		s.tex = tex;
		s.textureAddressing = textureAddr;

		s.blendFunc = blendFunc;
		s.blendFactor1 = blendFactor1;
		s.blendFactor2 = blendFactor2;

		s.intensity = intensityFactor;
		s.mipmapCount = tex.isNull() ? 0.0f : tex->getNumMipmaps();

		_hasSamplerChanged = true;
		_hasSamplerListChanged = s.status == SS_ADDED || s.status == SS_REMOVED;
	}
void TextureToolWindow::updateControls(String texName)
{
    try
    {
        bool exists = TextureManager::getSingleton().resourceExists(texName);
        if (!exists)
        {
            mTxt->setCaption(convertToMyGUIString("Texture not found:\n" + texName));
            mBtnSavePNG->setEnabled(false);
            return;
        }

        TexturePtr tex = TextureManager::getSingleton().getByName(texName);
        if (tex.isNull())
        {
            mTxt->setCaption(convertToMyGUIString("Error loading texture:\n" + texName));
            mBtnSavePNG->setEnabled(false);
            return;
        }

        String str = "#aa0000" + texName + "#000000\n";
        str += "#00aa00res: #000000" + TOSTRING(tex->getWidth()) + " x " + TOSTRING(tex->getHeight()) + " pixels\n";
        str += "#00aa00size: #000000" + formatBytes(tex->getSize()) + "\n";
        str += "#00aa00format: #000000" + PixelUtil::getFormatName(tex->getFormat()) + "\n";
        if (tex->getNumFaces() > 1)
            str += "#00aa00faces: #000000" + TOSTRING(tex->getNumFaces()) + "\n";
        if (tex->getFSAA() > 0)
            str += "#00aa00FSAA: #000000" + TOSTRING(tex->getFSAA()) + "\n";
        if (tex->getNumMipmaps() > 0)
            str += "#00aa00mipmaps: #000000" + TOSTRING(tex->getNumMipmaps()) + "\n";

        String typeStr = "";
        switch (tex->getTextureType())
        {
        case TEX_TYPE_1D: typeStr = "1D";
            break;
        case TEX_TYPE_2D: typeStr = "2D";
            break;
        case TEX_TYPE_3D: typeStr = "3D";
            break;
        case TEX_TYPE_CUBE_MAP: typeStr = "Cube Map";
            break;
        }
        str += "#00aa00type: #000000" + typeStr + "\n";

        String usageStr = "";
        if (tex->getUsage() & TU_STATIC)
            usageStr += "static,\n";
        if (tex->getUsage() & TU_DYNAMIC)
            usageStr += "dynamic,\n";
        if (tex->getUsage() & TU_WRITE_ONLY)
            usageStr += "write only,\n";
        if (tex->getUsage() & TU_STATIC_WRITE_ONLY)
            usageStr += "static write only,\n";
        if (tex->getUsage() & TU_DYNAMIC_WRITE_ONLY)
            usageStr += "dynamic write only,\n";
        if (tex->getUsage() & TU_DYNAMIC_WRITE_ONLY_DISCARDABLE)
            usageStr += "dynamic write only discardable,\n";
        if (tex->getUsage() & TU_AUTOMIPMAP)
            usageStr += "automipmap,\n";
        if (tex->getUsage() & TU_RENDERTARGET)
            usageStr += "rendertarget,\n";
        if (tex->getUsage() & TU_DEFAULT)
            usageStr += "default\n";

        str += "#00aa00usage: #000000" + usageStr + "\n";
        if (tex->getDepth() > 1)
            str += "#00aa00depth: #000000" + TOSTRING(tex->getDepth()) + "\n";

        mTxt->setCaption(convertToMyGUIString(str));
        mImage->setImageTexture(texName);
        mBtnSavePNG->setEnabled(true);
    }
    catch (Exception& e)
    {
        UTFString str = "Exception while opening texture:" + e.getFullDescription();
        RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_MSGTYPE_INFO, str, "error.png");
    }
}
Exemple #4
0
	TexturePtr GetLodTexture(const std::string& name)
	{

		std::string texname(name + ".Texture");
		

		if(TextureManager::getSingleton().resourceExists(texname))
			return TextureManager::getSingleton().getByName(texname);
		angel::Log << "loading texture " << name << angel::aeLog::endl;

		int alpha = 0;

		angel::pLodData ldata=angel::LodManager.LoadFile( name );

		if(!ldata)
			return GetDefaultTexture();
		BYTE*data= &((*ldata)[0]);
		int size = (int)ldata->size();
		int psize = *(int*)(data+0x14);
		unsigned int unpsize1 = *(int*)(data+0x10);
		unsigned long unpsize2 = *(int*)(data+0x28);

		if( psize+0x30+0x300 != size )
			return GetDefaultTexture();
		if( unpsize2 && unpsize2 < unpsize1)
			return GetDefaultTexture();
		BYTE* pal = data + 0x30 + psize;
		BYTE*unpdata = new BYTE[unpsize2 ];
		boost::scoped_array<BYTE> sunpdata(unpdata);
		if ( uncompress( unpdata, &unpsize2 , data + 0x30, psize ) != Z_OK )
			return GetDefaultTexture();
		int width  = *(WORD*)(data+0x18);
		int height = *(WORD*)(data+0x1a);
		int imgsize = width*height;
		BYTE *pSrc=unpdata;

        int nummipmaps = 3;
		// Create the texture
		TexturePtr texture = TextureManager::getSingleton().createManual(
			name + ".Texture", // name
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D,      // type
			width, height,         // width & height
			nummipmaps,                // number of mipmaps
			PF_BYTE_BGRA,     // pixel format
			TU_DEFAULT);      // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for



		// Fill in some pixel data. This will give a semi-transparent blue,
		// but this is of course dependent on the chosen pixel format.
		int w=width;
		int h=height;

		int n=0,off=0; 
		nummipmaps = (int)texture->getNumMipmaps();
		for ( n = 0,off= 0; off < (int)unpsize2 && n <nummipmaps + 1 ;  n++)
		{
			if( w < 1 || h <1 )
				break;
			// Get the pixel buffer
			HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(0,n);

			// Lock the pixel buffer and get a pixel box
			pixelBuffer->lock(HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD!
			const PixelBox& pixelBox = pixelBuffer->getCurrentLock();

			uint8* pDest = static_cast<uint8*>(pixelBox.data);

			for (int j = 0; j < w; j++)
				for(int i = 0; i < h; i++)
				{
					int index=*pSrc++;
					int r = pal[index*3+0]; 
					int g = pal[index*3+1]; 
					int b = pal[index*3+2]; 
					int a = 0xff;
					if( index == 0 && ((r == 0 && g >250 && b > 250) || (r > 250 && g ==0 && b > 250)))
					{
						alpha=1;
						a= 0;
						r=g=b=0;
					}
					*pDest++ =   b; // G
					*pDest++ =   g; // R
					*pDest++ =   r;
					*pDest++ = a; // A
				}
				pixelBuffer->unlock();
				

				//off += w*h;
				w/=2;
				h/=2;
		}
		// Unlock the pixel buffer
		
		return texture;
	}