1 /* |
|
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 #ifndef D3DUTILS_H |
|
27 #define D3DUTILS_H |
|
28 |
|
29 #include "D3DContext.h" |
|
30 |
|
31 // - Types and macros used in SelectDeviceGUID ----------------------- |
|
32 // Indexes for the rasterizers: |
|
33 // TNL, HAL, REF, RGB |
|
34 #define TNL_IDX (0) |
|
35 #define HAL_IDX (1) |
|
36 #define REF_IDX (2) |
|
37 #define RGB_IDX (3) |
|
38 #define DEV_IDX_MAX (RGB_IDX+1) |
|
39 |
|
40 typedef struct { |
|
41 const GUID *pGUIDs[4]; |
|
42 } DEVICES_INFO; |
|
43 |
|
44 // - Utility funcions for dealing with pixel formats ---------------- |
|
45 const GUID * |
|
46 D3DUtils_SelectDeviceGUID(IDirect3D7 *d3dObject); |
|
47 |
|
48 HRESULT |
|
49 D3DUtils_FindDepthBufferFormat(IDirect3D7 *d3dObject, |
|
50 int preferredDepth, |
|
51 DDPIXELFORMAT* pddpf, |
|
52 const GUID *pDeviceGUID); |
|
53 HRESULT |
|
54 D3DUtils_FindMaskTileTextureFormat(IDirect3DDevice7 *d3dDevice, |
|
55 DDPIXELFORMAT* pddpf); |
|
56 void |
|
57 D3DUtils_SetupTextureFormats(IDirect3DDevice7 *d3dDevice, |
|
58 D3DTextureTable &table); |
|
59 |
|
60 // - Utility funcions for working with matricies --------------------- |
|
61 void |
|
62 D3DUtils_SetIdentityMatrix(D3DMATRIX *m, BOOL adjust = TRUE); |
|
63 |
|
64 void |
|
65 D3DUtils_SetOrthoMatrixOffCenterLH(D3DMATRIX *m, |
|
66 float width, float height); |
|
67 DDrawSurface * |
|
68 D3DUtils_CreatePlainSurface(JNIEnv *env, DDraw *ddObject, |
|
69 D3DContext *d3dContext, |
|
70 int w, int h); |
|
71 |
|
72 DDrawSurface * |
|
73 D3DUtils_CreateTexture(JNIEnv *env, DDraw *ddObject, |
|
74 D3DContext *d3dContext, |
|
75 int transparency, |
|
76 int w, int h); |
|
77 |
|
78 HRESULT |
|
79 D3DUtils_UploadIntImageToXRGBTexture(DDrawSurface *lpTexture, |
|
80 int *pSrc, int width, int height); |
|
81 |
|
82 // - Utility functions for checking various capabilities of the device |
|
83 |
|
84 HRESULT |
|
85 D3DUtils_CheckD3DCaps(LPD3DDEVICEDESC7 lpDesc7); |
|
86 |
|
87 HRESULT |
|
88 D3DUtils_CheckDepthCaps(LPD3DDEVICEDESC7 lpDesc7); |
|
89 |
|
90 HRESULT |
|
91 D3DUtils_CheckTextureCaps(LPD3DDEVICEDESC7 lpDesc7); |
|
92 |
|
93 HRESULT |
|
94 D3DUtils_CheckDeviceCaps(LPD3DDEVICEDESC7 lpDesc7); |
|
95 |
|
96 // - Utility macros error handling of d3d operations ----------------- |
|
97 |
|
98 /* #define NO_D3D_CHECKING */ |
|
99 |
|
100 #ifdef NO_D3D_CHECKING |
|
101 |
|
102 #define D3DU_PRIM_LOOP_BEGIN(RES, DST_WSDO) |
|
103 #define D3DU_PRIM2_LOOP_BEGIN(RES, SRC_WSDO, DST_WSDO) |
|
104 #define D3DU_PRIM_LOOP_END(ENV, RES, DST_WSDO, PRIM) |
|
105 #define D3DU_PRIM2_LOOP_END(ENV, RES, SRC_WSDO, DST_WSDO, PRIM) |
|
106 |
|
107 #else /* NO_D3D_CHECKING */ |
|
108 |
|
109 #ifndef MAX_BUSY_ATTEMPTS |
|
110 #define MAX_BUSY_ATTEMPTS 50 // Arbitrary number of times to attempt |
|
111 #endif |
|
112 |
|
113 |
|
114 #define D3DU_PRIM_LOOP_BEGIN(RES, DST_WSDO) \ |
|
115 do { \ |
|
116 int attempts = 0; \ |
|
117 while (attempts++ < MAX_BUSY_ATTEMPTS) { \ |
|
118 if (FAILED((DST_WSDO)->lpSurface->IsLost())) { \ |
|
119 RES = DDERR_SURFACELOST; \ |
|
120 } else { |
|
121 |
|
122 #define D3DU_PRIM2_LOOP_BEGIN(RES, SRC_WSDO, DST_WSDO) \ |
|
123 do { \ |
|
124 int attempts = 0; \ |
|
125 while (attempts++ < MAX_BUSY_ATTEMPTS) { \ |
|
126 if (FAILED((DST_WSDO)->lpSurface->IsLost()) || \ |
|
127 FAILED((SRC_WSDO)->lpSurface->IsLost())) \ |
|
128 { \ |
|
129 RES = DDERR_SURFACELOST; \ |
|
130 } else { |
|
131 |
|
132 #define D3DU_PRIM_LOOP_END(ENV, RES, DST_WSDO, PRIM) \ |
|
133 } \ |
|
134 if (SUCCEEDED(RES)) { \ |
|
135 break; \ |
|
136 } else if (RES == DDERR_SURFACEBUSY || RES == DDERR_WASSTILLDRAWING) { \ |
|
137 J2dTraceLn(J2D_TRACE_VERBOSE, #PRIM ## ": surface is busy."); \ |
|
138 continue; \ |
|
139 } else if (RES == DDERR_SURFACELOST) { \ |
|
140 J2dTraceLn(J2D_TRACE_INFO, #PRIM ## ": dest surface lost."); \ |
|
141 DST_WSDO->RestoreSurface(ENV, DST_WSDO); \ |
|
142 break; \ |
|
143 } else { \ |
|
144 DebugPrintDirectDrawError(RES, #PRIM); \ |
|
145 } \ |
|
146 } \ |
|
147 } while (0) |
|
148 |
|
149 #define D3DU_PRIM2_LOOP_END(ENV, RES, SRC_WSDO, DST_WSDO, PRIM) \ |
|
150 } \ |
|
151 if (SUCCEEDED(RES)) { \ |
|
152 break; \ |
|
153 } else if (RES == DDERR_SURFACEBUSY || RES == DDERR_WASSTILLDRAWING) { \ |
|
154 J2dTraceLn(J2D_TRACE_VERBOSE, #PRIM ## ": surface is busy."); \ |
|
155 continue; \ |
|
156 } else if (RES == DDERR_SURFACELOST) { \ |
|
157 if (FAILED((DST_WSDO)->lpSurface->IsLost())) { \ |
|
158 J2dTraceLn(J2D_TRACE_INFO, #PRIM ## ": dst surface lost."); \ |
|
159 (DST_WSDO)->RestoreSurface(ENV, (DST_WSDO)); \ |
|
160 } \ |
|
161 if (FAILED((SRC_WSDO)->lpSurface->IsLost())) { \ |
|
162 J2dTraceLn(J2D_TRACE_INFO, #PRIM ## ": src surface lost."); \ |
|
163 (SRC_WSDO)->RestoreSurface(ENV, (SRC_WSDO)); \ |
|
164 } \ |
|
165 break; \ |
|
166 } else { \ |
|
167 DebugPrintDirectDrawError(RES, #PRIM); \ |
|
168 } \ |
|
169 } \ |
|
170 } while (0) |
|
171 |
|
172 #endif /* NO_D3D_CHECKING */ |
|
173 |
|
174 // - Utility macros for initializing vertex structures --------------- |
|
175 |
|
176 #define D3D_EXEC_PRIM_LOOP(ENV, RES, DST_WSDO, PRIM) \ |
|
177 D3DU_PRIM_LOOP_BEGIN(RES, DST_WSDO); \ |
|
178 RES = (PRIM); \ |
|
179 D3DU_PRIM_LOOP_END(ENV, RES, DST_WSDO, PRIM); |
|
180 |
|
181 #define D3DU_INIT_VERTEX_PENT_XY(VQUAD, X1, Y1, X2, Y2) \ |
|
182 do { \ |
|
183 D3DU_INIT_VERTEX_QUAD_XY(VQUAD, X1, Y1, X2, Y2); \ |
|
184 (VQUAD)[4].x = (X1); (VQUAD)[4].y = (Y1); \ |
|
185 } while (0) |
|
186 |
|
187 #define D3DU_INIT_VERTEX_PENT_COLOR(VQUAD, VCOLOR) \ |
|
188 do { \ |
|
189 D3DU_INIT_VERTEX_QUAD_COLOR(VQUAD, VCOLOR); \ |
|
190 (VQUAD)[4].color = (VCOLOR); \ |
|
191 } while (0) |
|
192 |
|
193 #define D3DU_INIT_VERTEX_QUAD_XY(VQUAD, X1, Y1, X2, Y2) \ |
|
194 do { \ |
|
195 (VQUAD)[0].x = (X1); (VQUAD)[0].y = (Y1); \ |
|
196 (VQUAD)[1].x = (X2); (VQUAD)[1].y = (Y1); \ |
|
197 (VQUAD)[2].x = (X2); (VQUAD)[2].y = (Y2); \ |
|
198 (VQUAD)[3].x = (X1); (VQUAD)[3].y = (Y2); \ |
|
199 } while (0) |
|
200 |
|
201 #define D3DU_INIT_VERTEX_QUAD_XYZ(VQUAD, X1, Y1, X2, Y2, Z) \ |
|
202 do { \ |
|
203 D3DU_INIT_VERTEX_QUAD_XY(VQUAD, X1, Y1, X2, Y2); \ |
|
204 (VQUAD)[0].z = (Z); \ |
|
205 (VQUAD)[1].z = (Z); \ |
|
206 (VQUAD)[2].z = (Z); \ |
|
207 (VQUAD)[3].z = (Z); \ |
|
208 } while (0) |
|
209 |
|
210 #define D3DU_INIT_VERTEX_QUAD_COLOR(VQUAD, VCOLOR) \ |
|
211 do { \ |
|
212 (VQUAD)[0].color = (VCOLOR); \ |
|
213 (VQUAD)[1].color = (VCOLOR); \ |
|
214 (VQUAD)[2].color = (VCOLOR); \ |
|
215 (VQUAD)[3].color = (VCOLOR); \ |
|
216 } while (0) |
|
217 |
|
218 #define D3DU_INIT_VERTEX_QUAD_UV(VQUAD, TU1, TV1, TU2, TV2) \ |
|
219 do { \ |
|
220 (VQUAD)[0].tu = (TU1); (VQUAD)[0].tv = (TV1); \ |
|
221 (VQUAD)[1].tu = (TU2); (VQUAD)[1].tv = (TV1); \ |
|
222 (VQUAD)[2].tu = (TU2); (VQUAD)[2].tv = (TV2); \ |
|
223 (VQUAD)[3].tu = (TU1); (VQUAD)[3].tv = (TV2); \ |
|
224 } while (0) |
|
225 |
|
226 #define D3DU_INIT_VERTEX_QUAD_XYUV(VQUAD, X1, Y1, X2, Y2, TU1, TV1, TU2, TV2) \ |
|
227 do { \ |
|
228 D3DU_INIT_VERTEX_QUAD_XY(VQUAD, X1, Y1, X2, Y2); \ |
|
229 D3DU_INIT_VERTEX_QUAD_UV(VQUAD, TU1, TV1, TU2, TV2); \ |
|
230 } while (0) |
|
231 |
|
232 #define D3DU_INIT_VERTEX_QUAD(VQUAD, X1, Y1, X2, Y2, VCOLOR, TU1, TV1, TU2, TV2) \ |
|
233 do { \ |
|
234 D3DU_INIT_VERTEX_QUAD_XYUV(VQUAD, X1, Y1, X2, Y2, TU1, TV1, TU2, TV2); \ |
|
235 D3DU_INIT_VERTEX_QUAD_COLOR(VQUAD, VCOLOR); \ |
|
236 } while (0) |
|
237 |
|
238 #define D3DU_INIT_VERTEX_6(VQUAD, X1, Y1, X2, Y2, VCOLOR, TU1, TV1, TU2, TV2) \ |
|
239 do { \ |
|
240 D3DU_INIT_VERTEX_XY_6(VHEX, X1, Y1, X2, Y2); \ |
|
241 D3DU_INIT_VERTEX_UV_6(VHEX, TU1, TV1, TU2, TV2); \ |
|
242 D3DU_INIT_VERTEX_COLOR_6(VHEX, VCOLOR); \ |
|
243 } while (0) |
|
244 |
|
245 #define D3DU_INIT_VERTEX_UV_6(VHEX, TU1, TV1, TU2, TV2) \ |
|
246 do { \ |
|
247 (VHEX)[0].tu = TU1; (VHEX)[0].tv = TV1; \ |
|
248 (VHEX)[1].tu = TU2; (VHEX)[1].tv = TV1; \ |
|
249 (VHEX)[2].tu = TU1; (VHEX)[2].tv = TV2; \ |
|
250 (VHEX)[3].tu = TU1; (VHEX)[3].tv = TV2; \ |
|
251 (VHEX)[4].tu = TU2; (VHEX)[4].tv = TV1; \ |
|
252 (VHEX)[5].tu = TU2; (VHEX)[5].tv = TV2; \ |
|
253 } while (0) |
|
254 |
|
255 #define D3DU_INIT_VERTEX_COLOR_6(VHEX, VCOLOR) \ |
|
256 do { \ |
|
257 (VHEX)[0].color = VCOLOR; \ |
|
258 (VHEX)[1].color = VCOLOR; \ |
|
259 (VHEX)[2].color = VCOLOR; \ |
|
260 (VHEX)[3].color = VCOLOR; \ |
|
261 (VHEX)[4].color = VCOLOR; \ |
|
262 (VHEX)[5].color = VCOLOR; \ |
|
263 } while (0) |
|
264 |
|
265 #define D3DU_INIT_VERTEX_XY_6(VHEX, X1, Y1, X2, Y2) \ |
|
266 do { \ |
|
267 (VHEX)[0].x = X1; (VHEX)[0].y = Y1; \ |
|
268 (VHEX)[1].x = X2; (VHEX)[1].y = Y1; \ |
|
269 (VHEX)[2].x = X1; (VHEX)[2].y = Y2; \ |
|
270 (VHEX)[3].x = X1; (VHEX)[3].y = Y2; \ |
|
271 (VHEX)[4].x = X2; (VHEX)[4].y = Y1; \ |
|
272 (VHEX)[5].x = X2; (VHEX)[5].y = Y2; \ |
|
273 } while (0) |
|
274 |
|
275 #define D3DU_INIT_VERTEX_XYZ_6(VHEX, X1, Y1, X2, Y2, Z) \ |
|
276 do { \ |
|
277 D3DU_INIT_VERTEX_XY_6(VHEX, X1, Y1, X2, Y2); \ |
|
278 (VHEX)[0].z = (Z); \ |
|
279 (VHEX)[1].z = (Z); \ |
|
280 (VHEX)[2].z = (Z); \ |
|
281 (VHEX)[3].z = (Z); \ |
|
282 (VHEX)[4].z = (Z); \ |
|
283 (VHEX)[5].z = (Z); \ |
|
284 } while (0) |
|
285 |
|
286 |
|
287 #endif // D3DUTILS_H |
|