MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / d3d_CreateTextureFromBitmap

Function d3d_CreateTextureFromBitmap

legacy/renderer/Direct3D.cpp:749–873  ·  view source on GitHub ↗

Returns index into the global array of texture interfaces we have

Source from the content-addressed store, hash-verified

747
748// Returns index into the global array of texture interfaces we have
749int d3d_CreateTextureFromBitmap(int bm_handle, int map_type) {
750 int w, h;
751 int retval = -1;
752 HRESULT ddrval;
753
754 // mprintf(0,"Creating texture from handle %d type %d\n",bm_handle,map_type);
755
756 if (map_type == MAP_TYPE_BUMPMAP) {
757 ASSERT(GameBumpmaps[bm_handle].cache_slot == -1);
758
759 w = bump_w(bm_handle);
760 h = bump_h(bm_handle);
761 } else if (map_type == MAP_TYPE_LIGHTMAP) {
762 ASSERT(GameLightmaps[bm_handle].cache_slot == -1);
763
764 w = GameLightmaps[bm_handle].square_res;
765 h = GameLightmaps[bm_handle].square_res;
766
767 } else {
768 ASSERT(GameBitmaps[bm_handle].cache_slot == -1);
769 w = bm_w(bm_handle, 0);
770 h = bm_h(bm_handle, 0);
771 // Pointer to a bitmap surface
772 }
773
774 // Create a texture interface and make it auto-managed
775 DDSURFACEDESC2 ddsd;
776
777 memset(&ddsd, 0, sizeof(ddsd));
778 ddsd.dwSize = sizeof(ddsd);
779 ddsd.dwFlags = DDSD_CAPS;
780 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
781 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
782 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
783
784 ddsd.dwWidth = w;
785 ddsd.dwHeight = h;
786
787 if (map_type == MAP_TYPE_BITMAP && bm_format(bm_handle) == BITMAP_FORMAT_4444) {
788 ddsd.ddpfPixelFormat = Texture_4444_format;
789 ddsd.ddsCaps.dwCaps2 |= DDSCAPS2_HINTSTATIC;
790 } else if (d3d_CanCompress && map_type == MAP_TYPE_BITMAP && bm_format(bm_handle) == BITMAP_FORMAT_1555 &&
791 (GameBitmaps[bm_handle].flags & BF_COMPRESSABLE)) {
792 ddsd.ddpfPixelFormat = Compressed_texture_format;
793 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
794 ddsd.ddpfPixelFormat.dwFourCC = FOURCC_DXT1;
795 ddsd.ddsCaps.dwCaps2 |= DDSCAPS2_HINTSTATIC;
796
797 } else if (map_type == MAP_TYPE_BUMPMAP) {
798 ddsd.ddpfPixelFormat = Bumpmap_texture_format;
799
800 ddsd.ddpfPixelFormat.dwFlags = DDPF_BUMPDUDV;
801 ddsd.ddpfPixelFormat.dwBumpBitCount = 16;
802 ddsd.ddpfPixelFormat.dwBumpDuBitMask = 0x000000ff;
803 ddsd.ddpfPixelFormat.dwBumpDvBitMask = 0x0000ff00;
804 ddsd.ddpfPixelFormat.dwBumpLuminanceBitMask = 0x00000000;
805 } else {
806 if (map_type == MAP_TYPE_LIGHTMAP) {

Callers 2

d3d_MakeBitmapCurrentFunction · 0.85

Calls 6

bump_wFunction · 0.85
bump_hFunction · 0.85
bm_wFunction · 0.85
bm_hFunction · 0.85
bm_formatFunction · 0.85

Tested by

no test coverage detected