Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
dsurface.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 : Command & Conquer *
24 * *
25 * $Archive:: /G/wwlib/dsurface.h $*
26 * *
27 * $Author:: Neal_k $*
28 * *
29 * $Modtime:: 6/23/00 2:24p $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#ifndef DSURFACE_H
38#define DSURFACE_H
39
40#include "palette.h"
41#include "win.h"
42#include "xsurface.h"
43#include <ddraw.h>
44
45/*
46** This is a concrete surface class that is based on the DirectDraw
47** API.
48*/
49class DSurface : public XSurface
50{
51 typedef XSurface BASECLASS;
52
53 public:
54 virtual ~DSurface(void);
55
56 /*
57 ** Default constructor.
58 */
59 DSurface(void);
60
61 /*
62 ** Constructs a working surface (not visible).
63 */
64 DSurface(int width, int height, bool system_memory = false, DDPIXELFORMAT *pixform=NULL);
65
66 /*
67 ** Creates a surface from a previously created DirectDraw surface object.
68 */
69 DSurface(LPDIRECTDRAWSURFACE surfaceptr);
70
71 /*
72 ** Get/Release a windows device context from a DirectX surface
73 */
74 HDC GetDC(void);
75 int ReleaseDC(HDC hdc);
76
77 /*
78 ** Create a surface object that represents the currently visible screen.
79 */
80 static DSurface * Create_Primary(DSurface ** backsurface1=NULL);
81
82 /*
83 ** Copies regions from one surface to another.
84 */
85 virtual bool Blit_From(Rect const & dcliprect, Rect const & destrect, Surface const & source, Rect const & scliprect, Rect const & sourcerect, bool trans=false);
86 virtual bool Blit_From(Rect const & destrect, Surface const & source, Rect const & sourcerect, bool trans=false);
87 virtual bool Blit_From(Surface const & source, bool trans=false) {return(XSurface::Blit_From(source, trans));}
88
89 /*
90 ** Fills a region with a constant color.
91 */
92 virtual bool Fill_Rect(Rect const & rect, int color);
93 virtual bool Fill_Rect(Rect const & cliprect, Rect const & fillrect, int color);
94
95 /*
96 ** Gets and frees a direct pointer to the video memory.
97 */
98 virtual void * Lock(Point2D point = Point2D(0, 0)) const;
99 virtual bool Unlock(void) const;
100
101 /*
102 ** Queries information about the surface.
103 */
104 virtual int Bytes_Per_Pixel(void) const;
105 virtual int Stride(void) const;
106 bool In_Video_Ram(void) const {return(IsVideoRam);}
107
108 /*
109 ** Verifies that this is a direct draw enabled surface.
110 */
111 virtual bool Is_Direct_Draw(void) const {return(true);}
112
113 static int Build_Hicolor_Pixel(int red, int green, int blue);
114 static void Build_Remap_Table(unsigned short * table, PaletteClass const & palette);
115 static unsigned short Get_Halfbright_Mask(void) {return(HalfbrightMask);}
116 static unsigned short Get_Quarterbright_Mask(void) {return(QuarterbrightMask);}
117 static unsigned short Get_Eighthbright_Mask(void) {return(EighthbrightMask);}
118
119 protected:
120 void Restore_Check(void) const;
121
122 /*
123 ** Convenient copy of the bytes per pixel value to speed accessing it. It
124 ** gets accessed frequently.
125 */
126 mutable int BytesPerPixel;
127
128 /*
129 ** Lock count and pointer values. This is used to keep track of the levels
130 ** of locking the graphic data. This is only here because DirectDraw prohibits
131 ** the blitter from working on a surface that has been locked.
132 */
133 mutable void * LockPtr;
134
135 /*
136 ** If this surface object represents the one that is visible and associated
137 ** with the system GDI, then this flag will be true.
138 */
140
141 /*
142 ** Is this surface represented in video ram?
143 */
145
146 /*
147 ** Direct draw specific data.
148 */
149 LPDIRECTDRAWSURFACE SurfacePtr;
150 DDSURFACEDESC * Description;
151
152 /*
153 ** Pointer to the clipper object that is attached to the primary
154 ** surface.
155 */
156 static LPDIRECTDRAWCLIPPER Clipper;
157
158 /*
159 ** Pixel format of primary surface.
160 */
161 static DDPIXELFORMAT PixelFormat;
162
163 /*
164 ** Shift values to extract the gun value from a hicolor pixel such that the
165 ** gun component is normalized to a byte value.
166 */
167 static int RedRight;
168 static int RedLeft;
169 static int BlueRight;
170 static int BlueLeft;
171 static int GreenRight;
172 static int GreenLeft;
173
174 public:
175 /*
176 ** Shift values specific to this surface (the above are for the primary surface)
177 */
184
185 protected:
186 static unsigned short HalfbrightMask;
187 static unsigned short QuarterbrightMask;
188 static unsigned short EighthbrightMask;
189
190
191 /*
192 ** Number of locks we had to remove in order to get the device context...
193 */
195
196 private:
197 /*
198 ** This prevents the creation of a surface in ways that are not
199 ** supported.
200 */
201 DSurface(DSurface const & rvalue);
202 DSurface const operator = (DSurface const & rvalue);
203};
204
205#endif
#define NULL
Definition BaseType.h:92
TPoint2D< int > Point2D
Definition Point.h:114
static int BlueLeft
Definition dsurface.h:170
virtual bool Blit_From(Surface const &source, bool trans=false)
Definition dsurface.h:87
int BytesPerPixel
Definition dsurface.h:126
int ThisGreenLeft
Definition dsurface.h:183
static LPDIRECTDRAWCLIPPER Clipper
Definition dsurface.h:156
static int RedRight
Definition dsurface.h:167
static unsigned short QuarterbrightMask
Definition dsurface.h:187
LPDIRECTDRAWSURFACE SurfacePtr
Definition dsurface.h:149
virtual int Stride(void) const
Definition dsurface.cpp:578
int ThisRedLeft
Definition dsurface.h:179
static int Build_Hicolor_Pixel(int red, int green, int blue)
Definition dsurface.cpp:895
virtual bool Fill_Rect(Rect const &rect, int color)
Definition dsurface.cpp:800
static int RedLeft
Definition dsurface.h:168
HDC GetDC(void)
Definition dsurface.cpp:282
void Restore_Check(void) const
Definition dsurface.cpp:669
int ThisRedRight
Definition dsurface.h:178
bool In_Video_Ram(void) const
Definition dsurface.h:106
static unsigned short EighthbrightMask
Definition dsurface.h:188
static unsigned short Get_Eighthbright_Mask(void)
Definition dsurface.h:117
virtual bool Blit_From(Rect const &dcliprect, Rect const &destrect, Surface const &source, Rect const &scliprect, Rect const &sourcerect, bool trans=false)
Definition dsurface.cpp:741
int ThisBlueLeft
Definition dsurface.h:181
static unsigned short HalfbrightMask
Definition dsurface.h:186
static void Build_Remap_Table(unsigned short *table, PaletteClass const &palette)
Definition dsurface.cpp:919
static unsigned short Get_Quarterbright_Mask(void)
Definition dsurface.h:116
virtual ~DSurface(void)
Definition dsurface.cpp:214
int ThisBlueRight
Definition dsurface.h:180
static DSurface * Create_Primary(DSurface **backsurface1=NULL)
Definition dsurface.cpp:373
virtual void * Lock(Point2D point=Point2D(0, 0)) const
Definition dsurface.cpp:605
static int GreenLeft
Definition dsurface.h:172
int DCUnlockCount
Definition dsurface.h:194
static int BlueRight
Definition dsurface.h:169
static DDPIXELFORMAT PixelFormat
Definition dsurface.h:161
virtual bool Is_Direct_Draw(void) const
Definition dsurface.h:111
static unsigned short Get_Halfbright_Mask(void)
Definition dsurface.h:115
bool IsPrimary
Definition dsurface.h:139
static int GreenRight
Definition dsurface.h:171
virtual int Bytes_Per_Pixel(void) const
Definition dsurface.cpp:556
int ReleaseDC(HDC hdc)
Definition dsurface.cpp:329
void * LockPtr
Definition dsurface.h:133
bool IsVideoRam
Definition dsurface.h:144
DSurface(void)
Definition dsurface.cpp:256
int ThisGreenRight
Definition dsurface.h:182
virtual bool Unlock(void) const
Definition dsurface.cpp:639
DDSURFACEDESC * Description
Definition dsurface.h:150
Surface(int width, int height)
Definition Surface.h:55
XSurface(int width=0, int height=0)
Definition xsurface.h:54
virtual bool Blit_From(Rect const &dcliprect, Rect const &destrect, Surface const &source, Rect const &scliprect, Rect const &sourcerect, bool trans=false)
Definition xsurface.cpp:525
TRect< int > Rect
Definition trect.h:221