示例#1
0
    //---------------------------------------------------------------------
    TexturePtr ShadowTextureManager::getNullShadowTexture(PixelFormat format)
    {
        for (ShadowTextureList::iterator t = mNullTextureList.begin(); t != mNullTextureList.end(); ++t)
        {
            const TexturePtr& tex = *t;

            if (format == tex->getFormat())
            {
                // Ok, a match
                return tex;
            }
        }

        // not found, create a new one
        // A 1x1 texture of the correct format, not a render target
        static const String baseName = "Ogre/ShadowTextureNull";
        String targName = baseName + StringConverter::toString(mCount++);
        TexturePtr shadowTex = TextureManager::getSingleton().createManual(
            targName,
            ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
            TEX_TYPE_2D, 1, 1, 0, format, TU_STATIC_WRITE_ONLY);
        mNullTextureList.push_back(shadowTex);

        // lock & populate the texture based on format
        shadowTex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD);
        const PixelBox& box = shadowTex->getBuffer()->getCurrentLock();

        // set high-values across all bytes of the format
        PixelUtil::packColour( 1.0f, 1.0f, 1.0f, 1.0f, format, box.data );

        shadowTex->getBuffer()->unlock();

        return shadowTex;

    }
void PlaneNodeProcessor::createRenderToTextures(Ogre::Entity* entity, Plane* plane, MaterialPtr material, XERCES_CPP_NAMESPACE::DOMElement* rttElem)
{
    if(rttElem == NULL)
        return;

    Camera* cam = CoreSubsystem::getSingleton().getWorld()->getSceneManager()->createCamera("Cam" + entity->getName());
    cam->setNearClipDistance(CoreSubsystem::getSingleton().getWorld()->getActiveCamera()->getNearClipDistance());
    cam->setFarClipDistance(CoreSubsystem::getSingleton().getWorld()->getActiveCamera()->getFarClipDistance());
    //cam->setFarClipDistance(1000000);
    cam->setAspectRatio(CoreSubsystem::getSingleton().getWorld()->getActiveCamera()->getAspectRatio());
    cam->setFOVy(CoreSubsystem::getSingleton().getWorld()->getActiveCamera()->getFOVy());

    AliasTextureNamePairList aliases;

    if(getAttributeValueAsBool(rttElem, "reflection"))
    {
        TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "Reflection" + entity->getName(),
                             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,
                             512, 512, 0, PF_R8G8B8, TU_RENDERTARGET );
        RenderTexture* rttTex = texture->getBuffer()->getRenderTarget();

        Viewport *v = rttTex->addViewport( cam );
        v->setOverlaysEnabled(false);
        rttTex->addListener(new PlaneReflectionTextureListener(entity, cam, plane));

        aliases["reflection"] = "Reflection" + entity->getName();

        cam->enableCustomNearClipPlane((MovablePlane*)plane);
    }
    if(getAttributeValueAsBool(rttElem, "refraction"))
    {
        TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "Refraction" + entity->getName(),
                             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,
                             512, 512, 0, PF_R8G8B8, TU_RENDERTARGET );
        RenderTexture* rttTex = texture->getBuffer()->getRenderTarget();

        Viewport *v = rttTex->addViewport( cam);
        v->setOverlaysEnabled(false);
        rttTex->addListener(new PlaneRefractionTextureListener(entity, cam));

        aliases["refraction"] = "Refraction" + entity->getName();

        plane->normal = Vector3::NEGATIVE_UNIT_Y;
        cam->enableCustomNearClipPlane((MovablePlane*)plane);
    }
    if(!material->applyTextureAliases(aliases))
        LOG_ERROR("PLANE", "Texture Aliase konnten nicht angewandt werden");
}
示例#3
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;
}
示例#4
0
Dashboard::Dashboard() :
	  mDashCam(0)
	, mDashboardListener(0)
	, rttTex(0)
{
	TexturePtr rttTexPtr = TextureManager::getSingleton().createManual("dashtexture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 1024, 512, 0, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer());
	rttTex = rttTexPtr->getBuffer()->getRenderTarget();

	mDashCam = gEnv->sceneManager->createCamera("DashCam");
	mDashCam->setNearClipDistance(1.0);
	mDashCam->setFarClipDistance(10.0);
	mDashCam->setPosition(Vector3(0.0, -10000.0, 0.0));

	mDashCam->setAspectRatio(2.0);

	Viewport *v = rttTex->addViewport(mDashCam);
	v->setClearEveryFrame(true);
	v->setBackgroundColour(ColourValue::Black);
	//v->setOverlaysEnabled(false);

	MaterialPtr mat = MaterialManager::getSingleton().getByName("renderdash");
	mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("dashtexture");

	mDashboardListener = new DashboardListener();

	rttTex->addListener(mDashboardListener);

	mDashboardListener->dashOverlay     = OverlayManager::getSingleton().getByName("tracks/3D_DashboardOverlay");
	mDashboardListener->needlesOverlay  = OverlayManager::getSingleton().getByName("tracks/3D_NeedlesOverlay");
	mDashboardListener->blendOverlay    = OverlayManager::getSingleton().getByName("tracks/3D_BlendOverlay");
	mDashboardListener->truckHUDOverlay = OverlayManager::getSingleton().getByName("tracks/TruckInfoBox");
//	mDashboardListener->dbdebugOverlay  = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
//	mDashboardListener->dbeditorOverlay = OverlayManager::getSingleton().getByName("tracks/EditorOverlay");
}
bool SurveyMapTextureCreator::init()
{
	TexturePtr texture = TextureManager::getSingleton().createManual(getTextureName(), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 2048, 2048, TU_RENDERTARGET, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer());
	
	if ( texture.isNull() ) return false;;

	mRttTex = texture->getBuffer()->getRenderTarget();

	if ( !mRttTex ) return false;

	mRttTex->setAutoUpdated(false);

	mCamera = gEnv->sceneManager->createCamera(getCameraName());

	mViewport = mRttTex->addViewport(mCamera);
	mViewport->setBackgroundColour(ColourValue::Black);
	mViewport->setOverlaysEnabled(false);
	mViewport->setShadowsEnabled(false);
	mViewport->setSkiesEnabled(false);

	mMaterial = MaterialManager::getSingleton().create(getMaterialName(), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

	if ( mMaterial.isNull() ) return false;

	mTextureUnitState = mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(getTextureName());

	mRttTex->addListener(this);

	mCamera->setFixedYawAxis(false);
	mCamera->setProjectionType(PT_ORTHOGRAPHIC);
	mCamera->setNearClipDistance(1.0f);

	return true;
}
示例#6
0
void WaterRTT::create()
{
	if (!mSceneMgr)  return;
	mCamera = mSceneMgr->createCamera("PlaneReflectionRefraction");
	if (mViewerCamera)
	{
		mCamera->setFarClipDistance(mViewerCamera->getFarClipDistance());
		mCamera->setNearClipDistance(mViewerCamera->getNearClipDistance());
		mCamera->setAspectRatio(mViewerCamera->getAspectRatio());
	}
	
	for (unsigned int i = 0; i < 2; ++i)
	{
		if (i==0 && !mReflect) continue;
		if (i==1 && !mRefract) continue;
		
		TexturePtr tex = TextureManager::getSingleton().createManual(i == 0 ? "PlaneReflection" : "PlaneRefraction",
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, mRTTSize, mRTTSize, 0, PF_R8G8B8, TU_RENDERTARGET);

		RenderTarget* rtt = tex->getBuffer()->getRenderTarget();
		Viewport* vp = rtt->addViewport(mCamera);
		vp->setOverlaysEnabled(false);
		vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f));
		vp->setShadowsEnabled(false);
		vp->setMaterialScheme ("reflection");
		vp->setVisibilityMask( i == 0 ? RV_WaterReflect : RV_WaterRefract);
		rtt->addListener(this);

		if (i == 0) mReflectionTarget = rtt;
		else mRefractionTarget = rtt;
	}

	sh::Factory::getInstance ().setTextureAlias ("WaterReflection", "PlaneReflection");
	sh::Factory::getInstance ().setTextureAlias ("WaterRefraction", "PlaneRefraction");
}
示例#7
0
HeatHaze::HeatHaze(SceneManager *sceneMgr, RenderWindow *mWindow, Ogre::Camera *cam) : mSceneMgr(sceneMgr), rttTex(0), listener(0)
{
	TexturePtr rttTexPtr = TextureManager::getSingleton().createManual("heathaze_rtt", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, cam->getViewport()->getWidth(), cam->getViewport()->getHeight(), 0, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer());
	rttTex = rttTexPtr->getBuffer()->getRenderTarget();
	{
		/*
		// we use the main camera now
		mHazeCam = mSceneMgr->createCamera("Hazecam");
		mHazeCam->setNearClipDistance(1.0);
		mHazeCam->setFarClipDistance(1000.0);
		mHazeCam->setPosition(Vector3(0, 0, 0));
		*/

		//mHazeCam->setAspectRatio(2.0);

		// setup viewport
		Viewport *v = rttTex->addViewport(cam);
		//v->setClearEveryFrame(true);
		//v->setBackgroundColour(ColourValue::Black);
		v->setOverlaysEnabled(false);
		

		// setup projected material
		MaterialPtr mat = MaterialManager::getSingleton().getByName("tracks/HeatHazeMat");
		tex = mat->getTechnique(0)->getPass(0)->getTextureUnitState(1);
		tex->setTextureName("heathaze_rtt");
		tex->setProjectiveTexturing(true, cam);

		listener = new HeatHazeListener(mSceneMgr);
		rttTex->addListener(listener);
		rttTex->setAutoUpdated(false);
	}
}
示例#8
0
NxScreen * NxScreenManager::CreateExternalWindow( int MonitorID, bool FullScreen, unsigned int Width, unsigned int Height )
{
	//Viewport * mainviewport = NxEngine::getSingleton().GetNxViewport(); 
	//Log("Enabling Output Compositor...");
	//Ogre::CompositorManager::getSingleton().setCompositorEnabled( mainviewport , "NxCompositorOutput" , true );
	//Log("Enabling Output Compositor:Done");

	static bool Initialized = false;

	if( !Initialized )
	{
		TexturePtr tester = TextureManager::getSingleton().createManual( "RTT_Texture_100",
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
		32, 32, 0, Ogre::PF_BYTE_BGR, TU_RENDERTARGET  );

		mRenderTexture = tester->getBuffer(0,0)->getRenderTarget();
		mRenderTexture->setAutoUpdated( false );
		//Ogre::Viewport * NxViewport = mRenderTexture->addViewport( NxEngine::getSingleton().GetNxCamera() ); // view from main scene

		Ogre::Viewport * NxViewport = mRenderTexture->addViewport(  NxEngine::getSingleton().GetNxWindow()->GetViewport(0)->GetViewport()->getCamera( ) );
		Initialized = true;
	}
 
	NxScreen * Output = new NxScreen( MonitorID, FullScreen, Width, Height );
	MonitorListActive.push_back( Output );

	return Output ;
}
示例#9
0
 void CoverageMap::updateTexture()
 {
   // write the edit buffer into the texture's pixel buffer
   HardwarePixelBufferSharedPtr buffer = mTexture->getBuffer();
   PixelBox pixelBox (mWidth, mHeight, 1, getFormat(mChannels), mData);
   Image::Box imageBox (0, 0, mWidth, mHeight);
   buffer->blitFromMemory(pixelBox, imageBox);
 }
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;
}
示例#11
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);
}
示例#12
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();
}
示例#13
0
	//---------------------------------------------------------------------
	RenderTexture * RenderSystem::createRenderTexture( const String & name, 
		unsigned int width, unsigned int height,
		TextureType texType, PixelFormat internalFormat, const NameValuePairList *miscParams )
	{
		/// Create a new 2D texture, and return surface to render to
        TexturePtr mTexture = TextureManager::getSingleton().createManual( name, 
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, texType, 
			width, height, 0, internalFormat, TU_RENDERTARGET );
            
        // Ensure texture loaded and internal resources created
        mTexture->load();

        return mTexture->getBuffer()->getRenderTarget();
	}
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();
}
示例#15
0
void OgreRTT::setup(Ogre::SceneManager *inSceneMgr, Ogre::RenderWindow *inWindow, Ogre::Camera *inCamera)
{
    mSceneMgr = inSceneMgr;
    mWindow = inWindow;
    mCamera = inCamera;

    using namespace Ogre;
    TexturePtr mTexture =
        TextureManager::getSingleton().createManual(
            "RttTex_" + gUID,
            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            TEX_TYPE_2D,
            mWindow->getWidth(),
            mWindow->getHeight(),
            0,
            Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);


    mRenderTexture = mTexture->getBuffer()->getRenderTarget();

    mViewport = mRenderTexture->addViewport(mCamera);
    mViewport->setVisibilityMask(GfxEngine::ENTITY_MASK);
    mViewport->setClearEveryFrame(true);
    mViewport->setBackgroundColour(Ogre::ColourValue::Black);
    mViewport->setOverlaysEnabled(false);

    // Create the rectangle
    mMiniScreen = new Ogre::Rectangle2D(true);
    mMiniScreen->setCorners(0.5f, -0.5f, 1.0f, -1.0f);
    mMiniScreen->setBoundingBox(Ogre::AxisAlignedBox(-100000.0f * Ogre::Vector3::UNIT_SCALE, 100000.0f * Ogre::Vector3::UNIT_SCALE));

    mSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("MiniScreenNode_" + gUID);
    mSceneNode->attachObject(mMiniScreen);

    // Create the material
    mMatPtr = Ogre::MaterialManager::getSingleton().create("RttMat_" + gUID, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    mMatTechnique = mMatPtr->createTechnique();
    mMatTechnique->createPass();
    mMatPtr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    mMatPtr->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex_" + gUID);

    mMiniScreen->setMaterial("RttMat_" + gUID);

    ++gUID;

    GfxEngine::getSingletonPtr()->attachRTT(this);
}
示例#16
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;
}
示例#17
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));
         }
     }
 }
