mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige VertexBuffer
This commit is contained in:
parent
908539a995
commit
110e56aacb
@ -19,7 +19,7 @@ add_executable (xna WIN32
|
||||
"platform/vertexinput-dx.cpp"
|
||||
"platform/shader-dx.cpp"
|
||||
"platform/rasterizerstate-dx.cpp"
|
||||
"platform/vertexbuffer-dx.cpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -90,4 +90,35 @@ namespace xna {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer() : GraphicsResource(nullptr) {
|
||||
impl = uNew<PlatformImplementation>();
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||
impl = uNew<PlatformImplementation>();
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer() {
|
||||
impl = nullptr;
|
||||
}
|
||||
|
||||
bool VertexBuffer::Apply(xna_error_ptr_arg) {
|
||||
if (!impl || !m_device || !m_device->_context) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!impl->dxBuffer) {
|
||||
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
|
||||
return false;
|
||||
}
|
||||
|
||||
UINT stride = impl->size;
|
||||
UINT offset = 0;
|
||||
m_device->_context->IASetVertexBuffers(0, 1,
|
||||
&impl->dxBuffer, &stride, &offset);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
#include "platform-dx/vertexbuffer-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
}
|
@ -43,6 +43,20 @@ namespace xna {
|
||||
struct PlatformImplementation;
|
||||
uptr<PlatformImplementation> impl = nullptr;
|
||||
};
|
||||
|
||||
class VertexBuffer : public GraphicsResource {
|
||||
public:
|
||||
VertexBuffer();
|
||||
VertexBuffer(sptr<GraphicsDevice> const&);
|
||||
~VertexBuffer();
|
||||
template <typename T>
|
||||
bool Initialize(std::vector<T> const& data, xna_error_nullarg);
|
||||
bool Apply(xna_error_nullarg);
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
uptr<PlatformImplementation> impl = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,15 +0,0 @@
|
||||
#ifndef XNA_GRAPHICS_VERTEXBUFFER_HPP
|
||||
#define XNA_GRAPHICS_VERTEXBUFFER_HPP
|
||||
|
||||
#include "../default.hpp"
|
||||
|
||||
namespace xna {
|
||||
class IVertexBuffer {
|
||||
public:
|
||||
virtual ~IVertexBuffer(){}
|
||||
virtual bool Initialize(xna_error_nullarg) = 0;
|
||||
virtual bool Apply(xna_error_nullarg) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -302,6 +302,37 @@ namespace xna {
|
||||
ID3D11RenderTargetView* _renderTargetView = nullptr;
|
||||
D3D11_RENDER_TARGET_VIEW_DESC _renderTargetDesc{};
|
||||
};
|
||||
|
||||
struct VertexBuffer::PlatformImplementation {
|
||||
~PlatformImplementation() {
|
||||
if (dxBuffer) {
|
||||
dxBuffer->Release();
|
||||
dxBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11Buffer* dxBuffer = nullptr;
|
||||
UINT size{ 0 };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline bool VertexBuffer::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_VERTEX_BUFFER, &impl->dxBuffer);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
return false;
|
||||
}
|
||||
|
||||
impl->size = sizeof(T);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,38 +0,0 @@
|
||||
/**********************************************************************************
|
||||
// Pixel (Arquivo de Sombreamento)
|
||||
//
|
||||
// Criação: 11 Jul 2007
|
||||
// Atualização: 13 Ago 2021
|
||||
// Compilador: D3DCompiler
|
||||
//
|
||||
// Descrição: Define um pixel shader que apenas multiplica a cor do objeto
|
||||
// pela cor da textura, depois de fazer uma amostragem linear
|
||||
// ou anisotrópica
|
||||
//
|
||||
**********************************************************************************/
|
||||
|
||||
|
||||
Texture2D resource;
|
||||
|
||||
SamplerState linearfilter
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
};
|
||||
|
||||
SamplerState anisotropic
|
||||
{
|
||||
Filter = ANISOTROPIC;
|
||||
MaxAnisotropy = 4;
|
||||
};
|
||||
|
||||
struct pixelIn
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float4 Color : COLOR;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
float4 main(pixelIn pIn) : SV_TARGET
|
||||
{
|
||||
return resource.Sample(linearfilter, pIn.Tex) * pIn.Color;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/**********************************************************************************
|
||||
// Vertex (Arquivo de Sombreamento)
|
||||
//
|
||||
// Criação: 11 Jul 2007
|
||||
// Atualização: 13 Ago 2021
|
||||
// Compilador: D3DCompiler
|
||||
//
|
||||
// Descrição: Define um vertex shader que apenas multiplica os vértices
|
||||
// por uma matriz de transformação e projeção
|
||||
//
|
||||
**********************************************************************************/
|
||||
|
||||
// matriz de transformação e projeção
|
||||
cbuffer ConstantBuffer
|
||||
{
|
||||
float4x4 WorldViewProj;
|
||||
}
|
||||
|
||||
// estrutura dos vértices de entrada
|
||||
struct VertexIn
|
||||
{
|
||||
float3 Pos : POSITION;
|
||||
float4 Color : COLOR;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
// estrutura dos vértices de saída
|
||||
struct VertexOut
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float4 Color : COLOR;
|
||||
float2 Tex : TEXCOORD;
|
||||
};
|
||||
|
||||
// programa principal do vertex shader
|
||||
VertexOut main(VertexIn vIn)
|
||||
{
|
||||
VertexOut vOut;
|
||||
|
||||
// transforma vértices para coordenadas da tela
|
||||
vOut.Pos = mul(float4(vIn.Pos, 1.0f), WorldViewProj);
|
||||
|
||||
// mantém as cores inalteradas
|
||||
vOut.Color = vIn.Color;
|
||||
|
||||
// mantém as coordenadas da textura inalteradas
|
||||
vOut.Tex = vIn.Tex;
|
||||
|
||||
return vOut;
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
#ifndef XNA_PLATFORM_VERTEXBUFFER_DX_HPP
|
||||
#define XNA_PLATFORM_VERTEXBUFFER_DX_HPP
|
||||
|
||||
#include "../graphics/vertexbuffer.hpp"
|
||||
#include "../graphics/vertexposition.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
#include <BufferHelpers.h>
|
||||
#include <VertexTypes.h>
|
||||
#include "device-dx.hpp"
|
||||
#include "../graphics/gresource.hpp"
|
||||
|
||||
namespace xna {
|
||||
template <typename T>
|
||||
class VertexBuffer : public IVertexBuffer, public GraphicsResource {
|
||||
public:
|
||||
constexpr VertexBuffer(GraphicsDevice* device) : GraphicsResource(device){}
|
||||
|
||||
constexpr VertexBuffer(GraphicsDevice* device, std::vector<T> const& vertices) : data(vertices), GraphicsResource(device) {}
|
||||
|
||||
virtual ~VertexBuffer() 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_VERTEX_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;
|
||||
}
|
||||
|
||||
UINT stride = sizeof(T);
|
||||
UINT offset = 0;
|
||||
m_device->_context->IASetVertexBuffers(0, 1,
|
||||
&dxBuffer, &stride, &offset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
ID3D11Buffer* dxBuffer = nullptr;
|
||||
std::vector<T> data;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -8,7 +8,6 @@
|
||||
#include "gdevicemanager-dx.hpp"
|
||||
#include "init-dx.hpp"
|
||||
#include "soundeffect-dx.hpp"
|
||||
#include "vertexbuffer-dx.hpp"
|
||||
#include "vertexinput-dx.hpp"
|
||||
#include "window-dx.hpp"
|
||||
#include "implementations.hpp"
|
@ -45,7 +45,6 @@
|
||||
#include "graphics/sprite.hpp"
|
||||
#include "graphics/swapchain.hpp"
|
||||
#include "graphics/texture.hpp"
|
||||
#include "graphics/vertexbuffer.hpp"
|
||||
#include "graphics/vertexinput.hpp"
|
||||
#include "graphics/vertexposition.hpp"
|
||||
#include "graphics/viewport.hpp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user