Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
visrasterizer.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/visrasterizer.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Jani_p $*
30 * *
31 * $Modtime:: 11/24/01 5:42p $*
32 * *
33 * $Revision:: 6 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef VISRASTERIZER_H
44#define VISRASTERIZER_H
45
46#include "always.h"
47#include "matrix3d.h"
48#include "matrix4.h"
49#include "vector3i.h"
50#include "vector3.h"
51#include "simplevec.h"
52#include "bittype.h"
53#include "plane.h"
54#include "meshgeometry.h"
55
56
57class CameraClass;
58class AABoxClass;
59struct GradientsStruct;
60struct EdgeStruct;
61
68{
69public:
70 IDBufferClass(void);
71 ~IDBufferClass(void);
72
73 /*
74 ** State interface
75 */
76 void Set_Resolution(int w,int h);
77 void Get_Resolution(int * get_w,int * get_h);
78
83
86
88 void Set_Render_Mode(ModeType mode) { RenderMode = mode; }
90
92 int Get_Pixel_Counter(void) { return PixelCounter; }
93
94 /*
95 ** Rendering interface
96 */
97 void Clear(void);
98 bool Render_Triangle(const Vector3 & p0,const Vector3 & p1,const Vector3 & p2);
99 const uint32 * Get_Pixel_Row(int y,int min_x,int max_x);
100
101protected:
102 void Reset(void);
103 void Allocate_Buffers(void);
104 bool Is_Backfacing(const Vector3 & p0,const Vector3 & p1,const Vector3 & p2);
107 int Pixel_Coords_To_Address(int x,int y) { return y*ResWidth + x; }
108
115
119 float * ZBuffer; // actually a 1/z buffer...
120};
121
122inline const uint32 * IDBufferClass::Get_Pixel_Row(int y,int min_x,int max_x)
123{
124 WWASSERT(y>=0);
126 WWASSERT(min_x>=0);
127 WWASSERT(max_x<=ResWidth);
128
129 int addr = Pixel_Coords_To_Address(min_x,y);
130 return &(IDBuffer[addr]);
131}
132
133inline bool IDBufferClass::Is_Backfacing(const Vector3 & p0,const Vector3 & p1,const Vector3 & p2)
134{
135 float x1=p1[0]-p0[0];
136 float y1=p1[1]-p0[1];
137 float x2=p2[0]-p0[0];
138 float y2=p2[1]-p0[1];
139 float r=x1*y2-x2*y1;
140 if (r<0.0f) return true;
141 return false;
142}
143
144
145
146
155{
156public:
157
158 VisRasterizerClass(void);
160
161 /*
162 ** ID Buffer Interface
163 */
164 void Set_Render_Mode(IDBufferClass::ModeType mode) { IDBuffer.Set_Render_Mode(mode); }
165 IDBufferClass::ModeType Get_Render_Mode(void) { return IDBuffer.Get_Render_Mode(); }
166
167 void Set_Backface_ID(uint32 id) { IDBuffer.Set_Backface_ID(id); }
168 void Set_Frontface_ID(uint32 id) { IDBuffer.Set_Frontface_ID(id); }
169 uint32 Get_Backface_ID(void) { return IDBuffer.Get_Backface_ID(); }
170 uint32 Get_Frontface_ID(void) { return IDBuffer.Get_Frontface_ID(); }
171
172 void Enable_Two_Sided_Rendering(bool onoff) { IDBuffer.Enable_Two_Sided_Rendering(onoff); }
173 bool Is_Two_Sided_Rendering_Enabled(void) { return IDBuffer.Is_Two_Sided_Rendering_Enabled(); }
174
175 void Set_Resolution(int width,int height);
176 void Get_Resolution(int * set_width,int * set_height);
177
178 void Reset_Pixel_Counter(void) { IDBuffer.Reset_Pixel_Counter(); }
179 int Get_Pixel_Counter(void) { return IDBuffer.Get_Pixel_Counter(); }
180
181 /*
182 ** Rendering Interface
183 */
184 void Set_Model_Transform(const Matrix3D & model);
185 void Set_Camera(CameraClass * camera);
186
188 CameraClass * Get_Camera(void);
189 CameraClass * Peek_Camera(void);
190
191 void Clear(void) { IDBuffer.Clear(); }
192 bool Render_Triangles(const Vector3 * verts,int vcount,const TriIndex * tris, int tcount,const AABoxClass & bounds);
193 const uint32 * Get_Pixel_Row(int y,int min_x,int max_x) { return IDBuffer.Get_Pixel_Row(y,min_x,max_x); }
194
195protected:
196
197 void Update_MV_Transform(void);
198 const Matrix3D & Get_MV_Transform(void);
199 Vector3 * Get_Temp_Vertex_Buffer(int count);
200 bool Render_Triangles_Clip(const Vector3 * verts,int vcount,const TriIndex * tris, int tcount);
201 bool Render_Triangles_No_Clip(const Vector3 * verts,int vcount,const TriIndex * tris, int tcount);
202
203 Matrix3D ModelTransform; // AKA "World Transform"
206
208
210};
211
212#endif //VISRASTERIZER_H
213
#define WWASSERT
unsigned long uint32
Definition bittype.h:46
void Get_Resolution(int *get_w, int *get_h)
int Render_Non_Occluder_Scanline(GradientsStruct &grads, EdgeStruct *left, EdgeStruct *right)
void Set_Render_Mode(ModeType mode)
bool Is_Backfacing(const Vector3 &p0, const Vector3 &p1, const Vector3 &p2)
uint32 * IDBuffer
void Set_Frontface_ID(uint32 id)
void Reset_Pixel_Counter(void)
const uint32 * Get_Pixel_Row(int y, int min_x, int max_x)
ModeType RenderMode
ModeType Get_Render_Mode(void)
int Render_Occluder_Scanline(GradientsStruct &grads, EdgeStruct *left, EdgeStruct *right)
void Allocate_Buffers(void)
bool TwoSidedRenderingEnabled
uint32 Get_Frontface_ID(void)
bool Is_Two_Sided_Rendering_Enabled(void)
int Get_Pixel_Counter(void)
uint32 Get_Backface_ID(void)
int Pixel_Coords_To_Address(int x, int y)
void Enable_Two_Sided_Rendering(bool onoff)
void Set_Resolution(int w, int h)
bool Render_Triangle(const Vector3 &p0, const Vector3 &p1, const Vector3 &p2)
void Set_Backface_ID(uint32 id)
CameraClass * Camera
uint32 Get_Backface_ID(void)
void Set_Camera(CameraClass *camera)
bool Render_Triangles_No_Clip(const Vector3 *verts, int vcount, const TriIndex *tris, int tcount)
IDBufferClass::ModeType Get_Render_Mode(void)
CameraClass * Peek_Camera(void)
const Matrix3D & Get_Model_Transform(void)
void Enable_Two_Sided_Rendering(bool onoff)
IDBufferClass IDBuffer
int Get_Pixel_Counter(void)
bool Render_Triangles_Clip(const Vector3 *verts, int vcount, const TriIndex *tris, int tcount)
void Set_Render_Mode(IDBufferClass::ModeType mode)
void Set_Backface_ID(uint32 id)
void Get_Resolution(int *set_width, int *set_height)
void Set_Model_Transform(const Matrix3D &model)
void Reset_Pixel_Counter(void)
SimpleVecClass< Vector3 > TempVertexBuffer
const uint32 * Get_Pixel_Row(int y, int min_x, int max_x)
bool Is_Two_Sided_Rendering_Enabled(void)
const Matrix3D & Get_MV_Transform(void)
void Update_MV_Transform(void)
bool Render_Triangles(const Vector3 *verts, int vcount, const TriIndex *tris, int tcount, const AABoxClass &bounds)
Vector3 * Get_Temp_Vertex_Buffer(int count)
void Set_Frontface_ID(uint32 id)
CameraClass * Get_Camera(void)
void Set_Resolution(int width, int height)
uint32 Get_Frontface_ID(void)
Vector3i16 TriIndex