mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige IndexBuffer
This commit is contained in:
parent
9443d20ef7
commit
80ff2d2fe5
@ -20,7 +20,7 @@ add_executable (xna WIN32
|
|||||||
"platform/shader-dx.cpp"
|
"platform/shader-dx.cpp"
|
||||||
"platform/rasterizerstate-dx.cpp"
|
"platform/rasterizerstate-dx.cpp"
|
||||||
"platform/vertexbuffer-dx.cpp"
|
"platform/vertexbuffer-dx.cpp"
|
||||||
"platform/indexbuffer-dx.cpp"
|
|
||||||
|
|
||||||
|
|
||||||
"platform/samplerstate-dx.cpp"
|
"platform/samplerstate-dx.cpp"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
ConstantBuffer::ConstantBuffer() : GraphicsResource(nullptr){
|
ConstantBuffer::ConstantBuffer() : GraphicsResource(nullptr){
|
||||||
impl = uNew<PlatformImplementation>();
|
impl = uNew<PlatformImplementation>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantBuffer::ConstantBuffer(sptr<GraphicsDevice> const& device) : GraphicsResource(device){
|
ConstantBuffer::ConstantBuffer(sptr<GraphicsDevice> const& device) : GraphicsResource(device){
|
||||||
@ -67,4 +67,27 @@ namespace xna {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IndexBuffer::IndexBuffer() : GraphicsResource(nullptr) {
|
||||||
|
impl = uNew<PlatformImplementation>();
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexBuffer::IndexBuffer(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||||
|
impl = uNew<PlatformImplementation>();
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexBuffer::~IndexBuffer() {
|
||||||
|
impl = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IndexBuffer::Apply(xna_error_ptr_arg) {
|
||||||
|
if (!m_device || !m_device->_context || !impl || !impl->dxBuffer) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_device->_context->IASetIndexBuffer(impl->dxBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -41,6 +41,10 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::Initialize() {
|
void Game::Initialize() {
|
||||||
|
Keyboard::Initialize();
|
||||||
|
Mouse::Initialize();
|
||||||
|
GamePad::Initialize();
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
||||||
Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
|
Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
|
||||||
if (FAILED(initialize))
|
if (FAILED(initialize))
|
||||||
@ -53,10 +57,7 @@ namespace xna {
|
|||||||
{
|
{
|
||||||
MessageBox(nullptr, "Ocorreu um erro ao chamar CoInitializeEx.", "XN65", MB_OK);
|
MessageBox(nullptr, "Ocorreu um erro ao chamar CoInitializeEx.", "XN65", MB_OK);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Keyboard::Initialize();
|
|
||||||
Mouse::Initialize();
|
|
||||||
GamePad::Initialize();
|
|
||||||
|
|
||||||
_audioEngine = New<AudioEngine>();
|
_audioEngine = New<AudioEngine>();
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
#include "platform-dx/indexbuffer-dx.hpp"
|
|
||||||
#include "platform-dx/device-dx.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
}
|
|
@ -24,6 +24,21 @@ namespace xna {
|
|||||||
~DataBuffer();
|
~DataBuffer();
|
||||||
bool Initialize(xna_error_nullarg);
|
bool Initialize(xna_error_nullarg);
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct PlatformImplementation;
|
||||||
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class IndexBuffer : public GraphicsResource {
|
||||||
|
public:
|
||||||
|
IndexBuffer();
|
||||||
|
IndexBuffer(sptr<GraphicsDevice> const&);
|
||||||
|
~IndexBuffer();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool Initialize(std::vector<T> const& data, xna_error_nullarg);
|
||||||
|
bool Apply(xna_error_nullarg);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> impl = nullptr;
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
#ifndef XNA_GRAPHICS_INDEXBUFFER_HPP
|
|
||||||
#define XNA_GRAPHICS_INDEXBUFFER_HPP
|
|
||||||
|
|
||||||
#include "../default.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
class IIndexBuffer {
|
|
||||||
public:
|
|
||||||
virtual ~IIndexBuffer() {}
|
|
||||||
virtual bool Initialize(xna_error_nullarg) = 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -157,7 +157,7 @@ namespace xna {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GamePadState {
|
struct GamePadState {
|
||||||
GamePadState() = default;
|
constexpr GamePadState() = default;
|
||||||
|
|
||||||
constexpr bool IsButtonDown(xna::Buttons button) const {
|
constexpr bool IsButtonDown(xna::Buttons button) const {
|
||||||
switch (button)
|
switch (button)
|
||||||
|
@ -150,4 +150,32 @@ namespace xna {
|
|||||||
|
|
||||||
inline static uptr<DirectX::GamePad> _dxGamePad = nullptr;
|
inline static uptr<DirectX::GamePad> _dxGamePad = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct IndexBuffer::PlatformImplementation {
|
||||||
|
~PlatformImplementation() {
|
||||||
|
if (dxBuffer) {
|
||||||
|
dxBuffer->Release();
|
||||||
|
dxBuffer = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ID3D11Buffer* dxBuffer = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool IndexBuffer::Initialize(std::vector<T> const& data, xna_error_ptr_arg) {
|
||||||
|
if (!impl || !m_device || !m_device->_device || data.empty()) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto hr = DirectX::CreateStaticBuffer(m_device->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_INDEX_BUFFER, &impl->dxBuffer);
|
||||||
|
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,59 +0,0 @@
|
|||||||
#ifndef XNA_PLATFORM_INDEXBUFFER_DX_HPP
|
|
||||||
#define XNA_PLATFORM_INDEXBUFFER_DX_HPP
|
|
||||||
|
|
||||||
#include "../graphics/gresource.hpp"
|
|
||||||
#include "../graphics/indexbuffer.hpp"
|
|
||||||
#include "device-dx.hpp"
|
|
||||||
#include "dxheaders.hpp"
|
|
||||||
#include <BufferHelpers.h>
|
|
||||||
#include <VertexTypes.h>
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
template <typename T>
|
|
||||||
class IndexBuffer : public IIndexBuffer, public GraphicsResource {
|
|
||||||
public:
|
|
||||||
constexpr IndexBuffer(GraphicsDevice* device) : GraphicsResource(device) {}
|
|
||||||
|
|
||||||
constexpr IndexBuffer(GraphicsDevice* device, std::vector<T> const& indices) : data(indices), GraphicsResource(device) {}
|
|
||||||
|
|
||||||
virtual ~IndexBuffer() override {
|
|
||||||
if (dxBuffer) {
|
|
||||||
dxBuffer->Release();
|
|
||||||
dxBuffer = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool Initialize(xna_error_ptr_arg) override {
|
|
||||||
if (!m_device || !m_device->_device || data.empty()) {
|
|
||||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto hr = DirectX::CreateStaticBuffer(m_device->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_INDEX_BUFFER, &dxBuffer);
|
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool Apply(xna_error_ptr_arg) override {
|
|
||||||
if (!m_device || !m_device->_context || !dxBuffer) {
|
|
||||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_device->_context->IASetIndexBuffer(dxBuffer, DXGI_FORMAT_R16_UINT, 0);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
ID3D11Buffer* dxBuffer = nullptr;
|
|
||||||
std::vector<T> data;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -6,7 +6,6 @@
|
|||||||
#include "game-dx.hpp"
|
#include "game-dx.hpp"
|
||||||
#include "gdeviceinfo-dx.hpp"
|
#include "gdeviceinfo-dx.hpp"
|
||||||
#include "gdevicemanager-dx.hpp"
|
#include "gdevicemanager-dx.hpp"
|
||||||
#include "indexbuffer-dx.hpp"
|
|
||||||
#include "init-dx.hpp"
|
#include "init-dx.hpp"
|
||||||
#include "keyboard-dx.hpp"
|
#include "keyboard-dx.hpp"
|
||||||
#include "mouse-dx.hpp"
|
#include "mouse-dx.hpp"
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
#include "graphics/device.hpp"
|
#include "graphics/device.hpp"
|
||||||
#include "graphics/displaymode.hpp"
|
#include "graphics/displaymode.hpp"
|
||||||
#include "graphics/gresource.hpp"
|
#include "graphics/gresource.hpp"
|
||||||
#include "graphics/indexbuffer.hpp"
|
|
||||||
#include "graphics/presentparams.hpp"
|
#include "graphics/presentparams.hpp"
|
||||||
#include "graphics/rasterizerstate.hpp"
|
#include "graphics/rasterizerstate.hpp"
|
||||||
#include "graphics/rendertarget.hpp"
|
#include "graphics/rendertarget.hpp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user