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

# 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 //@todo hummm.....
    00037 #define Renderer CRoot::Instance().GetRenderSystem()
    00038
    00039 namespace Keos
    00040 {
    00041     typedef std::map< String, IRenderTarget * > RenderTargetMap;
    00042
    00043     //-----------------------------------------------------------------------
    00047     class KEOS_EXPORT IRenderSystem
    00048     {
    00049     public :
    00050
    00053         IRenderSystem();
    00054
    00057         virtual ~IRenderSystem();
    00058
    00061         virtual const String& GetName(void) const = 0;
    00062
    00071         virtual IRenderWindow* Initialise(bool bAutoCreateWindow, const String& strWindowTitle = "KEOS Render Window");
    00072
    00081         virtual IRenderWindow* CreateRenderWindow(const String &strName, uint nWidth, uint nHeight, uint nColourDepth, bool bFullScreen) = 0;
    00082
    00085         virtual void Reinitialise(void) = 0;
    00086
    00089         virtual void Shutdown(void);
    00090
    00093         void AttachRenderTarget( IRenderTarget& target , bool bIsWindow = true);
    00094
    00098         bool SetRenderApp(IRenderApp* pRenderApp)
    00099         {
    00100             if (m_pRenderWindow == NULL) return false;
    00101             m_pRenderWindow->SetRenderApp(pRenderApp);
    00102             return true;
    00103         }
    00104
    00110         bool SetRenderApp(IRenderApp* pRenderApp, String& strTargetName);
    00111
    00114                 const CRenderSystemCapabilities* GetCapabilities(void) const
    00115         {
    00116             return m_pCapabilities;
    00117         }
    00118
    00121         virtual void BeginScene(void) const = 0;
    00122
    00125         virtual void EndScene(void) const = 0;
    00126
    00129         virtual void PrintInfo(void) const = 0;
    00130
    00133         void InitAllRenderTargets(void);
    00134
    00137         void UpdateAllRenderTargets(void);
    00138
    00142         void DestroyRenderTarget(const String& strName);
    00143
    00148         IRenderTarget* DetachRenderTarget( const String &strName );
    00149
    00154         IRenderTarget* GetRenderTarget( const String &strName );
    00155
    00162         virtual IBufferBase* _CreateVB(ulong nSize, ulong nStride, ulong nFlags) const = 0;
    00163
    00170         virtual IBufferBase* _CreateIB(ulong nSize, ulong nStride, ulong nFlags) const = 0;
    00171
    00177         virtual IDeclaration* CreateDeclaration(const TDeclarationElement* pElements, size_t nCount) const = 0;
    00178
    00186         virtual void _SetVB(uint nStream, const IBufferBase* pBuffer, ulong nStride, ulong nMinVertex, ulong nMaxVertex) = 0;
    00187
    00192         virtual void _SetIB(const IBufferBase* pBuffer, ulong nStride) = 0;
    00193
    00197         virtual void SetDeclaration(const IDeclaration* pDeclaration) = 0;
    00198
    00204         virtual void DrawPrimitives(TPrimitiveType Type, ulong nFirstVertex, ulong nCount) const = 0;
    00205
    00211         virtual void DrawIndexedPrimitives(TPrimitiveType Type, ulong nFirstIndex, ulong nCount) const = 0;
    00212
    00216         virtual void PushMatrix(TMatrixType Type) = 0;
    00217
    00221         virtual void PopMatrix(TMatrixType Type) = 0;
    00222
    00227         virtual void LoadMatrix(TMatrixType Type, const CMatrix4& Matrix) = 0;
    00228
    00233         virtual void LoadMatrixMult(TMatrixType Type, const CMatrix4& Matrix) = 0;
    00234
    00239         virtual void GetMatrix(TMatrixType Type, CMatrix4& Matrix) const = 0;
    00240
    00245         virtual ulong ConvertColor(const CColor& Color) const = 0;
    00246
    00253         template <class T> CBuffer<T> CreateVertexBuffer(ulong nSize, ulong nFlags, const T* pData = NULL) const;
    00254
    00261         template <class T> CBuffer<T> CreateIndexBuffer(ulong nSize, ulong nFlags, const T* pData = NULL) const;
    00262
    00269         template <class T> void SetVertexBuffer(uint nStream, const CBuffer<T>& Buffer, ulong nMinVertex = 0, ulong nMaxVertex = 0);
    00270
    00274         template <class T> void SetIndexBuffer(const CBuffer<T>& Buffer);
    00275
    00280         template <size_t N> IDeclaration* CreateVertexDeclaration(const TDeclarationElement (&Elements)[N]) const;
    00281
    00288         virtual ITextureBase* CreateTexture(const TVector2I& Size, TPixelFormat Format, ulong nFlags = 0) const = 0;
    00289
    00294         virtual void SetTexture(uint nUnit, const ITextureBase* pTexture) const = 0;
    00295
    00298         virtual void InitConfigOptions(void);
    00299
    00302         virtual void SetConfigOption(const String& strName, const String& strValue);
    00303
    00306         virtual ConfigOptionMap GetConfigOptions()
    00307         { return m_Options; }
    00308
    00313         virtual void SetupAlphaBlending(TBlend Src, TBlend Dest) const = 0;
    00314
    00322         virtual void SetupTextureUnit(uint nUnit, TTextureOp Op, TTextureArg Arg1, TTextureArg Arg2 = TXA_DIFFUSE, const CColor& Constant = 0x00) const = 0;
    00323
    00328         virtual void Enable(TRenderParameter Param, bool bValue) const = 0;
    00329
    00334         CGprofile GetShaderProfile(TShaderType Type) const;
    00335
    00340         const char* const* GetShaderOptions(TShaderType Type) const;
    00341
    00347         virtual IShaderBase* CreateShader(CGprogram Program, TShaderType Type) const = 0;
    00348
    00352         virtual void SetVertexShader(const IShaderBase* pShader) = 0;
    00353
    00357         virtual void SetPixelShader(const IShaderBase* pShader) = 0;
    00358
    00362         virtual void SetClearColor(const CColor& Color) = 0;
    00363
    00364     protected :
    00365
    00367         IRenderWindow* m_pRenderWindow;
    00368
    00370         RenderTargetMap m_RenderTargets;
    00371
    00373         CRenderSystemCapabilities* m_pCapabilities;
    00374
    00376             ConfigOptionMap m_Options;
    00377
    00379         CGprofile   m_VSProfile;
    00381         CGprofile   m_PSProfile;
    00383         const char* m_VSOptions[2];
    00385         const char* m_PSOptions[2];
    00386
    00388                 CColor m_ClearColor; //@todo Modifier la place de cette variable
    00389     };
    00390
    00391
    00392     //=======================================================================
    00393     // IRenderSystem inline functions
    00394     //=======================================================================
    00395
    00396     //-----------------------------------------------------------------------
    00397     template <class T>
    00398     inline CBuffer<T> IRenderSystem::CreateVertexBuffer(ulong nSize, ulong nFlags, const T* pData) const
    00399     {
    00400         CBuffer<T> Buffer(_CreateVB(nSize, sizeof(T), nFlags));
    00401         if (pData)
    00402             Buffer.Fill(pData, nSize);
    00403
    00404         return Buffer;
    00405     }
    00406
    00407     //-----------------------------------------------------------------------
    00408     template <class T>
    00409     inline CBuffer<T> IRenderSystem::CreateIndexBuffer(ulong nSize, ulong nFlags, const T* pData) const
    00410     {
    00411         CBuffer<T> Buffer(_CreateIB(nSize, sizeof(T), nFlags));
    00412         if (pData)
    00413             Buffer.Fill(pData, nSize);
    00414
    00415         return Buffer;
    00416     }
    00417
    00418     //-----------------------------------------------------------------------
    00419     template <class T>
    00420     inline void IRenderSystem::SetVertexBuffer(uint nStream, const CBuffer<T>& Buffer, ulong nMinVertex, ulong nMaxVertex)
    00421     {
    00422         _SetVB(nStream, Buffer.GetBuffer(), sizeof(T), nMinVertex, nMaxVertex ? nMaxVertex : Buffer.GetCount() - 1);
    00423     }
    00424
    00425     //-----------------------------------------------------------------------
    00426     template <class T>
    00427     inline void IRenderSystem::SetIndexBuffer(const CBuffer<T>& Buffer)
    00428     {
    00429         _SetIB(Buffer.GetBuffer(), sizeof(T));
    00430     }
    00431
    00432     //-----------------------------------------------------------------------
    00433     template <size_t N>
    00434     IDeclaration* IRenderSystem::CreateVertexDeclaration(const TDeclarationElement (&Elements)[N]) const
    00435     {
    00436         return CreateDeclaration(Elements, N);
    00437     }
    00438
    00439 } // namespace Keos
    00440
    00441 #endif // KEOS_RENDERSYSTEM_H