Some changes to VertexLoaderManager:

- Lazily create the native vertex format (which involves GL calls) from
RunVertices rather than RefreshLoader itself, freeing the latter to be
run from the CPU thread (hopefully).

- In order to avoid useless allocations while doing so, store the native
format inside the VertexLoader rather than using a cache entry.

- Wrap the s_vertex_loader_map in a lock, for similar reasons.
This commit is contained in:
comex
2014-08-24 23:53:28 -04:00
parent 431fb4d82a
commit 63c62b277d
3 changed files with 64 additions and 52 deletions

View File

@ -548,6 +548,7 @@ VertexLoader::VertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr)
m_compiledCode = nullptr;
m_numLoadedVertices = 0;
m_VertexSize = 0;
m_native_vertex_format = nullptr;
loop_counter = 0;
VertexLoader_Normal::Init();
VertexLoader_Position::Init();
@ -1035,3 +1036,22 @@ void VertexLoader::AppendToString(std::string *dest) const
}
dest->append(StringFromFormat(" - %i v\n", m_numLoadedVertices));
}
NativeVertexFormat* VertexLoader::GetNativeVertexFormat()
{
if (m_native_vertex_format)
return m_native_vertex_format;
auto& native = s_native_vertex_map[m_native_vtx_decl];
if (!native)
{
auto raw_pointer = g_vertex_manager->CreateNativeVertexFormat();
native = std::unique_ptr<NativeVertexFormat>(raw_pointer);
native->Initialize(m_native_vtx_decl);
native->m_components = m_native_components;
}
m_native_vertex_format = native.get();
return native.get();
}
std::map<PortableVertexDeclaration, std::unique_ptr<NativeVertexFormat>> VertexLoader::s_native_vertex_map;