summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/VertexLoaderManager.cpp
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2014-07-26 02:03:03 +0200
committerPierre Bourdon <delroth@gmail.com>2014-07-26 02:03:03 +0200
commit906b05cb1c1a88c2af3d83c2cd422822abe143fe (patch)
treeec61a2703b69dd266d1d2b6274ae0b4d07c45694 /Source/Core/VideoCommon/VertexLoaderManager.cpp
parent5c4e5e9f8a79e932ab0ea96bdbdf12aceac89de0 (diff)
parent73f9a22e2ef8af906a116ad67f1054cc964ae3f0 (diff)
Merge pull request #672 from delroth/vertex-loader
Vertex loader: reduce dependency on global state
Diffstat (limited to 'Source/Core/VideoCommon/VertexLoaderManager.cpp')
-rw-r--r--Source/Core/VideoCommon/VertexLoaderManager.cpp43
1 files changed, 30 insertions, 13 deletions
diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp
index dd1196a48e..d5e74a0e11 100644
--- a/Source/Core/VideoCommon/VertexLoaderManager.cpp
+++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp
@@ -12,11 +12,13 @@
#include "VideoCommon/Statistics.h"
#include "VideoCommon/VertexLoader.h"
#include "VideoCommon/VertexLoaderManager.h"
+#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoCommon.h"
static int s_attr_dirty; // bitfield
+static NativeVertexFormat* s_current_vtx_fmt;
static VertexLoader *g_VertexLoaders[8];
namespace std
@@ -104,8 +106,7 @@ static VertexLoader* RefreshLoader(int vtx_attr_group)
{
if ((s_attr_dirty >> vtx_attr_group) & 1)
{
- VertexLoaderUID uid;
- uid.InitFromCurrentState(vtx_attr_group);
+ VertexLoaderUID uid(g_VtxDesc, g_VtxAttr[vtx_attr_group]);
VertexLoaderMap::iterator iter = g_VertexLoaderMap.find(uid);
if (iter != g_VertexLoaderMap.end())
{
@@ -123,11 +124,35 @@ static VertexLoader* RefreshLoader(int vtx_attr_group)
return g_VertexLoaders[vtx_attr_group];
}
+static NativeVertexFormat* GetNativeVertexFormat(const PortableVertexDeclaration& format,
+ u32 components)
+{
+ auto& native = s_native_vertex_map[format];
+ if (!native)
+ {
+ auto raw_pointer = g_vertex_manager->CreateNativeVertexFormat();
+ native = std::unique_ptr<NativeVertexFormat>(raw_pointer);
+ native->Initialize(format);
+ native->m_components = components;
+ }
+ return native.get();
+}
+
void RunVertices(int vtx_attr_group, int primitive, int count)
{
if (!count)
return;
- RefreshLoader(vtx_attr_group)->RunVertices(vtx_attr_group, primitive, count);
+ VertexLoader* loader = RefreshLoader(vtx_attr_group);
+
+ // If the native vertex format changed, force a flush.
+ NativeVertexFormat* required_vtx_fmt = GetNativeVertexFormat(
+ loader->GetNativeVertexDeclaration(),
+ loader->GetNativeComponents());
+ if (required_vtx_fmt != s_current_vtx_fmt)
+ VertexManager::Flush();
+ s_current_vtx_fmt = required_vtx_fmt;
+
+ RefreshLoader(vtx_attr_group)->RunVertices(g_VtxAttr[vtx_attr_group], primitive, count);
}
int GetVertexSize(int vtx_attr_group)
@@ -135,17 +160,9 @@ int GetVertexSize(int vtx_attr_group)
return RefreshLoader(vtx_attr_group)->GetVertexSize();
}
-NativeVertexFormat* GetNativeVertexFormat(const PortableVertexDeclaration& format, u32 components)
+NativeVertexFormat* GetCurrentVertexFormat()
{
- auto& native = s_native_vertex_map[format];
- if (!native)
- {
- auto raw_pointer = g_vertex_manager->CreateNativeVertexFormat();
- native = std::unique_ptr<NativeVertexFormat>(raw_pointer);
- native->m_components = components;
- native->Initialize(format);
- }
- return native.get();
+ return s_current_vtx_fmt;
}
} // namespace