Team Fortress 2 Source Code as on 22/4/2020
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.

165 lines
7.0 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef IUIRENDERENGINE_H
  6. #define IUIRENDERENGINE_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panoramatypes.h"
  11. #include "tier1/refcount.h"
  12. #if defined( SOURCE2_PANORAMA )
  13. class IRenderContext;
  14. #include "rendermessages.pb.h"
  15. class IRenderContext;
  16. #else
  17. #include "../../panorama/renderer/rendermessages.pb.h"
  18. #endif
  19. class CMsgFillBrushCollection;
  20. namespace panorama
  21. {
  22. enum E2DTextureFormat
  23. {
  24. k_EFormatRGBA8,
  25. k_EFormatBGRA8,
  26. k_EFormatBGR8, // 8 bits per channel, last 8 bits in the dword are ignored
  27. k_EFormatA8,
  28. k_EFormatYUV420,
  29. k_EFormatR16G16B16A16,
  30. k_EFormatDXT1,
  31. k_EFormatDXT5,
  32. };
  33. enum EAlphaChannelType
  34. {
  35. k_EAlphaChannelType_None,
  36. k_EAlphaChannelType_Normal,
  37. k_EAlphaChannelType_PreMultiplied,
  38. };
  39. //
  40. // Class to represent all textures
  41. //
  42. class IUITexture
  43. {
  44. public:
  45. virtual ~IUITexture() { }
  46. virtual uint32 GetTextureID() = 0;
  47. virtual uint32 GetOriginalWidth() { return GetTextureWidth(); }
  48. virtual uint32 GetOriginalHeight() { return GetTextureHeight(); }
  49. virtual uint32 GetTextureWidth() = 0;
  50. virtual uint32 GetTextureHeight() = 0;
  51. virtual uint32 GetStride() = 0;
  52. virtual E2DTextureFormat GetFormat() = 0;
  53. virtual EAlphaChannelType GetAlphaChannelType() = 0;
  54. virtual bool BIsReady() = 0;
  55. };
  56. //
  57. // Class to handle double buffered textures of various standard formats (RGBA8, BGRA8, alpha-premulitplied/or-not, etc)
  58. //
  59. class IUIDoubleBufferedTexture : public IUITexture
  60. {
  61. public:
  62. virtual ~IUIDoubleBufferedTexture() {}
  63. // Update the data for rendering next frame
  64. virtual int32 UpdateTextureData( void *pTextureData ) = 0;
  65. };
  66. //
  67. // YUV420 textures are special, because they need 3 textures one for Y, U, and V, and then
  68. // they need special rendering rules in a pixel shader to scale/color convert.
  69. //
  70. class IUIDoubleBufferedYUV420Texture : public IUITexture
  71. {
  72. public:
  73. virtual ~IUIDoubleBufferedYUV420Texture() {}
  74. // Update the YUV420 data for rendering next frame
  75. virtual bool BUpdateTextureData( void *pYBuffer, void *pUBuffer, void *pVBuffer, uint unStrideY, uint unStrideU, uint unStrideV ) = 0;
  76. };
  77. //
  78. // Render thread callback object interface
  79. //
  80. #if defined( SOURCE2_PANORAMA )
  81. class CRenderThreadCallback : public CRefCount
  82. {
  83. public:
  84. // Callback function to override and perform direct rendering within
  85. virtual void RenderThreadCallback(ISceneView *pSceneView, IRenderContext **pRenderContext, ISceneLayer *pSceneLayer, float x0, float y0, float x1, float y1) = 0;
  86. };
  87. #endif
  88. //-----------------------------------------------------------------------------
  89. // Purpose: Interface to do drawing onto windows. This is the full publically exposed
  90. // drawing interface that new panel types can use for drawing, the implementation has
  91. // more stuff available inside the framework.
  92. //-----------------------------------------------------------------------------
  93. class IUIRenderEngine
  94. {
  95. public:
  96. // Draw a filled quad
  97. virtual void DrawFilledRect( float x0, float y0, float x1, float y1, const CMsgFillBrushCollection &c, EAntialiasing antialiasing = k_EAntialisingEnabled ) = 0;
  98. // Draw a textured quad
  99. virtual void DrawTexturedRect( uint32 unTextureID, ETextureSampleMode eSampleMode, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1 ) = 0;
  100. // Draw text (utf-8 input)
  101. virtual void DrawTextRegion( const char *pchText, const char *pchFontName, const CMsgFillBrushCollection &c, float flSize, float flLineHeight, EFontWeight weight, EFontStyle style, ETextAlign align, ETextDecoration decoration, bool bWrap, bool bEllipsis, int nLetterSpacing, float x0, float y0, float x1, float y1, ::google::protobuf::RepeatedPtrField< ::CMsgTextRangeFormat > *pmsgRangeFormats ) = 0;
  102. // Draw text (wchar input)
  103. virtual void DrawTextRegion( const wchar_t *pchText, const char *pchFontName, const CMsgFillBrushCollection &c, float flSize, float flLineHeight, EFontWeight weight, EFontStyle style, ETextAlign align, ETextDecoration decoration, bool bWrap, bool bEllipsis, int nLetterSpacing, float x0, float y0, float x1, float y1, ::google::protobuf::RepeatedPtrField< ::CMsgTextRangeFormat > *pmsgRangeFormats ) = 0;
  104. // Draw one of the special syncronized textures
  105. virtual void DrawSyncronizedTexturedRect( uint32 unTextureID, ETextureSampleMode eSampleMode, int32 unSerialize, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1 ) = 0;
  106. // Queue a texture delete, won't actually delete until the layout threads active frame next reaches rendering
  107. virtual void QueueDeleteTexture( IUITexture *pTexture ) = 0;
  108. // Called to create a texture, you call this directly on the main thread and the returned texture interface is thread safe,
  109. // so you can access its id/size and delete it from the main thread as well. Drawing calls are not synchronized with texture creation,
  110. // but the contract is you must create the texture before attempting to draw for it's id.
  111. virtual bool BCreateTexture( IUITexture **pTextureOutput, void *pubTextureData, uint32 unWidth, uint32 unHeight, uint32 unStride, E2DTextureFormat eFormat, EAlphaChannelType eAlphaChannelType ) = 0;
  112. #if defined( SOURCE2_PANORAMA )
  113. virtual bool BCreateTexture( IUITexture **pTextureOutput, const char *pResourceFile ) = 0;
  114. // Tell the render thread to call the panel back on the specified method, which will then be able to do
  115. // direct render system calls on the render thread
  116. virtual void RequestRenderCallback( CRenderThreadCallback *pCallbackObj, float x0, float y0, float x1, float y1,
  117. float flPaddingLeft, float flPaddingRight, float flPaddingTop, float flPaddingBottom, bool bNeedsRedrawEveryFrame ) = 0;
  118. #endif
  119. // Called to create a double buffered texture, you call this directly on the main thread
  120. // and the returned texture interface is thread safe, so you can update the texture data directly. The textures are
  121. // double buffered, so it should be hard to block the render thread, but some locking does occur. Unlike normal texture
  122. // drawing your draw calls are not synchronized with texture data updates, so you could end up skipping frames or such.
  123. virtual bool BCreateDoubleBufferedTexture( IUIDoubleBufferedTexture **pDoubleBufferedOutput, uint32 unWidth, uint32 unHeight, uint32 unStride, E2DTextureFormat eFormat, EAlphaChannelType eAlphaChannelType, bool bSerializedUploads ) = 0;
  124. // Called to create a double buffered YUV420 texture (for movie rendering), you call this directly on the main thread
  125. // and the returned texture interface is thread safe, so you can update the texture data directly. The textures are
  126. // double buffered, so it should be hard to block the render thread, but some locking does occur. Unlike normal texture
  127. // drawing your draw calls are not synchronized with texture data updates, so you could end up skipping frames or such.
  128. virtual bool BCreateDoubleBufferedYUV420Texture( IUIDoubleBufferedYUV420Texture **pDoubleBufferedYUV420Output, uint32 unWidth, uint32 unHeight ) = 0;
  129. };
  130. }
  131. #endif // IUIRENDERENGINE_H