1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/framework/platform/texture-dx.cpp

58 lines
1.2 KiB
C++
Raw Normal View History

2024-03-18 15:41:46 -03:00
#include "texture-dx.hpp"
2024-04-07 14:06:12 -03:00
#include "WICTextureLoader.h"
#include "device-dx.hpp"
#include "../helpers.hpp"
2024-03-18 15:41:46 -03:00
namespace xna {
2024-03-21 16:01:47 -03:00
Texture2D::Texture2D() {
2024-04-14 16:11:15 -03:00
}
2024-04-07 14:06:12 -03:00
PTexture2D Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg)
{
2024-04-14 16:11:15 -03:00
auto texture2d = New<Texture2D>();
ID3D11Resource* resource = nullptr;
2024-04-14 21:23:09 -03:00
auto wstr = XnaHToWString(fileName);
2024-04-07 14:06:12 -03:00
HRESULT result = DirectX::CreateWICTextureFromFile(
2024-04-14 16:11:15 -03:00
device._device,
device._context,
wstr.c_str(),
&resource,
&texture2d->_textureView,
0U);
2024-04-07 14:06:12 -03:00
if (FAILED(result))
{
2024-04-14 16:11:15 -03:00
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
2024-04-07 14:06:12 -03:00
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr;
}
2024-04-14 16:11:15 -03:00
result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->_texture2D);
2024-04-07 14:06:12 -03:00
if (FAILED(result)) {
2024-04-14 16:11:15 -03:00
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
2024-04-07 14:06:12 -03:00
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr;
}
2024-04-14 16:11:15 -03:00
D3D11_TEXTURE2D_DESC desc;
texture2d->_texture2D->GetDesc(&desc);
texture2d->_description = desc;
2024-04-07 14:06:12 -03:00
resource->Release();
resource = nullptr;
return texture2d;
}
2024-03-18 15:41:46 -03:00
}