diff --git a/asset/AssetManagementSystem.h b/asset/AssetManagementSystem.h index f251feb..3ccbdc7 100644 --- a/asset/AssetManagementSystem.h +++ b/asset/AssetManagementSystem.h @@ -59,10 +59,10 @@ void ams_create(AssetManagementSystem* ams, BufferMemory* buf, int32 chunk_size, hashmap_create(&ams->hash_map, count, sizeof(HashEntryInt64), buf); // setup asset_memory - chunk_init(&ams->asset_memory, buf, count, sizeof(Asset), 1); + chunk_init(&ams->asset_memory, buf, count, sizeof(Asset), 64); // setup asset_data_memory - chunk_init(&ams->asset_data_memory, buf, count, chunk_size, 1); + chunk_init(&ams->asset_data_memory, buf, count, chunk_size, 64); ams->first = NULL; ams->last = NULL; @@ -71,7 +71,7 @@ void ams_create(AssetManagementSystem* ams, BufferMemory* buf, int32 chunk_size, } // WARNING: buf size see ams_get_buffer_size -void ams_create(AssetManagementSystem* ams, byte* buf, int chunk_size, int count) +void ams_create(AssetManagementSystem* ams, byte* buf, int32 chunk_size, int32 count) { ASSERT_SIMPLE(chunk_size); @@ -82,7 +82,7 @@ void ams_create(AssetManagementSystem* ams, byte* buf, int chunk_size, int count ams->asset_memory.count = count; ams->asset_memory.chunk_size = sizeof(Asset); ams->asset_memory.last_pos = -1; - ams->asset_memory.alignment = 1; + ams->asset_memory.alignment = 64; ams->asset_memory.memory = buf; ams->asset_memory.free = (uint64 *) (ams->asset_memory.memory + ams->asset_memory.chunk_size * count); @@ -90,7 +90,7 @@ void ams_create(AssetManagementSystem* ams, byte* buf, int chunk_size, int count ams->asset_data_memory.count = count; ams->asset_data_memory.chunk_size = chunk_size; ams->asset_data_memory.last_pos = -1; - ams->asset_data_memory.alignment = 1; + ams->asset_data_memory.alignment = 64; ams->asset_data_memory.memory = (byte *) (ams->asset_memory.free + CEIL_DIV(count, 64)); ams->asset_data_memory.free = (uint64 *) (ams->asset_data_memory.memory + ams->asset_data_memory.chunk_size * count); @@ -112,7 +112,7 @@ int32 ams_calculate_chunks(const AssetManagementSystem* ams, int32 byte_size) } inline -int64 ams_get_buffer_size(int count, int chunk_size) +int64 ams_get_buffer_size(int32 count, int32 chunk_size) { return hashmap_size(count, sizeof(HashEntryInt64)) // hash map + sizeof(Asset) * count + CEIL_DIV(count, 64) * sizeof(uint64) // asset_memory diff --git a/gpuapi/RenderUtils.h b/gpuapi/RenderUtils.h index 4d53526..e08aef6 100644 --- a/gpuapi/RenderUtils.h +++ b/gpuapi/RenderUtils.h @@ -624,7 +624,7 @@ f32 ui_text_create( vertex_rect_create( vertices, index, zindex, offset_x, offset_y2, glyph->metrics.width * scale, glyph->metrics.height * scale, UI_ALIGN_H_LEFT, UI_ALIGN_V_BOTTOM, - color_index->value_int, glyph->coords.x1, glyph->coords.y1, glyph->coords.x2, glyph->coords.y2 + color_index->value_float, glyph->coords.x1, glyph->coords.y1, glyph->coords.x2, glyph->coords.y2 ); offset_x += (glyph->metrics.width + glyph->metrics.advance_x) * scale; @@ -707,13 +707,13 @@ void ui_button_create( vertex_rect_border_create( vertices, index, zindex, - x->value_int, y->value_int, width->value_int, height->value_int, 1, UI_ALIGN_H_LEFT, UI_ALIGN_V_BOTTOM, + x->value_float, y->value_float, width->value_float, height->value_float, 1, UI_ALIGN_H_LEFT, UI_ALIGN_V_BOTTOM, 12, 0.0f, 0.0f ); vertex_rect_create( vertices, index, zindex, - x->value_int + 1, y->value_int + 1, width->value_int - 2, height->value_int - 2, UI_ALIGN_H_LEFT, UI_ALIGN_V_BOTTOM, + x->value_float + 1, y->value_float + 1, width->value_float - 2, height->value_float - 2, UI_ALIGN_H_LEFT, UI_ALIGN_V_BOTTOM, 14, 0.0f, 0.0f ); @@ -721,8 +721,8 @@ void ui_button_create( vertex_text_create( vertices, index, zindex, - x->value_int, y->value_int, width->value_int, height->value_int, align_h->value_int, align_v->value_int, - &theme->font, text->value_str, size->value_int, color_index->value_int + x->value_float, y->value_float, width->value_float, height->value_float, align_h->value_float, align_v->value_float, + &theme->font, text->value_str, size->value_float, color_index->value_float ); element->vertex_count = *index - start; diff --git a/gpuapi/opengl/OpenglUtils.h b/gpuapi/opengl/OpenglUtils.h index 486491d..53977b9 100644 --- a/gpuapi/opengl/OpenglUtils.h +++ b/gpuapi/opengl/OpenglUtils.h @@ -479,6 +479,17 @@ uint32 gpuapi_framebuffer_generate() return fbo; } +inline +uint32 gpuapi_renderbuffer_generate() +{ + uint32 rbo; + + glGenRenderbuffers(1, &rbo); + glBindRenderbuffer(GL_RENDERBUFFER, rbo); + + return rbo; +} + inline void gpuapi_buffer_update_dynamic(uint32 vbo, int32 size, const void* data) { @@ -595,6 +606,14 @@ int get_gpu_free_memory() return available; } +void gpuapi_error() +{ + GLenum err; + while ((err = glGetError()) != GL_NO_ERROR) { + ASSERT_SIMPLE(err == GL_NO_ERROR); + } +} + /* void render_9_patch(GLuint texture, int32 imgWidth, int32 imgHeight, diff --git a/log/Log.h b/log/Log.h index 26b9b7e..6796718 100644 --- a/log/Log.h +++ b/log/Log.h @@ -37,16 +37,16 @@ void log_counter(int32, int64); #if (!DEBUG && !INTERNAL) // Don't perform any logging at log level 0 - #define LOG(str, should_log, save) ((void) 0) - #define LOG_FORMAT(format, data_type, data, should_log, save) ((void) 0) + #define LOG(str, should_log, save) log((str), (should_log), (save), __FILE__, __func__, __LINE__) + #define LOG_FORMAT(format, data_type, data, should_log, save) log((format), (data_type), (data), (should_log), (save), __FILE__, __func__, __LINE__) #define LOG_TO_FILE() ((void) 0) #define LOG_INCREMENT(a) ((void) 0) #define LOG_INCREMENT_BY(a, b) ((void) 0) #define LOG_COUNTER(a, b) ((void) 0) #define RESET_COUNTER(a) ((void) 0) #else - #define LOG(str, should_log, save) ((void) 0) - #define LOG_FORMAT(format, data_type, data, should_log, save) ((void) 0) + #define LOG(str, should_log, save) log((str), (should_log), (save), __FILE__, __func__, __LINE__) + #define LOG_FORMAT(format, data_type, data, should_log, save) log((format), (data_type), (data), (should_log), (save), __FILE__, __func__, __LINE__) #define LOG_TO_FILE() log_to_file() #define LOG_INCREMENT(a) log_increment((a), 1) #define LOG_INCREMENT_BY(a, b) log_increment((a), (b)) diff --git a/memory/ChunkMemory.h b/memory/ChunkMemory.h index 7344d78..bb7b939 100644 --- a/memory/ChunkMemory.h +++ b/memory/ChunkMemory.h @@ -66,6 +66,8 @@ void chunk_alloc(ChunkMemory* buf, uint64 count, uint64 chunk_size, int32 alignm ASSERT_SIMPLE(chunk_size); ASSERT_SIMPLE(count); + chunk_size = ROUND_TO_NEAREST(chunk_size, alignment); + buf->memory = alignment < 2 ? (byte *) platform_alloc(count * chunk_size + sizeof(buf->free) * CEIL_DIV(count, 64)) : (byte *) platform_alloc_aligned(count * chunk_size + sizeof(buf->free) * CEIL_DIV(count, 64), alignment); @@ -101,7 +103,8 @@ void chunk_init(ChunkMemory* buf, BufferMemory* data, uint64 count, uint64 chunk ASSERT_SIMPLE(chunk_size); ASSERT_SIMPLE(count); - // @bug what if an alignment is defined? + chunk_size = ROUND_TO_NEAREST(chunk_size, alignment); + buf->memory = buffer_get_memory(data, count * chunk_size + sizeof(buf->free) * CEIL_DIV(count, 64)); buf->count = count; @@ -125,6 +128,8 @@ void chunk_init(ChunkMemory* buf, byte* data, uint64 count, uint64 chunk_size, i ASSERT_SIMPLE(chunk_size); ASSERT_SIMPLE(count); + chunk_size = ROUND_TO_NEAREST(chunk_size, alignment); + // @bug what if an alignment is defined? buf->memory = data; diff --git a/utils/TestUtils.h b/utils/TestUtils.h index 9fa68bd..64358c5 100644 --- a/utils/TestUtils.h +++ b/utils/TestUtils.h @@ -81,9 +81,12 @@ if constexpr (!(a)) { \ *(volatile int *) 0 = 0; \ } + + #define ASSERT_GPU_API() gpuapi_error() #else #define ASSERT_SIMPLE(a) ((void) 0) #define ASSERT_SIMPLE_CONST(a) ((void) 0) + #define ASSERT_GPU_API() ((void) 0) #endif #define ASSERT_TRUE(a) \