示例#18
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;
}
示例#20
0
	//---------------------------------------------------------------------------
	void WorldViewWindow::requestUpdateCanvas(MyGUI::Canvas* _canvas, MyGUI::Canvas::Event _event)
	{
		if (_event.textureChanged || _event.requested)
		{
			TexturePtr texture = MyGUITextureUtil::textureFromMyGUI(mCanvas->getTexture());
			RenderTexture* target = texture->getBuffer()->getRenderTarget();

			if (mRenderTarget != target && target != nullptr)
			{
				mRenderTarget = target;
				mRenderTarget->removeAllViewports();

				mCamera = mWorld->getCamera();
				mViewport = mRenderTarget->addViewport(mCamera, -1);
				mViewport->setClearEveryFrame(true);
				mViewport->setOverlaysEnabled(false);
				mWorld->setViewport(mViewport);
			}
		}
	}
Ogre::TexturePtr OgrePlanarReflectionMaterial::createRenderTargetTexture(Ogre::Camera& camera)
{
    using namespace Ogre;
    std::ostringstream s;
    s << "Rtt[" << numInstances << "]";
    TexturePtr texture = TextureManager::getSingleton().createManual(
            s.str(),
            "General",
            Ogre::TEX_TYPE_2D,
            resolutionTexture.getValue().elems[0],
            resolutionTexture.getValue().elems[1],
            0,
            PF_R8G8B8,
            Ogre::TU_RENDERTARGET);
    Ogre::RenderTarget* rtt = texture->getBuffer()->getRenderTarget();
    Ogre::Viewport* v = rtt->addViewport( &camera );
    v->setClearEveryFrame(true);
    v->setBackgroundColour( Ogre::ColourValue::Black );
    return texture;
}
示例#22
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
}
示例#23
0
    //-----------------------------------------------------------------------------------
    RenderTarget* CompositorPass::calculateRenderTarget( size_t rtIndex,
                                                         const CompositorChannel &source )
    {
        RenderTarget *retVal;

        if( !source.isMrt() && !source.textures.empty() &&
            source.textures[0]->getTextureType() > TEX_TYPE_2D )
        {
            //Who had the bright idea of handling Cubemaps differently
            //than 3D textures is a mystery. Anyway, deal with it.
            TexturePtr texturePtr = source.textures[0];

            if( rtIndex >= texturePtr->getDepth() && rtIndex >= texturePtr->getNumFaces() )
            {
                size_t maxRTs = std::max<size_t>( source.textures[0]->getDepth(),
                                                    source.textures[0]->getNumFaces() );
                OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
                        "Compositor pass is asking for a 3D/Cubemap/2D_array texture with "
                        "more faces/depth/slices than what's been supplied (Asked for slice '" +
                        StringConverter::toString( rtIndex ) + "', RT has '" +
                        StringConverter::toString( maxRTs ) + "')",
                        "CompositorPass::calculateRenderTarget" );
            }

            /*//If goes out bounds, will reference the last slice/face
            rtIndex = std::min( rtIndex, std::max( source.textures[0]->getDepth(),
                                                    source.textures[0]->getNumFaces() ) - 1 );*/

            TextureType textureType = texturePtr->getTextureType();
            size_t face = textureType == TEX_TYPE_CUBE_MAP ? rtIndex : 0;
            size_t slice= textureType != TEX_TYPE_CUBE_MAP ? rtIndex : 0;
            retVal = texturePtr->getBuffer( face )->getRenderTarget( slice );
        }
        else
        {
            retVal = source.target;
        }

        return retVal;
    }
