Exemplo n.º 1
0
    void GLTexture::loadImpl()
    {
        if( mUsage & TU_RENDERTARGET )
        {
            createRenderTexture();
            return;
        }

        // Now the only copy is on the stack and will be cleaned in case of
        // exceptions being thrown from _loadImages
        LoadedImages loadedImages = mLoadedImages;
        mLoadedImages.setNull();

        // Call internal _loadImages, not loadImage since that's external and 
        // will determine load status etc again
        ConstImagePtrList imagePtrs;
        for (size_t i=0 ; i<loadedImages->size() ; ++i) {
            imagePtrs.push_back(&(*loadedImages)[i]);
        }

        _loadImages(imagePtrs);


        // Generate mipmaps after all texture levels have been loaded
        // This is required for compressed formats such as DXT
        // If we can do automip generation and the user desires this, do so
        if((mUsage & TU_AUTOMIPMAP) &&
            mNumRequestedMipmaps && mMipmapsHardwareGenerated)
        {
            glGenerateMipmapEXT(getGLTextureTarget());
        }
    }
Exemplo n.º 2
0
    void GLES2Texture::loadImpl()
    {
        if (mUsage & TU_RENDERTARGET)
        {
            createRenderTexture();
            return;
        }

        // Now the only copy is on the stack and will be cleaned in case of
        // exceptions being thrown from _loadImages
        LoadedImages loadedImages = mLoadedImages;
        mLoadedImages.setNull();

        // Call internal _loadImages, not loadImage since that's external and 
        // will determine load status etc again
        ConstImagePtrList imagePtrs;

        for (size_t i = 0; i < loadedImages->size(); ++i)
        {
            imagePtrs.push_back(&(*loadedImages)[i]);
        }

        _loadImages(imagePtrs);

        if((mUsage & TU_AUTOMIPMAP) &&
           mNumRequestedMipmaps && mMipmapsHardwareGenerated)
        {
            OGRE_CHECK_GL_ERROR(glGenerateMipmap(getGLES2TextureTarget()));
        }
    }
Exemplo n.º 3
0
SPtr<RenderTexture> TextureManager::createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
        PixelFormat format, bool hwGamma, UINT32 multisampleCount,
        bool createDepth, PixelFormat depthStencilFormat)
{
    HTexture texture = Texture::create(textureType, width, height, 0, format, TU_RENDERTARGET, hwGamma, multisampleCount);

    HTexture depthStencil;
    if(createDepth)
    {
        depthStencil = Texture::create(TEX_TYPE_2D, width, height, 0, depthStencilFormat, TU_DEPTHSTENCIL, false, multisampleCount);
    }

    RENDER_TEXTURE_DESC desc;
    desc.colorSurface.texture = texture;
    desc.colorSurface.face = 0;
    desc.colorSurface.numFaces = 1;
    desc.colorSurface.mipLevel = 0;

    desc.depthStencilSurface.texture = depthStencil;
    desc.depthStencilSurface.face = 0;
    desc.depthStencilSurface.numFaces = 1;
    desc.depthStencilSurface.mipLevel = 0;

    SPtr<RenderTexture> newRT = createRenderTexture(desc);

    return newRT;
}
Exemplo n.º 4
0
    void GL3PlusTexture::loadImpl()
    {
        if (mUsage & TU_RENDERTARGET)
        {
            createRenderTexture();
            return;
        }

        // Now the only copy is on the stack and will be cleaned in case of
        // exceptions being thrown from _loadImages
        LoadedImages loadedImages = mLoadedImages;
        mLoadedImages.setNull();

        // Call internal _loadImages, not loadImage since that's external and 
        // will determine load status etc again
        ConstImagePtrList imagePtrs;

        for (size_t i = 0; i < loadedImages->size(); ++i)
        {
            imagePtrs.push_back(&(*loadedImages)[i]);
        }

        _loadImages(imagePtrs);

        // Generate mipmaps after all texture levels have been loaded
        // This is required for compressed formats such as DXT
        if (mUsage & TU_AUTOMIPMAP)
        {
            OGRE_CHECK_GL_ERROR(glGenerateMipmap(getGL3PlusTextureTarget()));
        }
    }
