diff --git a/graphics/tinygl/init.cpp b/graphics/tinygl/init.cpp index bf98caaeaf6..fb43fe33079 100644 --- a/graphics/tinygl/init.cpp +++ b/graphics/tinygl/init.cpp @@ -192,6 +192,10 @@ void glInit(void *zbuffer1, int textureSize) { c->color_mask = (1 << 24) | (1 << 16) | (1 << 8) | (1 << 0); + c->_currentAllocatorIndex = 0; + c->_drawCallAllocator[0].initialize(5 * 1024 * 1024); + c->_drawCallAllocator[1].initialize(5 * 1024 * 1024); + Graphics::Internal::tglBlitScissorRect(0, 0, c->fb->xsize, c->fb->ysize); } diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h index d2bf627805c..5ca4874d623 100644 --- a/graphics/tinygl/zgl.h +++ b/graphics/tinygl/zgl.h @@ -163,6 +163,43 @@ struct GLSharedState { GLTexture **texture_hash_table; }; +class LinearAllocator { +public: + LinearAllocator() { + _memoryBuffer = nullptr; + _memorySize = 0; + _memoryPosition = 0; + } + + void initialize(size_t newSize) { + assert(_memoryBuffer == nullptr); + void *newBuffer = gl_malloc(newSize); + _memoryBuffer = newBuffer; + _memorySize = newSize; + } + + ~LinearAllocator() { + if (_memoryBuffer != nullptr) { + gl_free(_memoryBuffer); + } + } + + void *allocate(size_t size) { + assert (_memoryPosition + size < _memorySize); + int returnPos = _memoryPosition; + _memoryPosition += size; + return ((char *)_memoryBuffer) + returnPos; + } + + void reset() { + _memoryPosition = 0; + } +private: + void *_memoryBuffer; + int _memorySize; + int _memoryPosition; +}; + struct GLContext; typedef void (*gl_draw_triangle_func)(GLContext *c, GLVertex *p0, GLVertex *p1, GLVertex *p2); @@ -300,6 +337,8 @@ struct GLContext { // Draw call queue Common::List _drawCallsQueue; Common::List _previousFrameDrawCallsQueue; + int _currentAllocatorIndex; + LinearAllocator _drawCallAllocator[2]; }; extern GLContext *gl_ctx;