Пример #1
0
static VertexLoader* RefreshLoader(int vtx_attr_group, CPState* state)
{
	VertexLoader* loader;
	if (state->attr_dirty[vtx_attr_group])
	{
		VertexLoaderUID uid(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
		std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock);
		VertexLoaderMap::iterator iter = s_vertex_loader_map.find(uid);
		if (iter != s_vertex_loader_map.end())
		{
			loader = iter->second.get();
		}
		else
		{
			loader = new VertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
			s_vertex_loader_map[uid] = std::unique_ptr<VertexLoader>(loader);
			INCSTAT(stats.numVertexLoaders);
		}
		state->vertex_loaders[vtx_attr_group] = loader;
		state->attr_dirty[vtx_attr_group] = false;
	} else {
		loader = state->vertex_loaders[vtx_attr_group];
	}
	return loader;
}
Пример #2
0
static VertexLoaderBase* RefreshLoader(int vtx_attr_group, bool preprocess = false)
{
  CPState* state = preprocess ? &g_preprocess_cp_state : &g_main_cp_state;
  state->last_id = vtx_attr_group;

  VertexLoaderBase* loader;
  if (state->attr_dirty[vtx_attr_group])
  {
    // We are not allowed to create a native vertex format on preprocessing as this is on the wrong
    // thread
    bool check_for_native_format = !preprocess;

    VertexLoaderUID uid(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
    std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock);
    VertexLoaderMap::iterator iter = s_vertex_loader_map.find(uid);
    if (iter != s_vertex_loader_map.end())
    {
      loader = iter->second.get();
      check_for_native_format &= !loader->m_native_vertex_format;
    }
    else
    {
      s_vertex_loader_map[uid] =
          VertexLoaderBase::CreateVertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
      loader = s_vertex_loader_map[uid].get();
      INCSTAT(stats.numVertexLoaders);
    }
    if (check_for_native_format)
    {
      // search for a cached native vertex format
      const PortableVertexDeclaration& format = loader->m_native_vtx_decl;
      std::unique_ptr<NativeVertexFormat>& native = s_native_vertex_map[format];
      if (!native)
      {
        native.reset(g_vertex_manager->CreateNativeVertexFormat(format));
      }
      loader->m_native_vertex_format = native.get();
    }
    state->vertex_loaders[vtx_attr_group] = loader;
    state->attr_dirty[vtx_attr_group] = false;
  }
  else
  {
    loader = state->vertex_loaders[vtx_attr_group];
  }

  // Lookup pointers for any vertex arrays.
  if (!preprocess)
    UpdateVertexArrayPointers();

  return loader;
}
Пример #3
0
inline VertexLoaderBase *GetOrAddLoader(const TVtxDesc &VtxDesc, const VAT &VtxAttr)
{
	VertexLoaderUID uid(VtxDesc, VtxAttr);
	VertexLoaderMap::iterator iter = s_vertex_loader_map.find(uid);
	if (iter == s_vertex_loader_map.end())
	{
		s_vertex_loader_map[uid] = VertexLoaderBase::CreateVertexLoader(VtxDesc, VtxAttr);
		VertexLoaderBase* loader = s_vertex_loader_map[uid].get();
		loader->m_native_vertex_format = GetNativeVertexFormat(loader->m_native_vtx_decl);
		VertexLoaderBase * fallback = loader->GetFallback();
		if (fallback)
		{
			fallback->m_native_vertex_format = GetNativeVertexFormat(fallback->m_native_vtx_decl);
		}
		INCSTAT(stats.numVertexLoaders);
		return loader;
	}
	return iter->second.get();
}