Exemplo n.º 5
0
    void GLTexture::loadImpl()
    {
        if( mUsage & TU_RENDERTARGET )
        {
            createRenderTexture();
            return;
        }

        // Now the only copy is on the stack and will be cleaned in case of
        // exceptions being thrown from _loadImages
        LoadedImages loadedImages = mLoadedImages;
        mLoadedImages.setNull();

        // Call internal _loadImages, not loadImage since that's external and 
        // will determine load status etc again
        ConstImagePtrList imagePtrs;
        for (size_t i=0 ; i<loadedImages->size() ; ++i) {
            imagePtrs.push_back(&(*loadedImages)[i]);
        }

        _loadImages(imagePtrs);

    }
Exemplo n.º 6
0
void Fluids::createBuffers()
{
	int tex_fmt = GL_R32F;
	int tex_int_fmt = GL_RED;
	frambuffer_ = createFrameBuffer();

	//velocity_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA);
	density_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	CHECK_GL_ERROR();
	velocity_accum_u_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	CHECK_GL_ERROR();
	velocity_accum_v_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	velocity_accum_ut_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	velocity_accum_vt_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);

	velocity_accum_u0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);	// 7
	velocity_accum_v0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); // 8
	velocity_accum_u0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	velocity_accum_v0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);

	//velocity_accum_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA );
	//velocity_accum2_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA );

	density_accum0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	density_accum0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	density_accum_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	density_accum_t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);

	//tex_fmt = GL_RGBA32F;
	//tex_int_fmt = GL_RGBA;
	p_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	p_prev_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);


	printf("density_accum: 1: %d 2: %d\n", density_accum0_, density_accum_);

	depth_ = createRenderBuffer(128, 128);
}
Exemplo n.º 7
0
int go()
{
    osg::setNotifyLevel(osg::NOTICE);

    //  ======================================================================

    //	Create root group node
	osg::Group* root = new osg::Group();

    //	Create groups
	osg::Group* group01 = new osg::Group();
	osg::Group* group02 = new osg::Group();

    //	Connect the two groups to the  root
	root->addChild(group01);
	root->addChild(group02);

    //  Create boxes and spheres
    osg::Box* box01 = new osg::Box(osg::Vec3f(0.0f,0.0f,0.0f),10.0f);
    osg::Box* box02 = new osg::Box(osg::Vec3f(0.0f,0.0f,0.0f),10.0f);
	osg::Sphere* sphere01 = new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),1.0f);
	osg::Sphere* sphere02 = new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),1.0f);

    osg::ShapeDrawable* box01Drawable = new osg::ShapeDrawable(box01);
    osg::ShapeDrawable* box02Drawable = new osg::ShapeDrawable(box02);
	osg::ShapeDrawable* sphere01Drawable = new osg::ShapeDrawable(sphere01);
	osg::ShapeDrawable* sphere02Drawable = new osg::ShapeDrawable(sphere02);

    osg::Group* mainSceneRoot = new osg::Group();

    osg::Geode* geode01 = new osg::Geode();
    osg::Geode* geode02 = new osg::Geode();

    geode01->addDrawable(sphere01Drawable);
    geode02->addDrawable(sphere02Drawable);

    //  ======================================================================

	osg::Node* model01 = osgDB::readNodeFile("data/models/cessna.osg");

	{
		osg::Program* program = loadProgram("data/shaders/simpleShader01");
		model01->getOrCreateStateSet()->setAttribute(program,osg::StateAttribute::ON);
	}

	//	Create RT textures
	osg::Texture2D* rttDepthTexture   = createDepthTexture (512,512);
	osg::Texture2D* rttColorTexture01 = createRenderTexture(512,512);
	osg::Texture2D* rttColorTexture02 = createRenderTexture(512,512);
	osg::Texture2D* rttColorTexture03 = createRenderTexture(512,512);
	//	Create RTT camera
	osg::Camera* rttCamera = createRenderTargetCamera(rttDepthTexture,rttColorTexture01,rttColorTexture02,rttColorTexture03);


	osg::MatrixTransform* modelTransform = new osg::MatrixTransform();
    modelTransform->addChild(model01);
	rttCamera->addChild(modelTransform);

	osg::NodeCallback* nc = new osg::AnimationPathCallback(modelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
    modelTransform->setUpdateCallback(nc);

	group01->addChild(rttCamera);

	//  ======================================================================

	osg::PositionAttitudeTransform* light01Transform = new osg::PositionAttitudeTransform();
	osg::PositionAttitudeTransform* light02Transform = new osg::PositionAttitudeTransform();

	light01Transform->setPosition(osg::Vec3(-20.0f, 0.0f, 0.0f));
	light02Transform->setPosition(osg::Vec3( 20.0f, 0.0f, 0.0f));

	light01Transform->addChild(geode01);
	light02Transform->addChild(geode02);

	rttCamera->addChild(light01Transform);
	rttCamera->addChild(light02Transform);

	osg::Uniform* light01Uniform = new osg::Uniform("uLight01Pos",osg::Vec4(-20.0f,0.0f,0.0f,1.0f));
	osg::Uniform* light02Uniform = new osg::Uniform("uLight02Pos",osg::Vec4( 20.0f,0.0f,0.0f,1.0f));

	rttCamera->getOrCreateStateSet()->addUniform(light01Uniform,osg::StateAttribute::ON);
	rttCamera->getOrCreateStateSet()->addUniform(light02Uniform,osg::StateAttribute::ON);

	//  ======================================================================
	//	Add 4 x ortho quads to the screen/scene

	//	Create 4 quads each one is a quarter of the screen.
	osg::Geode* fullScreenQuadGeode01 = createPlaneGeode( 0,	512, 512, 512);
	osg::Geode* fullScreenQuadGeode02 = createPlaneGeode( 512,	512, 512, 512);
	osg::Geode* fullScreenQuadGeode03 = createPlaneGeode( 0,	0,   512, 512);
	osg::Geode* fullScreenQuadGeode04 = createPlaneGeode( 512,	0,   512, 512);

	//	Create an orthographic camera and attach the 4 quads to it.
	osg::Camera* normalCamera = createNormalCamera();
	normalCamera->addChild(fullScreenQuadGeode01);
	normalCamera->addChild(fullScreenQuadGeode02);
	normalCamera->addChild(fullScreenQuadGeode03);
	normalCamera->addChild(fullScreenQuadGeode04);

	//	quad 01
	{
		osg::Program* program = loadProgram("data/shaders/colorTextureShader");
		osg::Uniform* uniformTex01 = new osg::Uniform("uTexture01",0);
		osg::StateSet* ss = new osg::StateSet();
		ss->setTextureAttributeAndModes(0,rttDepthTexture,osg::StateAttribute::ON);
		ss->setAttribute(program,osg::StateAttribute::ON);
		ss->addUniform(uniformTex01);
		fullScreenQuadGeode01->setStateSet(ss);
	}

	//	quad 02
	{
		osg::Program* program = loadProgram("data/shaders/colorTextureShader");
		osg::Uniform* uniformTex01 = new osg::Uniform("uTexture01",0);
		osg::StateSet* ss = new osg::StateSet();
		ss->setTextureAttributeAndModes(0,rttColorTexture01,osg::StateAttribute::ON);
		ss->setAttribute(program,osg::StateAttribute::ON);
		ss->addUniform(uniformTex01);
		fullScreenQuadGeode02->setStateSet(ss);
	}

	//	quad 03
	{
		osg::Program* program = loadProgram("data/shaders/colorTextureShader");
		osg::Uniform* uniformTex01 = new osg::Uniform("uTexture01",0);
		osg::StateSet* ss = new osg::StateSet();
		ss->setTextureAttributeAndModes(0,rttColorTexture02,osg::StateAttribute::ON);
		ss->setAttribute(program,osg::StateAttribute::ON);
		ss->addUniform(uniformTex01);
		fullScreenQuadGeode03->setStateSet(ss);
	}
	//	quad 04
	{
		osg::Program* program = loadProgram("data/shaders/lightingPass");
		osg::Uniform* uniformTexDepth  = new osg::Uniform("uDepthTex", 0);
		osg::Uniform* uniformTexColor  = new osg::Uniform("uColorTex", 1);
		osg::Uniform* uniformTexNormal = new osg::Uniform("uNormalTex",2);
		osg::StateSet* ss = new osg::StateSet();
		ss->setTextureAttributeAndModes(0,rttDepthTexture,osg::StateAttribute::ON);
		ss->setTextureAttributeAndModes(1,rttColorTexture01,osg::StateAttribute::ON);
		ss->setTextureAttributeAndModes(2,rttColorTexture02,osg::StateAttribute::ON);
		ss->setAttribute(program,osg::StateAttribute::ON);
		ss->addUniform(uniformTexDepth);
		ss->addUniform(uniformTexColor);
		ss->addUniform(uniformTexNormal);
		fullScreenQuadGeode04->setStateSet(ss);
	}

	group02->addChild(normalCamera);

    //  ======================================================================
	//	:D

    //	Create viewer
	osgViewer::Viewer viewer;
    //	Attach scene root node
	viewer.setSceneData(root);
	//	Setup window mode
	viewer.setUpViewInWindow( 50, 50, WINDOW_WIDTH, WINDOW_HEIGHT );
	//	Run! :)
	viewer.run();

	//  ======================================================================

    return EXIT_SUCCESS;
}
Exemplo n.º 8
0
    void GLTexture::loadImpl()
    {
        if( mUsage & TU_RENDERTARGET )
        {
            createRenderTexture();
        }
        else
        {
			String baseName, ext;
			size_t pos = mName.find_last_of(".");
			if( pos == String::npos )
				OGRE_EXCEPT(
					Exception::ERR_INVALIDPARAMS, 
					"Unable to load image file '"+ mName + "' - invalid extension.",
					"GLTexture::loadImpl" );

			baseName = mName.substr(0, pos);
			ext = mName.substr(pos+1);
    
			if(mTextureType == TEX_TYPE_1D || mTextureType == TEX_TYPE_2D || 
                mTextureType == TEX_TYPE_3D)
            {
                Image img;
	            // find & load resource data intro stream to allow resource
				// group changes if required
				DataStreamPtr dstream = 
					ResourceGroupManager::getSingleton().openResource(
						mName, mGroup, true, this);

                img.load(dstream, ext);

				// If this is a cube map, set the texture type flag accordingly.
                if (img.hasFlag(IF_CUBEMAP))
					mTextureType = TEX_TYPE_CUBE_MAP;
				// If this is a volumetric texture set the texture type flag accordingly.
				if(img.getDepth() > 1)
					mTextureType = TEX_TYPE_3D;

				// Call internal _loadImages, not loadImage since that's external and 
				// will determine load status etc again
				ConstImagePtrList imagePtrs;
				imagePtrs.push_back(&img);
				_loadImages( imagePtrs );
            }
            else if (mTextureType == TEX_TYPE_CUBE_MAP)
            {
				if(StringUtil::endsWith(getName(), ".dds"))
				{
					// XX HACK there should be a better way to specify whether 
					// all faces are in the same file or not
					Image img;
	            	// find & load resource data intro stream to allow resource
					// group changes if required
					DataStreamPtr dstream = 
						ResourceGroupManager::getSingleton().openResource(
							mName, mGroup, true, this);

	                img.load(dstream, ext);
					// Call internal _loadImages, not loadImage since that's external and 
					// will determine load status etc again
					ConstImagePtrList imagePtrs;
					imagePtrs.push_back(&img);
					_loadImages( imagePtrs );
				}
				else
				{
					std::vector<Image> images(6);
					ConstImagePtrList imagePtrs;
					static const String suffixes[6] = {"_rt", "_lf", "_up", "_dn", "_fr", "_bk"};
	
					for(size_t i = 0; i < 6; i++)
					{
						String fullName = baseName + suffixes[i] + "." + ext;
		            	// find & load resource data intro stream to allow resource
						// group changes if required
						DataStreamPtr dstream = 
							ResourceGroupManager::getSingleton().openResource(
								fullName, mGroup, true, this);
	
						images[i].load(dstream, ext);
						imagePtrs.push_back(&images[i]);
					}
	
					_loadImages( imagePtrs );
				}
            }
            else
                OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED, "**** Unknown texture type ****", "GLTexture::load" );
        }
    }