reserveBlitStorage/freeBlitStorage

This commit is contained in:
rachytski 2010-12-29 00:44:50 +02:00 committed by Alex Zolotarev
parent 4a6c966291
commit 4223de9099
22 changed files with 111 additions and 32 deletions

View file

@ -81,6 +81,7 @@
15000 * sizeof(yg::gl::Vertex), 30000 * sizeof(unsigned short), 20,
1500 * sizeof(yg::gl::Vertex), 3000 * sizeof(unsigned short), 100,
512, 256, 10,
2048, 2048, 20,
2000000));
// resourceManager->addFont(GetPlatform().ReadPathForFile("dejavusans.ttf").c_str());

View file

@ -20,7 +20,11 @@
DrawerYG::DrawerYG(shared_ptr<yg::ResourceManager> const & rm, string const & skinName, bool isAntiAliased)
{
m_pScreen = shared_ptr<yg::gl::Screen>(new yg::gl::Screen(rm, isAntiAliased));
yg::gl::Screen::Params params;
params.m_resourceManager = rm;
params.m_isAntiAliased = isAntiAliased;
m_pScreen = shared_ptr<yg::gl::Screen>(new yg::gl::Screen(params));
m_pSkin = shared_ptr<yg::Skin>(loadSkin(rm, skinName));
m_pScreen->setSkin(m_pSkin);

View file

@ -40,6 +40,9 @@ namespace qt
5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
2048,
2048,
30,
512, 256,
15,
2000000));

View file

@ -46,6 +46,9 @@ void GLDrawWidget::initializeGL()
3000 * sizeof(yg::gl::Vertex),
5000 * sizeof(unsigned short),
100,
2048,
2048,
30,
512, 256, 15,
2000000));
@ -57,7 +60,11 @@ void GLDrawWidget::initializeGL()
20,
256, 256, 10));*/
m_p = make_shared_ptr(new yg::gl::Screen(m_resourceManager, false));
yg::gl::Screen::Params params;
params.m_resourceManager = m_resourceManager;
params.m_isAntiAliased = false;
m_p = make_shared_ptr(new yg::gl::Screen(params));
m_primaryFrameBuffer = make_shared_ptr(new yg::gl::FrameBuffer(true));

View file

