Ejemplo n.º 1
0
//------------------------------------------------------
void MaterialService::prepareMaterialInstance(MaterialPtr &mat,
                                              unsigned int idx, int tag) {
    if (tag < 0) // Should not be here if the polygon is sky textured
        OPDE_EXCEPT("Non-instanced material instance requested");

    mat->setReceiveShadows(true);

    Ogre::StringStream lightmapName;
    lightmapName << "@lightmap" << tag;

    Pass *shadPass = mat->getTechnique(0)->getPass(0);

    if (shadPass->getNumTextureUnitStates() <= 1) {
        // Lightmap texture is added here
        TextureUnitState *tex = shadPass->createTextureUnitState();
        tex->setTexture(mLightService->getAtlasTexture(tag));

        // Blend
        tex->setColourOperation(LBO_MODULATE);
        // Use 2nd texture co-ordinate set
        tex->setTextureCoordSet(1);

        // Clamp
        tex->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);

        // Switch filtering off to see lmap pixels: TFO_NONE
        tex->setTextureFiltering(TFO_BILINEAR);
    } else {
        // There is a definition of the lightmapping pass already, we only
        // update that definition
        TextureUnitState *tex = shadPass->getTextureUnitState(1);
        tex->setTextureName(lightmapName.str());
        tex->setTextureCoordSet(1);
    }
}
Ejemplo n.º 2
0
void Game::parseCmdLine(const mkString& cmd_line)
{
    std::vector<mkString> tokens;
    extractTokens(cmd_line, tokens);

    for (size_t i = 0; i < tokens.size(); ++i)
    {
        const mkString& token = tokens[i];
        const mkString* next_token_ptr = (i < tokens.size() - 1) ? &tokens[i+1] : NULL;

        if (token == "-freelook")
            m_startWithFreelook = true;
        else if (token == "-disable_shadows")
            m_disableShadows = true;
        else if (token == "-level")
        {
            CHK_ARG("-level");
            m_levelName = *next_token_ptr;
            ++i;
        }
        else
        {
            Ogre::StringStream ss;
            ss << "Unrecognized command line parameter '" << token << "'";
            MessageBoxA(NULL, ss.str().c_str(), NULL, MB_OK);
        }
    }
}
//--------------------------------------------------------------------------
	bool CompositorDemo_FrameListener::keyPressed (const OIS::KeyEvent &e)
    {
        // give 'quitting' priority
		if (e.key == OIS::KC_ESCAPE)
        {
            mQuit = true;
            return false;
        }

		if (e.key == OIS::KC_V)
			mMain->getRenderWindow()->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0,1,0));

        if (e.key == OIS::KC_SYSRQ )
        {
			Ogre::StringStream ss;
            ss << "screenshot_" << ++mNumScreenShots << ".png";
            mMain->getRenderWindow()->writeContentsToFile(ss.str());
            mDebugText = "Saved: " + ss.str();
			//mTimeUntilNextToggle = 0.5;
        }

        // do event injection
        CEGUI::System& cegui = CEGUI::System::getSingleton();
        cegui.injectKeyDown(e.key);
		cegui.injectChar(e.text);
		return true;
    }
