DrawPort.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #ifndef SE_INCL_DRAWPORT_H
  13. #define SE_INCL_DRAWPORT_H
  14. #ifdef PRAGMA_ONCE
  15. #pragma once
  16. #endif
  17. #include <Engine/Base/Lists.h>
  18. class ENGINE_API CDrawPort {
  19. // implementation:
  20. public:
  21. CListNode dp_NodeInRaster; // for linking in list of clones
  22. public:
  23. class CRaster *dp_Raster; // pointer to the Raster this refers to
  24. class CFontData *dp_FontData; // pointer to the current text font
  25. PIX dp_Width, dp_Height; // width, height in pixels
  26. PIX dp_MinI, dp_MinJ; // I,J coord of the upper left edge in the Raster
  27. PIX dp_MaxI, dp_MaxJ; // I,J coord of the lower right edge in the Raster
  28. PIX dp_ScissorMinI, dp_ScissorMinJ; // I,J coord of the upper left edge in the Raster
  29. PIX dp_ScissorMaxI, dp_ScissorMaxJ; // I,J coord of the lower right edge in the Raster
  30. PIX dp_pixTextCharSpacing; // space between chars in text
  31. PIX dp_pixTextLineSpacing; // space between lines in text
  32. FLOAT dp_fTextScaling; // scaling factor for font size
  33. FLOAT dp_fTextAspect; // aspect ratio for font (x/y)
  34. INDEX dp_iTextMode; // text output mode (-1 = print special codes, 0 = ignore special codes, 1 = parse special codes)
  35. FLOAT dp_fWideAdjustment; // for wide (16:9 or 16:10) screen support (needed in some calculations) = 1.0f or >1 (10/12 perhaps)
  36. BOOL dp_bRenderingOverlay; // set when scene renderer requires overlay mode (don't clear z-buffer)
  37. // dimensions and position relative to the raster size
  38. double dp_SizeIOverRasterSizeI, dp_SizeJOverRasterSizeJ;
  39. double dp_MinIOverRasterSizeI, dp_MinJOverRasterSizeJ;
  40. // adjust this during frame to be used for screen blending
  41. ULONG dp_ulBlendingRA, dp_ulBlendingGA, dp_ulBlendingBA; // r*a, g*a, b*a
  42. ULONG dp_ulBlendingA;
  43. // set cloned drawport dimensions
  44. void InitCloned(CDrawPort *pdpBase, double rMinI,double rMinJ, double rSizeI,double rSizeJ);
  45. // Recalculate pixel dimensions from relative dimensions and raster size
  46. void RecalculateDimensions(void);
  47. // set orthogonal projection
  48. void SetOrtho(void) const;
  49. // set given projection
  50. void SetProjection(CAnyProjection3D &apr) const;
  51. //interface:
  52. // Create a drawport for full raster
  53. CDrawPort( CRaster *praBase=NULL);
  54. // Clone a drawport
  55. CDrawPort( CDrawPort *pdpBase, double rMinI,double rMinJ, double rSizeI,double rSizeJ);
  56. CDrawPort( CDrawPort *pdpBase, const PIXaabbox2D &box);
  57. // dualhead cloning
  58. CDrawPort( CDrawPort *pdpBase, BOOL bLeft);
  59. // wide-screen cloning
  60. void MakeWideScreen(CDrawPort *pdp);
  61. // check if a drawport is dualhead
  62. BOOL IsDualHead(void);
  63. // check if a drawport is wide screen
  64. BOOL IsWideScreen(void);
  65. // set/get rendering in overlay mode
  66. inline void SetOverlappedRendering(BOOL bOverlay) { dp_bRenderingOverlay = bOverlay; };
  67. inline BOOL IsOverlappedRendering(void) const { return dp_bRenderingOverlay; };
  68. // returns unique drawport number
  69. ULONG GetID(void);
  70. // Get dimensions and location of drawport
  71. inline PIX GetWidth( void) const { return dp_Width; };
  72. inline PIX GetHeight(void) const { return dp_Height; };
  73. // text manipulation
  74. void SetFont( CFontData *pfd); // WARNING: this resets text variables
  75. inline void SetTextCharSpacing( PIX pixSpacing) { dp_pixTextCharSpacing = pixSpacing; };
  76. inline void SetTextLineSpacing( PIX pixSpacing) { dp_pixTextLineSpacing = pixSpacing; };
  77. inline void SetTextScaling( FLOAT fScalingFactor) { dp_fTextScaling = fScalingFactor; };
  78. inline void SetTextAspect( FLOAT fAspectRatio) { dp_fTextAspect = fAspectRatio; };
  79. inline void SetTextMode( INDEX iMode) { dp_iTextMode = iMode; };
  80. // returns width of entire text string (with scale included)
  81. ULONG GetTextWidth( const CTString &strText) const;
  82. // writes text string on drawport (left-aligned)
  83. void PutText( const CTString &strText, PIX pixX0, PIX pixY0, const COLOR colBlend=0xFFFFFFFF) const;
  84. // writes text string on drawport (centered arround X)
  85. void PutTextC( const CTString &strText, PIX pixX0, PIX pixY0, const COLOR colBlend=0xFFFFFFFF) const;
  86. // writes text string on drawport (centered arround X and Y)
  87. void PutTextCXY( const CTString &strText, PIX pixX0, PIX pixY0, const COLOR colBlend=0xFFFFFFFF) const;
  88. // writes text string on drawport (right-aligned)
  89. void PutTextR( const CTString &strText, PIX pixX0, PIX pixY0, const COLOR colBlend=0xFFFFFFFF) const;
  90. // plain texture display
  91. void PutTexture( class CTextureObject *pTO, const PIXaabbox2D &boxScreen,
  92. const COLOR colBlend=0xFFFFFFFF) const;
  93. void PutTexture( class CTextureObject *pTO, const PIXaabbox2D &boxScreen,
  94. const COLOR colUL, const COLOR colUR, const COLOR colDL, const COLOR colDR) const;
  95. void PutTexture( class CTextureObject *pTO, const PIXaabbox2D &boxScreen,
  96. const MEXaabbox2D &boxTexture, const COLOR colBlend=0xFFFFFFFF) const;
  97. void PutTexture( class CTextureObject *pTO, const PIXaabbox2D &boxScreen, const MEXaabbox2D &boxTexture,
  98. const COLOR colUL, const COLOR colUR, const COLOR colDL, const COLOR colDR) const;
  99. // advanced texture display
  100. void InitTexture( class CTextureObject *pTO, const BOOL bClamp=FALSE) const; // prepares texture and rendering arrays
  101. // adds one full texture to rendering queue
  102. void AddTexture( const FLOAT fI0, const FLOAT fJ0, const FLOAT fI1, const FLOAT fJ1, const COLOR col) const;
  103. // adds one part of texture to rendering queue
  104. void AddTexture( const FLOAT fI0, const FLOAT fJ0, const FLOAT fI1, const FLOAT fJ1,
  105. const FLOAT fU0, const FLOAT fV0, const FLOAT fU1, const FLOAT fV1, const COLOR col) const;
  106. // adds one textured quad to rendering queue (up-left start, counter-clockwise)
  107. void AddTexture( const FLOAT fI0, const FLOAT fJ0, const FLOAT fU0, const FLOAT fV0, const COLOR col0,
  108. const FLOAT fI1, const FLOAT fJ1, const FLOAT fU1, const FLOAT fV1, const COLOR col1,
  109. const FLOAT fI2, const FLOAT fJ2, const FLOAT fU2, const FLOAT fV2, const COLOR col2,
  110. const FLOAT fI3, const FLOAT fJ3, const FLOAT fU3, const FLOAT fV3, const COLOR col3) const;
  111. // adds one flat triangle rendering queue (up-left start, counter-clockwise)
  112. void AddTriangle( const FLOAT fI0, const FLOAT fJ0, const FLOAT fI1, const FLOAT fJ1,
  113. const FLOAT fI2, const FLOAT fJ2, const COLOR col) const;
  114. // renders all textures from rendering queue and flushed rendering arrays
  115. void FlushRenderingQueue(void) const;
  116. // lock and unlock raster thru drawport functions
  117. BOOL Lock(void);
  118. void Unlock(void);
  119. // draw point (can be several pixels - depends on radius)
  120. void DrawPoint( PIX pixI, PIX pixJ, COLOR col, PIX pixRadius=1) const;
  121. void DrawPoint3D( FLOAT3D v, COLOR col, FLOAT fRadius=1.0f) const; // in 3D
  122. // draw line
  123. void DrawLine( PIX pixI0, PIX pixJ0, PIX pixI1, PIX pixJ1, COLOR col, ULONG typ=_FULL_) const;
  124. void DrawLine3D( FLOAT3D v0, FLOAT3D v1, COLOR col) const; // in 3D
  125. // draw border
  126. void DrawBorder( PIX pixI, PIX pixJ, PIX pixWidth, PIX pixHeight, COLOR col, ULONG typ=_FULL_) const;
  127. // fill with blending part of a drawport with a given color
  128. void Fill( PIX pixI, PIX pixJ, PIX pixWidth, PIX pixHeight, COLOR col) const;
  129. // fill with blending part of a drawport with a four corner colors
  130. void Fill( PIX pixI, PIX pixJ, PIX pixWidth, PIX pixHeight,
  131. COLOR colUL, COLOR colUR, COLOR colDL, COLOR colDR) const;
  132. // fill a part of Z-Buffer with a given value
  133. void FillZBuffer( PIX pixI, PIX pixJ, PIX pixWidth, PIX pixHeight, FLOAT zval) const;
  134. // fill without blending an entire drawport with a given color
  135. void Fill( COLOR col) const;
  136. // fill an entire Z-Buffer with a given value
  137. void FillZBuffer( FLOAT zval) const;
  138. // grab screen (iGrabZBuffer: 0=no, 1=if allowed, 2=yes)
  139. void GrabScreen( class CImageInfo &iiGrabbedImage, INDEX iGrabZBuffer=0) const;
  140. // functions for getting depth of points on drawport
  141. BOOL IsPointVisible( PIX pixI, PIX pixJ, FLOAT fOoK, INDEX iID, INDEX iMirrorLevel=0) const;
  142. // render one lens flare
  143. void RenderLensFlare( CTextureObject *pto, FLOAT fI, FLOAT fJ,
  144. FLOAT fSizeI, FLOAT fSizeJ, ANGLE aRotation, COLOR colLight) const;
  145. // blend entire drawport with accumulated colors
  146. void BlendScreen(void);
  147. };
  148. enum ParticleBlendType {
  149. PBT_BLEND,
  150. PBT_ADD,
  151. PBT_MULTIPLY,
  152. PBT_ADDALPHA,
  153. PBT_FLEX, // premultiplied alpha (ONE + [1-SRC_ALPHA])
  154. PBT_TRANSPARENT,
  155. };
  156. void ENGINE_API Particle_PrepareSystem( CDrawPort *pdpDrawPort, CAnyProjection3D &prProjection);
  157. void ENGINE_API Particle_PrepareEntity( FLOAT fMipFactor, BOOL bHasFog, BOOL bHasHaze, CEntity *penViewer);
  158. void ENGINE_API Particle_EndSystem( BOOL bRestoreOrtho=TRUE);
  159. FLOAT ENGINE_API Particle_GetMipFactor(void);
  160. INDEX ENGINE_API Particle_GetDrawPortID(void);
  161. ENGINE_API CEntity *Particle_GetViewer(void);
  162. ENGINE_API CProjection3D *Particle_GetProjection(void);
  163. void ENGINE_API Particle_PrepareTexture( CTextureObject *pto, enum ParticleBlendType pbt);
  164. void ENGINE_API Particle_SetTexturePart( MEX mexWidth, MEX mexHeight, INDEX iCol, INDEX iRow);
  165. void ENGINE_API Particle_RenderSquare( const FLOAT3D &vPos, FLOAT fSize, ANGLE aRotation, COLOR col, FLOAT fYRatio=1.0f);
  166. void ENGINE_API Particle_RenderQuad3D( const FLOAT3D &vPos0, const FLOAT3D &vPos1, const FLOAT3D &vPos2,
  167. const FLOAT3D &vPos3, COLOR col);
  168. void ENGINE_API Particle_RenderLine( const FLOAT3D &vPos0, const FLOAT3D &vPos1, FLOAT fWidth, COLOR col);
  169. void ENGINE_API Particle_Sort( BOOL b3D=FALSE);
  170. void ENGINE_API Particle_Flush(void);
  171. #endif /* include-once check. */