Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) |
3 |
* for some codes : |
4 |
* Copyright (C) 2010-2015 The RetroArch team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
* |
20 |
*/ |
21 |
|
22 |
#include "d3d9.h" |
23 |
#include "video/gfx_thread.h" |
24 |
#include "info.h" |
25 |
#include "gui.h" |
26 |
#include "conf.h" |
27 |
#include "ppu.h" |
28 |
#include "overscan.h" |
29 |
|
30 |
#define _SCR_ROWS_BRD\ |
31 |
((float)(SCR_ROWS - (overscan.borders->left + overscan.borders->right)) * gfx.pixel_aspect_ratio) |
32 |
#define _SCR_LINES_BRD\ |
33 |
(float)(SCR_LINES - (overscan.borders->up + overscan.borders->down)) |
34 |
#define _SCR_ROWS_NOBRD\ |
35 |
((float)SCR_ROWS * gfx.pixel_aspect_ratio) |
36 |
#define _SCR_LINES_NOBRD\ |
37 |
(float)SCR_LINES |
38 |
|
39 |
static void d3d9_shader_cg_error_handler(void); |
40 |
static BYTE d3d9_device_create(UINT width, UINT height); |
41 |
static void d3d9_context_delete(void); |
42 |
static BYTE d3d9_texture_create(_texture *texture, UINT index); |
43 |
static BYTE d3d9_texture_simple_create(_texture_simple *texture, UINT w, UINT h, BOOL text); |
44 |
static BYTE d3d9_texture_lut_create(_lut *lut, UINT index); |
45 |
static void d3d9_surface_clean(LPDIRECT3DSURFACE9 *surface, UINT width, UINT height); |
46 |
static BYTE d3d9_shader_init(UINT pass, _shader *shd, const uTCHAR *path, const char *code); |
47 |
static void d3d9_shader_delete(_shader *shd); |
48 |
static void d3d9_shader_uniform_ctrl(CGparameter *dst, CGparameter *param, const char *semantic); |
49 |
static void d3d9_shader_uni_texture_clear(_shader_uniforms_tex *sut); |
50 |
static void d3d9_shader_uni_texture(_shader_uniforms_tex *sut, _shader_prg_cg *prg, char *fmt, ...); |
51 |
static CGparameter d3d9_cg_find_param(CGparameter prm, const char *name); |
52 |
static BYTE d3d9_vertex_declaration_create(_shader *shd); |
53 |
static void d3d9_vertex_buffer_set(_shader *shd, _viewport *vp, _texture_rect *prev); |
54 |
INLINE static void d3d9_viewport_set(DWORD x, DWORD y, DWORD w, DWORD h); |
55 |
INLINE D3DTEXTUREFILTERTYPE d3d9_shader_filter(UINT type); |
56 |
INLINE static void d3d9_shader_params_text_set(_shader *shd); |
57 |
INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount); |
58 |
|
59 |
BYTE d3d9_init(void) { |
60 |
memset(&d3d9, 0x00, sizeof(d3d9)); |
61 |
|
62 |
if ((d3d9.d3d = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) { |
63 |
MessageBox(NULL, "Unable to create d3d object", "Error!", MB_ICONEXCLAMATION | MB_OK); |
64 |
return (EXIT_ERROR); |
65 |
} |
66 |
|
67 |
// mi passo in rassegna tutti gli adapter presenti sul sistema |
68 |
d3d9.adapters_on_system = IDirect3D9_GetAdapterCount(d3d9.d3d); |
69 |
|
70 |
if (!(d3d9.array = malloc(d3d9.adapters_on_system * sizeof(_d3d9_adapter)))) { |
71 |
MessageBox(NULL, "Unable to create devices array", "Error!", MB_ICONEXCLAMATION | MB_OK); |
72 |
return (EXIT_ERROR); |
73 |
} |
74 |
|
75 |
{ |
76 |
unsigned int adapt; |
77 |
|
78 |
#define dev_error(s) fprintf(stderr, "D3D9 adapter %d : "s, dev->id) |
79 |
#define dev_info(s) printf("D3D9 adapter %d : "s, dev->id) |
80 |
#define dev_info_args(s, ...) printf("D3D9 adapter %d : "s, dev->id, __VA_ARGS__) |
81 |
|
82 |
for (adapt = 0; adapt < d3d9.adapters_on_system; adapt++) { |
83 |
_d3d9_adapter *dev = D3D9_ADAPTER(d3d9.adapters_in_use); |
84 |
D3DADAPTER_IDENTIFIER9 info; |
85 |
D3DCAPS9 d3dcaps; |
86 |
|
87 |
memset(dev, 0x00, sizeof(_d3d9_adapter)); |
88 |
|
89 |
dev->id = adapt; |
90 |
|
91 |
if (IDirect3D9_GetAdapterIdentifier(d3d9.d3d, dev->id, 0, &info)!= D3D_OK) { |
92 |
dev_error("unable to get adapter display info\n"); |
93 |
continue; |
94 |
} |
95 |
|
96 |
dev_info_args("%s\n", info.Description); |
97 |
|
98 |
if (IDirect3D9_GetAdapterDisplayMode(d3d9.d3d, dev->id, &dev->display_mode) != D3D_OK) { |
99 |
dev_error("unable to get adapter display mode\n"); |
100 |
continue; |
101 |
} |
102 |
|
103 |
if ((dev->display_mode.Format == D3DFMT_X8R8G8B8) || |
104 |
(dev->display_mode.Format == D3DFMT_A8R8G8B8)) { |
105 |
dev->bit_per_pixel = 32; |
106 |
} |
107 |
if (dev->bit_per_pixel < 32) { |
108 |
dev_error("video mode < 32 bits are not supported\n"); |
109 |
continue; |
110 |
} |
111 |
|
112 |
// Check for hardware T&L |
113 |
if (IDirect3D9_GetDeviceCaps(d3d9.d3d, dev->id, D3DDEVTYPE_HAL, &d3dcaps) != D3D_OK) { |
114 |
dev_error("unable to get device caps\n"); |
115 |
continue; |
116 |
} |
117 |
|
118 |
if (d3dcaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) { |
119 |
dev->dynamic_texture = TRUE; |
120 |
} else { |
121 |
dev->dynamic_texture = FALSE; |
122 |
dev_info("don't support dynamic texture\n"); |
123 |
} |
124 |
|
125 |
if (d3dcaps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) { |
126 |
dev->texture_square_only = TRUE; |
127 |
dev_info("support only square texture\n"); |
128 |
} else { |
129 |
dev->texture_square_only = FALSE; |
130 |
} |
131 |
|
132 |
// Device can accelerate a memory copy from system memory to local video memory. |
133 |
// This cap guarantees that UpdateSurface and UpdateTexture calls will be hardware |
134 |
// accelerated. If this cap is absent, these calls will succeed but will be slower. |
135 |
if (!(d3dcaps.Caps3 & D3DCAPS3_COPY_TO_VIDMEM)) { |
136 |
dev_info("don't support accelerated texture update\n"); |
137 |
} |
138 |
|
139 |
if (d3dcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { |
140 |
dev->flags = D3DCREATE_HARDWARE_VERTEXPROCESSING; |
141 |
// se abilito il PURE DEVICE, non posso utilizzare il |
142 |
// IDirect3DDevice9_GetTransform quando uso le shaders. |
143 |
if (d3dcaps.DevCaps & D3DDEVCAPS_PUREDEVICE) { |
144 |
dev->flags |= D3DCREATE_PUREDEVICE; |
145 |
} |
146 |
} else { |
147 |
dev_info("don't support hardware accelaration\n"); |
148 |
dev->flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; |
149 |
} |
150 |
|
151 |
if (!(d3dcaps.MaxSimultaneousTextures > 1)) { //number of textures |
152 |
dev_info("single pass multitexturing not supported\n"); |
153 |
} else { |
154 |
dev_info_args("MaxSimultaneousTextures %ld\n", d3dcaps.MaxSimultaneousTextures); |
155 |
} |
156 |
|
157 |
dev->number_of_monitors = d3dcaps.NumberOfAdaptersInGroup; |
158 |
|
159 |
//if (dev->number_of_monitors > 1) { |
160 |
dev_info_args("MasterAdapterOrdinal %d\n", d3dcaps.MasterAdapterOrdinal); |
161 |
dev_info_args("AdapterOrdinalInGroup %d\n", d3dcaps.AdapterOrdinalInGroup); |
162 |
dev_info_args("NumberOfAdaptersInGroup %d\n", dev->number_of_monitors); |
163 |
//dev->flags |= D3DCREATE_ADAPTERGROUP_DEVICE; |
164 |
//} |
165 |
|
166 |
{ |
167 |
d3d9.adapter = dev; |
168 |
|
169 |
// per poter verificare se le shaders sono utilizzabili devo creare il dev d3d |
170 |
if (d3d9_device_create(1, 1) != EXIT_OK) { |
171 |
continue; |
172 |
} |
173 |
|
174 |
dev->hlsl_compliant = FALSE; |
175 |
|
176 |
if (d3dcaps.PixelShaderVersion < D3DPS_VERSION(2, 0) || |
177 |
(d3dcaps.VertexShaderVersion < D3DVS_VERSION(2, 0))) { |
178 |
dev_info("don't support shaders >= 2.0\n"); |
179 |
} else { |
180 |
dev->hlsl_compliant = TRUE; |
181 |
} |
182 |
|
183 |
if (dev->hlsl_compliant == FALSE) { |
184 |
dev_info("shaders are not supported\n"); |
185 |
} |
186 |
|
187 |
d3d9.adapter = NULL; |
188 |
} |
189 |
|
190 |
d3d9.adapters_in_use++; |
191 |
} |
192 |
|
193 |
#undef dev_error |
194 |
#undef dev_info |
195 |
#undef dev_info_args |
196 |
} |
197 |
|
198 |
if (d3d9.adapters_in_use == 0) { |
199 |
MessageBox(NULL, "Unable find usable adapter", "Error!", MB_ICONEXCLAMATION | MB_OK); |
200 |
return (EXIT_ERROR); |
201 |
} |
202 |
|
203 |
d3d9.adapter = D3D9_ADAPTER(0); |
204 |
if (d3d9.adapter->hlsl_compliant == FALSE) { |
205 |
MessageBox(NULL, "Adapter is not hlsl compliant", "Error!", MB_ICONEXCLAMATION | MB_OK); |
206 |
return (EXIT_ERROR); |
207 |
} |
208 |
|
209 |
gfx.bit_per_pixel = d3d9.adapter->bit_per_pixel; |
210 |
|
211 |
return (EXIT_OK); |
212 |
} |
213 |
BYTE d3d9_context_create(void) { |
214 |
D3DXMATRIX identity; |
215 |
WORD w, h; |
216 |
UINT i; |
217 |
|
218 |
d3d9_context_delete(); |
219 |
|
220 |
if (overscan.enabled && (!cfg->oscan_black_borders && !cfg->fullscreen)) { |
221 |
// visto che lavorero' con texture piu' grandi del video mode |
222 |
// setto un backbuffer piu' grande. |
223 |
w = gfx.w[VIDEO_MODE] * 2; |
224 |
h = gfx.h[VIDEO_MODE] * 2; |
225 |
} else { |
226 |
w = gfx.w[VIDEO_MODE]; |
227 |
h = gfx.h[VIDEO_MODE]; |
228 |
} |
229 |
|
230 |
if (d3d9_device_create(w, h) == EXIT_ERROR) { |
231 |
d3d9_context_delete(); |
232 |
return (EXIT_ERROR); |
233 |
} |
234 |
|
235 |
if ((d3d9.cgctx = cgCreateContext()) == NULL) { |
236 |
d3d9_context_delete(); |
237 |
return (EXIT_ERROR); |
238 |
} |
239 |
|
240 |
cgSetErrorCallback(d3d9_shader_cg_error_handler); |
241 |
|
242 |
cgD3D9SetDevice(d3d9.adapter->dev); |
243 |
|
244 |
w = gfx.w[PASS0]; |
245 |
h = gfx.h[PASS0]; |
246 |
|
247 |
D3DXMatrixIdentity(&identity); |
248 |
IDirect3DDevice9_SetTransform(d3d9.adapter->dev, D3DTS_WORLD, &identity); |
249 |
IDirect3DDevice9_SetTransform(d3d9.adapter->dev, D3DTS_VIEW, &identity); |
250 |
|
251 |
// screen |
252 |
d3d9_texture_simple_create(&d3d9.screen.tex[0], w, h, FALSE); |
253 |
|
254 |
// lut (devo farlo prima di elaborare le shaders) |
255 |
for (i = 0; i < shader_effect.luts; i++) { |
256 |
if (d3d9_texture_lut_create(&d3d9.lut[i], i) == EXIT_ERROR) { |
257 |
d3d9_context_delete(); |
258 |
return (EXIT_ERROR_SHADER); |
259 |
} |
260 |
} |
261 |
|
262 |
// devo precalcolarmi il viewport finale |
263 |
{ |
264 |
_viewport *vp = &gfx.vp; |
265 |
|
266 |
vp->x = 0; |
267 |
vp->y = 0; |
268 |
vp->w = gfx.w[VIDEO_MODE]; |
269 |
vp->h = gfx.h[VIDEO_MODE]; |
270 |
|
271 |
if (overscan.enabled && (!cfg->oscan_black_borders && !cfg->fullscreen)) { |
272 |
vp->x = (-overscan.borders->left * gfx.width_pixel) * gfx.pixel_aspect_ratio; |
273 |
vp->y = (-overscan.borders->up * cfg->scale); |
274 |
vp->w = gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio; |
275 |
vp->h = gfx.h[NO_OVERSCAN]; |
276 |
} |
277 |
|
278 |
// configuro l'aspect ratio del fullscreen |
279 |
if (cfg->fullscreen) { |
280 |
if (!cfg->stretch) { |
281 |
if (cfg->integer_scaling) { |
282 |
int mw = _SCR_ROWS_NOBRD; |
283 |
int mh = _SCR_LINES_NOBRD; |
284 |
int mul = gfx.w[VIDEO_MODE] > gfx.h[VIDEO_MODE] ? |
285 |
(gfx.h[VIDEO_MODE] - (gfx.h[VIDEO_MODE] % mh)) / mh : |
286 |
(gfx.w[VIDEO_MODE] - (gfx.w[VIDEO_MODE] % mw)) / mw; |
287 |
|
288 |
vp->w = mw * mul; |
289 |
vp->h = mh * mul; |
290 |
} else { |
291 |
float mw = _SCR_ROWS_NOBRD; |
292 |
float mh = _SCR_LINES_NOBRD; |
293 |
float mul = mw / mh ; |
294 |
|
295 |
if (gfx.w[VIDEO_MODE] > gfx.h[VIDEO_MODE]) { |
296 |
vp->w = (int)((float)gfx.h[VIDEO_MODE] * mul); |
297 |
} else { |
298 |
vp->h = (int)((float)gfx.w[VIDEO_MODE] / mul); |
299 |
} |
300 |
} |
301 |
vp->x = (gfx.w[VIDEO_MODE] - vp->w) >> 1; |
302 |
vp->y = (gfx.h[VIDEO_MODE] - vp->h) >> 1; |
303 |
} |
304 |
|
305 |
if (overscan.enabled && (cfg->oscan_black_borders_fscr == FALSE)) { |
306 |
float brd_l_x, brd_r_x, brd_u_y, brd_d_y; |
307 |
float ratio_x, ratio_y; |
308 |
|
309 |
ratio_x = (float)vp->w / _SCR_ROWS_NOBRD; |
310 |
ratio_y = (float)vp->h / _SCR_LINES_NOBRD; |
311 |
brd_l_x = (float)overscan.borders->left * ratio_x; |
312 |
brd_r_x = (float)overscan.borders->right * ratio_x; |
313 |
brd_u_y = (float)overscan.borders->up * ratio_y; |
314 |
brd_d_y = (float)overscan.borders->down * ratio_y; |
315 |
|
316 |
d3d9.viewp.left = brd_l_x; |
317 |
d3d9.viewp.top = brd_u_y; |
318 |
d3d9.viewp.right = gfx.w[VIDEO_MODE] - brd_r_x; |
319 |
d3d9.viewp.bottom = gfx.h[VIDEO_MODE] - brd_d_y; |
320 |
} else { |
321 |
d3d9.viewp.left = 0; |
322 |
d3d9.viewp.top = 0; |
323 |
d3d9.viewp.right = gfx.w[VIDEO_MODE]; |
324 |
d3d9.viewp.bottom = gfx.h[VIDEO_MODE]; |
325 |
} |
326 |
} else { |
327 |
d3d9.viewp.left = -vp->x; |
328 |
d3d9.viewp.top = -vp->y; |
329 |
d3d9.viewp.right = gfx.w[VIDEO_MODE] + d3d9.viewp.left; |
330 |
d3d9.viewp.bottom = gfx.h[VIDEO_MODE] + d3d9.viewp.top; |
331 |
} |
332 |
} |
333 |
|
334 |
// texture |
335 |
for (i = 0; i < shader_effect.pass; i++) { |
336 |
fprintf(stderr, "D3D9: Setting pass %d.\n", i); |
337 |
|
338 |
if (d3d9_texture_create(&d3d9.texture[i], i) == EXIT_ERROR) { |
339 |
d3d9_context_delete(); |
340 |
return (EXIT_ERROR); |
341 |
} |
342 |
|
343 |
if (d3d9_shader_init(i, &d3d9.texture[i].shader, shader_effect.sp[i].path, shader_effect.sp[i].code) == EXIT_ERROR) { |
344 |
d3d9_context_delete(); |
345 |
return (EXIT_ERROR_SHADER); |
346 |
} |
347 |
} |
348 |
|
349 |
// PREV (calcolo il numero di screen da utilizzare) |
350 |
// deve essere fatto dopo il d3d9_shader_init(). |
351 |
for (i = 0; i < shader_effect.pass; i++) { |
352 |
UINT a; |
353 |
|
354 |
for (a = 0; a < LENGTH(d3d9.texture[i].shader.uni.prev); a++) { |
355 |
if (d3d9.texture[i].shader.uni.prev[a].f.texture) { |
356 |
if (d3d9.screen.in_use < (a + 1)) { |
357 |
d3d9.screen.in_use = (a + 1); |
358 |
} |
359 |
} |
360 |
} |
361 |
} |
362 |
|
363 |
d3d9.screen.in_use++; |
364 |
|
365 |
// PREV |
366 |
for (i = 1; i < d3d9.screen.in_use; i++) { |
367 |
d3d9_texture_simple_create(&d3d9.screen.tex[i], w, h, FALSE); |
368 |
} |
369 |
|
370 |
// FEEDBACK |
371 |
if ((shader_effect.feedback_pass >= 0) && (shader_effect.feedback_pass < shader_effect.pass)) { |
372 |
d3d9.feedback.in_use = TRUE; |
373 |
|
374 |
if (d3d9_texture_create(&d3d9.feedback.tex, shader_effect.feedback_pass) == EXIT_ERROR) { |
375 |
d3d9_context_delete(); |
376 |
return (EXIT_ERROR); |
377 |
} |
378 |
} |
379 |
|
380 |
// testo |
381 |
{ |
382 |
int tw, th; |
383 |
|
384 |
// setto il necessario per il blending |
385 |
IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_BLENDOP, D3DBLENDOP_ADD); |
386 |
IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); |
387 |
IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); |
388 |
|
389 |
if (cfg->fullscreen) { |
390 |
float div = (float)gfx.w[VIDEO_MODE] / 1024.0f; |
391 |
|
392 |
if (div < 1.0f) { |
393 |
div = 1.0f; |
394 |
} |
395 |
|
396 |
tw = gfx.w[VIDEO_MODE] / div; |
397 |
th = gfx.h[VIDEO_MODE] / div; |
398 |
} else if (cfg->scale == 1) { |
399 |
tw = gfx.w[VIDEO_MODE]; |
400 |
th = gfx.h[VIDEO_MODE]; |
401 |
} else { |
402 |
tw = _SCR_ROWS_NOBRD * 2; |
403 |
th = _SCR_LINES_NOBRD * 2; |
404 |
} |
405 |
|
406 |
d3d9_texture_simple_create(&d3d9.text, tw, th, TRUE); |
407 |
|
408 |
text.w = d3d9.text.rect.w; |
409 |
text.h = d3d9.text.rect.h; |
410 |
|
411 |
gfx_text_reset(); |
412 |
|
413 |
fprintf(stderr, "D3D9: Setting text pass.\n"); |
414 |
|
415 |
if (d3d9_shader_init(0, &d3d9.text.shader, NULL, shader_code_blend()) == EXIT_ERROR) { |
416 |
d3d9_context_delete(); |
417 |
return (EXIT_ERROR); |
418 |
} |
419 |
} |
420 |
|
421 |
// setto tutto quello che mi serve per il rendering |
422 |
for (i = 0; i < shader_effect.pass; i++) { |
423 |
_texture *texture = &d3d9.texture[i]; |
424 |
_shader *shd = &texture->shader; |
425 |
_texture_rect *prev = NULL; |
426 |
|
427 |
if (i == 0) { |
428 |
prev = &d3d9.screen.tex[0].rect; |
429 |
} else { |
430 |
prev = &d3d9.texture[i - 1].rect; |
431 |
} |
432 |
|
433 |
shd->info.video_size.x = (FLOAT)prev->base.w; |
434 |
shd->info.video_size.y = (FLOAT)prev->base.h; |
435 |
shd->info.texture_size.x = prev->w, |
436 |
shd->info.texture_size.y = prev->h; |
437 |
shd->info.output_size.x = (FLOAT)texture->vp.w; |
438 |
shd->info.output_size.y = (FLOAT)texture->vp.h; |
439 |
|
440 |
d3d9_vertex_buffer_set(shd, &texture->vp, prev); |
441 |
} |
442 |
|
443 |
umemcpy(gfx.last_shader_file, cfg->shader_file, usizeof(gfx.last_shader_file)); |
444 |
|
445 |
return (EXIT_OK); |
446 |
} |
447 |
void d3d9_draw_scene(void) { |
448 |
const _texture_simple *scrtex = &d3d9.screen.tex[d3d9.screen.index]; |
449 |
LPDIRECT3DSURFACE9 back_buffer; |
450 |
UINT i; |
451 |
|
452 |
if (gui.start == FALSE) { |
453 |
return; |
454 |
} |
455 |
|
456 |
IDirect3DDevice9_GetRenderTarget(d3d9.adapter->dev, 0, &back_buffer); |
457 |
|
458 |
// texture |
459 |
for (i = 0; i < shader_effect.pass; i++) { |
460 |
const _texture *texture = &d3d9.texture[i]; |
461 |
const _shader_pass *sp = &shader_effect.sp[i]; |
462 |
D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(sp->linear); |
463 |
|
464 |
shader_effect.running_pass = i; |
465 |
|
466 |
if (i == shader_effect.last_pass) { |
467 |
IDirect3DDevice9_SetRenderTarget(d3d9.adapter->dev, 0, back_buffer); |
468 |
// pulisco l'intero schermo |
469 |
d3d9_viewport_set(0, 0, gfx.w[VIDEO_MODE], gfx.h[VIDEO_MODE]); |
470 |
} else { |
471 |
IDirect3DDevice9_SetRenderTarget(d3d9.adapter->dev, 0, texture->map0); |
472 |
// pulisco l'fbo |
473 |
d3d9_viewport_set(0, 0, texture->rect.w, texture->rect.h); |
474 |
} |
475 |
IDirect3DDevice9_Clear(d3d9.adapter->dev, 0, NULL, D3DCLEAR_TARGET, |
476 |
D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0); |
477 |
|
478 |
// ora setto il viewport corretto |
479 |
if (cfg->fullscreen) { |
480 |
d3d9_viewport_set(texture->vp.x, texture->vp.y, texture->vp.w, texture->vp.h); |
481 |
} else { |
482 |
d3d9_viewport_set(0, 0, texture->vp.w, texture->vp.h); |
483 |
} |
484 |
|
485 |
cgD3D9BindProgram(texture->shader.prg.f); |
486 |
cgD3D9BindProgram(texture->shader.prg.v); |
487 |
|
488 |
if (i == 0) { |
489 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 * )scrtex->data); |
490 |
} else { |
491 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 * )d3d9.texture[i - 1].data); |
492 |
} |
493 |
|
494 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, filter); |
495 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, filter); |
496 |
|
497 |
IDirect3DDevice9_SetVertexDeclaration(d3d9.adapter->dev, texture->shader.vd); |
498 |
|
499 |
d3d9_shader_param_set(texture, sp->frame_count_mod, ppu.frames); |
500 |
|
501 |
IDirect3DDevice9_BeginScene(d3d9.adapter->dev); |
502 |
IDirect3DDevice9_DrawPrimitive(d3d9.adapter->dev, D3DPT_TRIANGLESTRIP, 0, 2); |
503 |
IDirect3DDevice9_EndScene(d3d9.adapter->dev); |
504 |
} |
505 |
|
506 |
IDirect3DSurface9_Release(back_buffer); |
507 |
|
508 |
d3d9.screen.index = ((d3d9.screen.index + 1) % d3d9.screen.in_use); |
509 |
|
510 |
if (d3d9.feedback.in_use) { |
511 |
LPDIRECT3DTEXTURE9 data = d3d9.feedback.tex.data; |
512 |
LPDIRECT3DSURFACE9 map0 = d3d9.feedback.tex.map0; |
513 |
|
514 |
d3d9.feedback.tex.data = d3d9.texture[shader_effect.feedback_pass].data; |
515 |
d3d9.feedback.tex.map0 = d3d9.texture[shader_effect.feedback_pass].map0; |
516 |
d3d9.texture[shader_effect.feedback_pass].data = data; |
517 |
d3d9.texture[shader_effect.feedback_pass].map0 = map0; |
518 |
} |
519 |
|
520 |
// rendering del testo |
521 |
text_rendering(TRUE); |
522 |
|
523 |
// text |
524 |
if (cfg->txt_on_screen && text.on_screen) { |
525 |
float vpx, vpy, vpw, vph; |
526 |
|
527 |
// aggiorno la texture del testo |
528 |
IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, d3d9.text.offscreen, NULL, d3d9.text.map0, NULL); |
529 |
|
530 |
vpx = d3d9.viewp.left * gfx.device_pixel_ratio; |
531 |
vpy = d3d9.viewp.top * gfx.device_pixel_ratio; |
532 |
vpw = (d3d9.viewp.right - d3d9.viewp.left) * gfx.device_pixel_ratio; |
533 |
vph = (d3d9.viewp.bottom - d3d9.viewp.top) * gfx.device_pixel_ratio; |
534 |
|
535 |
d3d9_viewport_set(vpx, vpy, vpw, vph); |
536 |
|
537 |
cgD3D9BindProgram(d3d9.text.shader.prg.f); |
538 |
cgD3D9BindProgram(d3d9.text.shader.prg.v); |
539 |
|
540 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *)d3d9.text.data); |
541 |
|
542 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); |
543 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); |
544 |
|
545 |
IDirect3DDevice9_SetVertexDeclaration(d3d9.adapter->dev, d3d9.text.shader.vd); |
546 |
|
547 |
d3d9_shader_params_text_set(&d3d9.text.shader); |
548 |
|
549 |
IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_ALPHABLENDENABLE, TRUE); |
550 |
IDirect3DDevice9_BeginScene(d3d9.adapter->dev); |
551 |
IDirect3DDevice9_DrawPrimitive(d3d9.adapter->dev, D3DPT_TRIANGLESTRIP, 0, 2); |
552 |
IDirect3DDevice9_EndScene(d3d9.adapter->dev); |
553 |
IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_ALPHABLENDENABLE, FALSE); |
554 |
} |
555 |
|
556 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL); |
557 |
|
558 |
// swap buffers |
559 |
{ |
560 |
if (IDirect3DDevice9_Present(d3d9.adapter->dev, &d3d9.viewp, NULL, NULL, NULL) == D3DERR_DEVICELOST) { |
561 |
if (IDirect3DDevice9_TestCooperativeLevel(d3d9.adapter->dev) == D3DERR_DEVICENOTRESET) { |
562 |
emu_pause(TRUE); |
563 |
|
564 |
if (d3d9_context_create() == EXIT_ERROR) { |
565 |
fprintf(stderr, "D3D9 : Unable to initialize d3d context\n"); |
566 |
} |
567 |
|
568 |
emu_pause(FALSE); |
569 |
} |
570 |
} |
571 |
|
572 |
// screenshot |
573 |
if (gfx.save_screenshot == TRUE) { |
574 |
IDirect3DSurface9 *back_buffer, *surface; |
575 |
|
576 |
if (IDirect3DDevice9_GetBackBuffer(d3d9.adapter->dev, 0, 0, D3DBACKBUFFER_TYPE_MONO, &back_buffer) == D3D_OK) { |
577 |
D3DSURFACE_DESC sd; |
578 |
|
579 |
IDirect3DSurface9_GetDesc(back_buffer, &sd); |
580 |
|
581 |
if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, sd.Width, |
582 |
sd.Height, sd.Format, D3DPOOL_SYSTEMMEM, &surface, NULL) == D3D_OK) { |
583 |
if (IDirect3DDevice9_GetRenderTargetData(d3d9.adapter->dev, back_buffer, surface) == D3D_OK) { |
584 |
D3DLOCKED_RECT lrect; |
585 |
|
586 |
if (overscan.enabled && ((!cfg->fullscreen && !cfg->oscan_black_borders) || |
587 |
(cfg->fullscreen && !cfg->oscan_black_borders_fscr))) { |
588 |
int w = d3d9.viewp.right - d3d9.viewp.left; |
589 |
int h = d3d9.viewp.bottom - d3d9.viewp.top; |
590 |
IDirect3DSurface9 *zone; |
591 |
|
592 |
if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, |
593 |
w, h, sd.Format, D3DPOOL_DEFAULT, &zone, NULL) == D3D_OK) { |
594 |
if (IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, surface, &d3d9.viewp, zone, NULL) == D3D_OK) { |
595 |
IDirect3DSurface9_LockRect(zone, &lrect, NULL, 0); |
596 |
gui_save_screenshot(w, h, lrect.pBits, FALSE); |
597 |
IDirect3DSurface9_UnlockRect(zone); |
598 |
} |
599 |
IDirect3DSurface9_Release(zone); |
600 |
} |
601 |
} else { |
602 |
IDirect3DSurface9_LockRect(surface, &lrect, NULL, 0); |
603 |
gui_save_screenshot(sd.Width, sd.Height, lrect.pBits, FALSE); |
604 |
IDirect3DSurface9_UnlockRect(surface); |
605 |
} |
606 |
} |
607 |
IDirect3DSurface9_Release(surface); |
608 |
} |
609 |
IDirect3DSurface9_Release(back_buffer); |
610 |
} |
611 |
gfx.save_screenshot = FALSE; |
612 |
} |
613 |
} |
614 |
} |
615 |
void d3d9_quit(void) { |
616 |
d3d9_context_delete(); |
617 |
|
618 |
{ |
619 |
UINT i; |
620 |
|
621 |
for (i = 0; i < d3d9.adapters_in_use; i++) { |
622 |
_d3d9_adapter *dev = D3D9_ADAPTER(i); |
623 |
|
624 |
if (dev->dev) { |
625 |
IDirect3DDevice9_Release(dev->dev); |
626 |
dev->dev = NULL; |
627 |
} |
628 |
|
629 |
} |
630 |
} |
631 |
|
632 |
if (d3d9.d3d) { |
633 |
IDirect3D9_Release(d3d9.d3d); |
634 |
d3d9.d3d = NULL; |
635 |
} |
636 |
|
637 |
if (d3d9.array) { |
638 |
free(d3d9.array); |
639 |
d3d9.array = d3d9.adapter = NULL; |
640 |
} |
641 |
} |
642 |
|
643 |
static void d3d9_shader_cg_error_handler(void) { |
644 |
CGerror error = cgGetError(); |
645 |
|
646 |
if (error == (CGerror) cgD3D9Failed) { |
647 |
fprintf(stderr, "D3D9: Error '%s' occurred.\n", cgD3D9TranslateHRESULT(cgD3D9GetLastError())); |
648 |
} else { |
649 |
fprintf(stderr, "CG: Error '%s' occurred.\n", cgD3D9TranslateCGerror(error)); |
650 |
} |
651 |
} |
652 |
static BYTE d3d9_device_create(UINT width, UINT height) { |
653 |
D3DPRESENT_PARAMETERS d3dpp; |
654 |
|
655 |
if (d3d9.adapter->dev) { |
656 |
IDirect3DDevice9_Release(d3d9.adapter->dev); |
657 |
d3d9.adapter->dev = NULL; |
658 |
} |
659 |
|
660 |
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); |
661 |
d3dpp.Windowed = TRUE; |
662 |
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY; |
663 |
d3dpp.hDeviceWindow = gui_screen_id(); |
664 |
d3dpp.BackBufferCount = 1; |
665 |
d3dpp.BackBufferFormat = d3d9.adapter->display_mode.Format; |
666 |
d3dpp.BackBufferWidth = width; |
667 |
d3dpp.BackBufferHeight = height; |
668 |
if (cfg->vsync == TRUE) { |
669 |
//d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; |
670 |
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; |
671 |
} else { |
672 |
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; |
673 |
} |
674 |
|
675 |
if (IDirect3D9_CreateDevice(d3d9.d3d, |
676 |
d3d9.adapter->id, |
677 |
D3DDEVTYPE_HAL, |
678 |
gui_screen_id(), |
679 |
d3d9.adapter->flags | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, |
680 |
&d3dpp, |
681 |
&d3d9.adapter->dev) != D3D_OK) { |
682 |
MessageBox(NULL, "Unable to create d3d device", "Error!", MB_ICONEXCLAMATION | MB_OK); |
683 |
return (EXIT_ERROR); |
684 |
} |
685 |
|
686 |
return (EXIT_OK); |
687 |
} |
688 |
static void d3d9_context_delete(void) { |
689 |
UINT i; |
690 |
|
691 |
d3d9.screen.in_use = 0; |
692 |
d3d9.screen.index = 0; |
693 |
|
694 |
for (i = 0; i < LENGTH(d3d9.screen.tex); i++) { |
695 |
_texture_simple *texture = &d3d9.screen.tex[i]; |
696 |
if (texture->offscreen) { |
697 |
IDirect3DSurface9_Release(texture->offscreen); |
698 |
texture->offscreen = NULL; |
699 |
} |
700 |
if (texture->map0) { |
701 |
IDirect3DSurface9_Release(texture->map0); |
702 |
texture->map0 = NULL; |
703 |
} |
704 |
if (texture->data) { |
705 |
IDirect3DTexture9_Release(texture->data); |
706 |
texture->data = NULL; |
707 |
} |
708 |
if (texture->shader.vd) { |
709 |
IDirect3DVertexDeclaration9_Release(texture->shader.vd); |
710 |
texture->shader.vd = NULL; |
711 |
} |
712 |
if (texture->shader.quad) { |
713 |
IDirect3DVertexBuffer9_Release(texture->shader.quad); |
714 |
texture->shader.quad = NULL; |
715 |
} |
716 |
} |
717 |
|
718 |
{ |
719 |
if (d3d9.text.offscreen) { |
720 |
IDirect3DSurface9_Release(d3d9.text.offscreen); |
721 |
d3d9.text.offscreen = NULL; |
722 |
} |
723 |
if (d3d9.text.map0) { |
724 |
IDirect3DSurface9_Release(d3d9.text.map0); |
725 |
d3d9.text.map0 = NULL; |
726 |
} |
727 |
if (d3d9.text.data) { |
728 |
IDirect3DTexture9_Release(d3d9.text.data); |
729 |
d3d9.text.data = NULL; |
730 |
} |
731 |
if (d3d9.text.shader.vd) { |
732 |
IDirect3DVertexDeclaration9_Release(d3d9.text.shader.vd); |
733 |
d3d9.text.shader.vd = NULL; |
734 |
} |
735 |
if (d3d9.text.shader.quad) { |
736 |
IDirect3DVertexBuffer9_Release(d3d9.text.shader.quad); |
737 |
d3d9.text.shader.quad = NULL; |
738 |
} |
739 |
d3d9_shader_delete(&d3d9.text.shader); |
740 |
} |
741 |
|
742 |
{ |
743 |
d3d9.feedback.in_use = FALSE; |
744 |
|
745 |
if (d3d9.feedback.tex.map0) { |
746 |
IDirect3DSurface9_Release(d3d9.feedback.tex.map0); |
747 |
d3d9.feedback.tex.map0 = NULL; |
748 |
} |
749 |
if (d3d9.feedback.tex.data) { |
750 |
IDirect3DTexture9_Release(d3d9.feedback.tex.data); |
751 |
d3d9.feedback.tex.data = NULL; |
752 |
} |
753 |
if (d3d9.feedback.tex.shader.quad) { |
754 |
IDirect3DVertexBuffer9_Release(d3d9.feedback.tex.shader.quad); |
755 |
d3d9.feedback.tex.shader.quad = NULL; |
756 |
} |
757 |
if (d3d9.feedback.tex.shader.vd) { |
758 |
IDirect3DVertexDeclaration9_Release(d3d9.feedback.tex.shader.vd); |
759 |
d3d9.feedback.tex.shader.vd = NULL; |
760 |
} |
761 |
d3d9_shader_delete(&d3d9.feedback.tex.shader); |
762 |
} |
763 |
|
764 |
for (i = 0; i < LENGTH(d3d9.texture); i++) { |
765 |
_texture *texture = &d3d9.texture[i]; |
766 |
|
767 |
if (texture->map0) { |
768 |
IDirect3DSurface9_Release(texture->map0); |
769 |
texture->map0 = NULL; |
770 |
} |
771 |
if (texture->data) { |
772 |
IDirect3DTexture9_Release(texture->data); |
773 |
texture->data = NULL; |
774 |
} |
775 |
if (texture->shader.quad) { |
776 |
IDirect3DVertexBuffer9_Release(texture->shader.quad); |
777 |
texture->shader.quad = NULL; |
778 |
} |
779 |
if (texture->shader.vd) { |
780 |
IDirect3DVertexDeclaration9_Release(texture->shader.vd); |
781 |
texture->shader.vd = NULL; |
782 |
} |
783 |
d3d9_shader_delete(&d3d9.texture[i].shader); |
784 |
} |
785 |
|
786 |
for (i = 0; i < LENGTH(d3d9.lut); i++) { |
787 |
if (d3d9.lut[i].data) { |
788 |
IDirect3DTexture9_Release(d3d9.lut[i].data); |
789 |
d3d9.lut[i].data = NULL; |
790 |
} |
791 |
} |
792 |
|
793 |
if (d3d9.cgctx) { |
794 |
cgD3D9UnloadAllPrograms(); |
795 |
cgD3D9SetDevice(NULL); |
796 |
cgDestroyContext(d3d9.cgctx); |
797 |
d3d9.cgctx = NULL; |
798 |
} |
799 |
|
800 |
if (d3d9.adapter && d3d9.adapter->dev) { |
801 |
IDirect3DDevice9_Release(d3d9.adapter->dev); |
802 |
d3d9.adapter->dev = NULL; |
803 |
} |
804 |
} |
805 |
static BYTE d3d9_texture_create(_texture *texture, UINT index) { |
806 |
_shader_pass *sp = &shader_effect.sp[index]; |
807 |
_shader_scale *sc = &sp->sc; |
808 |
const _texture_rect *prev; |
809 |
_texture_rect *rect = &texture->rect; |
810 |
_viewport *vp = &texture->vp; |
811 |
|
812 |
if (index == 0) { |
813 |
prev = &d3d9.screen.tex[0].rect; |
814 |
} else { |
815 |
prev = &d3d9.texture[index - 1].rect; |
816 |
} |
817 |
|
818 |
if (index == shader_effect.last_pass) { |
819 |
sc->scale.x = 1.0f; |
820 |
sc->scale.y = 1.0f; |
821 |
sc->type.x = SHADER_SCALE_VIEWPORT; |
822 |
sc->type.y = SHADER_SCALE_VIEWPORT; |
823 |
} |
824 |
|
825 |
#if defined (FH_SHADERS_GEST) |
826 |
switch (sc->type.x) { |
827 |
case SHADER_SCALE_DEFAULT: |
828 |
case SHADER_SCALE_INPUT: |
829 |
rect->base.w = (FLOAT)prev->base.w * sc->scale.x; |
830 |
break; |
831 |
case SHADER_SCALE_ABSOLUTE: |
832 |
rect->base.w = sc->abs.x; |
833 |
break; |
834 |
case SHADER_SCALE_VIEWPORT: |
835 |
rect->base.w = (FLOAT)gfx.vp.w * sc->scale.x; |
836 |
break; |
837 |
} |
838 |
switch (sc->type.y) { |
839 |
case SHADER_SCALE_DEFAULT: |
840 |
case SHADER_SCALE_INPUT: |
841 |
rect->base.h = (FLOAT)prev->base.h * sc->scale.y; |
842 |
break; |
843 |
case SHADER_SCALE_ABSOLUTE: |
844 |
rect->base.h = sc->abs.y; |
845 |
break; |
846 |
case SHADER_SCALE_VIEWPORT: |
847 |
rect->base.h = (FLOAT)gfx.vp.h * sc->scale.y; |
848 |
break; |
849 |
} |
850 |
|
851 |
rect->w = emu_power_of_two(rect->base.w); |
852 |
rect->h = emu_power_of_two(rect->base.h); |
853 |
#else |
854 |
switch (sc->type.x) { |
855 |
case SHADER_SCALE_DEFAULT: |
856 |
case SHADER_SCALE_INPUT: |
857 |
rect->w = (FLOAT)prev->w * sc->scale.x; |
858 |
rect->base.w = (FLOAT)prev->base.w * sc->scale.x; |
859 |
break; |
860 |
case SHADER_SCALE_ABSOLUTE: |
861 |
rect->w = rect->base.w = sc->abs.x; |
862 |
break; |
863 |
case SHADER_SCALE_VIEWPORT: |
864 |
rect->w = rect->base.w = (FLOAT)gfx.vp.w * sc->scale.x; |
865 |
break; |
866 |
} |
867 |
switch (sc->type.y) { |
868 |
case SHADER_SCALE_DEFAULT: |
869 |
case SHADER_SCALE_INPUT: |
870 |
rect->h = (FLOAT)prev->h * sc->scale.y; |
871 |
rect->base.h = (FLOAT)prev->base.h * sc->scale.y; |
872 |
break; |
873 |
case SHADER_SCALE_ABSOLUTE: |
874 |
rect->h = rect->base.h = sc->abs.y; |
875 |
break; |
876 |
case SHADER_SCALE_VIEWPORT: |
877 |
rect->h = rect->base.h = (FLOAT)gfx.vp.h * sc->scale.y; |
878 |
break; |
879 |
} |
880 |
|
881 |
rect->w = emu_power_of_two(rect->w); |
882 |
rect->h = emu_power_of_two(rect->h); |
883 |
#endif |
884 |
|
885 |
// se la scheda video supporta solo texture quadre allore devo crearle quadre |
886 |
if (d3d9.adapter->texture_square_only == TRUE) { |
887 |
if (rect->w < rect->h) { |
888 |
rect->w = rect->h; |
889 |
} else { |
890 |
rect->h = rect->w; |
891 |
} |
892 |
} |
893 |
|
894 |
if (index == shader_effect.last_pass) { |
895 |
vp->x = gfx.vp.x * gfx.device_pixel_ratio; |
896 |
vp->y = gfx.vp.y * gfx.device_pixel_ratio; |
897 |
vp->w = gfx.vp.w * gfx.device_pixel_ratio; |
898 |
vp->h = gfx.vp.h * gfx.device_pixel_ratio; |
899 |
} else { |
900 |
vp->x = 0; |
901 |
vp->y = 0; |
902 |
vp->w = rect->base.w; |
903 |
vp->h = rect->base.h; |
904 |
} |
905 |
|
906 |
if (IDirect3DDevice9_CreateVertexBuffer(d3d9.adapter->dev, sizeof(_vertex_buffer) * 4, 0, 0, |
907 |
D3DPOOL_DEFAULT, &texture->shader.quad, NULL) != D3D_OK) { |
908 |
MessageBox(NULL, "Unable to create the vertex buffer", "Error!", MB_ICONEXCLAMATION | MB_OK); |
909 |
return (EXIT_ERROR); |
910 |
} |
911 |
|
912 |
if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev, |
913 |
(UINT)rect->w, (UINT)rect->h, 1, |
914 |
D3DUSAGE_RENDERTARGET, |
915 |
sp->fbo_flt ? D3DFMT_A32B32G32R32F : D3DFMT_A8R8G8B8, |
916 |
D3DPOOL_DEFAULT, |
917 |
&texture->data, |
918 |
NULL) != D3D_OK) { |
919 |
MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK); |
920 |
return (EXIT_ERROR); |
921 |
} |
922 |
|
923 |
IDirect3DTexture9_GetSurfaceLevel(texture->data, 0, &texture->map0); |
924 |
// cancello la superficie map0 perche' alcuni driver (tipo intel) nella |
925 |
// versione per windows XP non mi passano una superficia "pulita". |
926 |
d3d9_surface_clean(&texture->map0, rect->w, rect->h); |
927 |
|
928 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *) texture->data); |
929 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
930 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
931 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL); |
932 |
|
933 |
return (EXIT_OK); |
934 |
} |
935 |
static BYTE d3d9_texture_simple_create(_texture_simple *texture, UINT w, UINT h, BOOL text) { |
936 |
_texture_rect *rect = &texture->rect; |
937 |
_shader *shd = &texture->shader; |
938 |
_viewport vp = { 0, 0, w, h }; |
939 |
UINT flt; |
940 |
|
941 |
rect->base.w = w; |
942 |
rect->base.h = h; |
943 |
|
944 |
if (!text) { |
945 |
#if defined (FH_SHADERS_GEST) |
946 |
rect->w = emu_power_of_two(rect->base.w); |
947 |
rect->h = emu_power_of_two(rect->base.h); |
948 |
#else |
949 |
// rect->w = 1024 e rect->h = 1024 sono |
950 |
// le dimensioni che imposta retroarch |
951 |
// ma su alcune shader l'effetto e' piu' |
952 |
// sgranato ("mudlord/emboss.h" e |
953 |
// "antialiasing/fx-aa.h" sono un esempio) |
954 |
rect->w = 1024; |
955 |
rect->h = 1024; |
956 |
#endif |
957 |
flt = (cfg->interpolation || gfx.PSS) ? D3DTEXF_LINEAR : D3DTEXF_POINT; |
958 |
} else { |
959 |
rect->w = rect->base.w; |
960 |
rect->h = rect->base.h; |
961 |
flt = D3DTEXF_POINT; |
962 |
} |
963 |
|
964 |
// se la scheda video supporta solo texture quadre allore devo crearle quadre |
965 |
if (d3d9.adapter->texture_square_only == TRUE) { |
966 |
if (rect->w < rect->h) { |
967 |
rect->w = rect->h; |
968 |
} else { |
969 |
rect->h = rect->w; |
970 |
} |
971 |
} |
972 |
|
973 |
shd->info.video_size.x = (FLOAT)rect->base.w; |
974 |
shd->info.video_size.y = (FLOAT)rect->base.h; |
975 |
shd->info.texture_size.x = rect->w; |
976 |
shd->info.texture_size.y = rect->h; |
977 |
|
978 |
if (IDirect3DDevice9_CreateVertexBuffer(d3d9.adapter->dev, |
979 |
sizeof(_vertex_buffer) * 4, |
980 |
D3DUSAGE_WRITEONLY, |
981 |
0, |
982 |
D3DPOOL_DEFAULT, |
983 |
&texture->shader.quad, |
984 |
NULL) != D3D_OK) { |
985 |
MessageBox(NULL, "Unable to create the vertex buffer", "Error!", MB_ICONEXCLAMATION | MB_OK); |
986 |
return (EXIT_ERROR); |
987 |
} |
988 |
|
989 |
if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev, |
990 |
(UINT)rect->w, (UINT)rect->h, 1, |
991 |
d3d9.adapter->dynamic_texture ? D3DUSAGE_DYNAMIC : 0, |
992 |
D3DFMT_A8R8G8B8, |
993 |
D3DPOOL_DEFAULT, |
994 |
&texture->data, |
995 |
NULL) != D3D_OK) { |
996 |
MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK); |
997 |
return (EXIT_ERROR); |
998 |
} |
999 |
|
1000 |
IDirect3DTexture9_GetSurfaceLevel(texture->data, 0, &texture->map0); |
1001 |
// cancello la superficie map0 perche' alcuni driver (tipo intel) nella |
1002 |
// versione per windows XP non mi passano una superficia "pulita". |
1003 |
d3d9_surface_clean(&texture->map0, rect->w, rect->h); |
1004 |
|
1005 |
// creo la superficie temporanea le cui dimensioni non devono essere "POWerate" |
1006 |
if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, |
1007 |
rect->base.w, |
1008 |
rect->base.h, |
1009 |
D3DFMT_A8R8G8B8, |
1010 |
D3DPOOL_SYSTEMMEM, |
1011 |
&texture->offscreen, |
1012 |
NULL) != D3D_OK) { |
1013 |
MessageBox(NULL, "Unable to create the memory surface", "Error!", MB_ICONEXCLAMATION | MB_OK); |
1014 |
return (EXIT_ERROR); |
1015 |
} |
1016 |
|
1017 |
// cancello la superficie |
1018 |
d3d9_surface_clean(&texture->offscreen, rect->base.w, rect->base.h); |
1019 |
|
1020 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *) texture->data); |
1021 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
1022 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
1023 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, flt); |
1024 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, flt); |
1025 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL); |
1026 |
|
1027 |
d3d9_vertex_buffer_set(shd, &vp, rect); |
1028 |
|
1029 |
return (EXIT_OK); |
1030 |
} |
1031 |
static BYTE d3d9_texture_lut_create(_lut *lut, UINT index) { |
1032 |
_lut_pass *lp = &shader_effect.lp[index]; |
1033 |
LPDIRECT3DSURFACE9 map0, offscreen; |
1034 |
D3DLOCKED_RECT lrect; |
1035 |
UINT width, height; |
1036 |
|
1037 |
if (gui_load_lut(lut, lp->path) == EXIT_ERROR) { |
1038 |
return (EXIT_ERROR); |
1039 |
} |
1040 |
|
1041 |
width = lut->w; |
1042 |
height = lut->h; |
1043 |
|
1044 |
lut->name = lp->name; |
1045 |
lut->filter = d3d9_shader_filter(lp->linear); |
1046 |
|
1047 |
if (d3d9.adapter->texture_square_only == TRUE) { |
1048 |
if (width < height) { |
1049 |
width = height; |
1050 |
} else { |
1051 |
height = width; |
1052 |
} |
1053 |
} |
1054 |
|
1055 |
if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev, |
1056 |
width, height, 1, |
1057 |
0, |
1058 |
D3DFMT_A8R8G8B8, |
1059 |
D3DPOOL_DEFAULT, |
1060 |
&lut->data, |
1061 |
NULL) != D3D_OK) { |
1062 |
MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK); |
1063 |
return (EXIT_ERROR); |
1064 |
} |
1065 |
|
1066 |
if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, |
1067 |
lut->w, lut->h, |
1068 |
D3DFMT_A8R8G8B8, |
1069 |
D3DPOOL_SYSTEMMEM, |
1070 |
&offscreen, |
1071 |
NULL) != D3D_OK) { |
1072 |
MessageBox(NULL, "Unable to create the memory surface", "Error!", MB_ICONEXCLAMATION | MB_OK); |
1073 |
return (EXIT_ERROR); |
1074 |
} |
1075 |
|
1076 |
IDirect3DTexture9_GetSurfaceLevel(lut->data, 0, &map0); |
1077 |
|
1078 |
if (IDirect3DSurface9_LockRect(offscreen, &lrect, NULL, D3DLOCK_DISCARD) != D3D_OK) { |
1079 |
if (map0) { |
1080 |
IDirect3DSurface9_Release(map0); |
1081 |
} |
1082 |
if (offscreen) { |
1083 |
IDirect3DSurface9_Release(offscreen); |
1084 |
} |
1085 |
return (EXIT_ERROR); |
1086 |
} else { |
1087 |
UINT w = 0, h = 0; |
1088 |
uint32_t *sbits = (uint32_t *)lut->bits; |
1089 |
uint32_t *dbits = (uint32_t *)lrect.pBits; |
1090 |
|
1091 |
for (h = 0; h < lut->h; h++) { |
1092 |
for (w = 0; w < lut->w; w++) { |
1093 |
(*(dbits + w)) = (*(sbits + w)); |
1094 |
} |
1095 |
sbits += lrect.Pitch / (gfx.bit_per_pixel / 8); |
1096 |
dbits += lrect.Pitch / (gfx.bit_per_pixel / 8); |
1097 |
} |
1098 |
|
1099 |
IDirect3DSurface9_UnlockRect(offscreen); |
1100 |
IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, offscreen, NULL, map0, NULL); |
1101 |
|
1102 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *)lut->data); |
1103 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
1104 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
1105 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL); |
1106 |
|
1107 |
IDirect3DSurface9_Release(map0); |
1108 |
IDirect3DSurface9_Release(offscreen); |
1109 |
} |
1110 |
|
1111 |
return (EXIT_OK); |
1112 |
} |
1113 |
static void d3d9_surface_clean(LPDIRECT3DSURFACE9 *surface, UINT width, UINT height) { |
1114 |
D3DLOCKED_RECT lock_dst; |
1115 |
|
1116 |
if (IDirect3DSurface9_LockRect((*surface), &lock_dst, NULL, D3DLOCK_DISCARD) == D3D_OK) { |
1117 |
uint32_t *pbits; |
1118 |
UINT w, h; |
1119 |
|
1120 |
pbits = (uint32_t *)lock_dst.pBits; |
1121 |
|
1122 |
for (h = 0; h < height; h++) { |
1123 |
for (w = 0; w < width; w++) { |
1124 |
(*(pbits + w)) = 0; |
1125 |
} |
1126 |
pbits += lock_dst.Pitch / (gfx.bit_per_pixel / 8); |
1127 |
} |
1128 |
|
1129 |
IDirect3DSurface9_UnlockRect((*surface)); |
1130 |
} |
1131 |
} |
1132 |
static BYTE d3d9_shader_init(UINT pass, _shader *shd, const uTCHAR *path, const char *code) { |
1133 |
const char *list; |
1134 |
const char *argv[128]; |
1135 |
const char **fopts = cgD3D9GetOptimalOptions(cgD3D9GetLatestPixelProfile()); |
1136 |
const char **vopts = cgD3D9GetOptimalOptions(cgD3D9GetLatestVertexProfile()); |
1137 |
char alias[MAX_PASS][128]; |
1138 |
uTCHAR base[LENGTH_FILE_NAME_MID]; |
1139 |
uTCHAR dname[LENGTH_FILE_NAME_MID]; |
1140 |
char bname[LENGTH_FILE_NAME_MID]; |
1141 |
UINT i, argc; |
1142 |
|
1143 |
if ((path != NULL) && path[0]) { |
1144 |
uTCHAR buffer[LENGTH_FILE_NAME_MID]; |
1145 |
|
1146 |
umemset(base, 0x00, usizeof(base)); |
1147 |
if (ugetcwd(base, usizeof(base)) == NULL) { ; }; |
1148 |
|
1149 |
umemset(dname, 0x00, usizeof(dname)); |
1150 |
gui_utf_dirname((uTCHAR *) path, dname, usizeof(buffer) - 1); |
1151 |
|
1152 |
umemset(buffer, 0x00, usizeof(buffer)); |
1153 |
gui_utf_basename((uTCHAR *) path, buffer, usizeof(buffer) - 1); |
1154 |
memset(bname, 0x00, sizeof(bname)); |
1155 |
wcstombs(bname, buffer, sizeof(bname) - 1); |
1156 |
} |
1157 |
|
1158 |
// fragment |
1159 |
{ |
1160 |
memset(alias, 0x00, sizeof(alias)); |
1161 |
memset(argv, 0x00, sizeof(argv)); |
1162 |
|
1163 |
argc = 0; |
1164 |
argv[argc++] = "-DPARAMETER_UNIFORM"; |
1165 |
for (i = 0; i < pass; i++) { |
1166 |
_shader_pass *sp = &shader_effect.sp[i]; |
1167 |
|
1168 |
if (sp->alias[0]) { |
1169 |
snprintf(alias[i], 128, "-D%s_ALIAS", sp->alias); |
1170 |
argv[argc++] = alias[i]; |
1171 |
} |
1172 |
} |
1173 |
for (i = 0; i < 128; i++) { |
1174 |
if (!fopts[i]) { |
1175 |
break; |
1176 |
} |
1177 |
argv[argc] = fopts[i]; |
1178 |
|
1179 |
if (argc++ == 126) { |
1180 |
break; |
1181 |
} |
1182 |
} |
1183 |
argv[argc] = NULL; |
1184 |
|
1185 |
if ((path == NULL) || !path[0]) { |
1186 |
shd->prg.f = cgCreateProgram(d3d9.cgctx, CG_SOURCE, code, cgD3D9GetLatestPixelProfile(), "main_fragment", argv); |
1187 |
} else { |
1188 |
if (uchdir(dname) == -1) { ; } |
1189 |
shd->prg.f = cgCreateProgramFromFile(d3d9.cgctx, CG_SOURCE, bname, cgD3D9GetLatestPixelProfile(), "main_fragment", argv); |
1190 |
if (uchdir(base) == -1) { ; } |
1191 |
} |
1192 |
if (!shd->prg.f && (list = cgGetLastListing(d3d9.cgctx))) { |
1193 |
printf("CG: fragment program errors :\n%s\n", list); |
1194 |
} |
1195 |
} |
1196 |
|
1197 |
// vertex |
1198 |
{ |
1199 |
memset(alias, 0x00, sizeof(alias)); |
1200 |
memset(argv, 0x00, sizeof(argv)); |
1201 |
|
1202 |
argc = 0; |
1203 |
argv[argc++] = "-DPARAMETER_UNIFORM"; |
1204 |
for (i = 0; i < pass; i++) { |
1205 |
_shader_pass *sp = &shader_effect.sp[i]; |
1206 |
|
1207 |
if (sp->alias[0]) { |
1208 |
snprintf(alias[i], 128, "-D%s_ALIAS", sp->alias); |
1209 |
argv[argc++] = alias[i]; |
1210 |
} |
1211 |
} |
1212 |
for (i = 0; i < 128; i++) { |
1213 |
if (!vopts[i]) { |
1214 |
break; |
1215 |
} |
1216 |
argv[argc] = vopts[i]; |
1217 |
|
1218 |
if (argc++ == 126) { |
1219 |
break; |
1220 |
} |
1221 |
} |
1222 |
argv[argc] = NULL; |
1223 |
|
1224 |
if ((path == NULL) || !path[0]) { |
1225 |
shd->prg.v = cgCreateProgram(d3d9.cgctx, CG_SOURCE, code, cgD3D9GetLatestVertexProfile(), "main_vertex", argv); |
1226 |
} else { |
1227 |
if (uchdir(dname) == -1) { ; } |
1228 |
shd->prg.v = cgCreateProgramFromFile(d3d9.cgctx, CG_SOURCE, bname, cgD3D9GetLatestVertexProfile(), "main_vertex", argv); |
1229 |
if (uchdir(base) == -1) { ; } |
1230 |
} |
1231 |
if (!shd->prg.v && (list = cgGetLastListing(d3d9.cgctx))) { |
1232 |
printf("CG: vertex program errors :\n%s\n", list); |
1233 |
} |
1234 |
} |
1235 |
|
1236 |
if (!shd->prg.f || !shd->prg.v) { |
1237 |
fprintf(stderr, "CG: %s\n", cgGetErrorString(cgGetError())); |
1238 |
return (EXIT_ERROR); |
1239 |
} |
1240 |
|
1241 |
if (cgD3D9LoadProgram(shd->prg.f, TRUE, 0) != D3D_OK) { |
1242 |
fprintf(stderr, "CG: Error on loading fragment program\n"); |
1243 |
return (EXIT_ERROR); |
1244 |
} |
1245 |
if (cgD3D9LoadProgram(shd->prg.v, TRUE, 0) != D3D_OK) { |
1246 |
fprintf(stderr, "CG: Error on loading vertex program\n"); |
1247 |
return (EXIT_ERROR); |
1248 |
} |
1249 |
|
1250 |
shd->uni.mvp = cgGetNamedParameter(shd->prg.v, "modelViewProj"); |
1251 |
if (!shd->uni.mvp) { |
1252 |
shd->uni.mvp = cgGetNamedParameter(shd->prg.v, "IN.mvp_matrix"); |
1253 |
} |
1254 |
|
1255 |
shd->uni.v.video_size = cgGetNamedParameter(shd->prg.v, "IN.video_size"); |
1256 |
shd->uni.f.video_size = cgGetNamedParameter(shd->prg.f, "IN.video_size"); |
1257 |
shd->uni.v.texture_size = cgGetNamedParameter(shd->prg.v, "IN.texture_size"); |
1258 |
shd->uni.f.texture_size = cgGetNamedParameter(shd->prg.f, "IN.texture_size"); |
1259 |
shd->uni.v.output_size = cgGetNamedParameter(shd->prg.v, "IN.output_size"); |
1260 |
shd->uni.f.output_size = cgGetNamedParameter(shd->prg.f, "IN.output_size"); |
1261 |
|
1262 |
shd->uni.v.frame_count = cgGetNamedParameter(shd->prg.v, "IN.frame_count"); |
1263 |
shd->uni.f.frame_count = cgGetNamedParameter(shd->prg.f, "IN.frame_count"); |
1264 |
|
1265 |
shd->uni.v.frame_direction = cgGetNamedParameter(shd->prg.v, "IN.frame_direction"); |
1266 |
shd->uni.f.frame_direction = cgGetNamedParameter(shd->prg.f, "IN.frame_direction"); |
1267 |
|
1268 |
if (d3d9_vertex_declaration_create(shd) == EXIT_ERROR) { |
1269 |
return (EXIT_ERROR); |
1270 |
} |
1271 |
|
1272 |
for (i = 0; i < shader_effect.luts; i++) { |
1273 |
shd->uni.v.lut[i] = cgGetNamedParameter(shd->prg.v, d3d9.lut[i].name); |
1274 |
shd->uni.f.lut[i] = cgGetNamedParameter(shd->prg.f, d3d9.lut[i].name); |
1275 |
} |
1276 |
|
1277 |
for (i = 0; i < shader_effect.params; i++) { |
1278 |
shd->uni.v.param[i] = cgGetNamedParameter(shd->prg.v, shader_effect.param[i].name); |
1279 |
shd->uni.f.param[i] = cgGetNamedParameter(shd->prg.f, shader_effect.param[i].name); |
1280 |
} |
1281 |
|
1282 |
d3d9_shader_uni_texture_clear(&shd->uni.orig); |
1283 |
d3d9_shader_uni_texture(&shd->uni.orig, &shd->prg, "ORIG"); |
1284 |
d3d9_shader_uni_texture(&shd->uni.orig, &shd->prg, "PASSPREV%u", pass + 1); |
1285 |
|
1286 |
d3d9_shader_uni_texture_clear(&shd->uni.feedback); |
1287 |
d3d9_shader_uni_texture(&shd->uni.feedback, &shd->prg, "FEEDBACK"); |
1288 |
|
1289 |
for (i = 0; i < pass; i++) { |
1290 |
d3d9_shader_uni_texture_clear(&shd->uni.passprev[i]); |
1291 |
|
1292 |
d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, "PASS%u", i + 1); |
1293 |
d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, "PASSPREV%u", pass - i); |
1294 |
|
1295 |
if (shader_effect.sp[i].alias[0]) { |
1296 |
d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, shader_effect.sp[i].alias); |
1297 |
} |
1298 |
} |
1299 |
|
1300 |
d3d9_shader_uni_texture_clear(&shd->uni.prev[0]); |
1301 |
d3d9_shader_uni_texture(&shd->uni.prev[0], &shd->prg, "PREV"); |
1302 |
|
1303 |
for (i = 1; i < LENGTH(shd->uni.prev); i++) { |
1304 |
d3d9_shader_uni_texture_clear(&shd->uni.prev[i]); |
1305 |
d3d9_shader_uni_texture(&shd->uni.prev[i], &shd->prg, "PREV%u", i); |
1306 |
} |
1307 |
|
1308 |
return (EXIT_OK); |
1309 |
} |
1310 |
static void d3d9_shader_delete(_shader *shd) { |
1311 |
if (shd->prg.f) { |
1312 |
cgDestroyProgram(shd->prg.f); |
1313 |
shd->prg.f = NULL; |
1314 |
} |
1315 |
if (shd->prg.v) { |
1316 |
cgDestroyProgram(shd->prg.v); |
1317 |
shd->prg.v = NULL; |
1318 |
} |
1319 |
} |
1320 |
static void d3d9_shader_uniform_ctrl(CGparameter *dst, CGparameter *param, const char *semantic) { |
1321 |
static const FLOAT f2[2] = {1.0f, 1.0f}; |
1322 |
|
1323 |
if (!(*param)) { |
1324 |
return; |
1325 |
} |
1326 |
|
1327 |
if (cgD3D9SetUniform((*param), &f2) != D3D_OK) { |
1328 |
(*dst) = 0; |
1329 |
fprintf(stderr, "CG: Parameter \"%s\" disabled.\n", semantic); |
1330 |
} else { |
1331 |
(*dst) = (*param); |
1332 |
} |
1333 |
} |
1334 |
static void d3d9_shader_uni_texture_clear(_shader_uniforms_tex *sut) { |
1335 |
sut->f.texture = NULL; |
1336 |
sut->v.video_size = NULL; |
1337 |
sut->f.video_size = NULL; |
1338 |
sut->v.texture_size = NULL; |
1339 |
sut->f.texture_size = NULL; |
1340 |
sut->v.tex_coord = NULL; |
1341 |
} |
1342 |
static void d3d9_shader_uni_texture(_shader_uniforms_tex *sut, _shader_prg_cg *prg, char *fmt, ...) { |
1343 |
CGparameter param; |
1344 |
char type[50], buff[100]; |
1345 |
va_list ap; |
1346 |
|
1347 |
va_start(ap, fmt); |
1348 |
vsnprintf(type, sizeof(type), fmt, ap); |
1349 |
va_end(ap); |
1350 |
|
1351 |
snprintf(buff, sizeof(buff), "%s%s", type, ".texture"); |
1352 |
if (!sut->f.texture) { |
1353 |
sut->f.texture = cgGetNamedParameter(prg->f, buff); |
1354 |
} |
1355 |
snprintf(buff, sizeof(buff), "%s%s", type, ".video_size"); |
1356 |
if (!sut->v.video_size) { |
1357 |
param = cgGetNamedParameter(prg->v, buff); |
1358 |
d3d9_shader_uniform_ctrl(&sut->v.video_size, ¶m, buff); |
1359 |
} |
1360 |
if (!sut->f.video_size) { |
1361 |
param = cgGetNamedParameter(prg->f, buff); |
1362 |
d3d9_shader_uniform_ctrl(&sut->f.video_size, ¶m, buff); |
1363 |
} |
1364 |
snprintf(buff, sizeof(buff), "%s%s", type, ".texture_size"); |
1365 |
if (!sut->v.texture_size) { |
1366 |
param = cgGetNamedParameter(prg->v, buff); |
1367 |
d3d9_shader_uniform_ctrl(&sut->v.texture_size, ¶m, buff); |
1368 |
} |
1369 |
if (!sut->f.texture_size) { |
1370 |
param = cgGetNamedParameter(prg->f, buff); |
1371 |
d3d9_shader_uniform_ctrl(&sut->f.texture_size, ¶m, buff); |
1372 |
} |
1373 |
snprintf(buff, sizeof(buff), "%s%s", type, ".tex_coord"); |
1374 |
if (!sut->v.tex_coord) { |
1375 |
sut->v.tex_coord = cgGetNamedParameter(prg->v, buff); |
1376 |
} |
1377 |
} |
1378 |
static BYTE d3d9_vertex_declaration_create(_shader *shd) { |
1379 |
UINT i, count, index, tex_index = 0; |
1380 |
CGparameter param; |
1381 |
BYTE texcoord[2] = { FALSE }; |
1382 |
BYTE stream[4] = { FALSE }; |
1383 |
BYTE indices[LENGTH(shd->attribs.attrib)] = { FALSE }; |
1384 |
static const D3DVERTEXELEMENT9 end = D3DDECL_END(); |
1385 |
D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH]; |
1386 |
|
1387 |
if (cgD3D9GetVertexDeclaration(shd->prg.v, decl) == CG_FALSE) { |
1388 |
return (EXIT_ERROR); |
1389 |
} |
1390 |
|
1391 |
for (count = 0; count < MAXD3DDECLLENGTH; count++) { |
1392 |
if (memcmp(&end, &decl[count], sizeof(end)) == 0) { |
1393 |
break; |
1394 |
} |
1395 |
} |
1396 |
|
1397 |
if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "POSITION"))) { |
1398 |
param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "POSITION0"); |
1399 |
} |
1400 |
if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) { |
1401 |
stream[0] = TRUE; |
1402 |
index = cgGetParameterResourceIndex(param); |
1403 |
indices[index] = TRUE; |
1404 |
decl[index] = (D3DVERTEXELEMENT9) { |
1405 |
0, 0, |
1406 |
D3DDECLTYPE_FLOAT3, |
1407 |
D3DDECLMETHOD_DEFAULT, |
1408 |
D3DDECLUSAGE_POSITION, 0 |
1409 |
}; |
1410 |
|
1411 |
fprintf(stderr, "CG: semantic POSITION found (%d)\n", index); |
1412 |
} |
1413 |
|
1414 |
if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD"))) { |
1415 |
param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD0"); |
1416 |
} |
1417 |
if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) { |
1418 |
stream[1] = TRUE; |
1419 |
texcoord[0] = TRUE; |
1420 |
index = cgGetParameterResourceIndex(param); |
1421 |
indices[index] = TRUE; |
1422 |
decl[index] = (D3DVERTEXELEMENT9) { |
1423 |
1, sizeof(float) * 3, |
1424 |
D3DDECLTYPE_FLOAT2, |
1425 |
D3DDECLMETHOD_DEFAULT, |
1426 |
D3DDECLUSAGE_TEXCOORD, 0 |
1427 |
}; |
1428 |
|
1429 |
fprintf(stderr, "CG: semantic TEXCOORD0 found (%d)\n", index); |
1430 |
} |
1431 |
|
1432 |
param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD1"); |
1433 |
if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) { |
1434 |
stream[2] = TRUE; |
1435 |
texcoord[1] = TRUE; |
1436 |
index = cgGetParameterResourceIndex(param); |
1437 |
indices[index] = TRUE; |
1438 |
decl[index] = (D3DVERTEXELEMENT9) { |
1439 |
2, sizeof(float) * 5, |
1440 |
D3DDECLTYPE_FLOAT2, |
1441 |
D3DDECLMETHOD_DEFAULT, |
1442 |
D3DDECLUSAGE_TEXCOORD, 1 |
1443 |
}; |
1444 |
|
1445 |
fprintf(stderr, "CG: semantic TEXCOORD1 found (%d)\n", index); |
1446 |
} |
1447 |
|
1448 |
if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "COLOR"))) { |
1449 |
param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "COLOR0"); |
1450 |
} |
1451 |
if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) { |
1452 |
stream[3] = TRUE; |
1453 |
index = cgGetParameterResourceIndex(param); |
1454 |
indices[index] = TRUE; |
1455 |
decl[index] = (D3DVERTEXELEMENT9) { |
1456 |
3, sizeof(float) * 7, |
1457 |
D3DDECLTYPE_FLOAT4, |
1458 |
D3DDECLMETHOD_DEFAULT, |
1459 |
D3DDECLUSAGE_COLOR, 0 |
1460 |
}; |
1461 |
|
1462 |
fprintf(stderr, "CG: semantic COLOR found (%d)\n", index); |
1463 |
} |
1464 |
|
1465 |
// Stream {0, 1, 2, 3} might be already taken. Find first vacant stream |
1466 |
for (index = 0; index < 4; index++) { |
1467 |
if (stream[index] == FALSE) { |
1468 |
break; |
1469 |
} |
1470 |
} |
1471 |
|
1472 |
// Find first vacant texcoord declaration |
1473 |
if (texcoord[0] && texcoord[1]) { |
1474 |
tex_index = 2; |
1475 |
} else if (texcoord[1] && !texcoord[0]) { |
1476 |
tex_index = 0; |
1477 |
} else if (texcoord[0] && !texcoord[1]) { |
1478 |
tex_index = 1; |
1479 |
} |
1480 |
|
1481 |
shd->attribs.count = 0; |
1482 |
|
1483 |
for (i = 0; i < count; i++) { |
1484 |
if (indices[i]) { |
1485 |
shd->attribs.attrib[shd->attribs.count++] = 0; |
1486 |
} else { |
1487 |
fprintf(stderr, "CG: attrib found (%d %d %d %d)\n", i, shd->attribs.count, index, tex_index); |
1488 |
|
1489 |
shd->attribs.attrib[shd->attribs.count++] = index; |
1490 |
decl[i] = (D3DVERTEXELEMENT9) { |
1491 |
index, sizeof(float) * 3, |
1492 |
D3DDECLTYPE_FLOAT2, |
1493 |
D3DDECLMETHOD_DEFAULT, |
1494 |
D3DDECLUSAGE_TEXCOORD, tex_index |
1495 |
}; |
1496 |
while ((++index < 4) && stream[index]) { |
1497 |
index++; |
1498 |
} |
1499 |
if ((++tex_index == 1) && texcoord[1]) { |
1500 |
tex_index++; |
1501 |
} |
1502 |
} |
1503 |
} |
1504 |
|
1505 |
if (IDirect3DDevice9_CreateVertexDeclaration(d3d9.adapter->dev, decl, &shd->vd)) { |
1506 |
return (EXIT_ERROR); |
1507 |
} |
1508 |
|
1509 |
return (EXIT_OK); |
1510 |
} |
1511 |
static void d3d9_vertex_buffer_set(_shader *shd, _viewport *vp, _texture_rect *prev) { |
1512 |
D3DXMATRIX proj, ortho, rot; |
1513 |
FLOAT u = (FLOAT)prev->base.w / prev->w; |
1514 |
FLOAT v = (FLOAT)prev->base.h / prev->h; |
1515 |
void *buffer; |
1516 |
const UINT rotation = 0; |
1517 |
UINT i; |
1518 |
|
1519 |
shd->vb[0].x = 0.0f; |
1520 |
shd->vb[0].y = vp->h; |
1521 |
shd->vb[0].z = 0.5f; |
1522 |
shd->vb[0].u = 0.0f; |
1523 |
shd->vb[0].v = 0.0f; |
1524 |
shd->vb[0].lut_u = 0.0f; |
1525 |
shd->vb[0].lut_v = 0.0f; |
1526 |
shd->vb[0].r = 1.0f; |
1527 |
shd->vb[0].g = 1.0f; |
1528 |
shd->vb[0].b = 1.0f; |
1529 |
shd->vb[0].a = 1.0f; |
1530 |
|
1531 |
shd->vb[1].x = vp->w; |
1532 |
shd->vb[1].y = vp->h; |
1533 |
shd->vb[1].z = 0.5f; |
1534 |
shd->vb[1].u = u; |
1535 |
shd->vb[1].v = 0.0f; |
1536 |
shd->vb[1].lut_u = 1.0f; |
1537 |
shd->vb[1].lut_v = 0.0f; |
1538 |
shd->vb[1].r = 1.0f; |
1539 |
shd->vb[1].g = 1.0f; |
1540 |
shd->vb[1].b = 1.0f; |
1541 |
shd->vb[1].a = 1.0f; |
1542 |
|
1543 |
shd->vb[2].x = 0.0f; |
1544 |
shd->vb[2].y = 0.0f; |
1545 |
shd->vb[2].z = 0.5f; |
1546 |
shd->vb[2].u = 0.0f; |
1547 |
shd->vb[2].v = v; |
1548 |
shd->vb[2].lut_u = 0.0f; |
1549 |
shd->vb[2].lut_v = 1.0f; |
1550 |
shd->vb[2].r = 1.0f; |
1551 |
shd->vb[2].g = 1.0f; |
1552 |
shd->vb[2].b = 1.0f; |
1553 |
shd->vb[2].a = 1.0f; |
1554 |
|
1555 |
shd->vb[3].x = vp->w; |
1556 |
shd->vb[3].y = 0.0f; |
1557 |
shd->vb[3].z = 0.5f; |
1558 |
shd->vb[3].u = u; |
1559 |
shd->vb[3].v = v; |
1560 |
shd->vb[3].lut_u = 1.0f; |
1561 |
shd->vb[3].lut_v = 1.0f; |
1562 |
shd->vb[3].r = 1.0f; |
1563 |
shd->vb[3].g = 1.0f; |
1564 |
shd->vb[3].b = 1.0f; |
1565 |
shd->vb[3].a = 1.0f; |
1566 |
|
1567 |
// problema dell'infamous half-texel offset of D3D9 (corretto dalle D3D10 in poi) : |
1568 |
// http://msdn.microsoft.com/en-us/library/bb219690%28VS.85%29.aspx. |
1569 |
for (i = 0; i < 4; i++) { |
1570 |
shd->vb[i].x -= 0.5f; |
1571 |
shd->vb[i].y += 0.5f; |
1572 |
} |
1573 |
|
1574 |
IDirect3DVertexBuffer9_Lock(shd->quad, 0, 0, (void**) &buffer, 0); |
1575 |
memcpy(buffer, shd->vb, sizeof(shd->vb)); |
1576 |
IDirect3DVertexBuffer9_Unlock(shd->quad); |
1577 |
|
1578 |
D3DXMatrixOrthoOffCenterLH(&ortho, 0, vp->w, 0, vp->h, 0, 1); |
1579 |
D3DXMatrixIdentity(&rot); |
1580 |
D3DXMatrixRotationZ(&rot, rotation * (M_PI / 2.0)); |
1581 |
|
1582 |
D3DXMatrixMultiply(&proj, &ortho, &rot); |
1583 |
D3DXMatrixTranspose(&shd->mvp, &proj); |
1584 |
} |
1585 |
static CGparameter d3d9_cg_find_param(CGparameter prm, const char *name) { |
1586 |
UINT i; |
1587 |
static const char *illegal[] = { |
1588 |
"IN.", |
1589 |
"ORIG.", |
1590 |
"PASS", |
1591 |
"PREV.", |
1592 |
"PREV1.", "PREV2.", |
1593 |
"PREV3.", "PREV4.", |
1594 |
"PREV5.", "PREV6.", |
1595 |
}; |
1596 |
|
1597 |
for (; prm; prm = cgGetNextParameter(prm)) { |
1598 |
const char *semantic = NULL; |
1599 |
|
1600 |
if (cgGetParameterType(prm) == CG_STRUCT) { |
1601 |
CGparameter ret; |
1602 |
|
1603 |
if ((ret = d3d9_cg_find_param(cgGetFirstStructParameter(prm), name))) { |
1604 |
return (ret); |
1605 |
} |
1606 |
} |
1607 |
if (cgGetParameterDirection(prm) != CG_IN || cgGetParameterVariability(prm) != CG_VARYING) { |
1608 |
continue; |
1609 |
} |
1610 |
if (!(semantic = cgGetParameterSemantic(prm))) { |
1611 |
continue; |
1612 |
} |
1613 |
if (strcmp(name, semantic) == 0) { |
1614 |
const char *pname = cgGetParameterName(prm); |
1615 |
|
1616 |
if (!pname) { |
1617 |
return (NULL); |
1618 |
} |
1619 |
|
1620 |
for (i = 0; i < LENGTH(illegal); i++) { |
1621 |
if (strstr(pname, illegal[i]) == pname) { |
1622 |
return (NULL); |
1623 |
} |
1624 |
} |
1625 |
|
1626 |
return (prm); |
1627 |
} |
1628 |
} |
1629 |
return (NULL); |
1630 |
} |
1631 |
INLINE static void d3d9_viewport_set(DWORD x, DWORD y, DWORD w, DWORD h) { |
1632 |
static D3DVIEWPORT9 vp; |
1633 |
|
1634 |
vp.X = x; |
1635 |
vp.Y = y; |
1636 |
vp.Width = w; |
1637 |
vp.Height = h; |
1638 |
vp.MinZ = 0.0f; |
1639 |
vp.MaxZ = 1.0f; |
1640 |
IDirect3DDevice9_SetViewport(d3d9.adapter->dev, &vp); |
1641 |
} |
1642 |
INLINE D3DTEXTUREFILTERTYPE d3d9_shader_filter(UINT type) { |
1643 |
switch (type) { |
1644 |
case TEXTURE_LINEAR_ENAB: |
1645 |
return D3DTEXF_LINEAR; |
1646 |
case TEXTURE_LINEAR_DISAB: |
1647 |
return D3DTEXF_POINT; |
1648 |
default: |
1649 |
if (cfg->interpolation || gfx.PSS) { |
1650 |
return D3DTEXF_LINEAR; |
1651 |
} |
1652 |
return D3DTEXF_POINT; |
1653 |
} |
1654 |
} |
1655 |
INLINE static void d3d9_shader_params_text_set(_shader *shd) { |
1656 |
UINT i; |
1657 |
|
1658 |
if (shd->uni.mvp) { |
1659 |
// posso tranquillamente utilizzare l'mvp dell'ultimo pass |
1660 |
cgD3D9SetUniformMatrix(shd->uni.mvp, &shd->mvp); |
1661 |
} |
1662 |
|
1663 |
for (i = 0; i < 4; i++) { |
1664 |
IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, i, shd->quad, 0, sizeof(_vertex_buffer)); |
1665 |
} |
1666 |
} |
1667 |
INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount) { |
1668 |
const _shader *shd = &texture->shader; |
1669 |
UINT i, index; |
1670 |
|
1671 |
if (shd->uni.mvp) { |
1672 |
cgD3D9SetUniformMatrix(shd->uni.mvp, &shd->mvp); |
1673 |
} |
1674 |
|
1675 |
for (i = 0; i < 4; i++) { |
1676 |
IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, i, shd->quad, 0, sizeof(_vertex_buffer)); |
1677 |
} |
1678 |
|
1679 |
// IN |
1680 |
{ |
1681 |
// IN.video_size |
1682 |
if (shd->uni.v.video_size) { |
1683 |
cgD3D9SetUniform(shd->uni.v.video_size, &shd->info.video_size); |
1684 |
} |
1685 |
if (shd->uni.f.video_size) { |
1686 |
cgD3D9SetUniform(shd->uni.f.video_size, &shd->info.video_size); |
1687 |
} |
1688 |
// IN.texture_size |
1689 |
if (shd->uni.v.texture_size) { |
1690 |
cgD3D9SetUniform(shd->uni.v.texture_size, &shd->info.texture_size); |
1691 |
} |
1692 |
if (shd->uni.f.texture_size) { |
1693 |
cgD3D9SetUniform(shd->uni.f.texture_size, &shd->info.texture_size); |
1694 |
} |
1695 |
// IN.output_size |
1696 |
if (shd->uni.v.output_size) { |
1697 |
cgD3D9SetUniform(shd->uni.v.output_size, &shd->info.output_size); |
1698 |
} |
1699 |
if (shd->uni.f.output_size) { |
1700 |
cgD3D9SetUniform(shd->uni.f.output_size, &shd->info.output_size); |
1701 |
} |
1702 |
// IN.frame_count |
1703 |
{ |
1704 |
FLOAT fc = (FLOAT)fcount; |
1705 |
|
1706 |
if (fcountmod) { |
1707 |
fc = (FLOAT)(fcount % fcountmod); |
1708 |
} |
1709 |
|
1710 |
if (shd->uni.v.frame_count) { |
1711 |
cgD3D9SetUniform(shd->uni.v.frame_count, &fc); |
1712 |
} |
1713 |
if (shd->uni.f.frame_count) { |
1714 |
cgD3D9SetUniform(shd->uni.f.frame_count, &fc); |
1715 |
} |
1716 |
} |
1717 |
// IN.frame_direction |
1718 |
{ |
1719 |
FLOAT frame_direction = -1; |
1720 |
|
1721 |
if (shd->uni.v.frame_direction) { |
1722 |
cgD3D9SetUniform(shd->uni.v.frame_direction, &frame_direction); |
1723 |
} |
1724 |
if (shd->uni.f.frame_direction) { |
1725 |
cgD3D9SetUniform(shd->uni.f.frame_direction, &frame_direction); |
1726 |
} |
1727 |
} |
1728 |
} |
1729 |
|
1730 |
// param |
1731 |
for (i = 0; i < shader_effect.params; i++) { |
1732 |
if (shd->uni.v.param[i]) { |
1733 |
cgD3D9SetUniform(shd->uni.v.param[i], &shader_effect.param[i].value); |
1734 |
} |
1735 |
if (shd->uni.f.param[i]) { |
1736 |
cgD3D9SetUniform(shd->uni.f.param[i], &shader_effect.param[i].value); |
1737 |
} |
1738 |
} |
1739 |
|
1740 |
// lut |
1741 |
for (i = 0; i < shader_effect.luts; i++) { |
1742 |
_lut *lut = &d3d9.lut[i]; |
1743 |
UINT bound_index = (UINT)-1; |
1744 |
|
1745 |
if (shd->uni.v.lut[i]) { |
1746 |
index = cgGetParameterResourceIndex(shd->uni.v.lut[i]); |
1747 |
bound_index = index; |
1748 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )lut->data); |
1749 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, lut->filter); |
1750 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, lut->filter); |
1751 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
1752 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
1753 |
} |
1754 |
if (shd->uni.f.lut[i]) { |
1755 |
index = cgGetParameterResourceIndex(shd->uni.f.lut[i]); |
1756 |
if (index == bound_index) { |
1757 |
continue; |
1758 |
} |
1759 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )lut->data); |
1760 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, lut->filter); |
1761 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, lut->filter); |
1762 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
1763 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
1764 |
} |
1765 |
} |
1766 |
|
1767 |
// ORIG |
1768 |
{ |
1769 |
// ORIG.texture |
1770 |
if (shd->uni.orig.f.texture) { |
1771 |
index = cgGetParameterResourceIndex(shd->uni.orig.f.texture); |
1772 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )d3d9.screen.tex[d3d9.screen.index].data); |
1773 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, D3DTEXF_POINT); |
1774 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, D3DTEXF_POINT); |
1775 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
1776 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
1777 |
} |
1778 |
// ORIG.video_size |
1779 |
if (shd->uni.orig.v.video_size) { |
1780 |
cgD3D9SetUniform(shd->uni.orig.v.video_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.video_size); |
1781 |
} |
1782 |
if (shd->uni.orig.f.video_size) { |
1783 |
cgD3D9SetUniform(shd->uni.orig.f.video_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.video_size); |
1784 |
} |
1785 |
// ORIG.texture_size |
1786 |
if (shd->uni.orig.v.texture_size) { |
1787 |
cgD3D9SetUniform(shd->uni.orig.v.texture_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.texture_size); |
1788 |
} |
1789 |
if (shd->uni.orig.f.texture_size) { |
1790 |
cgD3D9SetUniform(shd->uni.orig.f.texture_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.texture_size); |
1791 |
} |
1792 |
// ORIG.tex_coord |
1793 |
if (shd->uni.orig.v.tex_coord) { |
1794 |
IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, |
1795 |
shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.orig.v.tex_coord)], |
1796 |
d3d9.screen.tex[d3d9.screen.index].shader.quad, 0, sizeof(_vertex_buffer)); |
1797 |
} |
1798 |
} |
1799 |
|
1800 |
// FEEDBACK |
1801 |
if (d3d9.feedback.in_use) { |
1802 |
// FEEDBACK.texture |
1803 |
if (shd->uni.feedback.f.texture) { |
1804 |
D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(shader_effect.sp[shader_effect.feedback_pass].linear); |
1805 |
|
1806 |
index = cgGetParameterResourceIndex(shd->uni.feedback.f.texture); |
1807 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )d3d9.feedback.tex.data); |
1808 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, filter); |
1809 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, filter); |
1810 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
1811 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
1812 |
} |
1813 |
// FEEDBACK.video_size |
1814 |
if (shd->uni.feedback.v.video_size) { |
1815 |
cgD3D9SetUniform(shd->uni.feedback.v.video_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.video_size); |
1816 |
} |
1817 |
if (shd->uni.feedback.f.video_size) { |
1818 |
cgD3D9SetUniform(shd->uni.feedback.f.video_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.video_size); |
1819 |
} |
1820 |
// FEEDBACK.texture_size |
1821 |
if (shd->uni.feedback.v.texture_size) { |
1822 |
cgD3D9SetUniform(shd->uni.feedback.v.texture_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.texture_size); |
1823 |
} |
1824 |
if (shd->uni.feedback.f.texture_size) { |
1825 |
cgD3D9SetUniform(shd->uni.feedback.f.texture_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.texture_size); |
1826 |
} |
1827 |
// FEEDBACK.tex_coord |
1828 |
if (shd->uni.feedback.v.tex_coord) { |
1829 |
IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, |
1830 |
shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.feedback.v.tex_coord)], |
1831 |
d3d9.texture[shader_effect.feedback_pass].shader.quad, 0, |
1832 |
sizeof(_vertex_buffer)); |
1833 |
} |
1834 |
} |
1835 |
|
1836 |
// PREV |
1837 |
{ |
1838 |
INT circle_index = d3d9.screen.index - 1; |
1839 |
|
1840 |
for (i = 0; i < (d3d9.screen.in_use - 1); i++) { |
1841 |
if (circle_index < 0) { |
1842 |
circle_index = d3d9.screen.in_use - 1; |
1843 |
} |
1844 |
// PREV[x].texture |
1845 |
if (shd->uni.prev[i].f.texture) { |
1846 |
index = cgGetParameterResourceIndex(shd->uni.prev[i].f.texture); |
1847 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 *)d3d9.screen.tex[circle_index].data); |
1848 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, D3DTEXF_POINT); |
1849 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, D3DTEXF_POINT); |
1850 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
1851 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
1852 |
} |
1853 |
// PREV[x].tex_coord |
1854 |
if (shd->uni.prev[i].v.tex_coord) { |
1855 |
IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, |
1856 |
shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.prev[i].v.tex_coord)], |
1857 |
d3d9.screen.tex[circle_index].shader.quad, 0, sizeof(_vertex_buffer)); |
1858 |
} |
1859 |
circle_index--; |
1860 |
} |
1861 |
} |
1862 |
|
1863 |
// PASS |
1864 |
for (i = 0; i < shader_effect.running_pass; i++) { |
1865 |
UINT next = i + 1; |
1866 |
|
1867 |
// PASS[x].texture |
1868 |
if (shd->uni.passprev[i].f.texture) { |
1869 |
D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(shader_effect.sp[i].linear); |
1870 |
UINT resind = cgGetParameterResourceIndex(shd->uni.passprev[i].f.texture); |
1871 |
|
1872 |
IDirect3DDevice9_SetTexture(d3d9.adapter->dev, resind, (IDirect3DBaseTexture9 *)d3d9.texture[i].data); |
1873 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_MAGFILTER, filter); |
1874 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_MINFILTER, filter); |
1875 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); |
1876 |
IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); |
1877 |
} |
1878 |
// PASS[x].video_size |
1879 |
if (shd->uni.passprev[i].v.video_size) { |
1880 |
cgD3D9SetUniform(shd->uni.passprev[i].v.video_size, &d3d9.texture[next].shader.info.video_size); |
1881 |
} |
1882 |
if (shd->uni.passprev[i].f.video_size) { |
1883 |
cgD3D9SetUniform(shd->uni.passprev[i].f.video_size, &d3d9.texture[next].shader.info.video_size); |
1884 |
} |
1885 |
// PASS[x].texture_size |
1886 |
if (shd->uni.passprev[i].v.texture_size) { |
1887 |
cgD3D9SetUniform(shd->uni.passprev[i].v.texture_size, &d3d9.texture[next].shader.info.texture_size); |
1888 |
} |
1889 |
if (shd->uni.passprev[i].f.texture_size) { |
1890 |
cgD3D9SetUniform(shd->uni.passprev[i].f.texture_size, &d3d9.texture[next].shader.info.texture_size); |
1891 |
} |
1892 |
// PASS[x].tex_coord |
1893 |
if (shd->uni.passprev[i].v.tex_coord) { |
1894 |
IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, |
1895 |
shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.passprev[i].v.tex_coord)], |
1896 |
d3d9.texture[next].shader.quad, 0, sizeof(_vertex_buffer)); |
1897 |
} |
1898 |
} |
1899 |
} |