Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
pointgr.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(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/***************************************************************************
20 *** 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 ***
21 ***************************************************************************
22 * *
23 * Project Name : G *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/pointgr.h $*
26 * *
27 * $Author:: Naty_h $*
28 * *
29 * $Modtime:: 8/02/01 8:34p $*
30 * *
31 * $Revision:: 10 $*
32 * *
33 *-------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#if defined(_MSC_VER)
38#pragma once
39#endif
40
41#ifndef POINTGR_H
42#define POINTGR_H
43
44#include "sharebuf.h"
45#include "shader.h"
46#include "vector4.h"
47#include "vector3.h"
48#include "vector2.h"
49#include "vector.h"
50
52class RenderInfoClass;
53class TextureClass;
54
55/*
56** PointGroupClass -- a custom object for rendering
57** groups of points (such as particle systems).
58** It is possible to change mode/number of points/shader/etc. but these
59** changes tend to be expensive if done often. Expected usage is to set the
60** point location/color/active arrays each frame the object is visible (with
61** the same number of points) and perform other changes relatively rarely.
62** NOTE: Currently it is implemented using general triangles (1 or 2 per
63** point), so it is probably suboptimal for software rasterization devices
64** (which would probably perform better with some kind of blit/sprite code).
65*/
67{
68public:
69
71 TRIS, // each point is a triangle
72 QUADS, // each point is a quad formed out of two triangles
73 SCREENSPACE // each point is a tri placed to affect certain pixels (should be used with 2D camera)
74 };
75
76 enum FlagsType {
77 TRANSFORM, // transform points w. modelview matrix (worldspace points)
78 };
79
80 PointGroupClass(void);
81 virtual ~PointGroupClass(void);
83
84 // PointGroupClass interface:
91 int active_point_count = -1,
92 float vpxmin = 0.0f, float vpymin = 0.0f,
93 float vpxmax = 0.0f, float vpymax = 0.0f);
94 void Set_Point_Size(float size);
95 float Get_Point_Size(void);
96 void Set_Point_Color(Vector3 color);
98 void Set_Point_Alpha(float alpha);
99 float Get_Point_Alpha(void);
100 void Set_Point_Orientation(unsigned char orientation);
101 unsigned char Get_Point_Orientation(void);
102 void Set_Point_Frame(unsigned char frame);
103 unsigned char Get_Point_Frame(void);
104 void Set_Point_Mode(PointModeEnum mode);
106 void Set_Flag(FlagsType flag, bool onoff);
108 void Set_Texture(TextureClass* texture);
111 void Set_Shader(ShaderClass shader);
113 void Set_Billboard(bool shouldBillboard);
114 bool Get_Billboard(void);
115
116 // The frame property is taken from a set of possible frames. The rows/columns in the frame
117 // texture determine the number of possible frames. Since it must be a power of 2, we represent
118 // it as its log base 2. This number cannot be greater than 4 (which corresponds to a 16x16
119 // square of frames, i.e. 256 frames).
120 unsigned char Get_Frame_Row_Column_Count_Log2(void);
121 void Set_Frame_Row_Column_Count_Log2(unsigned char frccl2);
122
123 int Get_Polygon_Count(void);
124
125 void Render(RenderInfoClass &rinfo);
126 void RenderVolumeParticle(RenderInfoClass &rinfo, unsigned int depth);
127
128protected:
129 // Update arrays.
130 void Update_Arrays(Vector3 *point_loc,
131 Vector4 *point_diffuse,
132 float *point_size,
133 unsigned char *point_orientation,
134 unsigned char *point_frame,
135 int active_points,
136 int total_points,
137 int &vnum,
138 int &pnum);
139
140 // These shared buffers are used for communication to the point group - to
141 // pass point locations, colors and enables. The location and color arrays
142 // are 'compressed' using the active point table (if present) and then
143 // are processed into other arrays which are passed to the GERD.
144 // SR rather than WWMath types are used so Vector Processors can be used.
145 // The arrays override the default value if present.
146 // The orientation and frame properties are "index properties": they select one out of a small
147 // group of possibilities for each point.
148 // Orientation: this is the 2D rotation of the point about its center. There are 256 discrete
149 // orientations. The unit circle is evenly subdivided 256 times to create the set of
150 // orientations. The reason we discretize orientation is for performance: this way we can
151 // precalculate vertex offsets.
152 // Frame: the texture is divided into a 2D square grid, and each point uses one grid square
153 // instead of the whole texture. The number of possible frames is not invariant - it depends
154 // on the number of rows / columns in the grid. The reason we do this instead of having
155 // different textures is to avoid texture state changes. Also for performance reasons, the
156 // number of possible frames must be a power of two - for this reason the number of frame rows
157 // and columns, orientations, etc. are represented as the log base 2 of the actual number.
158 ShareBufferClass<Vector3> * PointLoc; // World/cameraspace point locs
159 ShareBufferClass<Vector4> * PointDiffuse; // (NULL if not used) RGBA values
160 ShareBufferClass<unsigned int> * APT; // (NULL if not used) active point table
161 ShareBufferClass<float> * PointSize; // (NULL if not used) size override table
162 ShareBufferClass<unsigned char> * PointOrientation; // (NULL if not used) orientation indices
163 ShareBufferClass<unsigned char> * PointFrame; // (NULL if not used) frame indices
164 int PointCount; // Active (if APT) or total point count
165
166 // See comments for Get/Set_Frame_Row_Column_Count_Log2 above
167 unsigned char FrameRowColumnCountLog2; // MUST be equal or lesser than 4
168
169 // These parameters are passed to the GERD:
171 ShaderClass Shader; // (default created in CTor)
172
173 // Internal state:
174 PointModeEnum PointMode; // are points tris or quads?
175 unsigned int Flags; // operation control flags
176 float DefaultPointSize; // point size (size array overrides if present)
177 Vector3 DefaultPointColor; // point color (color array overrides if present)
178 float DefaultPointAlpha; // point alpha (alpha array overrides if present)
179 unsigned char DefaultPointOrientation;// point orientation (orientation array overrides if present)
180 unsigned char DefaultPointFrame; // point texture frame (frame array overrides if present)
181
182 // View plane rectangle (only used in SCREENSPACE mode - set by Set_Arrays
183 // and used in Update_GERD_Arrays).
184 float VPXMin;
185 float VPYMin;
186 float VPXMax;
187 float VPYMax;
188
190
191 // Static stuff:
192 // For performance / memory reasons we prepare vertex location and UV
193 // arrays for various orientations and texture frames, as static data
194 // members of this class. This avoids the need to create such arrays over
195 // again for each object. The values in the UV arrays are used as-is, the
196 // values in the location arrays normally need to be scaled to the point
197 // sizes and added to the point location before use. We have distinct sets
198 // of arrays for each point mode.
199 // There are tables of vertex positions for each of triangle and quad mode
200 // with 256 discrete orientations. Each entry contains 3 (for triangle
201 // mode) or 4 (for quad mode) Vector3s.
202 // There are five tables of texture UVs for each of triangle and quad mode:
203 // with 1x1(1), 2x2(4), 4x4(16), 8x8(64) and 16x16(256) frames. Each entry
204 // contains 3 (for triangle mode) or 4 (for quad mode) Vector2s.
205 // In addition, there is one array of vertex positions for screenspace mode
206 // with 2 entries (for size 1 and size 2). Each entry contains 3 Vector3s.
207 // the Init function (which is called by WW3D::Init()) creates these
208 // arrays, and the Shutdown function (which is called by WW3D::Shutdown()
209 // releases them.
210public:
211 static void _Init(void);
212 static void _Shutdown(void);
213
214private:
215 static Vector3 _TriVertexLocationOrientationTable[256][3];
216 static Vector3 _QuadVertexLocationOrientationTable[256][4];
217 static Vector3 _ScreenspaceVertexLocationSizeTable[2][3];
218 static Vector2 *_TriVertexUVFrameTable[5];
219 static Vector2 *_QuadVertexUVFrameTable[5];
220 static VertexMaterialClass *PointMaterial;
221
222 // Static arrays for intermediate calcs (never resized down, just up):
223 static VectorClass<Vector3> compressed_loc; // point locations 'compressed' by APT
224 static VectorClass<Vector4> compressed_diffuse; // point colors 'compressed' by APT
225 static VectorClass<float> compressed_size; // point sizes 'compressed' by APT
226 static VectorClass<unsigned char> compressed_orient; // point orientations 'compressed' by APT
227 static VectorClass<unsigned char> compressed_frame; // point frames 'compressed' by APT
228 static VectorClass<Vector3> transformed_loc; // transformed point locations
229};
230
231
233{
234public:
236 virtual ~SegmentGroupClass(void);
237
238};
239
240
241
242#endif
#define NULL
Definition BaseType.h:92
void Set_Point_Orientation(unsigned char orientation)
Definition pointgr.cpp:427
virtual ~PointGroupClass(void)
Definition pointgr.cpp:188
void Set_Point_Alpha(float alpha)
Definition pointgr.cpp:389
void Set_Frame_Row_Column_Count_Log2(unsigned char frccl2)
Definition pointgr.cpp:728
unsigned char Get_Point_Orientation(void)
Definition pointgr.cpp:445
unsigned char DefaultPointOrientation
Definition pointgr.h:179
unsigned char DefaultPointFrame
Definition pointgr.h:180
unsigned char FrameRowColumnCountLog2
Definition pointgr.h:167
ShareBufferClass< Vector4 > * PointDiffuse
Definition pointgr.h:159
void Set_Texture(TextureClass *texture)
Definition pointgr.cpp:574
void Set_Shader(ShaderClass shader)
Definition pointgr.cpp:638
static void _Shutdown(void)
Definition pointgr.cpp:1602
TextureClass * Texture
Definition pointgr.h:170
void Render(RenderInfoClass &rinfo)
Definition pointgr.cpp:775
PointModeEnum PointMode
Definition pointgr.h:174
ShareBufferClass< unsigned int > * APT
Definition pointgr.h:160
ShaderClass Get_Shader(void)
Definition pointgr.cpp:657
Vector3 DefaultPointColor
Definition pointgr.h:177
PointGroupClass & operator=(const PointGroupClass &that)
Definition pointgr.cpp:232
void Set_Arrays(ShareBufferClass< Vector3 > *locs, ShareBufferClass< Vector4 > *diffuse=NULL, ShareBufferClass< unsigned int > *apt=NULL, ShareBufferClass< float > *sizes=NULL, ShareBufferClass< unsigned char > *orientations=NULL, ShareBufferClass< unsigned char > *frames=NULL, int active_point_count=-1, float vpxmin=0.0f, float vpymin=0.0f, float vpxmax=0.0f, float vpymax=0.0f)
Definition pointgr.cpp:264
unsigned char Get_Frame_Row_Column_Count_Log2(void)
Definition pointgr.cpp:709
void Set_Point_Color(Vector3 color)
Definition pointgr.cpp:355
void Set_Flag(FlagsType flag, bool onoff)
Definition pointgr.cpp:537
ShareBufferClass< Vector3 > * PointLoc
Definition pointgr.h:158
ShareBufferClass< float > * PointSize
Definition pointgr.h:161
void RenderVolumeParticle(RenderInfoClass &rinfo, unsigned int depth)
Definition pointgr.cpp:1643
float Get_Point_Alpha(void)
Definition pointgr.cpp:407
unsigned char Get_Point_Frame(void)
Definition pointgr.cpp:483
void Set_Point_Size(float size)
Definition pointgr.cpp:319
ShareBufferClass< unsigned char > * PointFrame
Definition pointgr.h:163
PointGroupClass(void)
Definition pointgr.cpp:151
float Get_Point_Size(void)
Definition pointgr.cpp:337
float DefaultPointSize
Definition pointgr.h:176
unsigned int Flags
Definition pointgr.h:175
void Set_Billboard(bool shouldBillboard)
Definition pointgr.cpp:674
TextureClass * Peek_Texture(void)
Definition pointgr.cpp:614
void Set_Point_Frame(unsigned char frame)
Definition pointgr.cpp:465
ShareBufferClass< unsigned char > * PointOrientation
Definition pointgr.h:162
int Get_Flag(FlagsType flag)
Definition pointgr.cpp:556
void Set_Point_Mode(PointModeEnum mode)
Definition pointgr.cpp:501
Vector3 Get_Point_Color(void)
Definition pointgr.cpp:372
TextureClass * Get_Texture(void)
Definition pointgr.cpp:592
int Get_Polygon_Count(void)
Definition pointgr.cpp:746
void Update_Arrays(Vector3 *point_loc, Vector4 *point_diffuse, float *point_size, unsigned char *point_orientation, unsigned char *point_frame, int active_points, int total_points, int &vnum, int &pnum)
Definition pointgr.cpp:1015
float DefaultPointAlpha
Definition pointgr.h:178
PointModeEnum Get_Point_Mode(void)
Definition pointgr.cpp:519
bool Get_Billboard(void)
Definition pointgr.cpp:691
ShaderClass Shader
Definition pointgr.h:171
static void _Init(void)
Definition pointgr.cpp:1438
virtual ~SegmentGroupClass(void)
unsigned char flag
Definition vchannel.cpp:273