Ejemplo n.º 4
0
Ogre::String OgreBuilding::getUniqueObjectName()
{
  /* Generate unique alias for naming Ogre entities */
  static int roadNumber = 0;
  Ogre::StringStream convertor;
  convertor << roadNumber;
  roadNumber++;

  return "Building_" + convertor.str();
}
Ejemplo n.º 5
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();
}
Ejemplo n.º 6
0
    //-----------------------------------------------------------------------
    String RenderTarget::writeContentsToTimestampedFile(const String& filenamePrefix, const String& filenameSuffix)
    {
        struct tm *pTime;
        time_t ctTime; time(&ctTime);
        pTime = localtime( &ctTime );
        Ogre::StringStream oss;
        oss << std::setw(2) << std::setfill('0') << (pTime->tm_mon + 1)
            << std::setw(2) << std::setfill('0') << pTime->tm_mday
            << std::setw(2) << std::setfill('0') << (pTime->tm_year + 1900)
            << "_" << std::setw(2) << std::setfill('0') << pTime->tm_hour
            << std::setw(2) << std::setfill('0') << pTime->tm_min
            << std::setw(2) << std::setfill('0') << pTime->tm_sec
            << std::setw(3) << std::setfill('0') << (mTimer->getMilliseconds() % 1000);
        String filename = filenamePrefix + oss.str() + filenameSuffix;
        writeContentsToFile(filename);
        return filename;

    }
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------------
void Sample_Compositor::changePage(size_t pageNum)
{
	assert(pageNum < mNumCompositorPages);
	
	mActiveCompositorPage = pageNum;
	size_t maxCompositorsInPage = mCompositorNames.size() - (pageNum * COMPOSITORS_PER_PAGE);
	for (size_t i=0; i < COMPOSITORS_PER_PAGE; i++)
	{
		String checkBoxName = "Compositor_" + Ogre::StringConverter::toString(i);
		CheckBox* cb = static_cast<CheckBox*>(mTrayMgr->getWidget(TL_TOPLEFT, checkBoxName));
		if (i < maxCompositorsInPage)
		{
			String compositorName = mCompositorNames[pageNum * COMPOSITORS_PER_PAGE + i];
			CompositorInstance *tmpCompo = CompositorManager::getSingleton().getCompositorChain(mViewport)
				->getCompositor(compositorName);

			cb->setCaption(compositorName);

			if( tmpCompo )
			{
				cb->setChecked( tmpCompo->getEnabled(), false );
				cb->show();
			}
			else
			{
				cb->setChecked( false, false );
				cb->hide();
			}

		}
		else
		{
			cb->hide();
		}
	}

	OgreBites::Button* pageButton = static_cast<OgreBites::Button*>(mTrayMgr->getWidget(TL_TOPLEFT, "PageButton"));
	Ogre::StringStream ss;
	ss << "Compositors " << pageNum + 1 << "/" << mNumCompositorPages;
	pageButton->setCaption(ss.str());
}
	//-----------------------------------------------------------------------
	CoherentUIView::CoherentUIView(Ogre::CoherentUIViewListener* listener, int width, int height, bool enableDepthWrite)
		: mView(NULL)
	{
		mViewListener = OGRE_NEW CoherentUIViewListenerBridge(this, listener);

		static int _textureCounter = 0;
		Ogre::StringStream ss;
		ss << "CoherentDynamicTexture" << ++_textureCounter;
		Ogre::String textureName = ss.str();
		ss << "_Mat";
		Ogre::String materialName = ss.str();

		// Create a texture
		mTexture = TextureManager::getSingleton().createManual(
			textureName,
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			TEX_TYPE_2D,
			width,
			height,
			1,
			PF_BYTE_BGRA,
			TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

		// Clear the texture
		Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture->getBuffer();
		pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
		const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
		Ogre::uint32* dest = static_cast<Ogre::uint32*>(pixelBox.data);
		std::memset(dest, 0, (width * 4 + pixelBox.getRowSkip()) * height);
		pixelBuffer->unlock();

		// Create a material using the texture
		mTextureMaterial = MaterialManager::getSingleton().create(
			materialName,
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

		mTextureMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(textureName);
		mTextureMaterial->getTechnique(0)->getPass(0)->setSceneBlending(SBF_ONE, SBF_ONE_MINUS_SOURCE_ALPHA);
		mTextureMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(enableDepthWrite);
	}
Ejemplo n.º 9
0
//------------------------------------------------------
Ogre::MaterialPtr MaterialService::getWorldMaterialInstance(unsigned int idx,
                                                            int tag) {
    if (tag < 0) {
        MaterialPtr mat = getWorldMaterialTemplate(idx);
        return mat;
    } else {
        MaterialPtr tmat = getWorldMaterialTemplate(idx);
        MaterialPtr imat;

        // have to look for it and clone
        WorldMaterialInstanceMap::iterator it = mWorldMaterials.find(idx);

        if (it == mWorldMaterials.end()) {
            // no slot for the idx. have to clone
            std::pair<WorldMaterialInstanceMap::iterator, bool> res =
                mWorldMaterials.insert(make_pair(idx, SlotMaterialMap()));

            it = res.first;
        }

        // now search
        SlotMaterialMap::iterator sit = it->second.find(tag);

        if (sit == it->second.end()) {
            Ogre::StringStream tmp;

            tmp << "Shader" << idx << "#" << tag;

            imat = tmat->clone(tmp.str());

            prepareMaterialInstance(imat, idx, tag);

            it->second.insert(make_pair(tag, imat));
        } else {
            imat = sit->second;
        }

        return imat;
    }
}
Ogre::GpuProgramPtr GBufferMaterialGeneratorImpl::generateVertexShader(MaterialGenerator::Perm permutation)
{
	Ogre::StringStream ss;
	
	ss << "void ToGBufferVP(" << std::endl;
	ss << "	float4 iPosition : POSITION," << std::endl;
	ss << "	float3 iNormal   : NORMAL," << std::endl;

	Ogre::uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8;
	for (Ogre::uint32 i=0; i<numTexCoords; i++) 
	{
		ss << "	float2 iUV" << i << " : TEXCOORD" << i << ',' << std::endl;
	}

	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP)
	{
		ss << "	float3 iTangent : TANGENT0," << std::endl;
	}

	//TODO : Skinning inputs
	ss << std::endl;
	


	ss << "	out float4 oPosition : POSITION," << std::endl;
#ifdef WRITE_LINEAR_DEPTH
    ss << "	out float3 oViewPos : TEXCOORD0," << std::endl;
#else
	ss << "	out float oDepth : TEXCOORD0," << std::endl;
#endif
	ss << "	out float3 oNormal : TEXCOORD1," << std::endl;
	int texCoordNum = 2;
	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) 
	{
		ss << "	out float3 oTangent : TEXCOORD" << texCoordNum++ << ',' << std::endl;
		ss << "	out float3 oBiNormal : TEXCOORD" << texCoordNum++ << ',' << std::endl;
	}
	for (Ogre::uint32 i=0; i<numTexCoords; i++) 
	{
		ss << "	out float2 oUV" << i << " : TEXCOORD" << texCoordNum++ << ',' << std::endl;
	}

	ss << std::endl;

	ss << "	uniform float4x4 cWorldViewProj," << std::endl;
	ss << "	uniform float4x4 cWorldView" << std::endl;

	ss << "	)" << std::endl;
	
	
	ss << "{" << std::endl;
	ss << "	oPosition = mul(cWorldViewProj, iPosition);" << std::endl;
	ss << "	oNormal = mul(cWorldView, float4(iNormal,0)).xyz;" << std::endl;
	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP)
	{
		ss << "	oTangent = mul(cWorldView, float4(iTangent,0)).xyz;" << std::endl;
		ss << "	oBiNormal = cross(oNormal, oTangent);" << std::endl;
	}

