Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
seglinerenderer.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/seglinerenderer.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 SEGLINERENDERER_H
40#define SEGLINERENDERER_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
54// The maximum allowable level of subdivision. This should be no more than 7 to avoid increasing
55// the chunk buffer size too much
56#define MAX_SEGLINE_SUBDIV_LEVELS 7
57
58
59
66{
67public:
68
73
75 UNIFORM_WIDTH_TEXTURE_MAP = 0x00000000, // Entire line uses one row of texture (constant V)
76 UNIFORM_LENGTH_TEXTURE_MAP = 0x00000001, // Entire line uses one row of texture stretched length-wise
77 TILED_TEXTURE_MAP = 0x00000002 // Tiled continuously over line
78 };
79
80 void Init(const W3dEmitterLinePropertiesStruct & props);
81
82 // Get properties used to render this line segment
83 TextureClass * Get_Texture(void) const;
84 TextureClass * Peek_Texture(void) const { return Texture; }
85 ShaderClass Get_Shader(void) const { return Shader; }
86 float Get_Width(void) const { return Width; }
87 const Vector3 & Get_Color(void) const { return Color; }
88 float Get_Opacity(void) const { return Opacity; }
89 float Get_Noise_Amplitude(void) const { return NoiseAmplitude; }
90 float Get_Merge_Abort_Factor(void) const { return MergeAbortFactor; }
91 unsigned int Get_Current_Subdivision_Level(void) const { return SubdivisionLevel; }
93 float Get_Texture_Tile_Factor(void) const { return TextureTileFactor; }
94 Vector2 Get_UV_Offset_Rate(void) const;
95 int Is_Merge_Intersections(void) const { return Bits & MERGE_INTERSECTIONS; }
96 int Is_Freeze_Random(void) const { return Bits & FREEZE_RANDOM; }
97 int Is_Sorting_Disabled(void) const { return Bits & DISABLE_SORTING; }
98 int Are_End_Caps_Enabled(void) const { return Bits & END_CAPS; }
99
100 // Set properties used to render this line segment
101 void Set_Texture(TextureClass *texture);
102 void Set_Shader(ShaderClass shader) { Shader = shader; }
103 void Set_Width(float width) { Width = width; }
104 void Set_Color(const Vector3 &color) { Color = color; }
105 void Set_Opacity(float opacity) { Opacity = opacity; }
106 void Set_Noise_Amplitude(float amplitude) { NoiseAmplitude = amplitude; }
107 void Set_Merge_Abort_Factor(float factor) { MergeAbortFactor = factor; }
108 void Set_Current_Subdivision_Level(unsigned int lv) { SubdivisionLevel = lv; }
110 void Set_Texture_Tile_Factor(float factor); // Might be clamped if too high
111 void Set_Current_UV_Offset(const Vector2 & offset);
112 void Set_UV_Offset_Rate(const Vector2 &rate);
113 void Set_Merge_Intersections(int onoff) { if (onoff) { Bits |= MERGE_INTERSECTIONS; } else { Bits &= ~MERGE_INTERSECTIONS; }; }
114 void Set_Freeze_Random(int onoff) { if (onoff) { Bits |= FREEZE_RANDOM; } else { Bits &= ~FREEZE_RANDOM; }; }
115 void Set_Disable_Sorting(int onoff) { if (onoff) { Bits |= DISABLE_SORTING; } else { Bits &= ~DISABLE_SORTING; }; }
116 void Set_End_Caps(int onoff) { if (onoff) { Bits |= END_CAPS; } else { Bits &= ~END_CAPS; }; }
117
118
119 void Render( RenderInfoClass & rinfo,
120 const Matrix3D & transform,
121 unsigned int point_count,
122 Vector3 * points,
123 const SphereClass & obj_sphere,
124 Vector4 * rgbas = 0);
125
126 void Reset_Line(void);
127 void Scale(float scale);
128
129private:
130
131 // Utility functions
132 void subdivision_util(unsigned int point_cnt, const Vector3 *xformed_pts,
133 const float *base_tex_v, unsigned int *p_sub_point_cnt,
134 Vector3 *xformed_subdiv_pts, float *subdiv_tex_v,
135 Vector4 *base_diffuse, Vector4 *subdiv_diffuse);
136
137 // Global properties
138 TextureClass * Texture;
139 ShaderClass Shader;
140 float Width;
142 float Opacity;
143
144 // Subdivision properties
145 unsigned int SubdivisionLevel;
146 float NoiseAmplitude;
147
148 // If >0, will abort a merge which causes an intersection to move
149 // farther away than this factor * line radius from the line point.
150 // (defaults to 1.5, has no affect if intersection merging is disabled).
151 float MergeAbortFactor;
152
153 // Affects tiled texture mapping mode only. If this is set too high, performance (and
154 // possibly visual) problems will result from excessive tiling over a single polygon, over
155 // the entire line, or both.
156 float TextureTileFactor;
157
158 // Used for texture coordinate animation
159 unsigned int LastUsedSyncTime; // Last sync time used
160 Vector2 CurrentUVOffset; // Current UV offset
161 Vector2 UVOffsetDeltaPerMS; // Amount to increase offset each millisec
162
163 // Various flags
164 enum BitShiftOffsets {
165 TEXTURE_MAP_MODE_OFFSET = 24 // By how many bits do I need to shift the texture mapping mode?
166 };
167 enum {
168 MERGE_INTERSECTIONS = 0x00000001, // Merge intersections
169 FREEZE_RANDOM = 0x00000002, // Freeze random (note: offsets are in camera space)
170 DISABLE_SORTING = 0x00000004, // Disable sorting (even if shader has alpha-blending)
171 END_CAPS = 0x00000008, // Draw end caps on the line
172
173 // Some bits are used to select the texture mapping mode:
174 TEXTURE_MAP_MODE_MASK = 0xFF000000, // Must cover all possible TextureMapMode values
175
176 DEFAULT_BITS = MERGE_INTERSECTIONS | (UNIFORM_WIDTH_TEXTURE_MAP << TEXTURE_MAP_MODE_OFFSET)
177 };
178 unsigned int Bits;
179
180 friend class SegmentedLineClass;
181
182 VertexFormatXYZDUV1 *getVertexBuffer(unsigned int number);
183 unsigned int m_vertexBufferSize;
184 VertexFormatXYZDUV1 *m_vertexBuffer;
185};
186
187
188
190{
191 return (TextureMapMode)((Bits & TEXTURE_MAP_MODE_MASK) >> TEXTURE_MAP_MODE_OFFSET);
192}
193
195{
196 Bits &= ~TEXTURE_MAP_MODE_MASK;
197 Bits |= ((mode << TEXTURE_MAP_MODE_OFFSET) & TEXTURE_MAP_MODE_MASK);
198}
199
201{
202 return UVOffsetDeltaPerMS * 1000.0f;
203}
204
206{
207 UVOffsetDeltaPerMS = rate * 0.001f;
208}
209
210
211#endif //SEGLINERENDERER_H
212
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
Int Color
Definition Xfer.h:45
void Render(RenderInfoClass &rinfo, const Matrix3D &transform, unsigned int point_count, Vector3 *points, const SphereClass &obj_sphere, Vector4 *rgbas=0)
TextureMapMode Get_Texture_Mapping_Mode(void) const
void Set_Texture_Tile_Factor(float factor)
void Set_Texture(TextureClass *texture)
unsigned int Get_Current_Subdivision_Level(void) const
void Set_Texture_Mapping_Mode(TextureMapMode mode)
void Set_Current_Subdivision_Level(unsigned int lv)
int Is_Freeze_Random(void) const
SegLineRendererClass & operator=(const SegLineRendererClass &that)
void Set_End_Caps(int onoff)
float Get_Width(void) const
void Set_Width(float width)
void Set_Noise_Amplitude(float amplitude)
void Set_Merge_Abort_Factor(float factor)
Vector2 Get_UV_Offset_Rate(void) const
void Set_Shader(ShaderClass shader)
float Get_Noise_Amplitude(void) const
void Set_Disable_Sorting(int onoff)
void Set_Merge_Intersections(int onoff)
void Scale(float scale)
int Is_Merge_Intersections(void) const
friend class SegmentedLineClass
void Init(const W3dEmitterLinePropertiesStruct &props)
TextureClass * Get_Texture(void) const
float Get_Opacity(void) const
void Set_Freeze_Random(int onoff)
void Set_UV_Offset_Rate(const Vector2 &rate)
void Set_Current_UV_Offset(const Vector2 &offset)
const Vector3 & Get_Color(void) const
int Is_Sorting_Disabled(void) const
ShaderClass Get_Shader(void) const
float Get_Texture_Tile_Factor(void) const
void Set_Color(const Vector3 &color)
void Set_Opacity(float opacity)
TextureClass * Peek_Texture(void) const
int Are_End_Caps_Enabled(void) const
float Get_Merge_Abort_Factor(void) const