示例#24
0
	Terrain* SnowTerrain::getTerrain()
	{
		if(!mTerrainGroup) return NULL;

		Terrain *t =  mTerrainGroup->getTerrain(0,0);
		return t;

		TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
		while (ti.hasMoreElements())
		{
			Ogre::uint32 tkey = ti.peekNextKey();
			TerrainGroup::TerrainSlot* ts = ti.getNext();
			if (ts->instance && ts->instance->isLoaded())
			{

				float* heights = ts->instance->getHeightData();

				//PixelBox* pBox = ts->instance->calculateNormals());
				TexturePtr texturePtr = ts->instance->getTerrainNormalMap();
				HardwarePixelBufferSharedPtr buf = texturePtr->getBuffer();

				size_t bytes = buf->getSizeInBytes();
				size_t h = buf->getHeight();
				size_t w = buf->getWidth();
				size_t d = buf->getDepth();
				PixelFormat f = PF_BYTE_RGB;//buf->getFormat();


				uint8* tmpData = (uint8*)OGRE_MALLOC(w * h * 3, MEMCATEGORY_GENERAL);
				memset(tmpData,0,w*h*3);
				PixelBox pBox(w, h, d, f, tmpData);
				buf->blitToMemory(pBox);
				OGRE_FREE(tmpData, MEMCATEGORY_GENERAL);
				
			}
		}
		return NULL;
	}
