trunk/src/osd/windows/drawd3d.c
| r22936 | r22937 | |
| 113 | 113 | // GLOBALS |
| 114 | 114 | //============================================================ |
| 115 | 115 | |
| 116 | | static d3d_base * d3dintf; // FIX ME |
| 117 | | |
| 118 | 116 | static const line_aa_step line_aa_1step[] = |
| 119 | 117 | { |
| 120 | 118 | { 0.00f, 0.00f, 1.00f }, |
| r22936 | r22937 | |
| 202 | 200 | return MAKE_ARGB(0xff, r, g, b); |
| 203 | 201 | } |
| 204 | 202 | |
| 203 | //============================================================ |
| 204 | // drawd3d_init |
| 205 | //============================================================ |
| 205 | 206 | |
| 206 | | INLINE UINT32 texture_compute_hash(const render_texinfo *texture, UINT32 flags) |
| 207 | static d3d::base * d3dintf; // FIX ME |
| 208 | |
| 209 | //============================================================ |
| 210 | // PROTOTYPES |
| 211 | //============================================================ |
| 212 | |
| 213 | // core functions |
| 214 | static void drawd3d_exit(void); |
| 215 | static int drawd3d_window_init(win_window_info *window); |
| 216 | static void drawd3d_window_destroy(win_window_info *window); |
| 217 | static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window); |
| 218 | static void drawd3d_window_save(win_window_info *window); |
| 219 | static void drawd3d_window_record(win_window_info *window); |
| 220 | static void drawd3d_window_toggle_fsfx(win_window_info *window); |
| 221 | static int drawd3d_window_draw(win_window_info *window, HDC dc, int update); |
| 222 | |
| 223 | |
| 224 | //============================================================ |
| 225 | // drawd3d_window_init |
| 226 | //============================================================ |
| 227 | |
| 228 | static int drawd3d_window_init(win_window_info *window) |
| 207 | 229 | { |
| 208 | | return (FPTR)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)); |
| 230 | // allocate memory for our structures |
| 231 | d3d::renderer *d3d = global_alloc(d3d::renderer(window)); |
| 232 | window->drawdata = d3d; |
| 233 | |
| 234 | if (!d3d->initialize()) |
| 235 | { |
| 236 | drawd3d_window_destroy(window); |
| 237 | mame_printf_error("Unable to initialize Direct3D.\n"); |
| 238 | return 1; |
| 239 | } |
| 240 | |
| 241 | return 0; |
| 209 | 242 | } |
| 210 | 243 | |
| 244 | //============================================================ |
| 245 | // drawd3d_exit |
| 246 | //============================================================ |
| 211 | 247 | |
| 212 | | INLINE void set_texture(d3d_info *d3d, d3d_texture_info *texture) |
| 248 | static void drawd3d_exit(void) |
| 213 | 249 | { |
| 214 | | HRESULT result; |
| 215 | | if (texture != d3d->last_texture) |
| 250 | if (d3dintf != NULL) |
| 251 | (*d3dintf->d3d.release)(d3dintf); |
| 252 | } |
| 253 | |
| 254 | static 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 | |
| 260 | static void drawd3d_window_record(win_window_info *window) |
| 261 | { |
| 262 | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 263 | d3d->get_shaders()->window_record(); |
| 264 | } |
| 265 | |
| 266 | static void drawd3d_window_save(win_window_info *window) |
| 267 | { |
| 268 | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 269 | d3d->get_shaders()->window_save(); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | |
| 274 | //============================================================ |
| 275 | // drawd3d_window_destroy |
| 276 | //============================================================ |
| 277 | |
| 278 | static void drawd3d_window_destroy(win_window_info *window) |
| 279 | { |
| 280 | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 281 | |
| 282 | // skip if nothing |
| 283 | if (d3d == NULL) |
| 284 | return; |
| 285 | |
| 286 | if (d3d->get_shaders()->recording()) |
| 287 | d3d->get_shaders()->window_record(); |
| 288 | |
| 289 | // free the memory in the window |
| 290 | global_free(d3d); |
| 291 | window->drawdata = NULL; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | |
| 296 | //============================================================ |
| 297 | // drawd3d_window_get_primitives |
| 298 | //============================================================ |
| 299 | |
| 300 | static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window) |
| 301 | { |
| 302 | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 303 | RECT client; |
| 304 | |
| 305 | GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen); |
| 306 | if (rect_width(&client) > 0 && rect_height(&client) > 0) |
| 216 | 307 | { |
| 217 | | d3d->last_texture = texture; |
| 218 | | d3d->last_texture_flags = (texture == NULL ? 0 : texture->flags); |
| 219 | | result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 220 | | d3d->hlsl->set_texture(texture); |
| 308 | window->target->set_bounds(rect_width(&client), rect_height(&client), winvideo_monitor_get_aspect(window->monitor)); |
| 309 | window->target->set_max_update_rate((d3d->get_refresh() == 0) ? d3d->get_origmode().RefreshRate : d3d->get_refresh()); |
| 310 | } |
| 311 | return &window->target->get_primitives(); |
| 312 | } |
| 313 | |
| 314 | int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks) |
| 315 | { |
| 316 | d3dintf = NULL; |
| 317 | |
| 318 | // Use Direct3D9 |
| 319 | d3dintf = d3d::drawd3d9_init(); |
| 320 | |
| 321 | // if we failed, note the error |
| 322 | if (d3dintf == NULL) |
| 323 | { |
| 324 | mame_printf_error("Unable to initialize Direct3D.\n"); |
| 325 | return 1; |
| 326 | } |
| 327 | |
| 328 | // fill in the callbacks |
| 329 | callbacks->exit = drawd3d_exit; |
| 330 | callbacks->window_init = drawd3d_window_init; |
| 331 | callbacks->window_get_primitives = drawd3d_window_get_primitives; |
| 332 | callbacks->window_draw = drawd3d_window_draw; |
| 333 | callbacks->window_save = drawd3d_window_save; |
| 334 | callbacks->window_record = drawd3d_window_record; |
| 335 | callbacks->window_toggle_fsfx = drawd3d_window_toggle_fsfx; |
| 336 | callbacks->window_destroy = drawd3d_window_destroy; |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | //============================================================ |
| 341 | // drawd3d_window_draw |
| 342 | //============================================================ |
| 343 | |
| 344 | static int drawd3d_window_draw(win_window_info *window, HDC dc, int update) |
| 345 | { |
| 346 | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 347 | |
| 348 | // if we haven't been created, just punt |
| 349 | if (d3d == NULL) |
| 350 | return 1; |
| 351 | |
| 352 | int check = d3d->pre_window_draw_check(); |
| 353 | if (check >= 0) |
| 354 | return check; |
| 355 | |
| 356 | d3d->begin_frame(); |
| 357 | d3d->process_primitives(); |
| 358 | d3d->end_frame(); |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | namespace d3d |
| 364 | { |
| 365 | |
| 366 | void renderer::set_texture(texture_info *texture) |
| 367 | { |
| 368 | if (texture != m_last_texture) |
| 369 | { |
| 370 | m_last_texture = texture; |
| 371 | m_last_texture_flags = (texture == NULL ? 0 : texture->get_flags()); |
| 372 | HRESULT result = (*d3dintf->device.set_texture)(m_device, 0, (texture == NULL) ? get_default_texture()->get_finaltex() : texture->get_finaltex()); |
| 373 | m_shaders->set_texture(texture); |
| 221 | 374 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result); |
| 222 | 375 | } |
| 223 | 376 | } |
| 224 | 377 | |
| 225 | 378 | |
| 226 | | INLINE void set_filter(d3d_info *d3d, int filter) |
| 379 | void renderer::set_filter(int filter) |
| 227 | 380 | { |
| 228 | | HRESULT result; |
| 229 | | if (filter != d3d->last_filter) |
| 381 | if (filter != m_last_filter) |
| 230 | 382 | { |
| 231 | | d3d->last_filter = filter; |
| 232 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 383 | m_last_filter = filter; |
| 384 | HRESULT result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 233 | 385 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 234 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 386 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 235 | 387 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 236 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 388 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 237 | 389 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 238 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 390 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT); |
| 239 | 391 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 240 | 392 | } |
| 241 | 393 | } |
| 242 | 394 | |
| 243 | 395 | |
| 244 | | INLINE void set_wrap(d3d_info *d3d, int wrap) |
| 396 | void renderer::set_wrap(D3DTEXTUREADDRESS wrap) |
| 245 | 397 | { |
| 246 | | HRESULT result; |
| 247 | | if (wrap != d3d->last_wrap) |
| 398 | if (wrap != m_last_wrap) |
| 248 | 399 | { |
| 249 | | d3d->last_wrap = wrap; |
| 250 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); |
| 400 | m_last_wrap = wrap; |
| 401 | HRESULT result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap); |
| 251 | 402 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 252 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); |
| 403 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap); |
| 253 | 404 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 254 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); |
| 405 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap); |
| 255 | 406 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 256 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); |
| 407 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap); |
| 257 | 408 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 258 | 409 | } |
| 259 | 410 | } |
| 260 | 411 | |
| 261 | 412 | |
| 262 | | INLINE void set_modmode(d3d_info *d3d, DWORD modmode) |
| 413 | void renderer::set_modmode(DWORD modmode) |
| 263 | 414 | { |
| 264 | | HRESULT result; |
| 265 | | if (modmode != d3d->last_modmode) |
| 415 | if (modmode != m_last_modmode) |
| 266 | 416 | { |
| 267 | | d3d->last_modmode = modmode; |
| 268 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_COLOROP, modmode); |
| 417 | m_last_modmode = modmode; |
| 418 | HRESULT result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, D3DTSS_COLOROP, modmode); |
| 269 | 419 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 270 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_COLOROP, modmode); |
| 420 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, D3DTSS_COLOROP, modmode); |
| 271 | 421 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result); |
| 272 | 422 | } |
| 273 | 423 | } |
| 274 | 424 | |
| 275 | 425 | |
| 276 | | INLINE void set_blendmode(d3d_info *d3d, int blendmode) |
| 426 | void renderer::set_blendmode(int blendmode) |
| 277 | 427 | { |
| 278 | | HRESULT result; |
| 279 | 428 | int blendenable; |
| 280 | 429 | int blendop; |
| 281 | 430 | int blendsrc; |
| r22936 | r22937 | |
| 292 | 441 | } |
| 293 | 442 | |
| 294 | 443 | // adjust the bits that changed |
| 295 | | if (blendenable != d3d->last_blendenable) |
| 444 | if (blendenable != m_last_blendenable) |
| 296 | 445 | { |
| 297 | | d3d->last_blendenable = blendenable; |
| 298 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ALPHABLENDENABLE, blendenable); |
| 446 | m_last_blendenable = blendenable; |
| 447 | HRESULT result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ALPHABLENDENABLE, blendenable); |
| 299 | 448 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_state call\n", (int)result); |
| 300 | 449 | } |
| 301 | 450 | |
| 302 | | if (blendop != d3d->last_blendop) |
| 451 | if (blendop != m_last_blendop) |
| 303 | 452 | { |
| 304 | | d3d->last_blendop = blendop; |
| 305 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_BLENDOP, blendop); |
| 453 | m_last_blendop = blendop; |
| 454 | HRESULT result = (*d3dintf->device.set_render_state)(m_device, D3DRS_BLENDOP, blendop); |
| 306 | 455 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_state call\n", (int)result); |
| 307 | 456 | } |
| 308 | 457 | |
| 309 | | if (blendsrc != d3d->last_blendsrc) |
| 458 | if (blendsrc != m_last_blendsrc) |
| 310 | 459 | { |
| 311 | | d3d->last_blendsrc = blendsrc; |
| 312 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_SRCBLEND, blendsrc); |
| 460 | m_last_blendsrc = blendsrc; |
| 461 | HRESULT result = (*d3dintf->device.set_render_state)(m_device, D3DRS_SRCBLEND, blendsrc); |
| 313 | 462 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_state call\n", (int)result); |
| 314 | 463 | } |
| 315 | 464 | |
| 316 | | if (blenddst != d3d->last_blenddst) |
| 465 | if (blenddst != m_last_blenddst) |
| 317 | 466 | { |
| 318 | | d3d->last_blenddst = blenddst; |
| 319 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_DESTBLEND, blenddst); |
| 467 | m_last_blenddst = blenddst; |
| 468 | HRESULT result = (*d3dintf->device.set_render_state)(m_device, D3DRS_DESTBLEND, blenddst); |
| 320 | 469 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_state call\n", (int)result); |
| 321 | 470 | } |
| 322 | 471 | } |
| 323 | 472 | |
| 324 | 473 | |
| 325 | | INLINE void reset_render_states(d3d_info *d3d) |
| 474 | void renderer::reset_render_states() |
| 326 | 475 | { |
| 327 | 476 | // this ensures subsequent calls to the above setters will force-update the data |
| 328 | | d3d->last_texture = (d3d_texture_info *)~0; |
| 329 | | d3d->last_filter = -1; |
| 330 | | d3d->last_blendenable = -1; |
| 331 | | d3d->last_blendop = -1; |
| 332 | | d3d->last_blendsrc = -1; |
| 333 | | d3d->last_blenddst = -1; |
| 334 | | d3d->last_wrap = -1; |
| 477 | m_last_texture = (texture_info *)~0; |
| 478 | m_last_filter = -1; |
| 479 | m_last_blendenable = -1; |
| 480 | m_last_blendop = -1; |
| 481 | m_last_blendsrc = -1; |
| 482 | m_last_blenddst = -1; |
| 483 | m_last_wrap = (D3DTEXTUREADDRESS)-1; |
| 335 | 484 | } |
| 336 | 485 | |
| 337 | 486 | |
| 338 | 487 | |
| 339 | | //============================================================ |
| 340 | | // PROTOTYPES |
| 341 | | //============================================================ |
| 488 | texture_manager::texture_manager(renderer *d3d) |
| 489 | { |
| 490 | m_renderer = d3d; |
| 342 | 491 | |
| 343 | | // core functions |
| 344 | | static void drawd3d_exit(void); |
| 345 | | static int drawd3d_window_init(win_window_info *window); |
| 346 | | static void drawd3d_window_destroy(win_window_info *window); |
| 347 | | static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window); |
| 348 | | static void drawd3d_window_save(win_window_info *window); |
| 349 | | static void drawd3d_window_record(win_window_info *window); |
| 350 | | static void drawd3d_window_toggle_fsfx(win_window_info *window); |
| 351 | | static int drawd3d_window_draw(win_window_info *window, HDC dc, int update); |
| 492 | m_texlist = NULL; |
| 352 | 493 | |
| 353 | | // devices |
| 354 | | static int device_create(win_window_info *window); |
| 355 | | static int device_create_resources(d3d_info *d3d); |
| 356 | | static void device_delete(d3d_info *d3d); |
| 357 | | static void device_delete_resources(d3d_info *d3d); |
| 358 | | static int device_verify_caps(d3d_info *d3d, win_window_info *window); |
| 359 | | static int device_test_cooperative(d3d_info *d3d); |
| 494 | // check for dynamic texture support |
| 495 | DWORD tempcaps; |
| 496 | HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_CAPS2, &tempcaps); |
| 497 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 498 | m_dynamic_supported = ((tempcaps & D3DCAPS2_DYNAMICTEXTURES) != 0); |
| 499 | if (m_dynamic_supported) mame_printf_verbose("Direct3D: Using dynamic textures\n"); |
| 360 | 500 | |
| 361 | | // video modes |
| 362 | | static int config_adapter_mode(win_window_info *window); |
| 363 | | static int get_adapter_for_monitor(d3d_info *d3d, win_monitor_info *monitor); |
| 364 | | static void pick_best_mode(win_window_info *window); |
| 365 | | static int update_window_size(win_window_info *window); |
| 501 | // check for stretchrect support |
| 502 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_STRETCH_RECT_FILTER, &tempcaps); |
| 503 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 504 | m_stretch_supported = ((tempcaps & D3DPTFILTERCAPS_MAGFPOINT) != 0); |
| 505 | if (m_stretch_supported && video_config.prescale > 1) mame_printf_verbose("Direct3D: Using StretchRect for prescaling\n"); |
| 366 | 506 | |
| 367 | | // drawing |
| 368 | | static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_time); |
| 369 | | static void draw_quad(d3d_info *d3d, const render_primitive *prim); |
| 507 | // get texture caps |
| 508 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_TEXTURE_CAPS, &m_texture_caps); |
| 509 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 510 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_ASPECT, &m_texture_max_aspect); |
| 511 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 512 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_WIDTH, &m_texture_max_width); |
| 513 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 514 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_HEIGHT, &m_texture_max_height); |
| 515 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 370 | 516 | |
| 371 | | // primitives |
| 372 | | static d3d_vertex *primitive_alloc(d3d_info *d3d, int numverts); |
| 373 | | static void primitive_flush_pending(d3d_info *d3d); |
| 374 | | |
| 375 | | // textures |
| 376 | | static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d_texture_info *texture); |
| 377 | | static void texture_set_data(d3d_info *d3d, d3d_texture_info *texture, const render_texinfo *texsource, UINT32 flags); |
| 378 | | static void texture_prescale(d3d_info *d3d, d3d_texture_info *texture); |
| 379 | | static d3d_texture_info *texture_find(d3d_info *d3d, const render_primitive *prim); |
| 380 | | static void texture_update(d3d_info *d3d, const render_primitive *prim); |
| 381 | | |
| 382 | | //============================================================ |
| 383 | | // drawd3d_init |
| 384 | | //============================================================ |
| 385 | | |
| 386 | | int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks) |
| 387 | | { |
| 388 | | int version = downcast<windows_options &>(machine.options()).d3d_version(); |
| 389 | | d3dintf = NULL; |
| 390 | | |
| 391 | | // try Direct3D 9 if requested |
| 392 | | if (version >= 9) |
| 393 | | d3dintf = drawd3d9_init(); |
| 394 | | |
| 395 | | #if DIRECT3D_VERSION < 0x0900 |
| 396 | | // if that didn't work, try Direct3D 8 |
| 397 | | if (d3dintf == NULL && version >= 8) |
| 398 | | d3dintf = drawd3d8_init(); |
| 399 | | #endif |
| 400 | | |
| 401 | | // if we failed, note the error |
| 402 | | if (d3dintf == NULL) |
| 517 | // pick a YUV texture format |
| 518 | m_yuv_format = D3DFMT_UYVY; |
| 519 | result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, d3d->get_pixel_format(), 0, D3DRTYPE_TEXTURE, D3DFMT_UYVY); |
| 520 | if (result != D3D_OK) |
| 403 | 521 | { |
| 404 | | mame_printf_error("Unable to initialize Direct3D.\n"); |
| 405 | | return 1; |
| 522 | m_yuv_format = D3DFMT_YUY2; |
| 523 | result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, d3d->get_pixel_format(), 0, D3DRTYPE_TEXTURE, D3DFMT_YUY2); |
| 524 | if (result != D3D_OK) |
| 525 | m_yuv_format = D3DFMT_A8R8G8B8; |
| 406 | 526 | } |
| 527 | mame_printf_verbose("Direct3D: YUV format = %s\n", (m_yuv_format == D3DFMT_YUY2) ? "YUY2" : (m_yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB"); |
| 407 | 528 | |
| 408 | | // fill in the callbacks |
| 409 | | callbacks->exit = drawd3d_exit; |
| 410 | | callbacks->window_init = drawd3d_window_init; |
| 411 | | callbacks->window_get_primitives = drawd3d_window_get_primitives; |
| 412 | | callbacks->window_draw = drawd3d_window_draw; |
| 413 | | callbacks->window_save = drawd3d_window_save; |
| 414 | | callbacks->window_record = drawd3d_window_record; |
| 415 | | callbacks->window_toggle_fsfx = drawd3d_window_toggle_fsfx; |
| 416 | | callbacks->window_destroy = drawd3d_window_destroy; |
| 417 | | return 0; |
| 529 | // set the max texture size |
| 530 | d3d->get_window()->target->set_max_texture_size(m_texture_max_width, m_texture_max_height); |
| 531 | mame_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)m_texture_max_width, (int)m_texture_max_height); |
| 418 | 532 | } |
| 419 | 533 | |
| 420 | | |
| 421 | | |
| 422 | | //============================================================ |
| 423 | | // drawd3d_exit |
| 424 | | //============================================================ |
| 425 | | |
| 426 | | static void drawd3d_exit(void) |
| 534 | void texture_manager::create_resources() |
| 427 | 535 | { |
| 428 | | if (d3dintf != NULL) |
| 429 | | (*d3dintf->d3d.release)(d3dintf); |
| 430 | | } |
| 431 | | |
| 432 | | |
| 433 | | |
| 434 | | //============================================================ |
| 435 | | // drawd3d_window_init |
| 436 | | //============================================================ |
| 437 | | |
| 438 | | static int drawd3d_window_init(win_window_info *window) |
| 439 | | { |
| 440 | | d3d_info *d3d; |
| 441 | | |
| 442 | | // allocate memory for our structures |
| 443 | | d3d = global_alloc_clear(d3d_info); |
| 444 | | d3d->restarting = false; |
| 445 | | window->drawdata = d3d; |
| 446 | | d3d->window = window; |
| 447 | | d3d->hlsl = NULL; |
| 448 | | |
| 449 | 536 | // experimental: load a PNG to use for vector rendering; it is treated |
| 450 | 537 | // as a brightness map |
| 451 | | emu_file file(window->machine().options().art_path(), OPEN_FLAG_READ); |
| 452 | | render_load_png(d3d->vector_bitmap, file, NULL, "vector.png"); |
| 453 | | if (d3d->vector_bitmap.valid()) |
| 538 | emu_file file(m_renderer->get_window()->machine().options().art_path(), OPEN_FLAG_READ); |
| 539 | render_load_png(m_vector_bitmap, file, NULL, "vector.png"); |
| 540 | if (m_vector_bitmap.valid()) |
| 454 | 541 | { |
| 455 | | d3d->vector_bitmap.fill(MAKE_ARGB(0xff,0xff,0xff,0xff)); |
| 456 | | render_load_png(d3d->vector_bitmap, file, NULL, "vector.png", true); |
| 542 | m_vector_bitmap.fill(MAKE_ARGB(0xff,0xff,0xff,0xff)); |
| 543 | render_load_png(m_vector_bitmap, file, NULL, "vector.png", true); |
| 457 | 544 | } |
| 458 | 545 | |
| 459 | | d3d->default_bitmap.allocate(8, 8); |
| 460 | | d3d->default_bitmap.fill(MAKE_ARGB(0xff,0xff,0xff,0xff)); |
| 546 | m_default_bitmap.allocate(8, 8); |
| 547 | m_default_bitmap.fill(MAKE_ARGB(0xff,0xff,0xff,0xff)); |
| 461 | 548 | |
| 462 | | // configure the adapter for the mode we want |
| 463 | | if (config_adapter_mode(window)) |
| 464 | | goto error; |
| 549 | if (m_default_bitmap.valid()) |
| 550 | { |
| 551 | render_texinfo texture; |
| 465 | 552 | |
| 466 | | // create the device immediately for the full screen case (defer for window mode) |
| 467 | | if (window->fullscreen && device_create(window)) |
| 468 | | goto error; |
| 553 | // fake in the basic data so it looks like it came from render.c |
| 554 | texture.base = m_default_bitmap.raw_pixptr(0); |
| 555 | texture.rowpixels = m_default_bitmap.rowpixels(); |
| 556 | texture.width = m_default_bitmap.width(); |
| 557 | texture.height = m_default_bitmap.height(); |
| 558 | texture.palette = NULL; |
| 559 | texture.seqid = 0; |
| 469 | 560 | |
| 470 | | return 0; |
| 561 | // now create it |
| 562 | m_default_texture = global_alloc(texture_info(this, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32))); |
| 563 | } |
| 471 | 564 | |
| 472 | | error: |
| 473 | | drawd3d_window_destroy(window); |
| 474 | | mame_printf_error("Unable to initialize Direct3D.\n"); |
| 475 | | return 1; |
| 476 | | } |
| 565 | // experimental: if we have a vector bitmap, create a texture for it |
| 566 | if (m_vector_bitmap.valid()) |
| 567 | { |
| 568 | render_texinfo texture; |
| 477 | 569 | |
| 570 | // fake in the basic data so it looks like it came from render.c |
| 571 | texture.base = &m_vector_bitmap.pix32(0); |
| 572 | texture.rowpixels = m_vector_bitmap.rowpixels(); |
| 573 | texture.width = m_vector_bitmap.width(); |
| 574 | texture.height = m_vector_bitmap.height(); |
| 575 | texture.palette = NULL; |
| 576 | texture.seqid = 0; |
| 478 | 577 | |
| 578 | // now create it |
| 579 | m_vector_texture = global_alloc(texture_info(this, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32))); |
| 580 | } |
| 581 | } |
| 479 | 582 | |
| 480 | | static void drawd3d_window_toggle_fsfx(win_window_info *window) |
| 583 | void texture_manager::delete_resources() |
| 481 | 584 | { |
| 482 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 585 | global_free(m_default_texture); |
| 586 | m_default_texture = NULL; |
| 483 | 587 | |
| 484 | | d3d->restarting = true; |
| 588 | // free all textures |
| 589 | while (m_texlist != NULL) |
| 590 | { |
| 591 | texture_info *tex = m_texlist; |
| 592 | m_texlist = tex->get_next(); |
| 593 | global_free(tex); |
| 594 | } |
| 485 | 595 | } |
| 486 | 596 | |
| 487 | | static void drawd3d_window_record(win_window_info *window) |
| 597 | UINT32 texture_manager::texture_compute_hash(const render_texinfo *texture, UINT32 flags) |
| 488 | 598 | { |
| 489 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 490 | | |
| 491 | | d3d->hlsl->window_record(); |
| 599 | return (FPTR)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)); |
| 492 | 600 | } |
| 493 | 601 | |
| 494 | | static void drawd3d_window_save(win_window_info *window) |
| 602 | texture_info *texture_manager::find_texinfo(const render_texinfo *texinfo, UINT32 flags) |
| 495 | 603 | { |
| 496 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 604 | UINT32 hash = texture_compute_hash(texinfo, flags); |
| 605 | texture_info *texture; |
| 497 | 606 | |
| 498 | | d3d->hlsl->window_save(); |
| 499 | | } |
| 607 | // find a match |
| 608 | for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next()) |
| 609 | { |
| 610 | UINT32 test_screen = (UINT32)texture->get_texinfo().osddata >> 1; |
| 611 | UINT32 test_page = (UINT32)texture->get_texinfo().osddata & 1; |
| 612 | UINT32 prim_screen = (UINT32)texinfo->osddata >> 1; |
| 613 | UINT32 prim_page = (UINT32)texinfo->osddata & 1; |
| 614 | if (test_screen != prim_screen || test_page != prim_page) |
| 615 | { |
| 616 | continue; |
| 617 | } |
| 500 | 618 | |
| 619 | if (texture->get_hash() == hash && |
| 620 | texture->get_texinfo().base == texinfo->base && |
| 621 | texture->get_texinfo().width == texinfo->width && |
| 622 | texture->get_texinfo().height == texinfo->height && |
| 623 | ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0) |
| 624 | { |
| 625 | // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache |
| 626 | if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0) |
| 627 | { |
| 628 | if (m_renderer->get_shaders()->find_render_target(texture) != NULL) |
| 629 | { |
| 630 | return texture; |
| 631 | } |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | return texture; |
| 636 | } |
| 637 | } |
| 638 | } |
| 501 | 639 | |
| 640 | // Nothing found |
| 641 | /*int checkidx = 0; |
| 642 | for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next()) |
| 643 | { |
| 644 | printf("Checking texture index %d\n", checkidx); |
| 645 | UINT32 test_screen = (UINT32)texture->get_texinfo().osddata >> 1; |
| 646 | UINT32 test_page = (UINT32)texture->get_texinfo().osddata & 1; |
| 647 | UINT32 prim_screen = (UINT32)texinfo->osddata >> 1; |
| 648 | UINT32 prim_page = (UINT32)texinfo->osddata & 1; |
| 649 | if (test_screen != prim_screen || test_page != prim_page) |
| 650 | { |
| 651 | printf("No screen/page match: %d vs. %d, %d vs. %d\n", test_screen, prim_screen, test_page, prim_page); |
| 652 | continue; |
| 653 | } |
| 502 | 654 | |
| 503 | | //============================================================ |
| 504 | | // drawd3d_window_destroy |
| 505 | | //============================================================ |
| 655 | if (texture->get_hash() == hash && |
| 656 | texture->get_texinfo().base == texinfo->base && |
| 657 | texture->get_texinfo().width == texinfo->width && |
| 658 | texture->get_texinfo().height == texinfo->height && |
| 659 | ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0) |
| 660 | { |
| 661 | // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache |
| 662 | if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0) |
| 663 | { |
| 664 | if (m_renderer->get_shaders()->find_render_target(texture) != NULL) |
| 665 | { |
| 666 | return texture; |
| 667 | } |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | return texture; |
| 672 | } |
| 673 | } |
| 506 | 674 | |
| 507 | | static void drawd3d_window_destroy(win_window_info *window) |
| 508 | | { |
| 509 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 675 | if (texture->get_hash() != hash) |
| 676 | { |
| 677 | printf("No hash match: %d vs. %d\n", texture->get_hash(), hash); |
| 678 | } |
| 679 | if (texture->get_texinfo().base != texinfo->base) |
| 680 | { |
| 681 | printf("No base match\n"); |
| 682 | } |
| 683 | if (texture->get_texinfo().width != texinfo->width) |
| 684 | { |
| 685 | printf("No width match: %d vs. %d\n", texture->get_texinfo().width, texinfo->width); |
| 686 | } |
| 687 | if (texture->get_texinfo().height != texinfo->height) |
| 688 | { |
| 689 | printf("No height match: %d vs. %d\n", texture->get_texinfo().height, texinfo->height); |
| 690 | } |
| 691 | if (((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) != 0) |
| 692 | { |
| 693 | printf("No flag match: %08x & %08x = %08x\n", texture->get_flags(), flags, ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK))); |
| 694 | } |
| 695 | printf("\n"); |
| 696 | checkidx++; |
| 697 | } |
| 510 | 698 | |
| 511 | | // skip if nothing |
| 512 | | if (d3d == NULL) |
| 513 | | return; |
| 699 | printf("\n\n\n\n");*/ |
| 514 | 700 | |
| 515 | | if (d3d->hlsl->recording()) |
| 516 | | d3d->hlsl->window_record(); |
| 701 | // Nothing found, check if we need to unregister something with HLSL |
| 702 | if (m_renderer->get_shaders()->enabled()) |
| 703 | { |
| 704 | if (texinfo->width == 0 || texinfo->height == 0) |
| 705 | { |
| 706 | return NULL; |
| 707 | } |
| 517 | 708 | |
| 518 | | // delete the device |
| 519 | | device_delete(d3d); |
| 709 | UINT32 prim_screen = texinfo->osddata >> 1; |
| 710 | UINT32 prim_page = texinfo->osddata & 1; |
| 520 | 711 | |
| 521 | | // free the memory in the window |
| 522 | | global_free(d3d); |
| 523 | | window->drawdata = NULL; |
| 524 | | } |
| 712 | for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next()) |
| 713 | { |
| 714 | UINT32 test_screen = texture->get_texinfo().osddata >> 1; |
| 715 | UINT32 test_page = texture->get_texinfo().osddata & 1; |
| 716 | if (test_screen != prim_screen || test_page != prim_page) |
| 717 | { |
| 718 | continue; |
| 719 | } |
| 525 | 720 | |
| 721 | // Clear out our old texture reference |
| 722 | if (texture->get_hash() == hash && |
| 723 | texture->get_texinfo().base == texinfo->base && |
| 724 | ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0 && |
| 725 | (texture->get_texinfo().width != texinfo->width || |
| 726 | texture->get_texinfo().height != texinfo->height)) |
| 727 | { |
| 728 | m_renderer->get_shaders()->remove_render_target(texture); |
| 729 | } |
| 730 | } |
| 731 | } |
| 526 | 732 | |
| 733 | return NULL; |
| 734 | } |
| 527 | 735 | |
| 528 | | //============================================================ |
| 529 | | // drawd3d_window_get_primitives |
| 530 | | //============================================================ |
| 736 | renderer::renderer(win_window_info *window) |
| 737 | { |
| 738 | m_device = NULL; |
| 739 | m_restarting = false; |
| 740 | m_window = window; |
| 741 | m_shaders = NULL; |
| 742 | m_numverts = 0; |
| 743 | m_numpolys = 0; |
| 744 | } |
| 531 | 745 | |
| 532 | | static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window) |
| 746 | int renderer::initialize() |
| 533 | 747 | { |
| 534 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 535 | | RECT client; |
| 748 | // configure the adapter for the mode we want |
| 749 | if (config_adapter_mode()) |
| 750 | return false; |
| 536 | 751 | |
| 537 | | GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen); |
| 538 | | if (rect_width(&client) > 0 && rect_height(&client) > 0) |
| 539 | | { |
| 540 | | window->target->set_bounds(rect_width(&client), rect_height(&client), winvideo_monitor_get_aspect(window->monitor)); |
| 541 | | window->target->set_max_update_rate((d3d->refresh == 0) ? d3d->origmode.RefreshRate : d3d->refresh); |
| 542 | | } |
| 543 | | return &window->target->get_primitives(); |
| 544 | | } |
| 752 | // create the device immediately for the full screen case (defer for window mode) |
| 753 | if (m_window->fullscreen && device_create()) |
| 754 | return false; |
| 545 | 755 | |
| 756 | m_texture_manager = global_alloc(texture_manager(this)); |
| 546 | 757 | |
| 758 | return true; |
| 759 | } |
| 547 | 760 | |
| 548 | | //============================================================ |
| 549 | | // drawd3d_window_draw |
| 550 | | //============================================================ |
| 551 | | |
| 552 | | static int drawd3d_window_draw(win_window_info *window, HDC dc, int update) |
| 761 | int renderer::pre_window_draw_check() |
| 553 | 762 | { |
| 554 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 555 | | render_primitive *prim; |
| 556 | | HRESULT result; |
| 557 | | |
| 558 | 763 | // if we're in the middle of resizing, leave things alone |
| 559 | | if (window->resize_state == RESIZE_STATE_RESIZING) |
| 764 | if (m_window->resize_state == RESIZE_STATE_RESIZING) |
| 560 | 765 | return 0; |
| 561 | 766 | |
| 562 | 767 | // if we're restarting the renderer, leave things alone |
| 563 | | if (d3d->restarting) |
| 768 | if (m_restarting) |
| 564 | 769 | { |
| 565 | | d3d->hlsl->toggle(); |
| 770 | m_shaders->toggle(); |
| 566 | 771 | |
| 567 | 772 | // free all existing resources and re-create |
| 568 | | device_delete_resources(d3d); |
| 569 | | device_create_resources(d3d); |
| 773 | device_delete_resources(); |
| 774 | device_create_resources(); |
| 570 | 775 | |
| 571 | | d3d->restarting = false; |
| 776 | m_restarting = false; |
| 572 | 777 | } |
| 573 | 778 | |
| 574 | | // if we haven't been created, just punt |
| 575 | | if (d3d == NULL) |
| 576 | | return 1; |
| 577 | | |
| 578 | 779 | // if we have a device, check the cooperative level |
| 579 | | if (d3d->device != NULL) |
| 780 | if (m_device != NULL) |
| 580 | 781 | { |
| 581 | | int error = device_test_cooperative(d3d); |
| 582 | | if (error) |
| 782 | if (device_test_cooperative()) |
| 583 | 783 | return 1; |
| 584 | 784 | } |
| 585 | 785 | |
| 586 | 786 | // in window mode, we need to track the window size |
| 587 | | if (!window->fullscreen || d3d->device == NULL) |
| 787 | if (!m_window->fullscreen || m_device == NULL) |
| 588 | 788 | { |
| 589 | 789 | // if the size changes, skip this update since the render target will be out of date |
| 590 | | if (update_window_size(window)) |
| 790 | if (update_window_size()) |
| 591 | 791 | return 0; |
| 592 | 792 | |
| 593 | 793 | // if we have no device, after updating the size, return an error so GDI can try |
| 594 | | if (d3d->device == NULL) |
| 794 | if (m_device == NULL) |
| 595 | 795 | return 1; |
| 596 | 796 | } |
| 597 | 797 | |
| 598 | | mtlog_add("drawd3d_window_draw: begin"); |
| 599 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 600 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 798 | return -1; |
| 799 | } |
| 601 | 800 | |
| 602 | | d3d->hlsl->begin_frame(); |
| 603 | | |
| 604 | | // first update any textures |
| 605 | | window->primlist->acquire_lock(); |
| 606 | | for (prim = window->primlist->first(); prim != NULL; prim = prim->next()) |
| 801 | void texture_manager::update_textures() |
| 802 | { |
| 803 | for (render_primitive *prim = m_renderer->get_window()->primlist->first(); prim != NULL; prim = prim->next()) |
| 607 | 804 | { |
| 608 | 805 | if (prim->texture.base != NULL) |
| 609 | 806 | { |
| 610 | | texture_update(d3d, prim); |
| 807 | texture_info *texture = find_texinfo(&prim->texture, prim->flags); |
| 808 | if (texture == NULL) |
| 809 | { |
| 810 | // if there isn't one, create a new texture |
| 811 | global_alloc(texture_info(this, &prim->texture, prim->flags)); |
| 812 | } |
| 813 | else |
| 814 | { |
| 815 | // if there is one, but with a different seqid, copy the data |
| 816 | if (texture->get_texinfo().seqid != prim->texture.seqid) |
| 817 | { |
| 818 | texture->set_data(&prim->texture, prim->flags); |
| 819 | texture->get_texinfo().seqid = prim->texture.seqid; |
| 820 | } |
| 821 | } |
| 611 | 822 | } |
| 612 | | else if(d3d->hlsl->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags)) |
| 823 | else if(m_renderer->get_shaders()->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags)) |
| 613 | 824 | { |
| 614 | | if (!d3d->hlsl->get_vector_target()) |
| 825 | if (!m_renderer->get_shaders()->get_vector_target()) |
| 615 | 826 | { |
| 616 | | d3d->hlsl->create_vector_target(prim); |
| 827 | m_renderer->get_shaders()->create_vector_target(prim); |
| 617 | 828 | } |
| 618 | 829 | } |
| 619 | 830 | } |
| 831 | } |
| 620 | 832 | |
| 833 | void renderer::begin_frame() |
| 834 | { |
| 835 | HRESULT result = (*d3dintf->device.clear)(m_device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 836 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 837 | |
| 838 | m_shaders->begin_frame(); |
| 839 | |
| 840 | m_window->primlist->acquire_lock(); |
| 841 | |
| 842 | // first update any textures |
| 843 | m_texture_manager->update_textures(); |
| 844 | |
| 621 | 845 | // begin the scene |
| 622 | 846 | mtlog_add("drawd3d_window_draw: begin_scene"); |
| 623 | | result = (*d3dintf->device.begin_scene)(d3d->device); |
| 847 | result = (*d3dintf->device.begin_scene)(m_device); |
| 624 | 848 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device begin_scene call\n", (int)result); |
| 625 | 849 | |
| 626 | | d3d->lockedbuf = NULL; |
| 850 | m_lockedbuf = NULL; |
| 627 | 851 | |
| 628 | | // loop over primitives |
| 629 | | if(d3d->hlsl->enabled()) |
| 852 | if(m_shaders->enabled()) |
| 630 | 853 | { |
| 631 | | d3d->hlsl_buf = (void*)primitive_alloc(d3d, 6); |
| 632 | | d3d->hlsl->init_fsfx_quad(d3d->hlsl_buf); |
| 854 | m_hlsl_buf = (void*)mesh_alloc(6); |
| 855 | m_shaders->init_fsfx_quad(m_hlsl_buf); |
| 633 | 856 | } |
| 634 | 857 | |
| 635 | | mtlog_add("drawd3d_window_draw: count lines"); |
| 636 | | int line_count = 0; |
| 637 | | for (prim = window->primlist->first(); prim != NULL; prim = prim->next()) |
| 858 | m_line_count = 0; |
| 859 | // loop over primitives |
| 860 | for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next()) |
| 638 | 861 | if (prim->type == render_primitive::LINE && PRIMFLAG_GET_VECTOR(prim->flags)) |
| 639 | | line_count++; |
| 862 | m_line_count++; |
| 863 | } |
| 640 | 864 | |
| 641 | | mtlog_add("drawd3d_window_draw: primitive loop begin"); |
| 865 | void renderer::process_primitives() |
| 866 | { |
| 867 | if (m_line_count && m_shaders->enabled() && d3dintf->post_fx_available) |
| 868 | { |
| 869 | batch_vectors(); |
| 870 | } |
| 871 | |
| 642 | 872 | // Rotating index for vector time offsets |
| 643 | | static int start_index = 0; |
| 644 | | int line_index = 0; |
| 645 | | windows_options &options = downcast<windows_options &>(window->machine().options()); |
| 646 | | float period = options.screen_vector_time_period(); |
| 647 | | for (prim = window->primlist->first(); prim != NULL; prim = prim->next()) |
| 873 | for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next()) |
| 648 | 874 | { |
| 649 | 875 | switch (prim->type) |
| 650 | 876 | { |
| 651 | 877 | case render_primitive::LINE: |
| 652 | 878 | if (PRIMFLAG_GET_VECTOR(prim->flags)) |
| 653 | 879 | { |
| 654 | | if (period == 0.0f || line_count == 0) |
| 655 | | { |
| 656 | | draw_line(d3d, prim, 1.0f); |
| 657 | | } |
| 658 | | else |
| 659 | | { |
| 660 | | draw_line(d3d, prim, (float)(start_index + line_index) / ((float)line_count * period)); |
| 661 | | line_index++; |
| 662 | | } |
| 880 | continue; |
| 663 | 881 | } |
| 664 | 882 | else |
| 665 | 883 | { |
| 666 | | draw_line(d3d, prim, 0.0f); |
| 884 | draw_line(prim); |
| 667 | 885 | } |
| 668 | 886 | break; |
| 669 | 887 | |
| 670 | 888 | case render_primitive::QUAD: |
| 671 | | draw_quad(d3d, prim); |
| 889 | draw_quad(prim); |
| 672 | 890 | break; |
| 673 | 891 | |
| 674 | 892 | default: |
| 675 | 893 | throw emu_fatalerror("Unexpected render_primitive type"); |
| 676 | 894 | } |
| 677 | 895 | } |
| 678 | | start_index += (int)((float)line_index * period); |
| 679 | | if (line_count > 0) |
| 896 | |
| 897 | if (m_line_count && !(m_shaders->enabled() && d3dintf->post_fx_available)) |
| 680 | 898 | { |
| 681 | | start_index %= line_count; |
| 899 | batch_vectors(); |
| 682 | 900 | } |
| 683 | | mtlog_add("drawd3d_window_draw: primitive loop end"); |
| 684 | | window->primlist->release_lock(); |
| 901 | } |
| 685 | 902 | |
| 903 | void renderer::end_frame() |
| 904 | { |
| 905 | m_window->primlist->release_lock(); |
| 906 | |
| 686 | 907 | // flush any pending polygons |
| 687 | | mtlog_add("drawd3d_window_draw: flush_pending begin"); |
| 688 | | primitive_flush_pending(d3d); |
| 689 | | mtlog_add("drawd3d_window_draw: flush_pending end"); |
| 908 | primitive_flush_pending(); |
| 690 | 909 | |
| 691 | | d3d->hlsl->end_frame(); |
| 910 | m_shaders->end_frame(); |
| 692 | 911 | |
| 693 | 912 | // finish the scene |
| 694 | | mtlog_add("drawd3d_window_draw: end_scene begin"); |
| 695 | | result = (*d3dintf->device.end_scene)(d3d->device); |
| 696 | | mtlog_add("drawd3d_window_draw: end_scene end"); |
| 913 | HRESULT result = (*d3dintf->device.end_scene)(m_device); |
| 697 | 914 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device end_scene call\n", (int)result); |
| 698 | 915 | |
| 699 | 916 | // present the current buffers |
| 700 | | mtlog_add("drawd3d_window_draw: present begin"); |
| 701 | | result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0); |
| 702 | | mtlog_add("drawd3d_window_draw: present end"); |
| 917 | result = (*d3dintf->device.present)(m_device, NULL, NULL, NULL, NULL, 0); |
| 703 | 918 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device present call\n", (int)result); |
| 704 | | |
| 705 | | return 0; |
| 706 | 919 | } |
| 707 | 920 | |
| 708 | | |
| 709 | | |
| 710 | 921 | //============================================================ |
| 711 | 922 | // device_create |
| 712 | 923 | //============================================================ |
| 713 | 924 | |
| 714 | | static int device_create(win_window_info *window) |
| 925 | int renderer::device_create() |
| 715 | 926 | { |
| 716 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 717 | | HRESULT result; |
| 718 | | int verify; |
| 719 | | |
| 720 | 927 | // if a device exists, free it |
| 721 | | if (d3d->device != NULL) |
| 722 | | device_delete(d3d); |
| 928 | if (m_device != NULL) |
| 929 | device_delete(); |
| 723 | 930 | |
| 724 | 931 | // verify the caps |
| 725 | | verify = device_verify_caps(d3d, window); |
| 932 | int verify = device_verify_caps(); |
| 726 | 933 | if (verify == 2) |
| 727 | 934 | { |
| 728 | 935 | mame_printf_error("Error: Device does not meet minimum requirements for Direct3D rendering\n"); |
| r22936 | r22937 | |
| 732 | 939 | mame_printf_warning("Warning: Device may not perform well for Direct3D rendering\n"); |
| 733 | 940 | |
| 734 | 941 | // verify texture formats |
| 735 | | result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8); |
| 942 | HRESULT result = (*d3dintf->d3d.check_device_format)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8); |
| 736 | 943 | if (result != D3D_OK) |
| 737 | 944 | { |
| 738 | 945 | mame_printf_error("Error: A8R8G8B8 format textures not supported\n"); |
| 739 | 946 | return 1; |
| 740 | 947 | } |
| 741 | 948 | |
| 742 | | // pick a YUV texture format |
| 743 | | d3d->yuv_format = D3DFMT_UYVY; |
| 744 | | result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, 0, D3DRTYPE_TEXTURE, D3DFMT_UYVY); |
| 745 | | if (result != D3D_OK) |
| 746 | | { |
| 747 | | d3d->yuv_format = D3DFMT_YUY2; |
| 748 | | result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, 0, D3DRTYPE_TEXTURE, D3DFMT_YUY2); |
| 749 | | if (result != D3D_OK) |
| 750 | | d3d->yuv_format = D3DFMT_A8R8G8B8; |
| 751 | | } |
| 752 | | mame_printf_verbose("Direct3D: YUV format = %s\n", (d3d->yuv_format == D3DFMT_YUY2) ? "YUY2" : (d3d->yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB"); |
| 753 | | |
| 754 | 949 | try_again: |
| 755 | 950 | // try for XRGB first |
| 756 | | d3d->screen_format = D3DFMT_X8R8G8B8; |
| 757 | | result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, d3d->dynamic_supported ? D3DUSAGE_DYNAMIC : 0, D3DRTYPE_TEXTURE, d3d->screen_format); |
| 951 | m_screen_format = D3DFMT_X8R8G8B8; |
| 952 | result = (*d3dintf->d3d.check_device_format)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_texture_manager->is_dynamic_supported() ? D3DUSAGE_DYNAMIC : 0, D3DRTYPE_TEXTURE, m_screen_format); |
| 758 | 953 | if (result != D3D_OK) |
| 759 | 954 | { |
| 760 | 955 | // if not, try for ARGB |
| 761 | | d3d->screen_format = D3DFMT_A8R8G8B8; |
| 762 | | result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, d3d->dynamic_supported ? D3DUSAGE_DYNAMIC : 0, D3DRTYPE_TEXTURE, d3d->screen_format); |
| 763 | | if (result != D3D_OK && d3d->dynamic_supported) |
| 956 | m_screen_format = D3DFMT_A8R8G8B8; |
| 957 | result = (*d3dintf->d3d.check_device_format)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_texture_manager->is_dynamic_supported() ? D3DUSAGE_DYNAMIC : 0, D3DRTYPE_TEXTURE, m_screen_format); |
| 958 | if (result != D3D_OK && m_texture_manager->is_dynamic_supported()) |
| 764 | 959 | { |
| 765 | | d3d->dynamic_supported = FALSE; |
| 960 | m_texture_manager->set_dynamic_supported(FALSE); |
| 766 | 961 | goto try_again; |
| 767 | 962 | } |
| 768 | 963 | if (result != D3D_OK) |
| r22936 | r22937 | |
| 773 | 968 | } |
| 774 | 969 | |
| 775 | 970 | // initialize the D3D presentation parameters |
| 776 | | memset(&d3d->presentation, 0, sizeof(d3d->presentation)); |
| 777 | | d3d->presentation.BackBufferWidth = d3d->width; |
| 778 | | d3d->presentation.BackBufferHeight = d3d->height; |
| 779 | | d3d->presentation.BackBufferFormat = d3d->pixformat; |
| 780 | | d3d->presentation.BackBufferCount = video_config.triplebuf ? 2 : 1; |
| 781 | | d3d->presentation.MultiSampleType = D3DMULTISAMPLE_NONE; |
| 782 | | d3d->presentation.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| 783 | | d3d->presentation.hDeviceWindow = window->hwnd; |
| 784 | | d3d->presentation.Windowed = !window->fullscreen || win_has_menu(window); |
| 785 | | d3d->presentation.EnableAutoDepthStencil = FALSE; |
| 786 | | d3d->presentation.AutoDepthStencilFormat = D3DFMT_D16; |
| 787 | | d3d->presentation.Flags = 0; |
| 788 | | d3d->presentation.FullScreen_RefreshRateInHz = d3d->refresh; |
| 789 | | d3d->presentation.PresentationInterval = ((video_config.triplebuf && window->fullscreen) || video_config.waitvsync || video_config.syncrefresh) ? |
| 790 | | D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; |
| 971 | memset(&m_presentation, 0, sizeof(m_presentation)); |
| 972 | m_presentation.BackBufferWidth = m_width; |
| 973 | m_presentation.BackBufferHeight = m_height; |
| 974 | m_presentation.BackBufferFormat = m_pixformat; |
| 975 | m_presentation.BackBufferCount = video_config.triplebuf ? 2 : 1; |
| 976 | m_presentation.MultiSampleType = D3DMULTISAMPLE_NONE; |
| 977 | m_presentation.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| 978 | m_presentation.hDeviceWindow = m_window->hwnd; |
| 979 | m_presentation.Windowed = !m_window->fullscreen || win_has_menu(m_window); |
| 980 | m_presentation.EnableAutoDepthStencil = FALSE; |
| 981 | m_presentation.AutoDepthStencilFormat = D3DFMT_D16; |
| 982 | m_presentation.Flags = 0; |
| 983 | m_presentation.FullScreen_RefreshRateInHz = m_refresh; |
| 984 | m_presentation.PresentationInterval = ((video_config.triplebuf && m_window->fullscreen) || |
| 985 | video_config.waitvsync || video_config.syncrefresh) ? |
| 986 | D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; |
| 791 | 987 | |
| 792 | 988 | // create the D3D device |
| 793 | | result = (*d3dintf->d3d.create_device)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, win_window_list->hwnd, |
| 794 | | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device); |
| 989 | result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, win_window_list->hwnd, |
| 990 | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &m_presentation, &m_device); |
| 795 | 991 | if (result != D3D_OK) |
| 796 | 992 | { |
| 797 | 993 | // if we got a "DEVICELOST" error, it may be transitory; count it and only fail if |
| 798 | 994 | // we exceed a threshold |
| 799 | 995 | if (result == D3DERR_DEVICELOST) |
| 800 | 996 | { |
| 801 | | d3d->create_error_count++; |
| 802 | | if (d3d->create_error_count < 10) |
| 997 | m_create_error_count++; |
| 998 | if (m_create_error_count < 10) |
| 803 | 999 | return 0; |
| 804 | 1000 | } |
| 805 | 1001 | |
| r22936 | r22937 | |
| 807 | 1003 | mame_printf_error("Unable to create the Direct3D device (%08X)\n", (UINT32)result); |
| 808 | 1004 | return 1; |
| 809 | 1005 | } |
| 810 | | d3d->create_error_count = 0; |
| 811 | | mame_printf_verbose("Direct3D: Device created at %dx%d\n", d3d->width, d3d->height); |
| 1006 | m_create_error_count = 0; |
| 1007 | mame_printf_verbose("Direct3D: Device created at %dx%d\n", m_width, m_height); |
| 812 | 1008 | |
| 813 | | // set the max texture size |
| 814 | | window->target->set_max_texture_size(d3d->texture_max_width, d3d->texture_max_height); |
| 815 | | mame_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)d3d->texture_max_width, (int)d3d->texture_max_height); |
| 816 | | |
| 817 | 1009 | // set the gamma if we need to |
| 818 | | if (window->fullscreen) |
| 1010 | if (m_window->fullscreen) |
| 819 | 1011 | { |
| 820 | 1012 | // only set the gamma if it's not 1.0f |
| 821 | | windows_options &options = downcast<windows_options &>(window->machine().options()); |
| 1013 | windows_options &options = downcast<windows_options &>(m_window->machine().options()); |
| 822 | 1014 | float brightness = options.full_screen_brightness(); |
| 823 | 1015 | float contrast = options.full_screen_contrast(); |
| 824 | 1016 | float gamma = options.full_screen_gamma(); |
| 825 | 1017 | if (brightness != 1.0f || contrast != 1.0f || gamma != 1.0f) |
| 826 | 1018 | { |
| 827 | 1019 | // warn if we can't do it |
| 828 | | if (!d3d->gamma_supported) |
| 1020 | if (!m_gamma_supported) |
| 1021 | { |
| 829 | 1022 | mame_printf_warning("Direct3D: Warning - device does not support full screen gamma correction.\n"); |
| 1023 | } |
| 830 | 1024 | else |
| 831 | 1025 | { |
| 1026 | // create a standard ramp and set it |
| 832 | 1027 | D3DGAMMARAMP ramp; |
| 833 | | int i; |
| 834 | | |
| 835 | | // create a standard ramp and set it |
| 836 | | for (i = 0; i < 256; i++) |
| 1028 | for (int i = 0; i < 256; i++) |
| 1029 | { |
| 837 | 1030 | ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, gamma) << 8; |
| 838 | | (*d3dintf->device.set_gamma_ramp)(d3d->device, 0, &ramp); |
| 1031 | } |
| 1032 | (*d3dintf->device.set_gamma_ramp)(m_device, 0, &ramp); |
| 839 | 1033 | } |
| 840 | 1034 | } |
| 841 | 1035 | } |
| 842 | 1036 | |
| 843 | | int ret = d3d->hlsl->create_resources(false); |
| 1037 | int ret = m_shaders->create_resources(false); |
| 844 | 1038 | if (ret != 0) |
| 845 | 1039 | return ret; |
| 846 | 1040 | |
| 847 | | return device_create_resources(d3d); |
| 1041 | return device_create_resources(); |
| 848 | 1042 | } |
| 849 | 1043 | |
| 850 | 1044 | |
| r22936 | r22937 | |
| 853 | 1047 | // device_create_resources |
| 854 | 1048 | //============================================================ |
| 855 | 1049 | |
| 856 | | static int device_create_resources(d3d_info *d3d) |
| 1050 | int renderer::device_create_resources() |
| 857 | 1051 | { |
| 858 | | HRESULT result; |
| 859 | | |
| 860 | 1052 | // allocate a vertex buffer to use |
| 861 | | result = (*d3dintf->device.create_vertex_buffer)(d3d->device, |
| 862 | | sizeof(d3d_vertex) * VERTEX_BUFFER_SIZE, |
| 1053 | HRESULT result = (*d3dintf->device.create_vertex_buffer)(m_device, |
| 1054 | sizeof(vertex) * VERTEX_BUFFER_SIZE, |
| 863 | 1055 | D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY, |
| 864 | | VERTEX_BASE_FORMAT | ((d3d->hlsl->enabled() && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW), D3DPOOL_DEFAULT, &d3d->vertexbuf); |
| 1056 | VERTEX_BASE_FORMAT | ((m_shaders->enabled() && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW), |
| 1057 | D3DPOOL_DEFAULT, &m_vertexbuf); |
| 865 | 1058 | if (result != D3D_OK) |
| 866 | 1059 | { |
| 867 | 1060 | printf("Error creating vertex buffer (%08X)", (UINT32)result); |
| r22936 | r22937 | |
| 869 | 1062 | } |
| 870 | 1063 | |
| 871 | 1064 | // set the vertex format |
| 872 | | result = (*d3dintf->device.set_vertex_format)(d3d->device, (D3DFORMAT)(VERTEX_BASE_FORMAT | ((d3d->hlsl->enabled() && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW))); |
| 1065 | result = (*d3dintf->device.set_vertex_format)(m_device, (D3DFORMAT)(VERTEX_BASE_FORMAT | ((m_shaders->enabled() && |
| 1066 | d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW))); |
| 873 | 1067 | if (result != D3D_OK) |
| 874 | 1068 | { |
| 875 | 1069 | mame_printf_error("Error setting vertex format (%08X)", (UINT32)result); |
| r22936 | r22937 | |
| 877 | 1071 | } |
| 878 | 1072 | |
| 879 | 1073 | // set the fixed render state |
| 880 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ZENABLE, D3DZB_FALSE); |
| 881 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_FILLMODE, D3DFILL_SOLID); |
| 882 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_SHADEMODE, D3DSHADE_FLAT); |
| 883 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ZWRITEENABLE, FALSE); |
| 884 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ALPHATESTENABLE, TRUE); |
| 885 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_LASTPIXEL, TRUE); |
| 886 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_CULLMODE, D3DCULL_NONE); |
| 887 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ZFUNC, D3DCMP_LESS); |
| 888 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ALPHAREF, 0); |
| 889 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ALPHAFUNC, D3DCMP_GREATER); |
| 890 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_DITHERENABLE, FALSE); |
| 891 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_FOGENABLE, FALSE); |
| 892 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_SPECULARENABLE, FALSE); |
| 893 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_STENCILENABLE, FALSE); |
| 894 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_WRAP0, FALSE); |
| 895 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_CLIPPING, TRUE); |
| 896 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_LIGHTING, FALSE); |
| 897 | | result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_COLORVERTEX, TRUE); |
| 1074 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ZENABLE, D3DZB_FALSE); |
| 1075 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_FILLMODE, D3DFILL_SOLID); |
| 1076 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_SHADEMODE, D3DSHADE_FLAT); |
| 1077 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ZWRITEENABLE, FALSE); |
| 1078 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ALPHATESTENABLE, TRUE); |
| 1079 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_LASTPIXEL, TRUE); |
| 1080 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_CULLMODE, D3DCULL_NONE); |
| 1081 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ZFUNC, D3DCMP_LESS); |
| 1082 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ALPHAREF, 0); |
| 1083 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ALPHAFUNC, D3DCMP_GREATER); |
| 1084 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_DITHERENABLE, FALSE); |
| 1085 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_FOGENABLE, FALSE); |
| 1086 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_SPECULARENABLE, FALSE); |
| 1087 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_STENCILENABLE, FALSE); |
| 1088 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_WRAP0, FALSE); |
| 1089 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_CLIPPING, TRUE); |
| 1090 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_LIGHTING, FALSE); |
| 1091 | result = (*d3dintf->device.set_render_state)(m_device, D3DRS_COLORVERTEX, TRUE); |
| 898 | 1092 | |
| 899 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); |
| 900 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); |
| 901 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE); |
| 902 | | result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE); |
| 1093 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE); |
| 1094 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); |
| 1095 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE); |
| 1096 | result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE); |
| 903 | 1097 | |
| 904 | 1098 | // reset the local states to force updates |
| 905 | | reset_render_states(d3d); |
| 1099 | reset_render_states(); |
| 906 | 1100 | |
| 907 | 1101 | // clear the buffer |
| 908 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 909 | | result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0); |
| 1102 | result = (*d3dintf->device.clear)(m_device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1103 | result = (*d3dintf->device.present)(m_device, NULL, NULL, NULL, NULL, 0); |
| 910 | 1104 | |
| 911 | | if (d3d->default_bitmap.valid()) |
| 912 | | { |
| 913 | | render_texinfo texture; |
| 1105 | m_texture_manager->create_resources(); |
| 914 | 1106 | |
| 915 | | // fake in the basic data so it looks like it came from render.c |
| 916 | | texture.base = d3d->default_bitmap.raw_pixptr(0); |
| 917 | | texture.rowpixels = d3d->default_bitmap.rowpixels(); |
| 918 | | texture.width = d3d->default_bitmap.width(); |
| 919 | | texture.height = d3d->default_bitmap.height(); |
| 920 | | texture.palette = NULL; |
| 921 | | texture.seqid = 0; |
| 922 | | |
| 923 | | // now create it |
| 924 | | d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 925 | | } |
| 926 | | |
| 927 | | // experimental: if we have a vector bitmap, create a texture for it |
| 928 | | if (d3d->vector_bitmap.valid()) |
| 929 | | { |
| 930 | | render_texinfo texture; |
| 931 | | |
| 932 | | // fake in the basic data so it looks like it came from render.c |
| 933 | | texture.base = &d3d->vector_bitmap.pix32(0); |
| 934 | | texture.rowpixels = d3d->vector_bitmap.rowpixels(); |
| 935 | | texture.width = d3d->vector_bitmap.width(); |
| 936 | | texture.height = d3d->vector_bitmap.height(); |
| 937 | | texture.palette = NULL; |
| 938 | | texture.seqid = 0; |
| 939 | | |
| 940 | | // now create it |
| 941 | | d3d->vector_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 942 | | } |
| 943 | | |
| 944 | 1107 | return 0; |
| 945 | 1108 | } |
| 946 | 1109 | |
| r22936 | r22937 | |
| 950 | 1113 | // device_delete |
| 951 | 1114 | //============================================================ |
| 952 | 1115 | |
| 953 | | static void device_delete(d3d_info *d3d) |
| 1116 | renderer::~renderer() |
| 954 | 1117 | { |
| 1118 | device_delete(); |
| 1119 | } |
| 1120 | |
| 1121 | void renderer::device_delete() |
| 1122 | { |
| 955 | 1123 | // free our effects |
| 956 | | d3d->hlsl->delete_resources(false); |
| 1124 | m_shaders->delete_resources(false); |
| 957 | 1125 | |
| 958 | 1126 | // delete the HLSL interface |
| 959 | | global_free(d3d->hlsl); |
| 1127 | global_free(m_shaders); |
| 960 | 1128 | |
| 961 | 1129 | // free our base resources |
| 962 | | device_delete_resources(d3d); |
| 1130 | device_delete_resources(); |
| 963 | 1131 | |
| 1132 | if (m_texture_manager != NULL) |
| 1133 | { |
| 1134 | global_free(m_texture_manager); |
| 1135 | } |
| 1136 | m_texture_manager = NULL; |
| 1137 | |
| 964 | 1138 | // free the device itself |
| 965 | | if (d3d->device != NULL) |
| 966 | | (*d3dintf->device.release)(d3d->device); |
| 967 | | d3d->device = NULL; |
| 1139 | if (m_device != NULL) |
| 1140 | (*d3dintf->device.release)(m_device); |
| 1141 | m_device = NULL; |
| 968 | 1142 | } |
| 969 | 1143 | |
| 970 | | |
| 971 | | |
| 972 | 1144 | //============================================================ |
| 973 | 1145 | // device_delete_resources |
| 974 | 1146 | //============================================================ |
| 975 | 1147 | |
| 976 | | static void device_delete_resources(d3d_info *d3d) |
| 1148 | void renderer::device_delete_resources() |
| 977 | 1149 | { |
| 978 | | // free all textures |
| 979 | | while (d3d->texlist != NULL) |
| 980 | | { |
| 981 | | d3d_texture_info *tex = d3d->texlist; |
| 982 | | d3d->texlist = tex->next; |
| 983 | | if (tex->d3dfinaltex != NULL) |
| 984 | | { |
| 985 | | if (tex->d3dtex == tex->d3dfinaltex) tex->d3dtex = NULL; |
| 986 | | (*d3dintf->texture.release)(tex->d3dfinaltex); |
| 987 | | tex->d3dfinaltex = NULL; |
| 988 | | } |
| 989 | | if (tex->d3dtex != NULL) |
| 990 | | { |
| 991 | | (*d3dintf->texture.release)(tex->d3dtex); |
| 992 | | tex->d3dtex = NULL; |
| 993 | | } |
| 994 | | if (tex->d3dsurface != NULL) |
| 995 | | { |
| 996 | | (*d3dintf->surface.release)(tex->d3dsurface); |
| 997 | | tex->d3dsurface = NULL; |
| 998 | | } |
| 999 | | global_free(tex); |
| 1000 | | } |
| 1001 | | |
| 1150 | m_texture_manager->delete_resources(); |
| 1002 | 1151 | // free the vertex buffer |
| 1003 | | if (d3d->vertexbuf != NULL) |
| 1004 | | (*d3dintf->vertexbuf.release)(d3d->vertexbuf); |
| 1005 | | d3d->vertexbuf = NULL; |
| 1006 | | |
| 1007 | | global_free(d3d->default_texture); |
| 1008 | | d3d->default_texture = NULL; |
| 1152 | if (m_vertexbuf != NULL) |
| 1153 | (*d3dintf->vertexbuf.release)(m_vertexbuf); |
| 1154 | m_vertexbuf = NULL; |
| 1009 | 1155 | } |
| 1010 | 1156 | |
| 1011 | 1157 | |
| r22936 | r22937 | |
| 1014 | 1160 | // device_verify_caps |
| 1015 | 1161 | //============================================================ |
| 1016 | 1162 | |
| 1017 | | static int device_verify_caps(d3d_info *d3d, win_window_info *window) |
| 1163 | int renderer::device_verify_caps() |
| 1018 | 1164 | { |
| 1019 | 1165 | int retval = 0; |
| 1020 | | HRESULT result; |
| 1021 | | DWORD tempcaps; |
| 1022 | 1166 | |
| 1023 | | // fetch a few core caps |
| 1024 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_CAPS, &d3d->texture_caps); |
| 1025 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1026 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_ASPECT, &d3d->texture_max_aspect); |
| 1027 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1028 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_WIDTH, &d3d->texture_max_width); |
| 1029 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1030 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_HEIGHT, &d3d->texture_max_height); |
| 1031 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1167 | m_shaders = global_alloc_clear(shaders); |
| 1168 | m_shaders->init(d3dintf, m_window); |
| 1032 | 1169 | |
| 1033 | | d3d->hlsl = global_alloc_clear(hlsl_info); |
| 1034 | | d3d->hlsl->init(d3dintf, window); |
| 1035 | | |
| 1036 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps); |
| 1170 | DWORD tempcaps; |
| 1171 | HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps); |
| 1037 | 1172 | if (result != D3D_OK) mame_printf_verbose("Direct3D Error %08X during get_caps_dword call\n", (int)result); |
| 1038 | 1173 | if(tempcaps < 512) |
| 1039 | 1174 | { |
| r22936 | r22937 | |
| 1042 | 1177 | } |
| 1043 | 1178 | |
| 1044 | 1179 | // verify presentation capabilities |
| 1045 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_PRESENTATION_INTERVALS, &tempcaps); |
| 1180 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_PRESENTATION_INTERVALS, &tempcaps); |
| 1046 | 1181 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1047 | 1182 | if (!(tempcaps & D3DPRESENT_INTERVAL_IMMEDIATE)) |
| 1048 | 1183 | { |
| r22936 | r22937 | |
| 1056 | 1191 | } |
| 1057 | 1192 | |
| 1058 | 1193 | // verify device capabilities |
| 1059 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_DEV_CAPS, &tempcaps); |
| 1194 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_DEV_CAPS, &tempcaps); |
| 1060 | 1195 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1061 | 1196 | if (!(tempcaps & D3DDEVCAPS_CANRENDERAFTERFLIP)) |
| 1062 | 1197 | { |
| r22936 | r22937 | |
| 1069 | 1204 | retval = 1; |
| 1070 | 1205 | } |
| 1071 | 1206 | |
| 1072 | | // verify source blend capabilities |
| 1073 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_SRCBLEND_CAPS, &tempcaps); |
| 1074 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1075 | | if (!(tempcaps & D3DPBLENDCAPS_SRCALPHA)) |
| 1076 | | { |
| 1077 | | mame_printf_verbose("Direct3D: Error - Device does not support source alpha blending with source alpha\n"); |
| 1078 | | retval = 2; |
| 1079 | | } |
| 1080 | | if (!(tempcaps & D3DPBLENDCAPS_DESTCOLOR)) |
| 1081 | | { |
| 1082 | | mame_printf_verbose("Direct3D: Error - Device does not support source alpha blending with destination color\n"); |
| 1083 | | retval = 2; |
| 1084 | | } |
| 1085 | | |
| 1086 | | // verify destination blend capabilities |
| 1087 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_DSTBLEND_CAPS, &tempcaps); |
| 1088 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1089 | | if (!(tempcaps & D3DPBLENDCAPS_ZERO)) |
| 1090 | | { |
| 1091 | | mame_printf_verbose("Direct3D: Error - Device does not support dest alpha blending with zero\n"); |
| 1092 | | retval = 2; |
| 1093 | | } |
| 1094 | | if (!(tempcaps & D3DPBLENDCAPS_ONE)) |
| 1095 | | { |
| 1096 | | mame_printf_verbose("Direct3D: Error - Device does not support dest alpha blending with one\n"); |
| 1097 | | retval = 2; |
| 1098 | | } |
| 1099 | | if (!(tempcaps & D3DPBLENDCAPS_INVSRCALPHA)) |
| 1100 | | { |
| 1101 | | mame_printf_verbose("Direct3D: Error - Device does not support dest alpha blending with inverted source alpha\n"); |
| 1102 | | retval = 2; |
| 1103 | | } |
| 1104 | | |
| 1105 | | // verify texture capabilities |
| 1106 | | if (!(d3d->texture_caps & D3DPTEXTURECAPS_ALPHA)) |
| 1107 | | { |
| 1108 | | mame_printf_verbose("Direct3D: Error - Device does not support texture alpha\n"); |
| 1109 | | retval = 2; |
| 1110 | | } |
| 1111 | | |
| 1112 | | // verify texture filter capabilities |
| 1113 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_FILTER_CAPS, &tempcaps); |
| 1114 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1115 | | if (!(tempcaps & D3DPTFILTERCAPS_MAGFPOINT)) |
| 1116 | | { |
| 1117 | | mame_printf_verbose("Direct3D: Warning - Device does not support point-sample texture filtering for magnification\n"); |
| 1118 | | retval = 1; |
| 1119 | | } |
| 1120 | | if (!(tempcaps & D3DPTFILTERCAPS_MAGFLINEAR)) |
| 1121 | | { |
| 1122 | | mame_printf_verbose("Direct3D: Warning - Device does not support bilinear texture filtering for magnification\n"); |
| 1123 | | retval = 1; |
| 1124 | | } |
| 1125 | | if (!(tempcaps & D3DPTFILTERCAPS_MINFPOINT)) |
| 1126 | | { |
| 1127 | | mame_printf_verbose("Direct3D: Warning - Device does not support point-sample texture filtering for minification\n"); |
| 1128 | | retval = 1; |
| 1129 | | } |
| 1130 | | if (!(tempcaps & D3DPTFILTERCAPS_MINFLINEAR)) |
| 1131 | | { |
| 1132 | | mame_printf_verbose("Direct3D: Warning - Device does not support bilinear texture filtering for minification\n"); |
| 1133 | | retval = 1; |
| 1134 | | } |
| 1135 | | |
| 1136 | | // verify texture addressing capabilities |
| 1137 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_ADDRESS_CAPS, &tempcaps); |
| 1138 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1139 | | if (!(tempcaps & D3DPTADDRESSCAPS_CLAMP)) |
| 1140 | | { |
| 1141 | | mame_printf_verbose("Direct3D: Warning - Device does not support texture clamping\n"); |
| 1142 | | retval = 1; |
| 1143 | | } |
| 1144 | | if (!(tempcaps & D3DPTADDRESSCAPS_WRAP)) |
| 1145 | | { |
| 1146 | | mame_printf_verbose("Direct3D: Warning - Device does not support texture wrapping\n"); |
| 1147 | | retval = 1; |
| 1148 | | } |
| 1149 | | |
| 1150 | 1207 | // verify texture operation capabilities |
| 1151 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_OP_CAPS, &tempcaps); |
| 1208 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_OP_CAPS, &tempcaps); |
| 1152 | 1209 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1153 | 1210 | if (!(tempcaps & D3DTEXOPCAPS_MODULATE)) |
| 1154 | 1211 | { |
| r22936 | r22937 | |
| 1157 | 1214 | } |
| 1158 | 1215 | |
| 1159 | 1216 | // set a simpler flag to indicate mod2x and mod4x texture modes |
| 1160 | | d3d->mod2x_supported = ((tempcaps & D3DTEXOPCAPS_MODULATE2X) != 0); |
| 1161 | | d3d->mod4x_supported = ((tempcaps & D3DTEXOPCAPS_MODULATE4X) != 0); |
| 1217 | m_mod2x_supported = ((tempcaps & D3DTEXOPCAPS_MODULATE2X) != 0); |
| 1218 | m_mod4x_supported = ((tempcaps & D3DTEXOPCAPS_MODULATE4X) != 0); |
| 1162 | 1219 | |
| 1163 | | // set a simpler flag to indicate we can use a gamma ramp |
| 1164 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_CAPS2, &tempcaps); |
| 1220 | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_CAPS2, &tempcaps); |
| 1165 | 1221 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1166 | | d3d->dynamic_supported = ((tempcaps & D3DCAPS2_DYNAMICTEXTURES) != 0); |
| 1167 | | d3d->gamma_supported = ((tempcaps & D3DCAPS2_FULLSCREENGAMMA) != 0); |
| 1168 | | if (d3d->dynamic_supported) mame_printf_verbose("Direct3D: Using dynamic textures\n"); |
| 1222 | m_gamma_supported = ((tempcaps & D3DCAPS2_FULLSCREENGAMMA) != 0); |
| 1169 | 1223 | |
| 1170 | | // set a simpler flag to indicate we can use StretchRect |
| 1171 | | result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_STRETCH_RECT_FILTER, &tempcaps); |
| 1172 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); |
| 1173 | | d3d->stretch_supported = ((tempcaps & D3DPTFILTERCAPS_MAGFPOINT) != 0); |
| 1174 | | if (d3d->stretch_supported && video_config.prescale > 1) mame_printf_verbose("Direct3D: Using StretchRect for prescaling\n"); |
| 1175 | | |
| 1176 | 1224 | return retval; |
| 1177 | 1225 | } |
| 1178 | 1226 | |
| r22936 | r22937 | |
| 1182 | 1230 | // device_test_cooperative |
| 1183 | 1231 | //============================================================ |
| 1184 | 1232 | |
| 1185 | | static int device_test_cooperative(d3d_info *d3d) |
| 1233 | int renderer::device_test_cooperative() |
| 1186 | 1234 | { |
| 1187 | | HRESULT result; |
| 1188 | | |
| 1189 | 1235 | // check our current status; if we lost the device, punt to GDI |
| 1190 | | result = (*d3dintf->device.test_cooperative_level)(d3d->device); |
| 1236 | HRESULT result = (*d3dintf->device.test_cooperative_level)(m_device); |
| 1191 | 1237 | if (result == D3DERR_DEVICELOST) |
| 1192 | 1238 | return 1; |
| 1193 | 1239 | |
| r22936 | r22937 | |
| 1197 | 1243 | mame_printf_verbose("Direct3D: resetting device\n"); |
| 1198 | 1244 | |
| 1199 | 1245 | // free all existing resources and call reset on the device |
| 1200 | | device_delete_resources(d3d); |
| 1201 | | d3d->hlsl->delete_resources(true); |
| 1202 | | result = (*d3dintf->device.reset)(d3d->device, &d3d->presentation); |
| 1246 | device_delete_resources(); |
| 1247 | m_shaders->delete_resources(true); |
| 1248 | result = (*d3dintf->device.reset)(m_device, &m_presentation); |
| 1203 | 1249 | |
| 1204 | 1250 | // if it didn't work, punt to GDI |
| 1205 | 1251 | if (result != D3D_OK) |
| r22936 | r22937 | |
| 1209 | 1255 | } |
| 1210 | 1256 | |
| 1211 | 1257 | // try to create the resources again; if that didn't work, delete the whole thing |
| 1212 | | if (device_create_resources(d3d)) |
| 1258 | if (device_create_resources()) |
| 1213 | 1259 | { |
| 1214 | 1260 | mame_printf_verbose("Direct3D: failed to recreate resources for device; failing permanently\n"); |
| 1215 | | device_delete(d3d); |
| 1261 | device_delete(); |
| 1216 | 1262 | return 1; |
| 1217 | 1263 | } |
| 1218 | 1264 | |
| 1219 | | if (d3d->hlsl->create_resources(true)) |
| 1265 | if (m_shaders->create_resources(true)) |
| 1220 | 1266 | { |
| 1221 | 1267 | mame_printf_verbose("Direct3D: failed to recreate HLSL resources for device; failing permanently\n"); |
| 1222 | | device_delete(d3d); |
| 1268 | device_delete(); |
| 1223 | 1269 | return 1; |
| 1224 | 1270 | } |
| 1225 | 1271 | } |
| r22936 | r22937 | |
| 1232 | 1278 | // config_adapter_mode |
| 1233 | 1279 | //============================================================ |
| 1234 | 1280 | |
| 1235 | | static int config_adapter_mode(win_window_info *window) |
| 1281 | int renderer::config_adapter_mode() |
| 1236 | 1282 | { |
| 1237 | | d3d_adapter_identifier identifier; |
| 1238 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1239 | | HRESULT result; |
| 1283 | adapter_identifier identifier; |
| 1240 | 1284 | |
| 1241 | 1285 | // choose the monitor number |
| 1242 | | d3d->adapter = get_adapter_for_monitor(d3d, window->monitor); |
| 1286 | m_adapter = get_adapter_for_monitor(); |
| 1243 | 1287 | |
| 1244 | 1288 | // get the identifier |
| 1245 | | result = (*d3dintf->d3d.get_adapter_identifier)(d3dintf, d3d->adapter, 0, &identifier); |
| 1289 | HRESULT result = (*d3dintf->d3d.get_adapter_identifier)(d3dintf, m_adapter, 0, &identifier); |
| 1246 | 1290 | if (result != D3D_OK) |
| 1247 | 1291 | { |
| 1248 | | mame_printf_error("Error getting identifier for adapter #%d\n", d3d->adapter); |
| 1292 | mame_printf_error("Error getting identifier for adapter #%d\n", m_adapter); |
| 1249 | 1293 | return 1; |
| 1250 | 1294 | } |
| 1251 | | mame_printf_verbose("Direct3D: Configuring adapter #%d = %s\n", d3d->adapter, identifier.Description); |
| 1295 | mame_printf_verbose("Direct3D: Configuring adapter #%d = %s\n", m_adapter, identifier.Description); |
| 1252 | 1296 | |
| 1253 | 1297 | // get the current display mode |
| 1254 | | result = (*d3dintf->d3d.get_adapter_display_mode)(d3dintf, d3d->adapter, &d3d->origmode); |
| 1298 | result = (*d3dintf->d3d.get_adapter_display_mode)(d3dintf, m_adapter, &m_origmode); |
| 1255 | 1299 | if (result != D3D_OK) |
| 1256 | 1300 | { |
| 1257 | | mame_printf_error("Error getting mode for adapter #%d\n", d3d->adapter); |
| 1301 | mame_printf_error("Error getting mode for adapter #%d\n", m_adapter); |
| 1258 | 1302 | return 1; |
| 1259 | 1303 | } |
| 1260 | 1304 | |
| 1261 | 1305 | // choose a resolution: window mode case |
| 1262 | | if (!window->fullscreen || !video_config.switchres || win_has_menu(window)) |
| 1306 | if (!m_window->fullscreen || !video_config.switchres || win_has_menu(m_window)) |
| 1263 | 1307 | { |
| 1264 | 1308 | RECT client; |
| 1265 | 1309 | |
| 1266 | 1310 | // bounds are from the window client rect |
| 1267 | | GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen); |
| 1268 | | d3d->width = client.right - client.left; |
| 1269 | | d3d->height = client.bottom - client.top; |
| 1311 | GetClientRectExceptMenu(m_window->hwnd, &client, m_window->fullscreen); |
| 1312 | m_width = client.right - client.left; |
| 1313 | m_height = client.bottom - client.top; |
| 1270 | 1314 | |
| 1271 | 1315 | // pix format is from the current mode |
| 1272 | | d3d->pixformat = d3d->origmode.Format; |
| 1273 | | d3d->refresh = 0; |
| 1316 | m_pixformat = m_origmode.Format; |
| 1317 | m_refresh = 0; |
| 1274 | 1318 | |
| 1275 | 1319 | // make sure it's a pixel format we can get behind |
| 1276 | | if (d3d->pixformat != D3DFMT_X1R5G5B5 && d3d->pixformat != D3DFMT_R5G6B5 && d3d->pixformat != D3DFMT_X8R8G8B8) |
| 1320 | if (m_pixformat != D3DFMT_X1R5G5B5 && m_pixformat != D3DFMT_R5G6B5 && m_pixformat != D3DFMT_X8R8G8B8) |
| 1277 | 1321 | { |
| 1278 | | char *utf8_device = utf8_from_tstring(window->monitor->info.szDevice); |
| 1322 | char *utf8_device = utf8_from_tstring(m_window->monitor->info.szDevice); |
| 1279 | 1323 | if (utf8_device != NULL) |
| 1280 | 1324 | { |
| 1281 | 1325 | mame_printf_error("Device %s currently in an unsupported mode\n", utf8_device); |
| r22936 | r22937 | |
| 1289 | 1333 | else |
| 1290 | 1334 | { |
| 1291 | 1335 | // default to the current mode exactly |
| 1292 | | d3d->width = d3d->origmode.Width; |
| 1293 | | d3d->height = d3d->origmode.Height; |
| 1294 | | d3d->pixformat = d3d->origmode.Format; |
| 1295 | | d3d->refresh = d3d->origmode.RefreshRate; |
| 1336 | m_width = m_origmode.Width; |
| 1337 | m_height = m_origmode.Height; |
| 1338 | m_pixformat = m_origmode.Format; |
| 1339 | m_refresh = m_origmode.RefreshRate; |
| 1296 | 1340 | |
| 1297 | 1341 | // if we're allowed to switch resolutions, override with something better |
| 1298 | 1342 | if (video_config.switchres) |
| 1299 | | pick_best_mode(window); |
| 1343 | pick_best_mode(); |
| 1300 | 1344 | } |
| 1301 | 1345 | |
| 1302 | 1346 | // see if we can handle the device type |
| 1303 | | result = (*d3dintf->d3d.check_device_type)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, d3d->pixformat, !window->fullscreen); |
| 1347 | result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !m_window->fullscreen); |
| 1304 | 1348 | if (result != D3D_OK) |
| 1305 | 1349 | { |
| 1306 | | char *utf8_device = utf8_from_tstring(window->monitor->info.szDevice); |
| 1350 | char *utf8_device = utf8_from_tstring(m_window->monitor->info.szDevice); |
| 1307 | 1351 | if (utf8_device != NULL) |
| 1308 | 1352 | { |
| 1309 | 1353 | mame_printf_error("Proposed video mode not supported on device %s\n", utf8_device); |
| r22936 | r22937 | |
| 1320 | 1364 | // get_adapter_for_monitor |
| 1321 | 1365 | //============================================================ |
| 1322 | 1366 | |
| 1323 | | static int get_adapter_for_monitor(d3d_info *d3d, win_monitor_info *monitor) |
| 1367 | int renderer::get_adapter_for_monitor() |
| 1324 | 1368 | { |
| 1325 | 1369 | int maxadapter = (*d3dintf->d3d.get_adapter_count)(d3dintf); |
| 1326 | | int adapternum; |
| 1327 | 1370 | |
| 1328 | 1371 | // iterate over adapters until we error or find a match |
| 1329 | | for (adapternum = 0; adapternum < maxadapter; adapternum++) |
| 1372 | for (int adapternum = 0; adapternum < maxadapter; adapternum++) |
| 1330 | 1373 | { |
| 1331 | | HMONITOR curmonitor; |
| 1332 | | |
| 1333 | 1374 | // get the monitor for this adapter |
| 1334 | | curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum); |
| 1375 | HMONITOR curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum); |
| 1335 | 1376 | |
| 1336 | 1377 | // if we match the proposed monitor, this is it |
| 1337 | | if (curmonitor == monitor->handle) |
| 1378 | if (curmonitor == m_window->monitor->handle) |
| 1379 | { |
| 1338 | 1380 | return adapternum; |
| 1381 | } |
| 1339 | 1382 | } |
| 1340 | 1383 | |
| 1341 | 1384 | // default to the default |
| r22936 | r22937 | |
| 1348 | 1391 | // pick_best_mode |
| 1349 | 1392 | //============================================================ |
| 1350 | 1393 | |
| 1351 | | static void pick_best_mode(win_window_info *window) |
| 1394 | void renderer::pick_best_mode() |
| 1352 | 1395 | { |
| 1353 | 1396 | double target_refresh = 60.0; |
| 1354 | | INT32 target_width, target_height; |
| 1355 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1356 | 1397 | INT32 minwidth, minheight; |
| 1357 | 1398 | float best_score = 0.0f; |
| 1358 | | int maxmodes; |
| 1359 | | int modenum; |
| 1360 | 1399 | |
| 1361 | 1400 | // determine the refresh rate of the primary screen |
| 1362 | | const screen_device *primary_screen = window->machine().config().first_screen(); |
| 1401 | const screen_device *primary_screen = m_window->machine().config().first_screen(); |
| 1363 | 1402 | if (primary_screen != NULL) |
| 1403 | { |
| 1364 | 1404 | target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds()); |
| 1405 | } |
| 1365 | 1406 | |
| 1366 | 1407 | // determine the minimum width/height for the selected target |
| 1367 | 1408 | // note: technically we should not be calling this from an alternate window |
| 1368 | 1409 | // thread; however, it is only done during init time, and the init code on |
| 1369 | 1410 | // the main thread is waiting for us to finish, so it is safe to do so here |
| 1370 | | window->target->compute_minimum_size(minwidth, minheight); |
| 1411 | m_window->target->compute_minimum_size(minwidth, minheight); |
| 1371 | 1412 | |
| 1372 | 1413 | // use those as the target for now |
| 1373 | | target_width = minwidth; |
| 1374 | | target_height = minheight; |
| 1414 | INT32 target_width = minwidth; |
| 1415 | INT32 target_height = minheight; |
| 1375 | 1416 | |
| 1376 | 1417 | // determine the maximum number of modes |
| 1377 | | maxmodes = (*d3dintf->d3d.get_adapter_mode_count)(d3dintf, d3d->adapter, D3DFMT_X8R8G8B8); |
| 1418 | int maxmodes = (*d3dintf->d3d.get_adapter_mode_count)(d3dintf, m_adapter, D3DFMT_X8R8G8B8); |
| 1378 | 1419 | |
| 1379 | 1420 | // enumerate all the video modes and find the best match |
| 1380 | 1421 | mame_printf_verbose("Direct3D: Selecting video mode...\n"); |
| 1381 | | for (modenum = 0; modenum < maxmodes; modenum++) |
| 1422 | for (int modenum = 0; modenum < maxmodes; modenum++) |
| 1382 | 1423 | { |
| 1383 | | float size_score, refresh_score, final_score; |
| 1424 | // check this mode |
| 1384 | 1425 | D3DDISPLAYMODE mode; |
| 1385 | | HRESULT result; |
| 1386 | | |
| 1387 | | // check this mode |
| 1388 | | result = (*d3dintf->d3d.enum_adapter_modes)(d3dintf, d3d->adapter, D3DFMT_X8R8G8B8, modenum, &mode); |
| 1426 | HRESULT result = (*d3dintf->d3d.enum_adapter_modes)(d3dintf, m_adapter, D3DFMT_X8R8G8B8, modenum, &mode); |
| 1389 | 1427 | if (result != D3D_OK) |
| 1390 | 1428 | break; |
| 1391 | 1429 | |
| r22936 | r22937 | |
| 1394 | 1432 | continue; |
| 1395 | 1433 | |
| 1396 | 1434 | // compute initial score based on difference between target and current |
| 1397 | | size_score = 1.0f / (1.0f + fabs((float)(mode.Width - target_width)) + fabs((float)(mode.Height - target_height))); |
| 1435 | float size_score = 1.0f / (1.0f + fabs((float)(mode.Width - target_width)) + fabs((float)(mode.Height - target_height))); |
| 1398 | 1436 | |
| 1399 | 1437 | // if the mode is too small, give a big penalty |
| 1400 | 1438 | if (mode.Width < minwidth || mode.Height < minheight) |
| r22936 | r22937 | |
| 1405 | 1443 | size_score *= 0.1f; |
| 1406 | 1444 | |
| 1407 | 1445 | // if we're looking for a particular mode, that's a winner |
| 1408 | | if (mode.Width == window->maxwidth && mode.Height == window->maxheight) |
| 1446 | if (mode.Width == m_window->maxwidth && mode.Height == m_window->maxheight) |
| 1409 | 1447 | size_score = 2.0f; |
| 1410 | 1448 | |
| 1411 | 1449 | // compute refresh score |
| 1412 | | refresh_score = 1.0f / (1.0f + fabs((double)mode.RefreshRate - target_refresh)); |
| 1450 | float refresh_score = 1.0f / (1.0f + fabs((double)mode.RefreshRate - target_refresh)); |
| 1413 | 1451 | |
| 1414 | 1452 | // if refresh is smaller than we'd like, it only scores up to 0.1 |
| 1415 | 1453 | if ((double)mode.RefreshRate < target_refresh) |
| 1416 | 1454 | refresh_score *= 0.1f; |
| 1417 | 1455 | |
| 1418 | 1456 | // if we're looking for a particular refresh, make sure it matches |
| 1419 | | if (mode.RefreshRate == window->refresh) |
| 1457 | if (mode.RefreshRate == m_window->refresh) |
| 1420 | 1458 | refresh_score = 2.0f; |
| 1421 | 1459 | |
| 1422 | 1460 | // weight size and refresh equally |
| 1423 | | final_score = size_score + refresh_score; |
| 1461 | float final_score = size_score + refresh_score; |
| 1424 | 1462 | |
| 1425 | 1463 | // best so far? |
| 1426 | 1464 | mame_printf_verbose(" %4dx%4d@%3dHz -> %f\n", mode.Width, mode.Height, mode.RefreshRate, final_score * 1000.0f); |
| 1427 | 1465 | if (final_score > best_score) |
| 1428 | 1466 | { |
| 1429 | 1467 | best_score = final_score; |
| 1430 | | d3d->width = mode.Width; |
| 1431 | | d3d->height = mode.Height; |
| 1432 | | d3d->pixformat = mode.Format; |
| 1433 | | d3d->refresh = mode.RefreshRate; |
| 1468 | m_width = mode.Width; |
| 1469 | m_height = mode.Height; |
| 1470 | m_pixformat = mode.Format; |
| 1471 | m_refresh = mode.RefreshRate; |
| 1434 | 1472 | } |
| 1435 | 1473 | } |
| 1436 | | mame_printf_verbose("Direct3D: Mode selected = %4dx%4d@%3dHz\n", d3d->width, d3d->height, d3d->refresh); |
| 1474 | mame_printf_verbose("Direct3D: Mode selected = %4dx%4d@%3dHz\n", m_width, m_height, m_refresh); |
| 1437 | 1475 | } |
| 1438 | 1476 | |
| 1439 | 1477 | |
| r22936 | r22937 | |
| 1442 | 1480 | // update_window_size |
| 1443 | 1481 | //============================================================ |
| 1444 | 1482 | |
| 1445 | | static int update_window_size(win_window_info *window) |
| 1483 | int renderer::update_window_size() |
| 1446 | 1484 | { |
| 1447 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1485 | // get the current window bounds |
| 1448 | 1486 | RECT client; |
| 1487 | GetClientRectExceptMenu(m_window->hwnd, &client, m_window->fullscreen); |
| 1449 | 1488 | |
| 1450 | | // get the current window bounds |
| 1451 | | GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen); |
| 1452 | | |
| 1453 | 1489 | // if we have a device and matching width/height, nothing to do |
| 1454 | | if (d3d->device != NULL && rect_width(&client) == d3d->width && rect_height(&client) == d3d->height) |
| 1490 | if (m_device != NULL && rect_width(&client) == m_width && rect_height(&client) == m_height) |
| 1455 | 1491 | { |
| 1456 | 1492 | // clear out any pending resizing if the area didn't change |
| 1457 | | if (window->resize_state == RESIZE_STATE_PENDING) |
| 1458 | | window->resize_state = RESIZE_STATE_NORMAL; |
| 1493 | if (m_window->resize_state == RESIZE_STATE_PENDING) |
| 1494 | m_window->resize_state = RESIZE_STATE_NORMAL; |
| 1459 | 1495 | return FALSE; |
| 1460 | 1496 | } |
| 1461 | 1497 | |
| 1462 | 1498 | // if we're in the middle of resizing, leave it alone as well |
| 1463 | | if (window->resize_state == RESIZE_STATE_RESIZING) |
| 1499 | if (m_window->resize_state == RESIZE_STATE_RESIZING) |
| 1464 | 1500 | return FALSE; |
| 1465 | 1501 | |
| 1466 | 1502 | // set the new bounds and create the device again |
| 1467 | | d3d->width = rect_width(&client); |
| 1468 | | d3d->height = rect_height(&client); |
| 1469 | | if (device_create(window)) |
| 1503 | m_width = rect_width(&client); |
| 1504 | m_height = rect_height(&client); |
| 1505 | if (device_create()) |
| 1470 | 1506 | return FALSE; |
| 1471 | 1507 | |
| 1472 | 1508 | // reset the resize state to normal, and indicate we made a change |
| 1473 | | window->resize_state = RESIZE_STATE_NORMAL; |
| 1509 | m_window->resize_state = RESIZE_STATE_NORMAL; |
| 1474 | 1510 | return TRUE; |
| 1475 | 1511 | } |
| 1476 | 1512 | |
| 1513 | //============================================================ |
| 1514 | // batch_vectors |
| 1515 | //============================================================ |
| 1477 | 1516 | |
| 1517 | void renderer::batch_vectors() |
| 1518 | { |
| 1519 | windows_options &options = downcast<windows_options &>(m_window->machine().options()); |
| 1478 | 1520 | |
| 1521 | int vector_size = (options.antialias() ? 24 : 6); |
| 1522 | m_vectorbatch = mesh_alloc(m_line_count * vector_size); |
| 1523 | m_batchindex = 0; |
| 1524 | |
| 1525 | static int start_index = 0; |
| 1526 | int line_index = 0; |
| 1527 | float period = options.screen_vector_time_period(); |
| 1528 | UINT32 cached_flags = 0; |
| 1529 | for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next()) |
| 1530 | { |
| 1531 | switch (prim->type) |
| 1532 | { |
| 1533 | case render_primitive::LINE: |
| 1534 | if (PRIMFLAG_GET_VECTOR(prim->flags)) |
| 1535 | { |
| 1536 | if (period == 0.0f || m_line_count == 0) |
| 1537 | { |
| 1538 | batch_vector(prim, 1.0f); |
| 1539 | } |
| 1540 | else |
| 1541 | { |
| 1542 | batch_vector(prim, (float)(start_index + line_index) / ((float)m_line_count * period)); |
| 1543 | line_index++; |
| 1544 | } |
| 1545 | cached_flags = prim->flags; |
| 1546 | } |
| 1547 | break; |
| 1548 | |
| 1549 | default: |
| 1550 | // Skip |
| 1551 | break; |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | // now add a polygon entry |
| 1556 | m_poly[m_numpolys].init(D3DPT_TRIANGLELIST, m_line_count * (options.antialias() ? 8 : 2), vector_size * m_line_count, cached_flags, |
| 1557 | m_texture_manager->get_vector_texture(), D3DTOP_MODULATE, 0.0f, 1.0f); |
| 1558 | m_numpolys++; |
| 1559 | |
| 1560 | start_index += (int)((float)line_index * period); |
| 1561 | if (m_line_count > 0) |
| 1562 | { |
| 1563 | start_index %= m_line_count; |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | void renderer::batch_vector(const render_primitive *prim, float line_time) |
| 1568 | { |
| 1569 | // compute the effective width based on the direction of the line |
| 1570 | float effwidth = prim->width; |
| 1571 | if (effwidth < 0.5f) |
| 1572 | { |
| 1573 | effwidth = 0.5f; |
| 1574 | } |
| 1575 | |
| 1576 | // determine the bounds of a quad to draw this line |
| 1577 | render_bounds b0, b1; |
| 1578 | render_line_to_quad(&prim->bounds, effwidth, &b0, &b1); |
| 1579 | |
| 1580 | // iterate over AA steps |
| 1581 | for (const line_aa_step *step = PRIMFLAG_GET_ANTIALIAS(prim->flags) ? line_aa_4step : line_aa_1step; |
| 1582 | step->weight != 0; step++) |
| 1583 | { |
| 1584 | // get a pointer to the vertex buffer |
| 1585 | if (m_vectorbatch == NULL) |
| 1586 | return; |
| 1587 | |
| 1588 | m_vectorbatch[m_batchindex + 0].x = b0.x0 + step->xoffs; |
| 1589 | m_vectorbatch[m_batchindex + 0].y = b0.y0 + step->yoffs; |
| 1590 | m_vectorbatch[m_batchindex + 1].x = b0.x1 + step->xoffs; |
| 1591 | m_vectorbatch[m_batchindex + 1].y = b0.y1 + step->yoffs; |
| 1592 | m_vectorbatch[m_batchindex + 2].x = b1.x0 + step->xoffs; |
| 1593 | m_vectorbatch[m_batchindex + 2].y = b1.y0 + step->yoffs; |
| 1594 | |
| 1595 | m_vectorbatch[m_batchindex + 3].x = b0.x1 + step->xoffs; |
| 1596 | m_vectorbatch[m_batchindex + 3].y = b0.y1 + step->yoffs; |
| 1597 | m_vectorbatch[m_batchindex + 4].x = b1.x0 + step->xoffs; |
| 1598 | m_vectorbatch[m_batchindex + 4].y = b1.y0 + step->yoffs; |
| 1599 | m_vectorbatch[m_batchindex + 5].x = b1.x1 + step->xoffs; |
| 1600 | m_vectorbatch[m_batchindex + 5].y = b1.y1 + step->yoffs; |
| 1601 | |
| 1602 | // determine the color of the line |
| 1603 | INT32 r = (INT32)(prim->color.r * step->weight * 255.0f); |
| 1604 | INT32 g = (INT32)(prim->color.g * step->weight * 255.0f); |
| 1605 | INT32 b = (INT32)(prim->color.b * step->weight * 255.0f); |
| 1606 | INT32 a = (INT32)(prim->color.a * 255.0f); |
| 1607 | if (r > 255) r = 255; |
| 1608 | if (g > 255) g = 255; |
| 1609 | if (b > 255) b = 255; |
| 1610 | if (a > 255) a = 255; |
| 1611 | DWORD color = D3DCOLOR_ARGB(a, r, g, b); |
| 1612 | |
| 1613 | vec2f& start = (get_vector_texture() ? get_vector_texture()->get_uvstart() : get_default_texture()->get_uvstart()); |
| 1614 | vec2f& stop = (get_vector_texture() ? get_vector_texture()->get_uvstop() : get_default_texture()->get_uvstop()); |
| 1615 | |
| 1616 | m_vectorbatch[m_batchindex + 0].u0 = start.c.x; |
| 1617 | m_vectorbatch[m_batchindex + 0].v0 = start.c.y; |
| 1618 | m_vectorbatch[m_batchindex + 1].u0 = start.c.x; |
| 1619 | m_vectorbatch[m_batchindex + 1].v0 = stop.c.y; |
| 1620 | m_vectorbatch[m_batchindex + 2].u0 = stop.c.x; |
| 1621 | m_vectorbatch[m_batchindex + 2].v0 = start.c.y; |
| 1622 | |
| 1623 | m_vectorbatch[m_batchindex + 3].u0 = start.c.x; |
| 1624 | m_vectorbatch[m_batchindex + 3].v0 = stop.c.y; |
| 1625 | m_vectorbatch[m_batchindex + 4].u0 = stop.c.x; |
| 1626 | m_vectorbatch[m_batchindex + 4].v0 = start.c.y; |
| 1627 | m_vectorbatch[m_batchindex + 5].u0 = stop.c.x; |
| 1628 | m_vectorbatch[m_batchindex + 5].v0 = stop.c.y; |
| 1629 | |
| 1630 | // set the color, Z parameters to standard values |
| 1631 | for (int i = 0; i < 6; i++) |
| 1632 | { |
| 1633 | m_vectorbatch[m_batchindex + i].z = 0.0f; |
| 1634 | m_vectorbatch[m_batchindex + i].rhw = 1.0f; |
| 1635 | m_vectorbatch[m_batchindex + i].color = color; |
| 1636 | } |
| 1637 | |
| 1638 | m_batchindex += 6; |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1479 | 1642 | //============================================================ |
| 1480 | 1643 | // draw_line |
| 1481 | 1644 | //============================================================ |
| 1482 | 1645 | |
| 1483 | | static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_time) |
| 1646 | void renderer::draw_line(const render_primitive *prim) |
| 1484 | 1647 | { |
| 1485 | | const line_aa_step *step = line_aa_4step; |
| 1486 | | render_bounds b0, b1; |
| 1487 | | d3d_vertex *vertex; |
| 1488 | | INT32 r, g, b, a; |
| 1489 | | d3d_poly_info *poly; |
| 1490 | | float effwidth; |
| 1491 | | DWORD color; |
| 1492 | | int i; |
| 1493 | | |
| 1494 | 1648 | // compute the effective width based on the direction of the line |
| 1495 | | effwidth = prim->width; |
| 1649 | float effwidth = prim->width; |
| 1496 | 1650 | if (effwidth < 0.5f) |
| 1651 | { |
| 1497 | 1652 | effwidth = 0.5f; |
| 1653 | } |
| 1498 | 1654 | |
| 1499 | 1655 | // determine the bounds of a quad to draw this line |
| 1656 | render_bounds b0, b1; |
| 1500 | 1657 | render_line_to_quad(&prim->bounds, effwidth, &b0, &b1); |
| 1501 | 1658 | |
| 1502 | 1659 | // iterate over AA steps |
| 1503 | | for (step = PRIMFLAG_GET_ANTIALIAS(prim->flags) ? line_aa_4step : line_aa_1step; step->weight != 0; step++) |
| 1660 | for (const line_aa_step *step = PRIMFLAG_GET_ANTIALIAS(prim->flags) ? line_aa_4step : line_aa_1step; |
| 1661 | step->weight != 0; step++) |
| 1504 | 1662 | { |
| 1505 | 1663 | // get a pointer to the vertex buffer |
| 1506 | | vertex = primitive_alloc(d3d, 4); |
| 1664 | vertex *vertex = mesh_alloc(4); |
| 1507 | 1665 | if (vertex == NULL) |
| 1508 | 1666 | return; |
| 1509 | 1667 | |
| r22936 | r22937 | |
| 1524 | 1682 | vertex[3].y = b1.y1 + step->yoffs; |
| 1525 | 1683 | |
| 1526 | 1684 | // determine the color of the line |
| 1527 | | r = (INT32)(prim->color.r * step->weight * 255.0f); |
| 1528 | | g = (INT32)(prim->color.g * step->weight * 255.0f); |
| 1529 | | b = (INT32)(prim->color.b * step->weight * 255.0f); |
| 1530 | | a = (INT32)(prim->color.a * 255.0f); |
| 1685 | INT32 r = (INT32)(prim->color.r * step->weight * 255.0f); |
| 1686 | INT32 g = (INT32)(prim->color.g * step->weight * 255.0f); |
| 1687 | INT32 b = (INT32)(prim->color.b * step->weight * 255.0f); |
| 1688 | INT32 a = (INT32)(prim->color.a * 255.0f); |
| 1531 | 1689 | if (r > 255) r = 255; |
| 1532 | 1690 | if (g > 255) g = 255; |
| 1533 | 1691 | if (b > 255) b = 255; |
| 1534 | 1692 | if (a > 255) a = 255; |
| 1535 | | color = D3DCOLOR_ARGB(a, r, g, b); |
| 1693 | DWORD color = D3DCOLOR_ARGB(a, r, g, b); |
| 1536 | 1694 | |
| 1537 | | // if we have a texture to use for the vectors, use it here |
| 1538 | | if (d3d->vector_texture != NULL) |
| 1539 | | { |
| 1540 | | vertex[0].u0 = d3d->vector_texture->ustart; |
| 1541 | | vertex[0].v0 = d3d->vector_texture->vstart; |
| 1695 | vec2f& start = (get_vector_texture() ? get_vector_texture()->get_uvstart() : get_default_texture()->get_uvstart()); |
| 1696 | vec2f& stop = (get_vector_texture() ? get_vector_texture()->get_uvstop() : get_default_texture()->get_uvstop()); |
| 1542 | 1697 | |
| 1543 | | vertex[2].u0 = d3d->vector_texture->ustop; |
| 1544 | | vertex[2].v0 = d3d->vector_texture->vstart; |
| 1698 | vertex[0].u0 = start.c.x; |
| 1699 | vertex[0].v0 = start.c.y; |
| 1545 | 1700 | |
| 1546 | | vertex[1].u0 = d3d->vector_texture->ustart; |
| 1547 | | vertex[1].v0 = d3d->vector_texture->vstop; |
| 1701 | vertex[2].u0 = stop.c.x; |
| 1702 | vertex[2].v0 = start.c.y; |
| 1548 | 1703 | |
| 1549 | | vertex[3].u0 = d3d->vector_texture->ustop; |
| 1550 | | vertex[3].v0 = d3d->vector_texture->vstop; |
| 1551 | | } |
| 1552 | | else if(d3d->default_texture != NULL) |
| 1553 | | { |
| 1554 | | vertex[0].u0 = d3d->default_texture->ustart; |
| 1555 | | vertex[0].v0 = d3d->default_texture->vstart; |
| 1704 | vertex[1].u0 = start.c.x; |
| 1705 | vertex[1].v0 = stop.c.y; |
| 1556 | 1706 | |
| 1557 | | vertex[2].u0 = d3d->default_texture->ustart; |
| 1558 | | vertex[2].v0 = d3d->default_texture->vstart; |
| 1707 | vertex[3].u0 = stop.c.x; |
| 1708 | vertex[3].v0 = stop.c.y; |
| 1559 | 1709 | |
| 1560 | | vertex[1].u0 = d3d->default_texture->ustart; |
| 1561 | | vertex[1].v0 = d3d->default_texture->vstart; |
| 1562 | | |
| 1563 | | vertex[3].u0 = d3d->default_texture->ustart; |
| 1564 | | vertex[3].v0 = d3d->default_texture->vstart; |
| 1565 | | } |
| 1566 | | |
| 1567 | 1710 | // set the color, Z parameters to standard values |
| 1568 | | for (i = 0; i < 4; i++) |
| 1711 | for (int i = 0; i < 4; i++) |
| 1569 | 1712 | { |
| 1570 | 1713 | vertex[i].z = 0.0f; |
| 1571 | 1714 | vertex[i].rhw = 1.0f; |
| r22936 | r22937 | |
| 1573 | 1716 | } |
| 1574 | 1717 | |
| 1575 | 1718 | // now add a polygon entry |
| 1576 | | poly = &d3d->poly[d3d->numpolys++]; |
| 1577 | | poly->type = D3DPT_TRIANGLESTRIP; |
| 1578 | | poly->count = 2; |
| 1579 | | poly->numverts = 4; |
| 1580 | | poly->flags = prim->flags; |
| 1581 | | poly->modmode = D3DTOP_MODULATE; |
| 1582 | | poly->texture = d3d->vector_texture; |
| 1583 | | poly->line_time = line_time; |
| 1584 | | poly->line_length = 1.0f; |
| 1585 | | if (PRIMFLAG_GET_VECTOR(poly->flags)) |
| 1586 | | { |
| 1587 | | float dx = fabs(prim->bounds.x1 - prim->bounds.x0); |
| 1588 | | float dy = fabs(prim->bounds.y1 - prim->bounds.y0); |
| 1589 | | float length2 = dx * dx + dy * dy; |
| 1590 | | if (length2 > 0.0f) |
| 1591 | | { |
| 1592 | | poly->line_length = sqrt(length2); |
| 1593 | | } |
| 1594 | | else |
| 1595 | | { |
| 1596 | | // use default length of 1.0f from above |
| 1597 | | } |
| 1598 | | } |
| 1719 | m_poly[m_numpolys].init(D3DPT_TRIANGLESTRIP, 2, 4, prim->flags, get_vector_texture(), |
| 1720 | D3DTOP_MODULATE, 0.0f, 1.0f); |
| 1721 | m_numpolys++; |
| 1599 | 1722 | } |
| 1600 | 1723 | } |
| 1601 | 1724 | |
| r22936 | r22937 | |
| 1605 | 1728 | // draw_quad |
| 1606 | 1729 | //============================================================ |
| 1607 | 1730 | |
| 1608 | | static void draw_quad(d3d_info *d3d, const render_primitive *prim) |
| 1731 | void renderer::draw_quad(const render_primitive *prim) |
| 1609 | 1732 | { |
| 1610 | | d3d_texture_info *texture = texture_find(d3d, prim); |
| 1611 | | DWORD color, modmode; |
| 1612 | | d3d_vertex *vertex; |
| 1613 | | INT32 r, g, b, a; |
| 1614 | | d3d_poly_info *poly; |
| 1615 | | int i; |
| 1733 | texture_info *texture = m_texture_manager->find_texinfo(&prim->texture, prim->flags); |
| 1616 | 1734 | |
| 1617 | | texture = texture != NULL ? texture : d3d->default_texture; |
| 1735 | if (texture == NULL) |
| 1736 | { |
| 1737 | texture = get_default_texture(); |
| 1738 | } |
| 1618 | 1739 | |
| 1619 | 1740 | // get a pointer to the vertex buffer |
| 1620 | | vertex = primitive_alloc(d3d, 4); |
| 1741 | vertex *vertex = mesh_alloc(4); |
| 1621 | 1742 | if (vertex == NULL) |
| 1622 | 1743 | return; |
| 1623 | 1744 | |
| r22936 | r22937 | |
| 1634 | 1755 | // set the texture coordinates |
| 1635 | 1756 | if(texture != NULL) |
| 1636 | 1757 | { |
| 1637 | | float du = texture->ustop - texture->ustart; |
| 1638 | | float dv = texture->vstop - texture->vstart; |
| 1639 | | vertex[0].u0 = texture->ustart + du * prim->texcoords.tl.u; |
| 1640 | | vertex[0].v0 = texture->vstart + dv * prim->texcoords.tl.v; |
| 1641 | | vertex[1].u0 = texture->ustart + du * prim->texcoords.tr.u; |
| 1642 | | vertex[1].v0 = texture->vstart + dv * prim->texcoords.tr.v; |
| 1643 | | vertex[2].u0 = texture->ustart + du * prim->texcoords.bl.u; |
| 1644 | | vertex[2].v0 = texture->vstart + dv * prim->texcoords.bl.v; |
| 1645 | | vertex[3].u0 = texture->ustart + du * prim->texcoords.br.u; |
| 1646 | | vertex[3].v0 = texture->vstart + dv * prim->texcoords.br.v; |
| 1758 | vec2f& start = texture->get_uvstart(); |
| 1759 | vec2f& stop = texture->get_uvstop(); |
| 1760 | vec2f delta = stop - start; |
| 1761 | vertex[0].u0 = start.c.x + delta.c.x * prim->texcoords.tl.u; |
| 1762 | vertex[0].v0 = start.c.y + delta.c.y * prim->texcoords.tl.v; |
| 1763 | vertex[1].u0 = start.c.x + delta.c.x * prim->texcoords.tr.u; |
| 1764 | vertex[1].v0 = start.c.y + delta.c.y * prim->texcoords.tr.v; |
| 1765 | vertex[2].u0 = start.c.x + delta.c.x * prim->texcoords.bl.u; |
| 1766 | vertex[2].v0 = start.c.y + delta.c.y * prim->texcoords.bl.v; |
| 1767 | vertex[3].u0 = start.c.x + delta.c.x * prim->texcoords.br.u; |
| 1768 | vertex[3].v0 = start.c.y + delta.c.y * prim->texcoords.br.v; |
| 1647 | 1769 | } |
| 1648 | 1770 | |
| 1649 | 1771 | // determine the color, allowing for over modulation |
| 1650 | | r = (INT32)(prim->color.r * 255.0f); |
| 1651 | | g = (INT32)(prim->color.g * 255.0f); |
| 1652 | | b = (INT32)(prim->color.b * 255.0f); |
| 1653 | | a = (INT32)(prim->color.a * 255.0f); |
| 1654 | | modmode = D3DTOP_MODULATE; |
| 1772 | INT32 r = (INT32)(prim->color.r * 255.0f); |
| 1773 | INT32 g = (INT32)(prim->color.g * 255.0f); |
| 1774 | INT32 b = (INT32)(prim->color.b * 255.0f); |
| 1775 | INT32 a = (INT32)(prim->color.a * 255.0f); |
| 1776 | DWORD modmode = D3DTOP_MODULATE; |
| 1655 | 1777 | if (texture != NULL) |
| 1656 | 1778 | { |
| 1657 | | if (d3d->mod2x_supported && (r > 255 || g > 255 || b > 255)) |
| 1779 | if (m_mod2x_supported && (r > 255 || g > 255 || b > 255)) |
| 1658 | 1780 | { |
| 1659 | | if (d3d->mod4x_supported && (r > 2*255 || g > 2*255 || b > 2*255)) |
| 1781 | if (m_mod4x_supported && (r > 2*255 || g > 2*255 || b > 2*255)) |
| 1660 | 1782 | { |
| 1661 | 1783 | r >>= 2; g >>= 2; b >>= 2; |
| 1662 | 1784 | modmode = D3DTOP_MODULATE4X; |
| r22936 | r22937 | |
| 1672 | 1794 | if (g > 255) g = 255; |
| 1673 | 1795 | if (b > 255) b = 255; |
| 1674 | 1796 | if (a > 255) a = 255; |
| 1675 | | color = D3DCOLOR_ARGB(a, r, g, b); |
| 1797 | DWORD color = D3DCOLOR_ARGB(a, r, g, b); |
| 1676 | 1798 | |
| 1677 | 1799 | // set the color, Z parameters to standard values |
| 1678 | | for (i = 0; i < 4; i++) |
| 1800 | for (int i = 0; i < 4; i++) |
| 1679 | 1801 | { |
| 1680 | 1802 | vertex[i].z = 0.0f; |
| 1681 | 1803 | vertex[i].rhw = 1.0f; |
| r22936 | r22937 | |
| 1683 | 1805 | } |
| 1684 | 1806 | |
| 1685 | 1807 | // now add a polygon entry |
| 1686 | | poly = &d3d->poly[d3d->numpolys++]; |
| 1687 | | poly->type = D3DPT_TRIANGLESTRIP; |
| 1688 | | poly->count = 2; |
| 1689 | | poly->numverts = 4; |
| 1690 | | poly->flags = prim->flags; |
| 1691 | | poly->modmode = modmode; |
| 1692 | | poly->texture = texture; |
| 1693 | | //poly-> |
| 1808 | m_poly[m_numpolys].init(D3DPT_TRIANGLESTRIP, 2, 4, prim->flags, texture, modmode); |
| 1809 | m_numpolys++; |
| 1694 | 1810 | } |
| 1695 | 1811 | |
| 1812 | void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts, |
| 1813 | UINT32 flags, texture_info *texture, UINT32 modmode, |
| 1814 | float line_time, float line_length) |
| 1815 | { |
| 1816 | init(type, count, numverts, flags, texture, modmode); |
| 1817 | m_line_time = line_time; |
| 1818 | m_line_length = line_length; |
| 1819 | } |
| 1696 | 1820 | |
| 1821 | void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts, |
| 1822 | UINT32 flags, texture_info *texture, UINT32 modmode) |
| 1823 | { |
| 1824 | m_type = type; |
| 1825 | m_count = count; |
| 1826 | m_numverts = numverts; |
| 1827 | m_flags = flags; |
| 1828 | m_texture = texture; |
| 1829 | m_modmode = modmode; |
| 1830 | } |
| 1831 | |
| 1697 | 1832 | //============================================================ |
| 1698 | 1833 | // primitive_alloc |
| 1699 | 1834 | //============================================================ |
| 1700 | 1835 | |
| 1701 | | static d3d_vertex *primitive_alloc(d3d_info *d3d, int numverts) |
| 1836 | vertex *renderer::mesh_alloc(int numverts) |
| 1702 | 1837 | { |
| 1703 | 1838 | HRESULT result; |
| 1704 | 1839 | |
| 1705 | 1840 | // if we're going to overflow, flush |
| 1706 | | if (d3d->lockedbuf != NULL && d3d->numverts + numverts >= VERTEX_BUFFER_SIZE) |
| 1841 | if (m_lockedbuf != NULL && m_numverts + numverts >= VERTEX_BUFFER_SIZE) |
| 1707 | 1842 | { |
| 1708 | | primitive_flush_pending(d3d); |
| 1843 | primitive_flush_pending(); |
| 1709 | 1844 | |
| 1710 | | if(d3d->hlsl->enabled()) |
| 1845 | if(m_shaders->enabled()) |
| 1711 | 1846 | { |
| 1712 | | d3d->hlsl_buf = (void*)primitive_alloc(d3d, 6); |
| 1713 | | d3d->hlsl->init_fsfx_quad(d3d->hlsl_buf); |
| 1847 | m_hlsl_buf = (void*)mesh_alloc(6); |
| 1848 | m_shaders->init_fsfx_quad(m_hlsl_buf); |
| 1714 | 1849 | } |
| 1715 | 1850 | } |
| 1716 | 1851 | |
| 1717 | 1852 | // if we don't have a lock, grab it now |
| 1718 | | if (d3d->lockedbuf == NULL) |
| 1853 | if (m_lockedbuf == NULL) |
| 1719 | 1854 | { |
| 1720 | | result = (*d3dintf->vertexbuf.lock)(d3d->vertexbuf, 0, 0, (VOID **)&d3d->lockedbuf, D3DLOCK_DISCARD); |
| 1855 | result = (*d3dintf->vertexbuf.lock)(m_vertexbuf, 0, 0, (VOID **)&m_lockedbuf, D3DLOCK_DISCARD); |
| 1721 | 1856 | if (result != D3D_OK) |
| 1722 | 1857 | return NULL; |
| 1723 | 1858 | } |
| 1724 | 1859 | |
| 1725 | 1860 | // if we already have the lock and enough room, just return a pointer |
| 1726 | | if (d3d->lockedbuf != NULL && d3d->numverts + numverts < VERTEX_BUFFER_SIZE) |
| 1861 | if (m_lockedbuf != NULL && m_numverts + numverts < VERTEX_BUFFER_SIZE) |
| 1727 | 1862 | { |
| 1728 | | int oldverts = d3d->numverts; |
| 1729 | | d3d->numverts += numverts; |
| 1730 | | return &d3d->lockedbuf[oldverts]; |
| 1863 | int oldverts = m_numverts; |
| 1864 | m_numverts += numverts; |
| 1865 | return &m_lockedbuf[oldverts]; |
| 1731 | 1866 | } |
| 1732 | 1867 | return NULL; |
| 1733 | 1868 | } |
| r22936 | r22937 | |
| 1738 | 1873 | // primitive_flush_pending |
| 1739 | 1874 | //============================================================ |
| 1740 | 1875 | |
| 1741 | | static void primitive_flush_pending(d3d_info *d3d) |
| 1876 | void renderer::primitive_flush_pending() |
| 1742 | 1877 | { |
| 1743 | | HRESULT result; |
| 1744 | | int polynum; |
| 1745 | | int vertnum; |
| 1746 | | |
| 1747 | 1878 | // ignore if we're not locked |
| 1748 | | if (d3d->lockedbuf == NULL) |
| 1879 | if (m_lockedbuf == NULL) |
| 1880 | { |
| 1749 | 1881 | return; |
| 1882 | } |
| 1750 | 1883 | |
| 1751 | 1884 | // unlock the buffer |
| 1752 | | result = (*d3dintf->vertexbuf.unlock)(d3d->vertexbuf); |
| 1885 | HRESULT result = (*d3dintf->vertexbuf.unlock)(m_vertexbuf); |
| 1753 | 1886 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during vertex buffer unlock call\n", (int)result); |
| 1754 | | d3d->lockedbuf = NULL; |
| 1887 | m_lockedbuf = NULL; |
| 1755 | 1888 | |
| 1756 | 1889 | // set the stream |
| 1757 | | result = (*d3dintf->device.set_stream_source)(d3d->device, 0, d3d->vertexbuf, sizeof(d3d_vertex)); |
| 1890 | result = (*d3dintf->device.set_stream_source)(m_device, 0, m_vertexbuf, sizeof(vertex)); |
| 1758 | 1891 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_stream_source call\n", (int)result); |
| 1759 | 1892 | |
| 1760 | | d3d->hlsl->begin_draw(); |
| 1893 | m_shaders->begin_draw(); |
| 1761 | 1894 | |
| 1762 | | if (d3d->hlsl->enabled()) |
| 1895 | int vertnum = 0; |
| 1896 | if (m_shaders->enabled()) |
| 1763 | 1897 | { |
| 1764 | 1898 | vertnum = 6; |
| 1765 | 1899 | } |
| 1766 | | else |
| 1767 | | { |
| 1768 | | vertnum = 0; |
| 1769 | | } |
| 1770 | 1900 | |
| 1771 | 1901 | // now do the polys |
| 1772 | | for (polynum = 0; polynum < d3d->numpolys; polynum++) |
| 1902 | for (int polynum = 0; polynum < m_numpolys; polynum++) |
| 1773 | 1903 | { |
| 1774 | | d3d_poly_info *poly = &d3d->poly[polynum]; |
| 1904 | UINT32 flags = m_poly[polynum].get_flags(); |
| 1905 | texture_info *texture = m_poly[polynum].get_texture(); |
| 1775 | 1906 | int newfilter; |
| 1776 | 1907 | |
| 1777 | 1908 | // set the texture if different |
| 1778 | | set_texture(d3d, poly->texture); |
| 1909 | set_texture(texture); |
| 1779 | 1910 | |
| 1780 | 1911 | // set filtering if different |
| 1781 | | if (poly->texture != NULL) |
| 1912 | if (texture != NULL) |
| 1782 | 1913 | { |
| 1783 | 1914 | newfilter = FALSE; |
| 1784 | | if (PRIMFLAG_GET_SCREENTEX(poly->flags)) |
| 1915 | if (PRIMFLAG_GET_SCREENTEX(flags)) |
| 1785 | 1916 | newfilter = video_config.filter; |
| 1786 | | set_filter(d3d, newfilter); |
| 1787 | | set_wrap(d3d, PRIMFLAG_GET_TEXWRAP(poly->flags)); |
| 1788 | | set_modmode(d3d, poly->modmode); |
| 1917 | set_filter(newfilter); |
| 1918 | set_wrap(PRIMFLAG_GET_TEXWRAP(flags) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); |
| 1919 | set_modmode(m_poly[polynum].get_modmode()); |
| 1789 | 1920 | |
| 1790 | | d3d->hlsl->init_effect_info(poly); |
| 1921 | m_shaders->init_effect_info(&m_poly[polynum]); |
| 1791 | 1922 | } |
| 1792 | 1923 | |
| 1793 | 1924 | // set the blendmode if different |
| 1794 | | set_blendmode(d3d, PRIMFLAG_GET_BLENDMODE(poly->flags)); |
| 1925 | set_blendmode(PRIMFLAG_GET_BLENDMODE(flags)); |
| 1795 | 1926 | |
| 1796 | | if(d3d->hlsl->enabled() && d3dintf->post_fx_available) |
| 1927 | assert(vertnum + m_poly[polynum].get_vertcount() <= m_numverts); |
| 1928 | |
| 1929 | if(m_shaders->enabled() && d3dintf->post_fx_available) |
| 1797 | 1930 | { |
| 1798 | | assert(vertnum + poly->numverts <= d3d->numverts); |
| 1799 | | |
| 1800 | | d3d->hlsl->render_quad(poly, vertnum); |
| 1931 | m_shaders->render_quad(&m_poly[polynum], vertnum); |
| 1801 | 1932 | } |
| 1802 | 1933 | else |
| 1803 | 1934 | { |
| 1804 | | assert(vertnum + poly->numverts <= d3d->numverts); |
| 1805 | | |
| 1806 | 1935 | // add the primitives |
| 1807 | | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 1936 | result = (*d3dintf->device.draw_primitive)(m_device, m_poly[polynum].get_type(), vertnum, |
| 1937 | m_poly[polynum].get_count()); |
| 1808 | 1938 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1809 | 1939 | } |
| 1810 | 1940 | |
| 1811 | | vertnum += poly->numverts; |
| 1941 | vertnum += m_poly[polynum].get_vertcount(); |
| 1812 | 1942 | } |
| 1813 | 1943 | |
| 1814 | | d3d->hlsl->end_draw(); |
| 1944 | m_shaders->end_draw(); |
| 1815 | 1945 | |
| 1816 | 1946 | // reset the vertex count |
| 1817 | | d3d->numverts = 0; |
| 1818 | | d3d->numpolys = 0; |
| 1947 | m_numverts = 0; |
| 1948 | m_numpolys = 0; |
| 1819 | 1949 | } |
| 1820 | 1950 | |
| 1951 | //============================================================ |
| 1952 | // texture_info destructor |
| 1953 | //============================================================ |
| 1821 | 1954 | |
| 1822 | | void texture_destroy(d3d_info *d3d, d3d_texture_info *info) |
| 1955 | texture_info::~texture_info() |
| 1823 | 1956 | { |
| 1957 | if (m_d3dfinaltex != NULL) |
| 1958 | { |
| 1959 | if (m_d3dtex == m_d3dfinaltex) |
| 1960 | { |
| 1961 | m_d3dtex = NULL; |
| 1962 | } |
| 1963 | (*d3dintf->texture.release)(m_d3dfinaltex); |
| 1964 | m_d3dfinaltex = NULL; |
| 1965 | } |
| 1966 | if (m_d3dtex != NULL) |
| 1967 | { |
| 1968 | (*d3dintf->texture.release)(m_d3dtex); |
| 1969 | m_d3dtex = NULL; |
| 1970 | } |
| 1971 | if (m_d3dsurface != NULL) |
| 1972 | { |
| 1973 | (*d3dintf->surface.release)(m_d3dsurface); |
| 1974 | m_d3dsurface = NULL; |
| 1975 | } |
| 1824 | 1976 | } |
| 1825 | 1977 | |
| 1826 | 1978 | //============================================================ |
| 1827 | | // texture_create |
| 1979 | // texture_info constructor |
| 1828 | 1980 | //============================================================ |
| 1829 | 1981 | |
| 1830 | | d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource, UINT32 flags) |
| 1982 | texture_info::texture_info(texture_manager *manager, const render_texinfo* texsource, UINT32 flags) |
| 1831 | 1983 | { |
| 1832 | | d3d_texture_info *texture; |
| 1833 | 1984 | HRESULT result; |
| 1834 | 1985 | |
| 1835 | | // allocate a new texture |
| 1836 | | texture = global_alloc_clear(d3d_texture_info); |
| 1837 | | |
| 1838 | 1986 | // fill in the core data |
| 1839 | | texture->hash = texture_compute_hash(texsource, flags); |
| 1840 | | texture->flags = flags; |
| 1841 | | texture->texinfo = *texsource; |
| 1842 | | texture->xprescale = video_config.prescale; |
| 1843 | | texture->yprescale = video_config.prescale; |
| 1987 | m_texture_manager = manager; |
| 1988 | m_renderer = m_texture_manager->get_d3d(); |
| 1989 | m_hash = m_texture_manager->texture_compute_hash(texsource, flags); |
| 1990 | m_flags = flags; |
| 1991 | m_texinfo = *texsource; |
| 1992 | m_xprescale = video_config.prescale; |
| 1993 | m_yprescale = video_config.prescale; |
| 1844 | 1994 | |
| 1995 | m_d3dtex = NULL; |
| 1996 | m_d3dsurface = NULL; |
| 1997 | m_d3dfinaltex = NULL; |
| 1998 | |
| 1845 | 1999 | // compute the size |
| 1846 | | texture_compute_size(d3d, texsource->width, texsource->height, texture); |
| 2000 | compute_size(texsource->width, texsource->height); |
| 1847 | 2001 | |
| 1848 | 2002 | // non-screen textures are easy |
| 1849 | 2003 | if (!PRIMFLAG_GET_SCREENTEX(flags)) |
| 1850 | 2004 | { |
| 1851 | 2005 | assert(PRIMFLAG_TEXFORMAT(flags) != TEXFORMAT_YUY16); |
| 1852 | | result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture->d3dtex); |
| 2006 | result = (*d3dintf->device.create_texture)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_d3dtex); |
| 1853 | 2007 | if (result != D3D_OK) |
| 1854 | 2008 | goto error; |
| 1855 | | texture->d3dfinaltex = texture->d3dtex; |
| 1856 | | texture->type = TEXTURE_TYPE_PLAIN; |
| 2009 | m_d3dfinaltex = m_d3dtex; |
| 2010 | m_type = TEXTURE_TYPE_PLAIN; |
| 1857 | 2011 | } |
| 1858 | 2012 | |
| 1859 | 2013 | // screen textures are allocated differently |
| 1860 | 2014 | else |
| 1861 | 2015 | { |
| 1862 | 2016 | D3DFORMAT format; |
| 1863 | | DWORD usage = d3d->dynamic_supported ? D3DUSAGE_DYNAMIC : 0; |
| 1864 | | D3DPOOL pool = d3d->dynamic_supported ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; |
| 1865 | | int maxdim = MAX(d3d->presentation.BackBufferWidth, d3d->presentation.BackBufferHeight); |
| 1866 | | int attempt; |
| 2017 | DWORD usage = m_texture_manager->is_dynamic_supported() ? D3DUSAGE_DYNAMIC : 0; |
| 2018 | D3DPOOL pool = m_texture_manager->is_dynamic_supported() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; |
| 2019 | int maxdim = MAX(m_renderer->get_presentation()->BackBufferWidth, m_renderer->get_presentation()->BackBufferHeight); |
| 1867 | 2020 | |
| 1868 | 2021 | // pick the format |
| 1869 | 2022 | if (PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_YUY16) |
| 1870 | | format = d3d->yuv_format; |
| 2023 | { |
| 2024 | format = m_texture_manager->get_yuv_format(); |
| 2025 | } |
| 1871 | 2026 | else if (PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_ARGB32 || PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_PALETTEA16) |
| 2027 | { |
| 1872 | 2028 | format = D3DFMT_A8R8G8B8; |
| 2029 | } |
| 1873 | 2030 | else |
| 1874 | | format = d3d->screen_format; |
| 2031 | { |
| 2032 | format = m_renderer->get_screen_format(); |
| 2033 | } |
| 1875 | 2034 | |
| 1876 | 2035 | // don't prescale above screen size |
| 1877 | | while (texture->xprescale > 1 && texture->rawwidth * texture->xprescale >= 2 * maxdim) |
| 1878 | | texture->xprescale--; |
| 1879 | | while (texture->xprescale > 1 && texture->rawwidth * texture->xprescale > d3d->texture_max_width) |
| 1880 | | texture->xprescale--; |
| 1881 | | while (texture->yprescale > 1 && texture->rawheight * texture->yprescale >= 2 * maxdim) |
| 1882 | | texture->yprescale--; |
| 1883 | | while (texture->yprescale > 1 && texture->rawheight * texture->yprescale > d3d->texture_max_height) |
| 1884 | | texture->yprescale--; |
| 1885 | | if (texture->xprescale != video_config.prescale || texture->yprescale != video_config.prescale) |
| 1886 | | mame_printf_verbose("Direct3D: adjusting prescale from %dx%d to %dx%d\n", video_config.prescale, video_config.prescale, texture->xprescale, texture->yprescale); |
| 2036 | while (m_xprescale > 1 && m_rawdims.c.x * m_xprescale >= 2 * maxdim) |
| 2037 | { |
| 2038 | m_xprescale--; |
| 2039 | } |
| 2040 | while (m_xprescale > 1 && m_rawdims.c.x * m_xprescale > manager->get_max_texture_width()) |
| 2041 | { |
| 2042 | m_xprescale--; |
| 2043 | } |
| 2044 | while (m_yprescale > 1 && m_rawdims.c.y * m_yprescale >= 2 * maxdim) |
| 2045 | { |
| 2046 | m_yprescale--; |
| 2047 | } |
| 2048 | while (m_yprescale > 1 && m_rawdims.c.y * m_yprescale > manager->get_max_texture_height()) |
| 2049 | { |
| 2050 | m_yprescale--; |
| 2051 | } |
| 2052 | if (m_xprescale != video_config.prescale || m_yprescale != video_config.prescale) |
| 2053 | { |
| 2054 | mame_printf_verbose("Direct3D: adjusting prescale from %dx%d to %dx%d\n", video_config.prescale, video_config.prescale, m_xprescale, m_yprescale); |
| 2055 | } |
| 1887 | 2056 | |
| 1888 | 2057 | // loop until we allocate something or error |
| 1889 | | for (attempt = 0; attempt < 2; attempt++) |
| 2058 | for (int attempt = 0; attempt < 2; attempt++) |
| 1890 | 2059 | { |
| 1891 | 2060 | // second attempt is always 1:1 |
| 1892 | 2061 | if (attempt == 1) |
| 1893 | | texture->xprescale = texture->yprescale = 1; |
| 2062 | { |
| 2063 | m_xprescale = m_yprescale = 1; |
| 2064 | } |
| 1894 | 2065 | |
| 1895 | 2066 | // screen textures with no prescaling are pretty easy |
| 1896 | | if (texture->xprescale == 1 && texture->yprescale == 1) |
| 2067 | if (m_xprescale == 1 && m_yprescale == 1) |
| 1897 | 2068 | { |
| 1898 | | result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, usage, format, pool, &texture->d3dtex); |
| 2069 | result = (*d3dintf->device.create_texture)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, 1, usage, format, pool, &m_d3dtex); |
| 1899 | 2070 | if (result == D3D_OK) |
| 1900 | 2071 | { |
| 1901 | | texture->d3dfinaltex = texture->d3dtex; |
| 1902 | | texture->type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN; |
| 2072 | m_d3dfinaltex = m_d3dtex; |
| 2073 | m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN; |
| 1903 | 2074 | |
| 1904 | | if (d3d->hlsl->enabled() && !d3d->hlsl->register_texture(texture)) |
| 2075 | if (m_renderer->get_shaders()->enabled() && !m_renderer->get_shaders()->register_texture(this)) |
| 1905 | 2076 | { |
| 1906 | 2077 | goto error; |
| 1907 | 2078 | } |
| r22936 | r22937 | |
| 1913 | 2084 | // screen textures with prescaling require two allocations |
| 1914 | 2085 | else |
| 1915 | 2086 | { |
| 1916 | | int scwidth, scheight; |
| 1917 | | D3DFORMAT finalfmt; |
| 1918 | | |
| 1919 | 2087 | // use an offscreen plain surface for stretching if supported |
| 1920 | 2088 | // (won't work for YUY textures) |
| 1921 | | if (d3d->stretch_supported && PRIMFLAG_GET_TEXFORMAT(flags) != TEXFORMAT_YUY16) |
| 2089 | if (m_texture_manager->is_stretch_supported() && PRIMFLAG_GET_TEXFORMAT(flags) != TEXFORMAT_YUY16) |
| 1922 | 2090 | { |
| 1923 | | result = (*d3dintf->device.create_offscreen_plain_surface)(d3d->device, texture->rawwidth, texture->rawheight, format, D3DPOOL_DEFAULT, &texture->d3dsurface); |
| 2091 | result = (*d3dintf->device.create_offscreen_plain_surface)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, format, D3DPOOL_DEFAULT, &m_d3dsurface); |
| 1924 | 2092 | if (result != D3D_OK) |
| 2093 | { |
| 1925 | 2094 | continue; |
| 1926 | | texture->type = TEXTURE_TYPE_SURFACE; |
| 2095 | } |
| 2096 | m_type = TEXTURE_TYPE_SURFACE; |
| 1927 | 2097 | } |
| 1928 | 2098 | |
| 1929 | 2099 | // otherwise, we allocate a dynamic texture for the source |
| 1930 | 2100 | else |
| 1931 | 2101 | { |
| 1932 | | result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, usage, format, pool, &texture->d3dtex); |
| 2102 | result = (*d3dintf->device.create_texture)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, 1, usage, format, pool, &m_d3dtex); |
| 1933 | 2103 | if (result != D3D_OK) |
| 2104 | { |
| 1934 | 2105 | continue; |
| 1935 | | texture->type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN; |
| 2106 | } |
| 2107 | m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN; |
| 1936 | 2108 | } |
| 1937 | 2109 | |
| 1938 | 2110 | // for the target surface, we allocate a render target texture |
| 1939 | | scwidth = texture->rawwidth * texture->xprescale; |
| 1940 | | scheight = texture->rawheight * texture->yprescale; |
| 2111 | int scwidth = m_rawdims.c.x * m_xprescale; |
| 2112 | int scheight = m_rawdims.c.y * m_yprescale; |
| 1941 | 2113 | |
| 1942 | 2114 | // target surfaces typically cannot be YCbCr, so we always pick RGB in that case |
| 1943 | | finalfmt = (format != d3d->yuv_format) ? format : D3DFMT_A8R8G8B8; |
| 1944 | | result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &texture->d3dfinaltex); |
| 2115 | D3DFORMAT finalfmt = (format != m_texture_manager->get_yuv_format()) ? format : D3DFMT_A8R8G8B8; |
| 2116 | result = (*d3dintf->device.create_texture)(m_renderer->get_device(), scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &m_d3dfinaltex); |
| 1945 | 2117 | if (result == D3D_OK) |
| 1946 | 2118 | { |
| 1947 | | if (d3d->hlsl->enabled() && !d3d->hlsl->register_prescaled_texture(texture)) |
| 2119 | if (m_renderer->get_shaders()->enabled() && !m_renderer->get_shaders()->register_prescaled_texture(this)) |
| 1948 | 2120 | { |
| 1949 | 2121 | goto error; |
| 1950 | 2122 | } |
| 1951 | 2123 | break; |
| 1952 | 2124 | } |
| 1953 | | (*d3dintf->texture.release)(texture->d3dtex); |
| 1954 | | texture->d3dtex = NULL; |
| 2125 | (*d3dintf->texture.release)(m_d3dtex); |
| 2126 | m_d3dtex = NULL; |
| 1955 | 2127 | } |
| 1956 | 2128 | } |
| 1957 | 2129 | } |
| 1958 | 2130 | |
| 1959 | 2131 | // copy the data to the texture |
| 1960 | | texture_set_data(d3d, texture, texsource, flags); |
| 2132 | set_data(texsource, flags); |
| 1961 | 2133 | |
| 2134 | //texsource->osdhandle = (void*)this; |
| 1962 | 2135 | // add us to the texture list |
| 1963 | | if(d3d->texlist != NULL) |
| 1964 | | d3d->texlist->prev = texture; |
| 1965 | | texture->prev = NULL; |
| 1966 | | texture->next = d3d->texlist; |
| 1967 | | d3d->texlist = texture; |
| 1968 | | return texture; |
| 2136 | if(m_texture_manager->get_texlist() != NULL) |
| 2137 | m_texture_manager->get_texlist()->m_prev = this; |
| 2138 | m_prev = NULL; |
| 2139 | m_next = m_texture_manager->get_texlist(); |
| 2140 | m_texture_manager->set_texlist(this); |
| 2141 | return; |
| 1969 | 2142 | |
| 1970 | 2143 | error: |
| 1971 | 2144 | d3dintf->post_fx_available = false; |
| 1972 | 2145 | printf("Direct3D: Critical warning: A texture failed to allocate. Expect things to get bad quickly.\n"); |
| 1973 | | if (texture->d3dsurface != NULL) |
| 1974 | | (*d3dintf->surface.release)(texture->d3dsurface); |
| 1975 | | if (texture->d3dtex != NULL) |
| 1976 | | (*d3dintf->texture.release)(texture->d3dtex); |
| 1977 | | global_free(texture); |
| 1978 | | return NULL; |
| 2146 | if (m_d3dsurface != NULL) |
| 2147 | (*d3dintf->surface.release)(m_d3dsurface); |
| 2148 | if (m_d3dtex != NULL) |
| 2149 | (*d3dintf->texture.release)(m_d3dtex); |
| 1979 | 2150 | } |
| 1980 | 2151 | |
| 1981 | 2152 | |
| 1982 | 2153 | |
| 1983 | 2154 | //============================================================ |
| 1984 | | // texture_compute_size |
| 2155 | // texture_info::compute_size |
| 1985 | 2156 | //============================================================ |
| 1986 | 2157 | |
| 1987 | | static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d_texture_info *texture) |
| 2158 | void texture_info::compute_size(int texwidth, int texheight) |
| 1988 | 2159 | { |
| 1989 | 2160 | int finalheight = texheight; |
| 1990 | 2161 | int finalwidth = texwidth; |
| 1991 | 2162 | |
| 1992 | 2163 | // if we're not wrapping, add a 1-2 pixel border on all sides |
| 1993 | | texture->xborderpix = 0; |
| 1994 | | texture->yborderpix = 0; |
| 1995 | | if (ENABLE_BORDER_PIX && !(texture->flags & PRIMFLAG_TEXWRAP_MASK)) |
| 2164 | m_xborderpix = 0; |
| 2165 | m_yborderpix = 0; |
| 2166 | if (ENABLE_BORDER_PIX && !(m_flags & PRIMFLAG_TEXWRAP_MASK)) |
| 1996 | 2167 | { |
| 1997 | 2168 | // note we need 2 pixels in X for YUY textures |
| 1998 | | texture->xborderpix = (PRIMFLAG_GET_TEXFORMAT(texture->flags) == TEXFORMAT_YUY16) ? 2 : 1; |
| 1999 | | texture->yborderpix = 1; |
| 2169 | m_xborderpix = (PRIMFLAG_GET_TEXFORMAT(m_flags) == TEXFORMAT_YUY16) ? 2 : 1; |
| 2170 | m_yborderpix = 1; |
| 2000 | 2171 | } |
| 2001 | 2172 | |
| 2002 | 2173 | // compute final texture size |
| 2003 | | finalwidth += 2 * texture->xborderpix; |
| 2004 | | finalheight += 2 * texture->yborderpix; |
| 2174 | finalwidth += 2 * m_xborderpix; |
| 2175 | finalheight += 2 * m_yborderpix; |
| 2005 | 2176 | |
| 2006 | 2177 | // round width/height up to nearest power of 2 if we need to |
| 2007 | | if (!(d3d->texture_caps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)) |
| 2178 | if (!(m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)) |
| 2008 | 2179 | { |
| 2009 | 2180 | // first the width |
| 2010 | 2181 | if (finalwidth & (finalwidth - 1)) |
| r22936 | r22937 | |
| 2028 | 2199 | } |
| 2029 | 2200 | |
| 2030 | 2201 | // round up to square if we need to |
| 2031 | | if (d3d->texture_caps & D3DPTEXTURECAPS_SQUAREONLY) |
| 2202 | if (m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_SQUAREONLY) |
| 2032 | 2203 | { |
| 2033 | 2204 | if (finalwidth < finalheight) |
| 2034 | 2205 | finalwidth = finalheight; |
| r22936 | r22937 | |
| 2037 | 2208 | } |
| 2038 | 2209 | |
| 2039 | 2210 | // adjust the aspect ratio if we need to |
| 2040 | | while (finalwidth < finalheight && finalheight / finalwidth > d3d->texture_max_aspect) |
| 2211 | while (finalwidth < finalheight && finalheight / finalwidth > m_texture_manager->get_max_texture_aspect()) |
| 2212 | { |
| 2041 | 2213 | finalwidth *= 2; |
| 2042 | | while (finalheight < finalwidth && finalwidth / finalheight > d3d->texture_max_aspect) |
| 2214 | } |
| 2215 | while (finalheight < finalwidth && finalwidth / finalheight > m_texture_manager->get_max_texture_aspect()) |
| 2216 | { |
| 2043 | 2217 | finalheight *= 2; |
| 2218 | } |
| 2044 | 2219 | |
| 2045 | 2220 | // if we added pixels for the border, and that just barely pushed us over, take it back |
| 2046 | | if ((finalwidth > d3d->texture_max_width && finalwidth - 2 * texture->xborderpix <= d3d->texture_max_width) || |
| 2047 | | (finalheight > d3d->texture_max_height && finalheight - 2 * texture->yborderpix <= d3d->texture_max_height)) |
| 2221 | if ((finalwidth > m_texture_manager->get_max_texture_width() && finalwidth - 2 * m_xborderpix <= m_texture_manager->get_max_texture_width()) || |
| 2222 | (finalheight > m_texture_manager->get_max_texture_height() && finalheight - 2 * m_yborderpix <= m_texture_manager->get_max_texture_height())) |
| 2048 | 2223 | { |
| 2049 | | finalwidth -= 2 * texture->xborderpix; |
| 2050 | | finalheight -= 2 * texture->yborderpix; |
| 2051 | | texture->xborderpix = 0; |
| 2052 | | texture->yborderpix = 0; |
| 2224 | finalwidth -= 2 * m_xborderpix; |
| 2225 | finalheight -= 2 * m_yborderpix; |
| 2226 | m_xborderpix = 0; |
| 2227 | m_yborderpix = 0; |
| 2053 | 2228 | } |
| 2054 | 2229 | |
| 2055 | 2230 | // if we're above the max width/height, do what? |
| 2056 | | if (finalwidth > d3d->texture_max_width || finalheight > d3d->texture_max_height) |
| 2231 | if (finalwidth > m_texture_manager->get_max_texture_width() || finalheight > m_texture_manager->get_max_texture_height()) |
| 2057 | 2232 | { |
| 2058 | 2233 | static int printed = FALSE; |
| 2059 | | if (!printed) mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth, finalheight, (int)d3d->texture_max_width, (int)d3d->texture_max_height); |
| 2234 | if (!printed) mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth, finalheight, (int)m_texture_manager->get_max_texture_width(), (int)m_texture_manager->get_max_texture_height()); |
| 2060 | 2235 | printed = TRUE; |
| 2061 | 2236 | } |
| 2062 | 2237 | |
| 2063 | 2238 | // compute the U/V scale factors |
| 2064 | | texture->ustart = (float)texture->xborderpix / (float)finalwidth; |
| 2065 | | texture->ustop = (float)(texwidth + texture->xborderpix) / (float)finalwidth; |
| 2066 | | texture->vstart = (float)texture->yborderpix / (float)finalheight; |
| 2067 | | texture->vstop = (float)(texheight + texture->yborderpix) / (float)finalheight; |
| 2239 | m_start.c.x = (float)m_xborderpix / (float)finalwidth; |
| 2240 | m_start.c.y = (float)m_yborderpix / (float)finalheight; |
| 2241 | m_stop.c.x = (float)(texwidth + m_xborderpix) / (float)finalwidth; |
| 2242 | m_stop.c.y = (float)(texheight + m_yborderpix) / (float)finalheight; |
| 2068 | 2243 | |
| 2069 | 2244 | // set the final values |
| 2070 | | texture->rawwidth = finalwidth; |
| 2071 | | texture->rawheight = finalheight; |
| 2245 | m_rawdims.c.x = finalwidth; |
| 2246 | m_rawdims.c.y = finalheight; |
| 2072 | 2247 | } |
| 2073 | 2248 | |
| 2074 | 2249 | |
| r22936 | r22937 | |
| 2411 | 2586 | // texture_set_data |
| 2412 | 2587 | //============================================================ |
| 2413 | 2588 | |
| 2414 | | static void texture_set_data(d3d_info *d3d, d3d_texture_info *texture, const render_texinfo *texsource, UINT32 flags) |
| 2589 | void texture_info::set_data(const render_texinfo *texsource, UINT32 flags) |
| 2415 | 2590 | { |
| 2416 | 2591 | D3DLOCKED_RECT rect; |
| 2417 | 2592 | HRESULT result; |
| 2418 | | int miny, maxy; |
| 2419 | | int dsty; |
| 2420 | 2593 | |
| 2421 | 2594 | // lock the texture |
| 2422 | | switch (texture->type) |
| 2595 | switch (m_type) |
| 2423 | 2596 | { |
| 2424 | 2597 | default: |
| 2425 | | case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.lock_rect)(texture->d3dtex, 0, &rect, NULL, 0); break; |
| 2426 | | case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.lock_rect)(texture->d3dtex, 0, &rect, NULL, D3DLOCK_DISCARD); break; |
| 2427 | | case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.lock_rect)(texture->d3dsurface, &rect, NULL, D3DLOCK_DISCARD); break; |
| 2598 | case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.lock_rect)(m_d3dtex, 0, &rect, NULL, 0); break; |
| 2599 | case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.lock_rect)(m_d3dtex, 0, &rect, NULL, D3DLOCK_DISCARD); break; |
| 2600 | case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.lock_rect)(m_d3dsurface, &rect, NULL, D3DLOCK_DISCARD); break; |
| 2428 | 2601 | } |
| 2429 | 2602 | if (result != D3D_OK) |
| 2603 | { |
| 2430 | 2604 | return; |
| 2605 | } |
| 2431 | 2606 | |
| 2432 | 2607 | // loop over Y |
| 2433 | | miny = 0 - texture->yborderpix; |
| 2434 | | maxy = texsource->height + texture->yborderpix; |
| 2435 | | for (dsty = miny; dsty < maxy; dsty++) |
| 2608 | int miny = 0 - m_yborderpix; |
| 2609 | int maxy = texsource->height + m_yborderpix; |
| 2610 | for (int dsty = miny; dsty < maxy; dsty++) |
| 2436 | 2611 | { |
| 2437 | 2612 | int srcy = (dsty < 0) ? 0 : (dsty >= texsource->height) ? texsource->height - 1 : dsty; |
| 2438 | | void *dst = (BYTE *)rect.pBits + (dsty + texture->yborderpix) * rect.Pitch; |
| 2613 | void *dst = (BYTE *)rect.pBits + (dsty + m_yborderpix) * rect.Pitch; |
| 2439 | 2614 | |
| 2440 | 2615 | // switch off of the format and |
| 2441 | 2616 | switch (PRIMFLAG_GET_TEXFORMAT(flags)) |
| 2442 | 2617 | { |
| 2443 | 2618 | case TEXFORMAT_PALETTE16: |
| 2444 | | copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix); |
| 2619 | copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2445 | 2620 | break; |
| 2446 | 2621 | |
| 2447 | 2622 | case TEXFORMAT_PALETTEA16: |
| 2448 | | copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix); |
| 2623 | copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2449 | 2624 | break; |
| 2450 | 2625 | |
| 2451 | 2626 | case TEXFORMAT_RGB32: |
| 2452 | | copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix); |
| 2627 | copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2453 | 2628 | break; |
| 2454 | 2629 | |
| 2455 | 2630 | case TEXFORMAT_ARGB32: |
| 2456 | | copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix); |
| 2631 | copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2457 | 2632 | break; |
| 2458 | 2633 | |
| 2459 | 2634 | case TEXFORMAT_YUY16: |
| 2460 | | if (d3d->yuv_format == D3DFMT_YUY2) |
| 2461 | | copyline_yuy16_to_yuy2((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix); |
| 2462 | | else if (d3d->yuv_format == D3DFMT_UYVY) |
| 2463 | | copyline_yuy16_to_uyvy((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix); |
| 2635 | if (m_texture_manager->get_yuv_format() == D3DFMT_YUY2) |
| 2636 | copyline_yuy16_to_yuy2((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2637 | else if (m_texture_manager->get_yuv_format() == D3DFMT_UYVY) |
| 2638 | copyline_yuy16_to_uyvy((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2464 | 2639 | else |
| 2465 | | copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix); |
| 2640 | copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); |
| 2466 | 2641 | break; |
| 2467 | 2642 | |
| 2468 | 2643 | default: |
| r22936 | r22937 | |
| 2472 | 2647 | } |
| 2473 | 2648 | |
| 2474 | 2649 | // unlock |
| 2475 | | switch (texture->type) |
| 2650 | switch (m_type) |
| 2476 | 2651 | { |
| 2477 | 2652 | default: |
| 2478 | | case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.unlock_rect)(texture->d3dtex, 0); break; |
| 2479 | | case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.unlock_rect)(texture->d3dtex, 0); break; |
| 2480 | | case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.unlock_rect)(texture->d3dsurface); break; |
| 2653 | case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.unlock_rect)(m_d3dtex, 0); break; |
| 2654 | case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.unlock_rect)(m_d3dtex, 0); break; |
| 2655 | case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.unlock_rect)(m_d3dsurface); break; |
| 2481 | 2656 | } |
| 2482 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result); |
| 2657 | if (result != D3D_OK) |
| 2658 | { |
| 2659 | mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result); |
| 2660 | } |
| 2483 | 2661 | |
| 2484 | 2662 | // prescale |
| 2485 | | texture_prescale(d3d, texture); |
| 2663 | prescale(); |
| 2486 | 2664 | } |
| 2487 | 2665 | |
| 2488 | 2666 | |
| 2489 | 2667 | |
| 2490 | 2668 | //============================================================ |
| 2491 | | // texture_prescale |
| 2669 | // texture_info::prescale |
| 2492 | 2670 | //============================================================ |
| 2493 | 2671 | |
| 2494 | | static void texture_prescale(d3d_info *d3d, d3d_texture_info *texture) |
| 2672 | void texture_info::prescale() |
| 2495 | 2673 | { |
| 2496 | | d3d_surface *surface; |
| 2674 | surface *scale_surface; |
| 2497 | 2675 | HRESULT result; |
| 2498 | 2676 | int i; |
| 2499 | 2677 | |
| 2500 | 2678 | // if we don't need to, just skip it |
| 2501 | | if (texture->d3dtex == texture->d3dfinaltex) |
| 2679 | if (m_d3dtex == m_d3dfinaltex) |
| 2502 | 2680 | return; |
| 2503 | 2681 | |
| 2504 | 2682 | // for all cases, we need to get the surface of the render target |
| 2505 | | result = (*d3dintf->texture.get_surface_level)(texture->d3dfinaltex, 0, &surface); |
| 2683 | result = (*d3dintf->texture.get_surface_level)(m_d3dfinaltex, 0, &scale_surface); |
| 2506 | 2684 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture get_surface_level call\n", (int)result); |
| 2507 | 2685 | |
| 2508 | 2686 | // if we have an offscreen plain surface, we can just StretchRect to it |
| 2509 | | if (texture->type == TEXTURE_TYPE_SURFACE) |
| 2687 | if (m_type == TEXTURE_TYPE_SURFACE) |
| 2510 | 2688 | { |
| 2511 | | RECT source, dest; |
| 2689 | assert(m_d3dsurface != NULL); |
| 2512 | 2690 | |
| 2513 | | assert(texture->d3dsurface != NULL); |
| 2514 | | |
| 2515 | 2691 | // set the source bounds |
| 2692 | RECT source; |
| 2516 | 2693 | source.left = source.top = 0; |
| 2517 | | source.right = texture->texinfo.width + 2 * texture->xborderpix; |
| 2518 | | source.bottom = texture->texinfo.height + 2 * texture->yborderpix; |
| 2694 | source.right = m_texinfo.width + 2 * m_xborderpix; |
| 2695 | source.bottom = m_texinfo.height + 2 * m_yborderpix; |
| 2519 | 2696 | |
| 2520 | 2697 | // set the target bounds |
| 2698 | RECT dest; |
| 2521 | 2699 | dest = source; |
| 2522 | | dest.right *= texture->xprescale; |
| 2523 | | dest.bottom *= texture->yprescale; |
| 2700 | dest.right *= m_xprescale; |
| 2701 | dest.bottom *= m_yprescale; |
| 2524 | 2702 | |
| 2525 | 2703 | // do the stretchrect |
| 2526 | | result = (*d3dintf->device.stretch_rect)(d3d->device, texture->d3dsurface, &source, surface, &dest, D3DTEXF_POINT); |
| 2704 | result = (*d3dintf->device.stretch_rect)(m_renderer->get_device(), m_d3dsurface, &source, scale_surface, &dest, D3DTEXF_POINT); |
| 2527 | 2705 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device stretct_rect call\n", (int)result); |
| 2528 | 2706 | } |
| 2529 | 2707 | |
| 2530 | 2708 | // if we are using a texture render target, we need to do more preparations |
| 2531 | 2709 | else |
| 2532 | 2710 | { |
| 2533 | | d3d_surface *backbuffer; |
| 2711 | surface *backbuffer; |
| 2534 | 2712 | |
| 2535 | | assert(texture->d3dtex != NULL); |
| 2713 | assert(m_d3dtex != NULL); |
| 2536 | 2714 | |
| 2537 | 2715 | // first remember the original render target and set the new one |
| 2538 | | result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer); |
| 2716 | result = (*d3dintf->device.get_render_target)(m_renderer->get_device(), 0, &backbuffer); |
| 2539 | 2717 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 2540 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, surface); |
| 2718 | result = (*d3dintf->device.set_render_target)(m_renderer->get_device(), 0, scale_surface); |
| 2541 | 2719 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 1\n", (int)result); |
| 2542 | | reset_render_states(d3d); |
| 2720 | m_renderer->reset_render_states(); |
| 2543 | 2721 | |
| 2544 | 2722 | // start the scene |
| 2545 | | result = (*d3dintf->device.begin_scene)(d3d->device); |
| 2723 | result = (*d3dintf->device.begin_scene)(m_renderer->get_device()); |
| 2546 | 2724 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device begin_scene call\n", (int)result); |
| 2547 | 2725 | |
| 2548 | 2726 | // configure the rendering pipeline |
| 2549 | | set_filter(d3d, FALSE); |
| 2550 | | set_blendmode(d3d, BLENDMODE_NONE); |
| 2551 | | result = (*d3dintf->device.set_texture)(d3d->device, 0, texture->d3dtex); |
| 2727 | m_renderer->set_filter(FALSE); |
| 2728 | m_renderer->set_blendmode(BLENDMODE_NONE); |
| 2729 | result = (*d3dintf->device.set_texture)(m_renderer->get_device(), 0, m_d3dtex); |
| 2552 | 2730 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result); |
| 2553 | 2731 | |
| 2554 | 2732 | // lock the vertex buffer |
| 2555 | | result = (*d3dintf->vertexbuf.lock)(d3d->vertexbuf, 0, 0, (VOID **)&d3d->lockedbuf, D3DLOCK_DISCARD); |
| 2733 | result = (*d3dintf->vertexbuf.lock)(m_renderer->get_vertex_buffer(), 0, 0, m_renderer->get_locked_buffer_ptr(), D3DLOCK_DISCARD); |
| 2556 | 2734 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during vertex buffer lock call\n", (int)result); |
| 2557 | 2735 | |
| 2558 | 2736 | // configure the X/Y coordinates on the target surface |
| 2559 | | d3d->lockedbuf[0].x = -0.5f; |
| 2560 | | d3d->lockedbuf[0].y = -0.5f; |
| 2561 | | d3d->lockedbuf[1].x = (float)((texture->texinfo.width + 2 * texture->xborderpix) * texture->xprescale) - 0.5f; |
| 2562 | | d3d->lockedbuf[1].y = -0.5f; |
| 2563 | | d3d->lockedbuf[2].x = -0.5f; |
| 2564 | | d3d->lockedbuf[2].y = (float)((texture->texinfo.height + 2 * texture->yborderpix) * texture->yprescale) - 0.5f; |
| 2565 | | d3d->lockedbuf[3].x = (float)((texture->texinfo.width + 2 * texture->xborderpix) * texture->xprescale) - 0.5f; |
| 2566 | | d3d->lockedbuf[3].y = (float)((texture->texinfo.height + 2 * texture->yborderpix) * texture->yprescale) - 0.5f; |
| 2737 | vertex *lockedbuf = m_renderer->get_locked_buffer(); |
| 2738 | lockedbuf[0].x = -0.5f; |
| 2739 | lockedbuf[0].y = -0.5f; |
| 2740 | lockedbuf[1].x = (float)((m_texinfo.width + 2 * m_xborderpix) * m_xprescale) - 0.5f; |
| 2741 | lockedbuf[1].y = -0.5f; |
| 2742 | lockedbuf[2].x = -0.5f; |
| 2743 | lockedbuf[2].y = (float)((m_texinfo.height + 2 * m_yborderpix) * m_yprescale) - 0.5f; |
| 2744 | lockedbuf[3].x = (float)((m_texinfo.width + 2 * m_xborderpix) * m_xprescale) - 0.5f; |
| 2745 | lockedbuf[3].y = (float)((m_texinfo.height + 2 * m_yborderpix) * m_yprescale) - 0.5f; |
| 2567 | 2746 | |
| 2568 | 2747 | // configure the U/V coordintes on the source texture |
| 2569 | | d3d->lockedbuf[0].u0 = 0.0f; |
| 2570 | | d3d->lockedbuf[0].v0 = 0.0f; |
| 2571 | | d3d->lockedbuf[1].u0 = (float)(texture->texinfo.width + 2 * texture->xborderpix) / (float)texture->rawwidth; |
| 2572 | | d3d->lockedbuf[1].v0 = 0.0f; |
| 2573 | | d3d->lockedbuf[2].u0 = 0.0f; |
| 2574 | | d3d->lockedbuf[2].v0 = (float)(texture->texinfo.height + 2 * texture->yborderpix) / (float)texture->rawheight; |
| 2575 | | d3d->lockedbuf[3].u0 = (float)(texture->texinfo.width + 2 * texture->xborderpix) / (float)texture->rawwidth; |
| 2576 | | d3d->lockedbuf[3].v0 = (float)(texture->texinfo.height + 2 * texture->yborderpix) / (float)texture->rawheight; |
| 2748 | lockedbuf[0].u0 = 0.0f; |
| 2749 | lockedbuf[0].v0 = 0.0f; |
| 2750 | lockedbuf[1].u0 = (float)(m_texinfo.width + 2 * m_xborderpix) / (float)m_rawdims.c.x; |
| 2751 | lockedbuf[1].v0 = 0.0f; |
| 2752 | lockedbuf[2].u0 = 0.0f; |
| 2753 | lockedbuf[2].v0 = (float)(m_texinfo.height + 2 * m_yborderpix) / (float)m_rawdims.c.y; |
| 2754 | lockedbuf[3].u0 = (float)(m_texinfo.width + 2 * m_xborderpix) / (float)m_rawdims.c.x; |
| 2755 | lockedbuf[3].v0 = (float)(m_texinfo.height + 2 * m_yborderpix) / (float)m_rawdims.c.y; |
| 2577 | 2756 | |
| 2578 | 2757 | // reset the remaining vertex parameters |
| 2579 | 2758 | for (i = 0; i < 4; i++) |
| 2580 | 2759 | { |
| 2581 | | d3d->lockedbuf[i].z = 0.0f; |
| 2582 | | d3d->lockedbuf[i].rhw = 1.0f; |
| 2583 | | d3d->lockedbuf[i].color = D3DCOLOR_ARGB(0xff,0xff,0xff,0xff); |
| 2760 | lockedbuf[i].z = 0.0f; |
| 2761 | lockedbuf[i].rhw = 1.0f; |
| 2762 | lockedbuf[i].color = D3DCOLOR_ARGB(0xff,0xff,0xff,0xff); |
| 2584 | 2763 | } |
| 2585 | 2764 | |
| 2586 | 2765 | // unlock the vertex buffer |
| 2587 | | result = (*d3dintf->vertexbuf.unlock)(d3d->vertexbuf); |
| 2766 | result = (*d3dintf->vertexbuf.unlock)(m_renderer->get_vertex_buffer()); |
| 2588 | 2767 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during vertex buffer unlock call\n", (int)result); |
| 2589 | | d3d->lockedbuf = NULL; |
| 2768 | m_renderer->set_locked_buffer(NULL); |
| 2590 | 2769 | |
| 2591 | 2770 | // set the stream and draw the triangle strip |
| 2592 | | result = (*d3dintf->device.set_stream_source)(d3d->device, 0, d3d->vertexbuf, sizeof(d3d_vertex)); |
| 2771 | result = (*d3dintf->device.set_stream_source)(m_renderer->get_device(), 0, m_renderer->get_vertex_buffer(), sizeof(vertex)); |
| 2593 | 2772 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_stream_source call\n", (int)result); |
| 2594 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLESTRIP, 0, 2); |
| 2773 | result = (*d3dintf->device.draw_primitive)(m_renderer->get_device(), D3DPT_TRIANGLESTRIP, 0, 2); |
| 2595 | 2774 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2596 | 2775 | |
| 2597 | 2776 | // end the scene |
| 2598 | | result = (*d3dintf->device.end_scene)(d3d->device); |
| 2777 | result = (*d3dintf->device.end_scene)(m_renderer->get_device()); |
| 2599 | 2778 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device end_scene call\n", (int)result); |
| 2600 | 2779 | |
| 2601 | 2780 | // reset the render target and release our reference to the backbuffer |
| 2602 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 2781 | result = (*d3dintf->device.set_render_target)(m_renderer->get_device(), 0, backbuffer); |
| 2603 | 2782 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 2\n", (int)result); |
| 2604 | 2783 | (*d3dintf->surface.release)(backbuffer); |
| 2605 | | reset_render_states(d3d); |
| 2784 | m_renderer->reset_render_states(); |
| 2606 | 2785 | } |
| 2607 | 2786 | |
| 2608 | 2787 | // release our reference to the target surface |
| 2609 | | (*d3dintf->surface.release)(surface); |
| 2788 | (*d3dintf->surface.release)(scale_surface); |
| 2610 | 2789 | } |
| 2611 | 2790 | |
| 2612 | 2791 | |
| 2613 | | |
| 2614 | 2792 | //============================================================ |
| 2615 | | // texture_find |
| 2793 | // cache_target::~cache_target |
| 2616 | 2794 | //============================================================ |
| 2617 | 2795 | |
| 2618 | | static d3d_texture_info *texture_find(d3d_info *d3d, const render_primitive *prim) |
| 2796 | cache_target::~cache_target() |
| 2619 | 2797 | { |
| 2620 | | UINT32 texhash = texture_compute_hash(&prim->texture, prim->flags); |
| 2621 | | d3d_texture_info *texture; |
| 2622 | | |
| 2623 | | // find a match |
| 2624 | | for (texture = d3d->texlist; texture != NULL; texture = texture->next) |
| 2625 | | { |
| 2626 | | UINT32 test_screen = (UINT32)texture->texinfo.osddata >> 1; |
| 2627 | | UINT32 test_page = (UINT32)texture->texinfo.osddata & 1; |
| 2628 | | UINT32 prim_screen = (UINT32)prim->texture.osddata >> 1; |
| 2629 | | UINT32 prim_page = (UINT32)prim->texture.osddata & 1; |
| 2630 | | if (test_screen != prim_screen || test_page != prim_page) |
| 2631 | | { |
| 2632 | | continue; |
| 2633 | | } |
| 2634 | | |
| 2635 | | if (texture->hash == texhash && |
| 2636 | | texture->texinfo.base == prim->texture.base && |
| 2637 | | texture->texinfo.width == prim->texture.width && |
| 2638 | | texture->texinfo.height == prim->texture.height && |
| 2639 | | ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0) |
| 2640 | | { |
| 2641 | | // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache |
| 2642 | | if (d3d->hlsl->enabled() && prim->texture.width != 0 && prim->texture.height != 0 && (prim->flags & PRIMFLAG_SCREENTEX_MASK) != 0) |
| 2643 | | { |
| 2644 | | if (d3d->hlsl->find_render_target(texture) != NULL) |
| 2645 | | { |
| 2646 | | return texture; |
| 2647 | | } |
| 2648 | | } |
| 2649 | | else |
| 2650 | | { |
| 2651 | | return texture; |
| 2652 | | } |
| 2653 | | } |
| 2654 | | } |
| 2655 | | |
| 2656 | | // nothing found, check if we need to unregister something with hlsl |
| 2657 | | if (d3d->hlsl->enabled()) |
| 2658 | | { |
| 2659 | | if (prim->texture.width == 0 || prim->texture.height == 0) |
| 2660 | | { |
| 2661 | | return NULL; |
| 2662 | | } |
| 2663 | | |
| 2664 | | UINT32 prim_screen = (UINT32)prim->texture.osddata >> 1; |
| 2665 | | UINT32 prim_page = (UINT32)prim->texture.osddata & 1; |
| 2666 | | |
| 2667 | | for (texture = d3d->texlist; texture != NULL; texture = texture->next) |
| 2668 | | { |
| 2669 | | UINT32 test_screen = (UINT32)texture->texinfo.osddata >> 1; |
| 2670 | | UINT32 test_page = (UINT32)texture->texinfo.osddata & 1; |
| 2671 | | if (test_screen != prim_screen || test_page != prim_page) |
| 2672 | | { |
| 2673 | | continue; |
| 2674 | | } |
| 2675 | | |
| 2676 | | // Clear our old texture reference |
| 2677 | | if (texture->hash == texhash && |
| 2678 | | texture->texinfo.base == prim->texture.base && |
| 2679 | | ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0 && |
| 2680 | | (texture->texinfo.width != prim->texture.width || |
| 2681 | | texture->texinfo.height != prim->texture.height)) |
| 2682 | | { |
| 2683 | | d3d->hlsl->remove_render_target(texture); |
| 2684 | | break; |
| 2685 | | } |
| 2686 | | } |
| 2687 | | } |
| 2688 | | return NULL; |
| 2689 | | } |
| 2690 | | |
| 2691 | | |
| 2692 | | //============================================================ |
| 2693 | | // texture_update |
| 2694 | | //============================================================ |
| 2695 | | |
| 2696 | | static void texture_update(d3d_info *d3d, const render_primitive *prim) |
| 2697 | | { |
| 2698 | | d3d_texture_info *texture = texture_find(d3d, prim); |
| 2699 | | |
| 2700 | | // if we didn't find one, create a new texture |
| 2701 | | if (texture == NULL) |
| 2702 | | { |
| 2703 | | texture = texture_create(d3d, &prim->texture, prim->flags); |
| 2704 | | } |
| 2705 | | |
| 2706 | | // if we found it, but with a different seqid, copy the data |
| 2707 | | if (texture->texinfo.seqid != prim->texture.seqid) |
| 2708 | | { |
| 2709 | | texture_set_data(d3d, texture, &prim->texture, prim->flags); |
| 2710 | | texture->texinfo.seqid = prim->texture.seqid; |
| 2711 | | } |
| 2712 | | } |
| 2713 | | |
| 2714 | | |
| 2715 | | //============================================================ |
| 2716 | | // d3d_cache_target::~d3d_cache_target |
| 2717 | | //============================================================ |
| 2718 | | |
| 2719 | | d3d_cache_target::~d3d_cache_target() |
| 2720 | | { |
| 2721 | 2798 | for (int index = 0; index < 11; index++) |
| 2722 | 2799 | { |
| 2723 | 2800 | if (bloom_texture[index] != NULL) |
| r22936 | r22937 | |
| 2746 | 2823 | |
| 2747 | 2824 | |
| 2748 | 2825 | //============================================================ |
| 2749 | | // d3d_cache_target::init - initializes a target cache |
| 2826 | // cache_target::init - initializes a target cache |
| 2750 | 2827 | //============================================================ |
| 2751 | 2828 | |
| 2752 | | bool d3d_cache_target::init(d3d_info *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y, bool bloom) |
| 2829 | bool cache_target::init(renderer *d3d, base *d3dintf, int width, int height, int prescale_x, int prescale_y) |
| 2753 | 2830 | { |
| 2754 | | if (bloom) |
| 2831 | int bloom_size = (width * prescale_x < height * prescale_y) ? width * prescale_x : height * prescale_y; |
| 2832 | int bloom_index = 0; |
| 2833 | int bloom_width = width * prescale_x; |
| 2834 | int bloom_height = height * prescale_y; |
| 2835 | for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1) |
| 2755 | 2836 | { |
| 2756 | | int bloom_size = (width * prescale_x < height * prescale_y) ? width * prescale_x : height * prescale_y; |
| 2757 | | int bloom_index = 0; |
| 2758 | | int bloom_width = width * prescale_x; |
| 2759 | | int bloom_height = height * prescale_y; |
| 2760 | | for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1) |
| 2837 | bloom_width >>= 1; |
| 2838 | bloom_height >>= 1; |
| 2839 | HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]); |
| 2840 | if (result != D3D_OK) |
| 2761 | 2841 | { |
| 2762 | | bloom_width >>= 1; |
| 2763 | | bloom_height >>= 1; |
| 2764 | | HRESULT result = (*d3dintf->device.create_texture)(d3d->device, bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]); |
| 2765 | | if (result != D3D_OK) |
| 2766 | | { |
| 2767 | | return false; |
| 2768 | | } |
| 2769 | | (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]); |
| 2770 | | bloom_index++; |
| 2842 | return false; |
| 2771 | 2843 | } |
| 2844 | (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]); |
| 2845 | bloom_index++; |
| 2772 | 2846 | } |
| 2773 | 2847 | |
| 2774 | | HRESULT result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &last_texture); |
| 2848 | HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &last_texture); |
| 2775 | 2849 | if (result != D3D_OK) |
| 2776 | 2850 | return false; |
| 2777 | 2851 | (*d3dintf->texture.get_surface_level)(last_texture, 0, &last_target); |
| r22936 | r22937 | |
| 2783 | 2857 | } |
| 2784 | 2858 | |
| 2785 | 2859 | //============================================================ |
| 2786 | | // d3d_render_target::~d3d_render_target |
| 2860 | // render_target::~render_target |
| 2787 | 2861 | //============================================================ |
| 2788 | 2862 | |
| 2789 | | d3d_render_target::~d3d_render_target() |
| 2863 | render_target::~render_target() |
| 2790 | 2864 | { |
| 2791 | 2865 | for (int index = 0; index < 11; index++) |
| 2792 | 2866 | { |
| r22936 | r22937 | |
| 2804 | 2878 | |
| 2805 | 2879 | for (int index = 0; index < 5; index++) |
| 2806 | 2880 | { |
| 2807 | | if (texture[index] != NULL) |
| 2881 | if (render_texture[index] != NULL) |
| 2808 | 2882 | { |
| 2809 | | (*d3dintf->texture.release)(texture[index]); |
| 2810 | | texture[index] = NULL; |
| 2883 | (*d3dintf->texture.release)(render_texture[index]); |
| 2884 | render_texture[index] = NULL; |
| 2811 | 2885 | } |
| 2812 | 2886 | if (target[index] != NULL) |
| 2813 | 2887 | { |
| r22936 | r22937 | |
| 2841 | 2915 | |
| 2842 | 2916 | |
| 2843 | 2917 | //============================================================ |
| 2844 | | // d3d_render_target::init - initializes a render target |
| 2918 | // render_target::init - initializes a render target |
| 2845 | 2919 | //============================================================ |
| 2846 | 2920 | |
| 2847 | | bool d3d_render_target::init(d3d_info *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y, bool bloom) |
| 2921 | bool render_target::init(renderer *d3d, base *d3dintf, int width, int height, int prescale_x, int prescale_y) |
| 2848 | 2922 | { |
| 2849 | | D3DFORMAT format = bloom ? D3DFMT_A16B16G16R16F : D3DFMT_A8R8G8B8; |
| 2923 | D3DFORMAT format = D3DFMT_A8R8G8B8; |
| 2850 | 2924 | |
| 2851 | | HRESULT result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture[0]); |
| 2925 | HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &render_texture[0]); |
| 2852 | 2926 | if (result != D3D_OK) |
| 2853 | 2927 | return false; |
| 2854 | | (*d3dintf->texture.get_surface_level)(texture[0], 0, &target[0]); |
| 2928 | (*d3dintf->texture.get_surface_level)(render_texture[0], 0, &target[0]); |
| 2855 | 2929 | |
| 2856 | | result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture[1]); |
| 2930 | result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &render_texture[1]); |
| 2857 | 2931 | if (result != D3D_OK) |
| 2858 | 2932 | return false; |
| 2859 | | (*d3dintf->texture.get_surface_level)(texture[1], 0, &target[1]); |
| 2933 | (*d3dintf->texture.get_surface_level)(render_texture[1], 0, &target[1]); |
| 2860 | 2934 | |
| 2861 | | result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture[2]); |
| 2935 | result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &render_texture[2]); |
| 2862 | 2936 | if (result != D3D_OK) |
| 2863 | 2937 | return false; |
| 2864 | | (*d3dintf->texture.get_surface_level)(texture[2], 0, &target[2]); |
| 2938 | (*d3dintf->texture.get_surface_level)(render_texture[2], 0, &target[2]); |
| 2865 | 2939 | |
| 2866 | | if (!bloom) |
| 2867 | | { |
| 2868 | | result = (*d3dintf->device.create_texture)(d3d->device, width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture[3]); |
| 2869 | | if (result != D3D_OK) |
| 2870 | | return false; |
| 2871 | | (*d3dintf->texture.get_surface_level)(texture[3], 0, &target[3]); |
| 2940 | result = (*d3dintf->device.create_texture)(d3d->get_device(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &render_texture[3]); |
| 2941 | if (result != D3D_OK) |
| 2942 | return false; |
| 2943 | (*d3dintf->texture.get_surface_level)(render_texture[3], 0, &target[3]); |
| 2872 | 2944 | |
| 2873 | | result = (*d3dintf->device.create_texture)(d3d->device, width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture[4]); |
| 2874 | | if (result != D3D_OK) |
| 2875 | | return false; |
| 2876 | | (*d3dintf->texture.get_surface_level)(texture[4], 0, &target[4]); |
| 2945 | result = (*d3dintf->device.create_texture)(d3d->get_device(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &render_texture[4]); |
| 2946 | if (result != D3D_OK) |
| 2947 | return false; |
| 2948 | (*d3dintf->texture.get_surface_level)(render_texture[4], 0, &target[4]); |
| 2877 | 2949 | |
| 2878 | | result = (*d3dintf->device.create_texture)(d3d->device, width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &smalltexture); |
| 2879 | | if (result != D3D_OK) |
| 2880 | | return false; |
| 2881 | | (*d3dintf->texture.get_surface_level)(smalltexture, 0, &smalltarget); |
| 2950 | result = (*d3dintf->device.create_texture)(d3d->get_device(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &smalltexture); |
| 2951 | if (result != D3D_OK) |
| 2952 | return false; |
| 2953 | (*d3dintf->texture.get_surface_level)(smalltexture, 0, &smalltarget); |
| 2882 | 2954 | |
| 2883 | | result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &prescaletexture); |
| 2955 | result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &prescaletexture); |
| 2956 | if (result != D3D_OK) |
| 2957 | return false; |
| 2958 | (*d3dintf->texture.get_surface_level)(prescaletexture, 0, &prescaletarget); |
| 2959 | |
| 2960 | int bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height(); |
| 2961 | int bloom_index = 0; |
| 2962 | int bloom_width = d3d->get_width(); |
| 2963 | int bloom_height = d3d->get_height(); |
| 2964 | for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1) |
| 2965 | { |
| 2966 | bloom_width >>= 1; |
| 2967 | bloom_height >>= 1; |
| 2968 | result = (*d3dintf->device.create_texture)(d3d->get_device(), bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]); |
| 2884 | 2969 | if (result != D3D_OK) |
| 2885 | 2970 | return false; |
| 2886 | | (*d3dintf->texture.get_surface_level)(prescaletexture, 0, &prescaletarget); |
| 2887 | | |
| 2888 | | for (int index = 0; index < 11; index++) |
| 2889 | | { |
| 2890 | | bloom_texture[index] = NULL; |
| 2891 | | bloom_target[index] = NULL; |
| 2892 | | } |
| 2971 | (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]); |
| 2972 | bloom_index++; |
| 2893 | 2973 | } |
| 2894 | | else |
| 2895 | | { |
| 2896 | | int bloom_size = (width < height) ? width : height; |
| 2897 | | int bloom_index = 0; |
| 2898 | | int bloom_width = width; |
| 2899 | | int bloom_height = height; |
| 2900 | | for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1) |
| 2901 | | { |
| 2902 | | bloom_width >>= 1; |
| 2903 | | bloom_height >>= 1; |
| 2904 | | result = (*d3dintf->device.create_texture)(d3d->device, bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]); |
| 2905 | | if (result != D3D_OK) |
| 2906 | | return false; |
| 2907 | | (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]); |
| 2908 | | bloom_index++; |
| 2909 | | } |
| 2910 | | } |
| 2911 | 2974 | |
| 2912 | 2975 | target_width = width * prescale_x; |
| 2913 | 2976 | target_height = height * prescale_y; |
| 2914 | 2977 | |
| 2915 | 2978 | return true; |
| 2916 | 2979 | } |
| 2980 | |
| 2981 | }; |
| | No newline at end of file |
trunk/src/osd/windows/d3dhlsl.c
| r22936 | r22937 | |
| 83 | 83 | // GLOBALS |
| 84 | 84 | //============================================================ |
| 85 | 85 | |
| 86 | | static hlsl_options g_hlsl_presets[4] = |
| 86 | static slider_state *g_slider_list; |
| 87 | static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *templ, const char *extension, int idx); |
| 88 | |
| 89 | namespace d3d |
| 87 | 90 | { |
| 91 | |
| 92 | hlsl_options shaders::s_hlsl_presets[4] = |
| 93 | { |
| 88 | 94 | { // 25% Shadow mask, 50% Scanlines, 3% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation |
| 89 | 95 | true, |
| 90 | 96 | 0.25f, { "aperture.png" }, 320, 240, 0.09375f, 0.109375f, |
| r22936 | r22937 | |
| 104 | 110 | { 0.05f,0.05f,0.05f}, |
| 105 | 111 | { 0.25f,0.25f,0.25f}, |
| 106 | 112 | 1.2f, |
| 107 | | false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0 |
| 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.0f, 0.1f, 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 |
| 108 | 116 | }, |
| 109 | 117 | { // 25% Shadow mask, 0% Scanlines, 3% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation |
| 110 | 118 | true, |
| r22936 | r22937 | |
| 125 | 133 | { 0.05f,0.05f,0.05f}, |
| 126 | 134 | { 0.25f,0.25f,0.25f}, |
| 127 | 135 | 1.2f, |
| 128 | | false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0 |
| 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.0f, 0.1f, 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 |
| 129 | 139 | }, |
| 130 | 140 | { // 25% Shadow mask, 0% Scanlines, 0% Pincushion, 0 defocus, No Tint, 0.9 Exponent, 5% Floor, 25% Phosphor Return, 120% Saturation |
| 131 | 141 | true, |
| r22936 | r22937 | |
| 146 | 156 | { 0.05f,0.05f,0.05f}, |
| 147 | 157 | { 0.25f,0.25f,0.25f}, |
| 148 | 158 | 1.2f, |
| 149 | | false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0 |
| 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.0f, 0.1f, 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 |
| 150 | 162 | }, |
| 151 | 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 |
| 152 | 164 | true, |
| r22936 | r22937 | |
| 167 | 179 | { 0.05f,0.05f,0.05f}, |
| 168 | 180 | { 0.7f, 0.7f, 0.7f}, |
| 169 | 181 | 0.8f, |
| 170 | | false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0 |
| 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.0f, 0.1f, 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 |
| 171 | 185 | }, |
| 172 | 186 | }; |
| 173 | 187 | |
| 174 | | static slider_state *g_slider_list; |
| 175 | | |
| 176 | | |
| 177 | | |
| 178 | 188 | //============================================================ |
| 179 | 189 | // PROTOTYPES |
| 180 | 190 | //============================================================ |
| 181 | 191 | |
| 182 | 192 | static void get_vector(const char *data, int count, float *out, int report_error); |
| 183 | | static file_error open_next(d3d_info *d3d, emu_file &file, const char *templ, const char *extension, int idx); |
| 184 | 193 | |
| 185 | 194 | |
| 186 | 195 | |
| 187 | 196 | //============================================================ |
| 188 | | // hlsl_info constructor |
| 197 | // shader manager constructor |
| 189 | 198 | //============================================================ |
| 190 | 199 | |
| 191 | | hlsl_info::hlsl_info() |
| 200 | shaders::shaders() |
| 192 | 201 | { |
| 193 | 202 | master_enable = false; |
| 194 | 203 | vector_enable = true; |
| r22936 | r22937 | |
| 209 | 218 | |
| 210 | 219 | |
| 211 | 220 | //============================================================ |
| 212 | | // hlsl_info destructor |
| 221 | // shaders destructor |
| 213 | 222 | //============================================================ |
| 214 | 223 | |
| 215 | | hlsl_info::~hlsl_info() |
| 224 | shaders::~shaders() |
| 216 | 225 | { |
| 217 | 226 | global_free(options); |
| 218 | 227 | } |
| r22936 | r22937 | |
| 220 | 229 | |
| 221 | 230 | |
| 222 | 231 | //============================================================ |
| 223 | | // hlsl_info::window_save |
| 232 | // shaders::window_save |
| 224 | 233 | //============================================================ |
| 225 | 234 | |
| 226 | | void hlsl_info::window_save() |
| 235 | void shaders::window_save() |
| 227 | 236 | { |
| 228 | 237 | if (!master_enable || !d3dintf->post_fx_available) |
| 229 | 238 | return; |
| 230 | 239 | |
| 231 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 240 | renderer *d3d = (renderer *)window->drawdata; |
| 232 | 241 | |
| 233 | | HRESULT result = (*d3dintf->device.create_texture)(d3d->device, snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture); |
| 242 | HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture); |
| 234 | 243 | if (result != D3D_OK) |
| 235 | 244 | { |
| 236 | 245 | mame_printf_verbose("Direct3D: Unable to init system-memory target for HLSL snapshot (%08x), bailing\n", (UINT32)result); |
| r22936 | r22937 | |
| 238 | 247 | } |
| 239 | 248 | (*d3dintf->texture.get_surface_level)(snap_copy_texture, 0, &snap_copy_target); |
| 240 | 249 | |
| 241 | | result = (*d3dintf->device.create_texture)(d3d->device, snap_width, snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &snap_texture); |
| 250 | result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &snap_texture); |
| 242 | 251 | if (result != D3D_OK) |
| 243 | 252 | { |
| 244 | 253 | mame_printf_verbose("Direct3D: Unable to init video-memory target for HLSL snapshot (%08x), bailing\n", (UINT32)result); |
| r22936 | r22937 | |
| 253 | 262 | |
| 254 | 263 | |
| 255 | 264 | //============================================================ |
| 256 | | // hlsl_info::window_record |
| 265 | // shaders::window_record |
| 257 | 266 | //============================================================ |
| 258 | 267 | |
| 259 | | void hlsl_info::window_record() |
| 268 | void shaders::window_record() |
| 260 | 269 | { |
| 261 | 270 | if (!master_enable || !d3dintf->post_fx_available) |
| 262 | 271 | return; |
| r22936 | r22937 | |
| 272 | 281 | |
| 273 | 282 | |
| 274 | 283 | //============================================================ |
| 275 | | // hlsl_info::avi_update_snap |
| 284 | // shaders::avi_update_snap |
| 276 | 285 | //============================================================ |
| 277 | 286 | |
| 278 | | void hlsl_info::avi_update_snap(d3d_surface *surface) |
| 287 | void shaders::avi_update_snap(surface *surface) |
| 279 | 288 | { |
| 280 | 289 | if (!master_enable || !d3dintf->post_fx_available) |
| 281 | 290 | return; |
| 282 | 291 | |
| 283 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 292 | renderer *d3d = (renderer *)window->drawdata; |
| 284 | 293 | |
| 285 | 294 | D3DLOCKED_RECT rect; |
| 286 | 295 | |
| r22936 | r22937 | |
| 291 | 300 | } |
| 292 | 301 | |
| 293 | 302 | // copy the texture |
| 294 | | HRESULT result = (*d3dintf->device.get_render_target_data)(d3d->device, surface, avi_copy_surface); |
| 303 | HRESULT result = (*d3dintf->device.get_render_target_data)(d3d->get_device(), surface, avi_copy_surface); |
| 295 | 304 | if (result != D3D_OK) |
| 296 | 305 | { |
| 297 | 306 | return; |
| r22936 | r22937 | |
| 325 | 334 | // hlsl_render_snapshot |
| 326 | 335 | //============================================================ |
| 327 | 336 | |
| 328 | | void hlsl_info::render_snapshot(d3d_surface *surface) |
| 337 | void shaders::render_snapshot(surface *surface) |
| 329 | 338 | { |
| 330 | 339 | if (!master_enable || !d3dintf->post_fx_available) |
| 331 | 340 | return; |
| 332 | 341 | |
| 333 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 342 | renderer *d3d = (renderer *)window->drawdata; |
| 334 | 343 | |
| 335 | 344 | D3DLOCKED_RECT rect; |
| 336 | 345 | |
| r22936 | r22937 | |
| 343 | 352 | } |
| 344 | 353 | |
| 345 | 354 | // copy the texture |
| 346 | | HRESULT result = (*d3dintf->device.get_render_target_data)(d3d->device, surface, snap_copy_target); |
| 355 | HRESULT result = (*d3dintf->device.get_render_target_data)(d3d->get_device(), surface, snap_copy_target); |
| 347 | 356 | if (result != D3D_OK) |
| 348 | 357 | { |
| 349 | 358 | return; |
| r22936 | r22937 | |
| 427 | 436 | |
| 428 | 437 | |
| 429 | 438 | //============================================================ |
| 430 | | // hlsl_info::record_texture |
| 439 | // shaders::record_texture |
| 431 | 440 | //============================================================ |
| 432 | 441 | |
| 433 | | void hlsl_info::record_texture() |
| 442 | void shaders::record_texture() |
| 434 | 443 | { |
| 435 | 444 | if (!master_enable || !d3dintf->post_fx_available) |
| 436 | 445 | return; |
| 437 | 446 | |
| 438 | | d3d_surface *surface = avi_final_target; |
| 447 | surface *surface = avi_final_target; |
| 439 | 448 | |
| 440 | 449 | // ignore if nothing to do |
| 441 | 450 | if (avi_output_file == NULL || surface == NULL) |
| r22936 | r22937 | |
| 466 | 475 | |
| 467 | 476 | |
| 468 | 477 | //============================================================ |
| 469 | | // hlsl_info::end_hlsl_avi_recording |
| 478 | // shaders::end_hlsl_avi_recording |
| 470 | 479 | //============================================================ |
| 471 | 480 | |
| 472 | | void hlsl_info::end_avi_recording() |
| 481 | void shaders::end_avi_recording() |
| 473 | 482 | { |
| 474 | 483 | if (!master_enable || !d3dintf->post_fx_available) |
| 475 | 484 | return; |
| r22936 | r22937 | |
| 483 | 492 | |
| 484 | 493 | |
| 485 | 494 | //============================================================ |
| 486 | | // hlsl_info::set_texture |
| 495 | // shaders::set_texture |
| 487 | 496 | //============================================================ |
| 488 | 497 | |
| 489 | | void hlsl_info::toggle() |
| 498 | void shaders::toggle() |
| 490 | 499 | { |
| 491 | 500 | if (master_enable) |
| 492 | 501 | { |
| r22936 | r22937 | |
| 515 | 524 | } |
| 516 | 525 | |
| 517 | 526 | //============================================================ |
| 518 | | // hlsl_info::begin_avi_recording |
| 527 | // shaders::begin_avi_recording |
| 519 | 528 | //============================================================ |
| 520 | 529 | |
| 521 | | void hlsl_info::begin_avi_recording(const char *name) |
| 530 | void shaders::begin_avi_recording(const char *name) |
| 522 | 531 | { |
| 523 | 532 | if (!master_enable || !d3dintf->post_fx_available) |
| 524 | 533 | return; |
| 525 | 534 | |
| 526 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 535 | renderer *d3d = (renderer *)window->drawdata; |
| 527 | 536 | |
| 528 | 537 | // stop any existing recording |
| 529 | 538 | end_avi_recording(); |
| r22936 | r22937 | |
| 593 | 602 | // refcount hits zero |
| 594 | 603 | //============================================================ |
| 595 | 604 | |
| 596 | | void hlsl_info::remove_cache_target(d3d_cache_target *cache) |
| 605 | void shaders::remove_cache_target(cache_target *cache) |
| 597 | 606 | { |
| 598 | 607 | if (cache != NULL) |
| 599 | 608 | { |
| r22936 | r22937 | |
| 621 | 630 | // remove_render_target - remove an active target |
| 622 | 631 | //============================================================ |
| 623 | 632 | |
| 624 | | void hlsl_info::remove_render_target(d3d_texture_info *texture) |
| 633 | void shaders::remove_render_target(texture_info *texture) |
| 625 | 634 | { |
| 626 | 635 | remove_render_target(find_render_target(texture)); |
| 627 | 636 | } |
| 628 | 637 | |
| 629 | | void hlsl_info::remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index) |
| 638 | void shaders::remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index) |
| 630 | 639 | { |
| 631 | | d3d_render_target *target = find_render_target(width, height, screen_index, page_index); |
| 640 | render_target *target = find_render_target(width, height, screen_index, page_index); |
| 632 | 641 | if (target != NULL) |
| 633 | 642 | { |
| 634 | 643 | remove_render_target(target); |
| 635 | 644 | } |
| 636 | 645 | } |
| 637 | 646 | |
| 638 | | void hlsl_info::remove_render_target(d3d_render_target *rt) |
| 647 | void shaders::remove_render_target(render_target *rt) |
| 639 | 648 | { |
| 640 | 649 | if (rt != NULL) |
| 641 | 650 | { |
| r22936 | r22937 | |
| 654 | 663 | rt->next->prev = rt->prev; |
| 655 | 664 | } |
| 656 | 665 | |
| 657 | | d3d_cache_target *cache = find_cache_target(rt->screen_index, rt->width, rt->height); |
| 666 | cache_target *cache = find_cache_target(rt->screen_index, rt->width, rt->height); |
| 658 | 667 | if (cache != NULL) |
| 659 | 668 | { |
| 660 | 669 | remove_cache_target(cache); |
| r22936 | r22937 | |
| 674 | 683 | |
| 675 | 684 | |
| 676 | 685 | //============================================================ |
| 677 | | // hlsl_info::set_texture |
| 686 | // shaders::set_texture |
| 678 | 687 | //============================================================ |
| 679 | 688 | |
| 680 | | void hlsl_info::set_texture(d3d_texture_info *texture) |
| 689 | void shaders::set_texture(texture_info *texture) |
| 681 | 690 | { |
| 682 | 691 | if (!master_enable || !d3dintf->post_fx_available) |
| 683 | 692 | return; |
| 684 | 693 | |
| 685 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 694 | renderer *d3d = (renderer *)window->drawdata; |
| 686 | 695 | |
| 687 | 696 | if(texture != NULL) |
| 688 | 697 | { |
| 689 | | if(texture->prev_frame == texture->cur_frame) |
| 690 | | { |
| 691 | | paused = true; |
| 692 | | } |
| 693 | | else |
| 694 | | { |
| 695 | | paused = false; |
| 696 | | } |
| 697 | | |
| 698 | | texture->prev_frame = texture->cur_frame; |
| 698 | paused = texture->paused(); |
| 699 | texture->advance_frame(); |
| 699 | 700 | } |
| 700 | 701 | |
| 701 | | (*d3dintf->effect.set_texture)(effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 702 | texture_info *default_texture = d3d->get_default_texture(); |
| 703 | (*d3dintf->effect.set_texture)(default_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); |
| 702 | 704 | if (options->yiq_enable) |
| 703 | | (*d3dintf->effect.set_texture)(yiq_encode_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 705 | (*d3dintf->effect.set_texture)(yiq_encode_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); |
| 704 | 706 | else |
| 705 | | (*d3dintf->effect.set_texture)(color_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 706 | | (*d3dintf->effect.set_texture)(pincushion_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex); |
| 707 | (*d3dintf->effect.set_texture)(color_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); |
| 708 | (*d3dintf->effect.set_texture)(pincushion_effect, "Diffuse", (texture == NULL) ? default_texture->get_finaltex() : texture->get_finaltex()); |
| 707 | 709 | } |
| 708 | 710 | |
| 709 | 711 | |
| 710 | 712 | //============================================================ |
| 711 | | // hlsl_info::init |
| 713 | // shaders::init |
| 712 | 714 | //============================================================ |
| 713 | 715 | |
| 714 | | void hlsl_info::init(d3d_base *d3dintf, win_window_info *window) |
| 716 | void shaders::init(base *d3dintf, win_window_info *window) |
| 715 | 717 | { |
| 716 | 718 | if (!d3dintf->post_fx_available) |
| 717 | 719 | return; |
| r22936 | r22937 | |
| 746 | 748 | if(read_ini) |
| 747 | 749 | { |
| 748 | 750 | emu_file ini_file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_READ | OPEN_FLAG_CREATE_PATHS); |
| 749 | | file_error filerr = open_next((d3d_info*)window->drawdata, ini_file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0); |
| 751 | file_error filerr = open_next((renderer*)window->drawdata, ini_file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0); |
| 750 | 752 | |
| 751 | 753 | read_ini = false; |
| 752 | 754 | if (filerr == FILERR_NONE) |
| r22936 | r22937 | |
| 962 | 964 | } |
| 963 | 965 | else |
| 964 | 966 | { |
| 965 | | options = &g_hlsl_presets[preset]; |
| 967 | options = &s_hlsl_presets[preset]; |
| 966 | 968 | } |
| 967 | 969 | |
| 968 | 970 | options->yiq_enable = winoptions.screen_yiq_enable(); |
| r22936 | r22937 | |
| 981 | 983 | options->vector_time_period = winoptions.screen_vector_time_period(); |
| 982 | 984 | options->vector_length_scale = winoptions.screen_vector_length_scale(); |
| 983 | 985 | options->vector_length_ratio = winoptions.screen_vector_length_ratio(); |
| 986 | options->bloom_level0_weight = winoptions.screen_bloom_lvl0_weight(); |
| 987 | options->bloom_level1_weight = winoptions.screen_bloom_lvl1_weight(); |
| 988 | options->bloom_level2_weight = winoptions.screen_bloom_lvl2_weight(); |
| 989 | options->bloom_level3_weight = winoptions.screen_bloom_lvl3_weight(); |
| 990 | options->bloom_level4_weight = winoptions.screen_bloom_lvl4_weight(); |
| 991 | options->bloom_level5_weight = winoptions.screen_bloom_lvl5_weight(); |
| 992 | options->bloom_level6_weight = winoptions.screen_bloom_lvl6_weight(); |
| 993 | options->bloom_level7_weight = winoptions.screen_bloom_lvl7_weight(); |
| 994 | options->bloom_level8_weight = winoptions.screen_bloom_lvl8_weight(); |
| 995 | options->bloom_level9_weight = winoptions.screen_bloom_lvl9_weight(); |
| 996 | options->bloom_level10_weight = winoptions.screen_bloom_lvl10_weight(); |
| 984 | 997 | } |
| 985 | 998 | |
| 986 | 999 | options->params_dirty = true; |
| r22936 | r22937 | |
| 996 | 1009 | |
| 997 | 1010 | |
| 998 | 1011 | //============================================================ |
| 999 | | // hlsl_info::init_fsfx_quad |
| 1012 | // shaders::init_fsfx_quad |
| 1000 | 1013 | //============================================================ |
| 1001 | 1014 | |
| 1002 | | void hlsl_info::init_fsfx_quad(void *vertbuf) |
| 1015 | void shaders::init_fsfx_quad(void *vertbuf) |
| 1003 | 1016 | { |
| 1004 | 1017 | // Called at the start of each frame by the D3D code in order to reserve two triangles |
| 1005 | 1018 | // that are guaranteed to be at a fixed position so as to simply use D3DPT_TRIANGLELIST, 0, 2 |
| r22936 | r22937 | |
| 1007 | 1020 | if (!master_enable || !d3dintf->post_fx_available) |
| 1008 | 1021 | return; |
| 1009 | 1022 | |
| 1010 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1023 | renderer *d3d = (renderer *)window->drawdata; |
| 1011 | 1024 | |
| 1012 | 1025 | // get a pointer to the vertex buffer |
| 1013 | | fsfx_vertices = (d3d_vertex *)vertbuf; |
| 1026 | fsfx_vertices = (vertex *)vertbuf; |
| 1014 | 1027 | if (fsfx_vertices == NULL) |
| 1015 | 1028 | return; |
| 1016 | 1029 | |
| 1017 | 1030 | // fill in the vertexes clockwise |
| 1018 | 1031 | fsfx_vertices[0].x = 0.0f; |
| 1019 | 1032 | fsfx_vertices[0].y = 0.0f; |
| 1020 | | fsfx_vertices[1].x = d3d->width; |
| 1033 | fsfx_vertices[1].x = d3d->get_width(); |
| 1021 | 1034 | fsfx_vertices[1].y = 0.0f; |
| 1022 | 1035 | fsfx_vertices[2].x = 0.0f; |
| 1023 | | fsfx_vertices[2].y = d3d->height; |
| 1024 | | fsfx_vertices[3].x = d3d->width; |
| 1036 | fsfx_vertices[2].y = d3d->get_height(); |
| 1037 | fsfx_vertices[3].x = d3d->get_width(); |
| 1025 | 1038 | fsfx_vertices[3].y = 0.0f; |
| 1026 | 1039 | fsfx_vertices[4].x = 0.0f; |
| 1027 | | fsfx_vertices[4].y = d3d->height; |
| 1028 | | fsfx_vertices[5].x = d3d->width; |
| 1029 | | fsfx_vertices[5].y = d3d->height; |
| 1040 | fsfx_vertices[4].y = d3d->get_height(); |
| 1041 | fsfx_vertices[5].x = d3d->get_width(); |
| 1042 | fsfx_vertices[5].y = d3d->get_height(); |
| 1030 | 1043 | |
| 1031 | 1044 | fsfx_vertices[0].u0 = 0.0f; |
| 1032 | 1045 | fsfx_vertices[0].v0 = 0.0f; |
| r22936 | r22937 | |
| 1058 | 1071 | |
| 1059 | 1072 | |
| 1060 | 1073 | //============================================================ |
| 1061 | | // hlsl_info::create_resources |
| 1074 | // shaders::create_resources |
| 1062 | 1075 | //============================================================ |
| 1063 | 1076 | |
| 1064 | | int hlsl_info::create_resources(bool reset) |
| 1077 | int shaders::create_resources(bool reset) |
| 1065 | 1078 | { |
| 1066 | 1079 | if (!master_enable || !d3dintf->post_fx_available) |
| 1067 | 1080 | return 0; |
| 1068 | 1081 | |
| 1069 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1082 | renderer *d3d = (renderer *)window->drawdata; |
| 1070 | 1083 | |
| 1071 | | HRESULT result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer); |
| 1084 | HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer); |
| 1072 | 1085 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 1073 | 1086 | |
| 1074 | | result = (*d3dintf->device.create_texture)(d3d->device, 4, 4, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &black_texture); |
| 1087 | result = (*d3dintf->device.create_texture)(d3d->get_device(), 4, 4, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &black_texture); |
| 1075 | 1088 | if (result != D3D_OK) |
| 1076 | 1089 | { |
| 1077 | 1090 | mame_printf_verbose("Direct3D: Unable to init video-memory target for black texture (%08x)\n", (UINT32)result); |
| 1078 | 1091 | return 1; |
| 1079 | 1092 | } |
| 1080 | 1093 | (*d3dintf->texture.get_surface_level)(black_texture, 0, &black_surface); |
| 1081 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, black_surface); |
| 1094 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, black_surface); |
| 1082 | 1095 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1083 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1096 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1084 | 1097 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1085 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 1098 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 1086 | 1099 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1087 | 1100 | |
| 1088 | | result = (*d3dintf->device.create_texture)(d3d->device, (int)snap_width, (int)snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &avi_copy_texture); |
| 1101 | result = (*d3dintf->device.create_texture)(d3d->get_device(), (int)snap_width, (int)snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &avi_copy_texture); |
| 1089 | 1102 | if (result != D3D_OK) |
| 1090 | 1103 | { |
| 1091 | 1104 | mame_printf_verbose("Direct3D: Unable to init system-memory target for HLSL AVI dumping (%08x)\n", (UINT32)result); |
| r22936 | r22937 | |
| 1093 | 1106 | } |
| 1094 | 1107 | (*d3dintf->texture.get_surface_level)(avi_copy_texture, 0, &avi_copy_surface); |
| 1095 | 1108 | |
| 1096 | | result = (*d3dintf->device.create_texture)(d3d->device, (int)snap_width, (int)snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &avi_final_texture); |
| 1109 | result = (*d3dintf->device.create_texture)(d3d->get_device(), (int)snap_width, (int)snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &avi_final_texture); |
| 1097 | 1110 | if (result != D3D_OK) |
| 1098 | 1111 | { |
| 1099 | 1112 | mame_printf_verbose("Direct3D: Unable to init video-memory target for HLSL AVI dumping (%08x)\n", (UINT32)result); |
| r22936 | r22937 | |
| 1115 | 1128 | texture.seqid = 0; |
| 1116 | 1129 | |
| 1117 | 1130 | // now create it |
| 1118 | | shadow_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 1131 | shadow_texture = new texture_info(d3d->get_texture_manager(), &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)); |
| 1119 | 1132 | } |
| 1120 | 1133 | |
| 1121 | 1134 | const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(); |
| r22936 | r22937 | |
| 1162 | 1175 | TCHAR *yiq_decode_name = tstring_from_utf8(yiq_decode_name_cstr); |
| 1163 | 1176 | |
| 1164 | 1177 | // create the regular shader |
| 1165 | | result = (*d3dintf->device.create_effect)(d3d->device, primary_name, &effect); |
| 1178 | result = (*d3dintf->device.create_effect)(d3d->get_device(), primary_name, &default_effect); |
| 1166 | 1179 | if(result != D3D_OK) |
| 1167 | 1180 | { |
| 1168 | 1181 | mame_printf_verbose("Direct3D: Unable to load primary.fx\n"); |
| r22936 | r22937 | |
| 1170 | 1183 | } |
| 1171 | 1184 | |
| 1172 | 1185 | // create the post-processing shader |
| 1173 | | result = (*d3dintf->device.create_effect)(d3d->device, post_name, &post_effect); |
| 1186 | result = (*d3dintf->device.create_effect)(d3d->get_device(), post_name, &post_effect); |
| 1174 | 1187 | if(result != D3D_OK) |
| 1175 | 1188 | { |
| 1176 | 1189 | mame_printf_verbose("Direct3D: Unable to load post.fx\n"); |
| r22936 | r22937 | |
| 1178 | 1191 | } |
| 1179 | 1192 | |
| 1180 | 1193 | // create the prescaling shader |
| 1181 | | result = (*d3dintf->device.create_effect)(d3d->device, prescale_name, &prescale_effect); |
| 1194 | result = (*d3dintf->device.create_effect)(d3d->get_device(), prescale_name, &prescale_effect); |
| 1182 | 1195 | if(result != D3D_OK) |
| 1183 | 1196 | { |
| 1184 | 1197 | mame_printf_verbose("Direct3D: Unable to load prescale.fx\n"); |
| r22936 | r22937 | |
| 1186 | 1199 | } |
| 1187 | 1200 | |
| 1188 | 1201 | // create the pincushion shader |
| 1189 | | result = (*d3dintf->device.create_effect)(d3d->device, pincushion_name, &pincushion_effect); |
| 1202 | result = (*d3dintf->device.create_effect)(d3d->get_device(), pincushion_name, &pincushion_effect); |
| 1190 | 1203 | if(result != D3D_OK) |
| 1191 | 1204 | { |
| 1192 | 1205 | mame_printf_verbose("Direct3D: Unable to load pincushion.fx\n"); |
| r22936 | r22937 | |
| 1194 | 1207 | } |
| 1195 | 1208 | |
| 1196 | 1209 | // create the phosphor shader |
| 1197 | | result = (*d3dintf->device.create_effect)(d3d->device, phosphor_name, &phosphor_effect); |
| 1210 | result = (*d3dintf->device.create_effect)(d3d->get_device(), phosphor_name, &phosphor_effect); |
| 1198 | 1211 | if(result != D3D_OK) |
| 1199 | 1212 | { |
| 1200 | 1213 | mame_printf_verbose("Direct3D: Unable to load phosphor.fx\n"); |
| r22936 | r22937 | |
| 1202 | 1215 | } |
| 1203 | 1216 | |
| 1204 | 1217 | // create the focus shader |
| 1205 | | result = (*d3dintf->device.create_effect)(d3d->device, focus_name, &focus_effect); |
| 1218 | result = (*d3dintf->device.create_effect)(d3d->get_device(), focus_name, &focus_effect); |
| 1206 | 1219 | if(result != D3D_OK) |
| 1207 | 1220 | { |
| 1208 | 1221 | mame_printf_verbose("Direct3D: Unable to load focus.fx\n"); |
| r22936 | r22937 | |
| 1210 | 1223 | } |
| 1211 | 1224 | |
| 1212 | 1225 | // create the deconvergence shader |
| 1213 | | result = (*d3dintf->device.create_effect)(d3d->device, deconverge_name, &deconverge_effect); |
| 1226 | result = (*d3dintf->device.create_effect)(d3d->get_device(), deconverge_name, &deconverge_effect); |
| 1214 | 1227 | if(result != D3D_OK) |
| 1215 | 1228 | { |
| 1216 | 1229 | mame_printf_verbose("Direct3D: Unable to load deconverge.fx\n"); |
| r22936 | r22937 | |
| 1218 | 1231 | } |
| 1219 | 1232 | |
| 1220 | 1233 | // create the color convolution shader |
| 1221 | | result = (*d3dintf->device.create_effect)(d3d->device, color_name, &color_effect); |
| 1234 | result = (*d3dintf->device.create_effect)(d3d->get_device(), color_name, &color_effect); |
| 1222 | 1235 | if(result != D3D_OK) |
| 1223 | 1236 | { |
| 1224 | 1237 | mame_printf_verbose("Direct3D: Unable to load color.fx\n"); |
| r22936 | r22937 | |
| 1226 | 1239 | } |
| 1227 | 1240 | |
| 1228 | 1241 | // create the YIQ modulation shader |
| 1229 | | result = (*d3dintf->device.create_effect)(d3d->device, yiq_encode_name, &yiq_encode_effect); |
| 1242 | result = (*d3dintf->device.create_effect)(d3d->get_device(), yiq_encode_name, &yiq_encode_effect); |
| 1230 | 1243 | if(result != D3D_OK) |
| 1231 | 1244 | { |
| 1232 | 1245 | mame_printf_verbose("Direct3D: Unable to load yiq_encode.fx\n"); |
| r22936 | r22937 | |
| 1234 | 1247 | } |
| 1235 | 1248 | |
| 1236 | 1249 | // create the YIQ demodulation shader |
| 1237 | | result = (*d3dintf->device.create_effect)(d3d->device, yiq_decode_name, &yiq_decode_effect); |
| 1250 | result = (*d3dintf->device.create_effect)(d3d->get_device(), yiq_decode_name, &yiq_decode_effect); |
| 1238 | 1251 | if(result != D3D_OK) |
| 1239 | 1252 | { |
| 1240 | 1253 | mame_printf_verbose("Direct3D: Unable to load yiq_decode.fx\n"); |
| 1241 | 1254 | return 1; |
| 1242 | 1255 | } |
| 1243 | 1256 | |
| 1244 | | // create the vector shader |
| 1245 | | #if HLSL_VECTOR |
| 1257 | #if HLSL_VECTOR || CRT_BLOOM |
| 1246 | 1258 | char bloom_cstr[1024]; |
| 1247 | 1259 | sprintf(bloom_cstr, "%s\\bloom.fx", fx_dir); |
| 1248 | 1260 | TCHAR *bloom_name = tstring_from_utf8(bloom_cstr); |
| 1249 | 1261 | |
| 1250 | | result = (*d3dintf->device.create_effect)(d3d->device, bloom_name, &bloom_effect); |
| 1262 | result = (*d3dintf->device.create_effect)(d3d->get_device(), bloom_name, &bloom_effect); |
| 1251 | 1263 | if(result != D3D_OK) |
| 1252 | 1264 | { |
| 1253 | 1265 | mame_printf_verbose("Direct3D: Unable to load bloom.fx\n"); |
| r22936 | r22937 | |
| 1260 | 1272 | sprintf(downsample_cstr, "%s\\downsample.fx", fx_dir); |
| 1261 | 1273 | TCHAR *downsample_name = tstring_from_utf8(downsample_cstr); |
| 1262 | 1274 | |
| 1263 | | result = (*d3dintf->device.create_effect)(d3d->device, downsample_name, &downsample_effect); |
| 1275 | result = (*d3dintf->device.create_effect)(d3d->get_device(), downsample_name, &downsample_effect); |
| 1264 | 1276 | if(result != D3D_OK) |
| 1265 | 1277 | { |
| 1266 | 1278 | mame_printf_verbose("Direct3D: Unable to load downsample.fx\n"); |
| r22936 | r22937 | |
| 1268 | 1280 | } |
| 1269 | 1281 | if (downsample_name) |
| 1270 | 1282 | osd_free(downsample_name); |
| 1271 | | |
| 1283 | #endif |
| 1284 | #if HLSL_VECTOR |
| 1285 | // create the vector shader |
| 1272 | 1286 | char vector_cstr[1024]; |
| 1273 | 1287 | sprintf(vector_cstr, "%s\\vector.fx", fx_dir); |
| 1274 | 1288 | TCHAR *vector_name = tstring_from_utf8(vector_cstr); |
| 1275 | 1289 | |
| 1276 | | result = (*d3dintf->device.create_effect)(d3d->device, vector_name, &vector_effect); |
| 1290 | result = (*d3dintf->device.create_effect)(d3d->get_device(), vector_name, &vector_effect); |
| 1277 | 1291 | if(result != D3D_OK) |
| 1278 | 1292 | { |
| 1279 | 1293 | mame_printf_verbose("Direct3D: Unable to load vector.fx\n"); |
| r22936 | r22937 | |
| 1311 | 1325 | |
| 1312 | 1326 | |
| 1313 | 1327 | //============================================================ |
| 1314 | | // hlsl_info::begin_draw |
| 1328 | // shaders::begin_draw |
| 1315 | 1329 | //============================================================ |
| 1316 | 1330 | |
| 1317 | | void hlsl_info::begin_draw() |
| 1331 | void shaders::begin_draw() |
| 1318 | 1332 | { |
| 1319 | 1333 | if (!master_enable || !d3dintf->post_fx_available) |
| 1320 | 1334 | return; |
| 1321 | 1335 | |
| 1322 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1336 | renderer *d3d = (renderer *)window->drawdata; |
| 1323 | 1337 | |
| 1324 | | curr_effect = effect; |
| 1338 | curr_effect = default_effect; |
| 1325 | 1339 | |
| 1326 | | (*d3dintf->effect.set_technique)(effect, "TestTechnique"); |
| 1340 | (*d3dintf->effect.set_technique)(default_effect, "TestTechnique"); |
| 1327 | 1341 | (*d3dintf->effect.set_technique)(post_effect, "ScanMaskTechnique"); |
| 1328 | 1342 | (*d3dintf->effect.set_technique)(pincushion_effect, "TestTechnique"); |
| 1329 | 1343 | (*d3dintf->effect.set_technique)(phosphor_effect, "TestTechnique"); |
| r22936 | r22937 | |
| 1333 | 1347 | (*d3dintf->effect.set_technique)(yiq_encode_effect, "EncodeTechnique"); |
| 1334 | 1348 | (*d3dintf->effect.set_technique)(yiq_decode_effect, "DecodeTechnique"); |
| 1335 | 1349 | |
| 1336 | | HRESULT result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer); |
| 1350 | HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer); |
| 1337 | 1351 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result); |
| 1338 | 1352 | } |
| 1339 | 1353 | |
| 1340 | 1354 | |
| 1341 | 1355 | //============================================================ |
| 1342 | | // hlsl_info::begin_frame |
| 1356 | // shaders::begin_frame |
| 1343 | 1357 | //============================================================ |
| 1344 | 1358 | |
| 1345 | | void hlsl_info::begin_frame() |
| 1359 | void shaders::begin_frame() |
| 1346 | 1360 | { |
| 1347 | 1361 | record_texture(); |
| 1348 | | |
| 1349 | | /*d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1350 | | |
| 1351 | | d3d_render_target *rt = find_render_target(d3d->width, d3d->height, 0, 0); |
| 1352 | | if (rt == NULL) |
| 1353 | | { |
| 1354 | | return; |
| 1355 | | } |
| 1356 | | |
| 1357 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[0]); |
| 1358 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1359 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1360 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1361 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 1362 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);*/ |
| 1363 | 1362 | } |
| 1364 | 1363 | |
| 1365 | 1364 | |
| 1366 | 1365 | //============================================================ |
| 1367 | | // hlsl_info::blit |
| 1366 | // shaders::blit |
| 1368 | 1367 | //============================================================ |
| 1369 | 1368 | |
| 1370 | | void hlsl_info::blit(d3d_surface *dst, d3d_texture *src, d3d_surface *new_dst, D3DPRIMITIVETYPE prim_type, |
| 1369 | void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type, |
| 1371 | 1370 | UINT32 prim_index, UINT32 prim_count, int dstw, int dsth) |
| 1372 | 1371 | { |
| 1373 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1372 | renderer *d3d = (renderer *)window->drawdata; |
| 1374 | 1373 | |
| 1375 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, dst); |
| 1374 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst); |
| 1376 | 1375 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1377 | 1376 | |
| 1378 | | curr_effect = effect; |
| 1377 | curr_effect = default_effect; |
| 1379 | 1378 | |
| 1380 | 1379 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", src); |
| 1381 | 1380 | |
| r22936 | r22937 | |
| 1392 | 1391 | { |
| 1393 | 1392 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1394 | 1393 | // add the primitives |
| 1395 | | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->device, prim_type, prim_index, prim_count); |
| 1394 | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), prim_type, prim_index, prim_count); |
| 1396 | 1395 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1397 | 1396 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1398 | 1397 | } |
| r22936 | r22937 | |
| 1401 | 1400 | |
| 1402 | 1401 | if (new_dst) |
| 1403 | 1402 | { |
| 1404 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, new_dst); |
| 1403 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, new_dst); |
| 1405 | 1404 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1406 | 1405 | } |
| 1407 | 1406 | } |
| r22936 | r22937 | |
| 1409 | 1408 | |
| 1410 | 1409 | |
| 1411 | 1410 | //============================================================ |
| 1412 | | // hlsl_info::blit |
| 1411 | // shaders::blit |
| 1413 | 1412 | //============================================================ |
| 1414 | 1413 | |
| 1415 | | void hlsl_info::blit(d3d_surface *dst, d3d_texture *src, d3d_surface *new_dst, D3DPRIMITIVETYPE prim_type, |
| 1414 | void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type, |
| 1416 | 1415 | UINT32 prim_index, UINT32 prim_count) |
| 1417 | 1416 | { |
| 1418 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1417 | renderer *d3d = (renderer *)window->drawdata; |
| 1419 | 1418 | |
| 1420 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, dst); |
| 1419 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst); |
| 1421 | 1420 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1421 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(1,0,0,0), 0, 0); |
| 1422 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1422 | 1423 | |
| 1423 | | curr_effect = effect; |
| 1424 | curr_effect = default_effect; |
| 1424 | 1425 | |
| 1425 | | d3d_render_target *rt = find_render_target(d3d->width, d3d->height, 0, 0); |
| 1426 | | if (rt == NULL) |
| 1427 | | { |
| 1428 | | return; |
| 1429 | | } |
| 1430 | | |
| 1431 | 1426 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", src); |
| 1432 | 1427 | |
| 1433 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1434 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1435 | | (*d3dintf->effect.set_float)(curr_effect, "ScreenWidth", (float)d3d->width); |
| 1436 | | (*d3dintf->effect.set_float)(curr_effect, "ScreenHeight", (float)d3d->height); |
| 1428 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1429 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1430 | (*d3dintf->effect.set_float)(curr_effect, "ScreenWidth", (float)d3d->get_width()); |
| 1431 | (*d3dintf->effect.set_float)(curr_effect, "ScreenHeight", (float)d3d->get_height()); |
| 1437 | 1432 | (*d3dintf->effect.set_float)(curr_effect, "PostPass", 1.0f); |
| 1438 | 1433 | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion); |
| 1439 | 1434 | (*d3dintf->effect.set_float)(curr_effect, "Brighten", 1.0f); |
| r22936 | r22937 | |
| 1445 | 1440 | { |
| 1446 | 1441 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1447 | 1442 | // add the primitives |
| 1448 | | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->device, prim_type, prim_index, prim_count); |
| 1443 | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), prim_type, prim_index, prim_count); |
| 1449 | 1444 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1450 | 1445 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1451 | 1446 | } |
| r22936 | r22937 | |
| 1456 | 1451 | |
| 1457 | 1452 | if (new_dst) |
| 1458 | 1453 | { |
| 1459 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, new_dst); |
| 1454 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, new_dst); |
| 1460 | 1455 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1461 | 1456 | } |
| 1462 | 1457 | } |
| 1463 | 1458 | |
| 1464 | 1459 | //============================================================ |
| 1465 | | // hlsl_info::end_frame |
| 1460 | // shaders::end_frame |
| 1466 | 1461 | //============================================================ |
| 1467 | 1462 | |
| 1468 | | void hlsl_info::end_frame() |
| 1463 | void shaders::end_frame() |
| 1469 | 1464 | { |
| 1470 | 1465 | if (!master_enable || !d3dintf->post_fx_available) |
| 1471 | 1466 | return; |
| r22936 | r22937 | |
| 1479 | 1474 | return; |
| 1480 | 1475 | |
| 1481 | 1476 | lines_pending = false; |
| 1482 | | /*d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1483 | 1477 | |
| 1484 | | d3d_render_target *rt = find_render_target(d3d->width, d3d->height, 0, 0); |
| 1485 | | if (!rt) |
| 1486 | | return; |
| 1487 | | |
| 1488 | | blit(backbuffer, rt->texture[0], NULL, vecbuf_type, vecbuf_index, vecbuf_count);*/ |
| 1489 | | |
| 1490 | | /*d3d_render_target *rt = find_render_target(d3d->width, d3d->height, 0, 0); |
| 1478 | /*render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 1491 | 1479 | if (rt == NULL) |
| 1492 | 1480 | { |
| 1493 | 1481 | return; |
| 1494 | 1482 | } |
| 1495 | 1483 | |
| 1496 | | blit(backbuffer, rt->texture[1], NULL, vecbuf_type, vecbuf_index, vecbuf_count); |
| 1484 | blit(backbuffer, rt->render_texture[1], NULL, vecbuf_type, vecbuf_index, vecbuf_count); |
| 1497 | 1485 | |
| 1498 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[1]); |
| 1486 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]); |
| 1499 | 1487 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1500 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1488 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1501 | 1489 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1502 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 1490 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 1503 | 1491 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);*/ |
| 1504 | 1492 | } |
| 1505 | 1493 | |
| 1506 | 1494 | |
| 1507 | 1495 | //============================================================ |
| 1508 | | // hlsl_info::init_effect_info |
| 1496 | // shaders::init_effect_info |
| 1509 | 1497 | //============================================================ |
| 1510 | 1498 | |
| 1511 | | void hlsl_info::init_effect_info(d3d_poly_info *poly) |
| 1499 | void shaders::init_effect_info(poly_info *poly) |
| 1512 | 1500 | { |
| 1513 | 1501 | if (!master_enable || !d3dintf->post_fx_available) |
| 1514 | 1502 | return; |
| 1515 | 1503 | |
| 1516 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1504 | renderer *d3d = (renderer *)window->drawdata; |
| 1505 | texture_info *texture = poly->get_texture(); |
| 1517 | 1506 | |
| 1518 | | if(PRIMFLAG_GET_TEXSHADE(d3d->last_texture_flags)) |
| 1507 | vec2f shadow_dims; |
| 1508 | |
| 1509 | if (shadow_texture) |
| 1519 | 1510 | { |
| 1511 | shadow_dims = shadow_texture->get_rawdims(); |
| 1512 | } |
| 1513 | else |
| 1514 | { |
| 1515 | shadow_dims.c.x = 1.0f; |
| 1516 | shadow_dims.c.y = 1.0f; |
| 1517 | } |
| 1518 | |
| 1519 | if(PRIMFLAG_GET_TEXSHADE(d3d->get_last_texture_flags())) |
| 1520 | { |
| 1520 | 1521 | curr_effect = pincushion_effect; |
| 1521 | 1522 | } |
| 1522 | | else if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL) |
| 1523 | else if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL) |
| 1523 | 1524 | { |
| 1524 | 1525 | // Plug in all of the shader settings we're going to need |
| 1525 | 1526 | // This is extremely slow, but we're not rendering models here, |
| 1526 | 1527 | // just post-processing. |
| 1527 | 1528 | curr_effect = post_effect; |
| 1528 | 1529 | |
| 1529 | | (*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (poly->texture->cur_frame == 0) ? 0.0f : options->scanline_offset); |
| 1530 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (texture->get_cur_frame() == 0) ? 0.0f : options->scanline_offset); |
| 1530 | 1531 | |
| 1531 | 1532 | if(options->params_dirty) |
| 1532 | 1533 | { |
| 1533 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1534 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1535 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart)); |
| 1536 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart)); |
| 1537 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", d3d->width); |
| 1538 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", d3d->height); |
| 1534 | vec2f delta = texture->get_uvstop() - texture->get_uvstart(); |
| 1535 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &texture->get_rawdims().c.x); |
| 1536 | (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x); |
| 1537 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", d3d->get_width()); |
| 1538 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", d3d->get_height()); |
| 1539 | 1539 | (*d3dintf->effect.set_vector)(curr_effect, "Floor", 3, options->floor); |
| 1540 | 1540 | (*d3dintf->effect.set_float)(curr_effect, "SnapX", snap_width); |
| 1541 | 1541 | (*d3dintf->effect.set_float)(curr_effect, "SnapY", snap_height); |
| 1542 | 1542 | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion); |
| 1543 | 1543 | (*d3dintf->effect.set_float)(curr_effect, "CurvatureAmount", options->curvature); |
| 1544 | 1544 | (*d3dintf->effect.set_float)(curr_effect, "UseShadow", shadow_texture == NULL ? 0.0f : 1.0f); |
| 1545 | | (*d3dintf->effect.set_texture)(curr_effect, "Shadow", shadow_texture == NULL ? NULL : shadow_texture->d3dfinaltex); |
| 1545 | (*d3dintf->effect.set_texture)(curr_effect, "Shadow", shadow_texture == NULL ? NULL : shadow_texture->get_finaltex()); |
| 1546 | 1546 | (*d3dintf->effect.set_float)(curr_effect, "ShadowBrightness", options->shadow_mask_alpha); |
| 1547 | 1547 | (*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeX", (float)options->shadow_mask_count_x); |
| 1548 | 1548 | (*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeY", (float)options->shadow_mask_count_y); |
| 1549 | 1549 | (*d3dintf->effect.set_float)(curr_effect, "ShadowU", options->shadow_mask_u_size); |
| 1550 | 1550 | (*d3dintf->effect.set_float)(curr_effect, "ShadowV", options->shadow_mask_v_size); |
| 1551 | | (*d3dintf->effect.set_float)(curr_effect, "ShadowWidth", shadow_texture == NULL ? 1.0f : (float)shadow_texture->rawwidth); |
| 1552 | | (*d3dintf->effect.set_float)(curr_effect, "ShadowHeight", shadow_texture == NULL ? 1.0f : (float)shadow_texture->rawheight); |
| 1551 | |
| 1552 | (*d3dintf->effect.set_vector)(curr_effect, "ShadowDims", 2, &shadow_dims.c.x); |
| 1553 | 1553 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineAmount", options->scanline_alpha); |
| 1554 | 1554 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineScale", options->scanline_scale); |
| 1555 | 1555 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineHeight", options->scanline_height); |
| 1556 | 1556 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightScale", options->scanline_bright_scale); |
| 1557 | 1557 | (*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightOffset", options->scanline_bright_offset); |
| 1558 | | //(*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (poly->texture->cur_frame == 0) ? 0.0f : options->scanline_offset); |
| 1558 | //(*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (texture->get_cur_frame() == 0) ? 0.0f : options->scanline_offset); |
| 1559 | 1559 | (*d3dintf->effect.set_vector)(curr_effect, "Power", 3, options->power); |
| 1560 | 1560 | } |
| 1561 | 1561 | } |
| 1562 | 1562 | else |
| 1563 | 1563 | { |
| 1564 | | curr_effect = effect; |
| 1564 | curr_effect = default_effect; |
| 1565 | 1565 | |
| 1566 | 1566 | (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f); |
| 1567 | 1567 | } |
| r22936 | r22937 | |
| 1569 | 1569 | |
| 1570 | 1570 | |
| 1571 | 1571 | //============================================================ |
| 1572 | | // hlsl_info::find_render_target |
| 1572 | // shaders::find_render_target |
| 1573 | 1573 | //============================================================ |
| 1574 | 1574 | |
| 1575 | | d3d_render_target* hlsl_info::find_render_target(d3d_texture_info *info) |
| 1575 | render_target* shaders::find_render_target(texture_info *info) |
| 1576 | 1576 | { |
| 1577 | | d3d_render_target *curr = targethead; |
| 1578 | | |
| 1579 | | UINT32 screen_index_data = (UINT32)info->texinfo.osddata; |
| 1577 | render_target *curr = targethead; |
| 1578 | UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata; |
| 1580 | 1579 | UINT32 screen_index = screen_index_data >> 1; |
| 1581 | 1580 | UINT32 page_index = screen_index_data & 1; |
| 1582 | 1581 | |
| 1583 | | while (curr != NULL && (curr->screen_index != screen_index || curr->page_index != page_index || curr->width != info->texinfo.width || curr->height != info->texinfo.height)) |
| 1582 | while (curr != NULL && (curr->screen_index != screen_index || curr->page_index != page_index || |
| 1583 | curr->width != info->get_texinfo().width || curr->height != info->get_texinfo().height)) |
| 1584 | 1584 | { |
| 1585 | 1585 | curr = curr->next; |
| 1586 | 1586 | } |
| r22936 | r22937 | |
| 1590 | 1590 | |
| 1591 | 1591 | |
| 1592 | 1592 | //============================================================ |
| 1593 | | // hlsl_info::find_render_target |
| 1593 | // shaders::find_render_target |
| 1594 | 1594 | //============================================================ |
| 1595 | 1595 | |
| 1596 | | d3d_render_target* hlsl_info::find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index) |
| 1596 | render_target* shaders::find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index) |
| 1597 | 1597 | { |
| 1598 | | d3d_render_target *curr = targethead; |
| 1598 | render_target *curr = targethead; |
| 1599 | 1599 | |
| 1600 | 1600 | while (curr != NULL && (curr->width != width || curr->height != height || curr->screen_index != screen_index || curr->page_index != page_index)) |
| 1601 | 1601 | { |
| r22936 | r22937 | |
| 1607 | 1607 | |
| 1608 | 1608 | |
| 1609 | 1609 | //============================================================ |
| 1610 | | // hlsl_info::find_cache_target |
| 1610 | // shaders::find_cache_target |
| 1611 | 1611 | //============================================================ |
| 1612 | 1612 | |
| 1613 | | d3d_cache_target* hlsl_info::find_cache_target(UINT32 screen_index, int width, int height) |
| 1613 | cache_target* shaders::find_cache_target(UINT32 screen_index, int width, int height) |
| 1614 | 1614 | { |
| 1615 | | d3d_cache_target *curr = cachehead; |
| 1615 | cache_target *curr = cachehead; |
| 1616 | 1616 | |
| 1617 | 1617 | while (curr != NULL && (curr->screen_index != screen_index || curr->width != width || curr->height != height)) |
| 1618 | 1618 | { |
| r22936 | r22937 | |
| 1624 | 1624 | |
| 1625 | 1625 | |
| 1626 | 1626 | //============================================================ |
| 1627 | | // hlsl_info::render_quad |
| 1627 | // shaders::render_quad |
| 1628 | 1628 | //============================================================ |
| 1629 | 1629 | |
| 1630 | | void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum) |
| 1630 | void shaders::render_quad(poly_info *poly, int vertnum) |
| 1631 | 1631 | { |
| 1632 | 1632 | if (!master_enable || !d3dintf->post_fx_available) |
| 1633 | 1633 | return; |
| 1634 | 1634 | |
| 1635 | 1635 | UINT num_passes = 0; |
| 1636 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1636 | renderer *d3d = (renderer *)window->drawdata; |
| 1637 | texture_info *texture = poly->get_texture(); |
| 1637 | 1638 | |
| 1638 | | if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL) |
| 1639 | if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL) |
| 1639 | 1640 | { |
| 1640 | | d3d_render_target *rt = find_render_target(poly->texture); |
| 1641 | render_target *rt = find_render_target(texture); |
| 1641 | 1642 | if (rt == NULL) |
| 1642 | 1643 | { |
| 1643 | 1644 | return; |
| 1644 | 1645 | } |
| 1645 | | d3d_cache_target *ct = find_cache_target(rt->screen_index, poly->texture->texinfo.width, poly->texture->texinfo.height); |
| 1646 | cache_target *ct = find_cache_target(rt->screen_index, texture->get_texinfo().width, texture->get_texinfo().height); |
| 1646 | 1647 | |
| 1648 | vec2f& rawdims = texture->get_rawdims(); |
| 1649 | vec2f delta = texture->get_uvstop() - texture->get_uvstart(); |
| 1650 | |
| 1647 | 1651 | if(options->yiq_enable) |
| 1648 | 1652 | { |
| 1649 | | /* Convert our signal into YIQ */ |
| 1653 | // Convert our signal into YIQ |
| 1650 | 1654 | curr_effect = yiq_encode_effect; |
| 1651 | 1655 | |
| 1652 | 1656 | if(options->params_dirty) |
| 1653 | 1657 | { |
| 1654 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1655 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1656 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart)); |
| 1657 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart)); |
| 1658 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1659 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1658 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1659 | (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x); |
| 1660 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1661 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1660 | 1662 | (*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc); |
| 1661 | 1663 | (*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a); |
| 1662 | | (*d3dintf->effect.set_float)(curr_effect, "BValue", (poly->texture->cur_frame == 2) ? 0.0f : ((float)poly->texture->cur_frame * options->yiq_b)); |
| 1664 | (*d3dintf->effect.set_float)(curr_effect, "BValue", (texture->get_cur_frame() == 2) ? 0.0f : ((float)texture->get_cur_frame() * options->yiq_b)); |
| 1663 | 1665 | (*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p); |
| 1664 | 1666 | (*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n); |
| 1665 | 1667 | (*d3dintf->effect.set_float)(curr_effect, "YFreqResponse", options->yiq_y); |
| r22936 | r22937 | |
| 1668 | 1670 | (*d3dintf->effect.set_float)(curr_effect, "ScanTime", options->yiq_scan_time); |
| 1669 | 1671 | } |
| 1670 | 1672 | |
| 1671 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[4]); |
| 1673 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[4]); |
| 1672 | 1674 | |
| 1673 | 1675 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1674 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1676 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1675 | 1677 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1676 | 1678 | |
| 1677 | 1679 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r22936 | r22937 | |
| 1680 | 1682 | { |
| 1681 | 1683 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1682 | 1684 | // add the primitives |
| 1683 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1685 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1684 | 1686 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1685 | 1687 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1686 | 1688 | } |
| 1687 | 1689 | |
| 1688 | 1690 | (*d3dintf->effect.end)(curr_effect); |
| 1689 | 1691 | |
| 1690 | | /* Convert our signal from YIQ */ |
| 1692 | // Convert our signal from YIQ |
| 1691 | 1693 | curr_effect = yiq_decode_effect; |
| 1692 | 1694 | |
| 1693 | | (*d3dintf->effect.set_texture)(curr_effect, "Composite", rt->texture[4]); |
| 1694 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dfinaltex); |
| 1695 | (*d3dintf->effect.set_texture)(curr_effect, "Composite", rt->render_texture[4]); |
| 1696 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", texture->get_finaltex()); |
| 1695 | 1697 | if(options->params_dirty) |
| 1696 | 1698 | { |
| 1697 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1698 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1699 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart)); |
| 1700 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart)); |
| 1701 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1702 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1699 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1700 | (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x); |
| 1701 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1702 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1703 | 1703 | (*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc); |
| 1704 | 1704 | (*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a); |
| 1705 | | (*d3dintf->effect.set_float)(curr_effect, "BValue", (poly->texture->cur_frame == 2) ? 0.0f : ((float)poly->texture->cur_frame * options->yiq_b)); |
| 1705 | (*d3dintf->effect.set_float)(curr_effect, "BValue", (texture->get_cur_frame() == 2) ? 0.0f : ((float)texture->get_cur_frame() * options->yiq_b)); |
| 1706 | 1706 | (*d3dintf->effect.set_float)(curr_effect, "OValue", options->yiq_o); |
| 1707 | 1707 | (*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p); |
| 1708 | 1708 | (*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n); |
| r22936 | r22937 | |
| 1712 | 1712 | (*d3dintf->effect.set_float)(curr_effect, "ScanTime", options->yiq_scan_time); |
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[3]); |
| 1715 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[3]); |
| 1716 | 1716 | |
| 1717 | 1717 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1718 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1718 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1719 | 1719 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1720 | 1720 | |
| 1721 | 1721 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r22936 | r22937 | |
| 1724 | 1724 | { |
| 1725 | 1725 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1726 | 1726 | // add the primitives |
| 1727 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1727 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1728 | 1728 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1729 | 1729 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1730 | 1730 | } |
| r22936 | r22937 | |
| 1733 | 1733 | |
| 1734 | 1734 | curr_effect = color_effect; |
| 1735 | 1735 | |
| 1736 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[3]); |
| 1736 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[3]); |
| 1737 | 1737 | } |
| 1738 | 1738 | |
| 1739 | 1739 | curr_effect = color_effect; |
| 1740 | 1740 | |
| 1741 | | /* Render the initial color-convolution pass */ |
| 1741 | // Render the initial color-convolution pass |
| 1742 | 1742 | if(options->params_dirty) |
| 1743 | 1743 | { |
| 1744 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1745 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1746 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", options->yiq_enable ? 1.0f : (1.0f / (poly->texture->ustop - poly->texture->ustart))); |
| 1747 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", options->yiq_enable ? 1.0f : (1.0f / (poly->texture->vstop - poly->texture->vstart))); |
| 1748 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1749 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1744 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1745 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1746 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1750 | 1747 | (*d3dintf->effect.set_float)(curr_effect, "YIQEnable", options->yiq_enable ? 1.0f : 0.0f); |
| 1751 | 1748 | (*d3dintf->effect.set_vector)(curr_effect, "RedRatios", 3, options->red_ratio); |
| 1752 | 1749 | (*d3dintf->effect.set_vector)(curr_effect, "GrnRatios", 3, options->grn_ratio); |
| r22936 | r22937 | |
| 1756 | 1753 | (*d3dintf->effect.set_float)(curr_effect, "Saturation", options->saturation); |
| 1757 | 1754 | } |
| 1758 | 1755 | |
| 1759 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->smalltarget); |
| 1756 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->smalltarget); |
| 1760 | 1757 | |
| 1761 | 1758 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1762 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1759 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1763 | 1760 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1764 | 1761 | |
| 1765 | 1762 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r22936 | r22937 | |
| 1768 | 1765 | { |
| 1769 | 1766 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1770 | 1767 | // add the primitives |
| 1771 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1768 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1772 | 1769 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1773 | 1770 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1774 | 1771 | } |
| 1775 | 1772 | |
| 1776 | 1773 | (*d3dintf->effect.end)(curr_effect); |
| 1777 | 1774 | |
| 1778 | | /* Pre-scaling pass */ |
| 1775 | // Pre-scaling pass |
| 1779 | 1776 | curr_effect = prescale_effect; |
| 1780 | 1777 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->smalltexture); |
| 1781 | 1778 | |
| 1782 | 1779 | if(options->params_dirty) |
| 1783 | 1780 | { |
| 1784 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1785 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1786 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1787 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1788 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart)); |
| 1789 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart)); |
| 1781 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1782 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1783 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1790 | 1784 | } |
| 1791 | 1785 | |
| 1792 | 1786 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1793 | 1787 | |
| 1794 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->prescaletarget); |
| 1788 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->prescaletarget); |
| 1795 | 1789 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1796 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1790 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1797 | 1791 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1798 | 1792 | |
| 1799 | 1793 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1800 | 1794 | { |
| 1801 | 1795 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1802 | 1796 | // add the primitives |
| 1803 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1797 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1804 | 1798 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1805 | 1799 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1806 | 1800 | } |
| 1807 | 1801 | |
| 1808 | 1802 | (*d3dintf->effect.end)(curr_effect); |
| 1809 | 1803 | |
| 1810 | | /* Deconverge pass */ |
| 1804 | // Deconverge pass |
| 1811 | 1805 | curr_effect = deconverge_effect; |
| 1812 | 1806 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->prescaletexture); |
| 1813 | 1807 | |
| 1814 | 1808 | if(options->params_dirty) |
| 1815 | 1809 | { |
| 1816 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1817 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1818 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1819 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1820 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart)); |
| 1821 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart)); |
| 1810 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1811 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1812 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 1813 | (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x); |
| 1822 | 1814 | (*d3dintf->effect.set_vector)(curr_effect, "ConvergeX", 3, options->converge_x); |
| 1823 | 1815 | (*d3dintf->effect.set_vector)(curr_effect, "ConvergeY", 3, options->converge_y); |
| 1824 | 1816 | (*d3dintf->effect.set_vector)(curr_effect, "RadialConvergeX", 3, options->radial_converge_x); |
| r22936 | r22937 | |
| 1827 | 1819 | |
| 1828 | 1820 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1829 | 1821 | |
| 1830 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[2]); |
| 1822 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[2]); |
| 1831 | 1823 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 1832 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1824 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1833 | 1825 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1834 | 1826 | |
| 1835 | 1827 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1836 | 1828 | { |
| 1837 | 1829 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1838 | 1830 | // add the primitives |
| 1839 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1831 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1840 | 1832 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1841 | 1833 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1842 | 1834 | } |
| r22936 | r22937 | |
| 1848 | 1840 | bool focus_enable = defocus_x != 0.0f || defocus_y != 0.0f; |
| 1849 | 1841 | if(focus_enable) |
| 1850 | 1842 | { |
| 1851 | | /* Defocus pass 1 */ |
| 1843 | // Defocus pass 1 |
| 1852 | 1844 | curr_effect = focus_effect; |
| 1853 | 1845 | |
| 1854 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[2]); |
| 1846 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[2]); |
| 1855 | 1847 | |
| 1856 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1857 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1858 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1859 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1860 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); |
| 1861 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); |
| 1848 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1849 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1862 | 1850 | (*d3dintf->effect.set_vector)(curr_effect, "Defocus", 2, &options->defocus[0]); |
| 1863 | 1851 | |
| 1864 | 1852 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1865 | 1853 | |
| 1866 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[0]); |
| 1854 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]); |
| 1867 | 1855 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 1868 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1856 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1869 | 1857 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1870 | 1858 | |
| 1871 | 1859 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1872 | 1860 | { |
| 1873 | 1861 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1874 | 1862 | // add the primitives |
| 1875 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1863 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1876 | 1864 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1877 | 1865 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1878 | 1866 | } |
| 1879 | 1867 | |
| 1880 | 1868 | (*d3dintf->effect.end)(curr_effect); |
| 1881 | 1869 | |
| 1882 | | /* Defocus pass 2 */ |
| 1870 | // Defocus pass 2 |
| 1883 | 1871 | |
| 1884 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[0]); |
| 1872 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 1885 | 1873 | |
| 1886 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1887 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1888 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1889 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1890 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f); |
| 1891 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f); |
| 1874 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1875 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1892 | 1876 | (*d3dintf->effect.set_vector)(curr_effect, "Defocus", 2, &options->defocus[1]); |
| 1893 | 1877 | |
| 1894 | 1878 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 1895 | 1879 | |
| 1896 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[1]); |
| 1880 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]); |
| 1897 | 1881 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7\n", (int)result); |
| 1898 | 1882 | |
| 1899 | 1883 | for (UINT pass = 0; pass < num_passes; pass++) |
| 1900 | 1884 | { |
| 1901 | 1885 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1902 | 1886 | // add the primitives |
| 1903 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1887 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1904 | 1888 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1905 | 1889 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1906 | 1890 | } |
| r22936 | r22937 | |
| 1915 | 1899 | |
| 1916 | 1900 | if(options->params_dirty) |
| 1917 | 1901 | { |
| 1918 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1919 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1920 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 1921 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 1922 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart)); |
| 1923 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart)); |
| 1902 | //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)rt->target_width); |
| 1903 | //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)rt->target_height); |
| 1904 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1905 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1924 | 1906 | (*d3dintf->effect.set_vector)(curr_effect, "Phosphor", 3, options->phosphor); |
| 1925 | 1907 | } |
| 1926 | 1908 | (*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)rt->target_width); |
| 1927 | 1909 | (*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)rt->target_height); |
| 1928 | 1910 | (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 0.0f); |
| 1929 | 1911 | |
| 1930 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", focus_enable ? rt->texture[1] : rt->texture[2]); |
| 1912 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", focus_enable ? rt->render_texture[1] : rt->render_texture[2]); |
| 1931 | 1913 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", ct->last_texture); |
| 1932 | 1914 | |
| 1933 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[0]); |
| 1915 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]); |
| 1934 | 1916 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result); |
| 1935 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1917 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1936 | 1918 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1937 | 1919 | |
| 1938 | 1920 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r22936 | r22937 | |
| 1941 | 1923 | { |
| 1942 | 1924 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1943 | 1925 | // add the primitives |
| 1944 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1926 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1945 | 1927 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1946 | 1928 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1947 | 1929 | } |
| 1948 | 1930 | |
| 1949 | 1931 | (*d3dintf->effect.end)(curr_effect); |
| 1950 | 1932 | |
| 1951 | | /* Pass along our phosphor'd screen */ |
| 1933 | // Pass along our phosphor'd screen |
| 1952 | 1934 | curr_effect = phosphor_effect; |
| 1953 | 1935 | |
| 1954 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[0]); |
| 1955 | | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", rt->texture[0]); |
| 1936 | //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1937 | //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1938 | //(*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)d3d->get_width()); |
| 1939 | //(*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)d3d->get_height()); |
| 1940 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 1941 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", rt->render_texture[0]); |
| 1956 | 1942 | (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 1.0f); |
| 1957 | 1943 | |
| 1958 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, ct->last_target); // Avoid changing targets due to page flipping |
| 1944 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, ct->last_target); // Avoid changing targets due to page flipping |
| 1945 | //result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); // Avoid changing targets due to page flipping |
| 1959 | 1946 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result); |
| 1960 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1947 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 1961 | 1948 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 1962 | 1949 | |
| 1963 | 1950 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r22936 | r22937 | |
| 1966 | 1953 | { |
| 1967 | 1954 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1968 | 1955 | // add the primitives |
| 1969 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 1956 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 1970 | 1957 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1971 | 1958 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1972 | 1959 | } |
| r22936 | r22937 | |
| 1974 | 1961 | (*d3dintf->effect.end)(curr_effect); |
| 1975 | 1962 | |
| 1976 | 1963 | curr_effect = post_effect; |
| 1977 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 1978 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 1964 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 1965 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 1979 | 1966 | |
| 1980 | | /* Scanlines and shadow mask, at high res for AVI logging*/ |
| 1967 | // Scanlines and shadow mask, at high res for AVI logging |
| 1981 | 1968 | if(avi_output_file != NULL) |
| 1982 | 1969 | { |
| 1983 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[0]); |
| 1970 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 1984 | 1971 | |
| 1985 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, avi_final_target); |
| 1972 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, avi_final_target); |
| 1986 | 1973 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 1987 | 1974 | |
| 1988 | 1975 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r22936 | r22937 | |
| 1991 | 1978 | { |
| 1992 | 1979 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 1993 | 1980 | // add the primitives |
| 1994 | | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 1981 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 1995 | 1982 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 1996 | 1983 | (*d3dintf->effect.end_pass)(curr_effect); |
| 1997 | 1984 | } |
| r22936 | r22937 | |
| 2001 | 1988 | |
| 2002 | 1989 | if(render_snap) |
| 2003 | 1990 | { |
| 2004 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[0]); |
| 1991 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 2005 | 1992 | |
| 2006 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, snap_target); |
| 1993 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, snap_target); |
| 2007 | 1994 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2008 | 1995 | |
| 2009 | 1996 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r22936 | r22937 | |
| 2012 | 1999 | { |
| 2013 | 2000 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2014 | 2001 | // add the primitives |
| 2015 | | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2002 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2016 | 2003 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2017 | 2004 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2018 | 2005 | } |
| r22936 | r22937 | |
| 2022 | 2009 | snap_rendered = true; |
| 2023 | 2010 | } |
| 2024 | 2011 | |
| 2025 | | /* Scanlines and shadow mask */ |
| 2012 | // Scanlines and shadow mask |
| 2026 | 2013 | curr_effect = post_effect; |
| 2027 | 2014 | |
| 2028 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[0]); |
| 2015 | //float raw_dims[2] = { d3d->get_width(), d3d->get_height() }; |
| 2016 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 2017 | (*d3dintf->effect.set_vector)(curr_effect, "RawDims", 2, &rawdims.c.x); |
| 2018 | (*d3dintf->effect.set_vector)(curr_effect, "SizeRatio", 2, &delta.c.x); |
| 2029 | 2019 | |
| 2020 | d3d->set_wrap(D3DTADDRESS_MIRROR); |
| 2021 | |
| 2022 | #if CRT_BLOOM |
| 2030 | 2023 | //(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)rt->target_width); |
| 2031 | 2024 | //(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)rt->target_height); |
| 2025 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2026 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2032 | 2027 | |
| 2033 | | #if HLSL_VECTOR |
| 2034 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[1]); |
| 2028 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[2]); |
| 2029 | |
| 2030 | d3d->set_wrap(D3DTADDRESS_MIRROR); |
| 2031 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(1,0,0,0), 0, 0); |
| 2032 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2035 | 2033 | #else |
| 2036 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 2034 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2035 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2036 | |
| 2037 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2037 | 2038 | #endif |
| 2038 | 2039 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2039 | 2040 | |
| r22936 | r22937 | |
| 2043 | 2044 | { |
| 2044 | 2045 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2045 | 2046 | // add the primitives |
| 2046 | | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2047 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2047 | 2048 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2048 | 2049 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2049 | 2050 | } |
| 2050 | 2051 | |
| 2051 | 2052 | (*d3dintf->effect.end)(curr_effect); |
| 2052 | 2053 | |
| 2053 | | #if HLSL_VECTOR |
| 2054 | | /* Bloom */ |
| 2054 | d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(poly->get_texture()->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); |
| 2055 | |
| 2056 | #if CRT_BLOOM |
| 2057 | // Bloom |
| 2055 | 2058 | curr_effect = downsample_effect; |
| 2056 | 2059 | |
| 2057 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[1]); |
| 2060 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[2]); |
| 2058 | 2061 | |
| 2059 | | int bloom_size = (rt->target_width < rt->target_height) ? rt->target_width : rt->target_height; |
| 2062 | int bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height(); |
| 2060 | 2063 | int bloom_index = 0; |
| 2061 | | int bloom_width = rt->target_width; |
| 2062 | | int bloom_height = rt->target_height; |
| 2064 | int bloom_width = d3d->get_width(); |
| 2065 | int bloom_height = d3d->get_height(); |
| 2063 | 2066 | for(; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1) |
| 2064 | 2067 | { |
| 2065 | 2068 | float source_size[2] = { bloom_width, bloom_height }; |
| r22936 | r22937 | |
| 2069 | 2072 | |
| 2070 | 2073 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2071 | 2074 | |
| 2072 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", (bloom_index == 0) ? rt->texture[1] : ct->bloom_texture[bloom_index - 1]); |
| 2075 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", (bloom_index == 0) ? rt->render_texture[2] : rt->bloom_texture[bloom_index - 1]); |
| 2073 | 2076 | |
| 2074 | | if (ct->bloom_target[bloom_index] == NULL) |
| 2075 | | { |
| 2076 | | (*d3dintf->effect.end)(curr_effect); |
| 2077 | | break; |
| 2078 | | } |
| 2079 | | |
| 2080 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, ct->bloom_target[bloom_index]); |
| 2081 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7:%d\n", (int)result, bloom_size); |
| 2082 | | //result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2077 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->bloom_target[bloom_index]); |
| 2078 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2079 | //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2083 | 2080 | //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2084 | 2081 | |
| 2085 | 2082 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2086 | 2083 | { |
| 2087 | 2084 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2088 | 2085 | // add the primitives |
| 2089 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 2086 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 2087 | //result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2090 | 2088 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2091 | 2089 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2092 | 2090 | } |
| r22936 | r22937 | |
| 2098 | 2096 | bloom_height >>= 1; |
| 2099 | 2097 | } |
| 2100 | 2098 | |
| 2101 | | /* Bloom composite pass*/ |
| 2099 | // Bloom composite pass |
| 2102 | 2100 | curr_effect = bloom_effect; |
| 2103 | 2101 | |
| 2104 | | float target_size[2] = { rt->target_width, rt->target_height }; |
| 2102 | float target_size[2] = { d3d->get_width(), d3d->get_height() }; |
| 2105 | 2103 | (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size); |
| 2104 | float weight0123[4] = { options->bloom_level0_weight, options->bloom_level1_weight, |
| 2105 | options->bloom_level2_weight, options->bloom_level3_weight }; |
| 2106 | float weight4567[4] = { options->bloom_level4_weight, options->bloom_level5_weight, |
| 2107 | options->bloom_level6_weight, options->bloom_level7_weight }; |
| 2108 | float weight89A[3] = { options->bloom_level8_weight, options->bloom_level9_weight, |
| 2109 | options->bloom_level10_weight }; |
| 2110 | (*d3dintf->effect.set_vector)(curr_effect, "Level0123Weight", 4, weight0123); |
| 2111 | (*d3dintf->effect.set_vector)(curr_effect, "Level4567Weight", 4, weight4567); |
| 2112 | (*d3dintf->effect.set_vector)(curr_effect, "Level89AWeight", 3, weight89A); |
| 2113 | (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size); |
| 2106 | 2114 | |
| 2107 | | (*d3dintf->effect.set_texture)(curr_effect, "DiffuseA", rt->texture[1]); |
| 2115 | (*d3dintf->effect.set_texture)(curr_effect, "DiffuseA", rt->render_texture[2]); |
| 2108 | 2116 | (*d3dintf->effect.set_float)(curr_effect, "DiffuseScaleA", 1.0f); |
| 2109 | 2117 | |
| 2110 | 2118 | char name[9] = "Diffuse*"; |
| r22936 | r22937 | |
| 2113 | 2121 | { |
| 2114 | 2122 | name[7] = 'A' + index; |
| 2115 | 2123 | scale[12] = 'A' + index; |
| 2116 | | (*d3dintf->effect.set_texture)(curr_effect, name, ct->bloom_texture[index - 1]); |
| 2124 | (*d3dintf->effect.set_texture)(curr_effect, name, rt->bloom_texture[index - 1]); |
| 2117 | 2125 | (*d3dintf->effect.set_float)(curr_effect, scale, 1.0f); |
| 2118 | 2126 | } |
| 2119 | 2127 | for(int index = bloom_index; index < 11; index++) |
| r22936 | r22937 | |
| 2126 | 2134 | |
| 2127 | 2135 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2128 | 2136 | |
| 2129 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[2]); |
| 2130 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 8\n", (int)result); |
| 2137 | //HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]); |
| 2138 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2139 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2140 | //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2141 | //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2131 | 2142 | |
| 2132 | 2143 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2133 | 2144 | { |
| 2134 | 2145 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2135 | 2146 | // add the primitives |
| 2136 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 2147 | //result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 2148 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2137 | 2149 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2138 | 2150 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2139 | 2151 | } |
| 2140 | 2152 | |
| 2141 | 2153 | (*d3dintf->effect.end)(curr_effect); |
| 2142 | | |
| 2143 | | curr_effect = effect; |
| 2144 | | |
| 2145 | | //(*d3dintf->effect.set_float)(curr_effect, "PostPass", 1.0f); |
| 2146 | | |
| 2147 | | //blit(backbuffer, ct->last_texture, NULL, poly->type, vertnum, poly->count, d3d->width, d3d->height); |
| 2148 | | |
| 2149 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 2150 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 9\n", (int)result); |
| 2151 | | |
| 2152 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[2]); |
| 2153 | | |
| 2154 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); |
| 2155 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f); |
| 2156 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); |
| 2157 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); |
| 2158 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2159 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2160 | | (*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f); |
| 2161 | | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion); |
| 2162 | | |
| 2163 | | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2164 | | |
| 2165 | | for (UINT pass = 0; pass < num_passes; pass++) |
| 2166 | | { |
| 2167 | | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2168 | | // add the primitives |
| 2169 | | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2170 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2171 | | (*d3dintf->effect.end_pass)(curr_effect); |
| 2172 | | } |
| 2173 | | |
| 2174 | | (*d3dintf->effect.end)(curr_effect); |
| 2175 | 2154 | #endif |
| 2155 | texture->increment_frame_count(); |
| 2156 | texture->mask_frame_count(options->yiq_phase_count); |
| 2176 | 2157 | |
| 2177 | | poly->texture->cur_frame++; |
| 2178 | | poly->texture->cur_frame %= options->yiq_phase_count; |
| 2179 | | |
| 2180 | 2158 | options->params_dirty = false; |
| 2159 | |
| 2181 | 2160 | } |
| 2182 | 2161 | #if HLSL_VECTOR |
| 2183 | | else if(PRIMFLAG_GET_VECTOR(poly->flags) && vector_enable) |
| 2162 | else if(PRIMFLAG_GET_VECTOR(poly->get_flags()) && vector_enable) |
| 2184 | 2163 | { |
| 2185 | | d3d_render_target *rt = find_render_target(d3d->width, d3d->height, 0, 0); |
| 2164 | render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 2186 | 2165 | if (rt == NULL) |
| 2187 | 2166 | { |
| 2188 | 2167 | return; |
| r22936 | r22937 | |
| 2191 | 2170 | lines_pending = true; |
| 2192 | 2171 | |
| 2193 | 2172 | curr_effect = vector_effect; |
| 2194 | | //curr_effect = effect; |
| 2195 | 2173 | |
| 2196 | 2174 | if(options->params_dirty) |
| 2197 | 2175 | { |
| 2198 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2199 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2176 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2177 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2200 | 2178 | } |
| 2201 | 2179 | |
| 2202 | | float time_params[2] = { poly->line_time, options->vector_time_scale }; |
| 2203 | | float length_params[3] = { poly->line_length, options->vector_length_scale, options->vector_length_ratio }; |
| 2180 | float time_params[2] = { poly->get_line_time(), options->vector_time_scale }; |
| 2181 | float length_params[3] = { poly->get_line_length(), options->vector_length_scale, options->vector_length_ratio }; |
| 2204 | 2182 | (*d3dintf->effect.set_vector)(curr_effect, "TimeParams", 2, time_params); |
| 2205 | 2183 | (*d3dintf->effect.set_vector)(curr_effect, "LengthParams", 3, length_params); |
| 2206 | 2184 | |
| 2207 | 2185 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2208 | 2186 | |
| 2209 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[0]); |
| 2187 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]); |
| 2210 | 2188 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2211 | 2189 | |
| 2212 | 2190 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2213 | 2191 | { |
| 2214 | 2192 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2215 | 2193 | // add the primitives |
| 2216 | | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2194 | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2217 | 2195 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2218 | 2196 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2219 | 2197 | } |
| 2220 | 2198 | |
| 2221 | 2199 | (*d3dintf->effect.end)(curr_effect); |
| 2222 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 2200 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2223 | 2201 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2224 | 2202 | |
| 2225 | | curr_effect = effect; |
| 2203 | curr_effect = default_effect; |
| 2226 | 2204 | |
| 2227 | 2205 | (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f); |
| 2228 | 2206 | } |
| 2229 | | else if (PRIMFLAG_GET_VECTORBUF(poly->flags) && vector_enable) |
| 2207 | else if (PRIMFLAG_GET_VECTORBUF(poly->get_flags()) && vector_enable) |
| 2230 | 2208 | { |
| 2231 | 2209 | //if (!lines_pending) |
| 2232 | 2210 | //return; |
| 2233 | 2211 | //lines_pending = false; |
| 2234 | 2212 | |
| 2235 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 2213 | renderer *d3d = (renderer *)window->drawdata; |
| 2236 | 2214 | |
| 2237 | | d3d_render_target *rt = find_render_target(d3d->width, d3d->height, 0, 0); |
| 2215 | render_target *rt = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 2238 | 2216 | if (rt == NULL) |
| 2239 | 2217 | { |
| 2240 | 2218 | return; |
| r22936 | r22937 | |
| 2243 | 2221 | /* Bloom */ |
| 2244 | 2222 | curr_effect = downsample_effect; |
| 2245 | 2223 | |
| 2246 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[0]); |
| 2224 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[0]); |
| 2247 | 2225 | |
| 2248 | | int bloom_size = (d3d->width < d3d->height) ? d3d->width : d3d->height; |
| 2226 | int bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height(); |
| 2249 | 2227 | int bloom_index = 0; |
| 2250 | | int bloom_width = d3d->width; |
| 2251 | | int bloom_height = d3d->height; |
| 2228 | int bloom_width = d3d->get_width(); |
| 2229 | int bloom_height = d3d->get_height(); |
| 2252 | 2230 | for(; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1) |
| 2253 | 2231 | { |
| 2254 | 2232 | float source_size[2] = { bloom_width, bloom_height }; |
| r22936 | r22937 | |
| 2258 | 2236 | |
| 2259 | 2237 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2260 | 2238 | |
| 2261 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", (bloom_index == 0) ? rt->texture[0] : rt->bloom_texture[bloom_index - 1]); |
| 2239 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", (bloom_index == 0) ? rt->render_texture[0] : rt->bloom_texture[bloom_index - 1]); |
| 2262 | 2240 | |
| 2263 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->bloom_target[bloom_index]); |
| 2241 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->bloom_target[bloom_index]); |
| 2264 | 2242 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2265 | | //result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2243 | //result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2266 | 2244 | //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2267 | 2245 | |
| 2268 | 2246 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2269 | 2247 | { |
| 2270 | 2248 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2271 | 2249 | // add the primitives |
| 2272 | | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2250 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2273 | 2251 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2274 | 2252 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2275 | 2253 | } |
| r22936 | r22937 | |
| 2281 | 2259 | bloom_height >>= 1; |
| 2282 | 2260 | } |
| 2283 | 2261 | |
| 2284 | | /* Bloom composite pass*/ |
| 2262 | // Bloom composite pass |
| 2285 | 2263 | curr_effect = bloom_effect; |
| 2286 | 2264 | |
| 2287 | | float target_size[2] = { d3d->width, d3d->height }; |
| 2265 | float target_size[2] = { d3d->get_width(), d3d->get_height() }; |
| 2288 | 2266 | (*d3dintf->effect.set_vector)(curr_effect, "TargetSize", 2, target_size); |
| 2289 | 2267 | |
| 2290 | | (*d3dintf->effect.set_texture)(curr_effect, "DiffuseA", rt->texture[0]); |
| 2268 | (*d3dintf->effect.set_texture)(curr_effect, "DiffuseA", rt->render_texture[0]); |
| 2291 | 2269 | (*d3dintf->effect.set_float)(curr_effect, "DiffuseScaleA", 1.0f); |
| 2292 | 2270 | |
| 2293 | 2271 | char name[9] = "Diffuse*"; |
| r22936 | r22937 | |
| 2309 | 2287 | |
| 2310 | 2288 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2311 | 2289 | |
| 2312 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[1]); |
| 2290 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[1]); |
| 2313 | 2291 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); |
| 2314 | | //result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2315 | | //if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2292 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2293 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2316 | 2294 | |
| 2317 | 2295 | for (UINT pass = 0; pass < num_passes; pass++) |
| 2318 | 2296 | { |
| 2319 | 2297 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2320 | 2298 | // add the primitives |
| 2321 | | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2299 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2322 | 2300 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2323 | 2301 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2324 | 2302 | } |
| r22936 | r22937 | |
| 2330 | 2308 | |
| 2331 | 2309 | if(options->params_dirty) |
| 2332 | 2310 | { |
| 2333 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2334 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2311 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2312 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2335 | 2313 | (*d3dintf->effect.set_vector)(curr_effect, "Phosphor", 3, options->phosphor); |
| 2336 | 2314 | } |
| 2337 | | (*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)d3d->width); |
| 2338 | | (*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)d3d->height); |
| 2315 | (*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)d3d->get_width()); |
| 2316 | (*d3dintf->effect.set_float)(curr_effect, "TextureHeight", (float)d3d->get_height()); |
| 2339 | 2317 | (*d3dintf->effect.set_float)(curr_effect, "Passthrough", 0.0f); |
| 2340 | 2318 | |
| 2341 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[1]); |
| 2342 | | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", rt->texture[2]); |
| 2319 | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->render_texture[1]); |
| 2320 | (*d3dintf->effect.set_texture)(curr_effect, "LastPass", rt->render_texture[2]); |
| 2343 | 2321 | |
| 2344 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[0]); |
| 2322 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[3]); |
| 2345 | 2323 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 4\n", (int)result); |
| 2346 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2324 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2347 | 2325 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2348 | 2326 | |
| 2349 | 2327 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| r22936 | r22937 | |
| 2352 | 2330 | { |
| 2353 | 2331 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2354 | 2332 | // add the primitives |
| 2355 | | result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLELIST, 0, 2); |
| 2333 | result = (*d3dintf->device.draw_primitive)(d3d->get_device(), D3DPT_TRIANGLELIST, 0, 2); |
| 2356 | 2334 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2357 | 2335 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2358 | 2336 | } |
| 2359 | 2337 | |
| 2360 | 2338 | (*d3dintf->effect.end)(curr_effect); |
| 2361 | 2339 | |
| 2362 | | //curr_effect = effect; |
| 2340 | blit(rt->target[2], rt->render_texture[3], NULL, poly->get_type(), vertnum, poly->get_count()); |
| 2341 | blit(backbuffer, rt->render_texture[3], backbuffer, poly->get_type(), vertnum, poly->get_count()); |
| 2363 | 2342 | |
| 2364 | | //blit(backbuffer, rt->bloom_texture[5], NULL, poly->type, vertnum, poly->count); |
| 2365 | | //blit(rt->target[2], rt->texture[0], NULL, poly->type, vertnum, poly->count); |
| 2366 | | blit(backbuffer, rt->texture[0], NULL, poly->type, vertnum, poly->count); |
| 2367 | | //blit(backbuffer, rt->texture[0], NULL, poly->type, vertnum, poly->count); |
| 2368 | | |
| 2369 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[0]); |
| 2343 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, rt->target[0]); |
| 2370 | 2344 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2371 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2345 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2372 | 2346 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2373 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 2347 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2374 | 2348 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2375 | 2349 | |
| 2376 | | /*curr_effect = post_effect; |
| 2377 | | |
| 2378 | | (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[0]); |
| 2379 | | |
| 2380 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2381 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2382 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); |
| 2383 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); |
| 2384 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart)); |
| 2385 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart)); |
| 2386 | | |
| 2387 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[1]); |
| 2388 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2389 | | |
| 2390 | | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2391 | | |
| 2392 | | for (UINT pass = 0; pass < num_passes; pass++) |
| 2393 | | { |
| 2394 | | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2395 | | // add the primitives |
| 2396 | | result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2397 | | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2398 | | (*d3dintf->effect.end_pass)(curr_effect); |
| 2399 | | } |
| 2400 | | |
| 2401 | | (*d3dintf->effect.end)(curr_effect);*/ |
| 2402 | | |
| 2403 | | vecbuf_type = poly->type; |
| 2404 | | vecbuf_index = vertnum; |
| 2405 | | vecbuf_count = poly->count; |
| 2350 | lines_pending = false; |
| 2406 | 2351 | } |
| 2352 | #else |
| 2353 | else if (PRIMFLAG_GET_VECTORBUF(poly->get_flags()) && vector_enable) |
| 2354 | { |
| 2355 | // Do nothing |
| 2356 | } |
| 2407 | 2357 | #endif |
| 2408 | 2358 | else |
| 2409 | 2359 | { |
| 2410 | | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); |
| 2411 | | (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f); |
| 2412 | | (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); |
| 2413 | | (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); |
| 2414 | | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); |
| 2415 | | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); |
| 2360 | curr_effect = default_effect; |
| 2361 | |
| 2362 | (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->get_width()); |
| 2363 | (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->get_height()); |
| 2416 | 2364 | (*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f); |
| 2417 | | (*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion); |
| 2418 | 2365 | |
| 2419 | 2366 | (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); |
| 2420 | 2367 | |
| r22936 | r22937 | |
| 2422 | 2369 | { |
| 2423 | 2370 | (*d3dintf->effect.begin_pass)(curr_effect, pass); |
| 2424 | 2371 | // add the primitives |
| 2425 | | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); |
| 2372 | HRESULT result = (*d3dintf->device.draw_primitive)(d3d->get_device(), poly->get_type(), vertnum, poly->get_count()); |
| 2426 | 2373 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); |
| 2427 | 2374 | (*d3dintf->effect.end_pass)(curr_effect); |
| 2428 | 2375 | } |
| r22936 | r22937 | |
| 2434 | 2381 | |
| 2435 | 2382 | |
| 2436 | 2383 | //============================================================ |
| 2437 | | // hlsl_info::end_draw |
| 2384 | // shaders::end_draw |
| 2438 | 2385 | //============================================================ |
| 2439 | 2386 | |
| 2440 | | void hlsl_info::end_draw() |
| 2387 | void shaders::end_draw() |
| 2441 | 2388 | { |
| 2442 | 2389 | if (!master_enable || !d3dintf->post_fx_available) |
| 2443 | 2390 | return; |
| r22936 | r22937 | |
| 2447 | 2394 | |
| 2448 | 2395 | |
| 2449 | 2396 | //============================================================ |
| 2450 | | // hlsl_info::register_prescaled_texture |
| 2397 | // shaders::register_prescaled_texture |
| 2451 | 2398 | //============================================================ |
| 2452 | 2399 | |
| 2453 | | bool hlsl_info::register_prescaled_texture(d3d_texture_info *texture) |
| 2400 | bool shaders::register_prescaled_texture(texture_info *texture) |
| 2454 | 2401 | { |
| 2455 | | return register_texture(texture, texture->rawwidth, texture->rawheight, texture->xprescale, texture->yprescale); |
| 2402 | return register_texture(texture); |
| 2456 | 2403 | } |
| 2457 | 2404 | |
| 2458 | 2405 | |
| 2459 | 2406 | //============================================================ |
| 2460 | | // hlsl_info::add_cache_target - register a cache target |
| 2407 | // shaders::add_cache_target - register a cache target |
| 2461 | 2408 | //============================================================ |
| 2462 | | bool hlsl_info::add_cache_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index) |
| 2409 | bool shaders::add_cache_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index) |
| 2463 | 2410 | { |
| 2464 | | d3d_cache_target* target = (d3d_cache_target*)global_alloc_clear(d3d_cache_target); |
| 2411 | cache_target* target = (cache_target*)global_alloc_clear(cache_target); |
| 2465 | 2412 | |
| 2466 | | if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale, false)) |
| 2413 | if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale)) |
| 2467 | 2414 | { |
| 2468 | 2415 | global_free(target); |
| 2469 | 2416 | return false; |
| r22936 | r22937 | |
| 2471 | 2418 | |
| 2472 | 2419 | if (info != NULL) |
| 2473 | 2420 | { |
| 2474 | | target->width = info->texinfo.width; |
| 2475 | | target->height = info->texinfo.height; |
| 2421 | target->width = info->get_texinfo().width; |
| 2422 | target->height = info->get_texinfo().height; |
| 2476 | 2423 | } |
| 2477 | 2424 | else |
| 2478 | 2425 | { |
| 2479 | | target->width = d3d->width; |
| 2480 | | target->height = d3d->height; |
| 2426 | target->width = d3d->get_width(); |
| 2427 | target->height = d3d->get_height(); |
| 2481 | 2428 | } |
| 2482 | 2429 | |
| 2483 | 2430 | target->next = cachehead; |
| r22936 | r22937 | |
| 2494 | 2441 | return true; |
| 2495 | 2442 | } |
| 2496 | 2443 | |
| 2497 | | d3d_render_target* hlsl_info::get_vector_target() |
| 2444 | render_target* shaders::get_vector_target() |
| 2498 | 2445 | { |
| 2499 | 2446 | #if HLSL_VECTOR |
| 2500 | 2447 | if (!vector_enable) |
| r22936 | r22937 | |
| 2502 | 2449 | return false; |
| 2503 | 2450 | } |
| 2504 | 2451 | |
| 2505 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 2452 | renderer *d3d = (renderer *)window->drawdata; |
| 2506 | 2453 | |
| 2507 | | return find_render_target(d3d->width, d3d->height, 0, 0); |
| 2508 | | #endif |
| 2454 | return find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 2455 | #else |
| 2509 | 2456 | return NULL; |
| 2457 | #endif |
| 2510 | 2458 | } |
| 2511 | 2459 | |
| 2512 | | void hlsl_info::create_vector_target(render_primitive *prim) |
| 2460 | void shaders::create_vector_target(render_primitive *prim) |
| 2513 | 2461 | { |
| 2514 | 2462 | #if HLSL_VECTOR |
| 2515 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 2516 | | if (!add_render_target(d3d, NULL, d3d->width, d3d->height, 1, 1, true)) |
| 2463 | renderer *d3d = (renderer *)window->drawdata; |
| 2464 | if (!add_render_target(d3d, NULL, d3d->get_width(), d3d->get_height(), 1, 1)) |
| 2517 | 2465 | { |
| 2518 | 2466 | vector_enable = false; |
| 2519 | 2467 | } |
| r22936 | r22937 | |
| 2521 | 2469 | } |
| 2522 | 2470 | |
| 2523 | 2471 | //============================================================ |
| 2524 | | // hlsl_info::add_render_target - register a render target |
| 2472 | // shaders::add_render_target - register a render target |
| 2525 | 2473 | //============================================================ |
| 2526 | 2474 | |
| 2527 | | bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, bool bloom) |
| 2475 | bool shaders::add_render_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale) |
| 2528 | 2476 | { |
| 2529 | 2477 | UINT32 screen_index = 0; |
| 2530 | 2478 | UINT32 page_index = 0; |
| 2531 | 2479 | if (info != NULL) |
| 2532 | 2480 | { |
| 2533 | | d3d_render_target *existing_target = find_render_target(info); |
| 2481 | render_target *existing_target = find_render_target(info); |
| 2534 | 2482 | if (existing_target != NULL) |
| 2535 | 2483 | { |
| 2536 | 2484 | remove_render_target(existing_target); |
| 2537 | 2485 | } |
| 2538 | 2486 | |
| 2539 | | UINT32 screen_index_data = (UINT32)info->texinfo.osddata; |
| 2487 | UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata; |
| 2540 | 2488 | screen_index = screen_index_data >> 1; |
| 2541 | 2489 | page_index = screen_index_data & 1; |
| 2542 | 2490 | } |
| 2543 | 2491 | else |
| 2544 | 2492 | { |
| 2545 | | d3d_render_target *existing_target = find_render_target(d3d->width, d3d->height, 0, 0); |
| 2493 | render_target *existing_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0); |
| 2546 | 2494 | if (existing_target != NULL) |
| 2547 | 2495 | { |
| 2548 | 2496 | remove_render_target(existing_target); |
| 2549 | 2497 | } |
| 2550 | 2498 | } |
| 2551 | 2499 | |
| 2552 | | d3d_render_target* target = (d3d_render_target*)global_alloc_clear(d3d_render_target); |
| 2500 | render_target* target = (render_target*)global_alloc_clear(render_target); |
| 2553 | 2501 | |
| 2554 | | if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale, bloom)) |
| 2502 | if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale)) |
| 2555 | 2503 | { |
| 2556 | 2504 | global_free(target); |
| 2557 | 2505 | return false; |
| r22936 | r22937 | |
| 2559 | 2507 | |
| 2560 | 2508 | if (info != NULL) |
| 2561 | 2509 | { |
| 2562 | | target->width = info->texinfo.width; |
| 2563 | | target->height = info->texinfo.height; |
| 2510 | target->width = info->get_texinfo().width; |
| 2511 | target->height = info->get_texinfo().height; |
| 2564 | 2512 | } |
| 2565 | 2513 | else |
| 2566 | 2514 | { |
| 2567 | | target->width = d3d->width; |
| 2568 | | target->height = d3d->height; |
| 2515 | target->width = d3d->get_width(); |
| 2516 | target->height = d3d->get_height(); |
| 2569 | 2517 | } |
| 2570 | 2518 | |
| 2571 | | HRESULT result = (*d3dintf->device.set_render_target)(d3d->device, 0, target->target[0]); |
| 2519 | HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, target->target[0]); |
| 2572 | 2520 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2573 | | result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2521 | result = (*d3dintf->device.clear)(d3d->get_device(), 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); |
| 2574 | 2522 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); |
| 2575 | | result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer); |
| 2523 | result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer); |
| 2576 | 2524 | if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); |
| 2577 | 2525 | |
| 2578 | 2526 | target->screen_index = screen_index; |
| 2579 | 2527 | target->page_index = page_index; |
| 2580 | 2528 | |
| 2581 | | d3d_cache_target* cache = find_cache_target(target->screen_index, target->width, target->height); |
| 2529 | cache_target* cache = find_cache_target(target->screen_index, target->width, target->height); |
| 2582 | 2530 | if (cache == NULL) |
| 2583 | 2531 | { |
| 2584 | 2532 | if (!add_cache_target(d3d, info, width, height, xprescale, yprescale, target->screen_index)) |
| r22936 | r22937 | |
| 2601 | 2549 | } |
| 2602 | 2550 | |
| 2603 | 2551 | //============================================================ |
| 2604 | | // hlsl_info::enumerate_screens |
| 2552 | // shaders::enumerate_screens |
| 2605 | 2553 | //============================================================ |
| 2606 | | void hlsl_info::enumerate_screens() |
| 2554 | void shaders::enumerate_screens() |
| 2607 | 2555 | { |
| 2608 | 2556 | screen_device_iterator iter(window->machine().root_device()); |
| 2609 | 2557 | num_screens = iter.count(); |
| r22936 | r22937 | |
| 2611 | 2559 | |
| 2612 | 2560 | |
| 2613 | 2561 | //============================================================ |
| 2614 | | // hlsl_info::register_texture |
| 2562 | // shaders::register_texture(texture::info) |
| 2615 | 2563 | //============================================================ |
| 2616 | 2564 | |
| 2617 | | bool hlsl_info::register_texture(d3d_texture_info *texture) |
| 2565 | bool shaders::register_texture(texture_info *texture) |
| 2618 | 2566 | { |
| 2619 | | return register_texture(texture, texture->rawwidth, texture->rawheight, 1, 1); |
| 2620 | | } |
| 2567 | int width = texture->get_width(); |
| 2568 | int height = texture->get_height(); |
| 2569 | int xscale = texture->get_xscale(); |
| 2570 | int yscale = texture->get_yscale(); |
| 2621 | 2571 | |
| 2622 | | |
| 2623 | | //============================================================ |
| 2624 | | // hlsl_info::register_texture(d3d_texture_info, int, int, int, int) |
| 2625 | | //============================================================ |
| 2626 | | |
| 2627 | | bool hlsl_info::register_texture(d3d_texture_info *texture, int width, int height, int xscale, int yscale) |
| 2628 | | { |
| 2629 | 2572 | if (!master_enable || !d3dintf->post_fx_available) |
| 2630 | | return 0; |
| 2573 | { |
| 2574 | return false; |
| 2575 | } |
| 2631 | 2576 | |
| 2632 | 2577 | enumerate_screens(); |
| 2633 | 2578 | |
| 2634 | | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 2579 | renderer *d3d = (renderer *)window->drawdata; |
| 2635 | 2580 | |
| 2636 | 2581 | int hlsl_prescale_x = prescale_force_x; |
| 2637 | 2582 | int hlsl_prescale_y = prescale_force_y; |
| r22936 | r22937 | |
| 2640 | 2585 | if (hlsl_prescale_x == 0) |
| 2641 | 2586 | { |
| 2642 | 2587 | hlsl_prescale_x = 1; |
| 2643 | | while (width * xscale * hlsl_prescale_x <= d3d->width) |
| 2588 | while (width * xscale * hlsl_prescale_x <= d3d->get_width()) |
| 2644 | 2589 | { |
| 2645 | 2590 | hlsl_prescale_x++; |
| 2646 | 2591 | } |
| r22936 | r22937 | |
| 2650 | 2595 | if (hlsl_prescale_y == 0) |
| 2651 | 2596 | { |
| 2652 | 2597 | hlsl_prescale_y = 1; |
| 2653 | | while (height * yscale * hlsl_prescale_y <= d3d->height) |
| 2598 | while (height * yscale * hlsl_prescale_y <= d3d->get_height()) |
| 2654 | 2599 | { |
| 2655 | 2600 | hlsl_prescale_y++; |
| 2656 | 2601 | } |
| r22936 | r22937 | |
| 2669 | 2614 | } |
| 2670 | 2615 | |
| 2671 | 2616 | //============================================================ |
| 2672 | | // hlsl_info::delete_resources |
| 2617 | // shaders::delete_resources |
| 2673 | 2618 | //============================================================ |
| 2674 | 2619 | |
| 2675 | | void hlsl_info::delete_resources(bool reset) |
| 2620 | void shaders::delete_resources(bool reset) |
| 2676 | 2621 | { |
| 2677 | 2622 | if (!master_enable || !d3dintf->post_fx_available) |
| 2678 | 2623 | return; |
| r22936 | r22937 | |
| 2682 | 2627 | if(write_ini && !reset) |
| 2683 | 2628 | { |
| 2684 | 2629 | emu_file file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 2685 | | file_error filerr = open_next((d3d_info*)window->drawdata, file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0); |
| 2630 | file_error filerr = open_next((renderer*)window->drawdata, file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0); |
| 2686 | 2631 | |
| 2687 | 2632 | if (filerr != FILERR_NONE) |
| 2688 | 2633 | return; |
| r22936 | r22937 | |
| 2744 | 2689 | remove_render_target(targethead); |
| 2745 | 2690 | } |
| 2746 | 2691 | |
| 2747 | | #if HLSL_VECTOR |
| 2692 | #if (HLSL_VECTOR || CRT_BLOOM) |
| 2748 | 2693 | if (downsample_effect != NULL) |
| 2749 | 2694 | { |
| 2750 | 2695 | (*d3dintf->effect.release)(downsample_effect); |
| r22936 | r22937 | |
| 2756 | 2701 | bloom_effect = NULL; |
| 2757 | 2702 | } |
| 2758 | 2703 | #endif |
| 2759 | | if (effect != NULL) |
| 2704 | if (default_effect != NULL) |
| 2760 | 2705 | { |
| 2761 | | (*d3dintf->effect.release)(effect); |
| 2762 | | effect = NULL; |
| 2706 | (*d3dintf->effect.release)(default_effect); |
| 2707 | default_effect = NULL; |
| 2763 | 2708 | } |
| 2764 | 2709 | if (post_effect != NULL) |
| 2765 | 2710 | { |
| r22936 | r22937 | |
| 3237 | 3182 | // init_slider_list |
| 3238 | 3183 | //============================================================ |
| 3239 | 3184 | |
| 3240 | | slider_state *hlsl_info::init_slider_list() |
| 3185 | slider_state *shaders::init_slider_list() |
| 3241 | 3186 | { |
| 3242 | 3187 | if (!master_enable || !d3dintf->post_fx_available) |
| 3243 | 3188 | { |
| r22936 | r22937 | |
| 3307 | 3252 | return listhead; |
| 3308 | 3253 | } |
| 3309 | 3254 | |
| 3255 | }; |
| 3256 | |
| 3310 | 3257 | //============================================================ |
| 3311 | 3258 | // get_slider_list |
| 3312 | 3259 | //============================================================ |
| r22936 | r22937 | |
| 3325 | 3272 | // scheme |
| 3326 | 3273 | //------------------------------------------------- |
| 3327 | 3274 | |
| 3328 | | static file_error open_next(d3d_info *d3d, emu_file &file, const char *templ, const char *extension, int idx) |
| 3275 | static file_error open_next(d3d::renderer *d3d, emu_file &file, const char *templ, const char *extension, int idx) |
| 3329 | 3276 | { |
| 3330 | 3277 | UINT32 origflags = file.openflags(); |
| 3331 | 3278 | |
| 3332 | 3279 | // handle defaults |
| 3333 | | const char *snapname = templ ? templ : d3d->window->machine().options().snap_name(); |
| 3280 | const char *snapname = templ ? templ : d3d->get_window()->machine().options().snap_name(); |
| 3334 | 3281 | |
| 3335 | 3282 | if (snapname == NULL || snapname[0] == 0) |
| 3336 | 3283 | snapname = "%g/%i"; |
| r22936 | r22937 | |
| 3377 | 3324 | snapdevname.cpysubstr(snapstr, pos + 3, end - pos - 3); |
| 3378 | 3325 | |
| 3379 | 3326 | // verify that there is such a device for this system |
| 3380 | | image_interface_iterator iter(d3d->window->machine().root_device()); |
| 3327 | image_interface_iterator iter(d3d->get_window()->machine().root_device()); |
| 3381 | 3328 | for (device_image_interface *image = iter.first(); image != NULL; iter.next()) |
| 3382 | 3329 | { |
| 3383 | 3330 | // get the device name |
| r22936 | r22937 | |
| 3414 | 3361 | |
| 3415 | 3362 | // substitute path and gamename up front |
| 3416 | 3363 | snapstr.replace(0, "/", PATH_SEPARATOR); |
| 3417 | | snapstr.replace(0, "%g", d3d->window->machine().basename()); |
| 3364 | snapstr.replace(0, "%g", d3d->get_window()->machine().basename()); |
| 3418 | 3365 | |
| 3419 | 3366 | // determine if the template has an index; if not, we always use the same name |
| 3420 | 3367 | astring fname; |
| r22936 | r22937 | |
| 3443 | 3390 | file.set_openflags(origflags); |
| 3444 | 3391 | return file.open(fname); |
| 3445 | 3392 | } |
| 3393 | |