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

Corrige DataBuffer

This commit is contained in:
Danilo 2024-05-20 09:32:34 -03:00
parent 908403ac7b
commit 1ca0bf2ffb
13 changed files with 78 additions and 63 deletions

View File

@ -22,7 +22,7 @@ add_executable (xna WIN32
"platform/vertexbuffer-dx.cpp" "platform/vertexbuffer-dx.cpp"
"platform/indexbuffer-dx.cpp" "platform/indexbuffer-dx.cpp"
"platform/databuffer-dx.cpp"
"platform/samplerstate-dx.cpp" "platform/samplerstate-dx.cpp"
"platform/sprite-dx.cpp" "platform/sprite-dx.cpp"

View File

@ -5,8 +5,13 @@
#include "platform-dx/implementations.hpp" #include "platform-dx/implementations.hpp"
namespace xna { namespace xna {
ConstantBuffer::ConstantBuffer() : GraphicsResource(nullptr){} ConstantBuffer::ConstantBuffer() : GraphicsResource(nullptr){
ConstantBuffer::ConstantBuffer(sptr<GraphicsDevice> const& device) : GraphicsResource(device){} impl = uNew<PlatformImplementation>();
}
ConstantBuffer::ConstantBuffer(sptr<GraphicsDevice> const& device) : GraphicsResource(device){
impl = uNew<PlatformImplementation>();
}
ConstantBuffer::~ConstantBuffer() { ConstantBuffer::~ConstantBuffer() {
impl = nullptr; impl = nullptr;
@ -36,4 +41,30 @@ namespace xna {
return true; return true;
} }
DataBuffer::DataBuffer() : GraphicsResource(nullptr) {
impl = uNew<PlatformImplementation>();
}
DataBuffer::DataBuffer(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
impl = uNew<PlatformImplementation>();
}
DataBuffer::~DataBuffer() {
impl = nullptr;
}
bool DataBuffer::Initialize(xna_error_ptr_arg) {
if (!m_device || !m_device->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
if (impl->_blob) {
impl->_blob->Release();
impl->_blob = nullptr;
}
return true;
}
} }

View File

@ -1,6 +0,0 @@
#include "platform-dx/databuffer-dx.hpp"
namespace xna {
}

View File

@ -1,6 +1,7 @@
#include "platform-dx/shader-dx.hpp" #include "platform-dx/shader-dx.hpp"
#include "platform-dx/device-dx.hpp" #include "platform-dx/device-dx.hpp"
#include "platform-dx/databuffer-dx.hpp" #include "graphics/buffer.hpp"
#include "platform-dx/implementations.hpp"
namespace xna { namespace xna {
HRESULT Shader::CompileFromFile(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob) HRESULT Shader::CompileFromFile(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob)
@ -49,7 +50,7 @@ namespace xna {
bool VertexShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg) bool VertexShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg)
{ {
if (!m_device || !m_device->_device || !buffer._blob) { if (!m_device || !m_device->_device || !buffer.impl->_blob) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false; return false;
} }
@ -60,8 +61,8 @@ namespace xna {
} }
const auto hr = m_device->_device->CreateVertexShader( const auto hr = m_device->_device->CreateVertexShader(
buffer._blob->GetBufferPointer(), buffer.impl->_blob->GetBufferPointer(),
buffer._blob->GetBufferSize(), buffer.impl->_blob->GetBufferSize(),
NULL, NULL,
&_vertexShader); &_vertexShader);
@ -75,7 +76,7 @@ namespace xna {
bool PixelShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg) bool PixelShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg)
{ {
if (!m_device || !m_device->_device || !buffer._blob) { if (!m_device || !m_device->_device || !buffer.impl->_blob) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false; return false;
} }
@ -86,8 +87,8 @@ namespace xna {
} }
const auto hr = m_device->_device->CreatePixelShader( const auto hr = m_device->_device->CreatePixelShader(
buffer._blob->GetBufferPointer(), buffer.impl->_blob->GetBufferPointer(),
buffer._blob->GetBufferSize(), buffer.impl->_blob->GetBufferSize(),
NULL, NULL,
&_pixelShader); &_pixelShader);

View File

@ -1,11 +1,11 @@
#include "platform-dx/vertexinput-dx.hpp" #include "platform-dx/vertexinput-dx.hpp"
#include "platform-dx/device-dx.hpp" #include "platform-dx/device-dx.hpp"
#include "platform-dx/dxheaders.hpp" #include "platform-dx/dxheaders.hpp"
#include "platform-dx/databuffer-dx.hpp" #include "platform-dx/implementations.hpp"
namespace xna { namespace xna {
bool VertexInputLayout::Initialize(GraphicsDevice& device, DataBuffer& blob, xna_error_ptr_arg){ bool VertexInputLayout::Initialize(GraphicsDevice& device, DataBuffer& blob, xna_error_ptr_arg){
if (!device._device || !blob._blob) { if (!device._device || !blob.impl->_blob) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false; return false;
} }
@ -18,8 +18,8 @@ namespace xna {
const auto hr = device._device->CreateInputLayout( const auto hr = device._device->CreateInputLayout(
_description.data(), _description.data(),
static_cast<UINT>(_description.size()), static_cast<UINT>(_description.size()),
blob._blob->GetBufferPointer(), blob.impl->_blob->GetBufferPointer(),
blob._blob->GetBufferSize(), blob.impl->_blob->GetBufferSize(),
&_inputLayout); &_inputLayout);
if (FAILED(hr)) { if (FAILED(hr)) {

View File

@ -44,7 +44,10 @@ namespace xna {
graphicsDevice->Clear(Colors::CornflowerBlue); graphicsDevice->Clear(Colors::CornflowerBlue);
spriteBatch->Begin(); spriteBatch->Begin();
spriteBatch->Draw(*texture, Vector2(), Colors::White);
if(texture)
spriteBatch->Draw(*texture, Vector2(), Colors::White);
spriteBatch->End(); spriteBatch->End();
Game::Draw(gameTime); Game::Draw(gameTime);

View File

@ -16,6 +16,18 @@ namespace xna {
struct PlatformImplementation; struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr; uptr<PlatformImplementation> impl = nullptr;
}; };
class DataBuffer : public GraphicsResource {
public:
DataBuffer();
DataBuffer(sptr<GraphicsDevice> const&);
~DataBuffer();
bool Initialize(xna_error_nullarg);
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
};
} }
#endif #endif

View File

@ -1,14 +0,0 @@
#ifndef XNA_GRAPHICS_DATABUFFER_HPP
#define XNA_GRAPHICS_DATABUFFER_HPP
#include "../default.hpp"
namespace xna {
class IDataBuffer {
public:
virtual ~IDataBuffer(){}
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0;
};
}
#endif

View File

@ -1,26 +0,0 @@
#ifndef XNA_PLATFORM_DATABUFFER_DX_HPP
#define XNA_PLATFORM_DATABUFFER_DX_HPP
#include "../graphics/databuffer.hpp"
#include "dxheaders.hpp"
namespace xna {
class DataBuffer : public IDataBuffer {
public:
virtual ~DataBuffer() override {
if (_blob) {
_blob->Release();
_blob = nullptr;
}
}
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override {
return false;
}
public:
ID3DBlob* _blob = nullptr;
};
}
#endif

View File

@ -233,4 +233,19 @@ namespace xna {
ID3D11Buffer* _buffer = nullptr; ID3D11Buffer* _buffer = nullptr;
DirectX::XMMATRIX _worldViewProjection; DirectX::XMMATRIX _worldViewProjection;
}; };
struct DataBuffer::PlatformImplementation {
~PlatformImplementation() {
if (_blob) {
_blob->Release();
_blob = nullptr;
}
}
ID3DBlob* _blob = nullptr;
void Set(ID3DBlob*& blob) {
_blob = blob;
}
};
} }

View File

@ -3,6 +3,7 @@
#include "../graphics/shader.hpp" #include "../graphics/shader.hpp"
#include "../graphics/gresource.hpp" #include "../graphics/gresource.hpp"
#include "graphics/buffer.hpp"
#include "dxheaders.hpp" #include "dxheaders.hpp"
namespace xna { namespace xna {

View File

@ -1,5 +1,4 @@
#include "audioengine-dx.hpp" #include "audioengine-dx.hpp"
#include "databuffer-dx.hpp"
#include "depthstencilstate-dx.hpp" #include "depthstencilstate-dx.hpp"
#include "device-dx.hpp" #include "device-dx.hpp"
#include "displaymode-dx.hpp" #include "displaymode-dx.hpp"

View File

@ -33,7 +33,6 @@
#include "game/window.hpp" #include "game/window.hpp"
#include "graphics/adapter.hpp" #include "graphics/adapter.hpp"
#include "graphics/blendstate.hpp" #include "graphics/blendstate.hpp"
#include "graphics/databuffer.hpp"
#include "graphics/depthstencilstate.hpp" #include "graphics/depthstencilstate.hpp"
#include "graphics/device.hpp" #include "graphics/device.hpp"
#include "graphics/displaymode.hpp" #include "graphics/displaymode.hpp"