示例#25
0
KDvoid Sample_Fresnel::setupWater ( KDvoid )
{
    // create our reflection & refraction render textures, and setup their render targets
    for ( KDuint i = 0; i < 2; i++ )
    {
        TexturePtr  pTex = TextureManager::getSingleton ( ).createManual
        (
            i == 0 ? "refraction" : "reflection",
            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 512, 512, 0, PF_R8G8B8, TU_RENDERTARGET
        );
        
        RenderTarget*  pRtt = pTex->getBuffer ( )->getRenderTarget ( );
        pRtt->addViewport ( m_pCamera )->setOverlaysEnabled ( false );
        pRtt->addListener ( this );
        
        if ( i == 0 )
        {
            m_pRefractionTarget = pRtt;
        }
        else
        {
            m_pReflectionTarget = pRtt;
        }
    }
    
    // create our water plane mesh
    m_tWaterPlane = Plane ( Vector3::UNIT_Y, 0 );
    MeshManager::getSingleton ( ).createPlane
    (
        "water", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        m_tWaterPlane, 700, 1300, 10, 10, true, 1, 3, 5, Vector3::UNIT_Z
    );
    
    // create a water entity using our mesh, give it the shader material, and attach it to the origin
    m_pWater = m_pSceneMgr->createEntity ( "Water", "water" );
    m_pWater->setMaterialName ( "Examples/FresnelReflectionRefraction" );
    m_pSceneMgr->getRootSceneNode ( )->attachObject ( m_pWater );
}
示例#26
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

}
示例#27
0
//-----------------------------------------------------------------------------
void LLEmotionProcessor::startLogFile()
{
	struct tm *pTime;
	char logFileName[256];
	time_t ctTime; time(&ctTime);
	pTime = localtime( &ctTime );
#ifdef _WINDOWS
	sprintf(logFileName, "log\\LLAffectLog_%i\-%02i\-%02i_%02i\-%02i\-%02i.log", (1900+pTime->tm_year), (1+pTime->tm_mon), pTime->tm_mday, pTime->tm_hour, pTime->tm_min, pTime->tm_sec);
#else
	sprintf(logFileName, "log/LLAffectLog_%i\-%02i\-%02i_%02i\-%02i\-%02i.log", (1900+pTime->tm_year), (1+pTime->tm_mon), pTime->tm_mday, pTime->tm_hour, pTime->tm_min, pTime->tm_sec);
#endif
	if (m_logFile = fopen(logFileName, "w"))
	{
		fprintf(m_logFile, "==========================================================================\n");
		fprintf(m_logFile, "LifeLike Affect Log. Ver.0.1\n");
		time_t rawtime;
		struct tm * timeinfo;
		time(&rawtime);
		timeinfo = localtime (&rawtime);
		fprintf(m_logFile, "%s", asctime(timeinfo));
		fprintf(m_logFile, "==========================================================================\n");
		fprintf(m_logFile, "time	Pleasure	Arousal	Dominance\n");
		fprintf(m_logFile, "==========================================================================\n");
		m_fLogTimer = 0.0f;
	}

	// create our dynamic texture with 8-bit luminance texels
	TexturePtr tex = TextureManager::getSingleton().createManual("PADImage", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D, PADWIDTH, PADHEIGHT, 0, PF_BYTE_RGBA, TU_DYNAMIC_WRITE_ONLY);
	
	m_pTexBuf = tex->getBuffer();  // save off the texture buffer
	// initialise the texture to have full luminance
	m_pTexBuf->lock(HardwareBuffer::HBL_DISCARD);
	memset(m_pTexBuf->getCurrentLock().data, 0x00, m_pTexBuf->getSizeInBytes());
	m_pTexBuf->unlock();
}
示例#28
0
//-----------------------------------------------------------------------
void CompositorInstance::createResources()
{
static size_t dummyCounter = 0;
    freeResources();
    /// Create temporary textures
    /// In principle, temporary textures could be shared between multiple viewports
    /// (CompositorChains). This will save a lot of memory in case more viewports
    /// are composited.
    CompositionTechnique::TextureDefinitionIterator it = mTechnique->getTextureDefinitionIterator();
    while(it.hasMoreElements())
    {
        CompositionTechnique::TextureDefinition *def = it.getNext();

        /// Determine width and height
        int width = def->width.adjust +
            static_cast<int>(mChain->getViewport()->getActualWidth() * def->width.viewport) +
            static_cast<int>(mChain->getViewport()->getActualWidth() * def->width.previous);    // FIXME
        int height = def->height.adjust +
            static_cast<int>(mChain->getViewport()->getActualHeight() * def->height.viewport) +
            static_cast<int>(mChain->getViewport()->getActualHeight() * def->height.previous);  // FIXME
        if (width <= 0)
        {
            // Throw exception? Not that case, because user can't guarantee
            // provides correct parameters always, since it might related to
            // viewport dimensions which can't control by user all the way.
            width = 1;
        }
        if (height <= 0)
        {
            // Throw exception? Not that case, because user can't guarantee
            // provides correct parameters always, since it might related to
            // viewport dimensions which can't control by user all the way.
            height = 1;
        }

        /// Make the tetxure
        TexturePtr tex = TextureManager::getSingleton().createManual(
            "CompositorInstanceTexture"+StringConverter::toString(dummyCounter), 
            ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 
            (uint)width, (uint)height, 0, def->format, TU_RENDERTARGET );    
        ++dummyCounter;
        mLocalTextures[def->name] = tex;
        
        /// Set up viewport over entire texture
        RenderTexture *rtt = tex->getBuffer()->getRenderTarget();
        rtt->setAutoUpdated( false );

        Camera* camera = mChain->getViewport()->getCamera();

        // Save last viewport and current aspect ratio
        Viewport* oldViewport = camera->getViewport();
        Real aspectRatio = camera->getAspectRatio();

        Viewport* v = rtt->addViewport( camera );
        v->setClearEveryFrame( false );
        v->setOverlaysEnabled( false );
        v->setBackgroundColour( ColourValue( 0, 0, 0, 0 ) );

        // Should restore aspect ratio, in case of auto aspect ratio
        // enabled, it'll changed when add new viewport.
        camera->setAspectRatio(aspectRatio);
        // Should restore last viewport, i.e. never disturb user code
        // which might based on that.
        camera->_notifyViewport(oldViewport);
    }
    
}
示例#29
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;
	}
}
示例#30
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;
}