main
Dominik Madarász 2023-12-04 09:13:46 +01:00
parent 4688b154e5
commit b970e828b1
4 changed files with 60 additions and 78 deletions

View File

@ -159,6 +159,8 @@ rem move /y v4k_*.? engine\split\
rem move /y 3rd_*.? engine\split\ rem move /y 3rd_*.? engine\split\
call make.bat tidy call make.bat tidy
git add engine/split
git add engine/joint
exit /b exit /b
) )

View File

@ -369817,6 +369817,27 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model)
for(int i = 0; i < (int)hdr->num_meshes; i++) { for(int i = 0; i < (int)hdr->num_meshes; i++) {
struct iqmmesh *m = &meshes[i]; struct iqmmesh *m = &meshes[i];
// reuse texture+material if already decoded
bool reused = 0;
for( int j = 0; !reused && j < model->num_textures; ++j ) {
if( !strcmpi(model->texture_names[j], &str[m->material])) {
*out++ = model->materials[j].layer[0].texture;
{
model->num_textures++;
array_push(model->texture_names, STRDUP(&str[m->material]));
array_push(model->materials, model->materials[j]);
array_back(model->materials)->name = STRDUP(&str[m->material]);
}
reused = true;
}
}
if( reused ) continue;
// decode texture+material
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT; // LINEAR, NEAREST int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT; // LINEAR, NEAREST
int invalid = texture_checker().id; int invalid = texture_checker().id;
@ -369828,7 +369849,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model)
array(char) embedded_texture = base64_decode(material_embedded_texture, strlen(material_embedded_texture)); array(char) embedded_texture = base64_decode(material_embedded_texture, strlen(material_embedded_texture));
//printf("%s %d\n", material_embedded_texture, array_count(embedded_texture)); //printf("%s %d\n", material_embedded_texture, array_count(embedded_texture));
//hexdump(embedded_texture, array_count(embedded_texture)); //hexdump(embedded_texture, array_count(embedded_texture));
*out = texture_compressed_from_mem( embedded_texture, array_count(embedded_texture), 0 ).id; *out = texture_compressed_from_mem( embedded_texture, array_count(embedded_texture), flags ).id;
array_free(embedded_texture); array_free(embedded_texture);
} }
@ -369881,6 +369902,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model)
*out = texture_checker().id; // placeholder *out = texture_checker().id; // placeholder
} }
inscribe_tex:;
{ {
model->num_textures++; model->num_textures++;
array_push(model->texture_names, STRDUP(&str[m->material])); array_push(model->texture_names, STRDUP(&str[m->material]));
@ -369948,7 +369970,7 @@ model_t model_from_mem(const void *mem, int len, int flags) {
// if( shaderprog < 0 ) { // if( shaderprog < 0 ) {
const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_texcoord2,att_bitangent","fragColor", "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor",
va("SHADING_PHONG,%s", (flags&MODEL_RIMLIGHT)?"RIM":"")); va("SHADING_PHONG,%s", (flags&MODEL_RIMLIGHT)?"RIM":""));
// } // }
// ASSERT(shaderprog > 0); // ASSERT(shaderprog > 0);
@ -370357,7 +370379,7 @@ lightmap_t lightmap(int hmsize, float cnear, float cfar, vec3 color, int passes,
const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
lm.shader = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, lm.shader = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_texcoord2,att_bitangent","fragColor", "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor",
va("%s", "LIGHTMAP_BAKING")); va("%s", "LIGHTMAP_BAKING"));
return lm; return lm;
@ -370391,6 +370413,10 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
texture_destroy(&m->lightmap); texture_destroy(&m->lightmap);
} }
m->lightmap = texture_create(w, h, 4, 0, TEXTURE_LINEAR|TEXTURE_FLOAT); m->lightmap = texture_create(w, h, 4, 0, TEXTURE_LINEAR|TEXTURE_FLOAT);
glBindTexture(GL_TEXTURE_2D, m->lightmap.id);
unsigned char emissive[] = { 0, 0, 0, 255 };
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, emissive);
glBindTexture(GL_TEXTURE_2D, 0);
} }
for (int b = 0; b < bounces; b++) { for (int b = 0; b < bounces; b++) {
@ -378429,42 +378455,6 @@ vec3 editor_pick(float mouse_x, float mouse_y) {
#endif #endif
} }
#if 0
int editor_ui_bits8(const char *label, uint8_t *enabled) { // @to deprecate
int clicked = 0;
uint8_t copy = *enabled;
// @fixme: better way to retrieve widget width? nk_layout_row_dynamic() seems excessive
nk_layout_row_dynamic(ui_ctx, 1, 1);
struct nk_rect bounds = nk_widget_bounds(ui_ctx);
// actual widget: label + 8 checkboxes
enum { HEIGHT = 18, BITS = 8, SPAN = 118 }; // bits widget below needs at least 118px wide
nk_layout_row_begin(ui_ctx, NK_STATIC, HEIGHT, 1+BITS);
int offset = bounds.w > SPAN ? bounds.w - SPAN : 0;
nk_layout_row_push(ui_ctx, offset);
if( ui_label_(label, NK_TEXT_LEFT) ) clicked = 1<<31;
for( int i = 0; i < BITS; ++i ) {
nk_layout_row_push(ui_ctx, 10);
// bit
int val = (*enabled >> i) & 1;
int chg = nk_checkbox_label(ui_ctx, "", &val);
*enabled = (*enabled & ~(1 << i)) | ((!!val) << i);
// tooltip
struct nk_rect bb = { offset + 10 + i * 14, bounds.y, 14, HEIGHT }; // 10:padding,14:width
if (nk_input_is_mouse_hovering_rect(&ui_ctx->input, bb) && !ui_popups()) {
const char *tips[BITS] = {"Init","Tick","Draw","Quit","","","",""};
if(tips[i][0]) nk_tooltipf(ui_ctx, "%s", tips[i]);
}
}
nk_layout_row_end(ui_ctx);
return clicked | (copy ^ *enabled);
}
#endif
typedef union engine_var { typedef union engine_var {
int i; int i;

View File

@ -86,42 +86,6 @@ vec3 editor_pick(float mouse_x, float mouse_y) {
#endif #endif
} }
#if 0
int editor_ui_bits8(const char *label, uint8_t *enabled) { // @to deprecate
int clicked = 0;
uint8_t copy = *enabled;
// @fixme: better way to retrieve widget width? nk_layout_row_dynamic() seems excessive
nk_layout_row_dynamic(ui_ctx, 1, 1);
struct nk_rect bounds = nk_widget_bounds(ui_ctx);
// actual widget: label + 8 checkboxes
enum { HEIGHT = 18, BITS = 8, SPAN = 118 }; // bits widget below needs at least 118px wide
nk_layout_row_begin(ui_ctx, NK_STATIC, HEIGHT, 1+BITS);
int offset = bounds.w > SPAN ? bounds.w - SPAN : 0;
nk_layout_row_push(ui_ctx, offset);
if( ui_label_(label, NK_TEXT_LEFT) ) clicked = 1<<31;
for( int i = 0; i < BITS; ++i ) {
nk_layout_row_push(ui_ctx, 10);
// bit
int val = (*enabled >> i) & 1;
int chg = nk_checkbox_label(ui_ctx, "", &val);
*enabled = (*enabled & ~(1 << i)) | ((!!val) << i);
// tooltip
struct nk_rect bb = { offset + 10 + i * 14, bounds.y, 14, HEIGHT }; // 10:padding,14:width
if (nk_input_is_mouse_hovering_rect(&ui_ctx->input, bb) && !ui_popups()) {
const char *tips[BITS] = {"Init","Tick","Draw","Quit","","","",""};
if(tips[i][0]) nk_tooltipf(ui_ctx, "%s", tips[i]);
}
}
nk_layout_row_end(ui_ctx);
return clicked | (copy ^ *enabled);
}
#endif
typedef union engine_var { typedef union engine_var {
int i; int i;

View File

@ -3215,6 +3215,27 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model)
for(int i = 0; i < (int)hdr->num_meshes; i++) { for(int i = 0; i < (int)hdr->num_meshes; i++) {
struct iqmmesh *m = &meshes[i]; struct iqmmesh *m = &meshes[i];
// reuse texture+material if already decoded
bool reused = 0;
for( int j = 0; !reused && j < model->num_textures; ++j ) {
if( !strcmpi(model->texture_names[j], &str[m->material])) {
*out++ = model->materials[j].layer[0].texture;
{
model->num_textures++;
array_push(model->texture_names, STRDUP(&str[m->material]));
array_push(model->materials, model->materials[j]);
array_back(model->materials)->name = STRDUP(&str[m->material]);
}
reused = true;
}
}
if( reused ) continue;
// decode texture+material
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT; // LINEAR, NEAREST int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT; // LINEAR, NEAREST
int invalid = texture_checker().id; int invalid = texture_checker().id;
@ -3226,7 +3247,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model)
array(char) embedded_texture = base64_decode(material_embedded_texture, strlen(material_embedded_texture)); array(char) embedded_texture = base64_decode(material_embedded_texture, strlen(material_embedded_texture));
//printf("%s %d\n", material_embedded_texture, array_count(embedded_texture)); //printf("%s %d\n", material_embedded_texture, array_count(embedded_texture));
//hexdump(embedded_texture, array_count(embedded_texture)); //hexdump(embedded_texture, array_count(embedded_texture));
*out = texture_compressed_from_mem( embedded_texture, array_count(embedded_texture), 0 ).id; *out = texture_compressed_from_mem( embedded_texture, array_count(embedded_texture), flags ).id;
array_free(embedded_texture); array_free(embedded_texture);
} }
@ -3279,6 +3300,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model)
*out = texture_checker().id; // placeholder *out = texture_checker().id; // placeholder
} }
inscribe_tex:;
{ {
model->num_textures++; model->num_textures++;
array_push(model->texture_names, STRDUP(&str[m->material])); array_push(model->texture_names, STRDUP(&str[m->material]));
@ -3346,7 +3368,7 @@ model_t model_from_mem(const void *mem, int len, int flags) {
// if( shaderprog < 0 ) { // if( shaderprog < 0 ) {
const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_texcoord2,att_bitangent","fragColor", "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor",
va("SHADING_PHONG,%s", (flags&MODEL_RIMLIGHT)?"RIM":"")); va("SHADING_PHONG,%s", (flags&MODEL_RIMLIGHT)?"RIM":""));
// } // }
// ASSERT(shaderprog > 0); // ASSERT(shaderprog > 0);
@ -3755,7 +3777,7 @@ lightmap_t lightmap(int hmsize, float cnear, float cfar, vec3 color, int passes,
const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM
lm.shader = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, lm.shader = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs,
"att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_texcoord2,att_bitangent","fragColor", "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor",
va("%s", "LIGHTMAP_BAKING")); va("%s", "LIGHTMAP_BAKING"));
return lm; return lm;
@ -3789,6 +3811,10 @@ void lightmap_bake(lightmap_t *lm, int bounces, void (*drawscene)(lightmap_t *lm
texture_destroy(&m->lightmap); texture_destroy(&m->lightmap);
} }
m->lightmap = texture_create(w, h, 4, 0, TEXTURE_LINEAR|TEXTURE_FLOAT); m->lightmap = texture_create(w, h, 4, 0, TEXTURE_LINEAR|TEXTURE_FLOAT);
glBindTexture(GL_TEXTURE_2D, m->lightmap.id);
unsigned char emissive[] = { 0, 0, 0, 255 };
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, emissive);
glBindTexture(GL_TEXTURE_2D, 0);
} }
for (int b = 0; b < bounces; b++) { for (int b = 0; b < bounces; b++) {