From fc00598785fc02393864dd3521056d70086ee4b7 Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 21 Nov 2015 10:32:07 +0100 Subject: [PATCH] NativeVertexFormat: Inline Initialize in contructor They were only called at once, so no need to seperate them. This also removes the only dereference of the NativeVertexFormat in VideoCommon, so backends may just return nullptr. --- .../VideoBackends/D3D/NativeVertexFormat.cpp | 12 +++---- Source/Core/VideoBackends/D3D/VertexManager.h | 2 +- .../VideoBackends/OGL/NativeVertexFormat.cpp | 31 ++++++++----------- Source/Core/VideoBackends/OGL/VertexManager.h | 5 ++- Source/Core/VideoCommon/NativeVertexFormat.h | 1 - .../Core/VideoCommon/VertexLoaderManager.cpp | 3 +- Source/Core/VideoCommon/VertexManagerBase.h | 2 +- 7 files changed, 24 insertions(+), 32 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/NativeVertexFormat.cpp b/Source/Core/VideoBackends/D3D/NativeVertexFormat.cpp index 4b2951a689..be29d9fbfe 100644 --- a/Source/Core/VideoBackends/D3D/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/D3D/NativeVertexFormat.cpp @@ -20,16 +20,15 @@ class D3DVertexFormat : public NativeVertexFormat ID3D11InputLayout* m_layout; public: - D3DVertexFormat() : m_num_elems(0), m_layout(nullptr) {} + D3DVertexFormat(const PortableVertexDeclaration& vtx_decl); ~D3DVertexFormat() { SAFE_RELEASE(m_layout); } - void Initialize(const PortableVertexDeclaration &_vtx_decl); void SetupVertexPointers(); }; -NativeVertexFormat* VertexManager::CreateNativeVertexFormat() +NativeVertexFormat* VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) { - return new D3DVertexFormat(); + return new D3DVertexFormat(vtx_decl); } static const DXGI_FORMAT d3d_format_lookup[5*4*2] = @@ -57,9 +56,10 @@ DXGI_FORMAT VarToD3D(VarType t, int size, bool integer) return retval; } -void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) +D3DVertexFormat::D3DVertexFormat(const PortableVertexDeclaration& _vtx_decl) + : m_num_elems(0), m_layout(nullptr) { - vtx_decl = _vtx_decl; + this->vtx_decl = _vtx_decl; memset(m_elems, 0, sizeof(m_elems)); const AttributeFormat* format = &_vtx_decl.position; diff --git a/Source/Core/VideoBackends/D3D/VertexManager.h b/Source/Core/VideoBackends/D3D/VertexManager.h index d963f81266..2cc6b555d7 100644 --- a/Source/Core/VideoBackends/D3D/VertexManager.h +++ b/Source/Core/VideoBackends/D3D/VertexManager.h @@ -15,7 +15,7 @@ public: VertexManager(); ~VertexManager(); - NativeVertexFormat* CreateNativeVertexFormat() override; + NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override; void CreateDeviceObjects() override; void DestroyDeviceObjects() override; diff --git a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp index f7f3ab301a..004692999f 100644 --- a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp @@ -21,19 +21,9 @@ namespace OGL { -NativeVertexFormat* VertexManager::CreateNativeVertexFormat() +NativeVertexFormat* VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) { - return new GLVertexFormat(); -} - -GLVertexFormat::GLVertexFormat() -{ - -} - -GLVertexFormat::~GLVertexFormat() -{ - glDeleteVertexArrays(1, &VAO); + return new GLVertexFormat(vtx_decl); } static inline GLuint VarToGL(VarType t) @@ -56,7 +46,7 @@ static void SetPointer(u32 attrib, u32 stride, const AttributeFormat &format) glVertexAttribPointer(attrib, format.components, VarToGL(format.type), true, stride, (u8*)nullptr + format.offset); } -void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) +GLVertexFormat::GLVertexFormat(const PortableVertexDeclaration& _vtx_decl) { this->vtx_decl = _vtx_decl; u32 vertex_stride = _vtx_decl.stride; @@ -74,22 +64,27 @@ void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vm->m_index_buffers); glBindBuffer(GL_ARRAY_BUFFER, vm->m_vertex_buffers); - SetPointer(SHADER_POSITION_ATTRIB, vertex_stride, vtx_decl.position); + SetPointer(SHADER_POSITION_ATTRIB, vertex_stride, _vtx_decl.position); for (int i = 0; i < 3; i++) - SetPointer(SHADER_NORM0_ATTRIB+i, vertex_stride, vtx_decl.normals[i]); + SetPointer(SHADER_NORM0_ATTRIB+i, vertex_stride, _vtx_decl.normals[i]); for (int i = 0; i < 2; i++) - SetPointer(SHADER_COLOR0_ATTRIB+i, vertex_stride, vtx_decl.colors[i]); + SetPointer(SHADER_COLOR0_ATTRIB+i, vertex_stride, _vtx_decl.colors[i]); for (int i = 0; i < 8; i++) - SetPointer(SHADER_TEXTURE0_ATTRIB+i, vertex_stride, vtx_decl.texcoords[i]); + SetPointer(SHADER_TEXTURE0_ATTRIB+i, vertex_stride, _vtx_decl.texcoords[i]); - SetPointer(SHADER_POSMTX_ATTRIB, vertex_stride, vtx_decl.posmtx); + SetPointer(SHADER_POSMTX_ATTRIB, vertex_stride, _vtx_decl.posmtx); vm->m_last_vao = VAO; } +GLVertexFormat::~GLVertexFormat() +{ + glDeleteVertexArrays(1, &VAO); +} + void GLVertexFormat::SetupVertexPointers() { } diff --git a/Source/Core/VideoBackends/OGL/VertexManager.h b/Source/Core/VideoBackends/OGL/VertexManager.h index 11d7e69e48..d674d5d792 100644 --- a/Source/Core/VideoBackends/OGL/VertexManager.h +++ b/Source/Core/VideoBackends/OGL/VertexManager.h @@ -15,10 +15,9 @@ namespace OGL class GLVertexFormat : public NativeVertexFormat { public: - GLVertexFormat(); + GLVertexFormat(const PortableVertexDeclaration& vtx_decl); ~GLVertexFormat(); - void Initialize(const PortableVertexDeclaration &_vtx_decl) override; void SetupVertexPointers() override; GLuint VAO; @@ -31,7 +30,7 @@ class VertexManager : public VertexManagerBase public: VertexManager(); ~VertexManager(); - NativeVertexFormat* CreateNativeVertexFormat() override; + NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override; void CreateDeviceObjects() override; void DestroyDeviceObjects() override; diff --git a/Source/Core/VideoCommon/NativeVertexFormat.h b/Source/Core/VideoCommon/NativeVertexFormat.h index 0f48341deb..ff461a02fd 100644 --- a/Source/Core/VideoCommon/NativeVertexFormat.h +++ b/Source/Core/VideoCommon/NativeVertexFormat.h @@ -108,7 +108,6 @@ class NativeVertexFormat : NonCopyable public: virtual ~NativeVertexFormat() {} - virtual void Initialize(const PortableVertexDeclaration &vtx_decl) = 0; virtual void SetupVertexPointers() = 0; u32 GetVertexStride() const { return vtx_decl.stride; } diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index 50f50cb78e..25c4c6adb0 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -152,8 +152,7 @@ static VertexLoaderBase* RefreshLoader(int vtx_attr_group, bool preprocess = fal std::unique_ptr& native = s_native_vertex_map[format]; if (!native) { - native.reset(g_vertex_manager->CreateNativeVertexFormat()); - native->Initialize(format); + native.reset(g_vertex_manager->CreateNativeVertexFormat(format)); } loader->m_native_vertex_format = native.get(); } diff --git a/Source/Core/VideoCommon/VertexManagerBase.h b/Source/Core/VideoCommon/VertexManagerBase.h index 316bcd4123..26b02ae122 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.h +++ b/Source/Core/VideoCommon/VertexManagerBase.h @@ -50,7 +50,7 @@ public: static void Flush(); - virtual ::NativeVertexFormat* CreateNativeVertexFormat() = 0; + virtual NativeVertexFormat* CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0; static void DoState(PointerWrap& p);