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.

546 lines
22 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef IRENDERDEVICE_H
  9. #define IRENDERDEVICE_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "tier1/interface.h"
  14. #include "appframework/iappsystem.h"
  15. #include "bitmap/imageformat.h"
  16. #include "tier1/utlbuffer.h"
  17. #include "mathlib/vector4d.h"
  18. #include "bitmap/colorformat.h"
  19. #include "rendersystem/renderstate.h"
  20. #include "resourcesystem/stronghandle.h"
  21. #include "rendersystem/schema/texture.g.h"
  22. #include "rendersystem/schema/renderbuffer.g.h"
  23. #include "rendersystem/schema/renderable.g.h"
  24. #include "tier0/platwindow.h"
  25. //-----------------------------------------------------------------------------
  26. // forward declarations
  27. //-----------------------------------------------------------------------------
  28. class KeyValues;
  29. struct RenderInputLayoutField_t;
  30. class IRenderContext;
  31. struct Rect_t;
  32. //-----------------------------------------------------------------------------
  33. // turn this on to get logging
  34. //----------------------------------------------------------------------------
  35. //#define LOG_COMMAND_BUFFER_EXECUTE
  36. //-----------------------------------------------------------------------------
  37. // Adapter info
  38. //-----------------------------------------------------------------------------
  39. enum
  40. {
  41. RENDER_ADAPTER_NAME_LENGTH = 512
  42. };
  43. struct RenderAdapterInfo_t
  44. {
  45. char m_pDriverName[RENDER_ADAPTER_NAME_LENGTH];
  46. unsigned int m_VendorID;
  47. unsigned int m_DeviceID;
  48. unsigned int m_SubSysID;
  49. unsigned int m_Revision;
  50. int m_nDXSupportLevel; // This is the *preferred* dx support level
  51. int m_nMinDXSupportLevel;
  52. int m_nMaxDXSupportLevel;
  53. unsigned int m_nDriverVersionHigh;
  54. unsigned int m_nDriverVersionLow;
  55. };
  56. //-----------------------------------------------------------------------------
  57. // Flags to be used with the CreateDevice call
  58. //-----------------------------------------------------------------------------
  59. enum RenderCreateDeviceFlags_t
  60. {
  61. RENDER_CREATE_DEVICE_RESIZE_WINDOWS = 0x1,
  62. };
  63. //-----------------------------------------------------------------------------
  64. // Describes how to set the mode
  65. //-----------------------------------------------------------------------------
  66. #define RENDER_DISPLAY_MODE_VERSION 1
  67. struct RenderDisplayMode_t
  68. {
  69. RenderDisplayMode_t() { memset( this, 0, sizeof(RenderDisplayMode_t) ); m_nVersion = RENDER_DISPLAY_MODE_VERSION; }
  70. int m_nVersion;
  71. int m_nWidth; // 0 when running windowed means use desktop resolution
  72. int m_nHeight;
  73. ImageFormat m_Format; // use ImageFormats (ignored for windowed mode)
  74. int m_nRefreshRateNumerator; // Refresh rate. Use 0 in numerator + denominator for a default setting.
  75. int m_nRefreshRateDenominator; // Refresh rate = numerator / denominator.
  76. };
  77. //-----------------------------------------------------------------------------
  78. // Describes how to set the device
  79. //-----------------------------------------------------------------------------
  80. #define RENDER_DEVICE_INFO_VERSION 1
  81. struct RenderDeviceInfo_t
  82. {
  83. RenderDeviceInfo_t() { memset( this, 0, sizeof(RenderDeviceInfo_t) ); m_nVersion = RENDER_DEVICE_INFO_VERSION; m_DisplayMode.m_nVersion = RENDER_DISPLAY_MODE_VERSION; }
  84. int m_nVersion;
  85. RenderDisplayMode_t m_DisplayMode;
  86. int m_nBackBufferCount; // valid values are 1 or 2 [2 results in triple buffering]
  87. RenderMultisampleType_t m_nMultisampleType;
  88. bool m_bFullscreen : 1;
  89. bool m_bUseStencil : 1;
  90. bool m_bWaitForVSync : 1; // Would we not present until vsync?
  91. bool m_bScaleToOutputResolution : 1;// 360 ONLY: sets up hardware scaling
  92. bool m_bProgressive : 1; // 360 ONLY: interlaced or progressive
  93. bool m_bUsingMultipleWindows : 1; // Forces D3DPresent to use _COPY instead
  94. };
  95. //-----------------------------------------------------------------------------
  96. // Vertex field description
  97. //-----------------------------------------------------------------------------
  98. enum
  99. {
  100. RENDER_INPUT_LAYOUT_FIELD_SEMANTIC_NAME_SIZE = 32,
  101. };
  102. struct RenderInputLayoutField_t
  103. {
  104. char m_pSemanticName[RENDER_INPUT_LAYOUT_FIELD_SEMANTIC_NAME_SIZE];
  105. int m_nSemanticIndex;
  106. ColorFormat_t m_Format;
  107. int m_nOffset;
  108. int m_nSlot;
  109. RenderSlotType_t m_nSlotType;
  110. int m_nInstanceStepRate;
  111. };
  112. #define DEFINE_PER_VERTEX_FIELD( _slot, _name, _index, _vertexformat, _field ) \
  113. { _name, _index, ComputeColorFormat( &(((_vertexformat*)0)->_field) ), offsetof( _vertexformat, _field ), _slot, RENDER_SLOT_PER_VERTEX, 0 },
  114. #define DEFINE_PER_INSTANCE_FIELD( _slot, _stepRate, _name, _index, _vertexformat, _field ) \
  115. { _name, _index, ComputeColorFormat( &(((_vertexformat*)0)->_field) ), offsetof( _vertexformat, _field ), _slot, RENDER_SLOT_PER_INSTANCE, _stepRate },
  116. //-----------------------------------------------------------------------------
  117. // When we switch render target bindings, should we keep the contents?
  118. //-----------------------------------------------------------------------------
  119. enum RenderTargetBindingFlags_t
  120. {
  121. DISCARD_CONTENTS = 0x00,
  122. PRESERVE_COLOR0 = 0x01, // corresponds to Render Target 0
  123. PRESERVE_COLOR1 = 0x02, // corresponds to Render Target 1
  124. PRESERVE_COLOR2 = 0x04,
  125. PRESERVE_COLOR3 = 0x08,
  126. PRESERVE_DEPTHSTENCIL = 0x10,
  127. PRESERVE_CONTENTS = PRESERVE_COLOR0 | PRESERVE_COLOR1 | PRESERVE_COLOR2 | PRESERVE_COLOR3 | PRESERVE_DEPTHSTENCIL,
  128. TILE_VERTICALLY = 0x20, // by default, we tile horizontally (splits are vertical)
  129. };
  130. //-----------------------------------------------------------------------------
  131. // Variations on input layouts
  132. // These are used to support various types of instancing
  133. //-----------------------------------------------------------------------------
  134. enum InputLayoutVariation_t
  135. {
  136. INPUT_LAYOUT_VARIATION_DEFAULT = 0x00,
  137. INPUT_LAYOUT_VARIATION_STREAM1_MAT3X4,
  138. INPUT_LAYOUT_VARIATION_STREAM1_MAT4X4,
  139. INPUT_LAYOUT_VARIATION_MAX
  140. };
  141. //-----------------------------------------------------------------------------
  142. // Handle to a vertex format
  143. //-----------------------------------------------------------------------------
  144. DECLARE_HANDLE_32BIT( RenderInputLayout_t );
  145. #define RENDER_INPUT_LAYOUT_INVALID ( RenderInputLayout_t::MakeHandle( (uint32)~0 ) )
  146. //-----------------------------------------------------------------------------
  147. // Standard texture handles
  148. //-----------------------------------------------------------------------------
  149. #define RENDER_TEXTURE_DEFAULT_RENDER_TARGET ( (HRenderTexture)-1 )
  150. //-----------------------------------------------------------------------------
  151. // Handle to a render resource
  152. //-----------------------------------------------------------------------------
  153. DECLARE_POINTER_HANDLE( RenderResourceHandle_t );
  154. #define RENDER_RESOURCE_HANDLE_INVALID ( (RenderResourceHandle_t)0 )
  155. //-----------------------------------------------------------------------------
  156. // Handle to a class that describes which render targets are in use
  157. //-----------------------------------------------------------------------------
  158. DECLARE_DERIVED_POINTER_HANDLE( RenderTargetBinding_t, RenderResourceHandle_t );
  159. #define RENDER_TARGET_BINDING_INVALID ( (RenderTargetBinding_t)0 )
  160. #define RENDER_TARGET_BINDING_BACK_BUFFER ( (RenderTargetBinding_t)-1 )
  161. //-----------------------------------------------------------------------------
  162. // Handle to a vertex, pixel, geometry, etc. shader
  163. //-----------------------------------------------------------------------------
  164. DECLARE_DERIVED_POINTER_HANDLE( RenderShaderHandle_t, RenderResourceHandle_t );
  165. #define RENDER_SHADER_HANDLE_INVALID ( (RenderShaderHandle_t)0 )
  166. enum RenderShaderType_t
  167. {
  168. RENDER_SHADER_TYPE_INVALID = -1,
  169. RENDER_PIXEL_SHADER = 0,
  170. RENDER_VERTEX_SHADER,
  171. RENDER_GEOMETRY_SHADER,
  172. RENDER_SHADER_TYPE_COUNT,
  173. };
  174. //-----------------------------------------------------------------------------
  175. // Handle to a vertex buffer/indexbuffer
  176. //-----------------------------------------------------------------------------
  177. DECLARE_DERIVED_POINTER_HANDLE( VertexBufferHandle_t, RenderResourceHandle_t );
  178. DECLARE_DERIVED_POINTER_HANDLE( IndexBufferHandle_t, RenderResourceHandle_t );
  179. #define VERTEX_BUFFER_HANDLE_INVALID ( (VertexBufferHandle_t)0 )
  180. #define INDEX_BUFFER_HANDLE_INVALID ( (IndexBufferHandle_t)0 )
  181. //-----------------------------------------------------------------------------
  182. // constant buffers
  183. //-----------------------------------------------------------------------------
  184. DECLARE_DERIVED_POINTER_HANDLE( ConstantBufferHandle_t, RenderResourceHandle_t );
  185. #define CONSTANT_BUFFER_HANDLE_INVALID ( ( ConstantBufferHandle_t ) 0 )
  186. //-----------------------------------------------------------------------------
  187. // A shader buffer returns a block of memory which must be released when done with it
  188. //-----------------------------------------------------------------------------
  189. abstract_class IRenderShaderBuffer
  190. {
  191. public:
  192. virtual size_t GetSize() const = 0;
  193. virtual const void* GetBits() const = 0;
  194. virtual void Release() = 0;
  195. };
  196. //-----------------------------------------------------------------------------
  197. // Swap chain handle
  198. //-----------------------------------------------------------------------------
  199. DECLARE_POINTER_HANDLE( SwapChainHandle_t );
  200. #define SWAP_CHAIN_HANDLE_INVALID ( (SwapChainHandle_t)0 )
  201. //-----------------------------------------------------------------------------
  202. // Mode change callback
  203. //-----------------------------------------------------------------------------
  204. typedef void (*RenderModeChangeCallbackFunc_t)( void );
  205. //-----------------------------------------------------------------------------
  206. // This is a little wacky. It's super convenient for app systems to be
  207. // able to use the render device in their Init() blocks. This is tricky
  208. // however because we don't have a great way of getting data to the
  209. // devicemgr so it knows how to create the device. Specifically, we need to
  210. // tell it which adapter to use, whether we're going to have resizing windows,
  211. // and what window we're going to have 3D on (this is a dx9 restriction).
  212. // So, we need to be able to run application code right after renderdevice init
  213. // but before any other inits. The other alternative is for the application
  214. // to send information to the render device mgr post connect but pre init.
  215. // The first option is better because it lets the application do arbitrary
  216. // stuff after it can query information about adapters, etc.
  217. //-----------------------------------------------------------------------------
  218. abstract_class IRenderDeviceSetup
  219. {
  220. public:
  221. // This will be called by the render device mgr after it initializes itself
  222. virtual bool CreateRenderDevice() = 0;
  223. };
  224. //-----------------------------------------------------------------------------
  225. // Methods related to discovering and selecting devices
  226. //-----------------------------------------------------------------------------
  227. abstract_class IRenderDeviceMgr : public IAppSystem
  228. {
  229. public:
  230. // Gets the number of adapters...
  231. virtual int GetAdapterCount() const = 0;
  232. // Returns info about each adapter
  233. virtual void GetAdapterInfo( int nAdapter, RenderAdapterInfo_t& info ) const = 0;
  234. // Gets recommended congifuration for a particular adapter at a particular dx level
  235. virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pConfiguration ) = 0;
  236. // Returns the number of modes
  237. virtual int GetModeCount( int nAdapter ) const = 0;
  238. // Returns mode information..
  239. virtual void GetModeInfo( RenderDisplayMode_t* pInfo, int nAdapter, int nMode ) const = 0;
  240. // Returns the current mode info for the requested adapter
  241. virtual void GetCurrentModeInfo( RenderDisplayMode_t* pInfo, int nAdapter ) const = 0;
  242. // Use the returned factory to get at an IRenderDevice and an IHardwareConfig
  243. // and any other interfaces we decide to create.
  244. // A returned factory of NULL indicates the device was not created properly.
  245. virtual CreateInterfaceFn CreateDevice( int nAdapter, int nFlags, int nDXLevel = 0 ) = 0;
  246. // Installs a callback to get called
  247. virtual void AddModeChangeCallback( RenderModeChangeCallbackFunc_t func ) = 0;
  248. virtual void RemoveModeChangeCallback( RenderModeChangeCallbackFunc_t func ) = 0;
  249. virtual bool GetRecommendedVideoConfig( int nAdapter, KeyValues *pConfiguration ) = 0;
  250. // Destroys the device
  251. virtual void DestroyDevice() = 0;
  252. // Method to allow callbacks to set up the device during init
  253. // See big comment above IRenderDeviceSetup for why this is necessary
  254. virtual void InstallRenderDeviceSetup( IRenderDeviceSetup *pSetup ) = 0;
  255. };
  256. //-----------------------------------------------------------------------------
  257. // Data for vertex/index buffer creation
  258. //-----------------------------------------------------------------------------
  259. struct BufferDesc_t
  260. {
  261. int m_nElementCount; // Number of vertices/indices
  262. int m_nElementSizeInBytes; // Size of a single vertex/index
  263. const char * m_pDebugName; // Used to debug buffers
  264. const char * m_pBudgetGroupName;
  265. };
  266. //-----------------------------------------------------------------------------
  267. // Base class for abstract dependency class obtained and managed by the render device. These MUST
  268. // be gotten from the device in order to be used in submits. Application code only needs to treat
  269. // these as pointers/handles
  270. //-----------------------------------------------------------------------------
  271. class CDependencyDescriptor;
  272. enum RenderSystemAssetFileLoadMode_t // controls behavior when rendersystem assets are created from files
  273. {
  274. LOADMODE_IMMEDIATE, // asset is created and loaded from disk immediately
  275. LOADMODE_ASYNCHRONOUS, // asset will start loading asynchronously
  276. LOADMODE_STREAMED, // asset will be asynchronously loaded when referenced.
  277. };
  278. //-----------------------------------------------------------------------------
  279. // Methods related to control of the device
  280. //-----------------------------------------------------------------------------
  281. abstract_class IRenderDevice
  282. {
  283. public:
  284. // Creates a 'swap chain' which represents a back buffer and a window.
  285. // When present happens, you must pass it a swap chain handle.
  286. virtual SwapChainHandle_t CreateSwapChain( PlatWindow_t hWnd, const RenderDeviceInfo_t &mode ) = 0;
  287. virtual void DestroySwapChain( SwapChainHandle_t hSwapChain ) = 0;
  288. virtual void UpdateSwapChain( SwapChainHandle_t hSwapChain, const RenderDeviceInfo_t &mode ) = 0;
  289. virtual const RenderDeviceInfo_t &GetSwapChainInfo( SwapChainHandle_t hSwapChain ) const = 0;
  290. // Returns the window associated with a swap chain
  291. virtual PlatWindow_t GetSwapChainWindow( SwapChainHandle_t hSwapChain ) const = 0;
  292. // Releases/reloads resources when other apps want some memory
  293. virtual void ReleaseResources() = 0;
  294. virtual void ReacquireResources() = 0;
  295. // returns the backbuffer format and dimensions
  296. virtual ImageFormat GetBackBufferFormat( SwapChainHandle_t hSwapChain ) const = 0;
  297. virtual void GetBackBufferDimensions( SwapChainHandle_t hSwapChain, int *pWidth, int *pHeight ) const = 0;
  298. // Returns the current adapter in use
  299. virtual int GetCurrentAdapter() const = 0;
  300. // Are we using graphics?
  301. virtual bool IsUsingGraphics() const = 0;
  302. // Use this to spew information about the 3D layer
  303. virtual void SpewDriverInfo() const = 0;
  304. // What's the bit depth of the stencil buffer?
  305. virtual int StencilBufferBits() const = 0;
  306. // Are we using a mode that uses MSAA
  307. virtual bool IsAAEnabled() const = 0;
  308. // Which version string should we use when compiling shaders
  309. virtual const char *GetShaderVersionString( RenderShaderType_t nType ) const = 0;
  310. // Does a page flip
  311. virtual void Present( ) = 0;
  312. // Gamma ramp control
  313. virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ) = 0;
  314. // Shader compilation
  315. virtual IRenderShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) = 0;
  316. // Shader creation, destruction
  317. virtual RenderShaderHandle_t CreateShader( RenderShaderType_t nType, IRenderShaderBuffer* pShaderBuffer ) = 0;
  318. virtual void DestroyShader( RenderShaderType_t nType, RenderShaderHandle_t hShader ) = 0;
  319. // Defines input layouts
  320. virtual RenderInputLayout_t CreateInputLayout( const char *pLayoutName, int nFieldCount, const RenderInputLayoutField_t *pFieldDescs ) = 0;
  321. virtual void DestroyInputLayout( RenderInputLayout_t hInputLayout ) = 0;
  322. // Defines render target bind objects
  323. // NOTE: Use RENDER_TARGET_BINDING_BACK_BUFFER for the back buffer
  324. // Also note: If you need to re-use a buffer and render into it a second time,
  325. // create a new render target binding to the same buffer. That will help sorting
  326. virtual RenderTargetBinding_t CreateRenderTargetBinding( int nFlags, int nRenderTargetCount, const HRenderTexture *pRenderTargets, HRenderTexture hDepthStencilTexture ) = 0;
  327. RenderTargetBinding_t CreateRenderTargetBinding( int nFlags, HRenderTexture hRenderTarget, HRenderTexture hDepthStencilTexture );
  328. virtual void DestroyRenderTargetBinding( RenderTargetBinding_t hBinding ) = 0;
  329. // Utility methods to make shader creation simpler
  330. // NOTE: For the utlbuffer version, use a binary buffer for a compiled shader
  331. // and a text buffer for a source-code (.fxc) shader
  332. RenderShaderHandle_t CreateShader( RenderShaderType_t nType, const char *pProgram, size_t nBufLen, const char *pShaderVersion );
  333. RenderShaderHandle_t CreateShader( RenderShaderType_t nType, CUtlBuffer &buf, const char *pShaderVersion = NULL );
  334. RenderShaderHandle_t CreateShader( RenderShaderType_t nType, const void *pCompiledProgram, size_t nBufLen );
  335. // Creates render state objects
  336. virtual RsRasterizerStateHandle_t FindOrCreateRasterizerState( const RsRasterizerStateDesc_t *pRsDesc ) = 0;
  337. virtual RsDepthStencilStateHandle_t FindOrCreateDepthStencilState( const RsDepthStencilStateDesc_t *pDsDesc ) = 0;
  338. virtual RsBlendStateHandle_t FindOrCreateBlendState( const RsBlendStateDesc_t *pBlendDesc ) = 0;
  339. // Creates/destroys vertex + index buffers
  340. // For CreateIndexBuffer, nMaxInstanceCount == 0 means we don't expect
  341. // the buffer to be used w/ instanced rendering.
  342. // mNaxInstanceCount == INT_MAX means we have no idea how many instances will be rendered
  343. virtual HRenderBuffer CreateRenderBuffer( const char *pGroupName, const char *pResourceName, const RenderBufferDesc_t *pDescriptor, size_t nDataSize ) = 0;
  344. virtual void DestroyRenderBuffer( HRenderBuffer hBuffer ) = 0;
  345. virtual HRenderBuffer CreateVertexBuffer( RenderBufferType_t nType, const BufferDesc_t& desc ) = 0;
  346. virtual void DestroyVertexBuffer( HRenderBuffer hVertexBuffer ) = 0;
  347. virtual HRenderBuffer CreateIndexBuffer( RenderBufferType_t nType, const BufferDesc_t& desc, int nMaxInstanceCount = 0 ) = 0;
  348. virtual void DestroyIndexBuffer( HRenderBuffer hIndexBuffer ) = 0;
  349. // Query buffer info
  350. virtual void GetVertexBufferDesc( HRenderBuffer hVertexBuffer, BufferDesc_t *pDesc ) = 0;
  351. virtual void GetIndexBufferDesc( HRenderBuffer hIndexBuffer, BufferDesc_t *pDesc ) = 0;
  352. // textures
  353. virtual HRenderTexture FindOrCreateTexture( const char *pGroupName, const char *pResourceName, const TextureHeader_t *pDescriptor ) = 0;
  354. // manage file-backed textures.
  355. virtual HRenderTexture FindOrCreateFileTexture( const char *pFileName, RenderSystemAssetFileLoadMode_t nLoadMode = LOADMODE_ASYNCHRONOUS ) = 0;
  356. virtual HRenderTexture FindFileTexture( ResourceId_t nId, RenderSystemAssetFileLoadMode_t nLoadMode = LOADMODE_ASYNCHRONOUS ) = 0;
  357. // Allows use of render contexts
  358. virtual void EnableRenderContexts( bool bEnable ) = 0;
  359. // render contexts
  360. virtual IRenderContext *GetRenderContext( ) = 0;
  361. virtual void ReleaseRenderContext( IRenderContext *pContext ) = 0;
  362. // submitting pre-built display lists
  363. virtual void SubmitDisplayList( class CDisplayList *pCommandList ) =0;
  364. // there is no release. These are automatically released when satisfied, and as far as the client is concerned, they are all gone after Present().
  365. virtual CDependencyDescriptor *GetDependencyDescriptor( int nNumBatchesWhichWillBeSubmitted = 1, char const *pDebugString = NULL ) =0;
  366. // create/destroy constant buffers
  367. virtual ConstantBufferHandle_t CreateConstantBuffer( size_t nNumBytes ) { return NULL; };
  368. virtual void DestroyConstantBuffer( ConstantBufferHandle_t hConstantBuffer ) {};
  369. // Forces a device lost
  370. virtual void ForceDeviceLost() = 0;
  371. // Reads the contents of a texture
  372. virtual void ReadTexturePixels( HRenderTexture hTexture, Rect_t *pSrcRect, Rect_t *pDstRect, void *pData, ImageFormat dstFormat, int nDstStride ) = 0;
  373. };
  374. //-----------------------------------------------------------------------------
  375. // Helper wrapper for IRenderShaderBuffer for reading precompiled shader files
  376. // NOTE: This is meant to be instanced on the stack; so don't call Release!
  377. //-----------------------------------------------------------------------------
  378. class CUtlRenderShaderBuffer : public IRenderShaderBuffer
  379. {
  380. public:
  381. CUtlRenderShaderBuffer( CUtlBuffer &buf ) : m_pBuf( &buf ) {}
  382. virtual size_t GetSize() const
  383. {
  384. return m_pBuf->TellMaxPut();
  385. }
  386. virtual const void* GetBits() const
  387. {
  388. return m_pBuf->Base();
  389. }
  390. virtual void Release()
  391. {
  392. Assert( 0 );
  393. }
  394. private:
  395. CUtlBuffer *m_pBuf;
  396. };
  397. //-----------------------------------------------------------------------------
  398. // Inline methods of IRenderDevice
  399. //-----------------------------------------------------------------------------
  400. inline RenderTargetBinding_t IRenderDevice::CreateRenderTargetBinding( int nFlags, HRenderTexture hRenderTarget, HRenderTexture hDepthStencilTexture )
  401. {
  402. return CreateRenderTargetBinding( nFlags, 1, &hRenderTarget, hDepthStencilTexture );
  403. }
  404. inline RenderShaderHandle_t IRenderDevice::CreateShader( RenderShaderType_t nType, const char *pProgram, size_t nBufLen, const char *pShaderVersion )
  405. {
  406. RenderShaderHandle_t hShader = RENDER_SHADER_HANDLE_INVALID;
  407. IRenderShaderBuffer* pShaderBuffer = CompileShader( pProgram, nBufLen, pShaderVersion );
  408. if ( pShaderBuffer )
  409. {
  410. hShader = CreateShader( nType, pShaderBuffer );
  411. pShaderBuffer->Release();
  412. }
  413. return hShader;
  414. }
  415. inline RenderShaderHandle_t IRenderDevice::CreateShader( RenderShaderType_t nType, CUtlBuffer &buf, const char *pShaderVersion )
  416. {
  417. // NOTE: Text buffers are assumed to have source-code shader files
  418. // Binary buffers are assumed to have compiled shader files
  419. if ( buf.IsText() )
  420. {
  421. Assert( pShaderVersion );
  422. return CreateShader( nType, (const char *)buf.Base(), buf.TellMaxPut(), pShaderVersion );
  423. }
  424. CUtlRenderShaderBuffer shaderBuffer( buf );
  425. return CreateShader( nType, &shaderBuffer );
  426. }
  427. inline RenderShaderHandle_t IRenderDevice::CreateShader( RenderShaderType_t nType, const void *pCompiledProgram, size_t nBufLen )
  428. {
  429. Assert( nBufLen == ( int )nBufLen ); // make sure we're not trimming 4Gb+ sizes
  430. CUtlBuffer tmpBuf( pCompiledProgram, ( int )nBufLen, CUtlBuffer::READ_ONLY );
  431. return CreateShader( nType, tmpBuf, NULL );
  432. }
  433. #endif // IRENDERDEVICE_H