| 2173 | } |
| 2174 | |
| 2175 | Texture* DXRenderDevice::LoadTexture(const StringImpl& fileName, int flags) |
| 2176 | { |
| 2177 | if (fileName.StartsWith("!backbuffer:")) |
| 2178 | { |
| 2179 | int colon = (int)fileName.IndexOf(':'); |
| 2180 | String addrStr = fileName.Substring(colon + 1); |
| 2181 | void* addr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16); |
| 2182 | BFWindow* window = (BFWindow*)addr; |
| 2183 | DXRenderWindow* renderWindow = (DXRenderWindow*)window->mRenderWindow; |
| 2184 | |
| 2185 | DXTexture* aTexture = NULL; |
| 2186 | aTexture->mD3DRenderTargetView = renderWindow->mD3DRenderTargetView; |
| 2187 | aTexture->mD3DTexture = renderWindow->mD3DBackBuffer; |
| 2188 | |
| 2189 | aTexture->mD3DRenderTargetView->AddRef(); |
| 2190 | aTexture->mD3DTexture->AddRef(); |
| 2191 | aTexture->AddRef(); |
| 2192 | return aTexture; |
| 2193 | } |
| 2194 | |
| 2195 | String pathEx = fileName; |
| 2196 | if ((flags & TextureFlag_Additive) != 0) |
| 2197 | pathEx += ":add"; |
| 2198 | |
| 2199 | DXTexture* aTexture = NULL; |
| 2200 | if ((!fileName.StartsWith('@')) && (mTextureMap.TryGetValue(pathEx, &aTexture))) |
| 2201 | { |
| 2202 | aTexture->AddRef(); |
| 2203 | return aTexture; |
| 2204 | } |
| 2205 | |
| 2206 | int dotPos = (int)fileName.LastIndexOf('.'); |
| 2207 | String ext; |
| 2208 | if (dotPos != -1) |
| 2209 | ext = fileName.Substring(dotPos); |
| 2210 | |
| 2211 | if (ext.Equals(".dds", StringImpl::CompareKind_OrdinalIgnoreCase)) |
| 2212 | { |
| 2213 | FileStream fs; |
| 2214 | if (!fs.Open(fileName, "rb")) |
| 2215 | return NULL; |
| 2216 | |
| 2217 | int header = fs.ReadInt32(); |
| 2218 | if (header != 0x20534444) |
| 2219 | return NULL; |
| 2220 | |
| 2221 | auto hdr = fs.ReadT<DDS_HEADER>(); |
| 2222 | |
| 2223 | DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM; |
| 2224 | |
| 2225 | if (hdr.ddspf.dwFlags == DDS_RGBA) |
| 2226 | { |
| 2227 | if (hdr.ddspf.dwRGBBitCount == 32) |
| 2228 | { |
| 2229 | if (hdr.ddspf.dwRBitMask == 0xff) |
| 2230 | format = DXGI_FORMAT_R8G8B8A8_UNORM; |
| 2231 | else if (hdr.ddspf.dwRBitMask = 0xff0000) |
| 2232 | format = DXGI_FORMAT_B8G8R8A8_UNORM; |
no test coverage detected