Previous 199869 Revisions Next

r23475 Thursday 6th June, 2013 at 02:43:23 UTC by David Haywood
"put HLSL back ..." fix build etc.
[src/osd/windows]d3d9intf.c d3dhlsl.c* d3dhlsl.h* d3dintf.h drawd3d.c drawd3d.h drawdd.c drawgdi.c drawnone.c input.c video.c windows.mak winmain.c winmain.h

trunk/src/osd/windows/input.c
r23474r23475
776776            entry->defseq(SEQ_TYPE_STANDARD).set(KEYCODE_LALT, KEYCODE_ENTER);
777777            break;
778778
779         // alt-F12 for fullscreen snap
780         case IPT_OSD_2:
781            entry->configure_osd("RENDER_SNAP", "Take Rendered Snapshot");
782            entry->defseq(SEQ_TYPE_STANDARD).set(KEYCODE_LALT, KEYCODE_F12, input_seq::not_code, KEYCODE_LCONTROL);
783            break;
784
785         // alt-F11 for fullscreen video
786         case IPT_OSD_3:
787            entry->configure_osd("RENDER_AVI", "Record Rendered Video");
788            entry->defseq(SEQ_TYPE_STANDARD).set(KEYCODE_LALT, KEYCODE_F11);
789            break;
790
791         // ctrl-alt-F12 to toggle post-processing
792         case IPT_OSD_4:
793            entry->configure_osd("POST_PROCESS", "Toggle Post-Processing");
794            entry->defseq(SEQ_TYPE_STANDARD).set(KEYCODE_LALT, KEYCODE_LCONTROL, KEYCODE_F5);
795            break;
796
779797         // leave everything else alone
780798         default:
781799            break;
trunk/src/osd/windows/winmain.c
r23474r23475
331331   { NULL,                                           NULL,       OPTION_HEADER,     "DIRECT3D-SPECIFIC OPTIONS" },
332332   { WINOPTION_FILTER ";d3dfilter;flt",              "1",        OPTION_BOOLEAN,    "enable bilinear filtering on screen output" },
333333
334   // post-processing options
335   { NULL,                                                     NULL,        OPTION_HEADER,     "DIRECT3D POST-PROCESSING OPTIONS" },
336   { WINOPTION_HLSL_ENABLE";hlsl",                             "0",         OPTION_BOOLEAN,    "enable HLSL post-processing (PS3.0 required)" },
337   { WINOPTION_HLSLPATH,                                       "hlsl",      OPTION_STRING,     "path to hlsl files" },
338   { WINOPTION_HLSL_INI_READ,                                  "0",         OPTION_BOOLEAN,    "enable HLSL INI reading" },
339   { WINOPTION_HLSL_INI_WRITE,                                 "0",         OPTION_BOOLEAN,    "enable HLSL INI writing" },
340   { WINOPTION_HLSL_INI_NAME,                                  "%g",        OPTION_STRING,     "HLSL INI file name for this game" },
341   { WINOPTION_HLSL_PRESCALE_X,                                "0",         OPTION_INTEGER,    "HLSL pre-scale override factor for X (0 for auto)" },
342   { WINOPTION_HLSL_PRESCALE_Y,                                "0",         OPTION_INTEGER,    "HLSL pre-scale override factor for Y (0 for auto)" },
343   { WINOPTION_HLSL_PRESET";(-1-3)",                           "-1",        OPTION_INTEGER,    "HLSL preset to use (0-3)" },
344   { WINOPTION_HLSL_WRITE,                                     NULL,        OPTION_STRING,     "enable HLSL AVI writing (huge disk bandwidth suggested)" },
345   { WINOPTION_HLSL_SNAP_WIDTH,                                "2048",      OPTION_STRING,     "HLSL upscaled-snapshot width" },
346   { WINOPTION_HLSL_SNAP_HEIGHT,                               "1536",      OPTION_STRING,     "HLSL upscaled-snapshot height" },
347   { WINOPTION_SHADOW_MASK_ALPHA";fs_shadwa(0.0-1.0)",         "0.0",       OPTION_FLOAT,      "shadow mask alpha-blend value (1.0 is fully blended, 0.0 is no mask)" },
348   { WINOPTION_SHADOW_MASK_TEXTURE";fs_shadwt(0.0-1.0)",       "aperture.png", OPTION_STRING,  "shadow mask texture name" },
349   { WINOPTION_SHADOW_MASK_COUNT_X";fs_shadww",                "320",       OPTION_INTEGER,    "shadow mask width, in phosphor dots" },
350   { WINOPTION_SHADOW_MASK_COUNT_Y";fs_shadwh",                "240",       OPTION_INTEGER,    "shadow mask height, in phosphor dots" },
351   { WINOPTION_SHADOW_MASK_USIZE";fs_shadwu(0.0-1.0)",         "0.09375",   OPTION_FLOAT,      "shadow mask texture size in U direction" },
352   { WINOPTION_SHADOW_MASK_VSIZE";fs_shadwv(0.0-1.0)",         "0.109375",  OPTION_FLOAT,      "shadow mask texture size in V direction" },
353   { WINOPTION_CURVATURE";fs_curv(0.0-4.0)",                   "0.03",      OPTION_FLOAT,      "screen curvature amount" },
354   /* Beam-related values below this line*/
355   { WINOPTION_PINCUSHION";fs_pin(0.0-4.0)",                   "0.03",      OPTION_FLOAT,      "pincushion amount" },
356   { WINOPTION_SCANLINE_AMOUNT";fs_scanam(0.0-4.0)",           "1.0",       OPTION_FLOAT,      "overall alpha scaling value for scanlines" },
357   { WINOPTION_SCANLINE_SCALE";fs_scansc(0.0-4.0)",            "1.0",       OPTION_FLOAT,      "overall height scaling value for scanlines" },
358   { WINOPTION_SCANLINE_HEIGHT";fs_scanh(0.0-4.0)",            "1.0",       OPTION_FLOAT,      "individual height scaling value for scanlines" },
359   { WINOPTION_SCANLINE_BRIGHT_SCALE";fs_scanbs(0.0-2.0)",     "1.0",       OPTION_FLOAT,      "overall brightness scaling value for scanlines (multiplicative)" },
360   { WINOPTION_SCANLINE_BRIGHT_OFFSET";fs_scanbo(0.0-1.0)",    "0.0",       OPTION_FLOAT,      "overall brightness offset value for scanlines (additive)" },
361   { WINOPTION_SCANLINE_OFFSET";fs_scanjt(0.0-4.0)",           "0.0",       OPTION_FLOAT,      "overall interlace jitter scaling value for scanlines" },
362   { WINOPTION_DEFOCUS";fs_focus",                             "0.0,0.0",   OPTION_STRING,     "overall defocus value in screen-relative coords" },
363   { WINOPTION_CONVERGE_X";fs_convx",                          "0.3,0.0,-0.3",OPTION_STRING,   "convergence in screen-relative X direction" },
364   { WINOPTION_CONVERGE_Y";fs_convy",                          "0.0,0.3,-0.3",OPTION_STRING,   "convergence in screen-relative Y direction" },
365   { WINOPTION_RADIAL_CONVERGE_X";fs_rconvx",                  "0.0,0.0,0.0",OPTION_STRING,    "radial convergence in screen-relative X direction" },
366   { WINOPTION_RADIAL_CONVERGE_Y";fs_rconvy",                  "0.0,0.0,0.0",OPTION_STRING,    "radial convergence in screen-relative Y direction" },
367   /* RGB colorspace convolution below this line */
368   { WINOPTION_RED_RATIO";fs_redratio",                        "1.0,0.0,0.0",OPTION_STRING,    "red output signal generated by input signal" },
369   { WINOPTION_GRN_RATIO";fs_grnratio",                        "0.0,1.0,0.0",OPTION_STRING,    "green output signal generated by input signal" },
370   { WINOPTION_BLU_RATIO";fs_bluratio",                        "0.0,0.0,1.0",OPTION_STRING,    "blue output signal generated by input signal" },
371   { WINOPTION_SATURATION";fs_sat(0.0-4.0)",                   "1.4",        OPTION_FLOAT,     "saturation scaling value" },
372   { WINOPTION_OFFSET";fs_offset",                             "0.0,0.0,0.0",OPTION_STRING,    "signal offset value (additive)" },
373   { WINOPTION_SCALE";fs_scale",                               "0.95,0.95,0.95",OPTION_STRING, "signal scaling value (multiplicative)" },
374   { WINOPTION_POWER";fs_power",                               "0.8,0.8,0.8",OPTION_STRING,    "signal power value (exponential)" },
375   { WINOPTION_FLOOR";fs_floor",                               "0.05,0.05,0.05",OPTION_STRING, "signal floor level" },
376   { WINOPTION_PHOSPHOR";fs_phosphor",                         "0.4,0.4,0.4",OPTION_STRING,    "phosphorescence decay rate (0.0 is instant, 1.0 is forever)" },
377   /* NTSC simulation below this line */
378   { NULL,                                                     NULL,        OPTION_HEADER,     "NTSC POST-PROCESSING OPTIONS" },
379   { WINOPTION_YIQ_ENABLE";yiq",                               "0",         OPTION_BOOLEAN,    "enable YIQ-space HLSL post-processing" },
380   { WINOPTION_YIQ_CCVALUE";yiqcc",                            "3.59754545",OPTION_FLOAT,      "Color Carrier frequency for NTSC signal processing" },
381   { WINOPTION_YIQ_AVALUE";yiqa",                              "0.5",       OPTION_FLOAT,      "A value for NTSC signal processing" },
382   { WINOPTION_YIQ_BVALUE";yiqb",                              "0.5",       OPTION_FLOAT,      "B value for NTSC signal processing" },
383   { WINOPTION_YIQ_OVALUE";yiqo",                              "0.0",       OPTION_FLOAT,      "Outgoing Color Carrier phase offset for NTSC signal processing" },
384   { WINOPTION_YIQ_PVALUE";yiqp",                              "1.0",       OPTION_FLOAT,      "Incoming Pixel Clock scaling value for NTSC signal processing" },
385   { WINOPTION_YIQ_NVALUE";yiqn",                              "1.0",       OPTION_FLOAT,      "Y filter notch width for NTSC signal processing" },
386   { WINOPTION_YIQ_YVALUE";yiqy",                              "6.0",       OPTION_FLOAT,      "Y filter cutoff frequency for NTSC signal processing" },
387   { WINOPTION_YIQ_IVALUE";yiqi",                              "1.2",       OPTION_FLOAT,      "I filter cutoff frequency for NTSC signal processing" },
388   { WINOPTION_YIQ_QVALUE";yiqq",                              "0.6",       OPTION_FLOAT,      "Q filter cutoff frequency for NTSC signal processing" },
389   { WINOPTION_YIQ_SCAN_TIME";yiqsc",                          "52.6",      OPTION_FLOAT,      "Horizontal scanline duration for NTSC signal processing (in usec)" },
390   { WINOPTION_YIQ_PHASE_COUNT";yiqp",                         "2",         OPTION_INTEGER,    "Phase Count value for NTSC signal processing" },
391   { WINOPTION_YIQ_SCAN_TIME";yiqsc",                          "52.6",      OPTION_FLOAT,      "Horizontal scanline duration for NTSC signal processing (in usec)" },
392   { WINOPTION_YIQ_PHASE_COUNT";yiqp",                         "2",         OPTION_INTEGER,    "Phase Count value for NTSC signal processing" },
393   /* Vector simulation below this line */
394   { NULL,                                                     NULL,        OPTION_HEADER,     "VECTOR POST-PROCESSING OPTIONS" },
395   { WINOPTION_VECTOR_LENGTH_SCALE";veclength",                "0.8",       OPTION_FLOAT,      "How much length affects vector fade" },
396   { WINOPTION_VECTOR_LENGTH_RATIO";vecsize",                  "500.0",     OPTION_FLOAT,      "Vector fade length (4.0 - vectors fade the most at and above 4 pixels, etc.)" },
397   /* Bloom below this line */
398   { NULL,                                                     NULL,        OPTION_HEADER,     "BLOOM POST-PROCESSING OPTIONS" },
399   { WINOPTION_VECTOR_BLOOM_SCALE,                             "0.3",       OPTION_FLOAT,      "Intensity factor for vector bloom" },
400   { WINOPTION_RASTER_BLOOM_SCALE,                             "0.225",     OPTION_FLOAT,      "Intensity factor for raster bloom" },
401   { WINOPTION_BLOOM_LEVEL0_WEIGHT,                          "1.0",       OPTION_FLOAT,      "Bloom level 0  (full-size target) weight" },
402   { WINOPTION_BLOOM_LEVEL1_WEIGHT,                          "0.21",      OPTION_FLOAT,      "Bloom level 1  (half-size target) weight" },
403   { WINOPTION_BLOOM_LEVEL2_WEIGHT,                          "0.19",      OPTION_FLOAT,      "Bloom level 2  (quarter-size target) weight" },
404   { WINOPTION_BLOOM_LEVEL3_WEIGHT,                          "0.17",      OPTION_FLOAT,      "Bloom level 3  (.) weight" },
405   { WINOPTION_BLOOM_LEVEL4_WEIGHT,                          "0.15",      OPTION_FLOAT,      "Bloom level 4  (.) weight" },
406   { WINOPTION_BLOOM_LEVEL5_WEIGHT,                          "0.14",      OPTION_FLOAT,      "Bloom level 5  (.) weight" },
407   { WINOPTION_BLOOM_LEVEL6_WEIGHT,                          "0.13",      OPTION_FLOAT,      "Bloom level 6  (.) weight" },
408   { WINOPTION_BLOOM_LEVEL7_WEIGHT,                          "0.12",      OPTION_FLOAT,      "Bloom level 7  (.) weight" },
409   { WINOPTION_BLOOM_LEVEL8_WEIGHT,                          "0.11",      OPTION_FLOAT,      "Bloom level 8  (.) weight" },
410   { WINOPTION_BLOOM_LEVEL9_WEIGHT,                          "0.10",      OPTION_FLOAT,      "Bloom level 9  (.) weight" },
411   { WINOPTION_BLOOM_LEVEL10_WEIGHT,                           "0.09",      OPTION_FLOAT,      "Bloom level 10 (1x1 target) weight" },
412
334413   // per-window options
335414   { NULL,                                           NULL,       OPTION_HEADER,     "PER-WINDOW VIDEO OPTIONS" },
336415   { WINOPTION_SCREEN,                               "auto",     OPTION_STRING,     "explicit name of all screens; 'auto' here will try to make a best guess" },
trunk/src/osd/windows/video.c
r23474r23475
366366   // check for toggling fullscreen mode
367367   if (ui_input_pressed(machine, IPT_OSD_1))
368368      winwindow_toggle_full_screen();
369
370   // check for taking fullscreen snap
371   if (ui_input_pressed(machine, IPT_OSD_2))
372      winwindow_take_snap();
373
374   // check for taking fullscreen video
375   if (ui_input_pressed(machine, IPT_OSD_3))
376      winwindow_take_video();
377
378   // check for taking fullscreen video
379   if (ui_input_pressed(machine, IPT_OSD_4))
380      winwindow_toggle_fsfx();
369381}
370382
371383
trunk/src/osd/windows/winmain.h
r23474r23475
7777// Direct3D-specific options
7878#define WINOPTION_FILTER                "filter"
7979
80// core post-processing options
81#define WINOPTION_HLSL_ENABLE               "hlsl_enable"
82#define WINOPTION_HLSLPATH                  "hlslpath"
83#define WINOPTION_HLSL_INI_NAME             "hlslini"
84#define WINOPTION_HLSL_INI_WRITE            "hlsl_ini_write"
85#define WINOPTION_HLSL_INI_READ             "hlsl_ini_read"
86#define WINOPTION_HLSL_PRESCALE_X           "hlsl_prescale_x"
87#define WINOPTION_HLSL_PRESCALE_Y           "hlsl_prescale_y"
88#define WINOPTION_HLSL_PRESET               "hlsl_preset"
89#define WINOPTION_HLSL_WRITE                "hlsl_write"
90#define WINOPTION_HLSL_SNAP_WIDTH           "hlsl_snap_width"
91#define WINOPTION_HLSL_SNAP_HEIGHT          "hlsl_snap_height"
92#define WINOPTION_SHADOW_MASK_ALPHA         "shadow_mask_alpha"
93#define WINOPTION_SHADOW_MASK_TEXTURE       "shadow_mask_texture"
94#define WINOPTION_SHADOW_MASK_COUNT_X       "shadow_mask_x_count"
95#define WINOPTION_SHADOW_MASK_COUNT_Y       "shadow_mask_y_count"
96#define WINOPTION_SHADOW_MASK_USIZE         "shadow_mask_usize"
97#define WINOPTION_SHADOW_MASK_VSIZE         "shadow_mask_vsize"
98#define WINOPTION_PINCUSHION                "pincushion"
99#define WINOPTION_CURVATURE                 "curvature"
100#define WINOPTION_SCANLINE_AMOUNT           "scanline_alpha"
101#define WINOPTION_SCANLINE_SCALE            "scanline_size"
102#define WINOPTION_SCANLINE_HEIGHT           "scanline_height"
103#define WINOPTION_SCANLINE_BRIGHT_SCALE     "scanline_bright_scale"
104#define WINOPTION_SCANLINE_BRIGHT_OFFSET    "scanline_bright_offset"
105#define WINOPTION_SCANLINE_OFFSET           "scanline_jitter"
106#define WINOPTION_DEFOCUS                   "defocus"
107#define WINOPTION_CONVERGE_X                "converge_x"
108#define WINOPTION_CONVERGE_Y                "converge_y"
109#define WINOPTION_RADIAL_CONVERGE_X         "radial_converge_x"
110#define WINOPTION_RADIAL_CONVERGE_Y         "radial_converge_y"
111#define WINOPTION_RED_RATIO                 "red_ratio"
112#define WINOPTION_GRN_RATIO                 "grn_ratio"
113#define WINOPTION_BLU_RATIO                 "blu_ratio"
114#define WINOPTION_OFFSET                    "offset"
115#define WINOPTION_SCALE                     "scale"
116#define WINOPTION_POWER                     "power"
117#define WINOPTION_FLOOR                     "floor"
118#define WINOPTION_PHOSPHOR                  "phosphor_life"
119#define WINOPTION_SATURATION                "saturation"
120#define WINOPTION_YIQ_ENABLE                "yiq_enable"
121#define WINOPTION_YIQ_CCVALUE               "yiq_cc"
122#define WINOPTION_YIQ_AVALUE                "yiq_a"
123#define WINOPTION_YIQ_BVALUE                "yiq_b"
124#define WINOPTION_YIQ_OVALUE                "yiq_o"
125#define WINOPTION_YIQ_PVALUE                "yiq_p"
126#define WINOPTION_YIQ_NVALUE                "yiq_n"
127#define WINOPTION_YIQ_YVALUE                "yiq_y"
128#define WINOPTION_YIQ_IVALUE                "yiq_i"
129#define WINOPTION_YIQ_QVALUE                "yiq_q"
130#define WINOPTION_YIQ_SCAN_TIME             "yiq_scan_time"
131#define WINOPTION_YIQ_PHASE_COUNT           "yiq_phase_count"
132#define WINOPTION_VECTOR_LENGTH_SCALE       "vector_length_scale"
133#define WINOPTION_VECTOR_LENGTH_RATIO       "vector_length_ratio"
134#define WINOPTION_VECTOR_BLOOM_SCALE        "vector_bloom_scale"
135#define WINOPTION_RASTER_BLOOM_SCALE        "raster_bloom_scale"
136#define WINOPTION_BLOOM_LEVEL0_WEIGHT       "bloom_lvl0_weight"
137#define WINOPTION_BLOOM_LEVEL1_WEIGHT       "bloom_lvl1_weight"
138#define WINOPTION_BLOOM_LEVEL2_WEIGHT       "bloom_lvl2_weight"
139#define WINOPTION_BLOOM_LEVEL3_WEIGHT       "bloom_lvl3_weight"
140#define WINOPTION_BLOOM_LEVEL4_WEIGHT       "bloom_lvl4_weight"
141#define WINOPTION_BLOOM_LEVEL5_WEIGHT       "bloom_lvl5_weight"
142#define WINOPTION_BLOOM_LEVEL6_WEIGHT       "bloom_lvl6_weight"
143#define WINOPTION_BLOOM_LEVEL7_WEIGHT       "bloom_lvl7_weight"
144#define WINOPTION_BLOOM_LEVEL8_WEIGHT       "bloom_lvl8_weight"
145#define WINOPTION_BLOOM_LEVEL9_WEIGHT       "bloom_lvl9_weight"
146#define WINOPTION_BLOOM_LEVEL10_WEIGHT      "bloom_lvl10_weight"
147
80148// per-window options
81149#define WINOPTION_SCREEN                "screen"
82150#define WINOPTION_ASPECT                "aspect"
r23474r23475
138206   // Direct3D-specific options
139207   bool filter() const { return bool_value(WINOPTION_FILTER); }
140208
209   // core post-processing options
210   const char *screen_post_fx_dir() const { return value(WINOPTION_HLSLPATH); }
211   const char *hlsl_ini_name() const { return value(WINOPTION_HLSL_INI_NAME); }
212   bool d3d_hlsl_enable() const { return bool_value(WINOPTION_HLSL_ENABLE); }
213   bool hlsl_write_ini() const { return bool_value(WINOPTION_HLSL_INI_WRITE); }
214   bool hlsl_read_ini() const { return bool_value(WINOPTION_HLSL_INI_READ); }
215   const char *d3d_hlsl_write() const { return value(WINOPTION_HLSL_WRITE); }
216   int d3d_hlsl_prescale_x() const { return int_value(WINOPTION_HLSL_PRESCALE_X); }
217   int d3d_hlsl_prescale_y() const { return int_value(WINOPTION_HLSL_PRESCALE_Y); }
218   int d3d_hlsl_preset() const { return int_value(WINOPTION_HLSL_PRESET); }
219   int d3d_snap_width() const { return int_value(WINOPTION_HLSL_SNAP_WIDTH); }
220   int d3d_snap_height() const { return int_value(WINOPTION_HLSL_SNAP_HEIGHT); }
221   float screen_shadow_mask_alpha() const { return float_value(WINOPTION_SHADOW_MASK_ALPHA); }
222   const char *screen_shadow_mask_texture() const { return value(WINOPTION_SHADOW_MASK_TEXTURE); }
223   int screen_shadow_mask_count_x() const { return int_value(WINOPTION_SHADOW_MASK_COUNT_X); }
224   int screen_shadow_mask_count_y() const { return int_value(WINOPTION_SHADOW_MASK_COUNT_Y); }
225   float screen_shadow_mask_u_size() const { return float_value(WINOPTION_SHADOW_MASK_USIZE); }
226   float screen_shadow_mask_v_size() const { return float_value(WINOPTION_SHADOW_MASK_VSIZE); }
227   float screen_scanline_amount() const { return float_value(WINOPTION_SCANLINE_AMOUNT); }
228   float screen_scanline_scale() const { return float_value(WINOPTION_SCANLINE_SCALE); }
229   float screen_scanline_height() const { return float_value(WINOPTION_SCANLINE_HEIGHT); }
230   float screen_scanline_bright_scale() const { return float_value(WINOPTION_SCANLINE_BRIGHT_SCALE); }
231   float screen_scanline_bright_offset() const { return float_value(WINOPTION_SCANLINE_BRIGHT_OFFSET); }
232   float screen_scanline_offset() const { return float_value(WINOPTION_SCANLINE_OFFSET); }
233   float screen_pincushion() const { return float_value(WINOPTION_PINCUSHION); }
234   float screen_curvature() const { return float_value(WINOPTION_CURVATURE); }
235   const char *screen_defocus() const { return value(WINOPTION_DEFOCUS); }
236   const char *screen_converge_x() const { return value(WINOPTION_CONVERGE_X); }
237   const char *screen_converge_y() const { return value(WINOPTION_CONVERGE_Y); }
238   const char *screen_radial_converge_x() const { return value(WINOPTION_RADIAL_CONVERGE_X); }
239   const char *screen_radial_converge_y() const { return value(WINOPTION_RADIAL_CONVERGE_Y); }
240   const char *screen_red_ratio() const { return value(WINOPTION_RED_RATIO); }
241   const char *screen_grn_ratio() const { return value(WINOPTION_GRN_RATIO); }
242   const char *screen_blu_ratio() const { return value(WINOPTION_BLU_RATIO); }
243   bool screen_yiq_enable() const { return bool_value(WINOPTION_YIQ_ENABLE); }
244   float screen_yiq_cc() const { return float_value(WINOPTION_YIQ_CCVALUE); }
245   float screen_yiq_a() const { return float_value(WINOPTION_YIQ_AVALUE); }
246   float screen_yiq_b() const { return float_value(WINOPTION_YIQ_BVALUE); }
247   float screen_yiq_o() const { return float_value(WINOPTION_YIQ_OVALUE); }
248   float screen_yiq_p() const { return float_value(WINOPTION_YIQ_PVALUE); }
249   float screen_yiq_n() const { return float_value(WINOPTION_YIQ_NVALUE); }
250   float screen_yiq_y() const { return float_value(WINOPTION_YIQ_YVALUE); }
251   float screen_yiq_i() const { return float_value(WINOPTION_YIQ_IVALUE); }
252   float screen_yiq_q() const { return float_value(WINOPTION_YIQ_QVALUE); }
253   float screen_yiq_scan_time() const { return float_value(WINOPTION_YIQ_SCAN_TIME); }
254   int screen_yiq_phase_count() const { return int_value(WINOPTION_YIQ_PHASE_COUNT); }
255   float screen_vector_length_scale() const { return float_value(WINOPTION_VECTOR_LENGTH_SCALE); }
256   float screen_vector_length_ratio() const { return float_value(WINOPTION_VECTOR_LENGTH_RATIO); }
257   float screen_vector_bloom_scale() const { return float_value(WINOPTION_VECTOR_BLOOM_SCALE); }
258   float screen_raster_bloom_scale() const { return float_value(WINOPTION_RASTER_BLOOM_SCALE); }
259   float screen_bloom_lvl0_weight() const { return float_value(WINOPTION_BLOOM_LEVEL0_WEIGHT); }
260   float screen_bloom_lvl1_weight() const { return float_value(WINOPTION_BLOOM_LEVEL1_WEIGHT); }
261   float screen_bloom_lvl2_weight() const { return float_value(WINOPTION_BLOOM_LEVEL2_WEIGHT); }
262   float screen_bloom_lvl3_weight() const { return float_value(WINOPTION_BLOOM_LEVEL3_WEIGHT); }
263   float screen_bloom_lvl4_weight() const { return float_value(WINOPTION_BLOOM_LEVEL4_WEIGHT); }
264   float screen_bloom_lvl5_weight() const { return float_value(WINOPTION_BLOOM_LEVEL5_WEIGHT); }
265   float screen_bloom_lvl6_weight() const { return float_value(WINOPTION_BLOOM_LEVEL6_WEIGHT); }
266   float screen_bloom_lvl7_weight() const { return float_value(WINOPTION_BLOOM_LEVEL7_WEIGHT); }
267   float screen_bloom_lvl8_weight() const { return float_value(WINOPTION_BLOOM_LEVEL8_WEIGHT); }
268   float screen_bloom_lvl9_weight() const { return float_value(WINOPTION_BLOOM_LEVEL9_WEIGHT); }
269   float screen_bloom_lvl10_weight() const { return float_value(WINOPTION_BLOOM_LEVEL10_WEIGHT); }
270   const char *screen_offset() const { return value(WINOPTION_OFFSET); }
271   const char *screen_scale() const { return value(WINOPTION_SCALE); }
272   const char *screen_power() const { return value(WINOPTION_POWER); }
273   const char *screen_floor() const { return value(WINOPTION_FLOOR); }
274   const char *screen_phosphor() const { return value(WINOPTION_PHOSPHOR); }
275   float screen_saturation() const { return float_value(WINOPTION_SATURATION); }
276
141277   // per-window options
142278   const char *screen() const { return value(WINOPTION_SCREEN); }
143279   const char *aspect() const { return value(WINOPTION_ASPECT); }
r23474r23475
202338   virtual void update_audio_stream(const INT16 *buffer, int samples_this_frame);
203339   virtual void set_mastervolume(int attenuation);
204340
341   // video overridables
342   virtual void *get_slider_list();
343
205344   // input overridables
206345   virtual void customize_input_type_list(simple_list<input_type_entry> &typelist);
207346
r23474r23475
210349   virtual void font_close(osd_font font);
211350   virtual bool font_get_bitmap(osd_font font, unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
212351
213   virtual void set_shader_system(void *shader_system) { m_shader_system = shader_system; }
214   virtual void *shader_system() { return m_shader_system; }
215
216352private:
217   void * m_shader_system;
218
219353   static void osd_exit(running_machine &machine);
220354
221355   static const int DEFAULT_FONT_HEIGHT = 200;
trunk/src/osd/windows/drawnone.c
r23474r23475
7777   callbacks->window_draw = drawnone_window_draw;
7878   callbacks->window_save = NULL;
7979   callbacks->window_record = NULL;
80   callbacks->window_toggle_fsfx = NULL;
8081   callbacks->window_destroy = drawnone_window_destroy;
8182   return 0;
8283}
trunk/src/osd/windows/d3d9intf.c
r23474r23475
102102//  drawd3d9_init
103103//============================================================
104104
105base *drawd3d9_init()
105base *drawd3d9_init(void)
106106{
107107   direct3dcreate9_ptr direct3dcreate9;
108108   HINSTANCE dllhandle;
109109   IDirect3D9 *d3d9;
110110   base *d3dptr;
111   bool post_available = true;
111112
112113   // dynamically grab the create function from d3d9.dll
113114   dllhandle = LoadLibrary(TEXT("d3d9.dll"));
r23474r23475
138139   }
139140
140141   // dynamically grab the shader load function from d3dx9.dll
141   g_load_effect = NULL;
142   HINSTANCE fxhandle = LoadLibrary(TEXT("d3dx9_43.dll"));
143   if (fxhandle == NULL)
144   {
145      post_available = false;
146      mame_printf_verbose("Direct3D: Warning - Unable to access d3dx9_43.dll; disabling post-effect rendering\n");
147   }
142148
149   // import the create function
150   if(post_available)
151   {
152      g_load_effect = (direct3dx9_loadeffect_ptr)GetProcAddress(fxhandle, "D3DXCreateEffectFromFileW");
153      if (g_load_effect == NULL)
154      {
155         printf("Direct3D: Unable to find D3DXCreateEffectFromFileW\n");
156         FreeLibrary(dllhandle);
157         fxhandle = NULL;
158         dllhandle = NULL;
159         return NULL;
160      }
161   }
162   else
163   {
164      g_load_effect = NULL;
165      post_available = false;
166      mame_printf_verbose("Direct3D: Warning - Unable to get a handle to D3DXCreateEffectFromFileW; disabling post-effect rendering\n");
167   }
168
143169   // allocate an object to hold our data
144170   d3dptr = global_alloc(base);
145171   d3dptr->version = 9;
146172   d3dptr->d3dobj = d3d9;
147173   d3dptr->dllhandle = dllhandle;
174   d3dptr->post_fx_available = post_available;
148175   set_interfaces(d3dptr);
149176
150177   mame_printf_verbose("Direct3D: Using Direct3D 9\n");
trunk/src/osd/windows/drawd3d.c
r23474r23475
217217static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window);
218218static void drawd3d_window_save(win_window_info *window);
219219static void drawd3d_window_record(win_window_info *window);
220static void drawd3d_window_toggle_fsfx(win_window_info *window);
220221static int drawd3d_window_draw(win_window_info *window, HDC dc, int update);
221222
222223
r23474r23475
250251      (*d3dintf->d3d.release)(d3dintf);
251252}
252253
254static void drawd3d_window_toggle_fsfx(win_window_info *window)
255{
256   d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
257   d3d->set_restarting(true);
258}
259
253260static void drawd3d_window_record(win_window_info *window)
254261{
262   d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
263   d3d->get_shaders()->window_record();
255264}
256265
257266static void drawd3d_window_save(win_window_info *window)
258267{
268   d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
269   d3d->get_shaders()->window_save();
259270}
260271
261272
r23474r23475
272283   if (d3d == NULL)
273284      return;
274285
286   if (d3d->get_shaders()->recording())
287      d3d->get_shaders()->window_record();
288
275289   // free the memory in the window
276290   global_free(d3d);
277291   window->drawdata = NULL;
r23474r23475
318332   callbacks->window_draw = drawd3d_window_draw;
319333   callbacks->window_save = drawd3d_window_save;
320334   callbacks->window_record = drawd3d_window_record;
335   callbacks->window_toggle_fsfx = drawd3d_window_toggle_fsfx;
321336   callbacks->window_destroy = drawd3d_window_destroy;
322337   return 0;
323338}
r23474r23475
354369      m_last_texture = texture;
355370      m_last_texture_flags = (texture == NULL ? 0 : texture->get_flags());
356371      HRESULT result = (*d3dintf->device.set_texture)(m_device, 0, (texture == NULL) ? get_default_texture()->get_finaltex() : texture->get_finaltex());
372      m_shaders->set_texture(texture);
357373      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result);
358374   }
359375}
r23474r23475
615631         texture->get_texinfo().height == texinfo->height &&
616632         ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
617633      {
618         return texture;
634         // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
635         if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0)
636         {
637            if (m_renderer->get_shaders()->find_render_target(texture) != NULL)
638            {
639               return texture;
640            }
641         }
642         else
643         {
644            return texture;
645         }
619646      }
620647   }
621648
649   // Nothing found
650   /*int checkidx = 0;
651   for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next())
652   {
653       printf("Checking texture index %d\n", checkidx);
654       UINT32 test_screen = (UINT32)texture->get_texinfo().osddata >> 1;
655       UINT32 test_page = (UINT32)texture->get_texinfo().osddata & 1;
656       UINT32 prim_screen = (UINT32)texinfo->osddata >> 1;
657       UINT32 prim_page = (UINT32)texinfo->osddata & 1;
658       if (test_screen != prim_screen || test_page != prim_page)
659       {
660           printf("No screen/page match: %d vs. %d, %d vs. %d\n", test_screen, prim_screen, test_page, prim_page);
661           continue;
662       }
663
664       if (texture->get_hash() == hash &&
665           texture->get_texinfo().base == texinfo->base &&
666           texture->get_texinfo().width == texinfo->width &&
667           texture->get_texinfo().height == texinfo->height &&
668           ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
669       {
670           // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
671           if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0)
672           {
673               if (m_renderer->get_shaders()->find_render_target(texture) != NULL)
674               {
675                   return texture;
676               }
677           }
678           else
679           {
680               return texture;
681           }
682       }
683
684       if (texture->get_hash() != hash)
685       {
686           printf("No hash match: %d vs. %d\n", texture->get_hash(), hash);
687       }
688       if (texture->get_texinfo().base != texinfo->base)
689       {
690           printf("No base match\n");
691       }
692       if (texture->get_texinfo().width != texinfo->width)
693       {
694           printf("No width match: %d vs. %d\n", texture->get_texinfo().width, texinfo->width);
695       }
696       if (texture->get_texinfo().height != texinfo->height)
697       {
698           printf("No height match: %d vs. %d\n", texture->get_texinfo().height, texinfo->height);
699       }
700       if (((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) != 0)
701       {
702           printf("No flag match: %08x & %08x = %08x\n", texture->get_flags(), flags, ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)));
703       }
704       printf("\n");
705       checkidx++;
706   }
707
708   printf("\n\n\n\n");*/
709
710   // Nothing found, check if we need to unregister something with HLSL
711   if (m_renderer->get_shaders()->enabled())
712   {
713      if (texinfo->width == 0 || texinfo->height == 0)
714      {
715         return NULL;
716      }
717
718      UINT32 prim_screen = texinfo->osddata >> 1;
719      UINT32 prim_page = texinfo->osddata & 1;
720
721      for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next())
722      {
723         UINT32 test_screen = texture->get_texinfo().osddata >> 1;
724         UINT32 test_page = texture->get_texinfo().osddata & 1;
725         if (test_screen != prim_screen || test_page != prim_page)
726         {
727            continue;
728         }
729
730         // Clear out our old texture reference
731         if (texture->get_hash() == hash &&
732            texture->get_texinfo().base == texinfo->base &&
733            ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0 &&
734            (texture->get_texinfo().width != texinfo->width ||
735               texture->get_texinfo().height != texinfo->height))
736         {
737            m_renderer->get_shaders()->remove_render_target(texture);
738         }
739      }
740   }
741
622742   return NULL;
623743}
624744
r23474r23475
627747   m_device = NULL;
628748   m_restarting = false;
629749   m_window = window;
750   m_shaders = NULL;
630751   m_numverts = 0;
631752   m_numpolys = 0;
632753   m_vertexbuf = NULL;
633754   m_lockedbuf = NULL;
634755   m_vectorbatch = NULL;
635756   m_last_texture = NULL;
757   m_hlsl_buf = NULL;
636758   m_texture_manager = NULL;
637759}
638760
r23474r23475
658780   // if we're restarting the renderer, leave things alone
659781   if (m_restarting)
660782   {
783      m_shaders->toggle();
784
661785      // free all existing resources and re-create
662786      device_delete_resources();
663787      device_create_resources();
r23474r23475
711835            }
712836         }
713837      }
838      else if(m_renderer->get_shaders()->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags))
839      {
840         if (!m_renderer->get_shaders()->get_vector_target())
841         {
842            m_renderer->get_shaders()->create_vector_target(prim);
843         }
844      }
714845   }
715846}
716847
r23474r23475
719850   HRESULT result = (*d3dintf->device.clear)(m_device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
720851   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
721852
853   m_shaders->begin_frame();
854
722855   m_window->primlist->acquire_lock();
723856
724857   // first update any textures
r23474r23475
731864
732865   m_lockedbuf = NULL;
733866
867   if(m_shaders->enabled())
868   {
869      m_hlsl_buf = (void*)mesh_alloc(6);
870      m_shaders->init_fsfx_quad(m_hlsl_buf);
871   }
872
734873   m_line_count = 0;
735874   // loop over primitives
736875   for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next())
r23474r23475
740879
741880void renderer::process_primitives()
742881{
882   if (m_line_count && m_shaders->enabled() && d3dintf->post_fx_available)
883   {
884      batch_vectors();
885   }
886
743887   // Rotating index for vector time offsets
744888   for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next())
745889   {
r23474r23475
764908            throw emu_fatalerror("Unexpected render_primitive type");
765909      }
766910   }
911
912   if (m_line_count && !(m_shaders->enabled() && d3dintf->post_fx_available))
913   {
914      batch_vectors();
915   }
767916}
768917
769918void renderer::end_frame()
r23474r23475
773922   // flush any pending polygons
774923   primitive_flush_pending();
775924
925   m_shaders->end_frame();
926
776927   // finish the scene
777928   HRESULT result = (*d3dintf->device.end_scene)(m_device);
778929   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device end_scene call\n", (int)result);
r23474r23475
9021053      }
9031054   }
9041055
1056   int ret = m_shaders->create_resources(false);
1057   if (ret != 0)
1058      return ret;
1059
9051060   return device_create_resources();
9061061}
9071062
r23474r23475
9171072   HRESULT result = (*d3dintf->device.create_vertex_buffer)(m_device,
9181073            sizeof(vertex) * VERTEX_BUFFER_SIZE,
9191074            D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY,
920            VERTEX_BASE_FORMAT | D3DFVF_XYZRHW,
1075            VERTEX_BASE_FORMAT | ((m_shaders->enabled() && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW),
9211076            D3DPOOL_DEFAULT, &m_vertexbuf);
9221077   if (result != D3D_OK)
9231078   {
r23474r23475
9261081   }
9271082
9281083   // set the vertex format
929   result = (*d3dintf->device.set_vertex_format)(m_device, (D3DFORMAT)(VERTEX_BASE_FORMAT | D3DFVF_XYZRHW));
1084   result = (*d3dintf->device.set_vertex_format)(m_device, (D3DFORMAT)(VERTEX_BASE_FORMAT | ((m_shaders->enabled() &&
1085      d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW)));
9301086   if (result != D3D_OK)
9311087   {
9321088      mame_printf_error("Error setting vertex format (%08X)", (UINT32)result);
r23474r23475
9831139
9841140void renderer::device_delete()
9851141{
1142   // free our effects
1143   m_shaders->delete_resources(false);
1144
1145   // delete the HLSL interface
1146   global_free(m_shaders);
1147
9861148   // free our base resources
9871149   device_delete_resources();
9881150
r23474r23475
10241186{
10251187   int retval = 0;
10261188
1189   m_shaders = global_alloc_clear(shaders);
1190   m_shaders->init(d3dintf, m_window);
1191
10271192   DWORD tempcaps;
1193   HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps);
1194   if (result != D3D_OK) mame_printf_verbose("Direct3D Error %08X during get_caps_dword call\n", (int)result);
1195   if(tempcaps < 512)
1196   {
1197      mame_printf_verbose("Direct3D: Warning - Device does not support Pixel Shader 3.0, falling back to non-PS rendering\n");
1198      d3dintf->post_fx_available = false;
1199   }
10281200
10291201   // verify presentation capabilities
1030   HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_PRESENTATION_INTERVALS, &tempcaps);
1202   result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_PRESENTATION_INTERVALS, &tempcaps);
10311203   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
10321204   if (!(tempcaps & D3DPRESENT_INTERVAL_IMMEDIATE))
10331205   {
r23474r23475
10941266
10951267      // free all existing resources and call reset on the device
10961268      device_delete_resources();
1269      m_shaders->delete_resources(true);
10971270      result = (*d3dintf->device.reset)(m_device, &m_presentation);
10981271
10991272      // if it didn't work, punt to GDI
r23474r23475
11101283         device_delete();
11111284         return 1;
11121285      }
1286
1287      if (m_shaders->create_resources(true))
1288      {
1289         mame_printf_verbose("Direct3D: failed to recreate HLSL resources for device; failing permanently\n");
1290         device_delete();
1291         return 1;
1292      }
11131293   }
11141294   return 0;
11151295}
r23474r23475
13641544   m_vectorbatch = mesh_alloc(m_line_count * vector_size);
13651545   m_batchindex = 0;
13661546
1367   //static int start_index = 0;
1368   //int line_index = 0;
1369   //float period = options.screen_vector_time_period();
1547   static int start_index = 0;
1548   int line_index = 0;
1549   float period = options.screen_vector_time_period();
13701550   UINT32 cached_flags = 0;
13711551   for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next())
13721552   {
r23474r23475
13751555         case render_primitive::LINE:
13761556            if (PRIMFLAG_GET_VECTOR(prim->flags))
13771557            {
1378               /*if (period == 0.0f || m_line_count == 0)
1558               if (period == 0.0f || m_line_count == 0)
13791559               {
13801560                  batch_vector(prim, 1.0f);
13811561               }
1382               else*/
1562               else
13831563               {
1384                  batch_vector(prim, 1.0f);//(float)(start_index + line_index) / ((float)m_line_count * period));
1385                  //line_index++;
1564                  batch_vector(prim, (float)(start_index + line_index) / ((float)m_line_count * period));
1565                  line_index++;
13861566               }
13871567               cached_flags = prim->flags;
13881568            }
r23474r23475
13991579      m_texture_manager->get_vector_texture(), D3DTOP_MODULATE, 0.0f, 1.0f, 0.0f, 0.0f);
14001580   m_numpolys++;
14011581
1402   //start_index += (int)((float)line_index * period);
1403   //if (m_line_count > 0)
1404   //{
1405   //   start_index %= m_line_count;
1406   //}
1582   start_index += (int)((float)line_index * period);
1583   if (m_line_count > 0)
1584   {
1585      start_index %= m_line_count;
1586   }
14071587}
14081588
14091589void renderer::batch_vector(const render_primitive *prim, float line_time)
r23474r23475
16991879   // if we're going to overflow, flush
17001880   if (m_lockedbuf != NULL && m_numverts + numverts >= VERTEX_BUFFER_SIZE)
17011881   {
1882      printf("request for %d verts\n", numverts);
17021883      primitive_flush_pending();
1884
1885      if(m_shaders->enabled())
1886      {
1887         m_hlsl_buf = (void*)mesh_alloc(6);
1888         m_shaders->init_fsfx_quad(m_hlsl_buf);
1889      }
17031890   }
17041891
17051892   // if we don't have a lock, grab it now
r23474r23475
17431930   result = (*d3dintf->device.set_stream_source)(m_device, 0, m_vertexbuf, sizeof(vertex));
17441931   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_stream_source call\n", (int)result);
17451932
1933   m_shaders->begin_draw();
1934
17461935   int vertnum = 0;
1936   if (m_shaders->enabled())
1937   {
1938      vertnum = 6;
1939   }
17471940
17481941   // now do the polys
17491942   for (int polynum = 0; polynum < m_numpolys; polynum++)
r23474r23475
17641957         set_filter(newfilter);
17651958         set_wrap(PRIMFLAG_GET_TEXWRAP(flags) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
17661959         set_modmode(m_poly[polynum].get_modmode());
1960
1961         m_shaders->init_effect_info(&m_poly[polynum]);
17671962      }
17681963
17691964      // set the blendmode if different
r23474r23475
17771972
17781973      assert(vertnum + m_poly[polynum].get_vertcount() <= m_numverts);
17791974
1780      // add the primitives
1781      result = (*d3dintf->device.draw_primitive)(m_device, m_poly[polynum].get_type(), vertnum,
1782                                       m_poly[polynum].get_count());
1783      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1975      if(m_shaders->enabled() && d3dintf->post_fx_available)
1976      {
1977         m_shaders->render_quad(&m_poly[polynum], vertnum);
1978      }
1979      else
1980      {
1981         // add the primitives
1982         result = (*d3dintf->device.draw_primitive)(m_device, m_poly[polynum].get_type(), vertnum,
1983                                          m_poly[polynum].get_count());
1984         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1985      }
17841986
17851987      vertnum += m_poly[polynum].get_vertcount();
17861988   }
17871989
1990   m_shaders->end_draw();
1991
17881992   // reset the vertex count
17891993   m_numverts = 0;
17901994   m_numpolys = 0;
r23474r23475
19132117            {
19142118               m_d3dfinaltex = m_d3dtex;
19152119               m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
2120
2121               if (m_renderer->get_shaders()->enabled() && !m_renderer->get_shaders()->register_texture(this))
2122               {
2123                  goto error;
2124               }
2125
19162126               break;
19172127            }
19182128         }
r23474r23475
19522162            result = (*d3dintf->device.create_texture)(m_renderer->get_device(), scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &m_d3dfinaltex);
19532163            if (result == D3D_OK)
19542164            {
2165               if (m_renderer->get_shaders()->enabled() && !m_renderer->get_shaders()->register_prescaled_texture(this))
2166               {
2167                  goto error;
2168               }
19552169               break;
19562170            }
19572171            (*d3dintf->texture.release)(m_d3dtex);
r23474r23475
19732187   return;
19742188
19752189error:
2190   d3dintf->post_fx_available = false;
19762191   printf("Direct3D: Critical warning: A texture failed to allocate. Expect things to get bad quickly.\n");
19772192   if (m_d3dsurface != NULL)
19782193      (*d3dintf->surface.release)(m_d3dsurface);
trunk/src/osd/windows/d3dhlsl.c
r0r23475
1//============================================================
2//
3//  d3dhlsl.c - Win32 Direct3D HLSL implementation
4//
5//============================================================
6//
7//  Copyright Aaron Giles
8//  All rights reserved.
9//
10//  Redistribution and use in source and binary forms, with or
11//  without modification, are permitted provided that the
12//  following conditions are met:
13//
14//    * Redistributions of source code must retain the above
15//      copyright notice, this list of conditions and the
16//      following disclaimer.
17//    * Redistributions in binary form must reproduce the
18//      above copyright notice, this list of conditions and
19//      the following disclaimer in the documentation and/or
20//      other materials provided with the distribution.
21//    * Neither the name 'MAME' nor the names of its
22//      contributors may be used to endorse or promote
23//      products derived from this software without specific
24//      prior written permission.
25//
26//  THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND
27//  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29//  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30//  EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
31//  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32//  DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33//  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35//  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37//  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38//  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39//
40//============================================================
41
42// Useful info:
43//  Windows XP/2003 shipped with DirectX 8.1
44//  Windows 2000 shipped with DirectX 7a
45//  Windows 98SE shipped with DirectX 6.1a
46//  Windows 98 shipped with DirectX 5
47//  Windows NT shipped with DirectX 3.0a
48//  Windows 95 shipped with DirectX 2
49
50// standard windows headers
51#define WIN32_LEAN_AND_MEAN
52#include <windows.h>
53#include <tchar.h>
54#include <mmsystem.h>
55#include <d3d9.h>
56#include <d3dx9.h>
57#include <math.h>
58#undef interface
59
60// MAME headers
61#include "emu.h"
62#include "render.h"
63#include "ui.h"
64#include "rendutil.h"
65#include "options.h"
66#include "emuopts.h"
67#include "aviio.h"
68#include "png.h"
69#include "screen.h"
70
71// MAMEOS headers
72#include "d3dintf.h"
73#include "winmain.h"
74#include "window.h"
75#include "config.h"
76#include "strconv.h"
77#include "d3dcomm.h"
78#include "drawd3d.h"
79
80
81
82//============================================================
83//  GLOBALS
84//============================================================
85
86static slider_state *g_slider_list;
87static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *templ, const char *extension, int idx);
88
89namespace d3d
90{
91
92hlsl_options shaders::s_hlsl_presets[4] =
93{
94   {   // 25% Shadow mask, 50% Scanlines, 3% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation
95      true,
96      0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f,
97      0.03f, 0.03f,
98      0.5f, 1.0f, 0.5f, 1.0f, 0.0f, 0.0f,
99      { 0.0f, 0.0f, 0.0f, 0.0f },
100      { 0.0f, 0.0f, 0.0f },
101      { 0.0f, 0.0f, 0.0f },
102      { 0.0f, 0.0f, 0.0f },
103      { 0.0f, 0.0f, 0.0f },
104      { 1.0f, 0.0f, 0.0f },
105      { 0.0f, 1.0f, 0.0f },
106      { 0.0f, 0.0f, 1.0f },
107      { 0.0f, 0.0f, 0.0f },
108      { 1.0f, 1.0f, 1.0f },
109      { 0.9f, 0.9f, 0.9f },
110      { 0.05f,0.05f,0.05f},
111      { 0.25f,0.25f,0.25f},
112      1.2f,
113      false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0,
114      0.9f, 4.0f,
115      1.0f, 0.21f, 0.19f, 0.17f, 0.15f, 0.14f, 0.13f, 0.12f, 0.11f, 0.10f, 0.09f
116   },
117   {   // 25% Shadow mask, 0% Scanlines, 3% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation
118      true,
119      0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f,
120      0.03f, 0.03f,
121      0.0f, 1.0f, 0.5f, 1.0f, 0.0f, 0.0f,
122      { 0.0f, 0.0f, 0.0f, 0.0f },
123      { 0.0f, 0.0f, 0.0f },
124      { 0.0f, 0.0f, 0.0f },
125      { 0.0f, 0.0f, 0.0f },
126      { 0.0f, 0.0f, 0.0f },
127      { 1.0f, 0.0f, 0.0f },
128      { 0.0f, 1.0f, 0.0f },
129      { 0.0f, 0.0f, 1.0f },
130      { 0.0f, 0.0f, 0.0f },
131      { 1.0f, 1.0f, 1.0f },
132      { 0.9f, 0.9f, 0.9f },
133      { 0.05f,0.05f,0.05f},
134      { 0.25f,0.25f,0.25f},
135      1.2f,
136      false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0,
137      0.9f, 4.0f,
138      1.0f, 0.21f, 0.19f, 0.17f, 0.15f, 0.14f, 0.13f, 0.12f, 0.11f, 0.10f, 0.09f
139   },
140   {   // 25% Shadow mask, 0% Scanlines, 0% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation
141      true,
142      0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f,
143      0.0f, 0.0f,
144      0.0f, 1.0f, 0.5f, 1.0f, 0.0f, 0.0f,
145      { 0.0f, 0.0f, 0.0f, 0.0f },
146      { 0.0f, 0.0f, 0.0f },
147      { 0.0f, 0.0f, 0.0f },
148      { 0.0f, 0.0f, 0.0f },
149      { 0.0f, 0.0f, 0.0f },
150      { 1.0f, 0.0f, 0.0f },
151      { 0.0f, 1.0f, 0.0f },
152      { 0.0f, 0.0f, 1.0f },
153      { 0.0f, 0.0f, 0.0f },
154      { 1.0f, 1.0f, 1.0f },
155      { 0.9f, 0.9f, 0.9f },
156      { 0.05f,0.05f,0.05f},
157      { 0.25f,0.25f,0.25f},
158      1.2f,
159      false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0,
160      0.9f, 4.0f,
161      1.0f, 0.21f, 0.19f, 0.17f, 0.15f, 0.14f, 0.13f, 0.12f, 0.11f, 0.10f, 0.09f
162   },
163   {   // 25% Shadow mask, 100% Scanlines, 15% Pincushion, 3 defocus, 24-degree Tint Out, 1.5 Exponent, 5% Floor, 70% Phosphor Return, 80% Saturation, Bad Convergence
164      true,
165      0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f,
166      0.15f, 0.15f,
167      1.0f, 1.0f, 0.5f, 1.0f, 0.0f, 0.5f,
168      { 3.0f, 3.0f, 3.0f, 3.0f },
169      { 0.5f,-0.33f,0.7f },
170      { 0.0f,-1.0f, 0.5f },
171      { 0.0f, 0.2f, 0.3f },
172      { 0.0f, 0.2f, 0.0f },
173      { 0.8f, 0.2f, 0.0f },
174      { 0.0f, 0.8f, 0.2f},
175      { 0.2f, 0.0f, 0.8f},
176      { 0.0f, 0.0f, 0.0f },
177      { 1.0f, 1.0f, 1.0f },
178      { 1.5f, 1.5f, 1.5f },
179      { 0.05f,0.05f,0.05f},
180      { 0.7f, 0.7f, 0.7f},
181      0.8f,
182      false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0,
183      0.9f, 4.0f,
184      1.0f, 0.21f, 0.19f, 0.17f, 0.15f, 0.14f, 0.13f, 0.12f, 0.11f, 0.10f, 0.09f
185   },
186};
187
188//============================================================
189//  PROTOTYPES
190//============================================================
191
192static void get_vector(const char *data, int count, float *out, int report_error);
193
194
195
196//============================================================
197//  shader manager constructor
198//============================================================
199
200shaders::shaders()
201{
202   master_enable = false;
203   vector_enable = true;
204   prescale_size_x = 1;
205   prescale_size_y = 1;
206   prescale_force_x = 0;
207   prescale_force_y = 0;
208   preset = -1;
209   shadow_texture = NULL;
210   options = NULL;
211   paused = true;
212   lastidx = -1;
213   targethead = NULL;
214   cachehead = NULL;
215   initialized = false;
216}
217
218
219
220//============================================================
221//  shaders destructor
222//============================================================
223
224shaders::~shaders()
225{
226   global_free(options);
227   cache_target *currcache = cachehead;
228   while(cachehead != NULL)
229   {
230      cachehead = currcache->next;
231      global_free(currcache);
232      currcache = cachehead;
233   }
234
235   render_target *currtarget = targethead;
236   while(targethead != NULL)
237   {
238      targethead = currtarget->next;
239      global_free(currtarget);
240      currtarget = targethead;
241   }
242}
243
244
245
246//============================================================
247//  shaders::window_save
248//============================================================
249
250void shaders::window_save()
251{
252   if (!master_enable || !d3dintf->post_fx_available)
253      return;
254
255   renderer *d3d = (renderer *)window->drawdata;
256
257   HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture);
258   if (result != D3D_OK)
259   {
260      mame_printf_verbose("Direct3D: Unable to init system-memory target for HLSL snapshot (%08x), bailing\n", (UINT32)result);
261      return;
262   }
263   (*d3dintf->texture.get_surface_level)(snap_copy_texture, 0, &snap_copy_target);
264
265   result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &snap_texture);
266   if (result != D3D_OK)
267   {
268      mame_printf_verbose("Direct3D: Unable to init video-memory target for HLSL snapshot (%08x), bailing\n", (UINT32)result);
269      return;
270   }
271   (*d3dintf->texture.get_surface_level)(snap_texture, 0, &snap_target);
272
273   render_snap = true;
274   snap_rendered = false;
275}
276
277
278
279//============================================================
280//  shaders::window_record
281//============================================================
282
283void shaders::window_record()
284{
285   if (!master_enable || !d3dintf->post_fx_available)
286      return;
287
288   windows_options &options = downcast<windows_options &>(window->machine().options());
289   const char *filename = options.d3d_hlsl_write();
290
291   if (avi_output_file != NULL)
292      end_avi_recording();
293   else if (filename[0] != 0)
294      begin_avi_recording(filename);
295}
296
297
298//============================================================
299//  shaders::avi_update_snap
300//============================================================
301
302void shaders::avi_update_snap(surface *surface)
303{
304   if (!master_enable || !d3dintf->post_fx_available)
305      return;
306
307   renderer *d3d = (renderer *)window->drawdata;
308
309   D3DLOCKED_RECT rect;
310
311   // if we don't have a bitmap, or if it's not the right size, allocate a new one
312   if (!avi_snap.valid() || (int)snap_width != avi_snap.width() || (int)snap_height != avi_snap.height())
313   {
314      avi_snap.allocate((int)snap_width, (int)snap_height);
315   }
316
317   // copy the texture
318   HRESULT result = (*d3dintf->device.get_render_target_data)(d3d->get_device(), surface, avi_copy_surface);
319   if (result != D3D_OK)
320   {
321      return;
322   }
323
324   // lock the texture
325   result = (*d3dintf->surface.lock_rect)(avi_copy_surface, &rect, NULL, D3DLOCK_DISCARD);
326   if (result != D3D_OK)
327   {
328      return;
329   }
330
331   // loop over Y
332   for (int srcy = 0; srcy < (int)snap_height; srcy++)
333   {
334      DWORD *src = (DWORD *)((BYTE *)rect.pBits + srcy * rect.Pitch);
335      UINT32 *dst = &avi_snap.pix32(srcy);
336
337      for(int x = 0; x < snap_width; x++)
338         *dst++ = *src++;
339   }
340
341   // unlock
342   result = (*d3dintf->surface.unlock_rect)(avi_copy_surface);
343   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result);
344}
345
346
347
348//============================================================
349//  hlsl_render_snapshot
350//============================================================
351
352void shaders::render_snapshot(surface *surface)
353{
354   if (!master_enable || !d3dintf->post_fx_available)
355      return;
356
357   renderer *d3d = (renderer *)window->drawdata;
358
359   D3DLOCKED_RECT rect;
360
361   render_snap = false;
362
363   // if we don't have a bitmap, or if it's not the right size, allocate a new one
364   if (!avi_snap.valid() || snap_width != (avi_snap.width() / 2) || snap_height != (avi_snap.height() / 2))
365   {
366      avi_snap.allocate(snap_width / 2, snap_height / 2);
367   }
368
369   // copy the texture
370   HRESULT result = (*d3dintf->device.get_render_target_data)(d3d->get_device(), surface, snap_copy_target);
371   if (result != D3D_OK)
372   {
373      return;
374   }
375
376   // lock the texture
377   result = (*d3dintf->surface.lock_rect)(snap_copy_target, &rect, NULL, D3DLOCK_DISCARD);
378   if (result != D3D_OK)
379   {
380      return;
381   }
382
383   for(int cy = 0; cy < 2; cy++)
384   {
385      for(int cx = 0; cx < 2; cx++)
386      {
387         // loop over Y
388         for (int srcy = 0; srcy < snap_height / 2; srcy++)
389         {
390            int toty = (srcy + cy * (snap_height / 2));
391            int totx = cx * (snap_width / 2);
392            DWORD *src = (DWORD *)((BYTE *)rect.pBits + toty * rect.Pitch + totx * 4);
393            UINT32 *dst = &avi_snap.pix32(srcy);
394
395            for(int x = 0; x < snap_width / 2; x++)
396               *dst++ = *src++;
397         }
398
399         int idx = cy * 2 + cx;
400
401         emu_file file(window->machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
402         file_error filerr = open_next(d3d, file, NULL, "png", idx);
403         if (filerr != FILERR_NONE)
404            return;
405
406         // add two text entries describing the image
407         astring text1(emulator_info::get_appname(), " ", build_version);
408         astring text2(window->machine().system().manufacturer, " ", window->machine().system().description);
409         png_info pnginfo = { 0 };
410         png_add_text(&pnginfo, "Software", text1);
411         png_add_text(&pnginfo, "System", text2);
412
413         // now do the actual work
414         png_error error = png_write_bitmap(file, &pnginfo, avi_snap, 1 << 24, NULL);
415         if (error != PNGERR_NONE)
416            mame_printf_error("Error generating PNG for HLSL snapshot: png_error = %d\n", error);
417
418         // free any data allocated
419         png_free(&pnginfo);
420      }
421   }
422
423   // unlock
424   result = (*d3dintf->surface.unlock_rect)(snap_copy_target);
425   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result);
426
427   if(snap_texture != NULL)
428   {
429      (*d3dintf->texture.release)(snap_texture);
430      snap_texture = NULL;
431   }
432
433   if(snap_target != NULL)
434   {
435      (*d3dintf->surface.release)(snap_target);
436      snap_target = NULL;
437   }
438
439   if(snap_copy_texture != NULL)
440   {
441      (*d3dintf->texture.release)(snap_copy_texture);
442      snap_copy_texture = NULL;
443   }
444
445   if(snap_copy_target != NULL)
446   {
447      (*d3dintf->surface.release)(snap_copy_target);
448      snap_copy_target = NULL;
449   }
450}
451
452
453//============================================================
454//  shaders::record_texture
455//============================================================
456
457void shaders::record_texture()
458{
459   if (!master_enable || !d3dintf->post_fx_available)
460      return;
461
462   surface *surface = avi_final_target;
463
464   // ignore if nothing to do
465   if (avi_output_file == NULL || surface == NULL)
466      return;
467
468   // get the current time
469   attotime curtime = window->machine().time();
470
471   avi_update_snap(surface);
472
473   // loop until we hit the right time
474   while (avi_next_frame_time <= curtime)
475   {
476      // handle an AVI recording
477      // write the next frame
478      avi_error avierr = avi_append_video_frame(avi_output_file, avi_snap);
479      if (avierr != AVIERR_NONE)
480      {
481         end_avi_recording();
482         return;
483      }
484
485      // advance time
486      avi_next_frame_time += avi_frame_period;
487      avi_frame++;
488   }
489}
490
491
492//============================================================
493//  shaders::end_hlsl_avi_recording
494//============================================================
495
496void shaders::end_avi_recording()
497{
498   if (!master_enable || !d3dintf->post_fx_available)
499      return;
500
501   if (avi_output_file != NULL)
502      avi_close(avi_output_file);
503
504   avi_output_file = NULL;
505   avi_frame = 0;
506}
507
508
509//============================================================
510//  shaders::set_texture
511//============================================================
512
513void shaders::toggle()
514{
515   if (master_enable)
516   {
517      if (initialized)
518      {
519         delete_resources(false);
520      }
521      master_enable = !master_enable;
522   }
523   else
524   {
525      if (!initialized)
526      {
527         master_enable = !master_enable;
528         bool failed = create_resources(false);
529         if (failed)
530         {
531            master_enable = false;
532         }
533      }
534      else
535      {
536         master_enable = !master_enable;
537      }
538   }
539}
540
541//============================================================
542//  shaders::begin_avi_recording
543//============================================================
544
545void shaders::begin_avi_recording(const char *name)
546{
547   if (!master_enable || !d3dintf->post_fx_available)
548      return;
549
550   renderer *d3d = (renderer *)window->drawdata;
551
552   // stop any existing recording
553   end_avi_recording();
554
555   // reset the state
556   avi_frame = 0;
557   avi_next_frame_time = window->machine().time();
558
559   // build up information about this new movie
560   avi_movie_info info;
561   info.video_format = 0;
562   info.video_timescale = 1000 * ((window->machine().primary_screen != NULL) ? ATTOSECONDS_TO_HZ(window->machine().primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE);
563   info.video_sampletime = 1000;
564   info.video_numsamples = 0;
565   info.video_width = snap_width;
566   info.video_height = snap_height;
567   info.video_depth = 24;
568
569   info.audio_format = 0;
570   info.audio_timescale = window->machine().sample_rate();
571   info.audio_sampletime = 1;
572   info.audio_numsamples = 0;
573   info.audio_channels = 2;
574   info.audio_samplebits = 16;
575   info.audio_samplerate = window->machine().sample_rate();
576
577   // create a new temporary movie file
578   file_error filerr;
579   astring fullpath;
580   {
581      emu_file tempfile(window->machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
582      if (name != NULL)
583      {
584         filerr = tempfile.open(name);
585      }
586      else
587      {
588         filerr = open_next(d3d, tempfile, NULL, "avi", 0);
589      }
590
591      // compute the frame time
592      {
593         avi_frame_period = attotime::from_seconds(1000) / info.video_timescale;
594      }
595
596      // if we succeeded, make a copy of the name and create the real file over top
597      if (filerr == FILERR_NONE)
598      {
599         fullpath = tempfile.fullpath();
600      }
601   }
602
603   if (filerr == FILERR_NONE)
604   {
605      // create the file and free the string
606      avi_error avierr = avi_create(fullpath, &info, &avi_output_file);
607      if (avierr != AVIERR_NONE)
608      {
609         mame_printf_error("Error creating AVI: %s\n", avi_error_string(avierr));
610      }
611   }
612}
613
614
615//============================================================
616//  remove_cache_target - remove an active cache target when
617//  refcount hits zero
618//============================================================
619
620void shaders::remove_cache_target(cache_target *cache)
621{
622   if (cache != NULL)
623   {
624      if (cache == cachehead)
625      {
626         cachehead = cachehead->next;
627      }
628
629      if (cache->prev != NULL)
630      {
631         cache->prev->next = cache->next;
632      }
633
634      if (cache->next != NULL)
635      {
636         cache->next->prev = cache->prev;
637      }
638
639      global_free(cache);
640   }
641}
642
643
644//============================================================
645//  remove_render_target - remove an active target
646//============================================================
647
648void shaders::remove_render_target(texture_info *texture)
649{
650   remove_render_target(find_render_target(texture));
651}
652
653void shaders::remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
654{
655   render_target *target = find_render_target(width, height, screen_index, page_index);
656   if (target != NULL)
657   {
658      remove_render_target(target);
659   }
660}
661
662void shaders::remove_render_target(render_target *rt)
663{
664   if (rt != NULL)
665   {
666      if (rt == targethead)
667      {
668         targethead = targethead->next;
669      }
670
671      if (rt->prev != NULL)
672      {
673         rt->prev->next = rt->next;
674      }
675
676      if (rt->next != NULL)
677      {
678         rt->next->prev = rt->prev;
679      }
680
681      cache_target *cache = find_cache_target(rt->screen_index, rt->width, rt->height);
682      if (cache != NULL)
683      {
684         remove_cache_target(cache);
685      }
686
687      int screen_index = rt->screen_index;
688      int other_page = 1 - rt->page_index;
689      int width = rt->width;
690      int height = rt->height;
691
692      global_free(rt);
693
694      // Remove other double-buffered page (if it exists)
695      remove_render_target(width, height, screen_index, other_page);
696   }
697}
698
699
700//============================================================
701//  shaders::set_texture
702//============================================================
703
704void shaders::set_texture(texture_info *texture)
705{
706   if (!master_enable || !d3dintf->post_fx_available)
707      return;
708
709   renderer *d3d = (renderer *)window->drawdata;
710
711   if(texture != NULL)
712   {
713      paused = texture->paused();
714      texture->advance_frame();
715   }
716
717   texture_info *default_texture = d3d->get_default_texture();
718   (*d3dintf->effect.set_texture)(default_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex());
719   if (options->yiq_enable)
720      (*d3dintf->effect.set_texture)(yiq_encode_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex());
721   else
722      (*d3dintf->effect.set_texture)(color_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex());
723   (*d3dintf->effect.set_texture)(pincushion_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex());
724}
725
726
727//============================================================
728//  shaders::init
729//============================================================
730
731void shaders::init(base *d3dintf, win_window_info *window)
732{
733   if (!d3dintf->post_fx_available)
734      return;
735
736   this->d3dintf = d3dintf;
737   this->window = window;
738
739   master_enable = downcast<windows_options &>(window->machine().options()).d3d_hlsl_enable();
740   prescale_size_x = 1;
741   prescale_size_y = 1;
742   preset = downcast<windows_options &>(window->machine().options()).d3d_hlsl_preset();
743   if (preset < -1 || preset > 3)
744   {
745      preset = -1;
746   }
747
748   snap_width = downcast<windows_options &>(window->machine().options()).d3d_snap_width();
749   snap_height = downcast<windows_options &>(window->machine().options()).d3d_snap_height();
750   prescale_force_x = 0;
751   prescale_force_y = 0;
752
753   windows_options &winoptions = downcast<windows_options &>(window->machine().options());
754
755   options = (hlsl_options*)global_alloc_clear(hlsl_options);
756
757   options->params_dirty = true;
758   strcpy(options->shadow_mask_texture, downcast<windows_options &>(window->machine().options()).screen_shadow_mask_texture()); // unsafe
759
760   write_ini = downcast<windows_options &>(window->machine().options()).hlsl_write_ini();
761   read_ini = downcast<windows_options &>(window->machine().options()).hlsl_read_ini();
762
763   if(read_ini)
764   {
765      emu_file ini_file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_READ | OPEN_FLAG_CREATE_PATHS);
766      file_error filerr = open_next((renderer*)window->drawdata, ini_file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0);
767
768      read_ini = false;
769      if (filerr == FILERR_NONE)
770      {
771         ini_file.seek(0, SEEK_END);
772         if (ini_file.tell() >= 1000)
773         {
774            read_ini = true;
775            ini_file.seek(0, SEEK_SET);
776
777            int en = 0;
778            char buf[1024];
779            ini_file.gets(buf, 1024);
780            sscanf(buf, "hlsl_enable %d\n", &en);
781            master_enable = en == 1;
782
783            ini_file.gets(buf, 1024);
784            sscanf(buf, "hlsl_prescale_x %d\n", &prescale_force_x);
785
786            ini_file.gets(buf, 1024);
787            sscanf(buf, "hlsl_prescale_y %d\n", &prescale_force_y);
788
789            ini_file.gets(buf, 1024);
790            sscanf(buf, "hlsl_preset %d\n", &preset);
791
792            ini_file.gets(buf, 1024);
793            sscanf(buf, "hlsl_snap_width %d\n", &snap_width);
794
795            ini_file.gets(buf, 1024);
796            sscanf(buf, "hlsl_snap_height %d\n", &snap_height);
797
798            ini_file.gets(buf, 1024);
799            sscanf(buf, "shadow_mask_alpha %f\n", &options->shadow_mask_alpha);
800
801            ini_file.gets(buf, 1024);
802            sscanf(buf, "shadow_mask_texture %s\n", options->shadow_mask_texture);
803
804            ini_file.gets(buf, 1024);
805            sscanf(buf, "shadow_mask_x_count %d\n", &options->shadow_mask_count_x);
806
807            ini_file.gets(buf, 1024);
808            sscanf(buf, "shadow_mask_y_count %d\n", &options->shadow_mask_count_y);
809
810            ini_file.gets(buf, 1024);
811            sscanf(buf, "shadow_mask_usize %f\n", &options->shadow_mask_u_size);
812
813            ini_file.gets(buf, 1024);
814            sscanf(buf, "shadow_mask_vsize %f\n", &options->shadow_mask_v_size);
815
816            ini_file.gets(buf, 1024);
817            sscanf(buf, "curvature %f\n", &options->curvature);
818
819            ini_file.gets(buf, 1024);
820            sscanf(buf, "pincushion %f\n", &options->pincushion);
821
822            ini_file.gets(buf, 1024);
823            sscanf(buf, "scanline_alpha %f\n", &options->scanline_alpha);
824
825            ini_file.gets(buf, 1024);
826            sscanf(buf, "scanline_size %f\n", &options->scanline_scale);
827
828            ini_file.gets(buf, 1024);
829            sscanf(buf, "scanline_height %f\n", &options->scanline_height);
830
831            ini_file.gets(buf, 1024);
832            sscanf(buf, "scanline_bright_scale %f\n", &options->scanline_bright_scale);
833
834            ini_file.gets(buf, 1024);
835            sscanf(buf, "scanline_bright_offset %f\n", &options->scanline_bright_offset);
836
837            ini_file.gets(buf, 1024);
838            sscanf(buf, "scanline_jitter %f\n", &options->scanline_offset);
839
840            ini_file.gets(buf, 1024);
841            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
842            sscanf(buf, "defocus %f %f\n", &options->defocus[0], &options->defocus[1]);
843
844            ini_file.gets(buf, 1024);
845            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
846            sscanf(buf, "converge_x %f %f %f\n", &options->converge_x[0], &options->converge_x[1], &options->converge_x[2]);
847
848            ini_file.gets(buf, 1024);
849            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
850            sscanf(buf, "converge_y %f %f %f\n", &options->converge_y[0], &options->converge_y[1], &options->converge_y[2]);
851
852            ini_file.gets(buf, 1024);
853            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
854            sscanf(buf, "radial_converge_x %f %f %f\n", &options->radial_converge_x[0], &options->radial_converge_x[1], &options->radial_converge_x[2]);
855
856            ini_file.gets(buf, 1024);
857            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
858            sscanf(buf, "radial_converge_y %f %f %f\n", &options->radial_converge_y[0], &options->radial_converge_y[1], &options->radial_converge_y[2]);
859
860            ini_file.gets(buf, 1024);
861            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
862            sscanf(buf, "red_ratio %f %f %f\n", &options->red_ratio[0], &options->red_ratio[1], &options->red_ratio[2]);
863
864            ini_file.gets(buf, 1024);
865            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
866            sscanf(buf, "grn_ratio %f %f %f\n", &options->grn_ratio[0], &options->grn_ratio[1], &options->grn_ratio[2]);
867
868            ini_file.gets(buf, 1024);
869            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
870            sscanf(buf, "blu_ratio %f %f %f\n", &options->blu_ratio[0], &options->blu_ratio[1], &options->blu_ratio[2]);
871
872            ini_file.gets(buf, 1024);
873            sscanf(buf, "saturation %f\n", &options->saturation);
874
875            ini_file.gets(buf, 1024);
876            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
877            sscanf(buf, "offset %f %f %f\n", &options->offset[0], &options->offset[1], &options->offset[2]);
878
879            ini_file.gets(buf, 1024);
880            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
881            sscanf(buf, "scale %f %f %f\n", &options->scale[0], &options->scale[1], &options->scale[2]);
882
883            ini_file.gets(buf, 1024);
884            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
885            sscanf(buf, "power %f %f %f\n", &options->power[0], &options->power[1], &options->power[2]);
886
887            ini_file.gets(buf, 1024);
888            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
889            sscanf(buf, "floor %f %f %f\n", &options->floor[0], &options->floor[1], &options->floor[2]);
890
891            ini_file.gets(buf, 1024);
892            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
893            sscanf(buf, "phosphor_life %f %f %f\n", &options->phosphor[0], &options->phosphor[1], &options->phosphor[2]);
894
895            ini_file.gets(buf, 1024);
896            sscanf(buf, "yiq_enable %d\n", &en);
897            options->yiq_enable = en == 1;
898
899            ini_file.gets(buf, 1024);
900            sscanf(buf, "yiq_cc %f\n", &options->yiq_cc);
901
902            ini_file.gets(buf, 1024);
903            sscanf(buf, "yiq_a %f\n", &options->yiq_a);
904
905            ini_file.gets(buf, 1024);
906            sscanf(buf, "yiq_b %f\n", &options->yiq_b);
907
908            ini_file.gets(buf, 1024);
909            sscanf(buf, "yiq_o %f\n", &options->yiq_o);
910
911            ini_file.gets(buf, 1024);
912            sscanf(buf, "yiq_p %f\n", &options->yiq_p);
913
914            ini_file.gets(buf, 1024);
915            sscanf(buf, "yiq_n %f\n", &options->yiq_n);
916
917            ini_file.gets(buf, 1024);
918            sscanf(buf, "yiq_y %f\n", &options->yiq_y);
919
920            ini_file.gets(buf, 1024);
921            sscanf(buf, "yiq_i %f\n", &options->yiq_i);
922
923            ini_file.gets(buf, 1024);
924            sscanf(buf, "yiq_q %f\n", &options->yiq_q);
925
926            ini_file.gets(buf, 1024);
927            sscanf(buf, "yiq_scan_time %f\n", &options->yiq_scan_time);
928
929            ini_file.gets(buf, 1024);
930            sscanf(buf, "yiq_phase_count %d\n", &options->yiq_phase_count);
931
932            ini_file.gets(buf, 1024);
933            sscanf(buf, "vector_length_scale %f\n", &options->vector_length_scale);
934
935            ini_file.gets(buf, 1024);
936            sscanf(buf, "vector_length_ratio %f\n", &options->vector_length_ratio);
937         }
938      }
939   }
940   else
941   {
942      prescale_force_x = winoptions.d3d_hlsl_prescale_x();
943      prescale_force_y = winoptions.d3d_hlsl_prescale_y();
944      if(preset == -1)
945      {
946         options->shadow_mask_alpha = winoptions.screen_shadow_mask_alpha();
947         options->shadow_mask_count_x = winoptions.screen_shadow_mask_count_x();
948         options->shadow_mask_count_y = winoptions.screen_shadow_mask_count_y();
949         options->shadow_mask_u_size = winoptions.screen_shadow_mask_u_size();
950         options->shadow_mask_v_size = winoptions.screen_shadow_mask_v_size();
951         options->curvature = winoptions.screen_curvature();
952         options->pincushion = winoptions.screen_pincushion();
953         options->scanline_alpha = winoptions.screen_scanline_amount();
954         options->scanline_scale = winoptions.screen_scanline_scale();
955         options->scanline_height = winoptions.screen_scanline_height();
956         options->scanline_bright_scale = winoptions.screen_scanline_bright_scale();
957         options->scanline_bright_offset = winoptions.screen_scanline_bright_offset();
958         options->scanline_offset = winoptions.screen_scanline_offset();
959         get_vector(winoptions.screen_defocus(), 2, options->defocus, TRUE);
960         get_vector(winoptions.screen_converge_x(), 3, options->converge_x, TRUE);
961         get_vector(winoptions.screen_converge_y(), 3, options->converge_y, TRUE);
962         get_vector(winoptions.screen_radial_converge_x(), 3, options->radial_converge_x, TRUE);
963         get_vector(winoptions.screen_radial_converge_y(), 3, options->radial_converge_y, TRUE);
964         get_vector(winoptions.screen_red_ratio(), 3, options->red_ratio, TRUE);
965         get_vector(winoptions.screen_grn_ratio(), 3, options->grn_ratio, TRUE);
966         get_vector(winoptions.screen_blu_ratio(), 3, options->blu_ratio, TRUE);
967         get_vector(winoptions.screen_offset(), 3, options->offset, TRUE);
968         get_vector(winoptions.screen_scale(), 3, options->scale, TRUE);
969         get_vector(winoptions.screen_power(), 3, options->power, TRUE);
970         get_vector(winoptions.screen_floor(), 3, options->floor, TRUE);
971         get_vector(winoptions.screen_phosphor(), 3, options->phosphor, TRUE);
972         options->saturation = winoptions.screen_saturation();
973      }
974      else
975      {
976         options = &s_hlsl_presets[preset];
977      }
978
979      options->yiq_enable = winoptions.screen_yiq_enable();
980      options->yiq_cc = winoptions.screen_yiq_cc();
981      options->yiq_a = winoptions.screen_yiq_a();
982      options->yiq_b = winoptions.screen_yiq_b();
983      options->yiq_o = winoptions.screen_yiq_o();
984      options->yiq_p = winoptions.screen_yiq_p();
985      options->yiq_n = winoptions.screen_yiq_n();
986      options->yiq_y = winoptions.screen_yiq_y();
987      options->yiq_i = winoptions.screen_yiq_i();
988      options->yiq_q = winoptions.screen_yiq_q();
989      options->yiq_scan_time = winoptions.screen_yiq_scan_time();
990      options->yiq_phase_count = winoptions.screen_yiq_phase_count();
991      options->vector_length_scale = winoptions.screen_vector_length_scale();
992      options->vector_length_ratio = winoptions.screen_vector_length_ratio();
993      options->vector_bloom_scale = winoptions.screen_vector_bloom_scale();
994      options->raster_bloom_scale = winoptions.screen_raster_bloom_scale();
995      options->bloom_level0_weight = winoptions.screen_bloom_lvl0_weight();
996      options->bloom_level1_weight = winoptions.screen_bloom_lvl1_weight();
997      options->bloom_level2_weight = winoptions.screen_bloom_lvl2_weight();
998      options->bloom_level3_weight = winoptions.screen_bloom_lvl3_weight();
999      options->bloom_level4_weight = winoptions.screen_bloom_lvl4_weight();
1000      options->bloom_level5_weight = winoptions.screen_bloom_lvl5_weight();
1001      options->bloom_level6_weight = winoptions.screen_bloom_lvl6_weight();
1002      options->bloom_level7_weight = winoptions.screen_bloom_lvl7_weight();
1003      options->bloom_level8_weight = winoptions.screen_bloom_lvl8_weight();
1004      options->bloom_level9_weight = winoptions.screen_bloom_lvl9_weight();
1005      options->bloom_level10_weight = winoptions.screen_bloom_lvl10_weight();
1006   }
1007
1008   options->params_dirty = true;
1009   // experimental: load a PNG to use for vector rendering; it is treated
1010   // as a brightness map
1011   emu_file file(window->machine().options().art_path(), OPEN_FLAG_READ);
1012
1013   render_load_png(shadow_bitmap, file, NULL, options->shadow_mask_texture);
1014
1015   g_slider_list = init_slider_list();
1016}
1017
1018
1019
1020//============================================================
1021//  shaders::init_fsfx_quad
1022//============================================================
1023
1024void shaders::init_fsfx_quad(void *vertbuf)
1025{
1026   // Called at the start of each frame by the D3D code in order to reserve two triangles
1027   // that are guaranteed to be at a fixed position so as to simply use D3DPT_TRIANGLELIST, 0, 2
1028   // instead of having to do bookkeeping about a specific screen quad
1029   if (!master_enable || !d3dintf->post_fx_available)
1030      return;
1031
1032   renderer *d3d = (renderer *)window->drawdata;
1033
1034   // get a pointer to the vertex buffer
1035   fsfx_vertices = (vertex *)vertbuf;
1036   if (fsfx_vertices == NULL)
1037      return;
1038
1039   // fill in the vertexes clockwise
1040   fsfx_vertices[0].x = 0.0f;
1041   fsfx_vertices[0].y = 0.0f;
1042   fsfx_vertices[1].x = d3d->get_width();
1043   fsfx_vertices[1].y = 0.0f;
1044   fsfx_vertices[2].x = 0.0f;
1045   fsfx_vertices[2].y = d3d->get_height();
1046   fsfx_vertices[3].x = d3d->get_width();
1047   fsfx_vertices[3].y = 0.0f;
1048   fsfx_vertices[4].x = 0.0f;
1049   fsfx_vertices[4].y = d3d->get_height();
1050   fsfx_vertices[5].x = d3d->get_width();
1051   fsfx_vertices[5].y = d3d->get_height();
1052
1053   fsfx_vertices[0].u0 = 0.0f;
1054   fsfx_vertices[0].v0 = 0.0f;
1055
1056   fsfx_vertices[1].u0 = 1.0f;
1057   fsfx_vertices[1].v0 = 0.0f;
1058
1059   fsfx_vertices[2].u0 = 0.0f;
1060   fsfx_vertices[2].v0 = 1.0f;
1061
1062   fsfx_vertices[3].u0 = 1.0f;
1063   fsfx_vertices[3].v0 = 0.0f;
1064
1065   fsfx_vertices[4].u0 = 0.0f;
1066   fsfx_vertices[4].v0 = 1.0f;
1067
1068   fsfx_vertices[5].u0 = 1.0f;
1069   fsfx_vertices[5].v0 = 1.0f;
1070
1071   fsfx_vertices[0].u1 = 0.0f;
1072   fsfx_vertices[0].v1 = 0.0f;
1073   fsfx_vertices[1].u1 = 0.0f;
1074   fsfx_vertices[1].v1 = 0.0f;
1075   fsfx_vertices[2].u1 = 0.0f;
1076   fsfx_vertices[2].v1 = 0.0f;
1077   fsfx_vertices[3].u1 = 0.0f;
1078   fsfx_vertices[3].v1 = 0.0f;
1079   fsfx_vertices[4].u1 = 0.0f;
1080   fsfx_vertices[4].v1 = 0.0f;
1081   fsfx_vertices[5].u1 = 0.0f;
1082   fsfx_vertices[5].v1 = 0.0f;
1083
1084   // set the color, Z parameters to standard values
1085   for (int i = 0; i < 6; i++)
1086   {
1087      fsfx_vertices[i].z = 0.0f;
1088      fsfx_vertices[i].rhw = 1.0f;
1089      fsfx_vertices[i].color = D3DCOLOR_ARGB(255, 255, 255, 255);
1090   }
1091}
1092
1093
1094
1095//============================================================
1096//  shaders::create_resources
1097//============================================================
1098
1099int shaders::create_resources(bool reset)
1100{
1101   if (!master_enable || !d3dintf->post_fx_available)
1102      return 0;
1103
1104   renderer *d3d = (renderer *)window->drawdata;
1105
1106   HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer);
1107   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
1108
1109   result = (*d3dintf->device.create_texture)(d3d->get_device(), 4, 4, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &black_texture);
1110   if (result != D3D_OK)
1111   {
1112      mame_printf_verbose("Direct3D: Unable to init video-memory target for black texture (%08x)\n", (UINT32)result);
1113      return 1;
1114   }
1115   (*d3dintf->texture.get_surface_level)(black_texture, 0, &black_surface);
1116   result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, black_surface);
1117   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1118   result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1119   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1120   result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
1121   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1122
1123   result = (*d3dintf->device.create_texture)(d3d->get_device(), (int)snap_width, (int)snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &avi_copy_texture);
1124   if (result != D3D_OK)
1125   {
1126      mame_printf_verbose("Direct3D: Unable to init system-memory target for HLSL AVI dumping (%08x)\n", (UINT32)result);
1127      return 1;
1128   }
1129   (*d3dintf->texture.get_surface_level)(avi_copy_texture, 0, &avi_copy_surface);
1130
1131   result = (*d3dintf->device.create_texture)(d3d->get_device(), (int)snap_width, (int)snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &avi_final_texture);
1132   if (result != D3D_OK)
1133   {
1134      mame_printf_verbose("Direct3D: Unable to init video-memory target for HLSL AVI dumping (%08x)\n", (UINT32)result);
1135      return 1;
1136   }
1137   (*d3dintf->texture.get_surface_level)(avi_final_texture, 0, &avi_final_target);
1138
1139   // experimental: if we have a shadow bitmap, create a texture for it
1140   if (shadow_bitmap.valid())
1141   {
1142      render_texinfo texture;
1143
1144      // fake in the basic data so it looks like it came from render.c
1145      texture.base = shadow_bitmap.raw_pixptr(0);
1146      texture.rowpixels = shadow_bitmap.rowpixels();
1147      texture.width = shadow_bitmap.width();
1148      texture.height = shadow_bitmap.height();
1149      texture.palette = NULL;
1150      texture.seqid = 0;
1151
1152      // now create it
1153      shadow_texture = new texture_info(d3d->get_texture_manager(), &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
1154   }
1155
1156   const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir();
1157
1158   // Replace all this garbage with a proper data-driven system
1159   char primary_name_cstr[1024];
1160   sprintf(primary_name_cstr, "%s\\primary.fx", fx_dir);
1161   TCHAR *primary_name = tstring_from_utf8(primary_name_cstr);
1162
1163   char post_name_cstr[1024];
1164   sprintf(post_name_cstr, "%s\\post.fx", fx_dir);
1165   TCHAR *post_name = tstring_from_utf8(post_name_cstr);
1166
1167   char prescale_name_cstr[1024];
1168   sprintf(prescale_name_cstr, "%s\\prescale.fx", fx_dir);
1169   TCHAR *prescale_name = tstring_from_utf8(prescale_name_cstr);
1170
1171   char pincushion_name_cstr[1024];
1172   sprintf(pincushion_name_cstr, "%s\\pincushion.fx", fx_dir);
1173   TCHAR *pincushion_name = tstring_from_utf8(pincushion_name_cstr);
1174
1175   char phosphor_name_cstr[1024];
1176   sprintf(phosphor_name_cstr, "%s\\phosphor.fx", fx_dir);
1177   TCHAR *phosphor_name = tstring_from_utf8(phosphor_name_cstr);
1178
1179   char focus_name_cstr[1024];
1180   sprintf(focus_name_cstr, "%s\\focus.fx", fx_dir);
1181   TCHAR *focus_name = tstring_from_utf8(focus_name_cstr);
1182
1183   char deconverge_name_cstr[1024];
1184   sprintf(deconverge_name_cstr, "%s\\deconverge.fx", fx_dir);
1185   TCHAR *deconverge_name = tstring_from_utf8(deconverge_name_cstr);
1186
1187   char color_name_cstr[1024];
1188   sprintf(color_name_cstr, "%s\\color.fx", fx_dir);
1189   TCHAR *color_name = tstring_from_utf8(color_name_cstr);
1190
1191   char yiq_encode_name_cstr[1024];
1192   sprintf(yiq_encode_name_cstr, "%s\\yiq_encode.fx", fx_dir);
1193   TCHAR *yiq_encode_name = tstring_from_utf8(yiq_encode_name_cstr);
1194
1195   char yiq_decode_name_cstr[1024];
1196   sprintf(yiq_decode_name_cstr, "%s\\yiq_decode.fx", fx_dir);
1197   TCHAR *yiq_decode_name = tstring_from_utf8(yiq_decode_name_cstr);
1198
1199   // create the regular shader
1200   result = (*d3dintf->device.create_effect)(d3d->get_device(), primary_name, &default_effect);
1201   if(result != D3D_OK)
1202   {
1203      mame_printf_verbose("Direct3D: Unable to load primary.fx\n");
1204      return 1;
1205   }
1206
1207   // create the post-processing shader
1208   result = (*d3dintf->device.create_effect)(d3d->get_device(), post_name, &post_effect);
1209   if(result != D3D_OK)
1210   {
1211      mame_printf_verbose("Direct3D: Unable to load post.fx\n");
1212      return 1;
1213   }
1214
1215   // create the prescaling shader
1216   result = (*d3dintf->device.create_effect)(d3d->get_device(), prescale_name, &prescale_effect);
1217   if(result != D3D_OK)
1218   {
1219      mame_printf_verbose("Direct3D: Unable to load prescale.fx\n");
1220      return 1;
1221   }
1222
1223   // create the pincushion shader
1224   result = (*d3dintf->device.create_effect)(d3d->get_device(), pincushion_name, &pincushion_effect);
1225   if(result != D3D_OK)
1226   {
1227      mame_printf_verbose("Direct3D: Unable to load pincushion.fx\n");
1228      return 1;
1229   }
1230
1231   // create the phosphor shader
1232   result = (*d3dintf->device.create_effect)(d3d->get_device(), phosphor_name, &phosphor_effect);
1233   if(result != D3D_OK)
1234   {
1235      mame_printf_verbose("Direct3D: Unable to load phosphor.fx\n");
1236      return 1;
1237   }
1238
1239   // create the focus shader
1240   result = (*d3dintf->device.create_effect)(d3d->get_device(), focus_name, &focus_effect);
1241   if(result != D3D_OK)
1242   {
1243      mame_printf_verbose("Direct3D: Unable to load focus.fx\n");
1244      return 1;
1245   }
1246
1247   // create the deconvergence shader
1248   result = (*d3dintf->device.create_effect)(d3d->get_device(), deconverge_name, &deconverge_effect);
1249   if(result != D3D_OK)
1250   {
1251      mame_printf_verbose("Direct3D: Unable to load deconverge.fx\n");
1252      return 1;
1253   }
1254
1255   // create the color convolution shader
1256   result = (*d3dintf->device.create_effect)(d3d->get_device(), color_name, &color_effect);
1257   if(result != D3D_OK)
1258   {
1259      mame_printf_verbose("Direct3D: Unable to load color.fx\n");
1260      return 1;
1261   }
1262
1263   // create the YIQ modulation shader
1264   result = (*d3dintf->device.create_effect)(d3d->get_device(), yiq_encode_name, &yiq_encode_effect);
1265   if(result != D3D_OK)
1266   {
1267      mame_printf_verbose("Direct3D: Unable to load yiq_encode.fx\n");
1268      return 1;
1269   }
1270
1271   // create the YIQ demodulation shader
1272   result = (*d3dintf->device.create_effect)(d3d->get_device(), yiq_decode_name, &yiq_decode_effect);
1273   if(result != D3D_OK)
1274   {
1275      mame_printf_verbose("Direct3D: Unable to load yiq_decode.fx\n");
1276      return 1;
1277   }
1278
1279#if HLSL_VECTOR || CRT_BLOOM
1280   char bloom_cstr[1024];
1281   sprintf(bloom_cstr, "%s\\bloom.fx", fx_dir);
1282   TCHAR *bloom_name = tstring_from_utf8(bloom_cstr);
1283
1284   result = (*d3dintf->device.create_effect)(d3d->get_device(), bloom_name, &bloom_effect);
1285   if(result != D3D_OK)
1286   {
1287      mame_printf_verbose("Direct3D: Unable to load bloom.fx\n");
1288      return 1;
1289   }
1290   if (bloom_name)
1291      osd_free(bloom_name);
1292
1293   char downsample_cstr[1024];
1294   sprintf(downsample_cstr, "%s\\downsample.fx", fx_dir);
1295   TCHAR *downsample_name = tstring_from_utf8(downsample_cstr);
1296
1297   result = (*d3dintf->device.create_effect)(d3d->get_device(), downsample_name, &downsample_effect);
1298   if(result != D3D_OK)
1299   {
1300      mame_printf_verbose("Direct3D: Unable to load downsample.fx\n");
1301      return 1;
1302   }
1303   if (downsample_name)
1304      osd_free(downsample_name);
1305#endif
1306#if HLSL_VECTOR
1307   // create the vector shader
1308   char vector_cstr[1024];
1309   sprintf(vector_cstr, "%s\\vector.fx", fx_dir);
1310   TCHAR *vector_name = tstring_from_utf8(vector_cstr);
1311
1312   result = (*d3dintf->device.create_effect)(d3d->get_device(), vector_name, &vector_effect);
1313   if(result != D3D_OK)
1314   {
1315      mame_printf_verbose("Direct3D: Unable to load vector.fx\n");
1316      return 1;
1317   }
1318   if (vector_name)
1319      osd_free(vector_name);
1320#endif
1321
1322   if (primary_name)
1323      osd_free(primary_name);
1324   if (post_name)
1325      osd_free(post_name);
1326   if (prescale_name)
1327      osd_free(prescale_name);
1328   if (pincushion_name)
1329      osd_free(pincushion_name);
1330   if (phosphor_name)
1331      osd_free(phosphor_name);
1332   if (focus_name)
1333      osd_free(focus_name);
1334   if (deconverge_name)
1335      osd_free(deconverge_name);
1336   if (color_name)
1337      osd_free(color_name);
1338   if (yiq_encode_name)
1339      osd_free(yiq_encode_name);
1340   if (yiq_decode_name)
1341      osd_free(yiq_decode_name);
1342
1343   initialized = true;
1344
1345   return 0;
1346}
1347
1348
1349//============================================================
1350//  shaders::begin_draw
1351//============================================================
1352
1353void shaders::begin_draw()
1354{
1355   if (!master_enable || !d3dintf->post_fx_available)
1356      return;
1357
1358   renderer *d3d = (renderer *)window->drawdata;
1359
1360   curr_effect = default_effect;
1361
1362   (*d3dintf->effect.set_technique)(default_effect, "TestTechnique");
1363   (*d3dintf->effect.set_technique)(post_effect, "ScanMaskTechnique");
1364   (*d3dintf->effect.set_technique)(pincushion_effect, "TestTechnique");
1365   (*d3dintf->effect.set_technique)(phosphor_effect, "TestTechnique");
1366   (*d3dintf->effect.set_technique)(focus_effect, "TestTechnique");
1367   (*d3dintf->effect.set_technique)(deconverge_effect, "DeconvergeTechnique");
1368   (*d3dintf->effect.set_technique)(color_effect, "ColorTechnique");
1369   (*d3dintf->effect.set_technique)(yiq_encode_effect, "EncodeTechnique");
1370   (*d3dintf->effect.set_technique)(yiq_decode_effect, "DecodeTechnique");
1371
1372   HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer);
1373   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
1374}
1375
1376
1377//============================================================
1378//  shaders::begin_frame
1379//============================================================
1380
1381void shaders::begin_frame()
1382{
1383   record_texture();
1384}
1385
1386
1387//============================================================
1388//  shaders::blit
1389//============================================================
1390
1391void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type,
1392                  UINT32 prim_index, UINT32 prim_count, int dstw, int dsth)
1393{
1394   renderer *d3d = (renderer *)window->drawdata;
1395
1396   HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst);
1397   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1398
1399   curr_effect = default_effect;
1400
1401   (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", src);
1402
1403   (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)dstw);
1404   (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)dsth);
1405   (*d3dintf->effect.set_float)(curr_effect, "PostPass", 1.0f);
1406   (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion);
1407   (*d3dintf->effect.set_float)(curr_effect, "Brighten", 0.0f);
1408
1409   unsigned int num_passes = 0;
1410   (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1411
1412   for (UINT pass = 0; pass < num_passes; pass++)
1413   {
1414      (*d3dintf->effect.begin_pass)(curr_effect, pass);
1415      // add the primitives
1416      HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), prim_type, prim_index, prim_count);
1417      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1418      (*d3dintf->effect.end_pass)(curr_effect);
1419   }
1420
1421   (*d3dintf->effect.end)(curr_effect);
1422
1423   if (new_dst)
1424   {
1425      HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, new_dst);
1426      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1427   }
1428}
1429
1430
1431
1432//============================================================
1433//  shaders::blit
1434//============================================================
1435
1436void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type,
1437                  UINT32 prim_index, UINT32 prim_count)
1438{
1439   renderer *d3d = (renderer *)window->drawdata;
1440
1441   HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst);
1442   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1443   result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(1,0,0,0), 0, 0);
1444   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1445
1446   curr_effect = default_effect;
1447
1448   (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", src);
1449
1450   (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1451   (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1452   (*d3dintf->effect.set_float)(curr_effect, "ScreenWidth", (float)d3d->get_width());
1453   (*d3dintf->effect.set_float)(curr_effect, "ScreenHeight", (float)d3d->get_height());
1454   (*d3dintf->effect.set_float)(curr_effect, "PostPass", 1.0f);
1455   (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion);
1456   (*d3dintf->effect.set_float)(curr_effect, "Brighten", 1.0f);
1457
1458   unsigned int num_passes = 0;
1459   (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1460
1461   for (UINT pass = 0; pass < num_passes; pass++)
1462   {
1463      (*d3dintf->effect.begin_pass)(curr_effect, pass);
1464      // add the primitives
1465      HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), prim_type, prim_index, prim_count);
1466      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1467      (*d3dintf->effect.end_pass)(curr_effect);
1468   }
1469
1470   (*d3dintf->effect.end)(curr_effect);
1471
1472   (*d3dintf->effect.set_float)(curr_effect, "Brighten", 0.0f);
1473
1474   if (new_dst)
1475   {
1476      HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, new_dst);
1477      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1478   }
1479}
1480
1481//============================================================
1482//  shaders::end_frame
1483//============================================================
1484
1485void shaders::end_frame()
1486{
1487   if (!master_enable || !d3dintf->post_fx_available)
1488      return;
1489
1490   if(render_snap && snap_rendered)
1491   {
1492      render_snapshot(snap_target);
1493   }
1494
1495   if (!lines_pending)
1496      return;
1497
1498   lines_pending = false;
1499
1500   /*render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
1501   if (rt == NULL)
1502   {
1503       return;
1504   }
1505
1506   blit(backbuffer, rt->render_texture[1], NULL, vecbuf_type, vecbuf_index, vecbuf_count);
1507
1508   HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]);
1509   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1510   result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1511   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1512   result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
1513   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);*/
1514}
1515
1516
1517//============================================================
1518//  shaders::init_effect_info
1519//============================================================
1520
1521void shaders::init_effect_info(poly_info *poly)
1522{
1523   if (!master_enable || !d3dintf->post_fx_available)
1524      return;
1525
1526   renderer *d3d = (renderer *)window->drawdata;
1527   texture_info *texture = poly->get_texture();
1528
1529   vec2f shadow_dims;
1530
1531   if (shadow_texture)
1532   {
1533      shadow_dims = shadow_texture->get_rawdims();
1534   }
1535   else
1536   {
1537      shadow_dims.c.x = 1.0f;
1538      shadow_dims.c.y = 1.0f;
1539   }
1540
1541   if(PRIMFLAG_GET_TEXSHADE(d3d->get_last_texture_flags()))
1542   {
1543      curr_effect = pincushion_effect;
1544   }
1545   else if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL)
1546   {
1547      // Plug in all of the shader settings we're going to need
1548      // This is extremely slow, but we're not rendering models here,
1549      // just post-processing.
1550      curr_effect = post_effect;
1551
1552      (*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (texture->get_cur_frame() == 0) ? 0.0f : options->scanline_offset);
1553
1554      if(options->params_dirty)
1555      {
1556         vec2f delta = texture->get_uvstop() - texture->get_uvstart();
1557         (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &texture->get_rawdims().c.x);
1558         (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x);
1559         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", d3d->get_width());
1560         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", d3d->get_height());
1561         (*d3dintf->effect.set_vector)(curr_effect, "Floor", 3, options->floor);
1562         (*d3dintf->effect.set_float)(curr_effect, "SnapX", snap_width);
1563         (*d3dintf->effect.set_float)(curr_effect, "SnapY", snap_height);
1564         (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion);
1565         (*d3dintf->effect.set_float)(curr_effect, "CurvatureAmount", options->curvature);
1566         (*d3dintf->effect.set_float)(curr_effect, "UseShadow", shadow_texture == NULL ? 0.0f : 1.0f);
1567         (*d3dintf->effect.set_texture)(curr_effect, "Shadow", shadow_texture == NULL ? NULL : shadow_texture->get_finaltex());
1568         (*d3dintf->effect.set_float)(curr_effect, "ShadowBrightness", options->shadow_mask_alpha);
1569         (*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeX", (float)options->shadow_mask_count_x);
1570         (*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeY", (float)options->shadow_mask_count_y);
1571         (*d3dintf->effect.set_float)(curr_effect, "ShadowU", options->shadow_mask_u_size);
1572         (*d3dintf->effect.set_float)(curr_effect, "ShadowV", options->shadow_mask_v_size);
1573
1574         (*d3dintf->effect.set_vector)(curr_effect, "ShadowDims", 2, &shadow_dims.c.x);
1575         (*d3dintf->effect.set_float)(curr_effect, "ScanlineAmount", options->scanline_alpha);
1576         (*d3dintf->effect.set_float)(curr_effect, "ScanlineScale", options->scanline_scale);
1577         (*d3dintf->effect.set_float)(curr_effect, "ScanlineHeight", options->scanline_height);
1578         (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightScale", options->scanline_bright_scale);
1579         (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightOffset", options->scanline_bright_offset);
1580         //(*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (texture->get_cur_frame() == 0) ? 0.0f : options->scanline_offset);
1581         (*d3dintf->effect.set_vector)(curr_effect, "Power", 3, options->power);
1582      }
1583   }
1584   else
1585   {
1586      curr_effect = default_effect;
1587
1588      (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f);
1589   }
1590}
1591
1592
1593//============================================================
1594//  shaders::find_render_target
1595//============================================================
1596
1597render_target* shaders::find_render_target(texture_info *info)
1598{
1599   render_target *curr = targethead;
1600   UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata;
1601   UINT32 screen_index = screen_index_data >> 1;
1602   UINT32 page_index = screen_index_data & 1;
1603
1604   while (curr != NULL && (curr->screen_index != screen_index || curr->page_index != page_index ||
1605      curr->width != info->get_texinfo().width || curr->height != info->get_texinfo().height))
1606   {
1607      curr = curr->next;
1608   }
1609
1610   return curr;
1611}
1612
1613
1614//============================================================
1615//  shaders::find_render_target
1616//============================================================
1617
1618render_target* shaders::find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
1619{
1620   render_target *curr = targethead;
1621
1622   while (curr != NULL && (curr->width != width || curr->height != height || curr->screen_index != screen_index || curr->page_index != page_index))
1623   {
1624      curr = curr->next;
1625   }
1626
1627   return curr;
1628}
1629
1630
1631//============================================================
1632//  shaders::find_cache_target
1633//============================================================
1634
1635cache_target* shaders::find_cache_target(UINT32 screen_index, int width, int height)
1636{
1637   cache_target *curr = cachehead;
1638
1639   while (curr != NULL && (curr->screen_index != screen_index || curr->width != width || curr->height != height))
1640   {
1641      curr = curr->next;
1642   }
1643
1644   return curr;
1645}
1646
1647
1648//============================================================
1649//  shaders::render_quad
1650//============================================================
1651
1652void shaders::render_quad(poly_info *poly, int vertnum)
1653{
1654   if (!master_enable || !d3dintf->post_fx_available)
1655      return;
1656
1657   UINT num_passes = 0;
1658   renderer *d3d = (renderer *)window->drawdata;
1659   texture_info *texture = poly->get_texture();
1660
1661   if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL)
1662   {
1663      render_target *rt = find_render_target(texture);
1664      if (rt == NULL)
1665      {
1666         return;
1667      }
1668      cache_target *ct = find_cache_target(rt->screen_index, texture->get_texinfo().width, texture->get_texinfo().height);
1669
1670      vec2f& rawdims = texture->get_rawdims();
1671      vec2f delta = texture->get_uvstop() - texture->get_uvstart();
1672
1673      if(options->yiq_enable)
1674      {
1675         // Convert our signal into YIQ
1676         curr_effect = yiq_encode_effect;
1677
1678         if(options->params_dirty)
1679         {
1680            (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x);
1681            (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / delta.c.x);
1682            (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / delta.c.y);
1683            (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1684            (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1685            (*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc);
1686            (*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a);
1687            (*d3dintf->effect.set_float)(curr_effect, "BValue", (texture->get_cur_frame() == 2) ? 0.0f : ((float)texture->get_cur_frame() * options->yiq_b));
1688            (*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p);
1689            (*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n);
1690            (*d3dintf->effect.set_float)(curr_effect, "YFreqResponse", options->yiq_y);
1691            (*d3dintf->effect.set_float)(curr_effect, "IFreqResponse", options->yiq_i);
1692            (*d3dintf->effect.set_float)(curr_effect, "QFreqResponse", options->yiq_q);
1693            (*d3dintf->effect.set_float)(curr_effect, "ScanTime", options->yiq_scan_time);
1694         }
1695
1696         HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[4]);
1697
1698         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1699         result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1700         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1701
1702         (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1703
1704         for (UINT pass = 0; pass < num_passes; pass++)
1705         {
1706            (*d3dintf->effect.begin_pass)(curr_effect, pass);
1707            // add the primitives
1708            result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1709            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1710            (*d3dintf->effect.end_pass)(curr_effect);
1711         }
1712
1713         (*d3dintf->effect.end)(curr_effect);
1714
1715         // Convert our signal from YIQ
1716         curr_effect = yiq_decode_effect;
1717
1718         (*d3dintf->effect.set_texture)(curr_effect, "Composite", rt->render_texture[4]);
1719         (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", texture->get_finaltex());
1720         if(true)//options->params_dirty)
1721         {
1722            (*d3dintf->effect.set_float)(curr_effect, "RawWidth", rawdims.c.x);
1723            (*d3dintf->effect.set_float)(curr_effect, "RawHeight", rawdims.c.y);
1724            (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / delta.c.x);
1725            (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / delta.c.y);
1726            (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1727            (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1728            (*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc);
1729            (*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a);
1730            (*d3dintf->effect.set_float)(curr_effect, "BValue", (texture->get_cur_frame() == 2) ? 0.0f : ((float)texture->get_cur_frame() * options->yiq_b));
1731            (*d3dintf->effect.set_float)(curr_effect, "OValue", options->yiq_o);
1732            (*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p);
1733            (*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n);
1734            (*d3dintf->effect.set_float)(curr_effect, "YFreqResponse", options->yiq_y);
1735            (*d3dintf->effect.set_float)(curr_effect, "IFreqResponse", options->yiq_i);
1736            (*d3dintf->effect.set_float)(curr_effect, "QFreqResponse", options->yiq_q);
1737            (*d3dintf->effect.set_float)(curr_effect, "ScanTime", options->yiq_scan_time);
1738         }
1739
1740         result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[3]);
1741
1742         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1743         result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1744         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1745
1746         (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1747
1748         for (UINT pass = 0; pass < num_passes; pass++)
1749         {
1750            (*d3dintf->effect.begin_pass)(curr_effect, pass);
1751            // add the primitives
1752            result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1753            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1754            (*d3dintf->effect.end_pass)(curr_effect);
1755         }
1756
1757         (*d3dintf->effect.end)(curr_effect);
1758
1759         curr_effect = color_effect;
1760
1761         (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[3]);
1762      }
1763
1764      curr_effect = color_effect;
1765
1766      // Render the initial color-convolution pass
1767      if(options->params_dirty)
1768      {
1769         (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x);
1770         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1771         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1772         (*d3dintf->effect.set_float)(curr_effect, "YIQEnable", options->yiq_enable ? 1.0f : 0.0f);
1773         (*d3dintf->effect.set_vector)(curr_effect, "RedRatios", 3, options->red_ratio);
1774         (*d3dintf->effect.set_vector)(curr_effect, "GrnRatios", 3, options->grn_ratio);
1775         (*d3dintf->effect.set_vector)(curr_effect, "BluRatios", 3, options->blu_ratio);
1776         (*d3dintf->effect.set_vector)(curr_effect, "Offset", 3, options->offset);
1777         (*d3dintf->effect.set_vector)(curr_effect, "Scale", 3, options->scale);
1778         (*d3dintf->effect.set_float)(curr_effect, "Saturation", options->saturation);
1779      }
1780
1781      HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->smalltarget);
1782
1783      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1784      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1785      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1786
1787      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1788
1789      for (UINT pass = 0; pass < num_passes; pass++)
1790      {
1791         (*d3dintf->effect.begin_pass)(curr_effect, pass);
1792         // add the primitives
1793         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1794         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1795         (*d3dintf->effect.end_pass)(curr_effect);
1796      }
1797
1798      (*d3dintf->effect.end)(curr_effect);
1799
1800      // Pre-scaling pass
1801      curr_effect = prescale_effect;
1802      (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->smalltexture);
1803
1804      if(options->params_dirty)
1805      {
1806         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1807         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1808         (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x);
1809      }
1810
1811      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1812
1813      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->prescaletarget);
1814      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1815      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1816      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1817
1818      for (UINT pass = 0; pass < num_passes; pass++)
1819      {
1820         (*d3dintf->effect.begin_pass)(curr_effect, pass);
1821         // add the primitives
1822         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1823         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1824         (*d3dintf->effect.end_pass)(curr_effect);
1825      }
1826
1827      (*d3dintf->effect.end)(curr_effect);
1828
1829      // Deconverge pass
1830      curr_effect = deconverge_effect;
1831      (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->prescaletexture);
1832
1833      if(options->params_dirty)
1834      {
1835         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1836         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1837         (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x);
1838         (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x);
1839         (*d3dintf->effect.set_vector)(curr_effect, "ConvergeX", 3, options->converge_x);
1840         (*d3dintf->effect.set_vector)(curr_effect, "ConvergeY", 3, options->converge_y);
1841         (*d3dintf->effect.set_vector)(curr_effect, "RadialConvergeX", 3, options->radial_converge_x);
1842         (*d3dintf->effect.set_vector)(curr_effect, "RadialConvergeY", 3, options->radial_converge_y);
1843      }
1844
1845      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1846
1847      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[2]);
1848      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result);
1849      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1850      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1851
1852      for (UINT pass = 0; pass < num_passes; pass++)
1853      {
1854         (*d3dintf->effect.begin_pass)(curr_effect, pass);
1855         // add the primitives
1856         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1857         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1858         (*d3dintf->effect.end_pass)(curr_effect);
1859      }
1860
1861      (*d3dintf->effect.end)(curr_effect);
1862
1863      float defocus_x = options->defocus[0];
1864      float defocus_y = options->defocus[1];
1865      bool focus_enable = defocus_x != 0.0f || defocus_y != 0.0f;
1866      if(focus_enable)
1867      {
1868         // Defocus pass 1
1869         curr_effect = focus_effect;
1870
1871         (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[2]);
1872
1873         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1874         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1875         (*d3dintf->effect.set_vector)(curr_effect, "Defocus", 2, &options->defocus[0]);
1876
1877         (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1878
1879         result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]);
1880         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result);
1881         result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1882         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1883
1884         for (UINT pass = 0; pass < num_passes; pass++)
1885         {
1886            (*d3dintf->effect.begin_pass)(curr_effect, pass);
1887            // add the primitives
1888            result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1889            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1890            (*d3dintf->effect.end_pass)(curr_effect);
1891         }
1892
1893         (*d3dintf->effect.end)(curr_effect);
1894
1895         // Defocus pass 2
1896
1897         (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]);
1898
1899         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1900         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1901         (*d3dintf->effect.set_vector)(curr_effect, "Defocus", 2, &options->defocus[1]);
1902
1903         (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1904
1905         result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]);
1906         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7\n", (int)result);
1907
1908         for (UINT pass = 0; pass < num_passes; pass++)
1909         {
1910            (*d3dintf->effect.begin_pass)(curr_effect, pass);
1911            // add the primitives
1912            result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1913            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1914            (*d3dintf->effect.end_pass)(curr_effect);
1915         }
1916
1917         (*d3dintf->effect.end)(curr_effect);
1918      }
1919
1920      // Simulate phosphorescence. This should happen after the shadow/scanline pass, but since
1921      // the phosphors are a direct result of the incoming texture, might as well just change the
1922      // input texture.
1923      curr_effect = phosphor_effect;
1924
1925      if(options->params_dirty)
1926      {
1927         //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)rt->target_width);
1928         //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)rt->target_height);
1929         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1930         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1931         (*d3dintf->effect.set_vector)(curr_effect, "Phosphor", 3, options->phosphor);
1932      }
1933      (*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)rt->target_width);
1934      (*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)rt->target_height);
1935      (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 0.0f);
1936
1937      (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", focus_enable ? rt->render_texture[1] : rt->render_texture[2]);
1938      (*d3dintf->effect.set_texture)(curr_effect, "LastPass", ct->last_texture);
1939
1940      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]);
1941      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result);
1942      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1943      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1944
1945      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1946
1947      for (UINT pass = 0; pass < num_passes; pass++)
1948      {
1949         (*d3dintf->effect.begin_pass)(curr_effect, pass);
1950         // add the primitives
1951         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1952         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1953         (*d3dintf->effect.end_pass)(curr_effect);
1954      }
1955
1956      (*d3dintf->effect.end)(curr_effect);
1957
1958      // Pass along our phosphor'd screen
1959      curr_effect = phosphor_effect;
1960
1961      //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1962      //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1963      //(*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)d3d->get_width());
1964      //(*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)d3d->get_height());
1965      (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]);
1966      (*d3dintf->effect.set_texture)(curr_effect, "LastPass", rt->render_texture[0]);
1967      (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 1.0f);
1968
1969      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, ct->last_target); // Avoid changing targets due to page flipping
1970      //result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); // Avoid changing targets due to page flipping
1971      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result);
1972      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1973      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1974
1975      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
1976
1977      for (UINT pass = 0; pass < num_passes; pass++)
1978      {
1979         (*d3dintf->effect.begin_pass)(curr_effect, pass);
1980         // add the primitives
1981         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
1982         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
1983         (*d3dintf->effect.end_pass)(curr_effect);
1984      }
1985
1986      (*d3dintf->effect.end)(curr_effect);
1987
1988      curr_effect = post_effect;
1989      (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
1990      (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
1991
1992      // Scanlines and shadow mask, at high res for AVI logging
1993      if(avi_output_file != NULL)
1994      {
1995         (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]);
1996
1997         result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, avi_final_target);
1998         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
1999
2000         (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2001
2002         for (UINT pass = 0; pass < num_passes; pass++)
2003         {
2004            (*d3dintf->effect.begin_pass)(curr_effect, pass);
2005            // add the primitives
2006            result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2007            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2008            (*d3dintf->effect.end_pass)(curr_effect);
2009         }
2010
2011         (*d3dintf->effect.end)(curr_effect);
2012      }
2013
2014      if(render_snap)
2015      {
2016         (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]);
2017
2018         result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, snap_target);
2019         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
2020
2021         (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2022
2023         for (UINT pass = 0; pass < num_passes; pass++)
2024         {
2025            (*d3dintf->effect.begin_pass)(curr_effect, pass);
2026            // add the primitives
2027            result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2028            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2029            (*d3dintf->effect.end_pass)(curr_effect);
2030         }
2031
2032         (*d3dintf->effect.end)(curr_effect);
2033
2034         snap_rendered = true;
2035      }
2036
2037      // Scanlines and shadow mask
2038      curr_effect = post_effect;
2039
2040      //float raw_dims[2] = { d3d->get_width(), d3d->get_height() };
2041      (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]);
2042      (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x);
2043      (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x);
2044
2045      d3d->set_wrap(D3DTADDRESS_MIRROR);
2046
2047#if CRT_BLOOM
2048      //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)rt->target_width);
2049      //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)rt->target_height);
2050      (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
2051      (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
2052
2053      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[2]);
2054
2055      d3d->set_wrap(D3DTADDRESS_MIRROR);
2056      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(1,0,0,0), 0, 0);
2057      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2058#else
2059      (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
2060      (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
2061
2062      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
2063#endif
2064      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
2065
2066      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2067
2068      for (UINT pass = 0; pass < num_passes; pass++)
2069      {
2070         (*d3dintf->effect.begin_pass)(curr_effect, pass);
2071         // add the primitives
2072         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2073         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2074         (*d3dintf->effect.end_pass)(curr_effect);
2075      }
2076
2077      (*d3dintf->effect.end)(curr_effect);
2078
2079      d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(poly->get_texture()->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
2080
2081#if CRT_BLOOM
2082      // Bloom
2083      curr_effect = downsample_effect;
2084
2085      (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[2]);
2086      (*d3dintf->effect.set_float)(curr_effect, "BloomRescale", options->raster_bloom_scale);
2087
2088      float bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height();
2089      int bloom_index = 0;
2090      float bloom_width = rt->target_width;
2091      float bloom_height = rt->target_height;
2092      float prim_width = poly->get_prim_width();
2093      float prim_height = poly->get_prim_height();
2094      float prim_ratio[2] = { prim_width / bloom_width, prim_height / bloom_height };
2095      float screen_size[2] = { d3d->get_width(), d3d->get_height() };
2096      //float target_size[2] = { bloom_width * 0.5f, bloom_height * 0.5f };
2097      (*d3dintf->effect.set_vector)(curr_effect, "ScreenSize", 2, screen_size);
2098      for(; bloom_size >= 2.0f && bloom_index < 11; bloom_size *= 0.5f)
2099      {
2100         float target_size[2] = { bloom_width, bloom_height };
2101         float source_size[2] = { bloom_width * 0.5f, bloom_height * 0.5f };
2102         (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size);
2103         (*d3dintf->effect.set_vector)(curr_effect, "SourceSize", 2, source_size);
2104         (*d3dintf->effect.set_vector)(curr_effect, "PrimRatio", 2, prim_ratio);
2105
2106         (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2107
2108         (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", (bloom_index == 0) ? rt->render_texture[2] : rt->bloom_texture[bloom_index - 1]);
2109
2110         HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->bloom_target[bloom_index]);
2111         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result);
2112         //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2113         //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2114
2115         for (UINT pass = 0; pass < num_passes; pass++)
2116         {
2117            (*d3dintf->effect.begin_pass)(curr_effect, pass);
2118            // add the primitives
2119            result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
2120            //result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2121            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2122            (*d3dintf->effect.end_pass)(curr_effect);
2123         }
2124
2125         (*d3dintf->effect.end)(curr_effect);
2126
2127         bloom_index++;
2128         bloom_width *= 0.5f;
2129         bloom_height *= 0.5f;
2130      }
2131
2132      // Bloom composite pass
2133      curr_effect = bloom_effect;
2134
2135      float target_size[2] = { d3d->get_width(), d3d->get_height() };
2136      (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size);
2137      float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight,
2138                        options->bloom_level2_weight, options->bloom_level3_weight };
2139      float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight,
2140                        options->bloom_level6_weight, options->bloom_level7_weight };
2141      float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight,
2142                        options->bloom_level10_weight };
2143      (*d3dintf->effect.set_vector)(curr_effect, "Level0123Weight", 4, weight0123);
2144      (*d3dintf->effect.set_vector)(curr_effect, "Level4567Weight", 4, weight4567);
2145      (*d3dintf->effect.set_vector)(curr_effect, "Level89AWeight", 3, weight89A);
2146      (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size);
2147
2148      (*d3dintf->effect.set_texture)(curr_effect, "DiffuseA", rt->render_texture[2]);
2149      (*d3dintf->effect.set_float)(curr_effect, "DiffuseScaleA", 1.0f);
2150
2151      char name[9] = "Diffuse*";
2152      char scale[14] = "DiffuseScale*";
2153      for(int index = 1; index < bloom_index; index++)
2154      {
2155         name[7] = 'A' + index;
2156         scale[12] = 'A' + index;
2157         (*d3dintf->effect.set_texture)(curr_effect, name, rt->bloom_texture[index - 1]);
2158         (*d3dintf->effect.set_float)(curr_effect, scale, 1.0f);
2159      }
2160      for(int index = bloom_index; index < 11; index++)
2161      {
2162         name[7] = 'A' + index;
2163         scale[12] = 'A' + index;
2164         (*d3dintf->effect.set_texture)(curr_effect, name, black_texture);
2165         (*d3dintf->effect.set_float)(curr_effect, scale, 0.0f);
2166      }
2167
2168      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2169
2170      //HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]);
2171      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
2172      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result);
2173      //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2174      //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2175
2176      for (UINT pass = 0; pass < num_passes; pass++)
2177      {
2178         (*d3dintf->effect.begin_pass)(curr_effect, pass);
2179         // add the primitives
2180         //result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
2181         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2182         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2183         (*d3dintf->effect.end_pass)(curr_effect);
2184      }
2185
2186      (*d3dintf->effect.end)(curr_effect);
2187#endif
2188      texture->increment_frame_count();
2189      texture->mask_frame_count(options->yiq_phase_count);
2190
2191      options->params_dirty = false;
2192
2193   }
2194#if HLSL_VECTOR
2195   else if(PRIMFLAG_GET_VECTOR(poly->get_flags()) && vector_enable)
2196   {
2197      render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
2198      if (rt == NULL)
2199      {
2200         return;
2201      }
2202
2203      lines_pending = true;
2204
2205      curr_effect = vector_effect;
2206
2207      if(options->params_dirty)
2208      {
2209         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
2210         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
2211      }
2212
2213      float time_params[2] = { 0.0f, 0.0f };
2214      float length_params[3] = { poly->get_line_length(), options->vector_length_scale, options->vector_length_ratio };
2215      (*d3dintf->effect.set_vector)(curr_effect, "TimeParams", 2, time_params);
2216      (*d3dintf->effect.set_vector)(curr_effect, "LengthParams", 3, length_params);
2217
2218      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2219
2220      HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]);
2221      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
2222
2223      for (UINT pass = 0; pass < num_passes; pass++)
2224      {
2225         (*d3dintf->effect.begin_pass)(curr_effect, pass);
2226         // add the primitives
2227         HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2228         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2229         (*d3dintf->effect.end_pass)(curr_effect);
2230      }
2231
2232      (*d3dintf->effect.end)(curr_effect);
2233      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
2234      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
2235
2236      curr_effect = default_effect;
2237
2238      (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f);
2239   }
2240   else if (PRIMFLAG_GET_VECTORBUF(poly->get_flags()) && vector_enable)
2241   {
2242      //if (!lines_pending)
2243         //return;
2244      //lines_pending = false;
2245
2246      renderer *d3d = (renderer *)window->drawdata;
2247
2248      render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
2249      if (rt == NULL)
2250      {
2251         return;
2252      }
2253
2254      /* Bloom */
2255      curr_effect = downsample_effect;
2256
2257      (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]);
2258      (*d3dintf->effect.set_float)(curr_effect, "BloomRescale", options->vector_bloom_scale);
2259
2260      float bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height();
2261      int bloom_index = 0;
2262      float bloom_width = rt->target_width;
2263      float bloom_height = rt->target_height;
2264      float prim_width = poly->get_prim_width();
2265      float prim_height = poly->get_prim_height();
2266      float prim_ratio[2] = { prim_width / bloom_width, prim_height / bloom_height };
2267      float screen_size[2] = { d3d->get_width(), d3d->get_height() };
2268      //float target_size[2] = { bloom_width * 0.5f, bloom_height * 0.5f };
2269      (*d3dintf->effect.set_vector)(curr_effect, "ScreenSize", 2, screen_size);
2270      for(; bloom_size >= 2.0f && bloom_index < 11; bloom_size *= 0.5f)
2271      {
2272         float target_size[2] = { bloom_width, bloom_height };
2273         float source_size[2] = { bloom_width * 0.5f, bloom_height * 0.5f };
2274         (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size);
2275         (*d3dintf->effect.set_vector)(curr_effect, "SourceSize", 2, source_size);
2276         (*d3dintf->effect.set_vector)(curr_effect, "PrimRatio", 2, prim_ratio);
2277
2278         (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2279
2280         (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", (bloom_index == 0) ? rt->render_texture[0] : rt->bloom_texture[bloom_index - 1]);
2281
2282         HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->bloom_target[bloom_index]);
2283         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result);
2284         //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2285         //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2286
2287         for (UINT pass = 0; pass < num_passes; pass++)
2288         {
2289            (*d3dintf->effect.begin_pass)(curr_effect, pass);
2290            // add the primitives
2291            result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2292            if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2293            (*d3dintf->effect.end_pass)(curr_effect);
2294         }
2295
2296         (*d3dintf->effect.end)(curr_effect);
2297
2298         bloom_index++;
2299         bloom_width *= 0.5f;
2300         bloom_height *= 0.5f;
2301      }
2302
2303      // Bloom composite pass
2304      curr_effect = bloom_effect;
2305
2306      float target_size[2] = { d3d->get_width(), d3d->get_height() };
2307      (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size);
2308      float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight,
2309                        options->bloom_level2_weight, options->bloom_level3_weight };
2310      float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight,
2311                        options->bloom_level6_weight, options->bloom_level7_weight };
2312      float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight,
2313                        options->bloom_level10_weight };
2314      (*d3dintf->effect.set_vector)(curr_effect, "Level0123Weight", 4, weight0123);
2315      (*d3dintf->effect.set_vector)(curr_effect, "Level4567Weight", 4, weight4567);
2316      (*d3dintf->effect.set_vector)(curr_effect, "Level89AWeight", 3, weight89A);
2317
2318      (*d3dintf->effect.set_texture)(curr_effect, "DiffuseA", rt->render_texture[0]);
2319      (*d3dintf->effect.set_float)(curr_effect, "DiffuseScaleA", 1.0f);
2320
2321      char name[9] = "Diffuse*";
2322      char scale[14] = "DiffuseScale*";
2323      for(int index = 1; index < bloom_index; index++)
2324      {
2325         name[7] = 'A' + index;
2326         scale[12] = 'A' + index;
2327         (*d3dintf->effect.set_texture)(curr_effect, name, rt->bloom_texture[index - 1]);
2328         (*d3dintf->effect.set_float)(curr_effect, scale, 1.0f);
2329      }
2330      for(int index = bloom_index; index < 11; index++)
2331      {
2332         name[7] = 'A' + index;
2333         scale[12] = 'A' + index;
2334         (*d3dintf->effect.set_texture)(curr_effect, name, black_texture);
2335         (*d3dintf->effect.set_float)(curr_effect, scale, 0.0f);
2336      }
2337
2338      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2339
2340      HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]);
2341      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result);
2342      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2343      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2344
2345      for (UINT pass = 0; pass < num_passes; pass++)
2346      {
2347         (*d3dintf->effect.begin_pass)(curr_effect, pass);
2348         // add the primitives
2349         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2350         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2351         (*d3dintf->effect.end_pass)(curr_effect);
2352      }
2353
2354      (*d3dintf->effect.end)(curr_effect);
2355
2356      /* Phosphor */
2357      curr_effect = phosphor_effect;
2358
2359      if(options->params_dirty)
2360      {
2361         (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
2362         (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
2363         (*d3dintf->effect.set_vector)(curr_effect, "Phosphor", 3, options->phosphor);
2364      }
2365      (*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)d3d->get_width());
2366      (*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)d3d->get_height());
2367      (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 0.0f);
2368
2369      (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[1]);
2370      (*d3dintf->effect.set_texture)(curr_effect, "LastPass", rt->render_texture[2]);
2371
2372      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[3]);
2373      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result);
2374      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2375      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2376
2377      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2378
2379      for (UINT pass = 0; pass < num_passes; pass++)
2380      {
2381         (*d3dintf->effect.begin_pass)(curr_effect, pass);
2382         // add the primitives
2383         result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2);
2384         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2385         (*d3dintf->effect.end_pass)(curr_effect);
2386      }
2387
2388      (*d3dintf->effect.end)(curr_effect);
2389
2390      blit(rt->target[2], rt->render_texture[3], NULL, poly->get_type(), vertnum, poly->get_count());
2391      blit(backbuffer, rt->render_texture[3], backbuffer, poly->get_type(), vertnum, poly->get_count());
2392
2393      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]);
2394      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
2395      result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2396      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2397      result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
2398      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
2399
2400      lines_pending = false;
2401   }
2402#else
2403   else if (PRIMFLAG_GET_VECTORBUF(poly->get_flags()) && vector_enable)
2404   {
2405      // Do nothing
2406   }
2407#endif
2408   else
2409   {
2410      curr_effect = default_effect;
2411
2412      (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width());
2413      (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height());
2414      (*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f);
2415
2416      (*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
2417
2418      for (UINT pass = 0; pass < num_passes; pass++)
2419      {
2420         (*d3dintf->effect.begin_pass)(curr_effect, pass);
2421         // add the primitives
2422         HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count());
2423         if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
2424         (*d3dintf->effect.end_pass)(curr_effect);
2425      }
2426
2427      (*d3dintf->effect.end)(curr_effect);
2428   }
2429}
2430
2431
2432
2433//============================================================
2434//  shaders::end_draw
2435//============================================================
2436
2437void shaders::end_draw()
2438{
2439   if (!master_enable || !d3dintf->post_fx_available)
2440      return;
2441
2442   (*d3dintf->surface.release)(backbuffer);
2443}
2444
2445
2446//============================================================
2447//  shaders::register_prescaled_texture
2448//============================================================
2449
2450bool shaders::register_prescaled_texture(texture_info *texture)
2451{
2452   return register_texture(texture);
2453}
2454
2455
2456//============================================================
2457//  shaders::add_cache_target - register a cache target
2458//============================================================
2459bool shaders::add_cache_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index)
2460{
2461   cache_target* target = (cache_target*)global_alloc_clear(cache_target);
2462
2463   if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
2464   {
2465      global_free(target);
2466      return false;
2467   }
2468
2469   if (info != NULL)
2470   {
2471      target->width = info->get_texinfo().width;
2472      target->height = info->get_texinfo().height;
2473   }
2474   else
2475   {
2476      target->width = d3d->get_width();
2477      target->height = d3d->get_height();
2478   }
2479
2480   target->next = cachehead;
2481   target->prev = NULL;
2482
2483   target->screen_index = screen_index;
2484
2485   if (cachehead != NULL)
2486   {
2487      cachehead->prev = target;
2488   }
2489   cachehead = target;
2490
2491   return true;
2492}
2493
2494render_target* shaders::get_vector_target()
2495{
2496#if HLSL_VECTOR
2497   if (!vector_enable)
2498   {
2499      return NULL;
2500   }
2501
2502   renderer *d3d = (renderer *)window->drawdata;
2503
2504   return find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
2505#else
2506   return NULL;
2507#endif
2508}
2509
2510void shaders::create_vector_target(render_primitive *prim)
2511{
2512#if HLSL_VECTOR
2513   renderer *d3d = (renderer *)window->drawdata;
2514   if (!add_render_target(d3d, NULL, d3d->get_width(), d3d->get_height(), 1, 1))
2515   {
2516      vector_enable = false;
2517   }
2518#endif
2519}
2520
2521//============================================================
2522//  shaders::add_render_target - register a render target
2523//============================================================
2524
2525bool shaders::add_render_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale)
2526{
2527   UINT32 screen_index = 0;
2528   UINT32 page_index = 0;
2529   if (info != NULL)
2530   {
2531      render_target *existing_target = find_render_target(info);
2532      if (existing_target != NULL)
2533      {
2534         remove_render_target(existing_target);
2535      }
2536
2537      UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata;
2538      screen_index = screen_index_data >> 1;
2539      page_index = screen_index_data & 1;
2540   }
2541   else
2542   {
2543      render_target *existing_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
2544      if (existing_target != NULL)
2545      {
2546         remove_render_target(existing_target);
2547      }
2548   }
2549
2550   render_target* target = (render_target*)global_alloc_clear(render_target);
2551
2552   if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
2553   {
2554      global_free(target);
2555      return false;
2556   }
2557
2558   if (info != NULL)
2559   {
2560      target->width = info->get_texinfo().width;
2561      target->height = info->get_texinfo().height;
2562   }
2563   else
2564   {
2565      target->width = d3d->get_width();
2566      target->height = d3d->get_height();
2567   }
2568
2569   HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, target->target[0]);
2570   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
2571   result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
2572   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
2573   result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
2574   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
2575
2576   target->screen_index = screen_index;
2577   target->page_index = page_index;
2578
2579   cache_target* cache = find_cache_target(target->screen_index, target->width, target->height);
2580   if (cache == NULL)
2581   {
2582      if (!add_cache_target(d3d, info, width, height, xprescale, yprescale, target->screen_index))
2583      {
2584         global_free(target);
2585         return false;
2586      }
2587   }
2588
2589   target->next = targethead;
2590   target->prev = NULL;
2591
2592   if (targethead != NULL)
2593   {
2594      targethead->prev = target;
2595   }
2596   targethead = target;
2597
2598   return true;
2599}
2600
2601//============================================================
2602//  shaders::enumerate_screens
2603//============================================================
2604void shaders::enumerate_screens()
2605{
2606   screen_device_iterator iter(window->machine().root_device());
2607   num_screens = iter.count();
2608}
2609
2610
2611//============================================================
2612//  shaders::register_texture(texture::info)
2613//============================================================
2614
2615bool shaders::register_texture(texture_info *texture)
2616{
2617   int width = texture->get_width();
2618   int height = texture->get_height();
2619   int xscale = texture->get_xscale();
2620   int yscale = texture->get_yscale();
2621
2622   if (!master_enable || !d3dintf->post_fx_available)
2623   {
2624      return false;
2625   }
2626
2627   enumerate_screens();
2628
2629   renderer *d3d = (renderer *)window->drawdata;
2630
2631   int hlsl_prescale_x = prescale_force_x;
2632   int hlsl_prescale_y = prescale_force_y;
2633
2634   // Find the nearest prescale factor that is over our screen size
2635   if (hlsl_prescale_x == 0)
2636   {
2637      hlsl_prescale_x = 1;
2638      while (width * xscale * hlsl_prescale_x <= d3d->get_width())
2639      {
2640         hlsl_prescale_x++;
2641      }
2642      hlsl_prescale_x--;
2643   }
2644
2645   if (hlsl_prescale_y == 0)
2646   {
2647      hlsl_prescale_y = 1;
2648      while (height * yscale * hlsl_prescale_y <= d3d->get_height())
2649      {
2650         hlsl_prescale_y++;
2651      }
2652      hlsl_prescale_y--;
2653   }
2654
2655   hlsl_prescale_x = ((hlsl_prescale_x == 0) ? 1 : hlsl_prescale_x);
2656   hlsl_prescale_y = ((hlsl_prescale_y == 0) ? 1 : hlsl_prescale_y);
2657
2658   if (!add_render_target(d3d, texture, width, height, xscale * hlsl_prescale_x, yscale * hlsl_prescale_y))
2659      return false;
2660
2661   options->params_dirty = true;
2662
2663   return true;
2664}
2665
2666//============================================================
2667//  shaders::delete_resources
2668//============================================================
2669
2670void shaders::delete_resources(bool reset)
2671{
2672   if (!master_enable || !d3dintf->post_fx_available)
2673      return;
2674
2675   initialized = false;
2676
2677   if(write_ini && !reset)
2678   {
2679      emu_file file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
2680      file_error filerr = open_next((renderer*)window->drawdata, file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0);
2681
2682      if (filerr != FILERR_NONE)
2683         return;
2684
2685      file.printf("hlsl_enable            %d\n", master_enable ? 1 : 0);
2686      file.printf("hlsl_prescale_x        %d\n", prescale_force_x);
2687      file.printf("hlsl_prescale_y        %d\n", prescale_force_y);
2688      file.printf("hlsl_preset            %d\n", preset);
2689      file.printf("hlsl_snap_width        %d\n", snap_width);
2690      file.printf("hlsl_snap_height       %d\n", snap_height);
2691      file.printf("shadow_mask_alpha      %f\n", options->shadow_mask_alpha);
2692      file.printf("shadow_mask_texture    %s\n", options->shadow_mask_texture);
2693      file.printf("shadow_mask_x_count    %d\n", options->shadow_mask_count_x);
2694      file.printf("shadow_mask_y_count    %d\n", options->shadow_mask_count_y);
2695      file.printf("shadow_mask_usize      %f\n", options->shadow_mask_u_size);
2696      file.printf("shadow_mask_vsize      %f\n", options->shadow_mask_v_size);
2697      file.printf("curvature              %f\n", options->curvature);
2698      file.printf("pincushion             %f\n", options->pincushion);
2699      file.printf("scanline_alpha         %f\n", options->scanline_alpha);
2700      file.printf("scanline_size          %f\n", options->scanline_scale);
2701      file.printf("scanline_height        %f\n", options->scanline_height);
2702      file.printf("scanline_bright_scale  %f\n", options->scanline_bright_scale);
2703      file.printf("scanline_bright_offset %f\n", options->scanline_bright_offset);
2704      file.printf("scanline_jitter        %f\n", options->scanline_offset);
2705      file.printf("defocus                %f,%f\n", options->defocus[0], options->defocus[1]);
2706      file.printf("converge_x             %f,%f,%f\n", options->converge_x[0], options->converge_x[1], options->converge_x[2]);
2707      file.printf("converge_y             %f,%f,%f\n", options->converge_y[0], options->converge_y[1], options->converge_y[2]);
2708      file.printf("radial_converge_x      %f,%f,%f\n", options->radial_converge_x[0], options->radial_converge_x[1], options->radial_converge_x[2]);
2709      file.printf("radial_converge_y      %f,%f,%f\n", options->radial_converge_y[0], options->radial_converge_y[1], options->radial_converge_y[2]);
2710      file.printf("red_ratio              %f,%f,%f\n", options->red_ratio[0], options->red_ratio[1], options->red_ratio[2]);
2711      file.printf("grn_ratio              %f,%f,%f\n", options->grn_ratio[0], options->grn_ratio[1], options->grn_ratio[2]);
2712      file.printf("blu_ratio              %f,%f,%f\n", options->blu_ratio[0], options->blu_ratio[1], options->blu_ratio[2]);
2713      file.printf("saturation             %f\n", options->saturation);
2714      file.printf("offset                 %f,%f,%f\n", options->offset[0], options->offset[1], options->offset[2]);
2715      file.printf("scale                  %f,%f,%f\n", options->scale[0], options->scale[1], options->scale[2]);
2716      file.printf("power                  %f,%f,%f\n", options->power[0], options->power[1], options->power[2]);
2717      file.printf("floor                  %f,%f,%f\n", options->floor[0], options->floor[1], options->floor[2]);
2718      file.printf("phosphor_life          %f,%f,%f\n", options->phosphor[0], options->phosphor[1], options->phosphor[2]);
2719      file.printf("yiq_enable             %d\n", options->yiq_enable ? 1 : 0);
2720      file.printf("yiq_cc                 %f\n", options->yiq_cc);
2721      file.printf("yiq_a                  %f\n", options->yiq_a);
2722      file.printf("yiq_b                  %f\n", options->yiq_b);
2723      file.printf("yiq_o                  %f\n", options->yiq_o);
2724      file.printf("yiq_p                  %f\n", options->yiq_p);
2725      file.printf("yiq_n                  %f\n", options->yiq_n);
2726      file.printf("yiq_y                  %f\n", options->yiq_y);
2727      file.printf("yiq_i                  %f\n", options->yiq_i);
2728      file.printf("yiq_q                  %f\n", options->yiq_q);
2729      file.printf("yiq_scan_time          %f\n", options->yiq_scan_time);
2730      file.printf("yiq_phase_count        %d\n", options->yiq_phase_count);
2731      file.printf("vector_length_scale    %f\n", options->vector_length_scale);
2732      file.printf("vector_length_ratio    %f\n", options->vector_length_ratio);
2733   }
2734
2735   while (targethead != NULL)
2736   {
2737      remove_render_target(targethead);
2738   }
2739
2740#if (HLSL_VECTOR || CRT_BLOOM)
2741   if (downsample_effect != NULL)
2742   {
2743      (*d3dintf->effect.release)(downsample_effect);
2744      downsample_effect = NULL;
2745   }
2746   if (bloom_effect != NULL)
2747   {
2748      (*d3dintf->effect.release)(bloom_effect);
2749      bloom_effect = NULL;
2750   }
2751#endif
2752   if (default_effect != NULL)
2753   {
2754      (*d3dintf->effect.release)(default_effect);
2755      default_effect = NULL;
2756   }
2757   if (post_effect != NULL)
2758   {
2759      (*d3dintf->effect.release)(post_effect);
2760      post_effect = NULL;
2761   }
2762   if (prescale_effect != NULL)
2763   {
2764      (*d3dintf->effect.release)(prescale_effect);
2765      prescale_effect = NULL;
2766   }
2767   if (pincushion_effect != NULL)
2768   {
2769      (*d3dintf->effect.release)(pincushion_effect);
2770      pincushion_effect = NULL;
2771   }
2772   if (phosphor_effect != NULL)
2773   {
2774      (*d3dintf->effect.release)(phosphor_effect);
2775      phosphor_effect = NULL;
2776   }
2777   if (focus_effect != NULL)
2778   {
2779      (*d3dintf->effect.release)(focus_effect);
2780      focus_effect = NULL;
2781   }
2782   if (deconverge_effect != NULL)
2783   {
2784      (*d3dintf->effect.release)(deconverge_effect);
2785      deconverge_effect = NULL;
2786   }
2787   if (color_effect != NULL)
2788   {
2789      (*d3dintf->effect.release)(color_effect);
2790      color_effect = NULL;
2791   }
2792   if (yiq_encode_effect != NULL)
2793   {
2794      (*d3dintf->effect.release)(yiq_encode_effect);
2795      yiq_encode_effect = NULL;
2796   }
2797   if (yiq_decode_effect != NULL)
2798   {
2799      (*d3dintf->effect.release)(yiq_decode_effect);
2800      yiq_decode_effect = NULL;
2801   }
2802
2803   if (black_texture != NULL)
2804   {
2805      (*d3dintf->texture.release)(black_texture);
2806      black_texture = NULL;
2807   }
2808
2809   if (avi_copy_texture != NULL)
2810   {
2811      (*d3dintf->texture.release)(avi_copy_texture);
2812      avi_copy_texture = NULL;
2813   }
2814
2815   if (avi_copy_surface != NULL)
2816   {
2817      (*d3dintf->surface.release)(avi_copy_surface);
2818      avi_copy_surface = NULL;
2819   }
2820
2821   if (avi_final_texture != NULL)
2822   {
2823      (*d3dintf->texture.release)(avi_final_texture);
2824      avi_final_texture = NULL;
2825   }
2826
2827   if (avi_final_target != NULL)
2828   {
2829      (*d3dintf->surface.release)(avi_final_target);
2830      avi_final_target = NULL;
2831   }
2832
2833   shadow_bitmap.reset();
2834}
2835
2836
2837//============================================================
2838//  get_vector
2839//============================================================
2840
2841static void get_vector(const char *data, int count, float *out, int report_error)
2842{
2843   if (count > 3)
2844   {
2845      if (sscanf(data, "%f,%f,%f,%f", &out[0], &out[1], &out[2], &out[3]) < 4 && report_error)
2846         mame_printf_error("Illegal quad vector value = %s\n", data);
2847   }
2848   else if(count > 2)
2849   {
2850      if (sscanf(data, "%f,%f,%f", &out[0], &out[1], &out[2]) < 3 && report_error)
2851         mame_printf_error("Illegal triple vector value = %s\n", data);
2852   }
2853   else if(count > 1)
2854   {
2855      if (sscanf(data, "%f,%f", &out[0], &out[1]) < 2 && report_error)
2856         mame_printf_error("Illegal double vector value = %s\n", data);
2857   }
2858   else if(count > 0)
2859   {
2860      if (sscanf(data, "%f", &out[0]) < 1 && report_error)
2861         mame_printf_error("Illegal single vector value = %s\n", data);
2862   }
2863}
2864
2865
2866/*-------------------------------------------------
2867    slider_alloc - allocate a new slider entry
2868    currently duplicated from ui.c, this could
2869    be done in a more ideal way.
2870-------------------------------------------------*/
2871
2872static slider_state *slider_alloc(running_machine &machine, const char *title, INT32 minval, INT32 defval, INT32 maxval, INT32 incval, slider_update update, void *arg)
2873{
2874   int size = sizeof(slider_state) + strlen(title);
2875   slider_state *state = (slider_state *)auto_alloc_array_clear(machine, UINT8, size);
2876
2877   state->minval = minval;
2878   state->defval = defval;
2879   state->maxval = maxval;
2880   state->incval = incval;
2881   state->update = update;
2882   state->arg = arg;
2883   strcpy(state->description, title);
2884
2885   return state;
2886}
2887
2888
2889//============================================================
2890//  assorted global slider accessors
2891//============================================================
2892
2893static INT32 slider_set(float *option, float scale, const char *fmt, astring *string, INT32 newval)
2894{
2895   if (option != NULL && newval != SLIDER_NOCHANGE) *option = (float)newval * scale;
2896   if (string != NULL) string->printf(fmt, *option);
2897   return floor(*option / scale + 0.5f);
2898}
2899
2900static INT32 slider_shadow_mask_alpha(running_machine &machine, void *arg, astring *string, INT32 newval)
2901{
2902   return slider_set(&(((hlsl_options*)arg)->shadow_mask_alpha), 0.01f, "%2.2f", string, newval);
2903}
2904
2905static INT32 slider_shadow_mask_x_count(running_machine &machine, void *arg, astring *string, INT32 newval)
2906{
2907   hlsl_options *options = (hlsl_options*)arg;
2908   if (newval != SLIDER_NOCHANGE) options->shadow_mask_count_x = newval;
2909   if (string != NULL) string->printf("%d", options->shadow_mask_count_x);
2910   options->params_dirty = true;
2911   return options->shadow_mask_count_x;
2912}
2913
2914static INT32 slider_shadow_mask_y_count(running_machine &machine, void *arg, astring *string, INT32 newval)
2915{
2916   hlsl_options *options = (hlsl_options*)arg;
2917   if (newval != SLIDER_NOCHANGE) options->shadow_mask_count_y = newval;
2918   if (string != NULL) string->printf("%d", options->shadow_mask_count_y);
2919   options->params_dirty = true;
2920   return options->shadow_mask_count_y;
2921}
2922
2923static INT32 slider_shadow_mask_usize(running_machine &machine, void *arg, astring *string, INT32 newval)
2924{
2925   ((hlsl_options*)arg)->params_dirty = true;
2926   return slider_set(&(((hlsl_options*)arg)->shadow_mask_u_size), 1.0f / 32.0f, "%2.5f", string, newval);
2927}
2928
2929static INT32 slider_shadow_mask_vsize(running_machine &machine, void *arg, astring *string, INT32 newval)
2930{
2931   ((hlsl_options*)arg)->params_dirty = true;
2932   return slider_set(&(((hlsl_options*)arg)->shadow_mask_v_size), 1.0f / 32.0f, "%2.5f", string, newval);
2933}
2934
2935static INT32 slider_curvature(running_machine &machine, void *arg, astring *string, INT32 newval)
2936{
2937   ((hlsl_options*)arg)->params_dirty = true;
2938   return slider_set(&(((hlsl_options*)arg)->curvature), 0.01f, "%2.2f", string, newval);
2939}
2940
2941static INT32 slider_pincushion(running_machine &machine, void *arg, astring *string, INT32 newval)
2942{
2943   ((hlsl_options*)arg)->params_dirty = true;
2944   return slider_set(&(((hlsl_options*)arg)->pincushion), 0.01f, "%2.2f", string, newval);
2945}
2946
2947static INT32 slider_scanline_alpha(running_machine &machine, void *arg, astring *string, INT32 newval)
2948{
2949   ((hlsl_options*)arg)->params_dirty = true;
2950   return slider_set(&(((hlsl_options*)arg)->scanline_alpha), 0.01f, "%2.2f", string, newval);
2951}
2952
2953static INT32 slider_scanline_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
2954{
2955   ((hlsl_options*)arg)->params_dirty = true;
2956   return slider_set(&(((hlsl_options*)arg)->scanline_scale), 0.05f, "%2.2f", string, newval);
2957}
2958
2959static INT32 slider_scanline_height(running_machine &machine, void *arg, astring *string, INT32 newval)
2960{
2961   ((hlsl_options*)arg)->params_dirty = true;
2962   return slider_set(&(((hlsl_options*)arg)->scanline_height), 0.05f, "%2.2f", string, newval);
2963}
2964
2965static INT32 slider_scanline_bright_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
2966{
2967   ((hlsl_options*)arg)->params_dirty = true;
2968   return slider_set(&(((hlsl_options*)arg)->scanline_bright_scale), 0.05f, "%2.2f", string, newval);
2969}
2970
2971static INT32 slider_scanline_bright_offset(running_machine &machine, void *arg, astring *string, INT32 newval)
2972{
2973   ((hlsl_options*)arg)->params_dirty = true;
2974   return slider_set(&(((hlsl_options*)arg)->scanline_bright_offset), 0.05f, "%2.2f", string, newval);
2975}
2976
2977static INT32 slider_scanline_offset(running_machine &machine, void *arg, astring *string, INT32 newval)
2978{
2979   ((hlsl_options*)arg)->params_dirty = true;
2980   return slider_set(&(((hlsl_options*)arg)->scanline_offset), 0.05f, "%2.2f", string, newval);
2981}
2982
2983static INT32 slider_defocus_x(running_machine &machine, void *arg, astring *string, INT32 newval)
2984{
2985   ((hlsl_options*)arg)->params_dirty = true;
2986   return slider_set(&(((hlsl_options*)arg)->defocus[0]), 0.5f, "%2.1f", string, newval);
2987}
2988
2989static INT32 slider_defocus_y(running_machine &machine, void *arg, astring *string, INT32 newval)
2990{
2991   ((hlsl_options*)arg)->params_dirty = true;
2992   return slider_set(&(((hlsl_options*)arg)->defocus[1]), 0.5f, "%2.1f", string, newval);
2993}
2994
2995static INT32 slider_red_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval)
2996{
2997   ((hlsl_options*)arg)->params_dirty = true;
2998   return slider_set(&(((hlsl_options*)arg)->converge_x[0]), 0.1f, "%3.1f", string, newval);
2999}
3000
3001static INT32 slider_red_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval)
3002{
3003   ((hlsl_options*)arg)->params_dirty = true;
3004   return slider_set(&(((hlsl_options*)arg)->converge_y[0]), 0.1f, "%3.1f", string, newval);
3005}
3006
3007static INT32 slider_green_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval)
3008{
3009   ((hlsl_options*)arg)->params_dirty = true;
3010   return slider_set(&(((hlsl_options*)arg)->converge_x[1]), 0.1f, "%3.1f", string, newval);
3011}
3012
3013static INT32 slider_green_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval)
3014{
3015   ((hlsl_options*)arg)->params_dirty = true;
3016   return slider_set(&(((hlsl_options*)arg)->converge_y[1]), 0.1f, "%3.1f", string, newval);
3017}
3018
3019static INT32 slider_blue_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval)
3020{
3021   ((hlsl_options*)arg)->params_dirty = true;
3022   return slider_set(&(((hlsl_options*)arg)->converge_x[2]), 0.1f, "%3.1f", string, newval);
3023}
3024
3025static INT32 slider_blue_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval)
3026{
3027   ((hlsl_options*)arg)->params_dirty = true;
3028   return slider_set(&(((hlsl_options*)arg)->converge_y[2]), 0.1f, "%3.1f", string, newval);
3029}
3030
3031static INT32 slider_red_radial_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval)
3032{
3033   ((hlsl_options*)arg)->params_dirty = true;
3034   return slider_set(&(((hlsl_options*)arg)->radial_converge_x[0]), 0.1f, "%3.1f", string, newval);
3035}
3036
3037static INT32 slider_red_radial_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval)
3038{
3039   ((hlsl_options*)arg)->params_dirty = true;
3040   return slider_set(&(((hlsl_options*)arg)->radial_converge_y[0]), 0.1f, "%3.1f", string, newval);
3041}
3042
3043static INT32 slider_green_radial_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval)
3044{
3045   ((hlsl_options*)arg)->params_dirty = true;
3046   return slider_set(&(((hlsl_options*)arg)->radial_converge_x[1]), 0.1f, "%3.1f", string, newval);
3047}
3048
3049static INT32 slider_green_radial_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval)
3050{
3051   ((hlsl_options*)arg)->params_dirty = true;
3052   return slider_set(&(((hlsl_options*)arg)->radial_converge_y[1]), 0.1f, "%3.1f", string, newval);
3053}
3054
3055static INT32 slider_blue_radial_converge_x(running_machine &machine, void *arg, astring *string, INT32 newval)
3056{
3057   ((hlsl_options*)arg)->params_dirty = true;
3058   return slider_set(&(((hlsl_options*)arg)->radial_converge_x[2]), 0.1f, "%3.1f", string, newval);
3059}
3060
3061static INT32 slider_blue_radial_converge_y(running_machine &machine, void *arg, astring *string, INT32 newval)
3062{
3063   ((hlsl_options*)arg)->params_dirty = true;
3064   return slider_set(&(((hlsl_options*)arg)->radial_converge_y[2]), 0.1f, "%3.1f", string, newval);
3065}
3066
3067static INT32 slider_red_from_r(running_machine &machine, void *arg, astring *string, INT32 newval)
3068{
3069   ((hlsl_options*)arg)->params_dirty = true;
3070   return slider_set(&(((hlsl_options*)arg)->red_ratio[0]), 0.005f, "%2.3f", string, newval);
3071}
3072
3073static INT32 slider_red_from_g(running_machine &machine, void *arg, astring *string, INT32 newval)
3074{
3075   ((hlsl_options*)arg)->params_dirty = true;
3076   return slider_set(&(((hlsl_options*)arg)->red_ratio[1]), 0.005f, "%2.3f", string, newval);
3077}
3078
3079static INT32 slider_red_from_b(running_machine &machine, void *arg, astring *string, INT32 newval)
3080{
3081   ((hlsl_options*)arg)->params_dirty = true;
3082   return slider_set(&(((hlsl_options*)arg)->red_ratio[2]), 0.005f, "%2.3f", string, newval);
3083}
3084
3085static INT32 slider_green_from_r(running_machine &machine, void *arg, astring *string, INT32 newval)
3086{
3087   ((hlsl_options*)arg)->params_dirty = true;
3088   return slider_set(&(((hlsl_options*)arg)->grn_ratio[0]), 0.005f, "%2.3f", string, newval);
3089}
3090
3091static INT32 slider_green_from_g(running_machine &machine, void *arg, astring *string, INT32 newval)
3092{
3093   ((hlsl_options*)arg)->params_dirty = true;
3094   return slider_set(&(((hlsl_options*)arg)->grn_ratio[1]), 0.005f, "%2.3f", string, newval);
3095}
3096
3097static INT32 slider_green_from_b(running_machine &machine, void *arg, astring *string, INT32 newval)
3098{
3099   ((hlsl_options*)arg)->params_dirty = true;
3100   return slider_set(&(((hlsl_options*)arg)->grn_ratio[2]), 0.005f, "%2.3f", string, newval);
3101}
3102
3103static INT32 slider_blue_from_r(running_machine &machine, void *arg, astring *string, INT32 newval)
3104{
3105   ((hlsl_options*)arg)->params_dirty = true;
3106   return slider_set(&(((hlsl_options*)arg)->blu_ratio[0]), 0.005f, "%2.3f", string, newval);
3107}
3108
3109static INT32 slider_blue_from_g(running_machine &machine, void *arg, astring *string, INT32 newval)
3110{
3111   ((hlsl_options*)arg)->params_dirty = true;
3112   return slider_set(&(((hlsl_options*)arg)->blu_ratio[1]), 0.005f, "%2.3f", string, newval);
3113}
3114
3115static INT32 slider_blue_from_b(running_machine &machine, void *arg, astring *string, INT32 newval)
3116{
3117   ((hlsl_options*)arg)->params_dirty = true;
3118   return slider_set(&(((hlsl_options*)arg)->blu_ratio[2]), 0.005f, "%2.3f", string, newval);
3119}
3120
3121static INT32 slider_red_offset(running_machine &machine, void *arg, astring *string, INT32 newval)
3122{
3123   ((hlsl_options*)arg)->params_dirty = true;
3124   return slider_set(&(((hlsl_options*)arg)->offset[0]), 0.01f, "%2.2f", string, newval);
3125}
3126
3127static INT32 slider_green_offset(running_machine &machine, void *arg, astring *string, INT32 newval)
3128{
3129   ((hlsl_options*)arg)->params_dirty = true;
3130   return slider_set(&(((hlsl_options*)arg)->offset[1]), 0.01f, "%2.2f", string, newval);
3131}
3132
3133static INT32 slider_blue_offset(running_machine &machine, void *arg, astring *string, INT32 newval)
3134{
3135   ((hlsl_options*)arg)->params_dirty = true;
3136   return slider_set(&(((hlsl_options*)arg)->offset[2]), 0.01f, "%2.2f", string, newval);
3137}
3138
3139static INT32 slider_red_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3140{
3141   ((hlsl_options*)arg)->params_dirty = true;
3142   return slider_set(&(((hlsl_options*)arg)->scale[0]), 0.01f, "%2.2f", string, newval);
3143}
3144
3145static INT32 slider_green_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3146{
3147   ((hlsl_options*)arg)->params_dirty = true;
3148   return slider_set(&(((hlsl_options*)arg)->scale[1]), 0.01f, "%2.2f", string, newval);
3149}
3150
3151static INT32 slider_blue_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3152{
3153   ((hlsl_options*)arg)->params_dirty = true;
3154   return slider_set(&(((hlsl_options*)arg)->scale[2]), 0.01f, "%2.2f", string, newval);
3155}
3156
3157static INT32 slider_red_power(running_machine &machine, void *arg, astring *string, INT32 newval)
3158{
3159   ((hlsl_options*)arg)->params_dirty = true;
3160   return slider_set(&(((hlsl_options*)arg)->power[0]), 0.05f, "%2.2f", string, newval);
3161}
3162
3163static INT32 slider_green_power(running_machine &machine, void *arg, astring *string, INT32 newval)
3164{
3165   ((hlsl_options*)arg)->params_dirty = true;
3166   return slider_set(&(((hlsl_options*)arg)->power[1]), 0.05f, "%2.2f", string, newval);
3167}
3168
3169static INT32 slider_blue_power(running_machine &machine, void *arg, astring *string, INT32 newval)
3170{
3171   ((hlsl_options*)arg)->params_dirty = true;
3172   return slider_set(&(((hlsl_options*)arg)->power[2]), 0.05f, "%2.2f", string, newval);
3173}
3174
3175static INT32 slider_red_floor(running_machine &machine, void *arg, astring *string, INT32 newval)
3176{
3177   ((hlsl_options*)arg)->params_dirty = true;
3178   return slider_set(&(((hlsl_options*)arg)->floor[0]), 0.01f, "%2.2f", string, newval);
3179}
3180
3181static INT32 slider_green_floor(running_machine &machine, void *arg, astring *string, INT32 newval)
3182{
3183   ((hlsl_options*)arg)->params_dirty = true;
3184   return slider_set(&(((hlsl_options*)arg)->floor[1]), 0.01f, "%2.2f", string, newval);
3185}
3186
3187static INT32 slider_blue_floor(running_machine &machine, void *arg, astring *string, INT32 newval)
3188{
3189   ((hlsl_options*)arg)->params_dirty = true;
3190   return slider_set(&(((hlsl_options*)arg)->floor[2]), 0.01f, "%2.2f", string, newval);
3191}
3192
3193static INT32 slider_red_phosphor_life(running_machine &machine, void *arg, astring *string, INT32 newval)
3194{
3195   ((hlsl_options*)arg)->params_dirty = true;
3196   return slider_set(&(((hlsl_options*)arg)->phosphor[0]), 0.01f, "%2.2f", string, newval);
3197}
3198
3199static INT32 slider_green_phosphor_life(running_machine &machine, void *arg, astring *string, INT32 newval)
3200{
3201   ((hlsl_options*)arg)->params_dirty = true;
3202   return slider_set(&(((hlsl_options*)arg)->phosphor[1]), 0.01f, "%2.2f", string, newval);
3203}
3204
3205static INT32 slider_blue_phosphor_life(running_machine &machine, void *arg, astring *string, INT32 newval)
3206{
3207   ((hlsl_options*)arg)->params_dirty = true;
3208   return slider_set(&(((hlsl_options*)arg)->phosphor[2]), 0.01f, "%2.2f", string, newval);
3209}
3210
3211static INT32 slider_saturation(running_machine &machine, void *arg, astring *string, INT32 newval)
3212{
3213   ((hlsl_options*)arg)->params_dirty = true;
3214   return slider_set(&(((hlsl_options*)arg)->saturation), 0.01f, "%2.2f", string, newval);
3215}
3216
3217static INT32 slider_vector_attenuation(running_machine &machine, void *arg, astring *string, INT32 newval)
3218{
3219   ((hlsl_options*)arg)->params_dirty = true;
3220   return slider_set(&(((hlsl_options*)arg)->vector_length_scale), 0.01f, "%1.2f", string, newval);
3221}
3222
3223static INT32 slider_vector_length_max(running_machine &machine, void *arg, astring *string, INT32 newval)
3224{
3225   ((hlsl_options*)arg)->params_dirty = true;
3226   return slider_set(&(((hlsl_options*)arg)->vector_length_ratio), 1.0f, "%4f", string, newval);
3227}
3228
3229static INT32 slider_vector_bloom_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3230{
3231   ((hlsl_options*)arg)->params_dirty = true;
3232   return slider_set(&(((hlsl_options*)arg)->vector_bloom_scale), 0.001f, "%1.3f", string, newval);
3233}
3234
3235static INT32 slider_raster_bloom_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3236{
3237   ((hlsl_options*)arg)->params_dirty = true;
3238   return slider_set(&(((hlsl_options*)arg)->raster_bloom_scale), 0.001f, "%1.3f", string, newval);
3239}
3240
3241static INT32 slider_bloom_lvl0_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3242{
3243   ((hlsl_options*)arg)->params_dirty = true;
3244   return slider_set(&(((hlsl_options*)arg)->bloom_level0_weight), 0.01f, "%1.2f", string, newval);
3245}
3246
3247static INT32 slider_bloom_lvl1_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3248{
3249   ((hlsl_options*)arg)->params_dirty = true;
3250   return slider_set(&(((hlsl_options*)arg)->bloom_level1_weight), 0.01f, "%1.2f", string, newval);
3251}
3252
3253static INT32 slider_bloom_lvl2_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3254{
3255   ((hlsl_options*)arg)->params_dirty = true;
3256   return slider_set(&(((hlsl_options*)arg)->bloom_level2_weight), 0.01f, "%1.2f", string, newval);
3257}
3258
3259static INT32 slider_bloom_lvl3_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3260{
3261   ((hlsl_options*)arg)->params_dirty = true;
3262   return slider_set(&(((hlsl_options*)arg)->bloom_level3_weight), 0.01f, "%1.2f", string, newval);
3263}
3264
3265static INT32 slider_bloom_lvl4_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3266{
3267   ((hlsl_options*)arg)->params_dirty = true;
3268   return slider_set(&(((hlsl_options*)arg)->bloom_level4_weight), 0.01f, "%1.2f", string, newval);
3269}
3270
3271static INT32 slider_bloom_lvl5_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3272{
3273   ((hlsl_options*)arg)->params_dirty = true;
3274   return slider_set(&(((hlsl_options*)arg)->bloom_level5_weight), 0.01f, "%1.2f", string, newval);
3275}
3276
3277static INT32 slider_bloom_lvl6_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3278{
3279   ((hlsl_options*)arg)->params_dirty = true;
3280   return slider_set(&(((hlsl_options*)arg)->bloom_level6_weight), 0.01f, "%1.2f", string, newval);
3281}
3282
3283static INT32 slider_bloom_lvl7_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3284{
3285   ((hlsl_options*)arg)->params_dirty = true;
3286   return slider_set(&(((hlsl_options*)arg)->bloom_level7_weight), 0.01f, "%1.2f", string, newval);
3287}
3288
3289static INT32 slider_bloom_lvl8_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3290{
3291   ((hlsl_options*)arg)->params_dirty = true;
3292   return slider_set(&(((hlsl_options*)arg)->bloom_level8_weight), 0.01f, "%1.2f", string, newval);
3293}
3294
3295static INT32 slider_bloom_lvl9_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3296{
3297   ((hlsl_options*)arg)->params_dirty = true;
3298   return slider_set(&(((hlsl_options*)arg)->bloom_level9_weight), 0.01f, "%1.2f", string, newval);
3299}
3300
3301static INT32 slider_bloom_lvl10_scale(running_machine &machine, void *arg, astring *string, INT32 newval)
3302{
3303   ((hlsl_options*)arg)->params_dirty = true;
3304   return slider_set(&(((hlsl_options*)arg)->bloom_level10_weight), 0.01f, "%1.2f", string, newval);
3305}
3306
3307//============================================================
3308//  init_slider_list
3309//============================================================
3310
3311shaders::slider_desc shaders::s_sliders[] =
3312{
3313   { "Shadow Mask Darkness",                0,     0,   100, 1, slider_shadow_mask_alpha },
3314   { "Shadow Mask X Count",                 1,   320,  1024, 1, slider_shadow_mask_x_count },
3315   { "Shadow Mask Y Count",                 1,   240,  1024, 1, slider_shadow_mask_y_count },
3316   { "Shadow Mask Pixel Count X",           1,     6,    64, 1, slider_shadow_mask_usize },
3317   { "Shadow Mask Pixel Count Y",           1,     7,    64, 1, slider_shadow_mask_vsize },
3318   { "Shadow Mask Pixel Count Y",           1,     7,    64, 1, slider_shadow_mask_vsize },
3319   { "Shadow Mask Pixel Count Y",           1,     7,    64, 1, slider_shadow_mask_vsize },
3320   { "Shadow Mask Pixel Count Y",           1,     7,    64, 1, slider_shadow_mask_vsize },
3321   { "Screen Curvature",                    0,     3,   100, 1, slider_curvature },
3322   { "Image Pincushion",                    0,     3,   100, 1, slider_pincushion },
3323   { "Scanline Darkness",                   0,   100,   100, 1, slider_scanline_alpha },
3324   { "Scanline Screen Height",              1,    20,    80, 1, slider_scanline_scale },
3325   { "Scanline Indiv. Height",              1,    20,    80, 1, slider_scanline_height },
3326   { "Scanline Brightness",                 0,    20,    40, 1, slider_scanline_bright_scale },
3327   { "Scanline Brightness Overdrive",       0,     0,    20, 1, slider_scanline_bright_offset },
3328   { "Scanline Jitter",                     0,     0,    40, 1, slider_scanline_offset },
3329   { "Defocus X",                           0,     0,    64, 1, slider_defocus_x },
3330   { "Defocus Y",                           0,     0,    64, 1, slider_defocus_y },
3331   { "Red Position Offset X",           -1500,     3,  1500, 1, slider_red_converge_x },
3332   { "Red Position Offset Y",           -1500,     0,  1500, 1, slider_red_converge_y },
3333   { "Green Position Offset X",         -1500,     0,  1500, 1, slider_green_converge_x },
3334   { "Green Position Offset Y",         -1500,     3,  1500, 1, slider_green_converge_y },
3335   { "Blue Position Offset X",          -1500,     3,  1500, 1, slider_blue_converge_x },
3336   { "Blue Position Offset Y",          -1500,     3,  1500, 1, slider_blue_converge_y },
3337   { "Red Convergence X",               -1500,     0,  1500, 1, slider_red_radial_converge_x },
3338   { "Red Convergence Y",               -1500,     0,  1500, 1, slider_red_radial_converge_y },
3339   { "Green Convergence X",             -1500,     0,  1500, 1, slider_green_radial_converge_x },
3340   { "Green Convergence Y",             -1500,     0,  1500, 1, slider_green_radial_converge_y },
3341   { "Blue Convergence X",              -1500,     0,  1500, 1, slider_blue_radial_converge_x },
3342   { "Blue Convergence Y",              -1500,     0,  1500, 1, slider_blue_radial_converge_y },
3343   { "Red Output from Red Input",        -400,     0,   400, 5, slider_red_from_r },
3344   { "Red Output from Green Input",      -400,     0,   400, 5, slider_red_from_g },
3345   { "Red Output from Blue Input",       -400,     0,   400, 5, slider_red_from_b },
3346   { "Green Output from Red Input",      -400,     0,   400, 5, slider_green_from_r },
3347   { "Green Output from Green Input",    -400,     0,   400, 5, slider_green_from_g },
3348   { "Green Output from Blue Input",     -400,     0,   400, 5, slider_green_from_b },
3349   { "Blue Output from Red Input",       -400,     0,   400, 5, slider_blue_from_r },
3350   { "Blue Output from Green Input",     -400,     0,   400, 5, slider_blue_from_g },
3351   { "Blue Output from Blue Input",      -400,     0,   400, 5, slider_blue_from_b },
3352   { "Saturation",                          0,   140,   400, 1, slider_saturation },
3353   { "Red DC Offset",                    -100,     0,   100, 1, slider_red_offset },
3354   { "Green DC Offset",                  -100,     0,   100, 1, slider_green_offset },
3355   { "Blue DC Offset",                   -100,     0,   100, 1, slider_blue_offset },
3356   { "Red Scale",                        -200,    95,   200, 1, slider_red_scale },
3357   { "Green Scale",                      -200,    95,   200, 1, slider_green_scale },
3358   { "Blue Scale",                       -200,    95,   200, 1, slider_blue_scale },
3359   { "Red Gamma",                         -80,    16,    80, 1, slider_red_power },
3360   { "Green Gamma",                       -80,    16,    80, 1, slider_green_power },
3361   { "Blue Gamma",                        -80,    16,    80, 1, slider_blue_power },
3362   { "Red Floor",                           0,     5,   100, 1, slider_red_floor },
3363   { "Green Floor",                         0,     5,   100, 1, slider_green_floor },
3364   { "Blue Floor",                          0,     5,   100, 1, slider_blue_floor },
3365   { "Red Phosphor Life",                   0,    40,   100, 1, slider_red_phosphor_life },
3366   { "Green Phosphor Life",                 0,    40,   100, 1, slider_green_phosphor_life },
3367   { "Blue Phosphor Life",                  0,    40,   100, 1, slider_blue_phosphor_life },
3368   { "Vector Length Attenuation",           0,    80,   100, 1, slider_vector_attenuation },
3369   { "Vector Attenuation Length Limit",     1,   500,  1000, 1, slider_vector_length_max },
3370   { "Vector Bloom Scale",                  0,   300,  1000, 5, slider_vector_bloom_scale },
3371   { "Raster Bloom Scale",                  0,   225,  1000, 5, slider_raster_bloom_scale },
3372   { "Bloom Level 0 Scale",                 0,   100,   100, 1, slider_bloom_lvl0_scale },
3373   { "Bloom Level 1 Scale",                 0,    21,   100, 1, slider_bloom_lvl1_scale },
3374   { "Bloom Level 2 Scale",                 0,    19,   100, 1, slider_bloom_lvl2_scale },
3375   { "Bloom Level 3 Scale",                 0,    17,   100, 1, slider_bloom_lvl3_scale },
3376   { "Bloom Level 4 Scale",                 0,    15,   100, 1, slider_bloom_lvl4_scale },
3377   { "Bloom Level 5 Scale",                 0,    14,   100, 1, slider_bloom_lvl5_scale },
3378   { "Bloom Level 6 Scale",                 0,    13,   100, 1, slider_bloom_lvl6_scale },
3379   { "Bloom Level 7 Scale",                 0,    12,   100, 1, slider_bloom_lvl7_scale },
3380   { "Bloom Level 8 Scale",                 0,    11,   100, 1, slider_bloom_lvl8_scale },
3381   { "Bloom Level 9 Scale",                 0,    10,   100, 1, slider_bloom_lvl9_scale },
3382   { "Bloom Level 10 Scale",                0,     9,   100, 1, slider_bloom_lvl10_scale },
3383   { NULL, 0, 0, 0, 0, NULL },
3384};
3385
3386slider_state *shaders::init_slider_list()
3387{
3388   if (!master_enable || !d3dintf->post_fx_available)
3389   {
3390      g_slider_list = NULL;
3391      return NULL;
3392   }
3393
3394   slider_state *listhead = NULL;
3395   slider_state **tailptr = &listhead;
3396
3397   for (int index = 0; s_sliders[index].name != NULL; index++)
3398   {
3399      slider_desc *slider = &s_sliders[index];
3400      *tailptr = slider_alloc(window->machine(), slider->name, slider->minval, slider->defval, slider->maxval, slider->step, slider->adjustor, (void*)options);
3401      tailptr = &(*tailptr)->next;
3402   }
3403
3404   return listhead;
3405}
3406
3407};
3408
3409//============================================================
3410//  get_slider_list
3411//============================================================
3412
3413void *windows_osd_interface::get_slider_list()
3414{
3415   return (void*)g_slider_list;
3416}
3417
3418
3419
3420// NOTE: The function below is taken directly from src/emu/video.c and should likely be moved into a global helper function.
3421//-------------------------------------------------
3422//  open_next - open the next non-existing file of
3423//  type filetype according to our numbering
3424//  scheme
3425//-------------------------------------------------
3426
3427static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *templ, const char *extension, int idx)
3428{
3429   UINT32 origflags = file.openflags();
3430
3431   // handle defaults
3432   const char *snapname = templ ? templ : d3d->get_window()->machine().options().snap_name();
3433
3434   if (snapname == NULL || snapname[0] == 0)
3435      snapname = "%g/%i";
3436   astring snapstr(snapname);
3437
3438   // strip any extension in the provided name
3439   int index = snapstr.rchr(0, '.');
3440   if (index != -1)
3441      snapstr.substr(0, index);
3442
3443   // handle %d in the template (for image devices)
3444   astring snapdev("%d_");
3445   int pos = snapstr.find(0, snapdev);
3446
3447   if (pos != -1)
3448   {
3449      // if more %d are found, revert to default and ignore them all
3450      if (snapstr.find(pos + 3, snapdev) != -1)
3451         snapstr.cpy("%g/%i");
3452      // else if there is a single %d, try to create the correct snapname
3453      else
3454      {
3455         int name_found = 0;
3456
3457         // find length of the device name
3458         int end1 = snapstr.find(pos + 3, "/");
3459         int end2 = snapstr.find(pos + 3, "%");
3460         int end = -1;
3461
3462         if ((end1 != -1) && (end2 != -1))
3463            end = MIN(end1, end2);
3464         else if (end1 != -1)
3465            end = end1;
3466         else if (end2 != -1)
3467            end = end2;
3468         else
3469            end = snapstr.len();
3470
3471         if (end - pos < 3)
3472            fatalerror("Something very wrong is going on!!!\n");
3473
3474         // copy the device name to an astring
3475         astring snapdevname;
3476         snapdevname.cpysubstr(snapstr, pos + 3, end - pos - 3);
3477
3478         // verify that there is such a device for this system
3479         image_interface_iterator iter(d3d->get_window()->machine().root_device());
3480         for (device_image_interface *image = iter.first(); image != NULL; iter.next())
3481         {
3482            // get the device name
3483            astring tempdevname(image->brief_instance_name());
3484
3485            if (snapdevname.cmp(tempdevname) == 0)
3486            {
3487               // verify that such a device has an image mounted
3488               if (image->basename() != NULL)
3489               {
3490                  astring filename(image->basename());
3491
3492                  // strip extension
3493                  filename.substr(0, filename.rchr(0, '.'));
3494
3495                  // setup snapname and remove the %d_
3496                  snapstr.replace(0, snapdevname, filename);
3497                  snapstr.del(pos, 3);
3498
3499                  name_found = 1;
3500               }
3501            }
3502         }
3503
3504         // or fallback to default
3505         if (name_found == 0)
3506            snapstr.cpy("%g/%i");
3507      }
3508   }
3509
3510   // add our own index
3511   // add our own extension
3512   snapstr.cat(".").cat(extension);
3513
3514   // substitute path and gamename up front
3515   snapstr.replace(0, "/", PATH_SEPARATOR);
3516   snapstr.replace(0, "%g", d3d->get_window()->machine().basename());
3517
3518   // determine if the template has an index; if not, we always use the same name
3519   astring fname;
3520   if (snapstr.find(0, "%i") == -1)
3521      fname.cpy(snapstr);
3522
3523   // otherwise, we scan for the next available filename
3524   else
3525   {
3526      // try until we succeed
3527      astring seqtext;
3528      file.set_openflags(OPEN_FLAG_READ);
3529      for (int seq = 0; ; seq++)
3530      {
3531         // build up the filename
3532         fname.cpy(snapstr).replace(0, "%i", seqtext.format("%04d_%d", seq, idx).cstr());
3533
3534         // try to open the file; stop when we fail
3535         file_error filerr = file.open(fname);
3536         if (filerr != FILERR_NONE)
3537            break;
3538      }
3539   }
3540
3541   // create the final file
3542   file.set_openflags(origflags);
3543   return file.open(fname);
3544}
Property changes on: trunk/src/osd/windows/d3dhlsl.c
Added: svn:eol-style
   + native
