Example #1
0
TexturePtr RandomTools::generateRandomVelocityTexture()
{
    // PPP: Temp workaround for DX 11 which does not seem to like usage dynamic
    // TextureUsage usage = (Root::getSingletonPtr()->getRenderSystem()->getName()=="Direct3D11 Rendering Subsystem") ?
    //     TU_DEFAULT : TU_DYNAMIC;
    TexturePtr texPtr = TextureManager::getSingleton().createManual(
        "RandomVelocityTexture",
        // ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        "General",
        TEX_TYPE_1D, 
        1024, 1, 1, 
        0, 
        PF_FLOAT32_RGBA);//, 
        //usage);

    HardwarePixelBufferSharedPtr pixelBuf = texPtr->getBuffer();

    // Lock the buffer so we can write to it.
    pixelBuf->lock(HardwareBuffer::HBL_DISCARD);
    const PixelBox &pb = pixelBuf->getCurrentLock();
    
    float *randomData = static_cast<float*>(pb.data);
    // float randomData[NUM_RAND_VALUES * 4];
    for(int i = 0; i < NUM_RAND_VALUES * 4; i++)
    {
        randomData[i] = float( (rand() % 10000) - 5000 );
    }

    // PixelBox pixelBox(1024, 1, 1, PF_FLOAT32_RGBA, &randomData[0]);
    // pixelBuf->blitFromMemory(pixelBox);

    pixelBuf->unlock();

    return texPtr;
}
///  update terrain generator preview texture
//--------------------------------------------------------------------------------------------------------------------------
void App::updateTerPrv(bool first)
{
	if (!first && !ovTerPrv)  return;
	if (terPrvTex.isNull())  return;

	HardwarePixelBufferSharedPtr pbuf = terPrvTex->getBuffer();
	pbuf->lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox& pb = pbuf->getCurrentLock();  using Ogre::uint8;
	uint8* p = static_cast<uint8*>(pb.data);

	const static float fB[2] = { 90.f, 90.f}, fG[2] = {255.f,160.f}, fR[2] = { 90.f,255.f};

	const float s = TerPrvSize * 0.5f, s1 = 1.f/s;
	const float ox = pSet->gen_ofsx, oy = pSet->gen_ofsy;

	for (int y = 0; y < TerPrvSize; ++y)
	for (int x = 0; x < TerPrvSize; ++x)
	{	float fx = ((float)x - s)*s1, fy = ((float)y - s)*s1;  // -1..1

		float c = Noise(x*s1-oy, y*s1+ox, pSet->gen_freq, pSet->gen_oct, pSet->gen_persist) * 0.8f;  // par fit
		bool b = c >= 0.f;
		c = b ? powf(c, pSet->gen_pow) : -powf(-c, pSet->gen_pow);

		int i = b ? 0 : 1;  c = b ? c : -c;
		//c *= pSet->gen_scale;  //no
		
		uint8 bR = c * fR[i], bG = c * fG[i], bB = c * fB[i];
		*p++ = bR;  *p++ = bG;  *p++ = bB;  *p++ = 255;//bG > 32 ? 255 : 0;
	}
	pbuf->unlock();
}
Example #3
0
void WebView::createMaterial()
{
	if(opacity > 1) opacity = 1;
	else if(opacity < 0) opacity = 0;

	if(!Bitwise::isPO2(viewWidth) || !Bitwise::isPO2(viewHeight))
	{
		if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_NON_POWER_OF_2_TEXTURES))
		{
			if(Root::getSingleton().getRenderSystem()->getCapabilities()->getNonPOW2TexturesLimited())
				compensateNPOT = true;
		}
		else compensateNPOT = true;
#ifdef __APPLE__
//cus those fools always report #t when I ask if they support this or that
//and then fall back to their buggy and terrible software driver which has never once in my life rendered a single correct frame.
		compensateNPOT=true;
#endif
		if(compensateNPOT)
		{
			texWidth = Bitwise::firstPO2From(viewWidth);
			texHeight = Bitwise::firstPO2From(viewHeight);
		}
	}


	// Create the texture
#if defined(HAVE_AWESOMIUM) || !defined(__APPLE__)
	TexturePtr texture = TextureManager::getSingleton().createManual(
		viewName + "Texture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		TEX_TYPE_2D, texWidth, texHeight, 0, PF_BYTE_BGRA,
		TU_DYNAMIC_WRITE_ONLY_DISCARDABLE, this);

	HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
	pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox& pixelBox = pixelBuffer->getCurrentLock();
	texDepth = Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
	texPitch = (pixelBox.rowPitch*texDepth);

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

	memset(pDest, 128, texHeight*texPitch);

	pixelBuffer->unlock();
