source: golgotha/src/i4/video/win32/dx5_util.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.7 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef DX5_UTIL_HH
10#define DX5_UTIL_HH
11
12
13
14
15#include <ddraw.h>
16#include <d3d.h>
17#include "image/image.hh"
18#include "palette/pal.hh"
19#include "threads/threads.hh"
20
21enum dx5_surface_type
22{
23  DX5_SURFACE,                          // used only for Blt's
24  DX5_TEXTURE,
25  DX5_PAGE_FLIPPED_PRIMARY_SURFACE,    // will grab backbuffer surface
26  DX5_BACKBUFFERED_PRIMARY_SURFACE     // will grab backbuffer surface
27} ;
28
29
30enum
31{
32  DX5_VRAM              = 1,
33  DX5_SYSTEM_RAM        = 2,
34  DX5_RENDERING_SURFACE = 4,
35  DX5_CLEAR
36};
37
38struct dx5_mode
39{
40  DDSURFACEDESC desc;
41  dx5_mode     *next;
42  dx5_mode(dx5_mode *next) : next(next) {}
43};
44
45struct dx5_driver
46{
47  LPGUID lpGuid;
48  char   DriverName[128];
49  char   DeviceDesc[128];
50  dx5_driver *next;
51  dx5_driver(dx5_driver *next) : next(next) {}
52};
53
54struct dx5_d3d_info
55{
56  LPGUID lpGuid;
57  LPSTR  lpDeviceName;
58  D3DDEVICEDESC hw_desc,sw_desc;
59};
60
61
62
63
64class dx5_common_class
65{
66
67public:
68  static IDirectDraw2          *ddraw;
69  static IDirectDrawSurface3   *primary_surface, *back_surface, *front_surface;
70  static DDPIXELFORMAT          dd_fmt_565, dd_fmt_1555;
71  static i4_pixel_format        i4_fmt_565, i4_fmt_1555;
72
73  dx5_common_class();
74
75  IDirectDrawSurface3 *create_surface(dx5_surface_type type,
76                                      int width=0, int height=0, // not need for primary
77                                      int flags=0,
78                                      DDPIXELFORMAT *format=0); // format not need for primary
79
80
81  i4_bool get_surface_description(IDirectDrawSurface3 *surface, DDSURFACEDESC &surface_desc)
82  {
83    memset(&surface_desc,0,sizeof(DDSURFACEDESC));
84    surface_desc.dwSize = sizeof(DDSURFACEDESC);
85    return (i4_bool)(surface->GetSurfaceDesc(&surface_desc)==DD_OK);
86  }
87
88  i4_bool get_desc(IDirectDrawSurface3 *surface, DDSURFACEDESC &surface_desc)
89  {
90    memset(&surface_desc,0,sizeof(DDSURFACEDESC));
91    surface_desc.dwSize = sizeof(DDSURFACEDESC);
92    return (i4_bool)(surface->GetSurfaceDesc(&surface_desc)==DD_OK);
93  }
94
95
96  dx5_d3d_info *get_driver_hardware_info(IDirectDraw2 *dd);
97
98  dx5_mode *get_mode_list(IDirectDraw2 *dd);
99  void free_mode_list(dx5_mode *list);
100
101  dx5_driver *get_driver_list();
102  void free_driver_list(dx5_driver *list);
103  IDirectDraw2 *initialize_driver(dx5_driver *driver);
104
105  IDirectDrawSurface3 *get_surface(i4_image_class *im);
106  i4_image_class *create_image(int w, int h, w32 surface_flags);
107
108  void cleanup();
109};
110
111
112class i4_dx5_image_class : public i4_image_class
113{
114public:
115  IDirectDrawSurface3 *surface;
116  i4_dx5_image_class(w16 w, w16 h, w32 surface_flags=DX5_SYSTEM_RAM);
117  ~i4_dx5_image_class()
118  {
119    if (surface)
120    {
121      surface->PageUnlock(0);
122      surface->Release();
123    }
124  }
125
126  w16 *paddr(int x, int y) { return (w16 *)(((w8 *)data)+y*bpl) + x; }
127  i4_color get_pixel(i4_coord x, i4_coord y)
128  {
129    return i4_pal_man.convert_to_32(*paddr(x,y), pal);
130  }
131 
132  void put_pixel(i4_coord x, i4_coord y, w32 color)
133  {
134    w16 *addr=paddr(x,y);
135    *addr=i4_pal_man.convert_32_to(color, &pal->source); 
136  }
137
138
139
140  void lock();
141  void unlock();
142};
143
144
145extern dx5_common_class dx5_common;
146
147
148#endif
Note: See TracBrowser for help on using the repository browser.