Added: svn:mime-type
   + text/plain
trunk/src/osd/windows/drawd3d.h
r23474r23475
4343#define __WIN_DRAWD3D__
4444
4545
46#include "d3dhlsl.h"
47
48
4649//============================================================
4750//  CONSTANTS
4851//============================================================
r23474r23475
198201   texture_info *          get_default_texture() { return m_texture_manager->get_default_texture(); }
199202   texture_info *          get_vector_texture() { return m_texture_manager->get_vector_texture(); }
200203
204   shaders *               get_shaders() { return m_shaders; }
205
201206private:
202207   int                     m_adapter;                  // ordinal adapter number
203208   int                     m_width;                    // current width
r23474r23475
239244   D3DTEXTUREADDRESS       m_last_wrap;                // previous wrap state
240245   DWORD                   m_last_modmode;             // previous texture modulation
241246
247   void *                  m_hlsl_buf;                 // HLSL vertex data
248   shaders *               m_shaders;                  // HLSL interface
249
242250   texture_manager *       m_texture_manager;          // texture manager
243251
244252   int                     m_line_count;
trunk/src/osd/windows/d3dintf.h
r23474r23475
4242#ifndef __WIN_D3DINTF__
4343#define __WIN_D3DINTF__
4444
45//#include "winmain.h"
4645
4746//============================================================
4847//  CONSTANTS
r23474r23475
267266   int                         version;
268267   void *                      d3dobj;
269268   HINSTANCE                   dllhandle;
269   bool                        post_fx_available;
270270
271271   // interface pointers
272272   interface               d3d;
r23474r23475
282282//  PROTOTYPES
283283//============================================================
284284
285base *drawd3d9_init();
285base *drawd3d9_init(void);
286286
287287};
288288
trunk/src/osd/windows/d3dhlsl.h
r0r23475
1//============================================================
2//
3//  drawd3d.c - Win32 Direct3D HLSL-specific header
4//
5//============================================================
6//
7//  Copyright Aaron Giles
8//  All rights reserved.
9//
10//  Redistribution and use in source and binary forms, with or
11//  without modification, are permitted provided that the
12//  following conditions are met:
13//
14//    * Redistributions of source code must retain the above
15//      copyright notice, this list of conditions and the
16//      following disclaimer.
17//    * Redistributions in binary form must reproduce the
18//      above copyright notice, this list of conditions and
19//      the following disclaimer in the documentation and/or
20//      other materials provided with the distribution.
21//    * Neither the name 'MAME' nor the names of its
22//      contributors may be used to endorse or promote
23//      products derived from this software without specific
24//      prior written permission.
25//
26//  THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND
27//  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29//  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30//  EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
31//  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32//  DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33//  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35//  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37//  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38//  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39//
40//============================================================
41
42#ifndef __WIN_D3DHLSL__
43#define __WIN_D3DHLSL__
44
45#include "aviio.h"
46
47//============================================================
48//  CONSTANTS
49//============================================================
50
51#define HLSL_VECTOR         (1)
52#define CRT_BLOOM           (1)
53
54//============================================================
55//  TYPE DEFINITIONS
56//============================================================
57
58namespace d3d
59{
60class render_target;
61class cache_target;
62class renderer;
63
64/* hlsl_options is the information about runtime-mutable Direct3D HLSL options */
65/* in the future this will be moved into an OSD/emu shared buffer */
66struct hlsl_options
67{
68   bool                    params_dirty;
69   float                   shadow_mask_alpha;
70   char                    shadow_mask_texture[1024];
71   int                     shadow_mask_count_x;
72   int                     shadow_mask_count_y;
73   float                   shadow_mask_u_size;
74   float                   shadow_mask_v_size;
75   float                   curvature;
76   float                   pincushion;
77   float                   scanline_alpha;
78   float                   scanline_scale;
79   float                   scanline_height;
80   float                   scanline_bright_scale;
81   float                   scanline_bright_offset;
82   float                   scanline_offset;
83   float                   defocus[4];
84   float                   converge_x[3];
85   float                   converge_y[3];
86   float                   radial_converge_x[3];
87   float                   radial_converge_y[3];
88   float                   red_ratio[3];
89   float                   grn_ratio[3];
90   float                   blu_ratio[3];
91   float                   offset[3];
92   float                   scale[3];
93   float                   power[3];
94   float                   floor[3];
95   float                   phosphor[3];
96   float                   saturation;
97
98   // NTSC
99   bool                    yiq_enable;
100   float                   yiq_cc;
101   float                   yiq_a;
102   float                   yiq_b;
103   float                   yiq_o;
104   float                   yiq_p;
105   float                   yiq_n;
106   float                   yiq_y;
107   float                   yiq_i;
108   float                   yiq_q;
109   float                   yiq_scan_time;
110   int                     yiq_phase_count;
111
112   // Vectors
113   float                   vector_length_scale;
114   float                   vector_length_ratio;
115
116   // Bloom
117   float                   vector_bloom_scale;
118   float                   raster_bloom_scale;
119   float                   bloom_level0_weight;
120   float                   bloom_level1_weight;
121   float                   bloom_level2_weight;
122   float                   bloom_level3_weight;
123   float                   bloom_level4_weight;
124   float                   bloom_level5_weight;
125   float                   bloom_level6_weight;
126   float                   bloom_level7_weight;
127   float                   bloom_level8_weight;
128   float                   bloom_level9_weight;
129   float                   bloom_level10_weight;
130};
131
132class shaders
133{
134public:
135   // construction/destruction
136   shaders();
137   ~shaders();
138
139   void init(base *d3dintf, win_window_info *window);
140
141   bool enabled() { return master_enable; }
142   void toggle();
143
144   bool vector_enabled() { return master_enable && vector_enable && (bool)HLSL_VECTOR; }
145   render_target* get_vector_target();
146   void create_vector_target(render_primitive *prim);
147
148   void begin_frame();
149   void end_frame();
150
151   void begin_draw();
152   void end_draw();
153
154   void init_effect_info(poly_info *poly);
155   void render_quad(poly_info *poly, int vertnum);
156
157   bool register_texture(texture_info *texture);
158   bool register_prescaled_texture(texture_info *texture);
159   bool add_render_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale);
160   bool add_cache_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index);
161
162   void window_save();
163   void window_record();
164   bool recording() { return avi_output_file != NULL; }
165
166   void avi_update_snap(surface *surface);
167   void render_snapshot(surface *surface);
168   void record_texture();
169   void init_fsfx_quad(void *vertbuf);
170
171   void                    set_texture(texture_info *texture);
172   render_target *         find_render_target(texture_info *info);
173   void                    remove_render_target(texture_info *texture);
174   void                    remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
175   void                    remove_render_target(render_target *rt);
176
177   int create_resources(bool reset);
178   void delete_resources(bool reset);
179
180   // slider-related functions
181   slider_state *init_slider_list();
182
183   struct slider_desc
184   {
185      const char *      name;
186      int               minval;
187      int               defval;
188      int               maxval;
189      int               step;
190      INT32 (*adjustor)(running_machine &, void *, astring *, INT32);
191   };
192
193private:
194   void                    blit(surface *dst, texture *src, surface *new_dst,
195                           D3DPRIMITIVETYPE prim_type, UINT32 prim_index, UINT32 prim_count,
196                           int dstw, int dsth);
197   void                    blit(surface *dst, texture *src, surface *new_dst,
198                           D3DPRIMITIVETYPE prim_type, UINT32 prim_index, UINT32 prim_count);
199   void                    enumerate_screens();
200
201   void                    end_avi_recording();
202   void                    begin_avi_recording(const char *name);
203
204   bool                    register_texture(texture_info *texture, int width, int height, int xscale, int yscale);
205
206   render_target*          find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
207   cache_target *          find_cache_target(UINT32 screen_index, int width, int height);
208   void                    remove_cache_target(cache_target *cache);
209
210   base *                  d3dintf;                    // D3D interface
211   win_window_info *       window;                     // D3D window info
212
213   bool                    master_enable;              // overall enable flag
214   bool                    vector_enable;              // vector post-processing enable flag
215   bool                    paused;                     // whether or not rendering is currently paused
216   int                     num_screens;                // number of emulated physical screens
217   int                     curr_screen;                // current screen for render target operations
218   int                     curr_frame;                 // current frame (0/1) of a screen for render target operations
219   int                     lastidx;                    // index of the last-encountered target
220   bool                    write_ini;                  // enable external ini saving
221   bool                    read_ini;                   // enable external ini loading
222   int                     prescale_force_x;           // prescale force x
223   int                     prescale_force_y;           // prescale force y
224   int                     prescale_size_x;            // prescale size x
225   int                     prescale_size_y;            // prescale size y
226   int                     preset;                     // preset, if relevant
227   bitmap_argb32           shadow_bitmap;              // shadow mask bitmap for post-processing shader
228   texture_info *          shadow_texture;             // shadow mask texture for post-processing shader
229   hlsl_options *          options;                    // current uniform state
230   D3DPRIMITIVETYPE        vecbuf_type;
231   UINT32                  vecbuf_index;
232   UINT32                  vecbuf_count;
233
234   avi_file *              avi_output_file;            // AVI file
235   bitmap_rgb32            avi_snap;                   // AVI snapshot
236   int                     avi_frame;                  // AVI frame
237   attotime                avi_frame_period;           // AVI frame period
238   attotime                avi_next_frame_time;        // AVI next frame time
239   surface *               avi_copy_surface;           // AVI destination surface in system memory
240   texture *               avi_copy_texture;           // AVI destination texture in system memory
241   surface *               avi_final_target;           // AVI upscaled surface
242   texture *               avi_final_texture;          // AVI upscaled texture
243
244   surface *               black_surface;              // black dummy surface
245   texture *               black_texture;              // black dummy texture
246
247   bool                    render_snap;                // whether or not to take HLSL post-render snapshot
248   bool                    snap_rendered;              // whether we just rendered our HLSL post-render shot or not
249   surface *               snap_copy_target;           // snapshot destination surface in system memory
250   texture *               snap_copy_texture;          // snapshot destination surface in system memory
251   surface *               snap_target;                // snapshot upscaled surface
252   texture *               snap_texture;               // snapshot upscaled texture
253   int                     snap_width;                 // snapshot width
254   int                     snap_height;                // snapshot height
255   bool                    lines_pending;              // whether or not we have lines to flush on the next quad
256
257   bool                    initialized;                // whether or not we're initialize
258
259   // HLSL effects
260   surface *               backbuffer;                 // pointer to our device's backbuffer
261   effect *                curr_effect;                // pointer to the currently active effect object
262   effect *                default_effect;             // pointer to the primary-effect object
263   effect *                prescale_effect;            // pointer to the prescale-effect object
264   effect *                post_effect;                // pointer to the post-effect object
265   effect *                pincushion_effect;          // pointer to the pincushion-effect object
266   effect *                focus_effect;               // pointer to the focus-effect object
267   effect *                phosphor_effect;            // pointer to the phosphor-effect object
268   effect *                deconverge_effect;          // pointer to the deconvergence-effect object
269   effect *                color_effect;               // pointer to the color-effect object
270   effect *                yiq_encode_effect;          // pointer to the YIQ encoder effect object
271   effect *                yiq_decode_effect;          // pointer to the YIQ decoder effect object
272#if (HLSL_VECTOR || CRT_BLOOM)
273   effect *                bloom_effect;               // pointer to the bloom composite effect
274   effect *                downsample_effect;          // pointer to the bloom downsample effect
275#endif
276#if (HLSL_VECTOR)
277   effect *                vector_effect;              // pointer to the vector-effect object
278#endif
279   vertex *                fsfx_vertices;              // pointer to our full-screen-quad object
280
281public:
282   render_target *         targethead;
283   cache_target *          cachehead;
284
285   static slider_desc       s_sliders[];
286   static hlsl_options     s_hlsl_presets[4];
287};
288
289};
290
291#endif
Property changes on: trunk/src/osd/windows/d3dhlsl.h
Added: svn:eol-style
   + native