#endif
	MaterialPtr material = MaterialManager::getSingleton().create(viewName + "Material",
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	matPass = material->getTechnique(0)->getPass(0);
	matPass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
	matPass->setDepthWriteEnabled(false);

	baseTexUnit = matPass->createTextureUnitState(viewName + "Texture");

	baseTexUnit->setTextureFiltering(texFiltering, texFiltering, FO_NONE);
	if(texFiltering == FO_ANISOTROPIC)
		baseTexUnit->setTextureAnisotropy(4);
}
bool gkOgreCompositorHelper::createHalftoneTexture()
{
	using namespace Ogre;

	try 
	{
		if (TextureManager::getSingleton().resourceExists(COMP_HALFTONE_TEX_NAME)) 
			return true; //already created

		TexturePtr tex = TextureManager::getSingleton().createManual(
			COMP_HALFTONE_TEX_NAME,
			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_3D,
			64,64,64,
			0,
			PF_A8
		);

		HardwarePixelBufferSharedPtr ptr = tex->getBuffer(0,0);
		ptr->lock(HardwareBuffer::HBL_DISCARD);
		const PixelBox &pb = ptr->getCurrentLock();
		uint8 *data = static_cast<uint8*>(pb.data);

		size_t height = pb.getHeight();
		size_t width = pb.getWidth();
		size_t depth = pb.getDepth();
		size_t rowPitch = pb.rowPitch;
		size_t slicePitch = pb.slicePitch;

		for (size_t z = 0; z < depth; ++z)
		{
			for (size_t y = 0; y < height; ++y)
			{
				for(size_t x = 0; x < width; ++x)
				{
					float fx = 32-(float)x+0.5f;
					float fy = 32-(float)y+0.5f;
					float fz = 32-((float)z)/3+0.5f;
					float distanceSquare = fx*fx+fy*fy+fz*fz;
					data[slicePitch*z + rowPitch*y + x] =  0x00;
					if (distanceSquare < 1024.0f)
						data[slicePitch*z + rowPitch*y + x] +=  0xFF;
				}
			}
		}
		ptr->unlock();

		
	} 
	catch (Exception &e) 
	{
		gkPrintf("[CMP] FAILED - Halftone Texture Creation. %s", e.getFullDescription().c_str()); 
		return false;
	}
	
	return true;
}
void FlashControl::createMaterial()
{
	texture.setNull();
	MaterialManager::getSingletonPtr()->remove(name + "Material");
	TextureManager::getSingletonPtr()->remove(name + "Texture");

	texWidth = width;
	texHeight = height;
	if(!Bitwise::isPO2(width) || !Bitwise::isPO2(height))
	{
		if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_NON_POWER_OF_2_TEXTURES))
		{
			if(Root::getSingleton().getRenderSystem()->getCapabilities()->getNonPOW2TexturesLimited())
				compensateNPOT = true;
		}
		else compensateNPOT = true;
		
		if(compensateNPOT)
		{
			texWidth = Bitwise::firstPO2From(width);
			texHeight = Bitwise::firstPO2From(height);
		}
	}

	// Create the texture
	texture = TextureManager::getSingleton().createManual(
		name + "Texture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		TEX_TYPE_2D, (uint)texWidth, (uint)texHeight, 0, isTransparent? PF_BYTE_BGRA : PF_BYTE_BGR,
		TU_DYNAMIC_WRITE_ONLY_DISCARDABLE, this);

	HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
	pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox& pixelBox = pixelBuffer->getCurrentLock();
	texDepth = Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
	texPitch = (pixelBox.rowPitch*texDepth);

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

	memset(pDest, 128, texHeight*texPitch);

	pixelBuffer->unlock();

	materialName = name + "Material";

	MaterialPtr material = MaterialManager::getSingleton().create(materialName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	Pass* matPass = material->getTechnique(0)->getPass(0);
	matPass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
	matPass->setDepthWriteEnabled(false);

	texUnit = matPass->createTextureUnitState(name + "Texture");
	texUnit->setTextureFiltering(FO_NONE, FO_NONE, FO_NONE);

	invalidateTotally();

}
Example #6
0
void Sample_VolumeTex::generate()
{
    /* Evaluate julia fractal for each point */
    Julia julia(global_real, global_imag, global_theta);
    const float scale = 2.5;
    const float vcut = 29.0f;
    const float vscale = 1.0f/vcut;

    HardwarePixelBufferSharedPtr buffer = ptex->getBuffer(0, 0);
    Ogre::StringStream d;
    d << "HardwarePixelBuffer " << buffer->getWidth() << " " << buffer->getHeight() << " " << buffer->getDepth();
    LogManager::getSingleton().logMessage(d.str());

    buffer->lock(HardwareBuffer::HBL_NORMAL);
    const PixelBox &pb = buffer->getCurrentLock();
    d.str("");
    d << "PixelBox " << pb.getWidth() << " " << pb.getHeight() << " " << pb.getDepth() << " " << pb.rowPitch << " " << pb.slicePitch << " " << pb.data << " " << PixelUtil::getFormatName(pb.format);
    LogManager::getSingleton().logMessage(d.str());

    Ogre::uint32 *pbptr = static_cast<Ogre::uint32*>(pb.data);
    for(size_t z=pb.front; z<pb.back; z++)
    {
        for(size_t y=pb.top; y<pb.bottom; y++)
        {
            for(size_t x=pb.left; x<pb.right; x++)
            {
                if(z==pb.front || z==(pb.back-1) || y==pb.top|| y==(pb.bottom-1) ||
                        x==pb.left || x==(pb.right-1))
                {
                    // On border, must be zero
                    pbptr[x] = 0;
                }
                else
                {
                    float val = julia.eval(((float)x/pb.getWidth()-0.5f) * scale,
                                           ((float)y/pb.getHeight()-0.5f) * scale,
                                           ((float)z/pb.getDepth()-0.5f) * scale);
                    if(val > vcut)
                        val = vcut;

                    PixelUtil::packColour((float)x/pb.getWidth(), (float)y/pb.getHeight(), (float)z/pb.getDepth(), (1.0f-(val*vscale))*0.7f, PF_A8R8G8B8, &pbptr[x]);

                }
            }
            pbptr += pb.rowPitch;
        }
        pbptr += pb.getSliceSkip();
    }
    buffer->unlock();
}
void SaveImage(TexturePtr TextureToSave, String filename)
{
    HardwarePixelBufferSharedPtr readbuffer;
    readbuffer = TextureToSave->getBuffer(0, 0);
    readbuffer->lock(HardwareBuffer::HBL_NORMAL );
    const PixelBox &readrefpb = readbuffer->getCurrentLock();
    uchar *readrefdata = static_cast<uchar*>(readrefpb.data);

    Image img;
    img = img.loadDynamicImage (readrefdata, TextureToSave->getWidth(),
                                TextureToSave->getHeight(), TextureToSave->getFormat());
    img.save(filename);

    readbuffer->unlock();
}
Example #8
0
MaterialPtr Visuals::getMaterial(std::string name, int red, int green, int blue, int alpha) {

	// Create the texture
	TexturePtr texture = TextureManager::getSingleton().createManual(
		name,				// name
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		TEX_TYPE_2D,      // type
		256, 256,         // width & height
		0,                // number of mipmaps
		PF_BYTE_BGRA,     // pixel format
		TU_DEFAULT);      // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
	// textures updated very often (e.g. each frame)

	// Get the pixel buffer
	HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();

	// 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);

	// Fill in some pixel data. This will give a semi-transparent blue,
	// but this is of course dependent on the chosen pixel format.
	for (size_t j = 0; j < 256; j++) {
		for(size_t i = 0; i < 256; i++)
		{
			*pDest++ = blue; // B
			*pDest++ = green; // G
			*pDest++ = red; // R
			*pDest++ = alpha; // A
		}
	}

	// Unlock the pixel buffer
	pixelBuffer->unlock();

	MaterialPtr material = MaterialManager::getSingleton().create(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

	material->getTechnique(0)->getPass(0)->createTextureUnitState(name);
	material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);

	return material;
}
Example #9
0
/*	static MaterialPtr MakeDefaultMaterial()
	{
		const int def_width=256;
		const int def_height=256;
		const char*defTexName="DefaultTexture";
		const char*defMatName="DefaultMaterial";
		if( MaterialManager::getSingleton().resourceExists(defMatName))
			return (MaterialPtr)MaterialManager::getSingleton().getByName(defMatName);

		TexturePtr texture = TextureManager::getSingleton().createManual(
			defTexName, // name
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D,      // type
			def_width, def_height,         // width & height
			0,                // number of mipmaps
			PF_BYTE_RGBA,     // pixel format
			TU_DEFAULT);      // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
		// textures updated very often (e.g. each frame)
		// Get the pixel buffer
		HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
		// 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);

		// Fill in some pixel data. This will give a semi-transparent blue,
		// but this is of course dependent on the chosen pixel format.
		for (size_t j = 0; j < def_height; j++)
			for(size_t i = 0; i < def_width; i++)
			{
				*pDest++ = 255; // R
				*pDest++ =   0; // G
				*pDest++ = 255; // B
				*pDest++ = 255; // A
			}

			// Unlock the pixel buffer
			pixelBuffer->unlock();

			// Create a material using the texture
			MaterialPtr material = MaterialManager::getSingleton().create(
				defMatName, // name
				ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

			material->getTechnique(0)->getPass(0)->createTextureUnitState(defTexName);
			//material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
			return material;
	}
	MaterialPtr GetLodMaterial(const std::string& name)
	{
		std::string matname(name + ".Material");
		std::string texname(name + ".Texture");


		if( MaterialManager::getSingleton().resourceExists(matname))
			return (MaterialPtr)MaterialManager::getSingleton().getByName(matname);

		TexturePtr texture;
		int alpha = 0;
		if(TextureManager::getSingleton().resourceExists(texname))
		{
			texture=TextureManager::getSingleton().getByName(texname);
		}else
		{
			angel::pLodData ldata=angel::LodManager.LoadFile( name );
			BYTE*data= &((*ldata)[0]);
			if(!data)
				return MakeDefaultMaterial();
			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 MakeDefaultMaterial();
			if( unpsize2 && unpsize2 < unpsize1)
				return MakeDefaultMaterial();
			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 MakeDefaultMaterial();
			int width  = *(WORD*)(data+0x18);
			int height = *(WORD*)(data+0x1a);
			int imgsize = width*height;
			BYTE *pSrc=unpdata;


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


			// Get the pixel buffer
			HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();

			// 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);

			// Fill in some pixel data. This will give a semi-transparent blue,
			// but this is of course dependent on the chosen pixel format.
			for (int j = 0; j < width; j++)
				for(int i = 0; i < height; 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++ =   r; // G
					*pDest++ =   g; // R
					*pDest++ =   b;
					*pDest++ = a; // A
				}
				// Unlock the pixel buffer
				pixelBuffer->unlock();
		}
		// Create a material using the texture
		MaterialPtr material = MaterialManager::getSingleton().create(
			matname, // name
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

		material->getTechnique(0)->getPass(0)->createTextureUnitState(texname);
		if(alpha)
			material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
	}*/
	static TexturePtr GetDefaultTexture()
	{
		const int def_width=256;
		const int def_height=256;
		const char*defTexName="DefaultTexture";
		

		if( TextureManager::getSingleton().resourceExists(defTexName))
			return (TexturePtr )TextureManager::getSingleton().getByName(defTexName);
		angel::Log << "loading default texture" << angel::aeLog::endl;

		TexturePtr texture = TextureManager::getSingleton().createManual(
			defTexName, // name
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D,      // type
			def_width, def_height,         // width & height
			0,                // number of mipmaps
			PF_BYTE_RGBA,     // pixel format
			TU_DEFAULT);//|TU_AUTOMIPMAP);      // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
		// textures updated very often (e.g. each frame)
		// Get the pixel buffer
		HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
		// 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);

		// Fill in some pixel data. This will give a semi-transparent blue,
		// but this is of course dependent on the chosen pixel format.
		for (size_t j = 0; j < def_height; j++)
			for(size_t i = 0; i < def_width; i++)
			{
				*pDest++ = 255; // R
				*pDest++ =   0; // G
				*pDest++ = 255; // B
				*pDest++ = 255; // A
			}

			// Unlock the pixel buffer
			pixelBuffer->unlock();
			return texture;
	}
