Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.6 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. #ifndef ISCENESYSTEM
  3. #define ISCENESYSTEM
  4. #ifdef _WIN32
  5. #pragma once
  6. #endif
  7. #include "appframework/iappsystem.h"
  8. #include "mathlib/camera.h"
  9. #include "rendersystem/irenderdevice.h"
  10. #include "rendersystem/irendercontext.h"
  11. #include "rendersystem/indexdata.h"
  12. #include "rendersystem/vertexdata.h"
  13. #include "particles/particles.h"
  14. #include "rendersystem/schema/renderbuffer.g.h"
  15. #include "rendersystem/schema/renderable.g.h"
  16. //---------------------------------------------------------------------------------------------------------------------------------------------------
  17. // Forward declarations
  18. //---------------------------------------------------------------------------------------------------------------------------------------------------
  19. class CSceneObject; // something that can be rendered
  20. class CSceneParticleObject;
  21. class CSceneMonitorObject;
  22. class CSceneObjectList; // a set of objects which pass some
  23. // test (for example, being in the
  24. // frustum. generated by traversal
  25. class CSceneView; // describes one scene render, such as
  26. // a splitscreen view, a shadow map
  27. // frustum, etc.
  28. enum MaterialDrawMode_t
  29. {
  30. MATDRAWMODE_REGULAR = 0, // full forward rendering
  31. MATDRAWMODE_LIGHTPREPASS = 1, // output to a gbuffer
  32. MATDRAWMODE_LIGHTPOSTPASS = 2, // 2nd pass deferred
  33. MATDRAWMODE_NUMMODES
  34. };
  35. // placeholder
  36. struct Mat2DrawModeDescriptor_t
  37. {
  38. HRenderTextureStrong m_hTextureToBind;
  39. RenderShaderHandle_t m_hVertexShader;
  40. RenderShaderHandle_t m_hPixelShader;
  41. };
  42. class IMat2
  43. {
  44. public:
  45. Mat2DrawModeDescriptor_t m_drawDescriptors[MATDRAWMODE_NUMMODES];
  46. RenderInputLayout_t m_hLayout;
  47. uint m_nPassFlags; // SCENEOBJECTFLAG_ flags about which material this pass renders in.
  48. void Bind( IRenderContext *pCtx, MaterialDrawMode_t nMode, RenderInputLayout_t hLayout = RENDER_INPUT_LAYOUT_INVALID );
  49. };
  50. struct ModelVertexXFormStream_t
  51. {
  52. Vector4D m_matTransform0;
  53. Vector4D m_matTransform1;
  54. Vector4D m_matTransform2;
  55. };
  56. struct CMeshDrawPrimitive_t
  57. {
  58. uint32 m_nSortKey;
  59. matrix3x4_t *m_pTransform;
  60. MaterialDrawDescriptor_t const *m_pDrawOp;
  61. CSceneObject *m_pObject;
  62. };
  63. class ISceneObjectDesc
  64. {
  65. public:
  66. virtual CSceneObject *Create( void ) = 0;
  67. virtual void DrawArray( class IRenderContext *pCtx, CMeshDrawPrimitive_t *pRenderList, int nNumRenderablesToDraw,
  68. class CSceneView const *pView, class CSceneLayer *pLayer ) {}
  69. // generate the simple static vb primitives for this object. may be called with a non 0
  70. // nStartPrimitive multiple times if there is a buffer overflow (this should be a rare
  71. // occurrence
  72. virtual int GeneratePrimitives( CSceneObject *pObject, int nStartPrimitive, int nMaxOutputPrimitives, CMeshDrawPrimitive_t *pOutBuf,
  73. CSceneView const *pView, CSceneLayer *pLayer ) { return 0; }
  74. };
  75. class CSceneLayer;
  76. typedef void (*LAYERDRAWFN)( class ISceneView *pView, IRenderContext *pCtx, CSceneLayer *pLayer );
  77. class ISceneView // this class is going to become concrete
  78. {
  79. public:
  80. virtual CSceneLayer *AddRenderLayer( RenderViewport_t const &viewport, MaterialDrawMode_t eShaderMode ) =0;
  81. virtual CSceneLayer *AddProceduralLayer( RenderViewport_t const &viewport, LAYERDRAWFN pFnToRender ) =0;
  82. virtual ~ISceneView( void ) {}
  83. };
  84. abstract_class ISceneSystem : public IAppSystem
  85. {
  86. public:
  87. // creating renderables
  88. virtual CSceneObject *CreateSceneObject( ISceneObjectDesc *pDesc, uint nFlags ) =0;
  89. // finding and adding renderable types
  90. virtual ISceneObjectDesc *GetSceneObjectDesc( char const *pName ) = 0;
  91. virtual void AddSceneObjectType( char const *pName, ISceneObjectDesc *pDescriptor ) =0;
  92. virtual CSceneObject *CreateSceneObject( uint nFlags ) =0;
  93. // rendering. First call beginRenderingViews, then call AddRenerView on all of the views you
  94. // want to render, and then call FinishRenderingViews which will kick off all of the threads.
  95. // since rendering is asynchronous, you need to call WaitForRenderingToComplete() before
  96. // starting another render or changing the state of sceneobjects, etc.
  97. virtual void BeginRenderingViews( IRenderDevice *pDevice ) = 0;
  98. virtual ISceneView *AddView( CFrustum const &frustum ) = 0;
  99. virtual void BeginRenderingDynamicView( ISceneView *pView ) = 0; // only call this on views created during rendering
  100. virtual void FinishRenderingViews( void ) = 0;
  101. virtual void WaitForRenderingToComplete( void ) = 0;
  102. virtual void InitSystem( void ) =0;
  103. // general obejct stuff
  104. virtual void SetObjectBounds( CSceneObject *pObj, Vector const &vecMins, Vector const &vecMaxes ) =0;
  105. // particles
  106. virtual CSceneParticleObject *CreateParticleObject( const char *pParticleSystemName, float flDelay = 0.0f, int nRandomSeed = 0 ) =0;
  107. virtual CSceneMonitorObject *CreateMonitorObject( void ) =0;
  108. virtual CParticleSystemMgr *ParticleMgr( void ) =0;
  109. virtual bool ReadParticleConfigFile( const char *pFileName, bool bPrecache, bool bDecommitTempMemory = true ) =0;
  110. // create a particle system by name. returns null if one of that name does not exist
  111. virtual CParticleCollection *CreateParticleCollection( const char *pParticleSystemName, float flDelay = 0.0f, int nRandomSeed = 0 ) =0;
  112. virtual CParticleCollection *CreateParticleCollection( ParticleSystemHandle_t particleSystemName, float flDelay = 0.0f, int nRandomSeed = 0 ) =0;
  113. virtual void Shutdown( void ) =0;
  114. virtual ~ISceneSystem( void ) {}
  115. };
  116. #endif // ISCENESYSTEM