#ifdef WRITE_LINEAR_DEPTH
    ss << "	oViewPos = mul(cWorldView, iPosition).xyz;" << std::endl;
#else
	ss << "	oDepth = oPosition.w;" << std::endl;
#endif

	for (Ogre::uint32 i=0; i<numTexCoords; i++) {
		ss << "	oUV" << i << " = iUV" << i << ';' << std::endl;
	}

	ss << "}" << std::endl;
	
	Ogre::String programSource = ss.str();
	Ogre::String programName = mBaseName + "VP_" + Ogre::StringConverter::toString(permutation);

#if OGRE_DEBUG_MODE
	Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource);
#endif

	// Create shader object
	Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
		programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		"cg", Ogre::GPT_VERTEX_PROGRAM);
	ptrProgram->setSource(programSource);
	ptrProgram->setParameter("entry_point","ToGBufferVP");
	ptrProgram->setParameter("profiles","vs_1_1 arbvp1");

	const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters();
	params->setNamedAutoConstant("cWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
	params->setNamedAutoConstant("cWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
	ptrProgram->load();

	return Ogre::GpuProgramPtr(ptrProgram);
}
Ogre::GpuProgramPtr GBufferMaterialGeneratorImpl::generateFragmentShader(MaterialGenerator::Perm permutation)
{
	Ogre::StringStream ss;
	
	ss << "void ToGBufferFP(" << std::endl;
#ifdef WRITE_LINEAR_DEPTH
    ss << "	float3 iViewPos : TEXCOORD0," << std::endl;
#else
    ss << "	float1 iDepth : TEXCOORD0," << std::endl;
#endif
	ss << "	float3 iNormal   : TEXCOORD1," << std::endl;

	int texCoordNum = 2;
	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) 
	{
		ss << "	float3 iTangent : TEXCOORD" << texCoordNum++ << ',' << std::endl;
		ss << "	float3 iBiNormal : TEXCOORD" << texCoordNum++ << ',' << std::endl;
	}

	Ogre::uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8;
	for (Ogre::uint32 i=0; i<numTexCoords; i++) 
	{
		ss << "	float2 iUV" << i << " : TEXCOORD" << texCoordNum++ << ',' << std::endl;
	}

	ss << std::endl;

	ss << "	out float4 oColor0 : COLOR0," << std::endl;
	ss << "	out float4 oColor1 : COLOR1," << std::endl;

	ss << std::endl;

	int samplerNum = 0;
	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP)
	{
		ss << "	uniform sampler sNormalMap : register(s" << samplerNum++ << ")," << std::endl;
	}
	Ogre::uint32 numTextures = permutation & GBufferMaterialGenerator::GBP_TEXTURE_MASK;
	for (Ogre::uint32 i=0; i<numTextures; i++) {
		ss << "	uniform sampler sTex" << i << " : register(s" << samplerNum++ << ")," << std::endl;
	}
    if (numTextures == 0 || permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR)
	{
		ss << "	uniform float4 cDiffuseColour," << std::endl;
	}

