summaryrefslogtreecommitdiff
path: root/gen_gl.c
diff options
context:
space:
mode:
Diffstat (limited to 'gen_gl.c')
-rw-r--r--gen_gl.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/gen_gl.c b/gen_gl.c
index 117d9bc..aabd13f 100644
--- a/gen_gl.c
+++ b/gen_gl.c
@@ -6,6 +6,63 @@ exit
#define KIT_IMPLEMENTATION
#include "include/kit.inl.h"
+#define MB *1024 * 1024
+#define GL_FOLDER ".gl_registry"
+#define GL_REPO "https://github.com/KhronosGroup/OpenGL-Registry"
+
int main(int argc, char **argv) {
+ if (path_type(SZ("." PATH_DELIM GL_FOLDER)) == PATH_NONE) {
+ int s = system("git clone --quiet --depth 1 " GL_REPO
+ " " GL_FOLDER);
+ int code = s & 0xff;
+
+ if (code != 0) {
+ printf("`git clone` failed.\n");
+ return code;
+ }
+ }
+
+ if (path_type(SZ("." PATH_DELIM GL_FOLDER)) != PATH_FOLDER) {
+ printf("OpenGL registry folder not found.\n");
+ return 1;
+ }
+
+ FILE *f = fopen("." PATH_DELIM GL_FOLDER PATH_DELIM "xml" PATH_DELIM
+ "gl.xml",
+ "rb");
+
+ if (f == NULL) {
+ printf("Failed to read OpenGL registry.\n");
+ return 1;
+ }
+
+ // FIXME
+ // Optimize memory use
+ i64 arena_size = 100 MB;
+ u8 *arena = kit_alloc_dispatch(NULL, KIT_ALLOCATE, arena_size, 0,
+ NULL);
+ kit_allocator_t alloc = kit_alloc_buffer(arena_size, arena);
+
+ is_handle_t is = is_wrap_file(f, &alloc);
+ struct timespec t0, t1;
+ timespec_get(&t0, TIME_UTC);
+ xml_parse_result_t res = xml_parse(is, &alloc);
+ timespec_get(&t1, TIME_UTC);
+ is_destroy(is);
+ fclose(f);
+
+ if (res.status != KIT_OK) {
+ printf("XML parse failed.\n");
+ kit_alloc_dispatch(NULL, KIT_DEALLOCATE, 0, 0, arena);
+ return 1;
+ }
+
+ i64 diff = 1000 * (t1.tv_sec - t0.tv_sec) +
+ (t1.tv_nsec - t0.tv_nsec + 500000) / 1000000;
+ printf("XML parsed in %lld milliseconds.\n", diff);
+
+ xml_destroy(&res.xml);
+
+ kit_alloc_dispatch(NULL, KIT_DEALLOCATE, 0, 0, arena);
return 0;
}