Ejemplo n.º 1
0
	bool Framework::keyPressed(const OIS::KeyEvent& evt)
	{
		if (evt.key == OIS::KC_H || evt.key == OIS::KC_F1)   // toggle visibility of help dialog
		{
			if (!mTrayMgr->isDialogVisible() && mInfo["Help"] != "") 
				mTrayMgr->showOkDialog("Help", mInfo["Help"]);
			else mTrayMgr->closeDialog();
		}

		if (mTrayMgr->isDialogVisible()) return true;   // don't process any more keys if dialog is up

		if (evt.key == OIS::KC_F)   // toggle visibility of advanced frame stats
		{
			mTrayMgr->toggleAdvancedFrameStats();
		}
		else if (evt.key == OIS::KC_G)   // toggle visibility of even rarer debugging details
		{
			if (mDetailsPanel->getTrayLocation() == TL_NONE)
			{
				mTrayMgr->moveWidgetToTray(mDetailsPanel, TL_TOPRIGHT, 0);
				mDetailsPanel->show();
			}
			else
			{
				mTrayMgr->removeWidgetFromTray(mDetailsPanel);
				mDetailsPanel->hide();
			}
		}
		else if (evt.key == OIS::KC_T)   // cycle polygon rendering mode
		{
			Ogre::String newVal;
			Ogre::TextureFilterOptions tfo;
			unsigned int aniso;

			switch (mDetailsPanel->getParamValue(9).asUTF8()[0])
			{
			case 'B':
				newVal = "Trilinear";
				tfo = Ogre::TFO_TRILINEAR;
				aniso = 1;
				break;
			case 'T':
				newVal = "Anisotropic";
				tfo = Ogre::TFO_ANISOTROPIC;
				aniso = 8;
				break;
			case 'A':
				newVal = "None";
				tfo = Ogre::TFO_NONE;
				aniso = 1;
				break;
			default:
				newVal = "Bilinear";
				tfo = Ogre::TFO_BILINEAR;
				aniso = 1;
			}

			Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(tfo);
			Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(aniso);
			mDetailsPanel->setParamValue(9, newVal);
		}
		else if (evt.key == OIS::KC_R)   // cycle polygon rendering mode
		{
			Ogre::String newVal;
			Ogre::PolygonMode pm;

			switch (mCamera->getPolygonMode())
			{
			case Ogre::PM_SOLID:
				newVal = "Wireframe";
				pm = Ogre::PM_WIREFRAME;
				break;
			case Ogre::PM_WIREFRAME:
				newVal = "Points";
				pm = Ogre::PM_POINTS;
				break;
			default:
				newVal = "Solid";
				pm = Ogre::PM_SOLID;
			}

			mCamera->setPolygonMode(pm);
			mDetailsPanel->setParamValue(10, newVal);
		}
		else if(evt.key == OIS::KC_F5)   // refresh all textures
		{
			Ogre::TextureManager::getSingleton().reloadAll();
		}
		else if (evt.key == OIS::KC_SYSRQ)   // take a screenshot
		{
			mWindow->writeContentsToTimestampedFile("screenshot", ".png");
		}

#ifdef USE_RTSHADER_SYSTEM		
		// Toggle schemes.			
		else if (evt.key == OIS::KC_F2)
		{	
			Ogre::Viewport* mainVP = mCamera->getViewport();
			const Ogre::String& curMaterialScheme = mainVP->getMaterialScheme();

			if (curMaterialScheme == Ogre::MaterialManager::DEFAULT_SCHEME_NAME)
			{							
				mainVP->setMaterialScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
				mDetailsPanel->setParamValue(11, "On");
			}
			else if (curMaterialScheme == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME)
			{
				mainVP->setMaterialScheme(Ogre::MaterialManager::DEFAULT_SCHEME_NAME);
				mDetailsPanel->setParamValue(11, "Off");
			}														
		}			

#ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS

		// Toggles per pixel per light model.
		else if (evt.key == OIS::KC_F3)
		{
			static bool usePerPixelLighting = true;					

			// Grab the scheme render state.												
			Ogre::RTShader::RenderState* schemRenderState = mShaderGenerator->getRenderState(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);


			// Add per pixel lighting sub render state to the global scheme render state.
			// It will override the default FFP lighting sub render state.
			if (usePerPixelLighting)
			{
				Ogre::RTShader::SubRenderState* perPixelLightModel = mShaderGenerator->createSubRenderState(Ogre::RTShader::PerPixelLighting::Type);

				schemRenderState->addTemplateSubRenderState(perPixelLightModel);					
			}

			// Search the per pixel sub render state and remove it.
			else
			{
				const Ogre::RTShader::SubRenderStateList& subRenderStateList = schemRenderState->getTemplateSubRenderStateList();
				Ogre::RTShader::SubRenderStateListConstIterator it = subRenderStateList.begin();
				Ogre::RTShader::SubRenderStateListConstIterator itEnd = subRenderStateList.end();

				for (; it != itEnd; ++it)
				{
					Ogre::RTShader::SubRenderState* curSubRenderState = *it;

					// This is the per pixel sub render state -> remove it.
					if (curSubRenderState->getType() == Ogre::RTShader::PerPixelLighting::Type)
					{
						schemRenderState->removeTemplateSubRenderState(*it);
						break;
					}
				}
			}

			// Invalidate the scheme in order to re-generate all shaders based technique related to this scheme.
			mShaderGenerator->invalidateScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);


			// Update UI.
			if (usePerPixelLighting)
				mDetailsPanel->setParamValue(12, "Pixel");
			else
				mDetailsPanel->setParamValue(12, "Vertex");
			usePerPixelLighting = !usePerPixelLighting;				
		}	
#endif

		// Switch vertex shader outputs compaction policy.
		else if (evt.key == OIS::KC_F4)   
		{
			switch (mShaderGenerator->getVertexShaderOutputsCompactPolicy())
			{
			case Ogre::RTShader::VSOCP_LOW:
				mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_MEDIUM);
				mDetailsPanel->setParamValue(13, "Medium");
				break;

			case Ogre::RTShader::VSOCP_MEDIUM:
				mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_HIGH);
				mDetailsPanel->setParamValue(13, "High");
				break;

			case Ogre::RTShader::VSOCP_HIGH:
				mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_LOW);
				mDetailsPanel->setParamValue(13, "Low");
				break;
			}

			// Invalidate the scheme in order to re-generate all shaders based technique related to this scheme.
			mShaderGenerator->invalidateScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
		}	
#endif

		mCameraMan->injectKeyDown(evt);
		return true;
	}
Ejemplo n.º 2
0
bool AdvancedRenderControls::keyPressed(const KeyboardEvent& evt) {
    if (mTrayMgr->isDialogVisible())
        return true; // don't process any more keys if dialog is up

    int key = evt.keysym.sym;

    if (key == 'f') // toggle visibility of advanced frame stats
    {
        mTrayMgr->toggleAdvancedFrameStats();
    } else if (key == 'g') // toggle visibility of even rarer debugging details
    {
        if (mDetailsPanel->getTrayLocation() == TL_NONE) {
            mTrayMgr->moveWidgetToTray(mDetailsPanel, TL_TOPRIGHT, 0);
            mDetailsPanel->show();
        } else {
            mTrayMgr->removeWidgetFromTray(mDetailsPanel);
            mDetailsPanel->hide();
        }
    } else if (key == 't') // cycle texture filtering mode
    {
        Ogre::String newVal;
        Ogre::TextureFilterOptions tfo;
        unsigned int aniso;

        Ogre::FilterOptions mip = Ogre::MaterialManager::getSingleton().getDefaultTextureFiltering(Ogre::FT_MIP);

        switch (Ogre::MaterialManager::getSingleton().getDefaultTextureFiltering(Ogre::FT_MAG)) {
        case Ogre::FO_LINEAR:
            if (mip == Ogre::FO_POINT) {
                newVal = "Trilinear";
                tfo = Ogre::TFO_TRILINEAR;
                aniso = 1;
            } else {
                newVal = "Anisotropic";
                tfo = Ogre::TFO_ANISOTROPIC;
                aniso = 8;
            }
            break;
        case Ogre::FO_ANISOTROPIC:
            newVal = "None";
            tfo = Ogre::TFO_NONE;
            aniso = 1;
            break;
        default:
            newVal = "Bilinear";
            tfo = Ogre::TFO_BILINEAR;
            aniso = 1;
            break;
        }

        Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(tfo);
        Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(aniso);
        mDetailsPanel->setParamValue(9, newVal);
    } else if (key == 'r') // cycle polygon rendering mode
    {
        Ogre::String newVal;
        Ogre::PolygonMode pm;

        switch (mCamera->getPolygonMode()) {
        case Ogre::PM_SOLID:
            newVal = "Wireframe";
            pm = Ogre::PM_WIREFRAME;
            break;
        case Ogre::PM_WIREFRAME:
            newVal = "Points";
            pm = Ogre::PM_POINTS;
            break;
        default:
            newVal = "Solid";
            pm = Ogre::PM_SOLID;
            break;
        }

        mCamera->setPolygonMode(pm);
        mDetailsPanel->setParamValue(10, newVal);
    } else if (key == SDLK_F5) // refresh all textures
    {
        Ogre::TextureManager::getSingleton().reloadAll();
    }
    else if (key == SDLK_F6)   // take a screenshot
    {
        mCamera->getViewport()->getTarget()->writeContentsToTimestampedFile("screenshot", ".png");
    }
#if OGRE_PROFILING
    // Toggle visibility of profiler window
    else if (key == 'p')
    {
        Ogre::Profiler* prof = Ogre::Profiler::getSingletonPtr();
        if (prof)
            prof->setEnabled(!prof->getEnabled());
    }
#endif // OGRE_PROFILING
#ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM
    // Toggle schemes.
    else if (key == SDLK_F2) {
        if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_FIXED_FUNCTION)) {
            Ogre::Viewport* mainVP = mCamera->getViewport();
            const Ogre::String& curMaterialScheme = mainVP->getMaterialScheme();

            if (curMaterialScheme == Ogre::MaterialManager::DEFAULT_SCHEME_NAME) {
                mainVP->setMaterialScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
                mDetailsPanel->setParamValue(11, "On");
            } else if (curMaterialScheme == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME) {
                mainVP->setMaterialScheme(Ogre::MaterialManager::DEFAULT_SCHEME_NAME);
                mDetailsPanel->setParamValue(11, "Off");
            }
        }
    }