#ifdef WRITE_LINEAR_DEPTH
    ss << "	uniform float cFarDistance," << std::endl;
#endif
	
	ss << "	uniform float cSpecularity" << std::endl;

	ss << "	)" << std::endl;
	
	
	ss << "{" << std::endl;

	if (numTexCoords > 0 && numTextures > 0) 
	{
		ss << "	oColor0.rgb = tex2D(sTex0, iUV0);" << std::endl;
        if (permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR)
        {
            ss << "	oColor0.rgb *= cDiffuseColour.rgb;" << std::endl;
        }
	}
    else
	{
		ss << "	oColor0.rgb = cDiffuseColour.rgb;" << std::endl;
	}
    
	
	ss << "	oColor0.a = cSpecularity;" << std::endl;
	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) 
	{
		ss << "	float3 texNormal = (tex2D(sNormalMap, iUV0)-0.5)*2;" << std::endl;
		ss << "	float3x3 normalRotation = float3x3(iTangent, iBiNormal, iNormal);" << std::endl;
		ss << "	oColor1.rgb = normalize(mul(texNormal, normalRotation));" << std::endl;
	} else 
	{
		ss << "	oColor1.rgb = normalize(iNormal);" << std::endl;
	}
#ifdef WRITE_LINEAR_DEPTH
    ss << "	oColor1.a = length(iViewPos) / cFarDistance;" << std::endl;
#else
    ss << "	oColor1.a = iDepth;" << std::endl;
#endif

	ss << "}" << std::endl;
	
	Ogre::String programSource = ss.str();
	Ogre::String programName = mBaseName + "FP_" + Ogre::StringConverter::toString(permutation);

#if OGRE_DEBUG_MODE
	Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource);
#endif

	// Create shader object
	Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
		programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		"cg", Ogre::GPT_FRAGMENT_PROGRAM);
	ptrProgram->setSource(programSource);
	ptrProgram->setParameter("entry_point","ToGBufferFP");
	ptrProgram->setParameter("profiles","ps_2_0 arbfp1");

	const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters();
	params->setNamedAutoConstant("cSpecularity", Ogre::GpuProgramParameters::ACT_SURFACE_SHININESS);
	if (numTextures == 0 || permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR)
	{
		params->setNamedAutoConstant("cDiffuseColour", Ogre::GpuProgramParameters::ACT_SURFACE_DIFFUSE_COLOUR);
	}

#ifdef WRITE_LINEAR_DEPTH
    //TODO : Should this be the distance to the far corner, not the far clip distance?
    params->setNamedAutoConstant("cFarDistance", Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE);
#endif

	ptrProgram->load();
	return Ogre::GpuProgramPtr(ptrProgram);
}
Ejemplo n.º 12
0
void TiXmlElement::SetAttribute( const TIXML_STRING& name, int val )
{	
   Ogre::StringStream oss;
   oss << val;
   SetAttribute( name, oss.str().c_str() );
}
Ejemplo n.º 13
0
Ogre::GpuProgramPtr GBufferMaterialGeneratorImpl::generateVertexShader(MaterialGenerator::Perm permutation)
{
	Ogre::StringStream ss;

    if(mIsGLSL)
    {
        int shadingLangVersion = Ogre::Root::getSingleton().getRenderSystem()->getNativeShadingLanguageVersion();
        const char *inSemantic = shadingLangVersion >= 150 ? "in" : "attribute";
        const char *outSemantic = shadingLangVersion >= 150 ? "out" : "varying";

        if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles"))
        {
            ss << "#version 300 es" << std::endl;
            ss << "precision mediump int;" << std::endl;
            ss << "precision mediump float;" << std::endl;
        }
        else
            ss << "#version " << shadingLangVersion << std::endl;

        ss << inSemantic << " vec4 vertex;" << std::endl;
        ss << inSemantic << " vec3 normal;" << std::endl;

        Ogre::uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8;
        for (Ogre::uint32 i = 0; i < numTexCoords; i++)
        {
            ss << inSemantic << " vec2 uv" << i << ';' << std::endl;
        }

        if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP)
        {
            ss << inSemantic << " vec3 tangent;" << std::endl;
        }

        //TODO : Skinning inputs
        ss << std::endl;

#ifdef WRITE_LINEAR_DEPTH
        ss << outSemantic << " vec3 oViewPos;" << std::endl;
#else
        ss << outSemantic << " float oDepth;" << std::endl;
#endif
        ss << outSemantic << " vec3 oNormal;" << std::endl;
        if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP)
        {
            ss << outSemantic << " vec3 oTangent;" << std::endl;
            ss << outSemantic << " vec3 oBiNormal;" << std::endl;
        }
        for (Ogre::uint32 i = 0; i < numTexCoords; i++)
        {
            ss << outSemantic << " vec2 oUv" << i << ";" << std::endl;
        }

        ss << std::endl;

        ss << "uniform mat4 cWorldViewProj;" << std::endl;
        ss << "uniform mat4 cWorldView;" << std::endl;

        ss << "void main()" << std::endl;

        ss << "{" << std::endl;
        ss << "	gl_Position = cWorldViewProj * vertex;" << std::endl;
        ss << "	oNormal = (cWorldView * vec4(normal,0)).xyz;" << std::endl;
        if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP)
        {
            ss << "	oTangent = (cWorldView * vec4(tangent,0)).xyz;" << std::endl;
            ss << "	oBiNormal = cross(oNormal, oTangent);" << std::endl;
        }

#ifdef WRITE_LINEAR_DEPTH
        ss << "	oViewPos = (cWorldView * vertex).xyz;" << std::endl;
#else
        ss << "	oDepth = gl_Position.w;" << std::endl;
#endif

        for (Ogre::uint32 i=0; i<numTexCoords; i++) {
            ss << "	oUv" << i << " = uv" << i << ';' << std::endl;
        }

        ss << "}" << std::endl;

        Ogre::String programSource = ss.str();
        Ogre::String programName = mBaseName + "VP_" + Ogre::StringConverter::toString(permutation);

#if OGRE_DEBUG_MODE
        Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource);
#endif

        // Create shader object
        Ogre::HighLevelGpuProgramPtr ptrProgram;
        if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles"))
        {
            ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(programName,
                                                                                  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                                  "glsles", Ogre::GPT_VERTEX_PROGRAM);
            ptrProgram->setParameter("syntax", "glsles");
        }
        else
        {
            ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(programName,
                                                                                  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                                  "glsl", Ogre::GPT_VERTEX_PROGRAM);
        }
        ptrProgram->setSource(programSource);

        const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters();
        params->setNamedAutoConstant("cWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
        params->setNamedAutoConstant("cWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
        ptrProgram->load();
        
        return Ogre::GpuProgramPtr(ptrProgram);
    }
    else
    {
Ejemplo n.º 14
0
Ogre::String Projectile::get_next_name()
{
	Ogre::StringStream ss;
	ss << Projectile::id;
	return "Projectile" + ss.str();
}
Ejemplo n.º 15
0
//------------------------------------------------------
void MaterialService::loadMaterials(const FileGroupPtr &db) {
    if (!db->hasFile("TXLIST"))
        throw Exception(
            Exception::ERR_ITEM_NOT_FOUND,
            "Mission file does not contain Texture list chunk (TXLIST)",
            "MaterialService::loadMaterials");

    // Load the TXLIST chunk from the resource mission file.
    Opde::FilePtr txtList = db->getFile("TXLIST");

    // TODO: Exception handling on the chunk readout!
    // Okay, we are ready to map the arrays
    if (mFamilies != NULL)
        delete[] mFamilies;

    if (mTextures != NULL)
        delete[] mTextures;

    try {
        // TODO: This should be implemented using dtypes
        // Read the header...
        txtList->read(&mTxlistHeader, sizeof(DarkDBChunkTXLIST));

        // now read all the families

        // allocate the needed space
        mFamilies = new DarkDBTXLIST_fam[mTxlistHeader.fam_count];
        // load
        txtList->read(&(mFamilies[0]),
                      sizeof(DarkDBTXLIST_fam) * mTxlistHeader.fam_count);

        // Now read the textures. Same as before

        // allocate the needed space
        mTextures = new DarkDBTXLIST_texture[mTxlistHeader.txt_count];
        // load texture names
        txtList->read(&(mTextures[0]),
                      sizeof(DarkDBTXLIST_texture) * mTxlistHeader.txt_count);
    } catch (Ogre::Exception &e) {
        if (mFamilies != NULL)
            delete[] mFamilies;
        if (mTextures != NULL)
            delete[] mTextures;

        // Connect the original exception to the printout:
        OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
                    String("Could not load texture list : ") +
                        e.getFullDescription(),
                    "BspLevel::loadMaterials");
    }

    // Okay, we are ready to load the materials now!

    // Our resource group
    String resourceGroup =
        ResourceGroupManager::getSingleton().getWorldResourceGroupName();

    // ------------- Following code loads the standard materials
    // -------------------

    // Iterate through all materials, and load them (tries to load material as a
    // script (named family/texture), and if it fails, it constructs one with
    // the default settings, and tries a few extensions too for the image)

    for (unsigned int id = 1; id < mTxlistHeader.txt_count; id++) {
        // Try to find the family for the texture
        std::string path = getMaterialName(id);

        // Resulting material name
        Ogre::StringStream matName;
        matName << "@template" << id;

        if (MaterialManager::getSingleton().resourceExists(
                matName.str())) // if the material is already defined
            // remove, as we have to redefine it
            MaterialManager::getSingleton().remove(matName.str());

        // See if the material is defined by a script. If so, clone it to be
        // named @templateXXXX (XXXX = texture number) We seek material named:
        // family/texture
        if (MaterialManager::getSingleton().resourceExists(path)) {
            LOG_INFO("loadMaterials: Found material definition for %s",
                     path.c_str());
            MaterialPtr origMat =
                MaterialManager::getSingleton().getByName(path);

            MaterialPtr shadMat =
                origMat->clone(matName.str(), true, resourceGroup);

            shadMat->load();

            addWorldMaterialTemplate(id, shadMat);
        } else { // The material script was not found
            createStandardMaterial(id, matName.str(), path, resourceGroup);
        }
        // This is it. Material @templateXX created
    }

    // Initialize the flow textures (do this first so water specialisation will
    // override)
    loadFlowTextures(db);

    createSkyHackMaterial(resourceGroup);
    createJorgeMaterial(resourceGroup);
}
Ejemplo n.º 16
0
//-----------------------------------------------------------------------
void MaterialService::loadFlowTextures(const FileGroupPtr &db) {
    // Load the TXLIST chunk from the resource mission file.
    Opde::FilePtr flow_tex;
    try {
        flow_tex = db->getFile("FLOW_TEX");
    } catch (FileException) {
        LOG_ERROR("Flow chunk does not exist. Water materials may not be "
                  "correctly displayed",
                  "MaterialService::loadFlowTextures");
        return;
    }

    // TODO: Exception handling on the chunk readout!
    // Okay, we are ready to map the arrays
    DarkDBChunkFLOW_TEX flows;
    int flow_count =
        flow_tex->size() / 32; // The record is 32 bytes long, this way we do
                               // not fail if the chunk is shorter

    try {
        // load
        flow_tex->read(&flows,
                       flow_tex->size()); // To be sure we do not overlap
    } catch (Ogre::Exception &e) {
        // Connect the original exception to the printout:
        OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
                    String("Could not load flow textures : ") +
                        e.getFullDescription(),
                    "MaterialService::loadFlowTextures");
    }

    // now try to load non-zero flow textures as materials
    for (int fnum = 0; fnum < flow_count; fnum++) {
        if (strlen(flows.flow[fnum].name) > 0) { // nonzero name, try to load
            // Construct the basic name of the material
            std::string matname("water/");
            matname += flows.flow[fnum].name;

            LOG_INFO("MaterialService::loadFlowTextures: Loading flow %d : "
                     "%d/%d '%s'",
                     fnum, flows.flow[fnum].in_texture,
                     flows.flow[fnum].out_texture, matname.c_str());

            // try to find the texture definition. If found, clone to the
            // @template + the in_texture/out_texture number
            if (MaterialManager::getSingleton().resourceExists(matname +
                                                               "_in")) {
                MaterialPtr origMat =
                    MaterialManager::getSingleton().getByName(matname + "_in");

                Ogre::StringStream strb;
                strb << "@template" << flows.flow[fnum].in_texture;

                std::string templn(strb.str());

                if (MaterialManager::getSingleton().resourceExists(templn)) {
                    MaterialManager::getSingleton().remove(templn);
                }

                MaterialPtr shadMat = origMat->clone(templn);
                shadMat->load();

                addWorldMaterialTemplate(flows.flow[fnum].in_texture, shadMat);
                LOG_INFO("Flow now defined : %s (template %s_in)",
                         templn.c_str(), matname.c_str());
            } else {
                LOG_ERROR("Material not found : %s_in", matname.c_str());
            }

            // OUT
            if (MaterialManager::getSingleton().resourceExists(matname +
                                                               "_out")) {
                MaterialPtr origMat =
                    MaterialManager::getSingleton().getByName(matname + "_out");

                Ogre::StringStream strb;
                strb << "@template" << flows.flow[fnum].in_texture;

                std::string templn(strb.str());

                if (MaterialManager::getSingleton().resourceExists(templn)) {
                    MaterialManager::getSingleton().remove(templn);
                }

                MaterialPtr shadMat = origMat->clone(templn);
                shadMat->load();

                addWorldMaterialTemplate(flows.flow[fnum].out_texture, shadMat);
                LOG_INFO("Flow now defined : %s (template %s_in)",
                         templn.c_str(), matname.c_str());
            } else {
                LOG_ERROR("Material not found : %s_out", matname.c_str());
            }
        }
    }
}