Debian Codegraph @

lib/Ddgr.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/lib/Ddgr.h $
21 * $Revision: 6 $
22 * $Date: 12/23/97 6:16p $
23 * $Author: Samir $
24 *
25 * DDGR library interface header
26 *
27 * $Log: /DescentIII/Main/lib/Ddgr.h $
28 *
29 * 6 12/23/97 6:16p Samir
30 * Moved ddgr_Close to header.
31 *
32 * 5 12/22/97 7:24p Samir
33 * took out transparent color defs.
34 *
35 * 4 12/22/97 7:13p Samir
36 * Moved constants to grdefs.h
37 *
38 * 3 9/12/97 4:13p Samir
39 * Added some private data access functions.
40 *
41 * 1 6/23/97 9:25p Samir
42 * added because source safe sucks
43 *
44 * 26 6/12/97 6:30p Samir
45 * DDGR v2.0 Changes in 2d system implemented.
46 *
47 * 25 6/11/97 1:07p Samir
48 * The removal of gameos and replaced with oeApplication, oeDatabase
49 *
50 * 24 5/22/97 4:03p Samir
51 * Hacked OpenGL stuff. WILL CHANGE
52 *
53 * 23 5/15/97 2:08p Samir
54 * Added 8-bit support and driver info structure.
55 *
56 * 22 3/28/97 3:07p Samir
57 * Clear function now takes a color
58 *
59 * 21 3/27/97 11:11a Samir
60 * Revised headers to reflect movement of functions from ddgr to 2dlib
61 *
62 * 20 3/26/97 7:44p Samir
63 * Took out prototypes to unimplemented functions.
64 *
65 * 19 2/27/97 6:16p Samir
66 * moved high level functions to 2dlib internal library
67 *
68 * 18 2/03/97 6:00p Jason
69 * added 2d bitmap scaling functions
70 *
71 * 17 1/30/97 6:01p Samir
72 * The partition of memory and os surfaces as well as the change in
73 * ddgr_surface structure and all related changes.
74 *
75 * $NoKeywords: $
76 */
77
78 #ifndef _DDGR_H
79 #define _DDGR_H
80
81 #include "pstypes.h"
82 #include "Macros.h"
83 #include "grdefs.h"
84
85 // ----------------------------------------------------------------------------
86 // DDGR
87 // version 1.0 // DirectDraw, GDI support
88 // version 2.x // fullscreen-windowed remanagement.
89 // ----------------------------------------------------------------------------
90
91 // ----------------------------------------------------------------------------
92 // Data structures
93 // ----------------------------------------------------------------------------
94
95 /* Type definitions */
96
97 class oeApplication;
98
99 /*
100 Diagnostic DDGR system types and functions
101 */
102
103 struct ddgr_init_info {
104 oeApplication *obj; // the app object created by app calling
105 char *subsystem; // subsystem name (i.e. 'DirectDraw', 'GDI')
106 uint16_t windowed : 1; // are we running in a fullscreen or windowed mode
107 uint16_t debug : 1; // are we running in debug mode?
108 };
109
110 /* app = application object.
111 subsystem = subsystem name ('DirectDraw', 'GDI')
112 fullscreen = whether it's full screen or windowed
113 */
114 bool ddgr_Init(oeApplication *app, char *subsystem, bool fullscreen);
115 void ddgr_Close();
116 void ddgr_GetSubsystem(char *name, bool *fullscreen);
117
118 // returns aspect ratio of current display.
119 float ddgr_GetAspectRatio();
120
121 /* Surface bit depths
122 The bitdepth of the surface determines the color format of the surface. Renderers
123 should use this value to plot
124 */
125
126 // Green with all 6 bits set to 1 is our transparent color
127 // default transparent color to 16bit, but all code should use the first 2 defines.
128
129 /* Surface types
130 Surfaces symbolize a flat 2d surface where pixels are lit. Essentially, a surface could
131 be a bitmap, but if it's the display, it's a bitmap managed by the video card.
132 The goal of this library is to provide a clean, device-independent method to accessing
133 surfaces.
134
135 SURFTYPE_VIDEOSCREEN:
136 The video screen is a physical or virtual display.
137 When you create a videoscreen, you may specify either it is monopage or dualpage (backbuffer)
138 When dualpage, the program can RENDER to the 1st page. To update the video display, you
139 must perform a surface flip.
140
141 SURFTYPE_GENERIC:
142 This is a generic bitmap managed by the operating system. RENDERING is allowed.
143 */
144 const int SURFTYPE_VIDEOSCREEN = 1, // This is equivical to the display.
145 SURFTYPE_GENERIC = 2; // This is an offscreen bitmap.
146
147 /* Surface flags
148 Flags modify a surfaces behavior. A surface may have a backbuffer, which is only really
149 useful for videoscreens.
150
151 SURFFLAG_BACKBUFFER:
152 This surface has a backbuffer.
153 v2.0 Supported in only videoscreen surfaces.
154
155 SURFFLAG_COLORKEY:
156 This surface was created with colorkeying in mind.
157 Renderers should keep this in mind, and check this flag.
158 */
159 const int SURFFLAG_BACKBUFFER = 1, SURFFLAG_COLORKEY = 2;
160
161 /* Surface structures
162 The surface
163 */
164 const int SURF_NAMELEN = 16;
165
166 struct ddgr_surface {
167 void *obj; // internal structure info to library
168 char name[SURF_NAMELEN]; // name
169 int w, h, bpp; // width, height and bit depth
170 uint16_t type; // how driver handles this surface
171 uint16_t flags; // colorkeying, etc.
172 int locks; // lock count.
173 };
174
175 #if defined(WIN32)
176 /*
177 ddraw_surf = true if this is a true DirectDraw surface, false if a GDI surface
178 object_ptr = DirectDraw object if ddraw_surf = true, a HDC if a GDI surface.
179 */
180 void ddgr_surf_GetPrivateData(ddgr_surface *sf, bool *ddraw_surf, uint32_t *object_ptr);
181
182 // you must typecase this return value to LPDIRECTDRAW
183 unsigned ddgr_GetDDrawObject();
184 #endif // WIN32
185
186 /* Surface Functions
187 */
188
189 /* input:
190 sf->name is optional.
191 sf->w, sf->h, sf->bpp are mandatory
192 sf->type and sf->flags are mandatory.
193 output:
194 sf->obj = surface object.
195 sf->locks = 0
196 */
197 bool ddgr_surf_Create(ddgr_surface *sf);
198 void ddgr_surf_Destroy(ddgr_surface *sf);
199
200 /* retrieves a pointer to surface memory. allowed to lock one surface multiple times.
201 ptr is the returned pointer to surface memory. used to unlock surface also
202 rowsize is the size in bytes of one row of memory.
203 */
204 bool ddgr_surf_Lock(ddgr_surface *sf, void **ptr, int *rowsize);
205 bool ddgr_surf_Unlock(ddgr_surface *sf, void *ptr);
206
207 // attaches an OS handle to a surface
208 void ddgr_surf_AttachHandle(ddgr_surface *sf, unsigned handle);
209
210 /* initializes a video screen from the given input surface which specifies the dimensions
211 of the screen.
212 sf->name is optional
213 sf->w, sf->h are mandatory
214 sf->bpp is recommended. if set to BPP_DEFAULT, it uses the current display bit depth
215 sf->type = SURFTYPE_VIDEOSCREEN
216 sf->flags = 0 or SURFFLAG_BACKBUFFER. surfaces with backbuffers allow rendering to
217 them and display via flip. monopage surfaces don't have this luxury.
218 */
219 bool ddgr_surf_InitVideo(ddgr_surface *sf);
220
221 /* close video reverses the operation of init video for that surface. the display should stay
222 the same, but no more operations may occur to that surface through this library.
223 */
224 void ddgr_surf_CloseVideo(ddgr_surface *sf);
225
226 /* flips the buffers in a surface. really only useful for video screens
227 */
228 bool ddgr_surf_FlipVideo(ddgr_surface *sf);
229
230 /* graphic primatives
231 */
232 void ddgr_surf_Clear(ddgr_surface *dsf, ddgr_color col, int l, int t, int w, int h);
233 bool ddgr_surf_Blt(ddgr_surface *dsf, int dx, int dy, ddgr_surface *ssf, int sx, int sy, int sw, int sh);
234
235 /*
236 8-bit palette surface structures
237 */
238 struct ddgr_rgb {
239 uint8_t r, g, b; // RGB triplet
240 uint8_t x; // reserved...
241 };
242
243 struct ddgr_palette {
244 void *obj; // internal object
245 ddgr_rgb rgb[256]; // rgb values for palette.
246 };
247
248 // attaches a palette to an 8-bit surface only.
249 bool ddgr_surf_AttachPalette(ddgr_surface *surf, ddgr_palette *pal);
250
251 // grabs a palette.
252 bool ddgr_surf_GetPalette(ddgr_surface *surf, ddgr_palette *pal);
253
254 // creates and destroys palette objects.
255 bool ddgr_8bit_CreatePalette(ddgr_palette *pal);
256 bool ddgr_8bit_DestroyPalette(ddgr_palette *pal);
257
258 // loads a palette with specified entriyes
259 bool ddgr_8bit_LoadPalette(ddgr_palette *pal, int start, int count);
260
261 // returns an index into the palette
262 int ddgr_8bit_FindClosestColor(ddgr_palette *pal, ddgr_color col);
263
264 #endif