mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Merge pull request #16 from borgesdan/develop
Implementações em Texture
This commit is contained in:
commit
c5ebd88adf
@ -11,8 +11,8 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int LzxDecoder::Decompress(Stream* inData, int inLen, Stream* outData, int outLen) {
|
int LzxDecoder::Decompress(Stream* inData, int inLen, Stream* outData, int outLen) {
|
||||||
auto input = reinterpret_cast<mspack_file*>(inData->Data());
|
mspack_file* input = nullptr;
|
||||||
auto output = reinterpret_cast<mspack_file*>(outData->Data());
|
mspack_file* output = nullptr;
|
||||||
|
|
||||||
auto lzxstream = lzxd_init(
|
auto lzxstream = lzxd_init(
|
||||||
//struct mspack_system* system,
|
//struct mspack_system* system,
|
||||||
|
@ -87,7 +87,7 @@ namespace xna {
|
|||||||
|
|
||||||
impl->_context->OMSetRenderTargets(
|
impl->_context->OMSetRenderTargets(
|
||||||
1,
|
1,
|
||||||
impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(),
|
impl->_renderTarget2D->impl2->_renderTargetView.GetAddressOf(),
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -104,7 +104,7 @@ namespace xna {
|
|||||||
impl->_backgroundColor[3] = v4.W;
|
impl->_backgroundColor[3] = v4.W;
|
||||||
|
|
||||||
impl->_context->ClearRenderTargetView(
|
impl->_context->ClearRenderTargetView(
|
||||||
impl->_renderTarget2D->render_impl->_renderTargetView.Get(),
|
impl->_renderTarget2D->impl2->_renderTargetView.Get(),
|
||||||
impl->_backgroundColor);
|
impl->_backgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,49 +1,49 @@
|
|||||||
#include "xna/xna-dx.hpp"
|
#include "xna/xna-dx.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
RenderTarget2D::RenderTarget2D() : Texture2D() {
|
|
||||||
render_impl = unew<PlatformImplementation>();
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
|
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
|
||||||
render_impl = unew<PlatformImplementation>();
|
impl2 = unew<PlatformImplementation>();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTarget2D::~RenderTarget2D() {
|
void RenderTarget2D::Initialize() {
|
||||||
render_impl = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderTarget2D::Initialize() {
|
|
||||||
if (!impl || !m_device || !m_device->impl->_device) {
|
if (!impl || !m_device || !m_device->impl->_device) {
|
||||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_device->impl->_swapChain->impl->GetBackBuffer(impl->dxTexture2D))
|
auto& swapChain = m_device->impl->_swapChain;
|
||||||
return false;
|
|
||||||
|
|
||||||
|
if (!swapChain->impl->GetBackBuffer(impl->dxTexture2D))
|
||||||
|
{
|
||||||
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl->dxTexture2D->GetDesc(&impl->dxDescription);
|
||||||
auto& dxdevice = m_device->impl->_device;
|
auto& dxdevice = m_device->impl->_device;
|
||||||
|
|
||||||
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D.Get(), NULL, render_impl->_renderTargetView.ReleaseAndGetAddressOf());
|
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D.Get(), NULL, impl2->_renderTargetView.ReleaseAndGetAddressOf());
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc);
|
||||||
|
|
||||||
|
//depthStencilFormat = DepthFormat::None;
|
||||||
|
multiSampleCount = impl->dxDescription.SampleDesc.Count;
|
||||||
|
//targetUsage = RenderTargetUsage::DiscardContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderTarget2D::Apply() {
|
void RenderTarget2D::Apply() {
|
||||||
if (!m_device || !m_device->impl->_context) {
|
if (!m_device || !m_device->impl->_context) {
|
||||||
Exception::Throw(Exception::FAILED_TO_APPLY);
|
Exception::Throw(Exception::FAILED_TO_APPLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!render_impl->_renderTargetView)
|
if (!impl2->_renderTargetView)
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& context = m_device->impl->_context;
|
auto& context = m_device->impl->_context;
|
||||||
context->OMSetRenderTargets(1, render_impl->_renderTargetView.GetAddressOf(), nullptr);
|
context->OMSetRenderTargets(1, impl2->_renderTargetView.GetAddressOf(), nullptr);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,41 +1,8 @@
|
|||||||
#include "xna/xna-dx.hpp"
|
#include "xna/xna-dx.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
Texture2D::~Texture2D() {
|
static void setDefaultTexture2DDesc(Texture2D::PlatformImplementation& impl);
|
||||||
impl = nullptr;
|
static HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data);
|
||||||
}
|
|
||||||
|
|
||||||
sptr<Texture2D> Texture2D::FromStream(GraphicsDevice& device, String const& fileName)
|
|
||||||
{
|
|
||||||
auto _this = device.shared_from_this();
|
|
||||||
auto texture2d = snew<Texture2D>(_this);
|
|
||||||
comptr<ID3D11Resource> resource = nullptr;
|
|
||||||
auto wstr = XnaHelper::ToWString(fileName);
|
|
||||||
|
|
||||||
HRESULT result = DirectX::CreateWICTextureFromFile(
|
|
||||||
device.impl->_device.Get(),
|
|
||||||
device.impl->_context.Get(),
|
|
||||||
wstr.c_str(),
|
|
||||||
resource.GetAddressOf(),
|
|
||||||
texture2d->impl->dxShaderResource.ReleaseAndGetAddressOf(),
|
|
||||||
0U);
|
|
||||||
|
|
||||||
if (FAILED(result)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)texture2d->impl->dxTexture2D.ReleaseAndGetAddressOf());
|
|
||||||
|
|
||||||
if (FAILED(result)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
D3D11_TEXTURE2D_DESC desc;
|
|
||||||
texture2d->impl->dxTexture2D->GetDesc(&desc);
|
|
||||||
texture2d->impl->dxDescription = desc;
|
|
||||||
|
|
||||||
return texture2d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Texture2D::Initialize()
|
void Texture2D::Initialize()
|
||||||
{
|
{
|
||||||
@ -64,80 +31,36 @@ namespace xna {
|
|||||||
|
|
||||||
surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format);
|
surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format);
|
||||||
levelCount = static_cast<Int>(impl->dxShaderDescription.Texture2D.MipLevels);
|
levelCount = static_cast<Int>(impl->dxShaderDescription.Texture2D.MipLevels);
|
||||||
}
|
width = static_cast<Int>(impl->dxDescription.Width);
|
||||||
|
height = static_cast<Int>(impl->dxDescription.Height);
|
||||||
void setDefaultDesc(Texture2D::PlatformImplementation& impl) {
|
}
|
||||||
impl.dxDescription.MipLevels = 1;
|
|
||||||
impl.dxDescription.ArraySize = 1;
|
|
||||||
impl.dxDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
impl.dxDescription.SampleDesc.Count = 1;
|
|
||||||
impl.dxDescription.Usage = D3D11_USAGE_DEFAULT;
|
|
||||||
impl.dxDescription.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
|
||||||
|
|
||||||
impl.dxShaderDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
impl.dxShaderDescription.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
|
||||||
impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels;
|
|
||||||
impl.dxShaderDescription.Texture2D.MostDetailedMip = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Texture2D::Texture2D() : Texture(nullptr) {
|
Texture2D::Texture2D() : Texture(nullptr) {
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
setDefaultDesc(*impl);
|
setDefaultTexture2DDesc(*impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : Texture(device) {
|
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : Texture(device) {
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
setDefaultDesc(*impl);
|
setDefaultTexture2DDesc(*impl);
|
||||||
impl->dxDescription.Width = static_cast<UINT>(width);
|
impl->dxDescription.Width = static_cast<UINT>(width);
|
||||||
impl->dxDescription.Height = static_cast<UINT>(height);
|
impl->dxDescription.Height = static_cast<UINT>(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : Texture(device) {
|
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : Texture(device) {
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
setDefaultDesc(*impl);
|
setDefaultTexture2DDesc(*impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : Texture(device)
|
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : Texture(device)
|
||||||
{
|
{
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
setDefaultDesc(*impl);
|
setDefaultTexture2DDesc(*impl);
|
||||||
impl->dxDescription.Width = static_cast<UINT>(width);
|
impl->dxDescription.Width = static_cast<UINT>(width);
|
||||||
impl->dxDescription.Height = static_cast<UINT>(height);
|
impl->dxDescription.Height = static_cast<UINT>(height);
|
||||||
impl->dxDescription.MipLevels = static_cast<UINT>(mipMap);
|
impl->dxDescription.MipLevels = static_cast<UINT>(mipMap);
|
||||||
impl->dxDescription.Format = DxHelpers::SurfaceFormatToDx(format);
|
impl->dxDescription.Format = DxHelpers::SurfaceFormatToDx(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT internalSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data)
|
|
||||||
{
|
|
||||||
if (!impl.dxTexture2D) {
|
|
||||||
auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, impl.dxTexture2D.ReleaseAndGetAddressOf());
|
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
comptr<ID3D11Resource> resource = nullptr;
|
|
||||||
auto hr = impl.dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf());
|
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
Exception::Throw(Exception::INVALID_OPERATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr int R8G8B8A8U_BYTE_SIZE = 4;
|
|
||||||
device.impl->_context->UpdateSubresource(resource.Get(), 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
|
|
||||||
|
|
||||||
impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels;
|
|
||||||
hr = device.impl->_device->CreateShaderResourceView(resource.Get(), &impl.dxShaderDescription, impl.dxShaderResource.ReleaseAndGetAddressOf());
|
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl.dxTexture2D->GetDesc(&impl.dxDescription);
|
|
||||||
|
|
||||||
return NO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount)
|
void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount)
|
||||||
{
|
{
|
||||||
@ -145,7 +68,7 @@ namespace xna {
|
|||||||
Exception::Throw(Exception::INVALID_OPERATION);
|
Exception::Throw(Exception::INVALID_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
internalSetData(*impl, *m_device, data.data());
|
internalTexture2DSetData(*impl, *m_device, data.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture2D::SetData(std::vector<Byte> const& data, size_t startIndex, size_t elementCount)
|
void Texture2D::SetData(std::vector<Byte> const& data, size_t startIndex, size_t elementCount)
|
||||||
@ -166,8 +89,8 @@ namespace xna {
|
|||||||
++fIndex;
|
++fIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
internalSetData(*impl, *m_device, finalData.data());
|
internalTexture2DSetData(*impl, *m_device, finalData.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture2D::SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount)
|
void Texture2D::SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount)
|
||||||
{
|
{
|
||||||
@ -241,10 +164,51 @@ namespace xna {
|
|||||||
++finalDataIndex;
|
++finalDataIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
internalSetData(*impl, *m_device, finalData.data());
|
internalTexture2DSetData(*impl, *m_device, finalData.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
sptr<Texture2D> Texture2D::FromMemory(GraphicsDevice& device, std::vector<Byte> const& data)
|
P_Texture2D Texture2D::FromStream(GraphicsDevice& device, P_Stream const& stream)
|
||||||
|
{
|
||||||
|
std::vector<Byte> data;
|
||||||
|
const auto lenght = stream->Length();
|
||||||
|
stream->Read(data, 0, lenght - 1);
|
||||||
|
|
||||||
|
return FromStream(device, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
sptr<Texture2D> Texture2D::FromStream(GraphicsDevice& device, String const& fileName)
|
||||||
|
{
|
||||||
|
auto _this = device.shared_from_this();
|
||||||
|
auto texture2d = snew<Texture2D>(_this);
|
||||||
|
comptr<ID3D11Resource> resource = nullptr;
|
||||||
|
auto wstr = XnaHelper::ToWString(fileName);
|
||||||
|
|
||||||
|
HRESULT result = DirectX::CreateWICTextureFromFile(
|
||||||
|
device.impl->_device.Get(),
|
||||||
|
device.impl->_context.Get(),
|
||||||
|
wstr.c_str(),
|
||||||
|
resource.GetAddressOf(),
|
||||||
|
texture2d->impl->dxShaderResource.ReleaseAndGetAddressOf(),
|
||||||
|
0U);
|
||||||
|
|
||||||
|
if (FAILED(result)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)texture2d->impl->dxTexture2D.ReleaseAndGetAddressOf());
|
||||||
|
|
||||||
|
if (FAILED(result)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D11_TEXTURE2D_DESC desc;
|
||||||
|
texture2d->impl->dxTexture2D->GetDesc(&desc);
|
||||||
|
texture2d->impl->dxDescription = desc;
|
||||||
|
|
||||||
|
return texture2d;
|
||||||
|
}
|
||||||
|
|
||||||
|
sptr<Texture2D> Texture2D::FromStream(GraphicsDevice& device, std::vector<Byte> const& data)
|
||||||
{
|
{
|
||||||
auto _this = device.shared_from_this();
|
auto _this = device.shared_from_this();
|
||||||
auto texture2d = snew<Texture2D>(_this);
|
auto texture2d = snew<Texture2D>(_this);
|
||||||
@ -274,27 +238,51 @@ namespace xna {
|
|||||||
texture2d->impl->dxDescription = desc;
|
texture2d->impl->dxDescription = desc;
|
||||||
|
|
||||||
return texture2d;
|
return texture2d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int Texture2D::Width() const {
|
HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data)
|
||||||
if (!impl) return 0;
|
{
|
||||||
|
if (!impl.dxTexture2D) {
|
||||||
|
auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, impl.dxTexture2D.ReleaseAndGetAddressOf());
|
||||||
|
|
||||||
return static_cast<Int>(impl->dxDescription.Width);
|
if (FAILED(hr)) {
|
||||||
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
comptr<ID3D11Resource> resource = nullptr;
|
||||||
|
auto hr = impl.dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf());
|
||||||
|
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
Exception::Throw(Exception::INVALID_OPERATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr int R8G8B8A8U_BYTE_SIZE = 4;
|
||||||
|
device.impl->_context->UpdateSubresource(resource.Get(), 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
|
||||||
|
|
||||||
|
impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels;
|
||||||
|
hr = device.impl->_device->CreateShaderResourceView(resource.Get(), &impl.dxShaderDescription, impl.dxShaderResource.ReleaseAndGetAddressOf());
|
||||||
|
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl.dxTexture2D->GetDesc(&impl.dxDescription);
|
||||||
|
|
||||||
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int Texture2D::Height() const {
|
void setDefaultTexture2DDesc(Texture2D::PlatformImplementation& impl) {
|
||||||
if (!impl) return 0;
|
impl.dxDescription.MipLevels = 1;
|
||||||
|
impl.dxDescription.ArraySize = 1;
|
||||||
|
impl.dxDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
impl.dxDescription.SampleDesc.Count = 1;
|
||||||
|
impl.dxDescription.Usage = D3D11_USAGE_DEFAULT;
|
||||||
|
impl.dxDescription.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||||
|
|
||||||
return static_cast<Int>(impl->dxDescription.Height);
|
impl.dxShaderDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
}
|
impl.dxShaderDescription.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||||
|
impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels;
|
||||||
Rectangle Texture2D::Bounds() const {
|
impl.dxShaderDescription.Texture2D.MostDetailedMip = 0;
|
||||||
if (!impl) return {};
|
|
||||||
|
|
||||||
return Rectangle(
|
|
||||||
0, 0,
|
|
||||||
static_cast<Int>(impl->dxDescription.Width),
|
|
||||||
static_cast<Int>(impl->dxDescription.Height)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,9 +38,7 @@ namespace xna {
|
|||||||
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) = 0;
|
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) = 0;
|
||||||
|
|
||||||
//Writes a byte to the current position in the stream and advances the position within the stream by one byte.
|
//Writes a byte to the current position in the stream and advances the position within the stream by one byte.
|
||||||
virtual void WriteByte(Byte value) = 0;
|
virtual void WriteByte(Byte value) = 0;
|
||||||
|
|
||||||
virtual void* Data() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//A simplified port of the System.IO.MemoryStream.
|
//A simplified port of the System.IO.MemoryStream.
|
||||||
@ -84,10 +82,6 @@ namespace xna {
|
|||||||
virtual void Write(Byte const* buffer, Int bufferLength, Int offset, Int count) override;
|
virtual void Write(Byte const* buffer, Int bufferLength, Int offset, Int count) override;
|
||||||
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) override;
|
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) override;
|
||||||
virtual void WriteByte(Byte value) override;
|
virtual void WriteByte(Byte value) override;
|
||||||
|
|
||||||
virtual void* Data() override {
|
|
||||||
return _buffer.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<Byte> _buffer;
|
std::vector<Byte> _buffer;
|
||||||
@ -125,11 +119,7 @@ namespace xna {
|
|||||||
virtual Int ReadByte() override;
|
virtual Int ReadByte() override;
|
||||||
virtual void Write(Byte const* buffer, Int bufferLength, Int offset, Int count) override;
|
virtual void Write(Byte const* buffer, Int bufferLength, Int offset, Int count) override;
|
||||||
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) override;
|
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) override;
|
||||||
virtual void WriteByte(Byte value) override;
|
virtual void WriteByte(Byte value) override;
|
||||||
|
|
||||||
virtual void* Data() override {
|
|
||||||
return _fstream.rdbuf();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::fstream _fstream;
|
std::fstream _fstream;
|
||||||
|
@ -202,6 +202,9 @@ namespace xna {
|
|||||||
using P_RasterizerState = sptr<RasterizerState>;
|
using P_RasterizerState = sptr<RasterizerState>;
|
||||||
using P_PresentationParameters = sptr<PresentationParameters>;
|
using P_PresentationParameters = sptr<PresentationParameters>;
|
||||||
using P_SamplerStateCollection = sptr<SamplerStateCollection>;
|
using P_SamplerStateCollection = sptr<SamplerStateCollection>;
|
||||||
|
using P_Stream = sptr<Stream>;
|
||||||
|
using P_MemoryStream = sptr<MemoryStream>;
|
||||||
|
using P_FileStream = sptr<FileStream>;
|
||||||
using P_Texture = sptr<Texture>;
|
using P_Texture = sptr<Texture>;
|
||||||
using P_Texture2D = sptr<Texture2D>;
|
using P_Texture2D = sptr<Texture2D>;
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,25 @@ namespace xna {
|
|||||||
class RenderTarget2D : public Texture2D {
|
class RenderTarget2D : public Texture2D {
|
||||||
public:
|
public:
|
||||||
RenderTarget2D();
|
RenderTarget2D();
|
||||||
RenderTarget2D(sptr<GraphicsDevice> const& device);
|
RenderTarget2D(sptr<GraphicsDevice> const& device);
|
||||||
|
|
||||||
|
//Gets the data format for the depth stencil data.
|
||||||
|
constexpr DepthFormat DepthStencilFormat() const { return depthStencilFormat; }
|
||||||
|
//Gets the number of sample locations during multisampling.
|
||||||
|
constexpr Int MultiSampleCount() const { return multiSampleCount; }
|
||||||
|
//Gets or sets the render target usage.
|
||||||
|
constexpr RenderTargetUsage TargetUsage() const { return targetUsage; }
|
||||||
|
|
||||||
~RenderTarget2D() override;
|
void Initialize();
|
||||||
bool Initialize();
|
void Apply();
|
||||||
bool Apply();
|
private:
|
||||||
|
DepthFormat depthStencilFormat{ DepthFormat::None };
|
||||||
|
Int multiSampleCount{ 0 };
|
||||||
|
RenderTargetUsage targetUsage{ RenderTargetUsage::DiscardContents };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> render_impl = nullptr;
|
uptr<PlatformImplementation> impl2 = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,38 +8,56 @@ namespace xna {
|
|||||||
//Represents a texture resource.
|
//Represents a texture resource.
|
||||||
class Texture : public GraphicsResource {
|
class Texture : public GraphicsResource {
|
||||||
public:
|
public:
|
||||||
Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {}
|
Texture(P_GraphicsDevice const& graphicsDevice) : GraphicsResource(graphicsDevice) {}
|
||||||
|
|
||||||
virtual ~Texture() {}
|
|
||||||
|
|
||||||
//Gets the format of the texture data.
|
//Gets the format of the texture data.
|
||||||
constexpr SurfaceFormat Format() const { return surfaceFormat; }
|
virtual SurfaceFormat Format() const = 0;
|
||||||
//Gets the number of texture levels in a multilevel texture.
|
//Gets the number of texture levels in a multilevel texture.
|
||||||
constexpr Int LevelCount() const { return levelCount; }
|
virtual Int LevelCount() const = 0;
|
||||||
|
|
||||||
protected:
|
|
||||||
SurfaceFormat surfaceFormat{SurfaceFormat::Color};
|
|
||||||
Int levelCount{ 0 };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Represents a 2D grid of texels.
|
||||||
class Texture2D : public Texture {
|
class Texture2D : public Texture {
|
||||||
public:
|
public:
|
||||||
Texture2D();
|
Texture2D();
|
||||||
Texture2D(P_GraphicsDevice const& device);
|
Texture2D(P_GraphicsDevice const& device);
|
||||||
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height);
|
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height);
|
||||||
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
|
Texture2D(P_GraphicsDevice const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format);
|
||||||
~Texture2D() override;
|
|
||||||
Int Width() const;
|
//Gets the width of this texture resource, in pixels.
|
||||||
Int Height() const;
|
constexpr Int Width() const { return width; }
|
||||||
Rectangle Bounds() const;
|
//Gets the height of this texture resource, in pixels.
|
||||||
|
constexpr Int Height() const { return height; }
|
||||||
|
//Gets the size of this resource.
|
||||||
|
constexpr Rectangle Bounds() const { return { 0, 0, width, height }; }
|
||||||
|
//Gets the format of the texture data.
|
||||||
|
constexpr SurfaceFormat Format() const override { return surfaceFormat; }
|
||||||
|
//Gets the number of texture levels in a multilevel texture.
|
||||||
|
constexpr Int LevelCount() const { return levelCount; }
|
||||||
|
|
||||||
|
//Sets data to the texture.
|
||||||
void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
void SetData(std::vector<Color> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
||||||
|
//Sets data to the texture.
|
||||||
void SetData(std::vector<Uint> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
void SetData(std::vector<Uint> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
||||||
|
//Sets data to the texture.
|
||||||
void SetData(std::vector<Byte> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
void SetData(std::vector<Byte> const& data, size_t startIndex = 0, size_t elementCount = 0);
|
||||||
|
//Sets data to the texture.
|
||||||
void SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount);
|
void SetData(Int level, Rectangle* rect, std::vector<Byte> const& data, size_t startIndex, size_t elementCount);
|
||||||
static P_Texture2D FromStream(GraphicsDevice& device, String const& fileName);
|
|
||||||
static P_Texture2D FromMemory(GraphicsDevice& device, std::vector<Byte> const& data);
|
|
||||||
|
|
||||||
void Initialize();
|
//Loads texture data from a stream.
|
||||||
|
static P_Texture2D FromStream(GraphicsDevice& device, P_Stream const& stream);
|
||||||
|
//Loads texture data from a file.
|
||||||
|
static P_Texture2D FromStream(GraphicsDevice& device, String const& fileName);
|
||||||
|
//Loads texture data from a data.
|
||||||
|
static P_Texture2D FromStream(GraphicsDevice& device, std::vector<Byte> const& data);
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SurfaceFormat surfaceFormat{ SurfaceFormat::Color };
|
||||||
|
Int levelCount{ 0 };
|
||||||
|
int width{ 0 };
|
||||||
|
int height{ 0 };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user