|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tsmartpointer.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// tcg includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tcg/tcg_list.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tgldisplaylistsmanager.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Local namespace - declarations
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct ProxyReference {
|
|
Toshihiro Shimizu |
890ddd |
TGLDisplayListsProxy *m_proxy;
|
|
Toshihiro Shimizu |
890ddd |
int m_refCount;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ProxyReference(TGLDisplayListsProxy *proxy) : m_proxy(proxy), m_refCount() {}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Local namespace - globals
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tcg::list<proxyreference> m_proxies;</proxyreference>
|
|
Toshihiro Shimizu |
890ddd |
std::map<tglcontext, int=""> m_proxyIdsByContext;</tglcontext,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// TGLDisplayListsManager implementation
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TGLDisplayListsManager *TGLDisplayListsManager::instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static TGLDisplayListsManager theInstance;
|
|
Toshihiro Shimizu |
890ddd |
return &theInstance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TGLDisplayListsManager::storeProxy(TGLDisplayListsProxy *proxy)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_proxies.push_back(ProxyReference(proxy));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TGLDisplayListsManager::attachContext(int dlSpaceId, TGlContext context)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_proxyIdsByContext.insert(std::make_pair(context, dlSpaceId));
|
|
Toshihiro Shimizu |
890ddd |
++m_proxies[dlSpaceId].m_refCount;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TGLDisplayListsManager::releaseContext(TGlContext context)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<tglcontext, int="">::iterator it = m_proxyIdsByContext.find(context);</tglcontext,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(it != m_proxyIdsByContext.end());
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_proxyIdsByContext.end())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int dlSpaceId = it->second;
|
|
Toshihiro Shimizu |
890ddd |
if (--m_proxies[dlSpaceId].m_refCount <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
// Notify observers first
|
|
Toshihiro Shimizu |
890ddd |
observers_container::const_iterator ot, oEnd = observers().end();
|
|
Toshihiro Shimizu |
890ddd |
for (ot = observers().begin(); ot != oEnd; ++ot)
|
|
Toshihiro Shimizu |
890ddd |
static_cast<observer *="">(*ot)->onDisplayListDestroyed(dlSpaceId);</observer>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Then, destroy stuff
|
|
Toshihiro Shimizu |
890ddd |
delete m_proxies[dlSpaceId].m_proxy;
|
|
Toshihiro Shimizu |
890ddd |
m_proxies.erase(dlSpaceId);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_proxyIdsByContext.erase(it);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TGLDisplayListsManager::displayListsSpaceId(TGlContext context)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<tglcontext, int="">::iterator it = m_proxyIdsByContext.find(context);</tglcontext,>
|
|
Toshihiro Shimizu |
890ddd |
return (it == m_proxyIdsByContext.end()) ? -1 : it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TGLDisplayListsProxy *TGLDisplayListsManager::dlProxy(int dlSpaceId)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_proxies[dlSpaceId].m_proxy;
|
|
Toshihiro Shimizu |
890ddd |
}
|