Merge pull request #4927 from lioncash/unique-ptr

VertexManagerBase: Make CreateNativeVertexFormat return a unique_ptr
This commit is contained in:
Markus Wick 2017-02-18 12:40:00 +01:00 committed by GitHub
commit 6acad27919
15 changed files with 36 additions and 21 deletions

View File

@ -27,10 +27,10 @@ private:
ID3D11InputLayout* m_layout = nullptr; ID3D11InputLayout* m_layout = nullptr;
}; };
NativeVertexFormat* std::unique_ptr<NativeVertexFormat>
VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{ {
return new D3DVertexFormat(vtx_decl); return std::make_unique<D3DVertexFormat>(vtx_decl);
} }
static const DXGI_FORMAT d3d_format_lookup[5 * 4 * 2] = { static const DXGI_FORMAT d3d_format_lookup[5 * 4 * 2] = {

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include "VideoCommon/VertexManagerBase.h" #include "VideoCommon/VertexManagerBase.h"
struct ID3D11Buffer; struct ID3D11Buffer;
@ -16,7 +17,9 @@ public:
VertexManager(); VertexManager();
~VertexManager(); ~VertexManager();
NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override; std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
void CreateDeviceObjects() override; void CreateDeviceObjects() override;
void DestroyDeviceObjects() override; void DestroyDeviceObjects() override;

View File

@ -81,7 +81,7 @@ public:
if (!native) if (!native)
{ {
native.reset(g_vertex_manager->CreateNativeVertexFormat(native_vtx_decl)); native = g_vertex_manager->CreateNativeVertexFormat(native_vtx_decl);
} }
desc.InputLayout = reinterpret_cast<D3DVertexFormat*>(native.get())->GetActiveInputLayout12(); desc.InputLayout = reinterpret_cast<D3DVertexFormat*>(native.get())->GetActiveInputLayout12();

View File

@ -13,10 +13,10 @@
namespace DX12 namespace DX12
{ {
NativeVertexFormat* std::unique_ptr<NativeVertexFormat>
VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{ {
return new D3DVertexFormat(vtx_decl); return std::make_unique<D3DVertexFormat>(vtx_decl);
} }
static const constexpr DXGI_FORMAT d3d_format_lookup[5 * 4 * 2] = { static const constexpr DXGI_FORMAT d3d_format_lookup[5 * 4 * 2] = {

View File

@ -17,7 +17,9 @@ public:
VertexManager(); VertexManager();
~VertexManager(); ~VertexManager();
NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override; std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
void CreateDeviceObjects() override; void CreateDeviceObjects() override;
void DestroyDeviceObjects() override; void DestroyDeviceObjects() override;

View File

@ -19,10 +19,10 @@ public:
void SetupVertexPointers() override {} void SetupVertexPointers() override {}
}; };
NativeVertexFormat* std::unique_ptr<NativeVertexFormat>
VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{ {
return new NullNativeVertexFormat; return std::make_unique<NullNativeVertexFormat>();
} }
VertexManager::VertexManager() : m_local_v_buffer(MAXVBUFFERSIZE), m_local_i_buffer(MAXIBUFFERSIZE) VertexManager::VertexManager() : m_local_v_buffer(MAXVBUFFERSIZE), m_local_i_buffer(MAXIBUFFERSIZE)

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include <vector> #include <vector>
#include "VideoCommon/VertexManagerBase.h" #include "VideoCommon/VertexManagerBase.h"
@ -15,7 +16,9 @@ class VertexManager : public VertexManagerBase
public: public:
VertexManager(); VertexManager();
~VertexManager(); ~VertexManager();
NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
protected: protected:
void ResetBuffer(u32 stride) override; void ResetBuffer(u32 stride) override;

View File

@ -17,10 +17,10 @@
namespace OGL namespace OGL
{ {
NativeVertexFormat* std::unique_ptr<NativeVertexFormat>
VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{ {
return new GLVertexFormat(vtx_decl); return std::make_unique<GLVertexFormat>(vtx_decl);
} }
static inline GLuint VarToGL(VarType t) static inline GLuint VarToGL(VarType t)

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include <vector> #include <vector>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -31,7 +32,10 @@ class VertexManager : public VertexManagerBase
public: public:
VertexManager(); VertexManager();
~VertexManager(); ~VertexManager();
NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
void CreateDeviceObjects() override; void CreateDeviceObjects() override;
void DestroyDeviceObjects() override; void DestroyDeviceObjects() override;

View File

@ -33,10 +33,10 @@ public:
void SetupVertexPointers() override {} void SetupVertexPointers() override {}
}; };
NativeVertexFormat* std::unique_ptr<NativeVertexFormat>
SWVertexLoader::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) SWVertexLoader::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{ {
return new NullNativeVertexFormat(vtx_decl); return std::make_unique<NullNativeVertexFormat>(vtx_decl);
} }
SWVertexLoader::SWVertexLoader() : LocalVBuffer(MAXVBUFFERSIZE), LocalIBuffer(MAXIBUFFERSIZE) SWVertexLoader::SWVertexLoader() : LocalVBuffer(MAXVBUFFERSIZE), LocalIBuffer(MAXIBUFFERSIZE)

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include <vector> #include <vector>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -19,7 +20,8 @@ public:
SWVertexLoader(); SWVertexLoader();
~SWVertexLoader(); ~SWVertexLoader();
NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vdec) override; std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vdec) override;
protected: protected:
void ResetBuffer(u32 stride) override; void ResetBuffer(u32 stride) override;

View File

@ -63,10 +63,10 @@ bool VertexManager::Initialize()
return true; return true;
} }
NativeVertexFormat* std::unique_ptr<NativeVertexFormat>
VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{ {
return new VertexFormat(vtx_decl); return std::make_unique<VertexFormat>(vtx_decl);
} }
void VertexManager::PrepareDrawBuffers(u32 stride) void VertexManager::PrepareDrawBuffers(u32 stride)

View File

@ -24,7 +24,8 @@ public:
bool Initialize(); bool Initialize();
NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override; std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
protected: protected:
void PrepareDrawBuffers(u32 stride); void PrepareDrawBuffers(u32 stride);

View File

@ -161,7 +161,7 @@ static VertexLoaderBase* RefreshLoader(int vtx_attr_group, bool preprocess = fal
std::unique_ptr<NativeVertexFormat>& native = s_native_vertex_map[format]; std::unique_ptr<NativeVertexFormat>& native = s_native_vertex_map[format];
if (!native) if (!native)
{ {
native.reset(g_vertex_manager->CreateNativeVertexFormat(format)); native = g_vertex_manager->CreateNativeVertexFormat(format);
} }
loader->m_native_vertex_format = native.get(); loader->m_native_vertex_format = native.get();
} }

View File

@ -56,7 +56,7 @@ public:
void Flush(); void Flush();
virtual NativeVertexFormat* virtual std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0; CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0;
void DoState(PointerWrap& p); void DoState(PointerWrap& p);