mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige ConstantBuffer
This commit is contained in:
parent
eff09301d9
commit
908403ac7b
@ -13,7 +13,7 @@ add_executable (xna WIN32
|
|||||||
"platform/texture-dx.cpp"
|
"platform/texture-dx.cpp"
|
||||||
"platform/blendstate-dx.cpp"
|
"platform/blendstate-dx.cpp"
|
||||||
"platform/game-dx.cpp"
|
"platform/game-dx.cpp"
|
||||||
"platform/clock-dx.cpp"
|
|
||||||
"csharp/stream.cpp"
|
"csharp/stream.cpp"
|
||||||
"platform/gdevicemanager-dx.cpp"
|
"platform/gdevicemanager-dx.cpp"
|
||||||
"platform/vertexinput-dx.cpp"
|
"platform/vertexinput-dx.cpp"
|
||||||
@ -21,7 +21,7 @@ add_executable (xna WIN32
|
|||||||
"platform/rasterizerstate-dx.cpp"
|
"platform/rasterizerstate-dx.cpp"
|
||||||
"platform/vertexbuffer-dx.cpp"
|
"platform/vertexbuffer-dx.cpp"
|
||||||
"platform/indexbuffer-dx.cpp"
|
"platform/indexbuffer-dx.cpp"
|
||||||
"platform/constbuffer-dx.cpp"
|
|
||||||
"platform/databuffer-dx.cpp"
|
"platform/databuffer-dx.cpp"
|
||||||
"platform/samplerstate-dx.cpp"
|
"platform/samplerstate-dx.cpp"
|
||||||
"platform/sprite-dx.cpp"
|
"platform/sprite-dx.cpp"
|
||||||
@ -47,7 +47,7 @@ add_executable (xna WIN32
|
|||||||
"common/color.cpp"
|
"common/color.cpp"
|
||||||
"common/collision.cpp"
|
"common/collision.cpp"
|
||||||
"common/gjk.cpp"
|
"common/gjk.cpp"
|
||||||
"common/numerics.cpp" "common/packedvalue.cpp")
|
"common/numerics.cpp" "common/packedvalue.cpp" "platform/buffer.cpp")
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||||
set_property(TARGET xna PROPERTY CXX_STANDARD 20)
|
set_property(TARGET xna PROPERTY CXX_STANDARD 20)
|
||||||
|
39
framework/platform/buffer.cpp
Normal file
39
framework/platform/buffer.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "graphics/buffer.hpp"
|
||||||
|
#include "common/numerics.hpp"
|
||||||
|
#include "platform-dx/dxheaders.hpp"
|
||||||
|
#include "platform-dx/device-dx.hpp"
|
||||||
|
#include "platform-dx/implementations.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
ConstantBuffer::ConstantBuffer() : GraphicsResource(nullptr){}
|
||||||
|
ConstantBuffer::ConstantBuffer(sptr<GraphicsDevice> const& device) : GraphicsResource(device){}
|
||||||
|
|
||||||
|
ConstantBuffer::~ConstantBuffer() {
|
||||||
|
impl = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConstantBuffer::Initialize(xna_error_ptr_arg)
|
||||||
|
{
|
||||||
|
if (!m_device || !m_device->_device) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (impl->_buffer) {
|
||||||
|
impl->_buffer->Release();
|
||||||
|
impl->_buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto hr = m_device->_device->CreateBuffer(
|
||||||
|
&impl->_description,
|
||||||
|
&impl->_subResource,
|
||||||
|
&impl->_buffer);
|
||||||
|
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,71 +0,0 @@
|
|||||||
#include "platform-dx/clock-dx.hpp"
|
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
void GameClock::Reset() {
|
|
||||||
_start = ClockNow();
|
|
||||||
_end = std::chrono::steady_clock::time_point();
|
|
||||||
_stopped = false;
|
|
||||||
_suspended = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameClock::Start() {
|
|
||||||
Reset();
|
|
||||||
_total = 0;
|
|
||||||
_start = ClockNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameClock::Resume() {
|
|
||||||
if (_stopped)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_suspended) {
|
|
||||||
auto elapsed = _end - _start;
|
|
||||||
auto now = ClockNow();
|
|
||||||
|
|
||||||
_start = now - elapsed;
|
|
||||||
_suspended = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_start = ClockNow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameClock::Suspend() {
|
|
||||||
if (_suspended || _stopped)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_end = ClockNow();
|
|
||||||
_suspended = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameClock::Stop() {
|
|
||||||
Reset();
|
|
||||||
_total = 0;
|
|
||||||
_stopped = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeSpan GameClock::ElapsedTime() {
|
|
||||||
if (_stopped) return TimeSpan();
|
|
||||||
|
|
||||||
if (!_suspended) {
|
|
||||||
_end = ClockNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto nano = GetNanoseconds(_start, _end);
|
|
||||||
return TimeSpan::FromSeconds(nano / 1'000'000'000.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeSpan GameClock::TotalTime() {
|
|
||||||
if (_stopped) return TimeSpan();
|
|
||||||
|
|
||||||
if (!_suspended) {
|
|
||||||
_end = ClockNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto nano = GetNanoseconds(_start, _end);
|
|
||||||
_total += nano;
|
|
||||||
|
|
||||||
return TimeSpan::FromSeconds(_total / 1'000'000'000.0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
#include "platform-dx/constbuffer-dx.hpp"
|
|
||||||
#include "platform-dx/device-dx.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
bool ConstantBuffer::Initialize(GraphicsDevice& device, xna_error_ptr_arg)
|
|
||||||
{
|
|
||||||
if (!device._device) {
|
|
||||||
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_buffer) {
|
|
||||||
_buffer->Release();
|
|
||||||
_buffer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto hr = device._device->CreateBuffer(
|
|
||||||
&_description,
|
|
||||||
&_subResource,
|
|
||||||
&_buffer);
|
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
#ifndef XNA_GAME_CLOCK_HPP
|
|
||||||
#define XNA_GAME_CLOCK_HPP
|
|
||||||
|
|
||||||
#include "../types.hpp"
|
|
||||||
#include "../forward.hpp"
|
|
||||||
#include "../enums.hpp"
|
|
||||||
#include "../csharp/timespan.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
class IGameClock {
|
|
||||||
public:
|
|
||||||
virtual ~IGameClock() {}
|
|
||||||
|
|
||||||
virtual void Start() = 0;
|
|
||||||
virtual void Resume() = 0;
|
|
||||||
virtual void Reset() = 0;
|
|
||||||
virtual void Suspend() = 0;
|
|
||||||
virtual void Stop() = 0;
|
|
||||||
virtual TimeSpan ElapsedTime() = 0;
|
|
||||||
virtual TimeSpan TotalTime() = 0;
|
|
||||||
virtual bool IsActive() = 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
21
inc/graphics/buffer.hpp
Normal file
21
inc/graphics/buffer.hpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef XNA_GRAPHICS_BUFFER_HPP
|
||||||
|
#define XNA_GRAPHICS_BUFFER_HPP
|
||||||
|
|
||||||
|
#include "../default.hpp"
|
||||||
|
#include "gresource.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
class ConstantBuffer : public GraphicsResource {
|
||||||
|
public:
|
||||||
|
ConstantBuffer();
|
||||||
|
ConstantBuffer(sptr<GraphicsDevice> const&);
|
||||||
|
~ConstantBuffer();
|
||||||
|
bool Initialize(xna_error_nullarg);
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct PlatformImplementation;
|
||||||
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,14 +0,0 @@
|
|||||||
#ifndef XNA_GRAPHICS_CONSTBUFFER_HPP
|
|
||||||
#define XNA_GRAPHICS_CONSTBUFFER_HPP
|
|
||||||
|
|
||||||
#include "../default.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
class IConstantBuffer {
|
|
||||||
public:
|
|
||||||
virtual ~IConstantBuffer(){}
|
|
||||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,51 +0,0 @@
|
|||||||
#ifndef XNA_PLATFORM_CLOCK_DX_HPP
|
|
||||||
#define XNA_PLATFORM_CLOCK_DX_HPP
|
|
||||||
|
|
||||||
#include "../game/clock.hpp"
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
using SteadyClock = std::chrono::steady_clock;
|
|
||||||
|
|
||||||
class GameClock : public IGameClock {
|
|
||||||
public:
|
|
||||||
virtual ~GameClock() override {}
|
|
||||||
virtual void Reset() override;
|
|
||||||
virtual void Start() override;
|
|
||||||
virtual void Resume() override;
|
|
||||||
virtual void Suspend() override;
|
|
||||||
virtual void Stop() override;
|
|
||||||
virtual TimeSpan ElapsedTime() override;
|
|
||||||
virtual TimeSpan TotalTime() override;
|
|
||||||
|
|
||||||
virtual constexpr bool IsActive() override {
|
|
||||||
return !_suspended && !_stopped;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SteadyClock::time_point ClockNow() {
|
|
||||||
return SteadyClock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr long long GetNanoseconds(SteadyClock::time_point start, SteadyClock::time_point end) {
|
|
||||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr long long GetMicroseconds(SteadyClock::time_point start, SteadyClock::time_point end) {
|
|
||||||
return std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr long long GetMilliSeconds(SteadyClock::time_point start, SteadyClock::time_point end) {
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
SteadyClock _clock;
|
|
||||||
SteadyClock::time_point _start;
|
|
||||||
SteadyClock::time_point _end;
|
|
||||||
long long _total{ 0 };
|
|
||||||
bool _suspended{ false };
|
|
||||||
bool _stopped { true };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,29 +0,0 @@
|
|||||||
#ifndef XNA_PLATFORM_CONSTBUFFER_DX_HPP
|
|
||||||
#define XNA_PLATFORM_CONSTBUFFER_DX_HPP
|
|
||||||
|
|
||||||
#include "../graphics/constbuffer.hpp"
|
|
||||||
#include "../common/numerics.hpp"
|
|
||||||
#include "dxheaders.hpp"
|
|
||||||
#include <BufferHelpers.h>
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
class ConstantBuffer : public IConstantBuffer {
|
|
||||||
public:
|
|
||||||
virtual ~ConstantBuffer() override {
|
|
||||||
if (_buffer) {
|
|
||||||
_buffer->Release();
|
|
||||||
_buffer = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
D3D11_BUFFER_DESC _description{};
|
|
||||||
D3D11_SUBRESOURCE_DATA _subResource{};
|
|
||||||
ID3D11Buffer* _buffer = nullptr;
|
|
||||||
DirectX::XMMATRIX _worldViewProjection;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,6 +1,7 @@
|
|||||||
#include "graphics/sprite.hpp"
|
#include "graphics/sprite.hpp"
|
||||||
#include "graphics/device.hpp"
|
#include "graphics/device.hpp"
|
||||||
#include "graphics/adapter.hpp"
|
#include "graphics/adapter.hpp"
|
||||||
|
#include "graphics/buffer.hpp"
|
||||||
#include "platform-dx/presentparameters-dx.hpp"
|
#include "platform-dx/presentparameters-dx.hpp"
|
||||||
#include "dxheaders.hpp"
|
#include "dxheaders.hpp"
|
||||||
#include "platform-dx/swapchain-dx.hpp"
|
#include "platform-dx/swapchain-dx.hpp"
|
||||||
@ -218,4 +219,18 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ConstantBuffer::PlatformImplementation {
|
||||||
|
~PlatformImplementation() {
|
||||||
|
if (_buffer) {
|
||||||
|
_buffer->Release();
|
||||||
|
_buffer = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D11_BUFFER_DESC _description{};
|
||||||
|
D3D11_SUBRESOURCE_DATA _subResource{};
|
||||||
|
ID3D11Buffer* _buffer = nullptr;
|
||||||
|
DirectX::XMMATRIX _worldViewProjection;
|
||||||
|
};
|
||||||
}
|
}
|
@ -1,6 +1,4 @@
|
|||||||
#include "audioengine-dx.hpp"
|
#include "audioengine-dx.hpp"
|
||||||
#include "clock-dx.hpp"
|
|
||||||
#include "constbuffer-dx.hpp"
|
|
||||||
#include "databuffer-dx.hpp"
|
#include "databuffer-dx.hpp"
|
||||||
#include "depthstencilstate-dx.hpp"
|
#include "depthstencilstate-dx.hpp"
|
||||||
#include "device-dx.hpp"
|
#include "device-dx.hpp"
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "csharp/stream.hpp"
|
#include "csharp/stream.hpp"
|
||||||
#include "csharp/timespan.hpp"
|
#include "csharp/timespan.hpp"
|
||||||
#include "csharp/type.hpp"
|
#include "csharp/type.hpp"
|
||||||
#include "game/clock.hpp"
|
|
||||||
#include "game/component.hpp"
|
#include "game/component.hpp"
|
||||||
#include "game/game.hpp"
|
#include "game/game.hpp"
|
||||||
#include "game/gdeviceinfo.hpp"
|
#include "game/gdeviceinfo.hpp"
|
||||||
@ -34,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/constbuffer.hpp"
|
|
||||||
#include "graphics/databuffer.hpp"
|
#include "graphics/databuffer.hpp"
|
||||||
#include "graphics/depthstencilstate.hpp"
|
#include "graphics/depthstencilstate.hpp"
|
||||||
#include "graphics/device.hpp"
|
#include "graphics/device.hpp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user