Merge branch 'master' of gitlab.com:simulant/GLdc

This commit is contained in:
Hayden Kowalchuk 2019-03-13 07:04:45 -04:00
commit 6f300dff44
3 changed files with 17 additions and 4 deletions

View File

@ -78,7 +78,7 @@ void APIENTRY glFinish() {
void APIENTRY glKosInitConfig(GLdcConfig* config) {
config->autosort_enabled = GL_FALSE;
config->initial_vbuf_capacity = 256;
config->initial_vbuf_capacity = 1024;
config->internal_palette_format = GL_RGBA4;
}
@ -94,7 +94,7 @@ void APIENTRY glKosInitEx(GLdcConfig* config) {
_glInitImmediateMode();
_glInitFramebuffers();
_glSetInternalPaletteFormat(GL_RGBA4);
_glSetInternalPaletteFormat(config->internal_palette_format);
_glInitTextures();

View File

@ -20,15 +20,28 @@ void aligned_vector_init(AlignedVector* vector, unsigned int element_size) {
vector->data = NULL;
/* Reserve some initial capacity */
aligned_vector_reserve(vector, ALIGNED_VECTOR_INITIAL_CAPACITY);
aligned_vector_reserve(vector, ALIGNED_VECTOR_CHUNK_SIZE);
}
static inline unsigned int round_to_chunk_size(unsigned int val) {
const unsigned int n = val;
const unsigned int m = ALIGNED_VECTOR_CHUNK_SIZE;
return ((n + m - 1) / m) * m;
}
void aligned_vector_reserve(AlignedVector* vector, unsigned int element_count) {
if(element_count <= vector->capacity) {
return;
}
unsigned int original_byte_size = vector->size * vector->element_size;
/* We overallocate so that we don't make small allocations during push backs */
element_count = round_to_chunk_size(element_count);
unsigned int new_byte_size = element_count * vector->element_size;
unsigned char* original_data = vector->data;
vector->data = (unsigned char*) memalign(0x20, new_byte_size);

View File

@ -12,7 +12,7 @@ typedef struct {
unsigned int element_size;
} AlignedVector;
#define ALIGNED_VECTOR_INITIAL_CAPACITY 256u
#define ALIGNED_VECTOR_CHUNK_SIZE 256u
void aligned_vector_init(AlignedVector* vector, unsigned int element_size);
void aligned_vector_reserve(AlignedVector* vector, unsigned int element_count);