#   ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
    // Toggles per pixel per light model.
    else if (key == SDLK_F3) {
        static bool usePerPixelLighting = true;

        //![rtss_per_pixel]
        // Grab the scheme render state.
        Ogre::RTShader::RenderState* schemRenderState =
            mShaderGenerator->getRenderState(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);

        // Add per pixel lighting sub render state to the global scheme render state.
        // It will override the default FFP lighting sub render state.
        if (usePerPixelLighting) {
            Ogre::RTShader::SubRenderState* perPixelLightModel =
                mShaderGenerator->createSubRenderState(Ogre::RTShader::PerPixelLighting::Type);

            schemRenderState->addTemplateSubRenderState(perPixelLightModel);
        }
        //![rtss_per_pixel]

        // Search the per pixel sub render state and remove it.
        else {
            const Ogre::RTShader::SubRenderStateList& subRenderStateList =
                schemRenderState->getTemplateSubRenderStateList();
            Ogre::RTShader::SubRenderStateListConstIterator it = subRenderStateList.begin();
            Ogre::RTShader::SubRenderStateListConstIterator itEnd = subRenderStateList.end();

            for (; it != itEnd; ++it) {
                Ogre::RTShader::SubRenderState* curSubRenderState = *it;

                // This is the per pixel sub render state -> remove it.
                if (curSubRenderState->getType() == Ogre::RTShader::PerPixelLighting::Type) {
                    schemRenderState->removeTemplateSubRenderState(*it);
                    break;
                }
            }
        }

        // Invalidate the scheme in order to re-generate all shaders based technique related to this
        // scheme.
        mShaderGenerator->invalidateScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);

        // Update UI.
        if (usePerPixelLighting)
            mDetailsPanel->setParamValue(12, "Pixel");
        else
            mDetailsPanel->setParamValue(12, "Vertex");
        usePerPixelLighting = !usePerPixelLighting;
    }
#   endif
    // Switch vertex shader outputs compaction policy.
    else if (key == SDLK_F4) {
        switch (mShaderGenerator->getVertexShaderOutputsCompactPolicy()) {
        case Ogre::RTShader::VSOCP_LOW:
            mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_MEDIUM);
            mDetailsPanel->setParamValue(13, "Medium");
            break;

        case Ogre::RTShader::VSOCP_MEDIUM:
            mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_HIGH);
            mDetailsPanel->setParamValue(13, "High");
            break;

        case Ogre::RTShader::VSOCP_HIGH:
            mShaderGenerator->setVertexShaderOutputsCompactPolicy(Ogre::RTShader::VSOCP_LOW);
            mDetailsPanel->setParamValue(13, "Low");
            break;
        }

        // Invalidate the scheme in order to re-generate all shaders based technique related to this
        // scheme.
        mShaderGenerator->invalidateScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
    }
#endif // INCLUDE_RTSHADER_SYSTEM

    return true;
}