mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa RenderTarget::FromBackBuffer
This commit is contained in:
parent
6d20f38b48
commit
fedb773b31
@ -54,8 +54,7 @@ namespace xna {
|
||||
if (FAILED(hr))
|
||||
Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION);
|
||||
|
||||
impl->_renderTarget2D = snew<RenderTarget2D>(_this);
|
||||
impl->_renderTarget2D->Initialize();
|
||||
impl->_renderTarget2D = RenderTarget2D::FromBackBuffer(_this);
|
||||
impl->_renderTarget2D->Apply();
|
||||
|
||||
D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport);
|
||||
|
@ -1,36 +1,53 @@
|
||||
#include "xna/xna-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
RenderTarget2D::RenderTarget2D() : Texture2D(nullptr) {
|
||||
impl2 = unew<PlatformImplementation>();
|
||||
}
|
||||
|
||||
RenderTarget2D::RenderTarget2D(sptr<GraphicsDevice> const& device) : Texture2D(device) {
|
||||
impl2 = unew<PlatformImplementation>();
|
||||
}
|
||||
|
||||
void RenderTarget2D::Initialize() {
|
||||
if (!impl || !m_device || !m_device->impl->_device) {
|
||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||
}
|
||||
P_RenderTarget2D RenderTarget2D::FromBackBuffer(P_GraphicsDevice const& device) {
|
||||
auto& swapChain = device->impl->_swapChain;
|
||||
auto rt = snew<RenderTarget2D>(device);
|
||||
auto& implementation = rt->impl;
|
||||
auto& implementation2 = rt->impl2;
|
||||
|
||||
auto& swapChain = m_device->impl->_swapChain;
|
||||
|
||||
if (!swapChain->impl->GetBackBuffer(impl->dxTexture2D))
|
||||
if (!swapChain->impl->GetBackBuffer(implementation->dxTexture2D))
|
||||
{
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
}
|
||||
|
||||
impl->dxTexture2D->GetDesc(&impl->dxDescription);
|
||||
rt->Initialize();
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
void RenderTarget2D::Initialize() {
|
||||
if (!impl || !m_device || !m_device->impl->_device) {
|
||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||
}
|
||||
|
||||
impl->dxDescription.Width = width;
|
||||
impl->dxDescription.Height = height;
|
||||
impl->dxDescription.BindFlags = D3D11_BIND_FLAG::D3D11_BIND_RENDER_TARGET;
|
||||
|
||||
Texture2D::Initialize();
|
||||
|
||||
auto& dxdevice = m_device->impl->_device;
|
||||
|
||||
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D.Get(), NULL, impl2->_renderTargetView.ReleaseAndGetAddressOf());
|
||||
const auto hr = dxdevice->CreateRenderTargetView(
|
||||
impl->dxTexture2D.Get(),
|
||||
NULL,
|
||||
impl2->_renderTargetView.ReleaseAndGetAddressOf());
|
||||
|
||||
if (FAILED(hr)) {
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
}
|
||||
|
||||
impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc);
|
||||
|
||||
//depthStencilFormat = DepthFormat::None;
|
||||
multiSampleCount = impl->dxDescription.SampleDesc.Count;
|
||||
//targetUsage = RenderTargetUsage::DiscardContent;
|
||||
}
|
||||
|
||||
void RenderTarget2D::Apply() {
|
||||
|
@ -4,16 +4,50 @@ namespace xna {
|
||||
static void setDefaultTexture2DDesc(Texture2D::PlatformImplementation& impl);
|
||||
static HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data);
|
||||
|
||||
Texture2D::Texture2D() : Texture(nullptr) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
setDefaultTexture2DDesc(*impl);
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : Texture(device), width(width), height(height) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
setDefaultTexture2DDesc(*impl);
|
||||
impl->dxDescription.Width = static_cast<UINT>(this->width);
|
||||
impl->dxDescription.Height = static_cast<UINT>(this->height);
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : Texture(device) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
setDefaultTexture2DDesc(*impl);
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format)
|
||||
: Texture(device), width(width), height(height), levelCount(mipMap) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
setDefaultTexture2DDesc(*impl);
|
||||
impl->dxDescription.Width = static_cast<UINT>(this->width);
|
||||
impl->dxDescription.Height = static_cast<UINT>(this->height);
|
||||
impl->dxDescription.MipLevels = static_cast<UINT>(this->levelCount);
|
||||
impl->dxDescription.Format = DxHelpers::SurfaceFormatToDx(format);
|
||||
}
|
||||
|
||||
void Texture2D::Initialize()
|
||||
{
|
||||
if (!m_device || !m_device->impl->_device) {
|
||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||
}
|
||||
|
||||
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.ReleaseAndGetAddressOf());
|
||||
HRESULT hr = 0;
|
||||
|
||||
if (FAILED(hr)) {
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
if (!impl->dxTexture2D) {
|
||||
hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.ReleaseAndGetAddressOf());
|
||||
|
||||
if (FAILED(hr)) {
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
impl->dxTexture2D->GetDesc(&impl->dxDescription);
|
||||
}
|
||||
|
||||
comptr<ID3D11Resource> resource = nullptr;
|
||||
@ -22,45 +56,20 @@ namespace xna {
|
||||
if (FAILED(hr)) {
|
||||
Exception::Throw(Exception::INVALID_OPERATION);
|
||||
}
|
||||
|
||||
if (impl->dxDescription.BindFlags & D3D11_BIND_SHADER_RESOURCE) {
|
||||
hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf());
|
||||
|
||||
hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, &impl->dxShaderResource);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
}
|
||||
if (FAILED(hr)) {
|
||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||
}
|
||||
}
|
||||
|
||||
surfaceFormat = DxHelpers::SurfaceFormatToXna(impl->dxDescription.Format);
|
||||
levelCount = static_cast<Int>(impl->dxShaderDescription.Texture2D.MipLevels);
|
||||
width = static_cast<Int>(impl->dxDescription.Width);
|
||||
height = static_cast<Int>(impl->dxDescription.Height);
|
||||
}
|
||||
|
||||
Texture2D::Texture2D() : Texture(nullptr) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
setDefaultTexture2DDesc(*impl);
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height) : Texture(device) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
setDefaultTexture2DDesc(*impl);
|
||||
impl->dxDescription.Width = static_cast<UINT>(width);
|
||||
impl->dxDescription.Height = static_cast<UINT>(height);
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device) : Texture(device) {
|
||||
impl = unew<PlatformImplementation>();
|
||||
setDefaultTexture2DDesc(*impl);
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(sptr<GraphicsDevice> const& device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : Texture(device)
|
||||
{
|
||||
impl = unew<PlatformImplementation>();
|
||||
setDefaultTexture2DDesc(*impl);
|
||||
impl->dxDescription.Width = static_cast<UINT>(width);
|
||||
impl->dxDescription.Height = static_cast<UINT>(height);
|
||||
impl->dxDescription.MipLevels = static_cast<UINT>(mipMap);
|
||||
impl->dxDescription.Format = DxHelpers::SurfaceFormatToDx(format);
|
||||
}
|
||||
}
|
||||
|
||||
void Texture2D::SetData(std::vector<Uint> const& data, size_t startIndex, size_t elementCount)
|
||||
{
|
||||
|
@ -207,6 +207,7 @@ namespace xna {
|
||||
using P_FileStream = sptr<FileStream>;
|
||||
using P_Texture = sptr<Texture>;
|
||||
using P_Texture2D = sptr<Texture2D>;
|
||||
using P_RenderTarget2D = sptr<RenderTarget2D>;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,22 +8,13 @@ namespace xna {
|
||||
class RenderTarget2D : public Texture2D {
|
||||
public:
|
||||
RenderTarget2D();
|
||||
RenderTarget2D(sptr<GraphicsDevice> const& device);
|
||||
RenderTarget2D(sptr<GraphicsDevice> const& device);
|
||||
|
||||
//Gets the data format for the depth stencil data.
|
||||
constexpr DepthFormat DepthStencilFormat() const { return depthStencilFormat; }
|
||||
//Gets the number of sample locations during multisampling.
|
||||
constexpr Int MultiSampleCount() const { return multiSampleCount; }
|
||||
//Gets or sets the render target usage.
|
||||
constexpr RenderTargetUsage TargetUsage() const { return targetUsage; }
|
||||
|
||||
static P_RenderTarget2D FromBackBuffer(P_GraphicsDevice const& device);
|
||||
|
||||
void Initialize();
|
||||
void Apply();
|
||||
private:
|
||||
DepthFormat depthStencilFormat{ DepthFormat::None };
|
||||
Int multiSampleCount{ 0 };
|
||||
RenderTargetUsage targetUsage{ RenderTargetUsage::DiscardContents };
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
uptr<PlatformImplementation> impl2 = nullptr;
|
||||
|
@ -4,4 +4,4 @@
|
||||
|
||||
# Add source to this project's executable.
|
||||
add_subdirectory ("01_blank")
|
||||
#add_subdirectory ("02_PlatfformerStarterKit")
|
||||
add_subdirectory ("02_PlatfformerStarterKit")
|
||||
|
Loading…
x
Reference in New Issue
Block a user