bool gkOgreCompositorHelper::createDitherTexture(int width, int height)
{
	using namespace Ogre;

	try 
	{
		if (TextureManager::getSingleton().resourceExists(COMP_DITHER_TEX_NAME)) 
			return true; //already created

		TexturePtr tex = TextureManager::getSingleton().createManual(
			COMP_DITHER_TEX_NAME,
			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D,
			width, height, 1,
			0,
			PF_A8
		);

		HardwarePixelBufferSharedPtr ptr = tex->getBuffer(0,0);
		ptr->lock(HardwareBuffer::HBL_DISCARD);
		const PixelBox &pb = ptr->getCurrentLock();
		uint8 *data = static_cast<uint8*>(pb.data);
		
		size_t height = pb.getHeight();
		size_t width = pb.getWidth();
		size_t rowPitch = pb.rowPitch;

		for (size_t y = 0; y < height; ++y)
			for(size_t x = 0; x < width; ++x)
				data[rowPitch*y + x] = (uint8)Ogre::Math::RangeRandom(64.0,192);

		ptr->unlock();

	} 
	catch (Exception &e) 
	{
		gkPrintf("[CMP] FAILED - Dither Texture Creation. %s", e.getFullDescription().c_str()); 
		return false;
	}

	return true;
}
void OgreText::setPanelColor(int R, int G, int B, int I)
{
    // Get the pixel buffer
    HardwarePixelBufferSharedPtr pixelBuffer = texture_->getBuffer();

    //directly modify pixel buffer in texture to change color

    // 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);
    *pDest++ = R;
    *pDest++ = G;
    *pDest++ = B;
    *pDest++ = I;

    // Unlock the pixel buffer
    pixelBuffer->unlock();
}
Example #12
0
void WebView::update()
{
#ifdef HAVE_AWESOMIUM
	if(maxUpdatePS)
		if(timer.getMilliseconds() - lastUpdateTime < 1000 / maxUpdatePS)
			return;

	updateFade();

	if(usingMask)
		baseTexUnit->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, fadeValue * opacity);
	else if(isWebViewTransparent)
		baseTexUnit->setAlphaOperation(LBX_BLEND_TEXTURE_ALPHA, LBS_MANUAL, LBS_TEXTURE, fadeValue * opacity);
	else
		baseTexUnit->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, fadeValue * opacity);

	if(!webView->isDirty())
		return;

	TexturePtr texture = TextureManager::getSingleton().getByName(viewName + "Texture");

	HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
	pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox& pixelBox = pixelBuffer->getCurrentLock();

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

	webView->render(destBuffer, (int)texPitch, (int)texDepth);

	if(isWebViewTransparent && !usingMask && ignoringTrans)
	{
		for(int row = 0; row < texHeight; row++)
			for(int col = 0; col < texWidth; col++)
				alphaCache[row * alphaCachePitch + col] = destBuffer[row * texPitch + col * 4 + 3];
	}

	pixelBuffer->unlock();

	lastUpdateTime = timer.getMilliseconds();
