Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
dx8vertexbuffer.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/dx8vertexbuffer.h $*
26 * *
27 * Original Author:: Jani Penttinen *
28 * *
29 * $Author:: Kenny Mitchell *
30 * *
31 * $Modtime:: 06/26/02 5:06p $*
32 * *
33 * $Revision:: 26 $*
34 * *
35 * 06/26/02 KM VB Vertex format size update for shaders *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40#if defined(_MSC_VER)
41#pragma once
42#endif
43
44#ifndef DX8VERTEXBUFFER_H
45#define DX8VERTEXBUFFER_H
46
47#include "always.h"
48#include "wwdebug.h"
49#include "refcount.h"
50#include "dx8fvf.h"
51
52const unsigned dynamic_fvf_type=D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2|D3DFVF_DIFFUSE;
53
54class DX8Wrapper;
56class Vector2;
57class Vector3;
58class Vector4;
59class StringClass;
61class FVFInfoClass;
62struct IDirect3DVertexBuffer8;
65
67{
68protected:
70 void* Vertices;
71
72 // This class can't be used directly, so constructor as to be protected
73 VertexBufferLockClass(VertexBufferClass* vertex_buffer_) : VertexBuffer(vertex_buffer_) {}
74public:
75 void* Get_Vertex_Array() { return Vertices; }
76};
77
83{
84 // nope, an ABC
85 //W3DMPO_GLUE(VertexBufferClass)
86
87protected:
88 VertexBufferClass(unsigned type, unsigned FVF, unsigned short VertexCount, unsigned vertex_size=0);
89 virtual ~VertexBufferClass();
90public:
91
92 inline const FVFInfoClass& FVF_Info() const { return *fvf_info; }
93 inline unsigned short Get_Vertex_Count() const { return VertexCount; }
94 inline unsigned Type() const { return type; }
95
96 void Add_Engine_Ref() const;
97 void Release_Engine_Ref() const;
98 inline unsigned Engine_Refs() const { return engine_refs; }
99
101 {
102 public:
103 WriteLockClass(VertexBufferClass* vertex_buffer, int flags=0);
105 };
106
108 {
109 public:
110 AppendLockClass(VertexBufferClass* vertex_buffer,unsigned start_index, unsigned index_range);
112 };
113
114 static unsigned Get_Total_Buffer_Count();
115 static unsigned Get_Total_Allocated_Vertices();
116 static unsigned Get_Total_Allocated_Memory();
117
118protected:
119 unsigned type;
120 unsigned short VertexCount;
121 mutable int engine_refs;
123};
124
125
126
138
140{
141 friend DX8Wrapper;
142 friend SortingRendererClass;
143
144 const FVFInfoClass& FVFInfo;
145 unsigned Type;
146 unsigned short VertexCount;
147 unsigned short VertexBufferOffset;
148 VertexBufferClass* VertexBuffer;
149// static VertexFormatXYZNDUV2* _Get_Sorting_Vertex_Array();
150
151 void Allocate_Sorting_Dynamic_Buffer();
152 void Allocate_DX8_Dynamic_Buffer();
153public:
154 // Type parameter can be either BUFFER_TYPE_DYNAMIC_DX8 or BUFFER_TYPE_DYNAMIC_SORTING.
155
156 // Note: Even though the constructor takes fvf as a parameter, currently the
157 // only acceptable parameter is "dynamic_fvf_type". Any other type will
158 // result to an assert.
159 DynamicVBAccessClass(unsigned type,unsigned fvf,unsigned short vertex_count);
161
162 // Access fvf
163 const FVFInfoClass& FVF_Info() const { return FVFInfo; }
164 unsigned Get_Type() const { return Type; }
165 unsigned short Get_Vertex_Count() const { return VertexCount; }
166
167 // Call at the end of the execution, or at whatever time you wish to release
168 // the recycled dynamic vertex buffer.
169 static void _Deinit();
170 static void _Reset(bool frame_changed);
171 static unsigned short Get_Default_Vertex_Count(void);
172
173 // To lock the vertex buffer, create instance of this write class locally.
174 // The buffer is automatically unlocked when you exit the scope.
175 class WriteLockClass// : public VertexBufferLockClass
176 {
177 DynamicVBAccessClass* DynamicVBAccess;
178 VertexFormatXYZNDUV2 * Vertices;
179 public:
182
183 // Use this function to get a pointer to the first vertex you can write into.
184 // If we ever change the format used by DynamicVBAccessClass, then the
185 // return type of this function will change and we'll easily find all code
186 // using it.
188 };
190};
191
192// ----------------------------------------------------------------------------
193
195{
196 // assert that the format of the dynamic vertex buffer is still what we think it is.
197 WWASSERT(DynamicVBAccess->VertexBuffer->FVF_Info().Get_FVF() == (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2|D3DFVF_DIFFUSE));
198 return Vertices;
199}
200
201// ----------------------------------------------------------------------------
202
208{
210protected:
212public:
219
220 DX8VertexBufferClass(unsigned FVF, unsigned short VertexCount, UsageType usage=USAGE_DEFAULT, unsigned vertex_size=0); // Vertex size not used with FVF formats
221 DX8VertexBufferClass(const Vector3* vertices, const Vector3* normals, const Vector2* tex_coords, unsigned short VertexCount,UsageType usage=USAGE_DEFAULT);
222 DX8VertexBufferClass(const Vector3* vertices, const Vector3* normals, const Vector4* diffuse, const Vector2* tex_coords, unsigned short VertexCount,UsageType usage=USAGE_DEFAULT);
223 DX8VertexBufferClass(const Vector3* vertices, const Vector4* diffuse, const Vector2* tex_coords, unsigned short VertexCount,UsageType usage=USAGE_DEFAULT);
224 DX8VertexBufferClass(const Vector3* vertices, const Vector2* tex_coords, unsigned short VertexCount,UsageType usage=USAGE_DEFAULT);
225
226 IDirect3DVertexBuffer8* Get_DX8_Vertex_Buffer() { return VertexBuffer; }
227
228 void Copy(const Vector3* loc, unsigned first_vertex, unsigned count);
229 void Copy(const Vector3* loc, const Vector2* uv, unsigned first_vertex, unsigned count);
230 void Copy(const Vector3* loc, const Vector3* norm, unsigned first_vertex, unsigned count);
231 void Copy(const Vector3* loc, const Vector3* norm, const Vector2* uv, unsigned first_vertex, unsigned count);
232 void Copy(const Vector3* loc, const Vector3* norm, const Vector2* uv, const Vector4* diffuse, unsigned first_vertex, unsigned count);
233 void Copy(const Vector3* loc, const Vector2* uv, const Vector4* diffuse, unsigned first_vertex, unsigned count);
234
235protected:
236 IDirect3DVertexBuffer8* VertexBuffer;
237
239};
240
241
247{
249
250 friend DX8Wrapper;
251 friend SortingRendererClass;
255
256 VertexFormatXYZNDUV2* VertexBuffer;
257
258protected:
260public:
262};
263
264
265#endif //DX8VERTEXBUFFER_H
#define WWASSERT
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
DX8VertexBufferClass(unsigned FVF, unsigned short VertexCount, UsageType usage=USAGE_DEFAULT, unsigned vertex_size=0)
void Create_Vertex_Buffer(UsageType usage)
IDirect3DVertexBuffer8 * VertexBuffer
IDirect3DVertexBuffer8 * Get_DX8_Vertex_Buffer()
VertexFormatXYZNDUV2 * Get_Formatted_Vertex_Array()
WriteLockClass(DynamicVBAccessClass *vb_access)
static unsigned short Get_Default_Vertex_Count(void)
current size of dynamic vertex buffer
unsigned Get_Type() const
static void _Reset(bool frame_changed)
DynamicVBAccessClass(unsigned type, unsigned fvf, unsigned short vertex_count)
unsigned short Get_Vertex_Count() const
const FVFInfoClass & FVF_Info() const
RefCountClass(void)
Definition refcount.h:108
SortingVertexBufferClass(unsigned short VertexCount)
AppendLockClass(VertexBufferClass *vertex_buffer, unsigned start_index, unsigned index_range)
WriteLockClass(VertexBufferClass *vertex_buffer, int flags=0)
unsigned short VertexCount
unsigned short Get_Vertex_Count() const
static unsigned Get_Total_Allocated_Vertices()
FVFInfoClass * fvf_info
unsigned Engine_Refs() const
VertexBufferClass(unsigned type, unsigned FVF, unsigned short VertexCount, unsigned vertex_size=0)
void Release_Engine_Ref() const
static unsigned Get_Total_Allocated_Memory()
unsigned Type() const
static unsigned Get_Total_Buffer_Count()
void Add_Engine_Ref() const
const FVFInfoClass & FVF_Info() const
VertexBufferClass * VertexBuffer
VertexBufferLockClass(VertexBufferClass *vertex_buffer_)
const unsigned dynamic_fvf_type