Added: svn:mime-type
   + text/plain
trunk/src/osd/windows/drawdd.c
r23474r23475
223223   callbacks->window_draw = drawdd_window_draw;
224224   callbacks->window_save = NULL;
225225   callbacks->window_record = NULL;
226   callbacks->window_toggle_fsfx = NULL;
226227   callbacks->window_destroy = drawdd_window_destroy;
227228
228229   mame_printf_verbose("DirectDraw: Using DirectDraw 7\n");
trunk/src/osd/windows/windows.mak
r23474r23475
306306OSDOBJS = \
307307   $(WINOBJ)/d3d9intf.o \
308308   $(WINOBJ)/drawd3d.o \
309   $(WINOBJ)/d3dhlsl.o \
309310   $(WINOBJ)/drawdd.o \
310311   $(WINOBJ)/drawgdi.o \
311312   $(WINOBJ)/drawnone.o \
trunk/src/osd/windows/drawgdi.c
r23474r23475
9393   callbacks->window_draw = drawgdi_window_draw;
9494   callbacks->window_save = NULL;
9595   callbacks->window_record = NULL;
96   callbacks->window_toggle_fsfx = NULL;
9697   callbacks->window_destroy = drawgdi_window_destroy;
9798   return 0;
9899}

Previous 199869 Revisions Next


© 1997-2024 The MAME Team