From ab842663be4b1d9b1ac3071cd46158df0d5a7813 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sun, 1 Mar 2026 20:35:13 +0100 Subject: [PATCH] base: move const_data.ts to c --- base/sources/const_data.c | 65 +++++++++++++++++++++++++++++++++++ base/sources/const_data.h | 15 ++++---- base/sources/iron.h | 1 + base/sources/ts/const_data.ts | 60 -------------------------------- base/sources/ts/iron.ts | 7 ++++ 5 files changed, 82 insertions(+), 66 deletions(-) delete mode 100644 base/sources/ts/const_data.ts diff --git a/base/sources/const_data.c b/base/sources/const_data.c index 6fae4a0f..9a33306d 100644 --- a/base/sources/const_data.c +++ b/base/sources/const_data.c @@ -1,4 +1,12 @@ +#include "const_data.h" +#include + +gpu_buffer_t *const_data_screen_aligned_vb; +gpu_buffer_t *const_data_screen_aligned_ib; +gpu_buffer_t *const_data_skydome_vb; +gpu_buffer_t *const_data_skydome_ib; + // Generated in Blender with armory_tools/export_skydome_geometry.py, using // a UV sphere with 24 segments and 12 rings. @@ -730,3 +738,60 @@ const unsigned char iron_font_13_pixels[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +void const_data_create_screen_aligned_data(void) { + // Over-sized triangle + float data[] = {-1.0f, -1.0f, 3.0f, -1.0f, -1.0f, 3.0f}; + int indices[] = {0, 1, 2}; + + gpu_vertex_structure_t structure; + structure.size = 0; + gpu_vertex_structure_add(&structure, "pos", GPU_VERTEX_DATA_F32_2X); + + int vertex_count = sizeof(data) / sizeof(data[0]) / (gpu_vertex_struct_size(&structure) / 4); + const_data_screen_aligned_vb = malloc(sizeof(gpu_buffer_t)); + gpu_vertex_buffer_init(const_data_screen_aligned_vb, vertex_count, &structure); + float *vertices = gpu_vertex_buffer_lock(const_data_screen_aligned_vb); + for (int i = 0; i < (int)(sizeof(data) / sizeof(data[0])); ++i) { + vertices[i] = data[i]; + } + gpu_vertex_buffer_unlock(const_data_screen_aligned_vb); + + const_data_screen_aligned_ib = malloc(sizeof(gpu_buffer_t)); + gpu_index_buffer_init(const_data_screen_aligned_ib, sizeof(indices) / sizeof(indices[0])); + int *id = gpu_index_buffer_lock(const_data_screen_aligned_ib); + for (int i = 0; i < (int)(sizeof(indices) / sizeof(indices[0])); ++i) { + id[i] = indices[i]; + } + gpu_index_buffer_unlock(const_data_screen_aligned_ib); +} + +void const_data_create_skydome_data(void) { + gpu_vertex_structure_t structure; + structure.size = 0; + gpu_vertex_structure_add(&structure, "pos", GPU_VERTEX_DATA_F32_3X); + gpu_vertex_structure_add(&structure, "nor", GPU_VERTEX_DATA_F32_3X); + + int struct_length = gpu_vertex_struct_size(&structure) / 4; + int vertex_count = _const_data_skydome_pos_count / 3; + const_data_skydome_vb = malloc(sizeof(gpu_buffer_t)); + gpu_vertex_buffer_init(const_data_skydome_vb, vertex_count, &structure); + float *vertices = gpu_vertex_buffer_lock(const_data_skydome_vb); + for (int i = 0; i < vertex_count; ++i) { + vertices[i * struct_length] = _const_data_skydome_pos[i * 3]; + vertices[i * struct_length + 1] = _const_data_skydome_pos[i * 3 + 1]; + vertices[i * struct_length + 2] = _const_data_skydome_pos[i * 3 + 2]; + vertices[i * struct_length + 3] = _const_data_skydome_nor[i * 3]; + vertices[i * struct_length + 4] = _const_data_skydome_nor[i * 3 + 1]; + vertices[i * struct_length + 5] = _const_data_skydome_nor[i * 3 + 2]; + } + gpu_vertex_buffer_unlock(const_data_skydome_vb); + + const_data_skydome_ib = malloc(sizeof(gpu_buffer_t)); + gpu_index_buffer_init(const_data_skydome_ib, _const_data_skydome_indices_count); + int *id = gpu_index_buffer_lock(const_data_skydome_ib); + for (int i = 0; i < _const_data_skydome_indices_count; ++i) { + id[i] = _const_data_skydome_indices[i]; + } + gpu_index_buffer_unlock(const_data_skydome_ib); +} diff --git a/base/sources/const_data.h b/base/sources/const_data.h index 93285384..0189c956 100644 --- a/base/sources/const_data.h +++ b/base/sources/const_data.h @@ -1,12 +1,15 @@ #pragma once -extern const int _const_data_skydome_indices[]; -extern const int _const_data_skydome_indices_count; -extern const float _const_data_skydome_pos[]; -extern const int _const_data_skydome_pos_count; -extern const float _const_data_skydome_nor[]; -extern const int _const_data_skydome_nor_count; +#include "iron_gpu.h" + +extern gpu_buffer_t *const_data_screen_aligned_vb; +extern gpu_buffer_t *const_data_screen_aligned_ib; +extern gpu_buffer_t *const_data_skydome_vb; +extern gpu_buffer_t *const_data_skydome_ib; + +void const_data_create_screen_aligned_data(void); +void const_data_create_skydome_data(void); extern const char iron_font_13_x0[]; extern const char iron_font_13_y0[]; diff --git a/base/sources/iron.h b/base/sources/iron.h index 68260cd8..8530bb4f 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -24,6 +24,7 @@ #include "iron_vec2.h" #include "iron_vec3.h" #include "iron_vec4.h" +#include "const_data.h" #include #include #include diff --git a/base/sources/ts/const_data.ts b/base/sources/ts/const_data.ts deleted file mode 100644 index 74399807..00000000 --- a/base/sources/ts/const_data.ts +++ /dev/null @@ -1,60 +0,0 @@ - -let const_data_screen_aligned_vb: gpu_buffer_t = null; -let const_data_screen_aligned_ib: gpu_buffer_t = null; -let const_data_skydome_vb: gpu_buffer_t = null; -let const_data_skydome_ib: gpu_buffer_t = null; - -function const_data_create_screen_aligned_data() { - // Over-sized triangle - let data: f32[] = [ -1.0, -1.0, 3.0, -1.0, -1.0, 3.0 ]; - let indices: i32[] = [ 0, 1, 2 ]; - - let structure: gpu_vertex_structure_t = {}; - gpu_vertex_struct_add(structure, "pos", gpu_vertex_data_t.F32_2X); - const_data_screen_aligned_vb = gpu_create_vertex_buffer(math_floor(data.length / math_floor(gpu_vertex_struct_size(structure) / 4)), structure); - let vertices: buffer_t = gpu_lock_vertex_buffer(const_data_screen_aligned_vb); - for (let i: i32 = 0; i < math_floor((vertices.length) / 4); ++i) { - buffer_set_f32(vertices, i * 4, data[i]); - } - gpu_vertex_buffer_unlock(const_data_screen_aligned_vb); - - const_data_screen_aligned_ib = gpu_create_index_buffer(indices.length); - let id: u32_array_t = gpu_lock_index_buffer(const_data_screen_aligned_ib); - for (let i: i32 = 0; i < id.length; ++i) { - id[i] = indices[i]; - } - gpu_index_buffer_unlock(const_data_screen_aligned_ib); -} - -/// include "const_data.h" -declare let _const_data_skydome_indices: i32_ptr; -declare let _const_data_skydome_indices_count: i32; -declare let _const_data_skydome_pos: f32_ptr; -declare let _const_data_skydome_pos_count: i32; -declare let _const_data_skydome_nor: f32_ptr; -declare let _const_data_skydome_nor_count: i32; - -function const_data_create_skydome_data() { - let structure: gpu_vertex_structure_t = {}; - gpu_vertex_struct_add(structure, "pos", gpu_vertex_data_t.F32_3X); - gpu_vertex_struct_add(structure, "nor", gpu_vertex_data_t.F32_3X); - let struct_length: i32 = math_floor(gpu_vertex_struct_size(structure) / 4); - const_data_skydome_vb = gpu_create_vertex_buffer(math_floor(_const_data_skydome_pos_count / 3), structure); - let vertices: buffer_t = gpu_lock_vertex_buffer(const_data_skydome_vb); - for (let i: i32 = 0; i < math_floor((vertices.length) / 4 / struct_length); ++i) { - buffer_set_f32(vertices, (i * struct_length) * 4, ARRAY_ACCESS(_const_data_skydome_pos, i * 3)); - buffer_set_f32(vertices, (i * struct_length + 1) * 4, ARRAY_ACCESS(_const_data_skydome_pos, i * 3 + 1)); - buffer_set_f32(vertices, (i * struct_length + 2) * 4, ARRAY_ACCESS(_const_data_skydome_pos, i * 3 + 2)); - buffer_set_f32(vertices, (i * struct_length + 3) * 4, ARRAY_ACCESS(_const_data_skydome_nor, i * 3)); - buffer_set_f32(vertices, (i * struct_length + 4) * 4, ARRAY_ACCESS(_const_data_skydome_nor, i * 3 + 1)); - buffer_set_f32(vertices, (i * struct_length + 5) * 4, ARRAY_ACCESS(_const_data_skydome_nor, i * 3 + 2)); - } - gpu_vertex_buffer_unlock(const_data_skydome_vb); - - const_data_skydome_ib = gpu_create_index_buffer(_const_data_skydome_indices_count); - let id: u32_array_t = gpu_lock_index_buffer(const_data_skydome_ib); - for (let i: i32 = 0; i < id.length; ++i) { - id[i] = ARRAY_ACCESS(_const_data_skydome_indices, i); - } - gpu_index_buffer_unlock(const_data_skydome_ib); -} diff --git a/base/sources/ts/iron.ts b/base/sources/ts/iron.ts index ec5cc496..4c23ad56 100644 --- a/base/sources/ts/iron.ts +++ b/base/sources/ts/iron.ts @@ -1028,3 +1028,10 @@ declare function path_join(a: string, b: string): string; declare function lz4_encode(b: buffer_t): buffer_t; declare function lz4_decode(b: buffer_t, olen: u32): buffer_t; + +declare let const_data_screen_aligned_vb: gpu_buffer_t; +declare let const_data_screen_aligned_ib: gpu_buffer_t; +declare let const_data_skydome_vb: gpu_buffer_t; +declare let const_data_skydome_ib: gpu_buffer_t; +declare function const_data_create_screen_aligned_data(); +declare function const_data_create_skydome_data();