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

Implementações em Texture2D

This commit is contained in:
Danilo 2024-05-05 15:50:17 -03:00
parent 7ebfa86809
commit 9b10adfc38
12 changed files with 376 additions and 125 deletions

View File

@ -1,15 +1,18 @@
#ifndef XNA_CONTENT_MANAGER_HPP
#define XNA_CONTENT_MANAGER_HPP
#include "../csharp/stream.hpp"
#include "../default.hpp"
#include "reader.hpp"
#include <algorithm>
#include <filesystem>
#include <map>
#include <algorithm>
#include "../csharp/stream.hpp"
namespace xna {
class ContentManager {
public:
friend class ContentReader;
ContentManager(String const& rootDirectory) :
_rootDirectory(rootDirectory),
_path(rootDirectory){};
@ -35,7 +38,7 @@ namespace xna {
}
template <typename T>
sptr<T> Load(String const& assetName) {
T Load(String const& assetName) {
if (assetName.empty()) return nullptr;
if (_loadedAssets.contains(assetName)) {
@ -69,6 +72,7 @@ namespace xna {
std::filesystem::path _path;
std::map<String, sptr<void>> _loadedAssets;
inline const static String contentExtension = ".xnb";
std::vector<Byte> byteBuffer;
};
}

View File

@ -2,6 +2,7 @@
#include "manager.hpp"
#include "lzx/decoderstream.hpp"
#include "typereadermanager.hpp"
#include "manager.hpp"
namespace xna {
sptr<ContentReader> ContentReader::Create(ContentManager* contentManager, sptr<Stream>& input, String const& assetName)
@ -88,6 +89,29 @@ namespace xna {
return *(double*)&int64;
}
std::vector<Byte> ContentReader::ReadByteBuffer(size_t size, xna_error_ptr_arg)
{
std::vector<Byte>& buffer = _contentManager->byteBuffer;
if (buffer.empty() || buffer.size() < size)
{
buffer = std::vector<Byte>(size);
//_contentManager->byteBuffer = buffer;
}
Int num = 0;
for (size_t index = 0; index < size; index += num)
{
num = Read(buffer, index, size - index);
if (num == 0) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return std::vector<Byte>();
}
}
return buffer;
}
sptr<Stream> ContentReader::PrepareStream(sptr<Stream>& input, String const& assetName, Int& graphicsProfile)
{
BinaryReader binaryReader = BinaryReader(input);

View File

@ -1,15 +1,15 @@
#ifndef XNA_CONTENT_READER_HPP
#define XNA_CONTENT_READER_HPP
#include "../default.hpp"
#include "../csharp/binary.hpp"
#include "../csharp/type.hpp"
#include "typereadermanager.hpp"
#include <any>
#include "../common/vectors.hpp"
#include "../common/color.hpp"
#include "../common/matrix.hpp"
#include "../common/quaternion.hpp"
#include "../common/color.hpp"
#include "../common/vectors.hpp"
#include "../csharp/binary.hpp"
#include "../csharp/type.hpp"
#include "../default.hpp"
#include "typereadermanager.hpp"
#include <any>
namespace xna {
class ContentReader : public BinaryReader, public std::enable_shared_from_this<ContentReader>{
@ -34,6 +34,8 @@ namespace xna {
float ReadSingle();
double ReadDouble();
std::vector<Byte> ReadByteBuffer(size_t size, xna_error_nullarg);
private:
ContentReader(ContentManager* contentManager, sptr<Stream>& input, String const& assetName, Int graphicsProfile)
: BinaryReader(input), _contentManager(contentManager), _assetName(assetName){}

View File

@ -41,7 +41,7 @@ namespace xna {
return std::any();
}
virtual T Read(ContentReader& input, T existingInstance) = 0;
virtual T Read(ContentReader& input, T& existingInstance) = 0;
};
//-------------------------------------------------------//
@ -175,7 +175,7 @@ namespace xna {
});
}
virtual Object Read(ContentReader& input, Object existingInstance) override {
virtual Object Read(ContentReader& input, Object& existingInstance) override {
return Object();
}
};

View File

@ -683,6 +683,11 @@ namespace xna {
return InternalReadChars(buffer.data(), buffer.size(), index, count, err);
}
Int BinaryReader::Read(std::vector<Byte>& buffer, size_t index, size_t count, xna_error_ptr_arg)
{
auto data = reinterpret_cast<Char*>(buffer.data());
return InternalReadChars(data, buffer.size(), index, count, err);
}
std::vector<Byte> BinaryReader::ReadBytes(size_t count, xna_error_ptr_arg)
{
std::vector<Byte> result(count);

View File

@ -29,6 +29,7 @@ namespace xna {
std::string ReadString(xna_error_nullarg);
Int Read(std::vector<Char>& buffer, size_t index, size_t count, xna_error_nullarg);
Int Read(std::vector<Byte>& buffer, size_t index, size_t count, xna_error_nullarg);
std::vector<Byte> ReadBytes(size_t count, xna_error_nullarg);

View File

@ -0,0 +1,28 @@
#ifndef XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
#define XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
#include "../../content/reader.hpp"
#include "../texture-dx.hpp"
namespace xna {
class Texture2DReader : public ContentTypeReaderT<Texture2D> {
Texture2D Read(ContentReader& input, Texture2D& existingInstance) override{
const auto format = static_cast<SurfaceFormat>(input.ReadInt32());
const auto width = input.ReadInt32();
const auto height = input.ReadInt32();
const auto mipMaps = input.ReadInt32();
auto texture2D = Texture2D(nullptr, width, height, mipMaps, format);
for (size_t level = 0; level < mipMaps; ++level) {
auto elementCount = input.ReadInt32();
std::vector<Byte> data = input.ReadByteBuffer(elementCount);
texture2D.SetData(level, nullptr, data, 0, elementCount);
}
return texture2D;
}
};
}
#endif

View File

@ -1,9 +1,33 @@
//DirectX
#include "dxgi.h"
#include "d3d11.h"
#include <d3d11_1.h>
#include <d3d11_2.h>
//HSLS
#include <d3dcompiler.h>
//DirectXTK
#include <DirectXMath.h>
#include <Audio.h>
#include <BufferHelpers.h>
#include <CommonStates.h>
#include <DDSTextureLoader.h>
#include <DirectXHelpers.h>
#include <Effects.h>
#include <GamePad.h>
#include <GeometricPrimitive.h>
#include <GraphicsMemory.h>
#include <Keyboard.h>
#include <Model.h>
#include <Mouse.h>
#include <PostProcess.h>
#include <PrimitiveBatch.h>
#include <ScreenGrab.h>
#include <SimpleMath.h>
#include <SpriteBatch.h>
#include <SpriteFont.h>
#include <VertexTypes.h>
#include <WICTextureLoader.h>
//Windows
#define NOMINMAX
#include <Windows.h>
#include <Windows.Foundation.h>

View File

@ -63,7 +63,7 @@ namespace xna {
if (!_dxspriteBatch)
return;
if (!texture.dxShaderResourceView)
if (!texture.dxShaderResource)
return;
const auto _position = XMFLOAT2(position.X, position.Y);
@ -71,7 +71,7 @@ namespace xna {
XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
_dxspriteBatch->Draw(
texture.dxShaderResourceView,
texture.dxShaderResource,
_position,
_color
);
@ -81,7 +81,7 @@ namespace xna {
if (!_dxspriteBatch)
return;
if (!texture.dxShaderResourceView)
if (!texture.dxShaderResource)
return;
const auto _position = XMFLOAT2(position.X, position.Y);
@ -98,7 +98,7 @@ namespace xna {
};
_dxspriteBatch->Draw(
texture.dxShaderResourceView,
texture.dxShaderResource,
_position,
sourceRectangle ? &_sourceRect : nullptr,
_color);
@ -108,7 +108,7 @@ namespace xna {
if (!_dxspriteBatch)
return;
if (!texture.dxShaderResourceView)
if (!texture.dxShaderResource)
return;
const auto _position = XMFLOAT2(position.X, position.Y);
@ -128,7 +128,7 @@ namespace xna {
const DxSpriteEffects _effects = static_cast<DxSpriteEffects>(effects);
_dxspriteBatch->Draw(
texture.dxShaderResourceView,
texture.dxShaderResource,
_position,
sourceRectangle ? &_sourceRect : nullptr,
_color,
@ -143,7 +143,7 @@ namespace xna {
if (!_dxspriteBatch)
return;
if (!texture.dxShaderResourceView)
if (!texture.dxShaderResource)
return;
const auto _position = XMFLOAT2(position.X, position.Y);
@ -164,7 +164,7 @@ namespace xna {
const XMFLOAT2 _scale = { scale.X, scale.Y };
_dxspriteBatch->Draw(
texture.dxShaderResourceView,
texture.dxShaderResource,
_position,
sourceRectangle ? &_sourceRect : nullptr,
_color,
@ -179,7 +179,7 @@ namespace xna {
if (!_dxspriteBatch)
return;
if (!texture.dxShaderResourceView)
if (!texture.dxShaderResource)
return;
RECT _destinationRect{};
@ -191,14 +191,14 @@ namespace xna {
const auto v4 = color.ToVector4();
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
_dxspriteBatch->Draw(texture.dxShaderResourceView, _destinationRect, _color);
_dxspriteBatch->Draw(texture.dxShaderResource, _destinationRect, _color);
}
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color) {
if (!_dxspriteBatch)
return;
if (!texture.dxShaderResourceView)
if (!texture.dxShaderResource)
return;
RECT _destinationRect{};
@ -219,14 +219,14 @@ namespace xna {
_sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height;
};
_dxspriteBatch->Draw(texture.dxShaderResourceView, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color);
_dxspriteBatch->Draw(texture.dxShaderResource, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color);
}
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color, float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) {
if (!_dxspriteBatch)
return;
if (!texture.dxShaderResourceView)
if (!texture.dxShaderResource)
return;
RECT _destinationRect{};
@ -251,7 +251,7 @@ namespace xna {
const auto _effects = static_cast<DxSpriteEffects>(effects);
_dxspriteBatch->Draw(
texture.dxShaderResourceView,
texture.dxShaderResource,
_destinationRect,
sourceRectangle ? &_sourceRect : nullptr,
_color,

View File

@ -1,7 +1,6 @@
#include "texture-dx.hpp"
#include "WICTextureLoader.h"
#include "device-dx.hpp"
#include "../helpers.hpp"
#include "adapter-dx.hpp"
namespace xna {
sptr<Texture2D> Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg)
@ -15,7 +14,7 @@ namespace xna {
device._context,
wstr.c_str(),
&resource,
&texture2d->dxShaderResourceView,
&texture2d->dxShaderResource,
0U);
if (FAILED(result))
@ -80,7 +79,7 @@ namespace xna {
return false;
}
hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDecription, &dxShaderResourceView);
hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDescription, &dxShaderResource);
if (resource) {
resource->Release();
@ -94,4 +93,233 @@ namespace xna {
return true;
}
Texture2D::Texture2D(GraphicsDevice* device, size_t width, size_t height) : GraphicsResource(device) {
setDefaultDesc();
dxDescription.Width = static_cast<UINT>(width);
dxDescription.Height = static_cast<UINT>(height);
}
Texture2D::Texture2D(GraphicsDevice* device) : GraphicsResource(device) {
setDefaultDesc();
}
Texture2D::Texture2D(GraphicsDevice* device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : GraphicsResource(device)
{
setDefaultDesc();
dxDescription.Width = static_cast<UINT>(width);
dxDescription.Height = static_cast<UINT>(height);
dxDescription.MipLevels = static_cast<UINT>(mipMap);
dxDescription.Format = GraphicsAdapter::ConvertSurfaceToDXGIFORMAT(format);
}
void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg)
{
if (!m_device || !m_device->_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return;
}
internalSetData(data.data(), err);
}
void Texture2D::SetData(std::vector<Byte> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg)
{
if (!m_device || !m_device->_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return;
}
std::vector<UINT> finalData(elementCount / 4);
auto fIndex = 0;
for (size_t i = startIndex; i < elementCount; ++i) {
const auto& r = data[i];
const auto& g = data[++i];
const auto& b = data[++i];
const auto& a = data[++i];
finalData[fIndex] = Color(r, g, b, a);
++fIndex;
}
internalSetData(finalData.data(), err);
}
void Texture2D::SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg)
{
if (!m_device || !m_device->_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return;
}
std::vector<UINT> finalData(elementCount / 4);
auto fIndex = 0;
for (size_t i = startIndex; i < elementCount; ++i) {
const auto& r = data[i];
const auto& g = data[++i];
const auto& b = data[++i];
const auto& a = data[++i];
finalData[fIndex] = Color(r, g, b, a);
++fIndex;
}
if (!dxTexture2D) {
auto hr = m_device->_device->CreateTexture2D(&dxDescription, nullptr, &dxTexture2D);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
}
ID3D11Resource* resource = nullptr;
auto hr = dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
D3D11_BOX box{};
if (rect) {
box.left = rect->X;
box.right = rect->X + rect->Width;
box.top = rect->Y;
box.bottom = rect->Y + rect->Height;
box.back = level;
box.front = 0;
}
m_device->_context->UpdateSubresource(resource, 0, rect ? &box : nullptr, finalData.data(), dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
if (dxShaderResource) {
dxShaderResource->Release();
dxShaderResource = nullptr;
}
dxShaderDescription.Texture2D.MipLevels = dxDescription.MipLevels;
hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDescription, &dxShaderResource);
if (resource) {
resource->Release();
resource = nullptr;
}
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
dxTexture2D->GetDesc(&dxDescription);
}
void Texture2D::SetData(std::vector<Color> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg)
{
if (!m_device || !m_device->_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return;
}
std::vector<UINT> finalData(elementCount);
auto finalDataIndex = 0;
for (size_t i = startIndex; i < elementCount; ++i) {
finalData[finalDataIndex] = static_cast<UINT>(data[i]);
++finalDataIndex;
}
internalSetData(finalData.data(), err);
}
sptr<Texture2D> Texture2D::FromMemory(GraphicsDevice& device, std::vector<Byte> const& data, xna_error_ptr_arg)
{
auto texture2d = New<Texture2D>(&device);
ID3D11Resource* resource = nullptr;
auto hr = DirectX::CreateWICTextureFromMemory(
device._device,
device._context,
data.data(),
data.size(),
&resource,
&texture2d->dxShaderResource);
if (FAILED(hr))
{
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr;
}
hr = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->dxTexture2D);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr;
}
D3D11_TEXTURE2D_DESC desc;
texture2d->dxTexture2D->GetDesc(&desc);
texture2d->dxDescription = desc;
resource->Release();
resource = nullptr;
return texture2d;
}
void Texture2D::internalSetData(UINT const* data, xna_error_ptr_arg)
{
if (!dxTexture2D) {
auto hr = m_device->_device->CreateTexture2D(&dxDescription, nullptr, &dxTexture2D);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
}
ID3D11Resource* resource = nullptr;
auto hr = dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
m_device->_context->UpdateSubresource(resource, 0, nullptr, data, dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
if (dxShaderResource) {
dxShaderResource->Release();
dxShaderResource = nullptr;
}
dxShaderDescription.Texture2D.MipLevels = dxDescription.MipLevels;
hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDescription, &dxShaderResource);
if (resource) {
resource->Release();
resource = nullptr;
}
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
dxTexture2D->GetDesc(&dxDescription);
}
}

View File

@ -2,27 +2,17 @@
#define XNA_PLATFORM_TEXTURE_DX_HPP
#include "../common/rectangle.hpp"
#include "../csharp/buffer.hpp"
#include "../graphics/texture.hpp"
#include "../xnaerror.hpp"
#include "dxheaders.hpp"
#include <WICTextureLoader.h>
#include "../graphics/gresource.hpp"
#include "../graphics/texture.hpp"
#include "dxheaders.hpp"
#include "device-dx.hpp"
#include <SimpleMath.h>
namespace xna {
class Texture2D : public ITexture2D, public GraphicsResource {
public:
Texture2D(GraphicsDevice* device, size_t width, size_t height) : GraphicsResource(device) {
dxDescription.Width = static_cast<UINT>(width);
dxDescription.Height = static_cast<UINT>(height);
setDefaultDesc();
}
Texture2D(GraphicsDevice* device) : GraphicsResource(device) {
setDefaultDesc();
}
Texture2D(GraphicsDevice* device);
Texture2D(GraphicsDevice* device, size_t width, size_t height);
Texture2D(GraphicsDevice* device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
virtual ~Texture2D() override {
if (dxTexture2D) {
@ -30,9 +20,9 @@ namespace xna {
dxTexture2D = nullptr;
}
if (dxShaderResourceView) {
dxShaderResourceView->Release();
dxShaderResourceView = nullptr;
if (dxShaderResource) {
dxShaderResource->Release();
dxShaderResource = nullptr;
}
}
@ -48,22 +38,23 @@ namespace xna {
return { 0, 0, static_cast<Int>(dxDescription.Width), static_cast<Int>(dxDescription.Height) };
}
bool Initialize(xna_error_nullarg) override;
template <typename T>
void SetData(std::vector<T> const& data, xna_error_ptr_arg);
template <typename T>
void SetData(std::vector<T> const& data, size_t startIndex, size_t elementCount, xna_error_nullarg);
bool Initialize(xna_error_nullarg) override;
void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg);
void SetData(std::vector<Uint> const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg);
void SetData(std::vector<Byte> const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg);
void SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount, xna_error_nullarg);
static sptr<Texture2D> FromStream(GraphicsDevice& device, String const& fileName, xna_error_nullarg);
static sptr<Texture2D> FromMemory(GraphicsDevice& device, std::vector<Byte> const& data, xna_error_nullarg);
public:
ID3D11Texture2D* dxTexture2D{ nullptr };
ID3D11ShaderResourceView* dxShaderResourceView{ nullptr };
ID3D11ShaderResourceView* dxShaderResource{ nullptr };
D3D11_SUBRESOURCE_DATA dxSubResource{};
D3D11_TEXTURE2D_DESC dxDescription{};
D3D11_SHADER_RESOURCE_VIEW_DESC dxShaderDecription{};
D3D11_SHADER_RESOURCE_VIEW_DESC dxShaderDescription{};
private:
static constexpr int R8G8B8A8U_BYTE_SIZE = 4;
@ -76,72 +67,14 @@ namespace xna {
dxDescription.Usage = D3D11_USAGE_DEFAULT;
dxDescription.BindFlags = D3D11_BIND_SHADER_RESOURCE;
dxShaderDecription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
dxShaderDecription.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
dxShaderDecription.Texture2D.MipLevels = dxDescription.MipLevels;
dxShaderDecription.Texture2D.MostDetailedMip = 0;
}
};
template <typename T>
inline void Texture2D::SetData(std::vector<T> const& data, xna_error_ptr_arg) {
SetData(data, 0, data.size(), err);
}
template <typename T>
inline void Texture2D::SetData(std::vector<T> const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) {
if (!m_device || !m_device->_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return;
dxShaderDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
dxShaderDescription.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
dxShaderDescription.Texture2D.MipLevels = dxDescription.MipLevels;
dxShaderDescription.Texture2D.MostDetailedMip = 0;
}
std::vector<UINT> finalData(elementCount);
auto finalDataIndex = 0;
for (size_t i = startIndex; i < elementCount; ++i) {
finalData[finalDataIndex] = static_cast<UINT>(data[i]);
++finalDataIndex;
}
if (!dxTexture2D) {
auto hr = m_device->_device->CreateTexture2D(&dxDescription, nullptr, &dxTexture2D);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
}
ID3D11Resource* resource = nullptr;
auto hr = dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
dxShaderDecription.Texture2D.MipLevels = dxDescription.MipLevels;
m_device->_context->UpdateSubresource(resource, 0, nullptr, finalData.data(), dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
if (dxShaderResourceView) {
dxShaderResourceView->Release();
dxShaderResourceView = nullptr;
}
hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDecription, &dxShaderResourceView);
if (resource) {
resource->Release();
resource = nullptr;
}
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return;
}
dxTexture2D->GetDesc(&dxDescription);
}
void internalSetData(UINT const* data, xna_error_nullarg);
};
}
#endif

View File

@ -14,6 +14,7 @@ namespace xna {
graphics = New<GraphicsDeviceManager>(_game);
graphics->PreferredBackBufferWidth(1280);
graphics->PreferredBackBufferHeight(720);
contentManager = New<ContentManager>("Content");
}
void Initialize() override {
@ -26,11 +27,12 @@ namespace xna {
XnaErrorCode err{0};
//texture = Texture2D::FromStream(*_graphicsDevice, "D:\\sprite.jpg", &err);
texture = New<Texture2D>(_graphicsDevice.get(), 256, 256);
std::vector<Color> data(256 * 256, 4278190080U);
//texture = New<Texture2D>(_graphicsDevice.get(), 256, 256);
//std::vector<Color> data(256 * 256, 4278190080U);
//std::vector<UINT> data(256 * 256, 0xffffffff);
//std::vector<Uint> data(256 * 256, 4278190080U);
texture->SetData(data, 0, data.size());
//texture->SetData(data, 0, data.size());
//Texture2D tx = contentManager->Load<Texture2D>("Idle");
Game::LoadContent();
}
@ -46,7 +48,7 @@ namespace xna {
_graphicsDevice->Clear(Colors::CornflowerBlue);
spriteBatch->Begin();
spriteBatch->Draw(*texture, position, Colors::White);
//spriteBatch->Draw(*texture, position, Colors::White);
spriteBatch->End();
Game::Draw(gameTime);