correct sharing of textures and storages among DisplayList's

This commit is contained in:
rachytski 2013-02-17 22:55:53 +03:00 committed by Alex Zolotarev
parent 0c5c340415
commit 22e5890860
4 changed files with 115 additions and 31 deletions

View file

@ -10,26 +10,17 @@ namespace graphics
DisplayList::~DisplayList()
{
for (list<shared_ptr<DiscardStorageCmd> >::const_iterator it = m_discardStorageCmd.begin();
it != m_discardStorageCmd.end();
++it)
m_parent->processCommand(*it);
set<TextureRef>::const_iterator tit;
for (tit = m_textures.begin();
tit != m_textures.end();
++tit)
m_parent->removeTextureRef(*tit);
m_discardStorageCmd.clear();
for (list<shared_ptr<FreeStorageCmd> >::const_iterator it = m_freeStorageCmd.begin();
it != m_freeStorageCmd.end();
++it)
m_parent->processCommand(*it);
m_freeStorageCmd.clear();
for (list<shared_ptr<FreeTextureCmd> >::const_iterator it = m_freeTextureCmd.begin();
it != m_freeTextureCmd.end();
++it)
m_parent->processCommand(*it);
m_freeTextureCmd.clear();
set<StorageRef>::const_iterator sit;
for (sit = m_storages.begin();
sit != m_storages.end();
++sit)
m_parent->removeStorageRef(*sit);
m_commands.clear();
}
@ -55,6 +46,26 @@ namespace graphics
void DisplayList::drawGeometry(shared_ptr<DrawGeometryCmd> const & cmd)
{
cmd->setIsDebugging(m_isDebugging);
shared_ptr<gl::BaseTexture> const & texture = cmd->m_texture;
gl::Storage const & storage = cmd->m_storage;
TextureRef tref(texture.get());
if (texture && (m_textures.find(tref) == m_textures.end()))
{
m_textures.insert(tref);
m_parent->addTextureRef(tref);
}
StorageRef sref(storage.m_vertices.get(), storage.m_indices.get());
if (storage.isValid() && (m_storages.find(sref) == m_storages.end()))
{
m_storages.insert(sref);
m_parent->addStorageRef(sref);
}
m_commands.push_back(cmd);
}
@ -66,20 +77,14 @@ namespace graphics
void DisplayList::freeStorage(shared_ptr<FreeStorageCmd> const & cmd)
{
cmd->setIsDebugging(m_isDebugging);
m_freeStorageCmd.push_back(cmd);
}
void DisplayList::freeTexture(shared_ptr<FreeTextureCmd> const & cmd)
{
cmd->setIsDebugging(m_isDebugging);
m_freeTextureCmd.push_back(cmd);
}
void DisplayList::discardStorage(shared_ptr<DiscardStorageCmd> const & cmd)
{
cmd->setIsDebugging(m_isDebugging);
m_discardStorageCmd.push_back(cmd);
}
void DisplayList::uploadResources(shared_ptr<UploadDataCmd> const & cmd)

View file

@ -2,6 +2,10 @@
#include "defines.hpp"
#include "display_list_renderer.hpp"
#include "opengl/base_texture.hpp"
#include "opengl/buffer_object.hpp"
#include "../std/set.hpp"
namespace graphics
{
@ -21,9 +25,11 @@ namespace graphics
list<shared_ptr<Command> > m_commands;
list<shared_ptr<DiscardStorageCmd> > m_discardStorageCmd;
list<shared_ptr<FreeTextureCmd> > m_freeTextureCmd;
list<shared_ptr<FreeStorageCmd> > m_freeStorageCmd;
typedef DisplayListRenderer::TextureRef TextureRef;
typedef DisplayListRenderer::StorageRef StorageRef;
set<TextureRef> m_textures;
set<StorageRef> m_storages;
DisplayListRenderer * m_parent;
bool m_isDebugging;

View file

@ -9,6 +9,52 @@ namespace graphics
{
}
void DisplayListRenderer::addStorageRef(StorageRef const & storage)
{
m_discardStorageCmds[storage].first++;
m_freeStorageCmds[storage].first++;
}
void DisplayListRenderer::removeStorageRef(StorageRef const & storage)
{
CHECK(m_discardStorageCmds.find(storage) != m_discardStorageCmds.end(), ());
pair<int, shared_ptr<DiscardStorageCmd> > & dval = m_discardStorageCmds[storage];
--dval.first;
if ((dval.first == 0) && dval.second)
{
dval.second->perform();
dval.second.reset();
}
CHECK(m_freeStorageCmds.find(storage) != m_freeStorageCmds.end(), ());
pair<int, shared_ptr<FreeStorageCmd> > & fval = m_freeStorageCmds[storage];
--fval.first;
if ((fval.first == 0) && fval.second)
{
fval.second->perform();
fval.second.reset();
}
}
void DisplayListRenderer::addTextureRef(TextureRef const & texture)
{
pair<int, shared_ptr<FreeTextureCmd> > & val = m_freeTextureCmds[texture];
val.first++;
}
void DisplayListRenderer::removeTextureRef(TextureRef const & texture)
{
CHECK(m_freeTextureCmds.find(texture) != m_freeTextureCmds.end(), ());
pair<int, shared_ptr<FreeTextureCmd> > & val = m_freeTextureCmds[texture];
--val.first;
if ((val.first == 0) && val.second)
{
val.second->perform();
val.second.reset();
}
}
DisplayList * DisplayListRenderer::createDisplayList()
{
return new DisplayList(this);
@ -83,7 +129,9 @@ namespace graphics
command->m_texture = texture;
command->m_texturePool = texturePool;
m_displayList->freeTexture(command);
m_freeTextureCmds[texture.get()].second = command;
// m_displayList->freeTexture(command);
}
else
base_t::freeTexture(texture, texturePool);
@ -99,7 +147,10 @@ namespace graphics
command->m_storage = storage;
command->m_storagePool = storagePool;
m_displayList->freeStorage(command);
StorageRef sref(storage.m_vertices.get(), storage.m_indices.get());
m_freeStorageCmds[sref].second = command;
// m_displayList->freeStorage(command);
}
else
base_t::freeStorage(storage, storagePool);
@ -127,7 +178,10 @@ namespace graphics
cmd->m_storage = storage;
m_displayList->discardStorage(cmd);
StorageRef sref(storage.m_vertices.get(), storage.m_indices.get());
m_discardStorageCmds[sref].second = cmd;
// m_displayList->discardStorage(cmd);
}
else
base_t::discardStorage(storage);

View file

@ -1,5 +1,7 @@
#pragma once
#include "../std/map.hpp"
#include "opengl/storage.hpp"
#include "opengl/base_texture.hpp"
#include "opengl/geometry_renderer.hpp"
@ -19,6 +21,23 @@ namespace graphics
typedef gl::GeometryRenderer base_t;
typedef base_t::Params Params;
typedef base_t::FreeTexture FreeTextureCmd;
typedef base_t::FreeStorage FreeStorageCmd;
typedef base_t::DiscardStorage DiscardStorageCmd;
typedef gl::BaseTexture const * TextureRef;
typedef pair<gl::BufferObject const *, gl::BufferObject const *> StorageRef;
map<TextureRef, pair<int, shared_ptr<FreeTextureCmd> > > m_freeTextureCmds;
map<StorageRef, pair<int, shared_ptr<FreeStorageCmd> > > m_freeStorageCmds;
map<StorageRef, pair<int, shared_ptr<DiscardStorageCmd> > > m_discardStorageCmds;
void addStorageRef(StorageRef const & storage);
void removeStorageRef(StorageRef const & storage);
void addTextureRef(TextureRef const & texture);
void removeTextureRef(TextureRef const & texture);
DisplayListRenderer(Params const & p);
/// create display list