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

Corrige Shader

This commit is contained in:
Danilo 2024-05-22 17:43:29 -03:00
parent a29d9d2790
commit 522edf20a0
5 changed files with 72 additions and 72 deletions

View File

@ -1,10 +1,10 @@
#include "platform-dx/shader-dx.hpp"
#include "platform-dx/device-dx.hpp"
#include "graphics/buffer.hpp"
#include "platform-dx/implementations.hpp"
#include "graphics/shader.hpp"
namespace xna {
HRESULT Shader::CompileFromFile(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob)
static HRESULT shaderCompileFromFile(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob)
{
//https://learn.microsoft.com/en-us/windows/win32/direct3d11/how-to--compile-a-shader
@ -48,23 +48,29 @@ namespace xna {
return hr;
}
bool Shader::CompileFromFile(WString srcFile, String entryPoint, String profile, DataBuffer& blob) {
const auto hr = shaderCompileFromFile(srcFile.c_str(), entryPoint.c_str(), profile.c_str(), &blob.impl->_blob);
return SUCCEEDED(hr);
}
bool VertexShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg)
{
if (!m_device || !m_device->_device || !buffer.impl->_blob) {
if (!impl || !m_device || !m_device->_device || !buffer.impl->_blob) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
if (_vertexShader) {
_vertexShader->Release();
_vertexShader = nullptr;
if (impl->_vertexShader) {
impl->_vertexShader->Release();
impl->_vertexShader = nullptr;
}
const auto hr = m_device->_device->CreateVertexShader(
buffer.impl->_blob->GetBufferPointer(),
buffer.impl->_blob->GetBufferSize(),
NULL,
&_vertexShader);
&impl->_vertexShader);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
@ -76,21 +82,21 @@ namespace xna {
bool PixelShader::Initialize(DataBuffer& buffer, xna_error_ptr_arg)
{
if (!m_device || !m_device->_device || !buffer.impl->_blob) {
if (!impl || !m_device || !m_device->_device || !buffer.impl->_blob) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
if (_pixelShader) {
_pixelShader->Release();
_pixelShader = nullptr;
if (impl->_pixelShader) {
impl->_pixelShader->Release();
impl->_pixelShader = nullptr;
}
const auto hr = m_device->_device->CreatePixelShader(
buffer.impl->_blob->GetBufferPointer(),
buffer.impl->_blob->GetBufferSize(),
NULL,
&_pixelShader);
&impl->_pixelShader);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);

View File

@ -2,12 +2,40 @@
#define XNA_GRAPHICS_SHADER_HPP
#include "../default.hpp"
#include "gresource.hpp"
namespace xna {
class IShader {
class Shader : public GraphicsResource {
public:
virtual ~IShader() {}
virtual bool Initialize(DataBuffer& buffer, xna_error_nullarg) = 0;
Shader();
Shader(sptr<GraphicsDevice> const& device);
~Shader();
bool Initialize(DataBuffer& buffer, xna_error_nullarg);
static bool CompileFromFile(WString srcFile, String entryPoint, String profile, DataBuffer& blob);
};
class VertexShader : public Shader {
public:
VertexShader();
VertexShader(sptr<GraphicsDevice> const& device);
~VertexShader();
bool Initialize(DataBuffer& buffer, xna_error_nullarg);
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
};
class PixelShader : public Shader {
public:
PixelShader();
PixelShader(sptr<GraphicsDevice> const& device);
~PixelShader();
bool Initialize(DataBuffer& buffer, xna_error_nullarg);
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
};
}

View File

@ -14,6 +14,7 @@
#include "graphics/presentparams.hpp"
#include "platform-dx/rendertarget-dx.hpp"
#include "platform-dx/swapchain-dx.hpp"
#include "graphics/shader.hpp"
namespace xna {
struct SpriteFont::PlatformImplementation {
@ -227,4 +228,26 @@ namespace xna {
ID3D11SamplerState* _samplerState = nullptr;
D3D11_SAMPLER_DESC _description{};
};
struct VertexShader::PlatformImplementation {
~PlatformImplementation() {
if (_vertexShader) {
_vertexShader->Release();
_vertexShader = nullptr;
}
}
ID3D11VertexShader* _vertexShader = nullptr;
};
struct PixelShader::PlatformImplementation {
~PlatformImplementation() {
if (_pixelShader) {
_pixelShader->Release();
_pixelShader = nullptr;
}
}
ID3D11PixelShader* _pixelShader = nullptr;
};
}

View File

@ -1,56 +0,0 @@
#ifndef XNA_PLATFORM_SHADER_DX_HPP
#define XNA_PLATFORM_SHADER_DX_HPP
#include "../graphics/shader.hpp"
#include "../graphics/gresource.hpp"
#include "graphics/buffer.hpp"
#include "dxheaders.hpp"
namespace xna {
class Shader : public IShader, public GraphicsResource {
public:
Shader(sptr<GraphicsDevice> const& device) : GraphicsResource(device){}
virtual ~Shader() override {}
virtual bool Initialize(DataBuffer& buffer, xna_error_nullarg) override {}
static HRESULT CompileFromFile(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob);
};
class VertexShader : public Shader {
public:
VertexShader(sptr<GraphicsDevice> const& device) : Shader(device){}
virtual ~VertexShader() override {
if (_vertexShader) {
_vertexShader->Release();
_vertexShader = nullptr;
}
}
virtual bool Initialize(DataBuffer& buffer, xna_error_nullarg) override;
public:
ID3D11VertexShader* _vertexShader = nullptr;
};
class PixelShader : public Shader {
public:
PixelShader(sptr<GraphicsDevice> const& device) : Shader(device) {}
virtual ~PixelShader() override {
if (_pixelShader) {
_pixelShader->Release();
_pixelShader = nullptr;
}
}
virtual bool Initialize(DataBuffer& buffer, xna_error_nullarg) override;
public:
ID3D11PixelShader* _pixelShader = nullptr;
};
}
#endif

View File

@ -8,7 +8,6 @@
#include "gdevicemanager-dx.hpp"
#include "init-dx.hpp"
#include "rendertarget-dx.hpp"
#include "shader-dx.hpp"
#include "soundeffect-dx.hpp"
#include "swapchain-dx.hpp"
#include "texture-dx.hpp"