Quake II RTX doxygen  1.0 dev
swimp.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 
19 /*
20 RW_IMP.C
21 
22 This file contains ALL Win32 specific stuff having to do with the
23 software refresh. When a port is being made the following functions
24 must be implemented by the port:
25 
26 SWimp_EndFrame
27 SWimp_Init
28 SWimp_SetPalette
29 SWimp_Shutdown
30 */
31 
32 #include "client.h"
33 
34 typedef struct {
35  HDC dibdc; // DC compatible with DIB section
36  HBITMAP dibsect; // DIB section
37  byte *pixels; // DIB base pointer, NOT used directly for rendering!
38  HGDIOBJ prevobj;
39 } sww_t;
40 
41 static sww_t sww;
42 
43 /*
44 SWimp_Shutdown
45 
46 System specific graphics subsystem shutdown routine.
47 Destroys DIB surfaces as appropriate.
48 */
49 void VID_Shutdown(void)
50 {
51  if (sww.dibdc) {
52  SelectObject(sww.dibdc, sww.prevobj);
53  DeleteDC(sww.dibdc);
54  }
55 
56  if (sww.dibsect) {
57  DeleteObject(sww.dibsect);
58  }
59 
60  memset(&sww, 0, sizeof(sww));
61 
62  Win_Shutdown();
63 }
64 
66 {
67  BITMAPINFO info;
68 
69  if (!sww.dibdc) {
70  return;
71  }
72 
73  // destroy previous DIB section
74  if (sww.dibsect) {
75  SelectObject(sww.dibdc, sww.prevobj);
76  DeleteObject(sww.dibsect);
77  }
78 
79  // fill in the BITMAPINFO struct
80  memset(&info, 0, sizeof(info));
81 
82  info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
83  info.bmiHeader.biWidth = win.rc.width;
84  info.bmiHeader.biHeight = win.rc.height;
85  info.bmiHeader.biPlanes = 1;
86  info.bmiHeader.biCompression = BI_RGB;
87  info.bmiHeader.biBitCount = 32;
88 
89  // create the DIB section
90  sww.dibsect = CreateDIBSection(win.dc,
91  &info,
92  DIB_RGB_COLORS,
93  (void **)&sww.pixels,
94  NULL,
95  0);
96 
97  if (!sww.dibsect) {
98  Com_Error(ERR_FATAL, "DIB_Init: CreateDIBSection failed");
99  }
100 
101  if (info.bmiHeader.biHeight > 0) {
102  // bottom up
103  win.buffer = sww.pixels + (win.rc.height - 1) * win.rc.width * 4;
104  win.pitch = -win.rc.width * 4;
105  } else {
106  // top down
107  win.buffer = sww.pixels;
108  win.pitch = win.rc.width * 4;
109  }
110 
111  // clear the DIB memory buffer
112  memset(sww.pixels, 0, win.rc.width * win.rc.height * 4);
113 
114  sww.prevobj = SelectObject(sww.dibdc, sww.dibsect);
115  if (!sww.prevobj) {
116  Com_Error(ERR_FATAL, "DIB_Init: SelectObject failed\n");
117  }
118 }
119 
120 
121 /*
122 SWimp_Init
123 
124 This routine is responsible for initializing the implementation
125 specific stuff in a software rendering subsystem.
126 */
127 qboolean VID_Init(void)
128 {
129  // create the window
130  Win_Init();
131 
132  // set display mode
133  Win_SetMode();
134 
135  // create logical DC
136  sww.dibdc = CreateCompatibleDC(win.dc);
137  if (!sww.dibdc) {
138  Com_EPrintf("DIB_Init: CreateCompatibleDC failed with error %lu\n", GetLastError());
139  Win_Shutdown();
140  return qfalse;
141  }
142 
143  // call SWimp_ModeChanged and friends
144  Win_ModeChanged();
145  return qtrue;
146 }
147 
148 void VID_VideoWait(void)
149 {
150 }
151 
152 qboolean VID_VideoSync(void)
153 {
154  return qtrue;
155 }
156 
157 void VID_BeginFrame(void)
158 {
159 }
160 
161 /*
162 SWimp_EndFrame
163 
164 This does an implementation specific copy from the backbuffer to the
165 front buffer. In the Win32 case it uses BitBlt if we're using DIB sections/GDI.
166 */
167 void VID_EndFrame(void)
168 {
169  BitBlt(win.dc, 0, 0, win.rc.width, win.rc.height, sww.dibdc, 0, 0, SRCCOPY);
170 }
171 
Win_Init
void Win_Init(void)
Definition: client.c:1014
Win_ModeChanged
void Win_ModeChanged(void)
Definition: client.c:123
sww_t::prevobj
HGDIOBJ prevobj
Definition: swimp.c:38
VID_VideoSync
qboolean VID_VideoSync(void)
Definition: swimp.c:152
VID_Init
qboolean VID_Init(void)
Definition: swimp.c:127
sww_t
Definition: swimp.c:34
VID_EndFrame
void VID_EndFrame(void)
Definition: swimp.c:167
Win_SetMode
void Win_SetMode(void)
Definition: client.c:358
VID_Shutdown
void VID_Shutdown(void)
Definition: swimp.c:49
SWimp_ModeChanged
void SWimp_ModeChanged(void)
Definition: swimp.c:65
sww_t::pixels
byte * pixels
Definition: swimp.c:37
sww_t::dibdc
HDC dibdc
Definition: swimp.c:35
VID_VideoWait
void VID_VideoWait(void)
Definition: swimp.c:148
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258
client.h
VID_BeginFrame
void VID_BeginFrame(void)
Definition: swimp.c:157
Win_Shutdown
void Win_Shutdown(void)
Definition: client.c:1091
sww_t::dibsect
HBITMAP dibsect
Definition: swimp.c:36
win
win_state_t win
Definition: client.c:33
sww
static sww_t sww
Definition: swimp.c:41