KeosRenderSystem.h

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 
00022 #ifndef KEOS_RENDERSYSTEM_H
00023 #define KEOS_RENDERSYSTEM_H
00024 
00025 #include "KeosPrerequisites.h"
00026 #include "KeosRenderTarget.h"
00027 #include "KeosRenderWindow.h"
00028 #include "KeosRenderApp.h"
00029 #include "KeosDeclaration.h"
00030 #include "KeosBuffer.h"
00031 #include "KeosRenderSystemCapabilities.h"
00032 #include "KeosConfigOption.h"
00033 #include "KeosColor.h"
00034 #include "Cg/cg.h"
00035 
00036 #define Renderer CRoot::Instance().GetRenderSystem()
00037 
00038 namespace Keos
00039 {
00040   typedef std::map< String, IRenderTarget * > RenderTargetMap;
00041 
00042   //-----------------------------------------------------------------------
00046   class KEOS_EXPORT IRenderSystem
00047   {
00048   public :
00049 
00052     IRenderSystem();
00053 
00056     virtual ~IRenderSystem();
00057 
00060     virtual const String& GetName(void) const = 0;
00061 
00070     virtual IRenderWindow* Initialise(bool bAutoCreateWindow, const String& strWindowTitle = "KEOS Render Window");
00071 
00080     virtual IRenderWindow* CreateRenderWindow(const String &strName, uint nWidth, uint nHeight, uint nColourDepth, bool bFullScreen) = 0;
00081 
00084     virtual void Reinitialise(void) = 0;
00085 
00088     virtual void Shutdown(void);
00089 
00092     void AttachRenderTarget( IRenderTarget& target , bool bIsWindow = true);
00093 
00097     bool SetRenderApp(IRenderApp* pRenderApp)
00098     {
00099       if (m_pRenderWindow == NULL) return false;
00100       m_pRenderWindow->SetRenderApp(pRenderApp);
00101       return true;
00102     }
00103 
00109     bool SetRenderApp(IRenderApp* pRenderApp, String& strTargetName);
00110 
00113     const CRenderSystemCapabilities* GetCapabilities(void) const
00114     {
00115       return m_pCapabilities;
00116     }
00117 
00120     virtual void BeginScene(void) const = 0;
00121 
00124     virtual void EndScene(void) const = 0;
00125 
00128     virtual void PrintInfo(void) const = 0;
00129 
00132     void InitAllRenderTargets(void);
00133 
00136     void UpdateAllRenderTargets(void);
00137 
00141     void DestroyRenderTarget(const String& strName);
00142 
00147     IRenderTarget* DetachRenderTarget( const String &strName );
00148 
00153     IRenderTarget* GetRenderTarget( const String &strName );
00154 
00161     virtual IBufferBase* _CreateVB(ulong nSize, ulong nStride, ulong nFlags) const = 0;
00162 
00169     virtual IBufferBase* _CreateIB(ulong nSize, ulong nStride, ulong nFlags) const = 0;
00170 
00176     virtual IDeclaration* CreateDeclaration(const TDeclarationElement* pElements, size_t nCount) const = 0;
00177 
00185     virtual void _SetVB(uint nStream, const IBufferBase* pBuffer, ulong nStride, ulong nMinVertex, ulong nMaxVertex) = 0;
00186 
00191     virtual void _SetIB(const IBufferBase* pBuffer, ulong nStride) = 0;
00192 
00196     virtual void SetDeclaration(const IDeclaration* pDeclaration) = 0;
00197 
00203     virtual void DrawPrimitives(TPrimitiveType Type, ulong nFirstVertex, ulong nCount) const = 0;
00204 
00210     virtual void DrawIndexedPrimitives(TPrimitiveType Type, ulong nFirstIndex, ulong nCount) const = 0;
00211 
00215     virtual void PushMatrix(TMatrixType Type) = 0;
00216 
00220     virtual void PopMatrix(TMatrixType Type) = 0;
00221 
00226     virtual void LoadMatrix(TMatrixType Type, const CMatrix4& Matrix) = 0;
00227 
00232     virtual void LoadMatrixMult(TMatrixType Type, const CMatrix4& Matrix) = 0;
00233 
00238     virtual void GetMatrix(TMatrixType Type, CMatrix4& Matrix) const = 0;
00239 
00244     virtual ulong ConvertColor(const CColor& Color) const = 0;
00245 
00252     template <class T> CBuffer<T> CreateVertexBuffer(ulong nSize, ulong nFlags, const T* pData = NULL) const;
00253 
00260     template <class T> CBuffer<T> CreateIndexBuffer(ulong nSize, ulong nFlags, const T* pData = NULL) const;
00261 
00268     template <class T> void SetVertexBuffer(uint nStream, const CBuffer<T>& Buffer, ulong nMinVertex = 0, ulong nMaxVertex = 0);
00269 
00273     template <class T> void SetIndexBuffer(const CBuffer<T>& Buffer);
00274 
00279     template <size_t N> IDeclaration* CreateVertexDeclaration(const TDeclarationElement (&Elements)[N]) const;
00280 
00287     virtual ITextureBase* CreateTexture(const TVector2I& Size, TPixelFormat Format, ulong nFlags = 0) const = 0;
00288 
00293     virtual void SetTexture(uint nUnit, const ITextureBase* pTexture) const = 0;
00294 
00297     virtual void InitConfigOptions(void);
00298 
00301     virtual void SetConfigOption(const String& strName, const String& strValue);
00302 
00305     virtual ConfigOptionMap GetConfigOptions()
00306     {
00307       return m_Options;
00308     }
00309 
00314     virtual void SetupAlphaBlending(TBlend Src, TBlend Dest) const = 0;
00315 
00323     virtual void SetupTextureUnit(uint nUnit, TTextureOp Op, TTextureArg Arg1, TTextureArg Arg2 = TXA_DIFFUSE, const CColor& Constant = 0x00) const = 0;
00324 
00329     virtual void Enable(TRenderParameter Param, bool bValue) const = 0;
00330 
00335     CGprofile GetShaderProfile(TShaderType Type) const;
00336 
00341     const char* const* GetShaderOptions(TShaderType Type) const;
00342 
00348     virtual IShaderBase* CreateShader(CGprogram Program, TShaderType Type) const = 0;
00349 
00353     virtual void SetVertexShader(const IShaderBase* pShader) = 0;
00354 
00358     virtual void SetPixelShader(const IShaderBase* pShader) = 0;
00359 
00363     virtual void SetClearColor(const CColor& Color) = 0;
00364 
00369     virtual void SetLight(uint nIndex, CLight* pLight) = 0;
00370 
00374     virtual void SetFillMode(TFillMode Mode) = 0;
00375 
00376   protected :
00377 
00379     IRenderWindow* m_pRenderWindow;
00380 
00382     RenderTargetMap m_RenderTargets;
00383 
00385     CRenderSystemCapabilities* m_pCapabilities;
00386 
00388     ConfigOptionMap m_Options;
00389 
00391     CGprofile   m_VSProfile;
00393     CGprofile   m_PSProfile;
00395     const char* m_VSOptions[2];
00397     const char* m_PSOptions[2];
00398 
00400     CColor m_ClearColor;
00401   };
00402 
00403 
00404   //=======================================================================
00405   // IRenderSystem inline functions
00406   //=======================================================================
00407 
00408   //-----------------------------------------------------------------------
00409   template <class T>
00410   inline CBuffer<T> IRenderSystem::CreateVertexBuffer(ulong nSize, ulong nFlags, const T* pData) const
00411   {
00412     CBuffer<T> Buffer(_CreateVB(nSize, sizeof(T), nFlags));
00413     if (pData)
00414       Buffer.Fill(pData, nSize);
00415 
00416     return Buffer;
00417   }
00418 
00419   //-----------------------------------------------------------------------
00420   template <class T>
00421   inline CBuffer<T> IRenderSystem::CreateIndexBuffer(ulong nSize, ulong nFlags, const T* pData) const
00422   {
00423     CBuffer<T> Buffer(_CreateIB(nSize, sizeof(T), nFlags));
00424     if (pData)
00425       Buffer.Fill(pData, nSize);
00426 
00427     return Buffer;
00428   }
00429 
00430   //-----------------------------------------------------------------------
00431   template <class T>
00432   inline void IRenderSystem::SetVertexBuffer(uint nStream, const CBuffer<T>& Buffer, ulong nMinVertex, ulong nMaxVertex)
00433   {
00434     _SetVB(nStream, Buffer.GetBuffer(), sizeof(T), nMinVertex, nMaxVertex ? nMaxVertex : Buffer.GetCount() - 1);
00435   }
00436 
00437   //-----------------------------------------------------------------------
00438   template <class T>
00439   inline void IRenderSystem::SetIndexBuffer(const CBuffer<T>& Buffer)
00440   {
00441     _SetIB(Buffer.GetBuffer(), sizeof(T));
00442   }
00443 
00444   //-----------------------------------------------------------------------
00445   template <size_t N>
00446   IDeclaration* IRenderSystem::CreateVertexDeclaration(const TDeclarationElement (&Elements)[N]) const
00447   {
00448     return CreateDeclaration(Elements, N);
00449   }
00450 
00451 } // namespace Keos
00452 
00453 #endif // KEOS_RENDERSYSTEM_H

Generated on Fri Mar 9 14:29:03 2007 for Keos by  doxygen 1.5.1-p1