@ -5,9 +5,11 @@
#include "framebuffer.hpp"
#include "base_texture.hpp"
#include "texture.hpp"
#include "resource_manager.hpp"
#include "vertexbuffer.hpp"
#include "indexbuffer.hpp"
#include "utils.hpp"
#include "storage.hpp"
#include "../geometry/screenbase.hpp"
@ -15,9 +17,7 @@ namespace yg
{
namespace gl
{
Blitter::Blitter() :
m_blitVertexBuffer(make_shared_ptr(new VertexBuffer(2048))),
m_blitIndexBuffer(make_shared_ptr(new IndexBuffer(2048)))
Blitter::Blitter(base_t::Params const & params) : base_t(params)
{}
void Blitter::beginFrame()
@ -171,7 +171,9 @@ namespace yg
yg::Color const & color,
bool hasColor)
{
AuxVertex * pointsData = (AuxVertex*)m_blitVertexBuffer->lock();
yg::gl::Storage blitStorage = resourceManager()->reserveBlitStorage();
AuxVertex * pointsData = (AuxVertex*)blitStorage.m_vertices->lock();
for (size_t i = 0; i < size; ++i)
{
@ -182,7 +184,7 @@ namespace yg
pointsData[i].color = color;
}
m_blitVertexBuffer->unlock();
blitStorage.m_vertices->unlock();
setupAuxVertexLayout(hasColor, hasTexture);
@ -190,9 +192,11 @@ namespace yg
texture->makeCurrent();
unsigned short idxData[4] = {0, 1, 2, 3};
memcpy(m_blitIndexBuffer->lock(), idxData, sizeof(idxData));
m_blitIndexBuffer->unlock();
m_blitIndexBuffer->makeCurrent();
memcpy(blitStorage.m_indices->lock(), idxData, sizeof(idxData));
blitStorage.m_indices->unlock();
blitStorage.m_indices->makeCurrent();
resourceManager()->freeBlitStorage(blitStorage);
OGLCHECK(glDisable(GL_BLEND));
OGLCHECK(glDisable(GL_DEPTH_TEST));

View file

@ -24,12 +24,9 @@ namespace yg
void setupAuxVertexLayout(bool hasColor, bool hasTexture);
shared_ptr<VertexBuffer> m_blitVertexBuffer;
shared_ptr<IndexBuffer> m_blitIndexBuffer;
public:
Blitter();
Blitter(base_t::Params const & params);
void beginFrame();
void endFrame();

View file

@ -6,8 +6,9 @@ namespace yg
{
namespace gl
{
Clipper::Clipper()
: m_isClippingEnabled(false)
Clipper::Clipper(base_t::Params const & params)
: base_t(params),
m_isClippingEnabled(false)
{}
void Clipper::beginFrame()

View file

@ -18,7 +18,7 @@ namespace yg
public:
Clipper();
Clipper(base_t::Params const & params);
void beginFrame();
void endFrame();

View file

@ -28,8 +28,8 @@ namespace yg
{
namespace gl
{
GeometryBatcher::GeometryBatcher(shared_ptr<ResourceManager> const & resourceManager, bool isAntiAliased)
: m_resourceManager(resourceManager), m_isAntiAliased(isAntiAliased)
GeometryBatcher::GeometryBatcher(Params const & params)
: base_t(params), m_isAntiAliased(params.m_isAntiAliased)
{
reset(-1);
applyStates();
@ -87,7 +87,7 @@ namespace yg
m_pipelines[i].m_currentVertex = 0;
m_pipelines[i].m_currentIndex = 0;
m_pipelines[i].m_storage = m_skin->pages()[i]->isDynamic() ? m_resourceManager->reserveStorage() : m_resourceManager->reserveSmallStorage();
m_pipelines[i].m_storage = m_skin->pages()[i]->isDynamic() ? resourceManager()->reserveStorage() : resourceManager()->reserveSmallStorage();
m_pipelines[i].m_maxVertices = m_pipelines[i].m_storage.m_vertices->size() / sizeof(Vertex);
m_pipelines[i].m_maxIndices = m_pipelines[i].m_storage.m_indices->size() / sizeof(unsigned short);
@ -171,10 +171,10 @@ namespace yg
renderedData = true;
if (skinPage->isDynamic())
m_resourceManager->freeStorage(pipeline.m_storage);
resourceManager()->freeStorage(pipeline.m_storage);
else
m_resourceManager->freeSmallStorage(pipeline.m_storage);
pipeline.m_storage = skinPage->isDynamic() ? m_resourceManager->reserveStorage() : m_resourceManager->reserveSmallStorage();
resourceManager()->freeSmallStorage(pipeline.m_storage);
pipeline.m_storage = skinPage->isDynamic() ? resourceManager()->reserveStorage() : resourceManager()->reserveSmallStorage();
pipeline.m_maxVertices = pipeline.m_storage.m_vertices->size() / sizeof(Vertex);
pipeline.m_maxIndices = pipeline.m_storage.m_indices->size() / sizeof(unsigned short);

View file

@ -92,7 +92,13 @@ namespace yg
public:
GeometryBatcher(shared_ptr<ResourceManager> const & resourceManager, bool isAntiAliased = false);
struct Params : base_t::Params
{
bool m_isAntiAliased;
Params() : m_isAntiAliased(false) {}
};
GeometryBatcher(Params const & params);
~GeometryBatcher();
void setSkin(shared_ptr<Skin> skin);

View file

@ -10,6 +10,9 @@ namespace yg
{
namespace gl
{
GeometryRenderer::GeometryRenderer(base_t::Params const & params) : base_t(params)
{}
void GeometryRenderer::drawGeometry(shared_ptr<BaseTexture> const & texture,
shared_ptr<VertexBuffer> const & vertices,
shared_ptr<IndexBuffer> const & indices,

View file

@ -15,6 +15,11 @@ namespace yg
class GeometryRenderer : public Blitter
{
public:
typedef Blitter base_t;
GeometryRenderer(base_t::Params const & params);
void drawGeometry(shared_ptr<BaseTexture> const & texture,
shared_ptr<VertexBuffer> const & vertices,
shared_ptr<IndexBuffer> const & indices,

View file

@ -7,6 +7,9 @@ namespace yg
{
namespace gl
{
RenderStateUpdater::RenderStateUpdater(base_t::Params const & params) : base_t(params)
{}
void RenderStateUpdater::setRenderState(shared_ptr<RenderState> const & renderState)
{
m_renderState = renderState;

View file

@ -25,6 +25,8 @@ namespace yg
public:
RenderStateUpdater(base_t::Params const & params);
void setRenderState(shared_ptr<RenderState> const & renderState);
shared_ptr<RenderState> const & renderState() const;

View file

@ -3,6 +3,7 @@
#include "utils.hpp"
#include "framebuffer.hpp"
#include "renderbuffer.hpp"
#include "resource_manager.hpp"
#include "../base/ptr_utils.hpp"
#include "internal/opengl.hpp"
@ -10,9 +11,15 @@ namespace yg
{
namespace gl
{
Renderer::Renderer() : m_isMultiSampled(false), m_isRendering(false)
Renderer::Renderer(Params const & params) : m_isMultiSampled(false), m_isRendering(false)
{
m_multiSampledFrameBuffer = make_shared_ptr(new FrameBuffer());
m_resourceManager = params.m_resourceManager;
}
shared_ptr<ResourceManager> const & Renderer::resourceManager() const
{
return m_resourceManager;
}
void Renderer::beginFrame()

View file

@ -6,6 +6,8 @@
namespace yg
{
class ResourceManager;
namespace gl
{
class FrameBuffer;
@ -13,8 +15,17 @@ namespace yg
class Renderer
{
public:
struct Params
{
shared_ptr<ResourceManager> m_resourceManager;
};
private:
shared_ptr<ResourceManager> m_resourceManager;
shared_ptr<FrameBuffer> m_frameBuffer;
shared_ptr<BaseTexture> m_renderTarget;
shared_ptr<RenderBuffer> m_depthBuffer;
@ -32,13 +43,15 @@ namespace yg
public:
Renderer();
Renderer(Params const & params = Params());
void beginFrame();
void endFrame();
bool isRendering() const;
shared_ptr<ResourceManager> const & resourceManager() const;
void setIsMultiSampled(bool isMultiSampled);
bool isMultiSampled() const;

View file

@ -18,6 +18,7 @@ namespace yg
ResourceManager::ResourceManager(size_t vbSize, size_t ibSize, size_t storagesCount,
size_t smallVBSize, size_t smallIBSize, size_t smallStoragesCount,
size_t blitVBSize, size_t blitIBSize, size_t blitStoragesCount,
size_t texWidth, size_t texHeight, size_t texCount,
size_t maxGlyphCacheSize) : m_glyphCache(maxGlyphCacheSize)
{
@ -27,6 +28,9 @@ namespace yg
for (size_t i = 0; i < smallStoragesCount; ++i)
m_smallStorages.push_back(gl::Storage(smallVBSize, smallIBSize));
for (size_t i = 0; i < blitStoragesCount; ++i)
m_blitStorages.push_back(gl::Storage(blitVBSize, blitIBSize));
for (size_t i = 0; i < texCount; ++i)
{
m_dynamicTextures.push_back(shared_ptr<gl::BaseTexture>(new TDynamicTexture(texWidth, texHeight)));
@ -105,6 +109,16 @@ namespace yg
return freeStorageImpl(storage, doSignal, m_smallStorages);
}
gl::Storage const ResourceManager::reserveBlitStorage(bool doWait)
{
return reserveStorageImpl(doWait, m_blitStorages);
}
void ResourceManager::freeBlitStorage(gl::Storage const & storage, bool doSignal)
{
return freeStorageImpl(storage, doSignal, m_blitStorages);
}
gl::Storage const ResourceManager::reserveStorage(bool doWait)
{
return reserveStorageImpl(doWait, m_storages);

View file

@ -36,6 +36,7 @@ namespace yg
list<gl::Storage> m_storages;
list<gl::Storage> m_smallStorages;
list<gl::Storage> m_blitStorages;
gl::Storage const reserveStorageImpl(bool doWait, list<gl::Storage> & l);
void freeStorageImpl(gl::Storage const & storage, bool doSignal, list<gl::Storage> & l);
@ -46,6 +47,7 @@ namespace yg
ResourceManager(size_t vbSize, size_t ibSize, size_t storagesCount,
size_t smallVBSize, size_t smallIBSize, size_t smallStoragesCount,
size_t blitVBSize, size_t blitIBSize, size_t blitStoragesCount,
size_t texWidth, size_t texHeight, size_t texCount,
size_t maxGlyphCacheSize);
@ -57,6 +59,9 @@ namespace yg
gl::Storage const reserveSmallStorage(bool doWait = false);
void freeSmallStorage(gl::Storage const & storage, bool doSignal = false);
gl::Storage const reserveBlitStorage(bool doWait = false);
void freeBlitStorage(gl::Storage const & storage, bool doSignal = false);
shared_ptr<gl::BaseTexture> const reserveTexture(bool doWait = false);
void freeTexture(shared_ptr<gl::BaseTexture> const & texture, bool doSignal = false);

View file

@ -12,8 +12,10 @@ namespace yg
{
private:
public:
Screen(shared_ptr<yg::ResourceManager> const & rm, bool isAntiAliased)
: TextRenderer(rm, isAntiAliased)
typedef TextRenderer::Params Params;
Screen(Params const & params) : TextRenderer(params)
{}
};
}

View file

@ -12,8 +12,10 @@ namespace yg
{
private:
public:
TextRenderer(shared_ptr<ResourceManager> const & rm, bool isAntiAliased)
: GeometryBatcher(rm, isAntiAliased)
typedef GeometryBatcher::Params Params;
TextRenderer(Params const & params) : GeometryBatcher(params)
{}
};
}

View file

@ -8,6 +8,6 @@
UNIT_TEST(SkinLoaderTest_Main)
{
GL_TEST_START;
shared_ptr<yg::ResourceManager> rm(new yg::ResourceManager(1000, 1000, 2, 1000, 1000, 2, 128, 128, 15, 2000000));
shared_ptr<yg::ResourceManager> rm(new yg::ResourceManager(1000, 1000, 2, 1000, 1000, 2, 1000, 1000, 2, 128, 128, 15, 2000000));
/*yg::Skin * skin = */loadSkin(rm, "basic.skn");
};

View file

@ -9,7 +9,7 @@ UNIT_TEST(SkinTest_Main)
{
GL_TEST_START;
shared_ptr<yg::ResourceManager> rm(new yg::ResourceManager(100, 100, 1, 100, 100, 1, 128, 128, 15, 2000000));
shared_ptr<yg::ResourceManager> rm(new yg::ResourceManager(100, 100, 1, 100, 100, 1, 100, 100, 1, 128, 128, 15, 2000000));
yg::Skin * skin = loadSkin(rm, "test.skn");
double p0 [] = {1, 1};