#endif
}
Example #13
0
void StandByState::convertIplToTexture(IplImage* img,TexturePtr texture)
{
    HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();//Get the Pixel Buffer for Texture
    pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);						//Lock the buffer
    const PixelBox& pixelBox = pixelBuffer->getCurrentLock();			//Get the pixel box for data pointer
    unsigned char* pDest = static_cast<unsigned char*>(pixelBox.data);
    unsigned char* videoPtr=(unsigned char*)(img->imageData);		//Get the pointer to the video frame

    for (int r=0; r<videoHeight; r++)
    {
        for(int c=0; c<videoWidth; c++)
        {
            for (int p=0; p<pix_size; p++)
                *(pDest++)=*(videoPtr++);//Copy the data
            if(pix_size==3)			//Ogre uses 4 bytes per pixel, so add an additional pass if video is RGB
                pDest++;
        }
        pDest+=empty_byte;			//If there are empty bytes at the end of the rows, add them to go to the correct location
        videoPtr+=empty_byte;
    }
    pixelBuffer->unlock();//Unlock the pixel buffer

}
Example #14
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;
	}
Example #15
0
void WebView::resize(int width, int height)
{
	if(width == viewWidth && height == viewHeight)
		return;

	viewWidth = width;
	viewHeight = height;

	int newTexWidth = viewWidth;
	int newTexHeight = viewHeight;

	if(!Bitwise::isPO2(viewWidth) || !Bitwise::isPO2(viewHeight))
	{
		if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_NON_POWER_OF_2_TEXTURES))
		{
			if(Root::getSingleton().getRenderSystem()->getCapabilities()->getNonPOW2TexturesLimited())
				compensateNPOT = true;
		}
		else compensateNPOT = true;
		compensateNPOT=true;
		if(compensateNPOT)
		{
			newTexWidth = Bitwise::firstPO2From(viewWidth);
			newTexHeight = Bitwise::firstPO2From(viewHeight);
		}
	}

	overlay->resize(viewWidth, viewHeight);
#ifdef HAVE_AWESOMIUM
	webView->resize(viewWidth, viewHeight);
#endif

    uint16 oldTexWidth = texWidth;
    uint16 oldTexHeight = texHeight;

    texWidth = newTexWidth;
    texHeight = newTexHeight;

    if (compensateNPOT) {
        Ogre::Real u1,v1,u2,v2;
        getDerivedUV(u1, v1,  u2,v2);
        overlay->panel->setUV(u1, v1, u2, v2);
    }

    if (texWidth == oldTexWidth && texHeight == oldTexHeight)
        return;

	matPass->removeAllTextureUnitStates();
	maskTexUnit = 0;
#if defined(HAVE_AWESOMIUM)|| !defined (__APPLE__)

	Ogre::TextureManager::getSingleton().remove(viewName + "Texture");

	TexturePtr texture = TextureManager::getSingleton().createManual(
		viewName + "Texture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		TEX_TYPE_2D, texWidth, texHeight, 0, PF_BYTE_BGRA,
		TU_DYNAMIC_WRITE_ONLY_DISCARDABLE, this);

	HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
	pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox& pixelBox = pixelBuffer->getCurrentLock();
	texDepth = Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
	texPitch = (pixelBox.rowPitch*texDepth);

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

	memset(pDest, 128, texHeight*texPitch);

	pixelBuffer->unlock();
#endif

	baseTexUnit = matPass->createTextureUnitState(viewName + "Texture");

	baseTexUnit->setTextureFiltering(texFiltering, texFiltering, FO_NONE);
	if(texFiltering == FO_ANISOTROPIC)
		baseTexUnit->setTextureAnisotropy(4);

	if(usingMask)
	{
		setMask(maskImageParameters.first, maskImageParameters.second);
	}
	else if(alphaCache)
	{
		delete[] alphaCache;
		alphaCache = new unsigned char[texWidth * texHeight];
		alphaCachePitch = texWidth;
	}
}
Example #16
0
void WebView::setMask(std::string maskFileName, std::string groupName)
{
	if(usingMask)
	{
		if(maskTexUnit)
		{
			matPass->removeTextureUnitState(1);
			maskTexUnit = 0;
		}

		if(!TextureManager::getSingleton().getByName(viewName + "MaskTexture").isNull())
			TextureManager::getSingleton().remove(viewName + "MaskTexture");
	}

	if(alphaCache)
	{
		delete[] alphaCache;
		alphaCache = 0;
	}

	if(maskFileName == "")
	{
		usingMask = false;
		maskImageParameters.first = "";
		maskImageParameters.second = "";

		if(isWebViewTransparent)
		{
			setTransparent(true);
			update();
		}

		return;
	}

	maskImageParameters.first = maskFileName;
	maskImageParameters.second = groupName;

	if(!maskTexUnit)
	{
		maskTexUnit = matPass->createTextureUnitState();
		maskTexUnit->setIsAlpha(true);
		maskTexUnit->setTextureFiltering(FO_NONE, FO_NONE, FO_NONE);
		maskTexUnit->setColourOperationEx(LBX_SOURCE1, LBS_CURRENT, LBS_CURRENT);
		maskTexUnit->setAlphaOperation(LBX_MODULATE);
	}

	Image srcImage;
	srcImage.load(maskFileName, groupName);

	Ogre::PixelBox srcPixels = srcImage.getPixelBox();
	unsigned char* conversionBuf = 0;

	if(srcImage.getFormat() != Ogre::PF_BYTE_A)
	{
		size_t dstBpp = Ogre::PixelUtil::getNumElemBytes(Ogre::PF_BYTE_A);
		conversionBuf = new unsigned char[srcImage.getWidth() * srcImage.getHeight() * dstBpp];
		Ogre::PixelBox convPixels(Ogre::Box(0, 0, srcImage.getWidth(), srcImage.getHeight()), Ogre::PF_BYTE_A, conversionBuf);
		Ogre::PixelUtil::bulkPixelConversion(srcImage.getPixelBox(), convPixels);
		srcPixels = convPixels;
	}

	TexturePtr maskTexture = TextureManager::getSingleton().createManual(
		viewName + "MaskTexture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		TEX_TYPE_2D, texWidth, texHeight, 0, PF_BYTE_A, TU_STATIC_WRITE_ONLY);

	HardwarePixelBufferSharedPtr pixelBuffer = maskTexture->getBuffer();
	pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox& pixelBox = pixelBuffer->getCurrentLock();
	size_t maskTexDepth = Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
	alphaCachePitch = pixelBox.rowPitch;

	alphaCache = new unsigned char[alphaCachePitch*texHeight];

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

	memset(buffer, 0, alphaCachePitch * texHeight);

	size_t minRowSpan = std::min(alphaCachePitch, srcPixels.rowPitch);
	size_t minHeight = std::min(texHeight, (unsigned short)srcPixels.getHeight());

	if(maskTexDepth == 1)
	{
		for(unsigned int row = 0; row < minHeight; row++)
			memcpy(buffer + row * alphaCachePitch, (unsigned char*)srcPixels.data + row * srcPixels.rowPitch, minRowSpan);

		memcpy(alphaCache, buffer, alphaCachePitch*texHeight);
	}
	else if(maskTexDepth == 4)
	{
		size_t destRowOffset, srcRowOffset, cacheRowOffset;

		for(unsigned int row = 0; row < minHeight; row++)
		{
			destRowOffset = row * alphaCachePitch * maskTexDepth;
			srcRowOffset = row * srcPixels.rowPitch;
			cacheRowOffset = row * alphaCachePitch;

			for(unsigned int col = 0; col < minRowSpan; col++)
				alphaCache[cacheRowOffset + col] = buffer[destRowOffset + col * maskTexDepth + 3] = ((unsigned char*)srcPixels.data)[srcRowOffset + col];
		}
	}
	else
	{
		OGRE_EXCEPT(Ogre::Exception::ERR_RT_ASSERTION_FAILED,
			"Unexpected depth and format were encountered while creating a PF_BYTE_A HardwarePixelBuffer. Pixel format: " +
                    StringConverter::toString((uint32)pixelBox.format) + ", Depth:" + StringConverter::toString(maskTexDepth), "WebView::setMask");
	}

	pixelBuffer->unlock();

	if(conversionBuf)
		delete[] conversionBuf;

	maskTexUnit->setTextureName(viewName + "MaskTexture");
	usingMask = true;
}
void FlashControl::update()
{
	if(isClean)
		return;

	int dirtyWidth = dirtyBounds.right - dirtyBounds.left;
	int dirtyHeight = dirtyBounds.bottom - dirtyBounds.top;
	int dirtyBufSize = dirtyWidth * dirtyHeight * 4;

	static int lastDirtyWidth = 0;
	static int lastDirtyHeight = 0;

	IViewObject* curView = 0;
	flashInterface->QueryInterface(IID_IViewObject, (void**)&curView);

	if(!oleObject || !curView)
		return;

	if(!mainContext || dirtyWidth != lastDirtyWidth || dirtyHeight != lastDirtyHeight)
	{
		if(mainContext)
		{
			DeleteDC(mainContext);
			mainContext = 0;
		}
		if(mainBitmap)
		{
			DeleteObject(mainBitmap);
			mainBitmap = 0;
		}
		
		lastDirtyWidth = dirtyWidth;
		lastDirtyHeight = dirtyHeight;

		HDC hdc = GetDC(0);
		BITMAPINFOHEADER bih = {0};
		bih.biSize = sizeof(BITMAPINFOHEADER);
		bih.biBitCount = 32;
		bih.biCompression = BI_RGB;
		bih.biPlanes = 1;
		bih.biWidth = dirtyWidth;
		bih.biHeight = -dirtyHeight;
		mainContext = CreateCompatibleDC(hdc);
		mainBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&mainBuffer, 0, 0);
		SelectObject(mainContext, mainBitmap);

		if(usingAlphaHack)
		{
			if(altContext)
			{
				DeleteDC(altContext);
				altContext = 0;
			}
			if(altBitmap)
			{
				DeleteObject(altBitmap);
				altBitmap = 0;
			}

			altContext = CreateCompatibleDC(hdc);
			altBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void **)&altBuffer, 0, 0);
			SelectObject(altContext, altBitmap);
		}

		ReleaseDC(0, hdc);
	}

	RECT local;
	local.left = -dirtyBounds.left;
	local.top = -dirtyBounds.top;
	local.right = local.left + dirtyBounds.right;
	local.bottom = local.top + dirtyBounds.bottom;

	if(!usingAlphaHack)
	{
		memset(mainBuffer, 0, dirtyBufSize);
		
		HRESULT hr = OleDraw(curView, DVASPECT_TRANSPARENT, mainContext, &local);
	}
	else 
	{
		memset(mainBuffer, 0, dirtyBufSize);
		memset(altBuffer, 255, dirtyBufSize);

		OleDraw(curView, DVASPECT_TRANSPARENT, mainContext, &local);
		OleDraw(curView, DVASPECT_TRANSPARENT, altContext, &local);

		// We've rendered the dirty area twice: once on black and once
		// on white. Now we compare the red channels of each to determine
		// the alpha value of each pixel.
		BYTE *blackBuffer, *whiteBuffer;
		blackBuffer = mainBuffer;
		whiteBuffer = altBuffer;
		BYTE blackRed, whiteRed;
		int size = dirtyWidth * dirtyHeight;
		for(int i = 0; i < size; i++)
		{
			blackRed = *blackBuffer;
			whiteRed = *whiteBuffer;
			blackBuffer += 3;
			whiteBuffer += 4;
			*blackBuffer++ = 255 - (whiteRed - blackRed);
		}
	}

	renderBuffer->copyArea(dirtyBounds, mainBuffer, dirtyWidth * 4);
	
	HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
	pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox& pixelBox = pixelBuffer->getCurrentLock();

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

	renderBuffer->blitBGR(destBuffer, (int)texPitch, (int)texDepth);

	pixelBuffer->unlock();

	isClean = true;
	isTotallyDirty = false;
}
	void LodTextureManager::loadResource(Ogre::Resource* res)
	{
		int alpha = 0;
		angel::Log << angel::aeLog::debug <<"loading texture " << res->getName() << angel::aeLog::endl;
		
		angel::pLodData ldata = angel::LodManager.LoadFileData( res->getName() );

//		angel::pLodData ldata=angel::LodManager.LoadFile( res->getName() );
		
		if(!ldata)
			return GetDefaultTexture(res);
		angel::pLodData hdr = angel::LodManager.LoadFileHdr( res->getName() );

		BYTE*data= &((*ldata)[0]);
		BYTE*hdrdata= &((*hdr)[0]);
		int size = (int)ldata->size();
		int psize = *(int*)(hdrdata+0x4);
		unsigned int unpsize1 = *(int*)(hdrdata+0x0);
		unsigned long unpsize2 = *(int*)(hdrdata+0x18);

		if( unpsize2+0x300 != size )
		{
			//angel::Log <<"texture " << res->getName() << " error datasize "  << unpsize2 << "/" << size<< angel::aeLog::endl;
			//return GetDefaultTexture(res);
			return loadSprite(res,hdr,ldata);
		}
//		if( unpsize2 && unpsize2 < unpsize1)
//			return GetDefaultTexture(res);
		BYTE* pal = data + unpsize2;
		int width  = *(WORD*)(hdrdata+0x8);
		int height = *(WORD*)(hdrdata+0xa);
		int imgsize = width*height;
		BYTE *pSrc=data;


/*		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(res);
		if( unpsize2 && unpsize2 < unpsize1)
			return GetDefaultTexture(res);
		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;
		int width  = *(WORD*)(data+0x18);
		int height = *(WORD*)(data+0x1a);
		int imgsize = width*height;
		BYTE *pSrc=unpdata;*/

		
		int nummipmaps = 3;
		// Create the texture
		Texture* texture = static_cast<Texture*>(res);
		texture->setTextureType(TEX_TYPE_2D);
		texture->setWidth(width);
		texture->setHeight(height);
		texture->setNumMipmaps(nummipmaps);
		texture->setFormat(PF_BYTE_BGRA);
		texture->setUsage(TU_DEFAULT);
		texture->setDepth(1);
		texture->setHardwareGammaEnabled(false);
		texture->setFSAA(0);
		texture->createInternalResources();

		/*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

	}
Example #19
0
//--------------------------------------------------------------------------
	void CompositorDemo::createTextures(void)
	{
		using namespace Ogre;

		TexturePtr tex = TextureManager::getSingleton().createManual(
			"HalftoneVolume",
			"General",
			TEX_TYPE_3D,
			64,64,64,
			0,
			PF_A8
		);

		HardwarePixelBufferSharedPtr ptr = tex->getBuffer(0,0);
		ptr->lock(HardwareBuffer::HBL_DISCARD);
		const PixelBox &pb = ptr->getCurrentLock();
		uint8 *data = static_cast<uint8*>(pb.data);

		size_t height = pb.getHeight();
		size_t width = pb.getWidth();
		size_t depth = pb.getDepth();
		size_t rowPitch = pb.rowPitch;
		size_t slicePitch = pb.slicePitch;

		for (size_t z = 0; z < depth; ++z)
		{
			for (size_t y = 0; y < height; ++y)
			{
				for(size_t x = 0; x < width; ++x)
				{
					float fx = 32-(float)x+0.5f;
					float fy = 32-(float)y+0.5f;
					float fz = 32-((float)z)/3+0.5f;
					float distanceSquare = fx*fx+fy*fy+fz*fz;
					data[slicePitch*z + rowPitch*y + x] =  0x00;
					if (distanceSquare < 1024.0f)
						data[slicePitch*z + rowPitch*y + x] +=  0xFF;
				}
			}
		}
		ptr->unlock();

		Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->getViewport(0); 

		TexturePtr tex2 = TextureManager::getSingleton().createManual(
			"DitherTex",
			"General",
			TEX_TYPE_2D,
			vp->getActualWidth(),vp->getActualHeight(),1,
			0,
			PF_A8
		);

		HardwarePixelBufferSharedPtr ptr2 = tex2->getBuffer(0,0);
		ptr2->lock(HardwareBuffer::HBL_DISCARD);
		const PixelBox &pb2 = ptr2->getCurrentLock();
		uint8 *data2 = static_cast<uint8*>(pb2.data);
		
		size_t height2 = pb2.getHeight();
		size_t width2 = pb2.getWidth();
		size_t rowPitch2 = pb2.rowPitch;

		for (size_t y = 0; y < height2; ++y)
		{
			for(size_t x = 0; x < width2; ++x)
			{
				data2[rowPitch2*y + x] = Ogre::Math::RangeRandom(64.0,192);
			}
		}
		
		ptr2->unlock();
	}
///  update brush preview texture
//--------------------------------------------------------------------------------------------------------------------------
void App::updateBrushPrv(bool first)
{
	if (!first && (!ovBrushPrv || edMode >= ED_Road /*|| bMoveCam/*|| !bEdit()*/))  return;
	if (!pSet->brush_prv || brushPrvTex.isNull())  return;

	//  Lock texture and fill pixel data
	HardwarePixelBufferSharedPtr pbuf = brushPrvTex->getBuffer();
	pbuf->lock(HardwareBuffer::HBL_DISCARD);
	const PixelBox& pb = pbuf->getCurrentLock();
	uint8* p = static_cast<uint8*>(pb.data);

	const float fB = brClr[edMode][0]*255.f, fG = brClr[edMode][1]*255.f, fR = brClr[edMode][2]*255.f;

	const float s = BrPrvSize * 0.5f, s1 = 1.f/s,
		fP = mBrPow[curBr], fQ = mBrFq[curBr]*5.f, nof = mBrNOf[curBr];
	int oct = mBrOct[curBr];	const float PiN = PI_d/oct;

	switch (mBrShape[curBr])
	{
	case BRS_Noise2:
		for (size_t y = 0; y < BrPrvSize; ++y)
		for (size_t x = 0; x < BrPrvSize; ++x)
		{	float fx = ((float)x - s)*s1, fy = ((float)y - s)*s1;  // -1..1
			float d = std::max(0.f, 1.f - float(sqrt(fx*fx + fy*fy)));  // 0..1

			float c = d * (1.0-pow( fabs(Noise(x*s1+nof,y*s1+nof, fQ, oct, 0.5f)), fP*d)) * (1.5f-fP*0.1);
			c = std::max(0.f, c);
			
			uint8 bR = c * fR, bG = c * fG, bB = c * fB;
			*p++ = bR;  *p++ = bG;  *p++ = bB;  *p++ = bG > 32 ? 255 : 0;
		}	break;

	case BRS_Noise:
		for (size_t y = 0; y < BrPrvSize; ++y)
		for (size_t x = 0; x < BrPrvSize; ++x)
		{	float fx = ((float)x - s)*s1, fy = ((float)y - s)*s1;  // -1..1
			float d = std::max(0.f, 1.f - float(sqrt(fx*fx + fy*fy)));  // 0..1

			float c = d * pow( fabs(Noise(x*s1+nof,y*s1+nof, fQ, oct, 0.5f)), fP*0.5f) * 0.9f;
			
			uint8 bR = c * fR, bG = c * fG, bB = c * fB;
			*p++ = bR;  *p++ = bG;  *p++ = bB;  *p++ = bG > 32 ? 255 : 0;
		}	break;

	case BRS_Sinus:
		for (size_t y = 0; y < BrPrvSize; ++y)
		for (size_t x = 0; x < BrPrvSize; ++x)
		{	float fx = ((float)x - s)*s1, fy = ((float)y - s)*s1;  // -1..1
			float d = std::max(0.f, 1.f - float(sqrt(fx*fx + fy*fy)));  // 0..1

			float c = powf( sinf(d * PI_d*0.5f), fP);
			
			uint8 bR = c * fR, bG = c * fG, bB = c * fB;
			*p++ = bR;  *p++ = bG;  *p++ = bB;  *p++ = bG > 32 ? 255 : 0;
		}	break;

	case BRS_Ngon:
		for (size_t y = 0; y < BrPrvSize; ++y)
		for (size_t x = 0; x < BrPrvSize; ++x)
		{	float fx = ((float)x - s)*s1, fy = ((float)y - s)*s1;  // -1..1
			float d = std::max(0.f, 1.f - float(sqrt(fx*fx + fy*fy)));  // 0..1
			float k = GetAngle(fx,fy);  // 0..2Pi

    		float c = std::max(0.f, std::min(1.f,
    			fQ * powf(fabs(d / (-1.f+nof + cosf(PiN) / cosf( fmodf(k, 2*PiN) - PiN ) )),fP) ));
			
			uint8 bR = c * fR, bG = c * fG, bB = c * fB;
			*p++ = bR;  *p++ = bG;  *p++ = bB;  *p++ = bG > 32 ? 255 : 0;
		}	break;

	case BRS_Triangle:
		for (size_t y = 0; y < BrPrvSize; ++y)
		for (size_t x = 0; x < BrPrvSize; ++x)
		{	float fx = ((float)x - s)*s1, fy = ((float)y - s)*s1;  // -1..1
			float d = std::max(0.f, 1.f - float(sqrt(fx*fx + fy*fy)));  // 0..1

			float c = powf( abs(d), fP);
			
			uint8 bR = c * fR, bG = c * fG, bB = c * fB;
			*p++ = bR;  *p++ = bG;  *p++ = bB;  *p++ = bG > 32 ? 255 : 0;
		}	break;
	}
	pbuf->unlock();
}
Example #21
0
void HTML::CreateMaterial(const std::string &name, bool destroyPrevious)
{
  using namespace Ogre;

  if(destroyPrevious)
  {
    static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(materialName))->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
    std::string texture_name = texture->getName();
    Ogre::TextureManager::getSingleton().remove(texture_name);
    texture = 0;
  }

  if(!Bitwise::isPO2(textureWidth) || !Bitwise::isPO2(textureHeight))
  {
	const Ogre::RenderSystemCapabilities* caps =  Root::getSingleton().getRenderSystem()->getCapabilities();
	if(caps && caps->hasCapability(RSC_NON_POWER_OF_2_TEXTURES))
	{
		if(Root::getSingleton().getRenderSystem()->getCapabilities()->getNonPOW2TexturesLimited())
			compensateNPOT = true;
    }
    else
		compensateNPOT = true;

    if(compensateNPOT)
    {
      textureWidth = Bitwise::firstPO2From(textureWidth);
      textureHeight = Bitwise::firstPO2From(textureHeight);
    }
  }
 //Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
  texture = Ogre::TextureManager::getSingleton().createManual(name + "_texture", MY_GROUP_NAME, Ogre::TEX_TYPE_2D, textureWidth, textureHeight, 0, // no mipmaps
    Ogre::PF_BYTE_BGRA, Ogre::TU_DYNAMIC).get();
    //Ogre::PF_BYTE_RGBA, Ogre::TU_DYNAMIC).get();
    //Ogre::PF_BYTE_RGBA, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE).get();

  // this clears buffer. may not be needed
  /**/
  HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
  pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
  const PixelBox& pixelBox = pixelBuffer->getCurrentLock();
  unsigned int texDepth = Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
  unsigned int texPitch = (pixelBox.rowPitch * texDepth);
  uint8* pDest = static_cast<uint8*>(pixelBox.data);
  memset(pDest, 0, textureHeight * texPitch);
  pixelBuffer->unlock();


  Ogre::MaterialPtr materialPtr;
  if(materialName == "")
  {
    materialName = name + "_mat";
//Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
    materialPtr = Ogre::MaterialManager::getSingletonPtr()->create(materialName, MY_GROUP_NAME);
  }
  else
    materialPtr = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(materialName));

  materialPtr->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
  // createTextureUnitState should take texture name of the texture we created!!!
  materialPtr->getTechnique(0)->getPass(0)->createTextureUnitState(name + "_texture");

  Ogre::Pass *matPass = materialPtr->getTechnique(0)->getPass(0);

  //matPass->setSeparateSceneBlending(SBF_ONE, SBF_ONE_MINUS_SOURCE_ALPHA, SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA);
  matPass->setDepthWriteEnabled(false);
}
Example #22
0
    TexturePtr TerrainManager::getVertexColours(ESM::Land* land,
                                                int cellX, int cellY,
                                                int fromX, int fromY, int size)
    {
        TextureManager* const texMgr = TextureManager::getSingletonPtr();

        const std::string colourTextureName = "VtexColours_" +
                                              boost::lexical_cast<std::string>(cellX) +
                                              "_" +
                                              boost::lexical_cast<std::string>(cellY) +
                                              "_" +
                                              boost::lexical_cast<std::string>(fromX) +
                                              "_" +
                                              boost::lexical_cast<std::string>(fromY);

        TexturePtr tex = texMgr->getByName(colourTextureName);
        if ( !tex.isNull() )
        {
            return tex;
        }

        tex = texMgr->createManual(colourTextureName,
                                   ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                   TEX_TYPE_2D, size, size, 0, PF_BYTE_BGR);

        HardwarePixelBufferSharedPtr pixelBuffer = tex->getBuffer();

        pixelBuffer->lock(HardwareBuffer::HBL_DISCARD);
        const PixelBox& pixelBox = pixelBuffer->getCurrentLock();

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

        if ( land != NULL )
        {
            const char* const colours = land->mLandData->mColours;
            for ( int y = 0; y < size; y++ )
            {
                for ( int x = 0; x < size; x++ )
                {
                    const size_t colourOffset = (y+fromY)*3*65 + (x+fromX)*3;

                    assert( colourOffset < 65*65*3 &&
                            "Colour offset is out of the expected bounds of record" );

                    const unsigned char r = colours[colourOffset + 0];
                    const unsigned char g = colours[colourOffset + 1];
                    const unsigned char b = colours[colourOffset + 2];

                    //as is the case elsewhere we need to flip the y
                    const size_t imageOffset = (size - 1 - y)*size*4 + x*4;
                    pDest[imageOffset + 0] = b;
                    pDest[imageOffset + 1] = g;
                    pDest[imageOffset + 2] = r;
                }
            }
        }
        else
        {
            for ( int y = 0; y < size; y++ )
            {
                for ( int x = 0; x < size; x++ )
                {
                    for ( int k = 0; k < 3; k++ )
                    {
                        *pDest++ = 0;
                    }
                }
            }
        }

        pixelBuffer->unlock();

        return tex;
    }
Example #23
0
//Parse sceneMetaData into UserTexture
void KinectDevice::ParseUserTexture(xn::SceneMetaData *sceneMetaData, bool m_front)
{
#if SHOW_DEPTH || SHOW_BAR
	//TexturePtr texture = TextureManager::getSingleton().getByName("MyDepthTexture");
	//TexturePtr texture = TextureManager::getSingleton().getByName("MyDepthTexture2");
	if(mUserTexture.isNull())
		return;
	// Get the pixel buffer
	HardwarePixelBufferSharedPtr pixelBuffer = mUserTexture->getBuffer();
	// Lock the pixel buffer and get a pixel box
	pixelBuffer->lock(HardwareBuffer::HBL_DISCARD); 
	const PixelBox& pixelBox = pixelBuffer->getCurrentLock();
	unsigned char* pDest = static_cast<unsigned char*>(pixelBox.data);

	// Get label map 
	const XnLabel* pUsersLBLs = sceneMetaData->Data();
		
	for (size_t j = 0; j < KINECT_DEPTH_HEIGHT; j++)
	{
		pDest = static_cast<unsigned char*>(pixelBox.data) + j*pixelBox.rowPitch*4;
#if SHOW_DEPTH
		for(size_t i = 0; i < KINECT_DEPTH_WIDTH; i++)
#elif SHOW_BAR
		for(size_t i = 0; i < 50; i++)
#endif
		{
			// fix i if we are mirrored
			uint fixed_i = i;
			if(!m_front)
			{
				fixed_i = KINECT_DEPTH_WIDTH - i;
			}

			// determine color
#if SHOW_DEPTH
			unsigned int color = GetColorForUser(pUsersLBLs[j*KINECT_DEPTH_WIDTH + fixed_i]);

			// if we have a candidate, filter out the rest
			if (m_candidateID != 0)
			{
				if  (m_candidateID == pUsersLBLs[j*KINECT_DEPTH_WIDTH + fixed_i])
				{
					color = GetColorForUser(1);
					if( j > KINECT_DEPTH_HEIGHT*(1 - m_pStartPoseDetector->GetDetectionPercent()))
					{
						//highlight user
						color |= 0xFF070707;
					}
					if( j < KINECT_DEPTH_HEIGHT*(m_pEndPoseDetector->GetDetectionPercent()))
					{	
						//hide user
						color &= 0x20F0F0F0;
					}
				}
				else
				{
					color = 0;
				}
			}
#elif SHOW_BAR
			// RED. kinda.
			unsigned int color = 0x80FF0000;
			if( j > KINECT_DEPTH_HEIGHT*(1 - m_pStartPoseDetector->GetDetectionPercent()))
			{
				//highlight user
				color |= 0xFF070707;
			}
			if( j < KINECT_DEPTH_HEIGHT*(m_pEndPoseDetector->GetDetectionPercent()))
			{	
				//hide user
				color &= 0x20F0F0F0;
			}

			if ((m_pStartPoseDetector->GetDetectionPercent() == 1) ||
				(m_pEndPoseDetector->GetDetectionPercent() == 1))
			{
				color = 0;
			}
#endif
				
			// write to output buffer
			*((unsigned int*)pDest) = color;
			pDest+=4;
		}
	}
	// Unlock the pixel buffer
	pixelBuffer->unlock();
#endif // SHOW_DEPTH
}