diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2012-09-29 21:07:45 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:44:25 +0300 |
commit | 499af27e6a799bcf007f3179b8467aa78402cd35 (patch) | |
tree | 7ddeb574b220512a4c06453cad121d71f69a8e0b /base | |
parent | 7ea55eff17c28cb688f314e0904c160cba4c8952 (diff) |
allocating opengl resources in AllocateOnDemandSingleThreadedPoolTraits directly in Reserve method if we're calling it from primary OpenGL thread.
Diffstat (limited to 'base')
-rw-r--r-- | base/resource_pool.cpp | 8 | ||||
-rw-r--r-- | base/resource_pool.hpp | 15 |
2 files changed, 20 insertions, 3 deletions
diff --git a/base/resource_pool.cpp b/base/resource_pool.cpp index 90220e667b..46ce9d46d5 100644 --- a/base/resource_pool.cpp +++ b/base/resource_pool.cpp @@ -2,8 +2,12 @@ #include "resource_pool.hpp" -BasePoolElemFactory::BasePoolElemFactory(char const * resName, size_t elemSize, size_t batchSize) - : m_resName(resName), m_elemSize(elemSize), m_batchSize(batchSize) +BasePoolElemFactory::BasePoolElemFactory(char const * resName, + size_t elemSize, + size_t batchSize) + : m_resName(resName), + m_elemSize(elemSize), + m_batchSize(batchSize) {} char const * BasePoolElemFactory::ResName() const diff --git a/base/resource_pool.hpp b/base/resource_pool.hpp index fdb354e21f..75f824ca40 100644 --- a/base/resource_pool.hpp +++ b/base/resource_pool.hpp @@ -1,5 +1,6 @@ #pragma once +#include "thread.hpp" #include "threaded_list.hpp" #include "logging.hpp" #include "../std/bind.hpp" @@ -25,11 +26,14 @@ struct BasePoolTraits TElemFactory m_factory; ThreadedList<TElem> m_pool; bool m_IsDebugging; + threads::ThreadID m_MainThreadID; typedef TElem elem_t; BasePoolTraits(TElemFactory const & factory) - : m_factory(factory), m_IsDebugging(false) + : m_factory(factory), + m_IsDebugging(false), + m_MainThreadID(threads::GetCurrentThreadID()) { m_pool.SetName(factory.ResName()); } @@ -220,6 +224,15 @@ struct AllocateOnDemandSingleThreadedPoolTraits : TBase } } + elem_t const Reserve() + { + /// allocate resources if needed if we're on the main thread. + if (threads::GetCurrentThreadID() == base_t::m_MainThreadID) + base_t::m_pool.ProcessList(bind(&self_t::AllocateIfNeeded, this, _1)); + + return base_t::Reserve(); + } + void UpdateState() { base_t::UpdateState(); |