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

54 lines
1.1 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-03-18 15:41:46 -03:00
}
2024-04-07 14:06:12 -03:00
PTexture2D Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg)
{
ID3D11Resource* resource = nullptr;
//D3D11ShaderResourceView* view = nullptr;
auto wstr = StringToWString(fileName);
HRESULT result = DirectX::CreateWICTextureFromFile(
device._device, device._context, wstr.c_str(),
&resource, nullptr, 0U);
if (FAILED(result))
{
xna_error_apply(err, XnaErrorCode::STREAM_ERROR);
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr;
}
ID3D11Texture2D* txt2d = nullptr;
result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&txt2d);
if (FAILED(result)) {
xna_error_apply(err, XnaErrorCode::BAD_CAST);
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr;
}
auto texture2d = New<Texture2D>();
texture2d->_texture2D = txt2d;
resource->Release();
resource = nullptr;
return texture2d;
}
2024-03-18 15:41:46 -03:00
}