base: move const_data.ts to c

This commit is contained in:
luboslenco
2026-03-01 20:35:13 +01:00
parent 5c305bf240
commit ab842663be
5 changed files with 82 additions and 66 deletions
+65
View File
@@ -1,4 +1,12 @@
#include "const_data.h"
#include <stdlib.h>
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);
}
+9 -6
View File
@@ -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[];
+1
View File
@@ -24,6 +24,7 @@
#include "iron_vec2.h"
#include "iron_vec3.h"
#include "iron_vec4.h"
#include "const_data.h"
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
-60
View File
@@ -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);
}
+7
View File
@@ -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();