1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 19:53:53 +00:00

Improve MyGUI widget creation performance

This commit is contained in:
scrawl 2015-06-07 18:57:26 +02:00
parent 508c57d6e2
commit ab626ca7b9

View file

@ -209,10 +209,17 @@ class OSGVertexBuffer : public MyGUI::IVertexBuffer
size_t mNeedVertexCount; size_t mNeedVertexCount;
bool mQueuedForDrawing;
void destroy();
void create();
public: public:
OSGVertexBuffer(); OSGVertexBuffer();
virtual ~OSGVertexBuffer(); virtual ~OSGVertexBuffer();
void markAsQueuedForDrawing();
virtual void setVertexCount(size_t count); virtual void setVertexCount(size_t count);
virtual size_t getVertexCount(); virtual size_t getVertexCount();
@ -220,8 +227,6 @@ public:
virtual void unlock(); virtual void unlock();
/*internal:*/ /*internal:*/
void destroy();
void create();
osg::VertexBufferObject *getBuffer() const { return mBuffer.get(); } osg::VertexBufferObject *getBuffer() const { return mBuffer.get(); }
osg::UByteArray *getArray() const { return mVertexArray.get(); } osg::UByteArray *getArray() const { return mVertexArray.get(); }
@ -229,6 +234,7 @@ public:
OSGVertexBuffer::OSGVertexBuffer() OSGVertexBuffer::OSGVertexBuffer()
: mNeedVertexCount(0) : mNeedVertexCount(0)
, mQueuedForDrawing(false)
{ {
} }
@ -237,14 +243,17 @@ OSGVertexBuffer::~OSGVertexBuffer()
destroy(); destroy();
} }
void OSGVertexBuffer::markAsQueuedForDrawing()
{
mQueuedForDrawing = true;
}
void OSGVertexBuffer::setVertexCount(size_t count) void OSGVertexBuffer::setVertexCount(size_t count)
{ {
if(count == mNeedVertexCount) if(count == mNeedVertexCount)
return; return;
mNeedVertexCount = count; mNeedVertexCount = count;
destroy();
create();
} }
size_t OSGVertexBuffer::getVertexCount() size_t OSGVertexBuffer::getVertexCount()
@ -254,15 +263,22 @@ size_t OSGVertexBuffer::getVertexCount()
MyGUI::Vertex *OSGVertexBuffer::lock() MyGUI::Vertex *OSGVertexBuffer::lock()
{ {
if (mQueuedForDrawing || !mVertexArray)
{
// Force recreating the buffer, to make sure we are not modifying a buffer currently // Force recreating the buffer, to make sure we are not modifying a buffer currently
// queued for rendering in the last frame's draw thread. // queued for rendering in the last frame's draw thread.
// a more efficient solution might be double buffering // a more efficient solution might be double buffering
destroy(); destroy();
create(); create();
mQueuedForDrawing = false;
}
else
{
mVertexArray->resize(mNeedVertexCount * sizeof(MyGUI::Vertex));
}
MYGUI_PLATFORM_ASSERT(mBuffer.valid(), "Vertex buffer is not created"); MYGUI_PLATFORM_ASSERT(mBuffer.valid(), "Vertex buffer is not created");
mVertexArray->resize(mNeedVertexCount * sizeof(MyGUI::Vertex));
return (MyGUI::Vertex*)&(*mVertexArray)[0]; return (MyGUI::Vertex*)&(*mVertexArray)[0];
} }
@ -389,6 +405,7 @@ void RenderManager::doRender(MyGUI::IVertexBuffer *buffer, MyGUI::ITexture *text
Drawable::Batch batch; Drawable::Batch batch;
batch.mVertexCount = count; batch.mVertexCount = count;
batch.mVertexBuffer = static_cast<OSGVertexBuffer*>(buffer)->getBuffer(); batch.mVertexBuffer = static_cast<OSGVertexBuffer*>(buffer)->getBuffer();
static_cast<OSGVertexBuffer*>(buffer)->markAsQueuedForDrawing();
batch.mArray = static_cast<OSGVertexBuffer*>(buffer)->getArray(); batch.mArray = static_cast<OSGVertexBuffer*>(buffer)->getArray();
if (texture) if (texture)
{ {