Given a bitmap handle, a map type, and a destination d3d slot, takes the data from the application and massages it for direct3d's consumption
| 546 | // Given a bitmap handle, a map type, and a destination d3d slot, takes the data |
| 547 | // from the application and massages it for direct3d's consumption |
| 548 | void d3d_UploadBitmapToSurface(int handle, int map_type, int slot, int new_upload) { |
| 549 | DDSURFACEDESC2 surf_desc; |
| 550 | LPDIRECTDRAWSURFACE4 dest_sp, upload_sp; |
| 551 | |
| 552 | HRESULT ddrval; |
| 553 | int w, h; |
| 554 | uint16_t *src_data; |
| 555 | |
| 556 | // mprintf(0,"Uploading bitmap %d type %d\n",handle,map_type); |
| 557 | // mprintf(0,"Slot=%d handle=%d\n",slot,handle); |
| 558 | |
| 559 | ASSERT(slot != -1); |
| 560 | ASSERT(slot == handle); |
| 561 | |
| 562 | int tex_class = d3d_GetTexClass(handle, map_type); |
| 563 | |
| 564 | if (map_type == MAP_TYPE_BITMAP) { |
| 565 | w = bm_w(handle, 0); |
| 566 | h = bm_h(handle, 0); |
| 567 | |
| 568 | ASSERT(GameBitmaps[handle].cache_slot == handle); |
| 569 | |
| 570 | if (bm_format(handle) == BITMAP_FORMAT_4444) |
| 571 | upload_sp = Upload4444Surfaces[tex_class]; |
| 572 | else |
| 573 | upload_sp = UploadSurfaces[tex_class]; |
| 574 | dest_sp = BitmapTextureSurfaces[slot]; |
| 575 | |
| 576 | src_data = bm_data(handle, 0); |
| 577 | } else if (map_type == MAP_TYPE_BUMPMAP) { |
| 578 | w = bump_w(handle); |
| 579 | h = bump_h(handle); |
| 580 | |
| 581 | ASSERT(GameBumpmaps[handle].cache_slot == handle); |
| 582 | dest_sp = BumpmapTextureSurfaces[slot]; |
| 583 | src_data = bump_data(handle); |
| 584 | } else { |
| 585 | w = lm_w(handle); |
| 586 | h = lm_h(handle); |
| 587 | |
| 588 | ASSERT(GameLightmaps[handle].cache_slot == handle); |
| 589 | dest_sp = LightmapTextureSurfaces[slot]; |
| 590 | upload_sp = UploadSurfaces[tex_class]; |
| 591 | |
| 592 | src_data = lm_data(handle); |
| 593 | } |
| 594 | |
| 595 | ASSERT(dest_sp != NULL); |
| 596 | |
| 597 | memset(&surf_desc, 0, sizeof(DDSURFACEDESC2)); |
| 598 | surf_desc.dwSize = sizeof(DDSURFACEDESC2); |
| 599 | surf_desc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); |
| 600 | |
| 601 | // Now that we have a lock, blit this bitmap to the surface |
| 602 | if (map_type == MAP_TYPE_BUMPMAP) { |
| 603 | ddrval = dest_sp->Lock(NULL, &surf_desc, DDLOCK_WAIT, NULL); |
| 604 | if (ddrval != DD_OK) { |
| 605 | mprintf(0, "D3D:Normal upload lock error %d! %s\n", ddrval, d3d_ErrorString(ddrval)); |
no test coverage detected