Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
streakRender.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 : ww3d *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/Streakrender.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Greg_h $*
30 * *
31 * $Modtime:: 6/08/01 5:23p $*
32 * *
33 * $Revision:: 1 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#ifndef STREAKRENDER_H
40#define STREAKRENDER_H
41
42#include "always.h"
43#include "shader.h"
44#include "texture.h"
45#include "matrix3d.h"
46#include "vector2.h"
47
48class RenderInfoClass;
49class SphereClass;
52
53// The maximum allowable level of subdivision. This should be no more than 7 to avoid increasing
54// the chunk buffer size too much
55#define MAX_STREAK_SUBDIV_LEVELS 7
56
57
58
65{
66public:
67
72
74 UNIFORM_WIDTH_TEXTURE_MAP = 0x00000000, // Entire line uses one row of texture (constant V)
75 UNIFORM_LENGTH_TEXTURE_MAP = 0x00000001, // Entire line uses one row of texture stretched length-wise
76 TILED_TEXTURE_MAP = 0x00000002 // Tiled continuously over line
77 };
78
79 void Init(const W3dEmitterLinePropertiesStruct & props);
80
81 // Get properties used to render this line segment
82 TextureClass * Get_Texture(void) const;
83 TextureClass * Peek_Texture(void) const { return Texture; }
84 ShaderClass Get_Shader(void) const { return Shader; }
85 float Get_Width(void) const { return Width; }
86 const Vector3 & Get_Color(void) const { return Color; }
87 float Get_Opacity(void) const { return Opacity; }
88 float Get_Noise_Amplitude(void) const { return NoiseAmplitude; }
89 float Get_Merge_Abort_Factor(void) const { return MergeAbortFactor; }
90 unsigned int Get_Current_Subdivision_Level(void) const { return SubdivisionLevel; }
92 // float Get_Texture_Tile_Factor(void) const { return TextureTileFactor; }
93 // Vector2 Get_UV_Offset_Rate(void) const;
94 int Is_Merge_Intersections(void) const { return Bits & MERGE_INTERSECTIONS; }
95 int Is_Freeze_Random(void) const { return Bits & FREEZE_RANDOM; }
96 int Is_Sorting_Disabled(void) const { return Bits & DISABLE_SORTING; }
97 int Are_End_Caps_Enabled(void) const { return Bits & END_CAPS; }
98
99 // Set properties used to render this line segment
100 void Set_Texture(TextureClass *texture);
101 void Set_Shader(ShaderClass shader) { Shader = shader; }
102 void Set_Width(float width) { Width = width; }
103 void Set_Color(const Vector3 &color) { Color = color; }
104 void Set_Opacity(float opacity) { Opacity = opacity; }
105 void Set_Noise_Amplitude(float amplitude) { NoiseAmplitude = amplitude; }
106 void Set_Merge_Abort_Factor(float factor) { MergeAbortFactor = factor; }
107 void Set_Current_Subdivision_Level(unsigned int lv) {
108 DEBUG_ASSERTCRASH(lv == 0, ("Streak renderer does not work for non-zero subdivisions"));
109 SubdivisionLevel = lv; SubdivisionLevel = 0;
110 }
112 // WARNING! Do NOT set the tile factor to be too high (should be less than 8) or negative
113 //performance impact will result!
114 // void Set_Texture_Tile_Factor(float factor);
115 // void Set_Current_UV_Offset(const Vector2 & offset);
116 // void Set_UV_Offset_Rate(const Vector2 &rate);
117 void Set_Merge_Intersections(int onoff) { if (onoff) { Bits |= MERGE_INTERSECTIONS; } else { Bits &= ~MERGE_INTERSECTIONS; }; }
118 void Set_Freeze_Random(int onoff) { if (onoff) { Bits |= FREEZE_RANDOM; } else { Bits &= ~FREEZE_RANDOM; }; }
119 void Set_Disable_Sorting(int onoff) { if (onoff) { Bits |= DISABLE_SORTING; } else { Bits &= ~DISABLE_SORTING; }; }
120 void Set_End_Caps(int onoff) { if (onoff) { Bits |= END_CAPS; } else { Bits &= ~END_CAPS; }; }
121
122 void Reset_Line(void);
123
124
125 void Render( RenderInfoClass & rinfo,
126 const Matrix3D & transform,
127 unsigned int point_count,
128 Vector3 * points,
129 const SphereClass & obj_sphere);
130
131 void RenderStreak( RenderInfoClass & rinfo,
132 const Matrix3D & transform,
133 unsigned int point_count,
134 Vector3 * points,
135 Vector4 * colors,
136 float * widths,
137 const SphereClass & obj_sphere,
138 unsigned int *personalities);
139
140private:
141
142 // Utility functions
143 void subdivision_util(unsigned int point_cnt, const Vector3 *xformed_pts,
144 const float *base_tex_v, unsigned int *p_sub_point_cnt,
145 Vector3 *xformed_subdiv_pts, float *subdiv_tex_v);
146
147 // Global properties
148 TextureClass * Texture;
149 ShaderClass Shader;
150 float Width;
152 float Opacity;
153
154 // Subdivision properties
155 unsigned int SubdivisionLevel;
156 float NoiseAmplitude;
157
158 // If >0, will abort a merge which causes an intersection to move
159 // farther away than this factor * line radius from the line point.
160 // (defaults to 1.5, has no affect if intersection merging is disabled).
161 float MergeAbortFactor;
162
163 // Affects tiled texture mapping mode only. If this is set too high, performance (and
164 // possibly visual) problems will result from excessive tiling over a single polygon, over
165 // the entire line, or both.
166 // float TextureTileFactor;
167
168 // Used for texture coordinate animation
169 // unsigned int LastUsedSyncTime; // Last sync time used
170 // Vector2 CurrentUVOffset; // Current UV offset
171 // Vector2 UVOffsetDeltaPerMS; // Amount to increase offset each millisec
172
173 // Various flags
174 enum BitShiftOffsets {
175 TEXTURE_MAP_MODE_OFFSET = 24 // By how many bits do I need to shift the texture mapping mode?
176 };
177 enum {
178 MERGE_INTERSECTIONS = 0x00000001, // Merge intersections
179 FREEZE_RANDOM = 0x00000002, // Freeze random (note: offsets are in camera space)
180 DISABLE_SORTING = 0x00000004, // Disable sorting (even if shader has alpha-blending)
181 END_CAPS = 0x00000008, // Draw end caps on the line
182
183 // Some bits are used to select the texture mapping mode:
184 TEXTURE_MAP_MODE_MASK = 0xFF000000, // Must cover all possible TextureMapMode values
185
186 DEFAULT_BITS = MERGE_INTERSECTIONS | (UNIFORM_WIDTH_TEXTURE_MAP << TEXTURE_MAP_MODE_OFFSET)
187 };
188 unsigned int Bits;
189
190 friend class SegmentedLineClass;
191
192 // Vertex buffer manager
193 VertexFormatXYZUV1 *getVertexBuffer(unsigned int number);
194 unsigned int m_vertexBufferSize;
195 VertexFormatXYZUV1 *m_vertexBuffer;
196};
197
198
199
201{
202 return (TextureMapMode)((Bits & TEXTURE_MAP_MODE_MASK) >> TEXTURE_MAP_MODE_OFFSET);
203}
204
206{
207 Bits &= ~TEXTURE_MAP_MODE_MASK;
208 Bits |= ((mode << TEXTURE_MAP_MODE_OFFSET) & TEXTURE_MAP_MODE_MASK);
209}
210
211// inline Vector2 StreakRendererClass::Get_UV_Offset_Rate(void) const
212// {
213// return UVOffsetDeltaPerMS * 1000.0f;
214// }
215
216// inline void StreakRendererClass::Set_UV_Offset_Rate(const Vector2 &rate)
217// {
218// UVOffsetDeltaPerMS = rate * 0.001f;
219// }
220
222{
223 // Empty
224}
225
226#endif //STREAKRENDER_H
227
#define DEBUG_ASSERTCRASH(c, m)
Definition Debug.h:193
Int Color
Definition Xfer.h:45
int Is_Merge_Intersections(void) const
int Is_Freeze_Random(void) const
const Vector3 & Get_Color(void) const
void Set_Merge_Abort_Factor(float factor)
float Get_Noise_Amplitude(void) const
TextureMapMode Get_Texture_Mapping_Mode(void) const
void Set_Shader(ShaderClass shader)
void Set_Texture_Mapping_Mode(TextureMapMode mode)
void Set_Noise_Amplitude(float amplitude)
void Set_Disable_Sorting(int onoff)
void Set_Current_Subdivision_Level(unsigned int lv)
unsigned int Get_Current_Subdivision_Level(void) const
int Are_End_Caps_Enabled(void) const
void Init(const W3dEmitterLinePropertiesStruct &props)
int Is_Sorting_Disabled(void) const
void Set_Width(float width)
void Set_Freeze_Random(int onoff)
void RenderStreak(RenderInfoClass &rinfo, const Matrix3D &transform, unsigned int point_count, Vector3 *points, Vector4 *colors, float *widths, const SphereClass &obj_sphere, unsigned int *personalities)
void Set_Texture(TextureClass *texture)
float Get_Merge_Abort_Factor(void) const
float Get_Opacity(void) const
void Set_Color(const Vector3 &color)
float Get_Width(void) const
void Set_Opacity(float opacity)
TextureClass * Peek_Texture(void) const
friend class SegmentedLineClass
TextureClass * Get_Texture(void) const
void Render(RenderInfoClass &rinfo, const Matrix3D &transform, unsigned int point_count, Vector3 *points, const SphereClass &obj_sphere)
void Set_End_Caps(int onoff)
StreakRendererClass & operator=(const StreakRendererClass &that)
ShaderClass Get_Shader(void) const
void Set_Merge_Intersections(int onoff)