Last active
December 29, 2015 18:39
-
-
Save smokris/7711889 to your computer and use it in GitHub Desktop.
Pooling GL_ELEMENT_ARRAY_BUFFERs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static vector<GLuint> elementArrayBufferPool; | |
static dispatch_semaphore_t elementArrayBufferPoolSemaphore; | |
static void __attribute__((constructor)) elementArrayBufferPoolInit(void) | |
{ | |
elementArrayBufferPoolSemaphore = dispatch_semaphore_create(1); | |
} | |
GLuint getUnusedElementArrayBufferFromPool(void) | |
{ | |
GLuint name = 0; | |
dispatch_semaphore_wait(elementArrayBufferPoolSemaphore, DISPATCH_TIME_FOREVER); | |
{ | |
if (elementArrayBufferPool.size()) | |
{ | |
name = elementArrayBufferPool.back(); | |
elementArrayBufferPool.pop_back(); | |
} | |
else | |
{ | |
CGLContextObj cgl_ctx = (CGLContextObj)getUnusedGLContext(); | |
glGenBuffers(1, &name); | |
throwUnusedGLContextBackInPool(cgl_ctx); | |
} | |
} | |
dispatch_semaphore_signal(elementArrayBufferPoolSemaphore); | |
return name; | |
} | |
void throwElementArrayBufferBackInPool(GLuint name) | |
{ | |
dispatch_semaphore_wait(elementArrayBufferPoolSemaphore, DISPATCH_TIME_FOREVER); | |
elementArrayBufferPool .push_back(name); | |
dispatch_semaphore_signal(elementArrayBufferPoolSemaphore); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment