pointgr.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. ** Command & Conquer Renegade(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 : G *
  23. * *
  24. * $Archive:: /VSS_Sync/ww3d2/pointgr.h $*
  25. * *
  26. * $Author:: Vss_sync $*
  27. * *
  28. * $Modtime:: 9/12/01 10:01p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef POINTGR_H
  39. #define POINTGR_H
  40. #include "sharebuf.h"
  41. #include "shader.h"
  42. #include "vector4.h"
  43. #include "vector3.h"
  44. #include "vector2.h"
  45. class VertexMaterialClass;
  46. class RenderInfoClass;
  47. class TextureClass;
  48. /*
  49. ** PointGroupClass -- a custom object for rendering
  50. ** groups of points (such as particle systems).
  51. ** It is possible to change mode/number of points/shader/etc. but these
  52. ** changes tend to be expensive if done often. Expected usage is to set the
  53. ** point location/color/active arrays each frame the object is visible (with
  54. ** the same number of points) and perform other changes relatively rarely.
  55. ** NOTE: Currently it is implemented using general triangles (1 or 2 per
  56. ** point), so it is probably suboptimal for software rasterization devices
  57. ** (which would probably perform better with some kind of blit/sprite code).
  58. */
  59. class PointGroupClass
  60. {
  61. public:
  62. enum PointModeEnum {
  63. TRIS, // each point is a triangle
  64. QUADS, // each point is a quad formed out of two triangles
  65. SCREENSPACE // each point is a tri placed to affect certain pixels (should be used with 2D camera)
  66. };
  67. enum FlagsType {
  68. TRANSFORM, // transform points w. modelview matrix (worldspace points)
  69. };
  70. PointGroupClass(void);
  71. virtual ~PointGroupClass(void);
  72. PointGroupClass & operator = (const PointGroupClass & that);
  73. // PointGroupClass interface:
  74. void Set_Arrays(ShareBufferClass<Vector3> *locs,
  75. ShareBufferClass<Vector4> *diffuse = NULL,
  76. ShareBufferClass<unsigned int> *apt = NULL,
  77. ShareBufferClass<float> *sizes = NULL,
  78. ShareBufferClass<unsigned char> *orientations = NULL,
  79. ShareBufferClass<unsigned char> *frames = NULL,
  80. int active_point_count = -1,
  81. float vpxmin = 0.0f, float vpymin = 0.0f,
  82. float vpxmax = 0.0f, float vpymax = 0.0f);
  83. void Set_Point_Size(float size);
  84. float Get_Point_Size(void);
  85. void Set_Point_Color(Vector3 color);
  86. Vector3 Get_Point_Color(void);
  87. void Set_Point_Alpha(float alpha);
  88. float Get_Point_Alpha(void);
  89. void Set_Point_Orientation(unsigned char orientation);
  90. unsigned char Get_Point_Orientation(void);
  91. void Set_Point_Frame(unsigned char frame);
  92. unsigned char Get_Point_Frame(void);
  93. void Set_Point_Mode(PointModeEnum mode);
  94. PointModeEnum Get_Point_Mode(void);
  95. void Set_Flag(FlagsType flag, bool onoff);
  96. int Get_Flag(FlagsType flag);
  97. void Set_Texture(TextureClass* texture);
  98. TextureClass * Get_Texture(void);
  99. TextureClass * Peek_Texture(void);
  100. void Set_Shader(ShaderClass shader);
  101. ShaderClass Get_Shader(void);
  102. // The frame property is taken from a set of possible frames. The rows/columns in the frame
  103. // texture determine the number of possible frames. Since it must be a power of 2, we represent
  104. // it as its log base 2. This number cannot be greater than 4 (which corresponds to a 16x16
  105. // square of frames, i.e. 256 frames).
  106. unsigned char Get_Frame_Row_Column_Count_Log2(void);
  107. void Set_Frame_Row_Column_Count_Log2(unsigned char frccl2);
  108. int Get_Polygon_Count(void);
  109. void Render(RenderInfoClass &rinfo);
  110. protected:
  111. // Update arrays.
  112. void Update_Arrays(Vector3 *point_loc,
  113. Vector4 *point_diffuse,
  114. float *point_size,
  115. unsigned char *point_orientation,
  116. unsigned char *point_frame,
  117. int active_points,
  118. int total_points,
  119. int &vnum,
  120. int &pnum);
  121. // These shared buffers are used for communication to the point group - to
  122. // pass point locations, colors and enables. The location and color arrays
  123. // are 'compressed' using the active point table (if present) and then
  124. // are processed into other arrays which are passed to the GERD.
  125. // SR rather than WWMath types are used so Vector Processors can be used.
  126. // The arrays override the default value if present.
  127. // The orientation and frame properties are "index properties": they select one out of a small
  128. // group of possibilities for each point.
  129. // Orientation: this is the 2D rotation of the point about its center. There are 256 discrete
  130. // orientations. The unit circle is evenly subdivided 256 times to create the set of
  131. // orientations. The reason we discretize orientation is for performance: this way we can
  132. // precalculate vertex offsets.
  133. // Frame: the texture is divided into a 2D square grid, and each point uses one grid square
  134. // instead of the whole texture. The number of possible frames is not invariant - it depends
  135. // on the number of rows / columns in the grid. The reason we do this instead of having
  136. // different textures is to avoid texture state changes. Also for performance reasons, the
  137. // number of possible frames must be a power of two - for this reason the number of frame rows
  138. // and columns, orientations, etc. are represented as the log base 2 of the actual number.
  139. ShareBufferClass<Vector3> * PointLoc; // World/cameraspace point locs
  140. ShareBufferClass<Vector4> * PointDiffuse; // (NULL if not used) RGBA values
  141. ShareBufferClass<unsigned int> * APT; // (NULL if not used) active point table
  142. ShareBufferClass<float> * PointSize; // (NULL if not used) size override table
  143. ShareBufferClass<unsigned char> * PointOrientation; // (NULL if not used) orientation indices
  144. ShareBufferClass<unsigned char> * PointFrame; // (NULL if not used) frame indices
  145. int PointCount; // Active (if APT) or total point count
  146. // See comments for Get/Set_Frame_Row_Column_Count_Log2 above
  147. unsigned char FrameRowColumnCountLog2; // MUST be equal or lesser than 4
  148. // These parameters are passed to the GERD:
  149. TextureClass* Texture;
  150. ShaderClass Shader; // (default created in CTor)
  151. // Internal state:
  152. PointModeEnum PointMode; // are points tris or quads?
  153. unsigned int Flags; // operation control flags
  154. float DefaultPointSize; // point size (size array overrides if present)
  155. Vector3 DefaultPointColor; // point color (color array overrides if present)
  156. float DefaultPointAlpha; // point alpha (alpha array overrides if present)
  157. unsigned char DefaultPointOrientation;// point orientation (orientation array overrides if present)
  158. unsigned char DefaultPointFrame; // point texture frame (frame array overrides if present)
  159. // View plane rectangle (only used in SCREENSPACE mode - set by Set_Arrays
  160. // and used in Update_GERD_Arrays).
  161. float VPXMin;
  162. float VPYMin;
  163. float VPXMax;
  164. float VPYMax;
  165. // Static stuff:
  166. // For performance / memory reasons we prepare vertex location and UV
  167. // arrays for various orientations and texture frames, as static data
  168. // members of this class. This avoids the need to create such arrays over
  169. // again for each object. The values in the UV arrays are used as-is, the
  170. // values in the location arrays normally need to be scaled to the point
  171. // sizes and added to the point location before use. We have distinct sets
  172. // of arrays for each point mode.
  173. // There are tables of vertex positions for each of triangle and quad mode
  174. // with 256 discrete orientations. Each entry contains 3 (for triangle
  175. // mode) or 4 (for quad mode) Vector3s.
  176. // There are five tables of texture UVs for each of triangle and quad mode:
  177. // with 1x1(1), 2x2(4), 4x4(16), 8x8(64) and 16x16(256) frames. Each entry
  178. // contains 3 (for triangle mode) or 4 (for quad mode) Vector2s.
  179. // In addition, there is one array of vertex positions for screenspace mode
  180. // with 2 entries (for size 1 and size 2). Each entry contains 3 Vector3s.
  181. // the Init function (which is called by WW3D::Init()) creates these
  182. // arrays, and the Shutdown function (which is called by WW3D::Shutdown()
  183. // releases them.
  184. public:
  185. static void _Init(void);
  186. static void _Shutdown(void);
  187. private:
  188. static Vector3 _TriVertexLocationOrientationTable[256][3];
  189. static Vector3 _QuadVertexLocationOrientationTable[256][4];
  190. static Vector3 _ScreenspaceVertexLocationSizeTable[2][3];
  191. static Vector2 *_TriVertexUVFrameTable[5];
  192. static Vector2 *_QuadVertexUVFrameTable[5];
  193. static VertexMaterialClass *PointMaterial;
  194. };
  195. #endif