Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# KeosRenderSystem.cpp

Go to the documentation of this file.

    00001 /*
    00002  * This source file is part of KEOS (Free 3D Engine)
    00003  * For the latest info, see http://www.keosengine.org/
    00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
    00005  *
    00006  * This program is free software; you can redistribute it and/or modify it under
    00007  * the terms of the GNU Lesser General Public License as published by the Free Software
    00008  * Foundation; either version 2 of the License, or (at your option) any later
    00009  * version.
    00010  *
    00011  * This program is distributed in the hope that it will be useful, but WITHOUT
    00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Lesser General Public License along with
    00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00018  * http://www.gnu.org/copyleft/lesser.txt.
    00019  *
    00020  */
    00021 #include "KeosRenderSystem.h"
    00022 #include "KeosRoot.h"
    00023 #include "KeosLogger.h"
    00024
    00025 namespace Keos
    00026 {
    00027     //=======================================================================
    00028     // IRenderSystem implementation
    00029     //=======================================================================
    00030
    00031     //-----------------------------------------------------------------------
    00032     IRenderSystem::IRenderSystem()
    00033     {
    00034         m_pRenderWindow = NULL;
    00035
    00036         m_pCapabilities = new CRenderSystemCapabilities();
    00037
    00038         InitConfigOptions();
    00039     }
    00040
    00041     //-----------------------------------------------------------------------
    00042     IRenderSystem::~IRenderSystem()
    00043     {
    00044         delete m_pCapabilities;
    00045     }
    00046
    00047     //-----------------------------------------------------------------------
    00048     IRenderWindow* IRenderSystem::Initialise(bool bAutoCreateWindow, const String& strWindowTitle)
    00049     {
    00050         return NULL;
    00051     }
    00052
    00053     //-----------------------------------------------------------------------
    00054     void IRenderSystem::Shutdown(void)
    00055     {
    00056         CRoot::Instance().StopRendering();
    00057
    00058         // Remove all the render targets.
    00059         for( RenderTargetMap::iterator it = m_RenderTargets.begin(); it != m_RenderTargets.end(); ++it )
    00060         {
    00061             delete it->second;
    00062         }
    00063             m_RenderTargets.clear();
    00064
    00065         ILogger::Log("<-- Shutdown RenderSystem");
    00066     }
    00067
    00068     //-----------------------------------------------------------------------
    00069     void IRenderSystem::DestroyRenderTarget(const String& strName)
    00070     {
    00071         IRenderTarget* rt = DetachRenderTarget(strName);
    00072         delete rt;
    00073     }
    00074
    00075     //-----------------------------------------------------------------------
    00076     IRenderTarget* IRenderSystem::GetRenderTarget( const String &strName )
    00077     {
    00078         RenderTargetMap::iterator it = m_RenderTargets.find( strName );
    00079         IRenderTarget *ret = NULL;
    00080
    00081         if( it != m_RenderTargets.end() )
    00082         {
    00083             ret = it->second;
    00084         }
    00085
    00086         return ret;
    00087     }
    00088
    00089     //-----------------------------------------------------------------------
    00090     bool IRenderSystem::SetRenderApp(IRenderApp* pRenderApp, String& strTargetName)
    00091     {
    00092         RenderTargetMap::iterator it = m_RenderTargets.find( strTargetName );
    00093         bool ret = false;
    00094         if( it != m_RenderTargets.end() )
    00095         {
    00096             ret = true;
    00097             it->second->SetRenderApp(pRenderApp);
    00098         }
    00099         return ret;
    00100     }
    00101
    00102     //-----------------------------------------------------------------------
    00103     void IRenderSystem::AttachRenderTarget( IRenderTarget& target, bool bIsWindow )
    00104     {
    00105         m_RenderTargets.insert( RenderTargetMap::value_type( target.GetName(), &target ) );
    00106         if (bIsWindow)
    00107           m_pRenderWindow = (IRenderWindow*)(&target);
    00108     }
    00109
    00110     //---------------------------------------------------------------------------------------------
    00111     IRenderTarget* IRenderSystem::DetachRenderTarget( const String &strName )
    00112     {
    00113         RenderTargetMap::iterator it = m_RenderTargets.find( strName );
    00114         IRenderTarget *ret = NULL;
    00115
    00116         if( it != m_RenderTargets.end() )
    00117         {
    00118             ret = it->second;
    00119
    00120             m_RenderTargets.erase( it );
    00121         }
    00122
    00123         return ret;
    00124     }
    00125
    00126     //-----------------------------------------------------------------------
    00127     void IRenderSystem::InitAllRenderTargets(void)
    00128     {
    00129         // Init stats
    00130         for(
    00131             RenderTargetMap::iterator it = m_RenderTargets.begin();
    00132             it != m_RenderTargets.end();
    00133             ++it )
    00134         {
    00135             it->second->ResetStatistics();
    00136             it->second->Init();
    00137         }
    00138     }
    00139
    00140     //-----------------------------------------------------------------------
    00141     void IRenderSystem::UpdateAllRenderTargets(void)
    00142     {
    00143         Assert(m_pRenderWindow != NULL);
    00144
    00145         // Si on ferme la fenetre on arrete le rendu
    00146         // Valide uniquement parcque il ne peut y avoir qu'une fenetre
    00147         if (m_pRenderWindow->IsClosed())
    00148             CRoot::Instance().StopRendering();
    00149
    00150         if( m_pRenderWindow->IsActive() && m_pRenderWindow->IsAutoUpdated())
    00151         {
    00152             BeginScene();
    00153                         m_pRenderWindow->Update();
    00154             EndScene();
    00155                         m_pRenderWindow->SwapBuffers(false);
    00156         }
    00157
    00158                 RenderTargetMap::iterator itarg, itargend;
    00159                 itargend = m_RenderTargets.end();
    00160                 for( itarg = m_RenderTargets.begin(); itarg != itargend; ++itarg )
    00161                 {
    00162                         if( m_pRenderWindow != itarg->second &&
    00163             itarg->second->IsActive() && itarg->second->IsAutoUpdated())
    00164             {
    00165                 BeginScene();
    00166                             itarg->second->Update();
    00167                 EndScene();
    00168             }
    00169                 }
    00170     }
    00171
    00172     //-----------------------------------------------------------------------
    00173     void IRenderSystem::InitConfigOptions()
    00174         {
    00175                 ConfigOption optVideoMode;
    00176         ConfigOption optColorDepth;
    00177                 ConfigOption optFullScreen;
    00178                 ConfigOption optVSync;
    00179
    00180                 optVideoMode.name = "Video Mode";
    00181                 optVideoMode.currentValue = "640x480";
    00182                 optVideoMode.possibleValues.push_back( "320x200" );
    00183         optVideoMode.possibleValues.push_back( "640x480" );
    00184         optVideoMode.possibleValues.push_back( "800x600" );
    00185         optVideoMode.possibleValues.push_back( "1024x768" );
    00186         optVideoMode.possibleValues.push_back( "1280x1024" );
    00187         optVideoMode.possibleValues.push_back( "1600x1200" );
    00188                 optVideoMode.immutable = false;
    00189
    00190         optColorDepth.name = "Color Depth";
    00191                 optColorDepth.possibleValues.push_back( "16" );
    00192                 optColorDepth.possibleValues.push_back( "32" );
    00193                 optColorDepth.currentValue = "32";
    00194                 optColorDepth.immutable = false;
    00195
    00196                 optFullScreen.name = "Fullscreen";
    00197                 optFullScreen.possibleValues.push_back( "yes" );
    00198                 optFullScreen.possibleValues.push_back( "no" );
    00199                 optFullScreen.currentValue = "no";
    00200                 optFullScreen.immutable = false;
    00201
    00202                 //optVSync.name = "vsync";
    00203                 //optVSync.immutable = false;
    00204                 //optVSync.possibleValues.push_back( "yes" );
    00205                 //optVSync.possibleValues.push_back( "no" );
    00206                 //optVSync.currentValue = "no";
    00207
    00208                 m_Options[optVideoMode.name] = optVideoMode;
    00209         m_Options[optColorDepth.name] = optColorDepth;
    00210                 m_Options[optFullScreen.name] = optFullScreen;
    00211         //m_Options[optVSync.name] = optVSync;
    00212         }
    00213
    00214     //-----------------------------------------------------------------------
    00215     void IRenderSystem::SetConfigOption(const String& strName, const String& strValue)
    00216     {
    00217         // Find option
    00218         ConfigOptionMap::iterator it = m_Options.find(strName);
    00219
    00220         // Update
    00221         if( it != m_Options.end())
    00222             it->second.currentValue = strValue;
    00223         else
    00224         {
    00225             ILogger::Log("Option named \"%s\" does not exist !", strName.c_str());
    00226         }
    00227     }
    00228
    00229         //-----------------------------------------------------------------------
    00230         CGprofile IRenderSystem::GetShaderProfile(TShaderType Type) const
    00231         {
    00232                 return Type == SHADER_VERTEX ? m_VSProfile : m_PSProfile;
    00233         }
    00234
    00235
    00236         //-----------------------------------------------------------------------
    00237         const char* const* IRenderSystem::GetShaderOptions(TShaderType Type) const
    00238         {
    00239                 return Type == SHADER_VERTEX ? m_VSOptions : m_PSOptions;
    00240         }
    00241
    00242
    00243 } // namespace Keos