| 102 | } |
| 103 | |
| 104 | void DirectXTexture::loadFromFile(const std::string& _filename) |
| 105 | { |
| 106 | destroy(); |
| 107 | mTextureUsage = TextureUsage::Default; |
| 108 | mPixelFormat = PixelFormat::R8G8B8A8; |
| 109 | mNumElemBytes = 4; |
| 110 | |
| 111 | std::string fullname = DirectXDataManager::getInstance().getDataPath(_filename); |
| 112 | |
| 113 | D3DXIMAGE_INFO info; |
| 114 | D3DXGetImageInfoFromFile(fullname.c_str(), &info); |
| 115 | |
| 116 | if (info.Format == D3DFMT_A8R8G8B8) |
| 117 | { |
| 118 | mPixelFormat = PixelFormat::R8G8B8A8; |
| 119 | mNumElemBytes = 4; |
| 120 | } |
| 121 | else if (info.Format == D3DFMT_R8G8B8) |
| 122 | { |
| 123 | mPixelFormat = PixelFormat::R8G8B8; |
| 124 | mNumElemBytes = 3; |
| 125 | } |
| 126 | else if (info.Format == D3DFMT_A8L8) |
| 127 | { |
| 128 | mPixelFormat = PixelFormat::L8A8; |
| 129 | mNumElemBytes = 2; |
| 130 | } |
| 131 | else if (info.Format == D3DFMT_L8) |
| 132 | { |
| 133 | mPixelFormat = PixelFormat::L8; |
| 134 | mNumElemBytes = 1; |
| 135 | } |
| 136 | |
| 137 | mSize.set(info.Width, info.Height); |
| 138 | HRESULT result = D3DXCreateTextureFromFile(mpD3DDevice, fullname.c_str(), &mpTexture); |
| 139 | if (FAILED(result)) |
| 140 | { |
| 141 | MYGUI_PLATFORM_EXCEPT( |
| 142 | "Failed to load texture '" << _filename << "' (error code " << result << "): size '" << mSize |
| 143 | << "' format '" << info.Format << "'."); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void DirectXTexture::destroy() |
| 148 | { |
nothing calls this directly
no test coverage detected