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.

308 lines
10 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef RENDER3DMS_H
  8. #define RENDER3DMS_H
  9. #pragma once
  10. #include "Render.h"
  11. #include "mathlib/Vector4D.h"
  12. #include "utlpriorityqueue.h"
  13. #include "mapclass.h"
  14. #include "lpreview_thread.h"
  15. //
  16. // Size of the buffer used for picking. See glSelectBuffer for documention on
  17. // the contents of the selection buffer.
  18. //
  19. #define SELECTION_BUFFER_SIZE 50
  20. //
  21. // Size of the texture cache. THis is the maximum number of unique textures that
  22. // a map can refer to and still render properly in the editor.
  23. //
  24. #define TEXTURE_CACHE_SIZE 2048
  25. //
  26. // Maximum number of objects that can be kept in the list of objects to render last.
  27. //
  28. #define MAX_RENDER_LAST_OBJECTS 256
  29. //
  30. // Maximum number of hits that can be returned by ObjectsAt.
  31. //
  32. #define MAX_PICK_HITS 512
  33. class BoundBox;
  34. class CCamera;
  35. class CCullTreeNode;
  36. class CMapClass;
  37. class CMapDoc;
  38. class CMapFace;
  39. class CMapInstance;
  40. class CMapWorld;
  41. class IMaterial;
  42. class IMaterialVar;
  43. template< class T, class A >
  44. class CUtlVector;
  45. enum Visibility_t;
  46. enum SelectionState_t;
  47. typedef struct TranslucentObjects_s {
  48. float depth;
  49. CMapAtom *object;
  50. bool m_bInstanceSelected;
  51. TInstanceState m_InstanceState;
  52. } TranslucentObjects_t;
  53. enum RenderState_t
  54. {
  55. RENDER_CENTER_CROSSHAIR, // Whether to draw the crosshair in the center of the view.
  56. RENDER_GRID, // Whether to draw a projected grid onto solid faces.
  57. RENDER_FILTER_TEXTURES, // Whether to filter textures.
  58. RENDER_POLYGON_OFFSET_FILL, // Whether to offset filled polygons (for decals)
  59. RENDER_POLYGON_OFFSET_LINE, // Whether to offset line polygons (for wireframe selections)
  60. RENDER_REVERSE_SELECTION, // Driver issue fix - whether to return the largest (rather than smallest) Z value when picking
  61. };
  62. //
  63. // Render state information set via RenderEnable:
  64. //
  65. typedef struct
  66. {
  67. bool bCenterCrosshair; // Whether to render the center crosshair.
  68. bool bDrawGrid; // Whether to render the grid.
  69. float fGridSpacing; // Grid spacing in world units.
  70. float fGridDistance; // Maximum distance from camera to draw grid.
  71. bool bFilterTextures; // Whether to filter textures.
  72. bool bReverseSelection; // Driver issue fix - whether to return the largest (rather than smallest) Z value when picking
  73. } RenderStateInfo_t;
  74. class CLightPreview_Light
  75. {
  76. public:
  77. LightDesc_t m_Light;
  78. float m_flDistanceToEye;
  79. };
  80. static inline bool RenderingModeIsTextured(EditorRenderMode_t mode)
  81. {
  82. return (
  83. (mode==RENDER_MODE_TEXTURED) ||
  84. (mode==RENDER_MODE_TEXTURED_SHADED) ||
  85. (mode==RENDER_MODE_LIGHT_PREVIEW_RAYTRACED) ||
  86. (mode==RENDER_MODE_LIGHT_PREVIEW2) );
  87. }
  88. //
  89. // Picking state information used when called from ObjectsAt.
  90. //
  91. typedef struct
  92. {
  93. bool bPicking; // Whether we are rendering in pick mode or not.
  94. unsigned int m_nFlags; // flags
  95. float fX; // Leftmost coordinate of pick rectangle, passed in by caller.
  96. float fY; // Topmost coordinate of pick rectangle, passed in by caller.
  97. float fWidth; // Width of pick rectangle, passed in by caller.
  98. float fHeight; // Height of pick rectangle, passed in by caller.
  99. HitInfo_t *pHitsDest; // Final array in which to place pick hits, passed in by caller.
  100. int nMaxHits; // Maximum number of hits to place in the 'pHits' array, passed in by caller, must be <= MAX_PICK_HITS.
  101. HitInfo_t Hits[MAX_PICK_HITS]; // Temporary array in which to place unsorted pick hits.
  102. int nNumHits; // Number of hits so far in this pick (number of hits in 'Hits' array).
  103. unsigned int uSelectionBuffer[SELECTION_BUFFER_SIZE];
  104. unsigned int uLastZ;
  105. } PickInfo_t;
  106. typedef struct
  107. {
  108. IEditorTexture *pTexture; // Pointer to the texture object that implements this texture.
  109. int nTextureID; // Unique ID of this texture across all renderers.
  110. unsigned int uTexture; // The texture name as returned by OpenGL when the texture was uploaded in this renderer.
  111. } TextureCache_t;
  112. typedef struct
  113. {
  114. HINSTANCE hInstance;
  115. int iCmdShow;
  116. HWND hWnd;
  117. HDC hDC;
  118. bool bActive;
  119. bool bFullScreen;
  120. ATOM wndclass;
  121. WNDPROC wndproc;
  122. bool bChangeBPP;
  123. bool bAllowSoft;
  124. char *szCmdLine;
  125. int argc;
  126. char **argv;
  127. int iResCount;
  128. int iVidMode;
  129. } MatWinData_t;
  130. class CRender3D : public CRender
  131. {
  132. public:
  133. // Constructor / Destructor.
  134. CRender3D(void);
  135. virtual ~CRender3D(void);
  136. // Initialization & shutdown functions.
  137. void ShutDown(void);
  138. float GetElapsedTime(void);
  139. float GetGridDistance(void);
  140. float GetGridSize(void);
  141. bool DeferRendering() const { return m_DeferRendering; }
  142. bool IsEnabled(RenderState_t eRenderState);
  143. bool IsPicking(void);
  144. virtual bool IsInLightingPreview();
  145. virtual void SetInLightingPreview( bool bLightingPreview );
  146. // Operations.
  147. float LightPlane(Vector& Normal);
  148. void UncacheAllTextures();
  149. bool SetView( CMapView *pView );
  150. virtual void StartRenderFrame( bool bRenderingOverEngine );
  151. void EndRenderFrame(void);
  152. virtual void PushInstanceData( CMapInstance *pInstanceClass, Vector &InstanceOrigin, QAngle &InstanceAngles );
  153. virtual void PopInstanceData( void );
  154. void ResetFocus();
  155. // Picking functions.
  156. void BeginRenderHitTarget(CMapAtom *pObject, unsigned int uHandle = 0);
  157. void EndRenderHitTarget(void);
  158. void Render( bool bRenderingOverEngine );
  159. void RenderEnable(RenderState_t eRenderState, bool bEnable);
  160. void RenderCrossHair();
  161. virtual void RenderWireframeBox(const Vector &Mins, const Vector &Maxs, unsigned char chRed, unsigned char chGreen, unsigned char chBlue);
  162. void RenderBox(const Vector &Mins, const Vector &Maxs, unsigned char chRed, unsigned char chGreen, unsigned char chBlue, SelectionState_t eBoxSelectionState);
  163. void RenderArrow(Vector const &vStartPt, Vector const &vEndPt, unsigned char chRed, unsigned char chGreen, unsigned char chBlue);
  164. void RenderCone(Vector const &vBasePt, Vector const &vTipPt, float fRadius, int nSlices,
  165. unsigned char chRed, unsigned char chGreen, unsigned char chBlue );
  166. void RenderSphere(Vector const &vCenter, float flRadius, int nTheta, int nPhi,
  167. unsigned char chRed, unsigned char chGreen, unsigned char chBlue );
  168. void RenderWireframeSphere(Vector const &vCenter, float flRadius, int nTheta, int nPhi,
  169. unsigned char chRed, unsigned char chGreen, unsigned char chBlue );
  170. void RenderInstanceMapClass( CMapInstance *pInstanceClass, CMapClass *pMapClass, Vector &InstanceOrigin, QAngle &InstanceAngles );
  171. int ObjectsAt( float x, float y, float fWidth, float fHeight, HitInfo_t *pObjects, int nMaxObjects, unsigned nFlags = 0 );
  172. void DebugHook1(void *pData = NULL);
  173. void DebugHook2(void *pData = NULL);
  174. // indicates we need to render an overlay pass...
  175. bool NeedsOverlay() const;
  176. CUtlIntrusiveList<CLightingPreviewLightDescription> BuildLightList( void ) const;
  177. void SendLightList(); // send lighting list to lighting preview thread
  178. void SendShadowTriangles();
  179. void AddTranslucentDeferredRendering( CMapPoint *pMapPoint );
  180. void AccumulateLights( CUtlPriorityQueue<CLightPreview_Light> &light_queue,
  181. CMatRenderContextPtr &pRenderContext,
  182. int nTargetWidth, int nTargetHeight,
  183. ITexture *dest_rt );
  184. void SendGBuffersToLightingThread( void );
  185. void SendGBuffersToLightingThread( int nTargetWidth, int nTargetHeight );
  186. // Utility.
  187. float ComputePixelWidthOfSphere( const Vector &vecOrigin, float flRadius );
  188. float ComputePixelDiameterOfSphere( const Vector &vecOrigin, float flRadius );
  189. protected:
  190. inline void DispatchRender3D(CMapClass *pMapClass);
  191. // Rendering functions.
  192. void RenderMapClass(CMapClass *pMapClass);
  193. void RenderInstanceMapClass_r(CMapClass *pMapClass);
  194. void RenderNode(CCullTreeNode *pNode, bool bForce);
  195. void RenderOverlayElements(void);
  196. void RenderTool(void);
  197. void RenderTree( CMapWorld *pWorld );
  198. void RenderPointsAndPortals(void);
  199. void RenderWorldAxes();
  200. void RenderTranslucentObjects( void );
  201. void RenderFoW( void );
  202. // Utility functions.
  203. void Preload(CMapClass *pParent);
  204. Visibility_t IsBoxVisible(Vector const &BoxMins, Vector const &BoxMaxs);
  205. // Frustum methods
  206. void ComputeFrustumRenderGeometry(CCamera * pCamera);
  207. void RenderFrustum();
  208. float m_fFrameRate; // Framerate in frames per second, calculated once per second.
  209. int m_nFramesThisSample; // Number of frames rendered in the current sample period.
  210. DWORD m_dwTimeLastSample; // Time when the framerate was last calculated.
  211. DWORD m_dwTimeLastFrame; // The time when the previous frame was rendered.
  212. float m_fTimeElapsed; // Milliseconds elapsed since the last frame was rendered.
  213. // context for the last bitmap we sent to lighting preview for ray tracing. we do not send if
  214. // nothing happens, even if we end up re-rendering
  215. Vector m_LastLPreviewCameraPos;
  216. float m_fLastLPreviewAngles[3]; // y,p,r
  217. float m_fLastLPreviewZoom;
  218. int m_nLastLPreviewWidth;
  219. int m_nLastLPreviewHeight;
  220. Vector4D m_FrustumPlanes[6]; // Plane normals and constants for the current view frustum.
  221. MatWinData_t m_WinData; // Defines our render window parameters.
  222. PickInfo_t m_Pick; // Contains information used when rendering in pick mode.
  223. RenderStateInfo_t m_RenderState; // Render state set via RenderEnable.
  224. bool m_bDroppedCamera; // Whether we have dropped the camera for debugging.
  225. bool m_DeferRendering; // Used when we want to sort lovely opaque objects
  226. bool m_TranslucentSortRendering; // Used when we want to sort translucent objects
  227. CCamera *m_pDropCamera; // Dropped camera to use for debugging.
  228. CUtlPriorityQueue<TranslucentObjects_t> m_TranslucentRenderObjects; // List of objects to render after all the other objects.
  229. IMaterial* m_pVertexColor[2]; // for selecting actual textures
  230. bool m_bLightingPreview;
  231. // for debugging... render the view frustum
  232. #ifdef _DEBUG
  233. Vector m_FrustumRenderPoint[8];
  234. bool m_bRenderFrustum;
  235. bool m_bRecomputeFrustumRenderGeometry;
  236. #endif
  237. };
  238. #endif // RENDER3DGL_H