surfaceclass.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /VSS_Sync/ww3d2/surfaceclass.h $*
  25. * *
  26. * Original Author:: Nathaniel Hoffman *
  27. * *
  28. * $Author:: Vss_sync $*
  29. * *
  30. * $Modtime:: 8/29/01 9:32p $*
  31. * *
  32. * $Revision:: 17 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef SURFACECLASS_H
  41. #define SURFACECLASS_H
  42. #include "ww3dformat.h"
  43. #include "refcount.h"
  44. struct IDirect3DSurface8;
  45. class Vector2i;
  46. class Vector3;
  47. /*************************************************************************
  48. ** SurfaceClass
  49. **
  50. ** This is our surface class, which wraps IDirect3DSurface8.
  51. **
  52. ** Hector Yee 2/12/01 - added in fills, blits etc for font3d class
  53. **
  54. *************************************************************************/
  55. class SurfaceClass : public W3DMPO, public RefCountClass
  56. {
  57. W3DMPO_GLUE(SurfaceClass)
  58. public:
  59. struct SurfaceDescription {
  60. WW3DFormat Format; // Surface format
  61. unsigned int Width; // Surface width in pixels
  62. unsigned int Height; // Surface height in pixels
  63. };
  64. // Create surface with desired height, width and format.
  65. SurfaceClass(unsigned width, unsigned height, WW3DFormat format);
  66. // Create surface from a file.
  67. SurfaceClass(const char *filename);
  68. // Create the surface from a D3D pointer
  69. SurfaceClass(IDirect3DSurface8 *d3d_surface);
  70. ~SurfaceClass(void);
  71. // Get surface description
  72. void Get_Description(SurfaceDescription &surface_desc);
  73. // Lock / unlock the surface
  74. void * Lock(int * pitch);
  75. void Unlock(void);
  76. // HY -- The following functions are support functions for font3d
  77. // zaps the surface memory to zero
  78. void Clear();
  79. // copies the contents of one surface to another
  80. void Copy(
  81. unsigned int dstx, unsigned int dsty,
  82. unsigned int srcx, unsigned int srcy,
  83. unsigned int width, unsigned int height,
  84. const SurfaceClass *other);
  85. // support for copying from a byte array
  86. void Copy(const unsigned char *other);
  87. // support for copying from a byte array
  88. void Copy(Vector2i &min,Vector2i &max, const unsigned char *other);
  89. // copies the contents of one surface to another, stretches
  90. void Stretch_Copy(
  91. unsigned int dstx, unsigned int dsty,unsigned int dstwidth, unsigned int dstheight,
  92. unsigned int srcx, unsigned int srcy, unsigned int srcwidth, unsigned int srcheight,
  93. const SurfaceClass *source);
  94. // finds the bounding box of non-zero pixels, used in font3d
  95. void FindBB(Vector2i *min,Vector2i*max);
  96. // tests a column to see if the alpha is nonzero, used in font3d
  97. bool Is_Transparent_Column(unsigned int column);
  98. // makes a copy of the surface into a byte array
  99. unsigned char *CreateCopy(int *width,int *height,int*size,bool flip=false);
  100. // For use by TextureClass:
  101. IDirect3DSurface8 *Peek_D3D_Surface(void) { return D3DSurface; }
  102. // Attaching and detaching a surface pointer
  103. void Attach (IDirect3DSurface8 *surface);
  104. void Detach (void);
  105. // draws a horizontal line
  106. void DrawHLine(const unsigned int y,const unsigned int x1, const unsigned int x2, unsigned int color);
  107. void DrawPixel(const unsigned int x,const unsigned int y, unsigned int color);
  108. // get pixel function .. to be used infrequently
  109. void Get_Pixel(Vector3 &rgb, int x,int y);
  110. void Hue_Shift(const Vector3 &hsv_shift);
  111. bool Is_Monochrome(void);
  112. WW3DFormat Get_Surface_Format() const { return SurfaceFormat; }
  113. private:
  114. // Direct3D surface object
  115. IDirect3DSurface8 *D3DSurface;
  116. WW3DFormat SurfaceFormat;
  117. friend class TextureClass;
  118. };
  119. #endif