diff --git a/gs_core/source/gs_asset.h b/gs_core/source/gs_asset.h index 7d08a8f..540b67a 100644 --- a/gs_core/source/gs_asset.h +++ b/gs_core/source/gs_asset.h @@ -97,7 +97,7 @@ typedef struct gs_mesh_t #define gs_mesh_draw(CB, MESH)\ gs_gfxt_mesh_draw((CB), &((MESH)->mesh)) -GS_API_DECL bool gs_mesh_load_resource_from_file(const char* path, gs_asset_t* out, void* import_options /*gs_gfxt_mesh_import_options_t*/); +GS_API_DECL bool gs_mesh_load_resource_from_file(const char* dir, const char* fname, gs_asset_t* out, void* import_options /*gs_gfxt_mesh_import_options_t*/); introspect() typedef struct gs_texture_t @@ -402,7 +402,7 @@ GS_API_DECL gs_asset_handle_t gs_assets_import(gs_asset_manager_t* am, const cha gs_transient_buffer(FINAL_PATH_TMP, GS_ASSET_STR_MAX); gs_transient_buffer(FINAL_PATH, GS_ASSET_STR_MAX); gs_snprintf(FINAL_PATH_TMP, GS_ASSET_STR_MAX, "%s/%s", am->root_path, QUAL_NAME); - gs_util_string_replace((FINAL_PATH_TMP + 1), (FINAL_PATH + 1), GS_ASSET_STR_MAX, '.', '/'); + gs_util_string_replace_delim(FINAL_PATH_TMP, (FINAL_PATH + 1), GS_ASSET_STR_MAX, '.', '/'); FINAL_PATH[0] = '.'; // Get file extension from registered mappings @@ -673,7 +673,9 @@ GS_API_DECL void gs_assets_init(gs_asset_manager_t* am, const char* path) _g_asset_manager = am; // Clear all previous records, if necessary - memcpy(am->root_path, path, GS_ASSET_STR_MAX); + gs_transient_buffer(TMP, GS_ASSET_STR_MAX); + gs_snprintf(TMP, GS_ASSET_STR_MAX, "%s", path); + memcpy(am->root_path, TMP, GS_ASSET_STR_MAX); // Register texture importer gs_assets_register_importer(am, gs_texture_t, (&(gs_asset_importer_desc_t){ @@ -693,7 +695,7 @@ GS_API_DECL void gs_assets_init(gs_asset_manager_t* am, const char* path) // Register pipeline importer gs_assets_register_importer(am, gs_pipeline_t, (&(gs_asset_importer_desc_t){ - .load_resource_from_file = gs_pipeline_load_resource_from_file, + .load_resource_from_file = gs_gfxt_pipeline_load_from_file, .file_extensions = {"sf"}, .file_extensions_size = 1 * sizeof(char*), .file_extension = "pip" @@ -794,11 +796,10 @@ GS_API_DECL void gs_asset_qualified_name(const char* src, char* dst, size_t sz) gs_transient_buffer(TMP2, GS_ASSET_STR_MAX); gs_transient_buffer(TMP3, GS_ASSET_STR_MAX); memcpy(TMP2, (TMP + s->start), s->count); - gs_util_string_replace(TMP2, TMP3, GS_ASSET_STR_MAX, '/', '.'); + gs_util_string_replace_delim(TMP2, TMP3, GS_ASSET_STR_MAX, '/', '.'); memcpy((dst + c), TMP3, s->count); c += s->count; } - // Need the last remainder of the string as well gs_dyn_array_free(splits); } @@ -925,7 +926,7 @@ GS_API_DECL gs_result gs_texture_deserialize(gs_byte_buffer_t* buffer, gs_object size_t sz = tex->desc.width * tex->desc.height * 4; // Allocate texture data - tex->desc.data = gs_malloc(sz); + *tex->desc.data = gs_malloc(sz * GS_GRAPHICS_TEXTURE_DATA_MAX); // Read in texture data gs_byte_buffer_read_bulk(buffer, &tex->desc.data, sz); @@ -958,11 +959,11 @@ GS_API_DECL bool gs_font_load_resource_from_file(const char* path, gs_asset_t* o //=======[ Mesh ]===================================================================== -GS_API_DECL bool gs_mesh_load_resource_from_file(const char* path, gs_asset_t* out, void* import_options /*gs_gfxt_mesh_import_options_t*/) +GS_API_DECL bool gs_mesh_load_resource_from_file(const char* dir, const char* fname, gs_asset_t* out, void* import_options /*gs_gfxt_mesh_import_options_t*/) { // Need to load up data, store in storage (slot array), then return pointer to asset for serialization. gs_mesh_t* mesh = (gs_mesh_t*)out; - mesh->mesh = gs_gfxt_mesh_load_from_file(path, import_options); + mesh->mesh = gs_gfxt_mesh_load_from_file(dir, fname, import_options); return true; } @@ -973,1221 +974,6 @@ GS_API_DECL void gs_material_set_uniform(gs_material_t* mat, const char* name, v gs_gfxt_material_set_uniform(&mat->material, name, data); } -//=======[ Pipeline ]================================================================= - -typedef struct tmp_buffer_t -{ - char txt[1024]; -} tmp_buffer_t; - -typedef struct gs_shader_io_data_t -{ - char type[64]; - char name[64]; -} gs_shader_io_data_t; - -typedef struct gs_pipeline_parse_data_t -{ - gs_dyn_array(gs_shader_io_data_t) io_list[3]; - gs_dyn_array(gs_gfxt_mesh_layout_t) mesh_layout; - char* code[3]; -} gs_ppd_t; - -#define gs_parse_warning(TXT, ...)\ - do {\ - gs_printf("WARNING::");\ - gs_printf(TXT, ##__VA_ARGS__);\ - gs_println("");\ - } while (0) - -#define gs_parse_error(TXT, ASSERT, ...)\ - do {\ - gs_printf("ERROR::");\ - gs_printf(TXT, ##__VA_ARGS__);\ - gs_println("");\ - if (ASSERT) gs_assert(false);\ - } while (0) - -#define gs_parse_block(NAME, ...)\ - do {\ - gs_println("gs_pipeline_load_resource_from_file::parsing::%s", #NAME);\ - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_LBRACE))\ - {\ - gs_println("error::gs_pipeline_load_resource_from_file::error parsing raster from .sf resource");\ - gs_assert(false);\ - }\ -\ - uint32_t bc = 1;\ - while (bc)\ - {\ - gs_token_t token = lex->next_token(lex);\ - switch (token.type)\ - {\ - case GS_TOKEN_LBRACE: {bc++;} break;\ - case GS_TOKEN_RBRACE: {bc--;} break;\ -\ - case GS_TOKEN_IDENTIFIER:\ - {\ - __VA_ARGS__\ - }\ - }\ - }\ - } while (0) - -const char* gs_get_vertex_attribute_string(gs_graphics_vertex_attribute_type type) -{ - switch (type) - { - case GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT: return "float"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT2: return "vec2"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT3: return "vec3"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT4: return "vec4"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_UINT: return "int"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_UINT2: return "vec2"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_UINT3: return "vec3"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_UINT4: return "vec4"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE: return "float"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE2: return "vec2"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE3: return "vec3"; break; - case GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE4: return "vec4"; break; - default: return "UNKNOWN"; break; - } -} - -gs_graphics_vertex_attribute_type gs_get_vertex_attribute_from_token(const gs_token_t* t) -{ - if (gs_token_compare_text(t, "float")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT; - else if (gs_token_compare_text(t, "float2")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT2; - else if (gs_token_compare_text(t, "float3")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT3; - else if (gs_token_compare_text(t, "float4")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT4; - else if (gs_token_compare_text(t, "uint4")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_UINT4; - else if (gs_token_compare_text(t, "uint3")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_UINT3; - else if (gs_token_compare_text(t, "uint2")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_UINT2; - else if (gs_token_compare_text(t, "uint")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_UINT; - else if (gs_token_compare_text(t, "byte4")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE4; - else if (gs_token_compare_text(t, "byte3")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE3; - else if (gs_token_compare_text(t, "byte2")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE2; - else if (gs_token_compare_text(t, "byte")) return GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE; - return 0x00; -} - -gs_graphics_uniform_type gs_uniform_type_from_token(const gs_token_t* t) -{ - if (gs_token_compare_text(t, "float")) return GS_GRAPHICS_UNIFORM_FLOAT; - else if (gs_token_compare_text(t, "int")) return GS_GRAPHICS_UNIFORM_INT; - else if (gs_token_compare_text(t, "vec2")) return GS_GRAPHICS_UNIFORM_VEC2; - else if (gs_token_compare_text(t, "vec3")) return GS_GRAPHICS_UNIFORM_VEC3; - else if (gs_token_compare_text(t, "vec4")) return GS_GRAPHICS_UNIFORM_VEC4; - else if (gs_token_compare_text(t, "mat4")) return GS_GRAPHICS_UNIFORM_MAT4; - else if (gs_token_compare_text(t, "sampler2D")) return GS_GRAPHICS_UNIFORM_SAMPLER2D; - else if (gs_token_compare_text(t, "img2D_rgba32f")) return GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F; - return 0x00; -} - -const char* gs_uniform_string_from_type(gs_graphics_uniform_type type) -{ - switch (type) - { - case GS_GRAPHICS_UNIFORM_FLOAT: return "float"; break; - case GS_GRAPHICS_UNIFORM_INT: return "int"; break; - case GS_GRAPHICS_UNIFORM_VEC2: return "vec2"; break; - case GS_GRAPHICS_UNIFORM_VEC3: return "vec3"; break; - case GS_GRAPHICS_UNIFORM_VEC4: return "vec4"; break; - case GS_GRAPHICS_UNIFORM_MAT4: return "mat4"; break; - case GS_GRAPHICS_UNIFORM_SAMPLER2D: return "sampler2D"; break; - case GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F: return "image2D"; break; - default: return "UNKNOWN"; break; - } - return 0x00; -} - -void gs_parse_uniforms(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd, gs_graphics_shader_stage_type stage) -{ - uint32_t image_binding = 0; - - gs_parse_block( - PIPELINE::UNIFORMS, - { - gs_gfxt_uniform_desc_t uniform = {0}; - uniform.type = gs_uniform_type_from_token(&token); - uniform.stage = stage; - - switch (uniform.type) - { - default: break; - - case GS_GRAPHICS_UNIFORM_SAMPLER2D: - case GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F: - { - uniform.binding = image_binding++; - } break; - } - - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_assert(false); - } - token = lex->current_token; - - memcpy(uniform.name, token.text, token.len); - - // Add uniform to ublock descriptor - gs_dyn_array_push(desc->ublock_desc.layout, uniform); - }); -} - -void gs_parse_in(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd, gs_graphics_shader_stage_type type) -{ - gs_parse_block( - PIPELINE::IN, - { - }); -} - -void gs_parse_io(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd, gs_graphics_shader_stage_type type) -{ - gs_parse_block( - PIPELINE::IO, - { - gs_shader_io_data_t io = {0}; - memcpy(io.type, token.text, token.len); - - switch (type) - { - case GS_GRAPHICS_SHADER_STAGE_VERTEX: - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::IO::expected identifier name after type."); - } - token = lex->current_token; - memcpy(io.name, token.text, token.len); - gs_dyn_array_push(ppd->io_list[0], io); - } break; - - case GS_GRAPHICS_SHADER_STAGE_FRAGMENT: - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::IO::expected identifier name after type."); - } - token = lex->current_token; - memcpy(io.name, token.text, token.len); - gs_dyn_array_push(ppd->io_list[1], io); - } break; - - case GS_GRAPHICS_SHADER_STAGE_COMPUTE: - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_NUMBER)) - { - gs_parse_error(false, "PIPELINE::IO::expected number after type."); - } - token = lex->current_token; - memcpy(io.name, token.text, token.len); - gs_dyn_array_push(ppd->io_list[2], io); - } break; - } - }); -} - -void gs_parse_code(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd, gs_graphics_shader_stage_type stage) -{ - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_LBRACE)) - { - gs_assert(false); - } - - uint32_t bc = 1; - gs_token_t cur = lex->next_token(lex); - gs_token_t token = lex->current_token; - while (bc) - { - switch (token.type) - { - case GS_TOKEN_LBRACE: {bc++;} break; - case GS_TOKEN_RBRACE: {bc--;} break; - } - token = lex->next_token(lex); - } - - const size_t sz = (size_t)(token.text - cur.text - 1); - char* code = gs_malloc(sz + 1); - memset(code, 0, sz); - memcpy(code, cur.text, sz - 1); - - switch (stage) - { - case GS_GRAPHICS_SHADER_STAGE_VERTEX: ppd->code[0] = code; break; - case GS_GRAPHICS_SHADER_STAGE_FRAGMENT: ppd->code[1] = code; break; - case GS_GRAPHICS_SHADER_STAGE_COMPUTE: ppd->code[2] = code; break; - } -} - -gs_gfxt_mesh_attribute_type gs_mesh_attribute_type_from_token(const gs_token_t* token) -{ - if (gs_token_compare_text(token, "POSITION")) return GS_GFXT_MESH_ATTRIBUTE_TYPE_POSITION; - else if (gs_token_compare_text(token, "NORMAL")) return GS_GFXT_MESH_ATTRIBUTE_TYPE_NORMAL; - else if (gs_token_compare_text(token, "TEXCOORD")) return GS_GFXT_MESH_ATTRIBUTE_TYPE_TEXCOORD; - else if (gs_token_compare_text(token, "COLOR")) return GS_GFXT_MESH_ATTRIBUTE_TYPE_COLOR; - - // Default - return 0x00; - // else if (gs_token_compare_text(token, "TANGENT")) return GS_GFXT_MESH_ATTRIBUTE_TYPE_TANGENT; - // else if (gs_token_compare_text(token, "JOINT")) return GS_GFXT_MESH_ATTRIBUTE_TYPE_JOINT; - // else if (gs_token_compare_text(token, "WEIGHT")) return GS_GFXT_MESH_ATTRIBUTE_TYPE_WEIGHT; -} - -void gs_parse_vertex_buffer_attributes(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd) -{ - gs_parse_block( - PIPELINE::VERTEX_BUFFER_ATTRIBUTES, - { - }); -} - -void gs_parse_vertex_mesh_attributes(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd) -{ - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_LBRACE)) - { - gs_assert(false); - } - - uint32_t bc = 1; - while (bc) - { - gs_token_t token = lex->next_token(lex); - switch (token.type) - { - case GS_TOKEN_LBRACE: {bc++;} break; - case GS_TOKEN_RBRACE: {bc--;} break; - - case GS_TOKEN_IDENTIFIER: - { - // Get mesh attribute type from - gs_gfxt_mesh_attribute_type mesh_type = gs_mesh_attribute_type_from_token(&token); - - // Build vertex attribute desc - gs_graphics_vertex_attribute_desc_t attr = {0}; - // attr.format = gs_get_vertex_attribute_from_token(&token); - - // Get attribute name - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_assert(false); - } - - token = lex->current_token; - memcpy(attr.name, token.text, token.len); - - switch (mesh_type) - { - default: - { - } break; - - case GS_GFXT_MESH_ATTRIBUTE_TYPE_POSITION: - { - attr.format = GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT3; - } break; - - case GS_GFXT_MESH_ATTRIBUTE_TYPE_NORMAL: - { - attr.format = GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT3; - } break; - - case GS_GFXT_MESH_ATTRIBUTE_TYPE_TEXCOORD: - { - attr.format = GS_GRAPHICS_VERTEX_ATTRIBUTE_FLOAT2; - } break; - - case GS_GFXT_MESH_ATTRIBUTE_TYPE_COLOR: - { - attr.format = GS_GRAPHICS_VERTEX_ATTRIBUTE_BYTE4; - } break; - - /* - GS_GFXT_MESH_ATTRIBUTE_TYPE_TANGENT, - GS_GFXT_MESH_ATTRIBUTE_TYPE_JOINT, - GS_GFXT_MESH_ATTRIBUTE_TYPE_WEIGHT, - */ - } - - // Push back mesh buffer - gs_dyn_array_push(ppd->mesh_layout, (gs_gfxt_mesh_layout_t){.type = mesh_type}); - - // Push back into layout - gs_dyn_array_push(desc->pip_desc.layout.attrs, attr); - - - // TODO(): Need to do idx as well for later... - } - } - } -} - -void gs_parse_vertex_attributes(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd) -{ - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_LBRACE)) - { - gs_assert(false); - } - - uint32_t bc = 1; - while (bc) - { - gs_token_t token = lex->next_token(lex); - switch (token.type) - { - case GS_TOKEN_LBRACE: {bc++;} break; - case GS_TOKEN_RBRACE: {bc--;} break; - - case GS_TOKEN_IDENTIFIER: { - - // Parse mesh attributes - if (gs_token_compare_text(&token, "mesh")) - { - gs_parse_vertex_mesh_attributes(lex, desc, ppd); - } - - // Parse buffer attributes - else if (gs_token_compare_text(&token, "buffer")) - { - gs_parse_vertex_buffer_attributes(lex, desc, ppd); - } - - } break; - } - } -} - -void gs_parse_shader_stage(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd, gs_graphics_shader_stage_type stage) -{ - gs_parse_block( - PIPELINE::SHADER_STAGE, - { - if (stage == GS_GRAPHICS_SHADER_STAGE_VERTEX && - gs_token_compare_text(&token, "attributes")) - { - gs_println("parsing attributes..."); - gs_parse_vertex_attributes(lex, desc, ppd); - } - - else if (gs_token_compare_text(&token, "uniforms")) - { - gs_parse_uniforms(lex, desc, ppd, stage); - } - - else if (gs_token_compare_text(&token, "out")) - { - gs_parse_io(lex, desc, ppd, stage); - } - - else if (gs_token_compare_text(&token, "in")) - { - gs_parse_io(lex, desc, ppd, stage); - } - - else if (gs_token_compare_text(&token, "code")) - { - gs_parse_code(lex, desc, ppd, stage); - } - }); -} - -void gs_parse_compute_shader_stage(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd) -{ - gs_parse_block( - PIPELINE::COMPUTE_SHADER_STAGE, - { - if (gs_token_compare_text(&token, "uniforms")) - { - gs_parse_uniforms(lex, desc, ppd, GS_GRAPHICS_SHADER_STAGE_COMPUTE); - } - - else if (gs_token_compare_text(&token, "in")) - { - gs_parse_in(lex, desc, ppd, GS_GRAPHICS_SHADER_STAGE_COMPUTE); - } - - else if (gs_token_compare_text(&token, "code")) - { - gs_parse_code(lex, desc, ppd, GS_GRAPHICS_SHADER_STAGE_COMPUTE); - } - }); -} - -void gs_parse_shader(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd) -{ - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_LBRACE)) - { - gs_println("error::gs_pipeline_load_resource_from_file ::error parsing shader from .sf resource"); - gs_assert(false); - } - - // Braces - uint32_t bc = 1; - while (bc) - { - gs_token_t token = lex->next_token(lex); - switch (token.type) - { - case GS_TOKEN_LBRACE: {bc++;} break; - case GS_TOKEN_RBRACE: {bc--;} break; - - case GS_TOKEN_IDENTIFIER: - { - // Vertex shader - if (gs_token_compare_text(&token, "vertex")) - { - gs_println("parsing vertex shader"); - gs_parse_shader_stage(lex, desc, ppd, GS_GRAPHICS_SHADER_STAGE_VERTEX); - } - - // Fragment shader - else if (gs_token_compare_text(&token, "fragment")) - { - gs_println("parsing fragment shader"); - gs_parse_shader_stage(lex, desc, ppd, GS_GRAPHICS_SHADER_STAGE_FRAGMENT); - } - - // Compute shader - else if (gs_token_compare_text(&token, "compute")) - { - gs_println("parsing compute shader"); - gs_parse_shader_stage(lex, desc, ppd, GS_GRAPHICS_SHADER_STAGE_COMPUTE); - } - - } break; - } - } -} - -void gs_parse_depth(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t* ppd) -{ - gs_parse_block( - PIPELINE::DEPTH, - { - // Depth function - if (gs_token_compare_text(&token, "func")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::DEPTH::func type not found after function decl."); - } - - token = lex->current_token; - - if (gs_token_compare_text(&token, "LESS")) pdesc->pip_desc.depth.func = GS_GRAPHICS_DEPTH_FUNC_LESS; - else if (gs_token_compare_text(&token, "EQUAL")) pdesc->pip_desc.depth.func = GS_GRAPHICS_DEPTH_FUNC_EQUAL; - else if (gs_token_compare_text(&token, "LEQUAL")) pdesc->pip_desc.depth.func = GS_GRAPHICS_DEPTH_FUNC_LEQUAL; - else if (gs_token_compare_text(&token, "GREATER")) pdesc->pip_desc.depth.func = GS_GRAPHICS_DEPTH_FUNC_GREATER; - else if (gs_token_compare_text(&token, "NOTEQUAL")) pdesc->pip_desc.depth.func = GS_GRAPHICS_DEPTH_FUNC_NOTEQUAL; - else if (gs_token_compare_text(&token, "GEQUAL")) pdesc->pip_desc.depth.func = GS_GRAPHICS_DEPTH_FUNC_GEQUAL; - else if (gs_token_compare_text(&token, "ALWAYS")) pdesc->pip_desc.depth.func = GS_GRAPHICS_DEPTH_FUNC_ALWAYS; - else if (gs_token_compare_text(&token, "NEVER")) pdesc->pip_desc.depth.func = GS_GRAPHICS_DEPTH_FUNC_NEVER; - else - { - gs_parse_warning("PIPELINE::DEPTH::func type %.*s not valid.", token.len, token.text); - } - } - }); -} - -void gs_parse_blend(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t* ppd) -{ - gs_parse_block( - PIPELINE::BLEND, - { - // Blend function - if (gs_token_compare_text(&token, "func")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::BLEND::func type not found after function decl."); - } - - token = lex->current_token; - - if (gs_token_compare_text(&token, "ADD")) pdesc->pip_desc.blend.func = GS_GRAPHICS_BLEND_EQUATION_ADD; - else if (gs_token_compare_text(&token, "SUBTRACT")) pdesc->pip_desc.blend.func = GS_GRAPHICS_BLEND_EQUATION_SUBTRACT; - else if (gs_token_compare_text(&token, "REVERSE_SUBTRACT")) pdesc->pip_desc.blend.func = GS_GRAPHICS_BLEND_EQUATION_REVERSE_SUBTRACT; - else if (gs_token_compare_text(&token, "MIN")) pdesc->pip_desc.blend.func = GS_GRAPHICS_BLEND_EQUATION_MIN; - else if (gs_token_compare_text(&token, "MAX")) pdesc->pip_desc.blend.func = GS_GRAPHICS_BLEND_EQUATION_MAX; - else - { - gs_parse_warning("PIPELINE::BLEND::func type %.*s not valid.", token.len, token.text); - } - } - - // Source blend - else if (gs_token_compare_text(&token, "src")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::BLEND::src type not found after decl."); - } - - token = lex->current_token; - - if (gs_token_compare_text(&token, "ZERO")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_ZERO; - else if (gs_token_compare_text(&token, "ONE")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_ONE; - else if (gs_token_compare_text(&token, "SRC_COLOR")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_SRC_COLOR; - else if (gs_token_compare_text(&token, "ONE_MINUS_SRC_COLOR")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_SRC_COLOR; - else if (gs_token_compare_text(&token, "DST_COLOR")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_DST_COLOR; - else if (gs_token_compare_text(&token, "ONE_MINUS_DST_COLOR")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_DST_COLOR; - else if (gs_token_compare_text(&token, "SRC_ALPHA")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_SRC_ALPHA; - else if (gs_token_compare_text(&token, "ONE_MINUS_SRC_ALPHA")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_SRC_ALPHA; - else if (gs_token_compare_text(&token, "DST_ALPHA")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_DST_ALPHA; - else if (gs_token_compare_text(&token, "ONE_MINUS_DST_ALPHA")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_DST_ALPHA; - else if (gs_token_compare_text(&token, "CONSTANT_COLOR")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_CONSTANT_COLOR; - else if (gs_token_compare_text(&token, "ONE_MINUS_CONSTANT_COLOR")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_CONSTANT_ALPHA; - else if (gs_token_compare_text(&token, "CONSTANT_ALPHA")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_CONSTANT_ALPHA; - else if (gs_token_compare_text(&token, "ONE_MINUS_CONSTANT_ALPHA")) pdesc->pip_desc.blend.src = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_CONSTANT_ALPHA; - else - { - gs_parse_warning("PIPELINE::BLEND::src type %.*s not valid.", token.len, token.text); - } - } - - // Dest blend - else if (gs_token_compare_text(&token, "dst")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::BLEND::dst type not found after decl."); - } - - token = lex->current_token; - - if (gs_token_compare_text(&token, "ZERO")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_ZERO; - else if (gs_token_compare_text(&token, "ONE")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_ONE; - else if (gs_token_compare_text(&token, "SRC_COLOR")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_SRC_COLOR; - else if (gs_token_compare_text(&token, "ONE_MINUS_SRC_COLOR")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_SRC_COLOR; - else if (gs_token_compare_text(&token, "DST_COLOR")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_DST_COLOR; - else if (gs_token_compare_text(&token, "ONE_MINUS_DST_COLOR")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_DST_COLOR; - else if (gs_token_compare_text(&token, "SRC_ALPHA")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_SRC_ALPHA; - else if (gs_token_compare_text(&token, "ONE_MINUS_SRC_ALPHA")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_SRC_ALPHA; - else if (gs_token_compare_text(&token, "DST_ALPHA")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_DST_ALPHA; - else if (gs_token_compare_text(&token, "ONE_MINUS_DST_ALPHA")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_DST_ALPHA; - else if (gs_token_compare_text(&token, "CONSTANT_COLOR")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_CONSTANT_COLOR; - else if (gs_token_compare_text(&token, "ONE_MINUS_CONSTANT_COLOR")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_CONSTANT_ALPHA; - else if (gs_token_compare_text(&token, "CONSTANT_ALPHA")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_CONSTANT_ALPHA; - else if (gs_token_compare_text(&token, "ONE_MINUS_CONSTANT_ALPHA")) pdesc->pip_desc.blend.dst = GS_GRAPHICS_BLEND_MODE_ONE_MINUS_CONSTANT_ALPHA; - else - { - gs_parse_warning("PIPELINE::BLEND::dst type %.*s not valid.", token.len, token.text); - } - } - - }); -} - -void gs_parse_stencil(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t* ppd) -{ - gs_parse_block( - PIPELINE::STENCIL, - { - // Function - if (gs_token_compare_text(&token, "func")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::STENCIL::func type not found after decl."); - } - - else - { - token = lex->current_token; - - if (gs_token_compare_text(&token, "LESS")) pdesc->pip_desc.stencil.func = GS_GRAPHICS_STENCIL_FUNC_LESS; - else if (gs_token_compare_text(&token, "EQUAL")) pdesc->pip_desc.stencil.func = GS_GRAPHICS_STENCIL_FUNC_EQUAL; - else if (gs_token_compare_text(&token, "LEQUAL")) pdesc->pip_desc.stencil.func = GS_GRAPHICS_STENCIL_FUNC_LEQUAL; - else if (gs_token_compare_text(&token, "GREATER")) pdesc->pip_desc.stencil.func = GS_GRAPHICS_STENCIL_FUNC_GREATER; - else if (gs_token_compare_text(&token, "NOTEQUAL")) pdesc->pip_desc.stencil.func = GS_GRAPHICS_STENCIL_FUNC_NOTEQUAL; - else if (gs_token_compare_text(&token, "GEQUAL")) pdesc->pip_desc.stencil.func = GS_GRAPHICS_STENCIL_FUNC_GEQUAL; - else if (gs_token_compare_text(&token, "ALWAYS")) pdesc->pip_desc.stencil.func = GS_GRAPHICS_STENCIL_FUNC_ALWAYS; - else if (gs_token_compare_text(&token, "NEVER")) pdesc->pip_desc.stencil.func = GS_GRAPHICS_STENCIL_FUNC_NEVER; - else - { - gs_parse_warning("PIPELINE::STENCIL::func type %.*s not valid.", token.len, token.text); - } - } - - } - - // Reference value - else if (gs_token_compare_text(&token, "ref")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_NUMBER)) - { - gs_parse_error(false, "PIPELINE::STENCIL::reference value not found after decl."); - } - - else - { - token = lex->current_token; - gs_snprintfc(TMP, 16, "%.*s", token.len, token.text); - pdesc->pip_desc.stencil.ref = atoi(TMP); - } - } - - // Component mask - else if (gs_token_compare_text(&token, "comp_mask")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_NUMBER)) - { - gs_parse_error(false, "PIPELINE::STENCIL::component mask value not found after decl."); - } - - else - { - token = lex->current_token; - gs_snprintfc(TMP, 16, "%.*s", token.len, token.text); - pdesc->pip_desc.stencil.comp_mask = atoi(TMP); - } - } - - // Write mask - else if (gs_token_compare_text(&token, "write_mask")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_NUMBER)) - { - gs_parse_error(false, "PIPELINE::STENCIL::write mask value not found after decl."); - } - - else - { - token = lex->current_token; - gs_snprintfc(TMP, 16, "%.*s", token.len, token.text); - pdesc->pip_desc.stencil.write_mask = atoi(TMP); - } - } - - // Stencil test failure - else if (gs_token_compare_text(&token, "sfail")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::STENCIL::sfail value not found after decl."); - } - - else - { - token = lex->current_token; - - if (gs_token_compare_text(&token, "KEEP")) pdesc->pip_desc.stencil.sfail = GS_GRAPHICS_STENCIL_OP_KEEP; - else if (gs_token_compare_text(&token, "ZERO")) pdesc->pip_desc.stencil.sfail = GS_GRAPHICS_STENCIL_OP_ZERO; - else if (gs_token_compare_text(&token, "REPLACE")) pdesc->pip_desc.stencil.sfail = GS_GRAPHICS_STENCIL_OP_REPLACE; - else if (gs_token_compare_text(&token, "INCR")) pdesc->pip_desc.stencil.sfail = GS_GRAPHICS_STENCIL_OP_INCR; - else if (gs_token_compare_text(&token, "INCR_WRAP")) pdesc->pip_desc.stencil.sfail = GS_GRAPHICS_STENCIL_OP_INCR_WRAP; - else if (gs_token_compare_text(&token, "DECR")) pdesc->pip_desc.stencil.sfail = GS_GRAPHICS_STENCIL_OP_DECR; - else if (gs_token_compare_text(&token, "DECR_WRAP")) pdesc->pip_desc.stencil.sfail = GS_GRAPHICS_STENCIL_OP_DECR_WRAP; - else if (gs_token_compare_text(&token, "INVERT")) pdesc->pip_desc.stencil.sfail = GS_GRAPHICS_STENCIL_OP_INVERT; - else - { - gs_parse_warning("PIPELINE::STENCIL::sfail type %.*s not valid.", token.len, token.text); - } - } - } - - // Stencil test pass, Depth fail - else if (gs_token_compare_text(&token, "dpfail")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::STENCIL::dpfail value not found after decl."); - } - - else - { - token = lex->current_token; - - if (gs_token_compare_text(&token, "KEEP")) pdesc->pip_desc.stencil.dpfail = GS_GRAPHICS_STENCIL_OP_KEEP; - else if (gs_token_compare_text(&token, "ZERO")) pdesc->pip_desc.stencil.dpfail = GS_GRAPHICS_STENCIL_OP_ZERO; - else if (gs_token_compare_text(&token, "REPLACE")) pdesc->pip_desc.stencil.dpfail = GS_GRAPHICS_STENCIL_OP_REPLACE; - else if (gs_token_compare_text(&token, "INCR")) pdesc->pip_desc.stencil.dpfail = GS_GRAPHICS_STENCIL_OP_INCR; - else if (gs_token_compare_text(&token, "INCR_WRAP")) pdesc->pip_desc.stencil.dpfail = GS_GRAPHICS_STENCIL_OP_INCR_WRAP; - else if (gs_token_compare_text(&token, "DECR")) pdesc->pip_desc.stencil.dpfail = GS_GRAPHICS_STENCIL_OP_DECR; - else if (gs_token_compare_text(&token, "DECR_WRAP")) pdesc->pip_desc.stencil.dpfail = GS_GRAPHICS_STENCIL_OP_DECR_WRAP; - else if (gs_token_compare_text(&token, "INVERT")) pdesc->pip_desc.stencil.dpfail = GS_GRAPHICS_STENCIL_OP_INVERT; - else - { - gs_parse_warning("PIPELINE::STENCIL::dpfail type %.*s not valid.", token.len, token.text); - } - } - } - - // Stencil test pass, Depth pass - else if (gs_token_compare_text(&token, "dppass")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::STENCIL::dppass value not found after decl."); - } - - else - { - token = lex->current_token; - - if (gs_token_compare_text(&token, "KEEP")) pdesc->pip_desc.stencil.dppass = GS_GRAPHICS_STENCIL_OP_KEEP; - else if (gs_token_compare_text(&token, "ZERO")) pdesc->pip_desc.stencil.dppass = GS_GRAPHICS_STENCIL_OP_ZERO; - else if (gs_token_compare_text(&token, "REPLACE")) pdesc->pip_desc.stencil.dppass = GS_GRAPHICS_STENCIL_OP_REPLACE; - else if (gs_token_compare_text(&token, "INCR")) pdesc->pip_desc.stencil.dppass = GS_GRAPHICS_STENCIL_OP_INCR; - else if (gs_token_compare_text(&token, "INCR_WRAP")) pdesc->pip_desc.stencil.dppass = GS_GRAPHICS_STENCIL_OP_INCR_WRAP; - else if (gs_token_compare_text(&token, "DECR")) pdesc->pip_desc.stencil.dppass = GS_GRAPHICS_STENCIL_OP_DECR; - else if (gs_token_compare_text(&token, "DECR_WRAP")) pdesc->pip_desc.stencil.dppass = GS_GRAPHICS_STENCIL_OP_DECR_WRAP; - else if (gs_token_compare_text(&token, "INVERT")) pdesc->pip_desc.stencil.dppass = GS_GRAPHICS_STENCIL_OP_INVERT; - else - { - gs_parse_warning("PIPELINE::STENCIL::dppass type %.*s not valid.", token.len, token.text); - } - } - } - }); -} - -void gs_parse_raster(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t* ppd) -{ - gs_parse_block( - PIPELINE::RASTER, - { - // Index Buffer Element Size - if (gs_token_compare_text(&token, "index_buffer_element_size")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::RASTER::index buffer element size not found.", token.len, token.text); - } - - token = lex->current_token; - - if (gs_token_compare_text(&token, "UINT32") || gs_token_compare_text(&token, "uint32_t") || gs_token_compare_text(&token, "u32")) - { - pdesc->pip_desc.raster.index_buffer_element_size = sizeof(uint32_t); - } - - else if (gs_token_compare_text(&token, "UINT16") || gs_token_compare_text(&token, "uint16_t") || gs_token_compare_text(&token, "u16")) - { - pdesc->pip_desc.raster.index_buffer_element_size = sizeof(uint16_t); - } - - // Default - else - { - pdesc->pip_desc.raster.index_buffer_element_size = sizeof(uint32_t); - } - } - - // Face culling - if (gs_token_compare_text(&token, "face_culling")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::RASTER::face culling type not found."); - } - - token = lex->current_token; - - if (gs_token_compare_text(&token, "FRONT")) pdesc->pip_desc.raster.face_culling = GS_GRAPHICS_FACE_CULLING_FRONT; - else if (gs_token_compare_text(&token, "BACK")) pdesc->pip_desc.raster.face_culling = GS_GRAPHICS_FACE_CULLING_BACK; - else if (gs_token_compare_text(&token, "FRONT_AND_BACK")) pdesc->pip_desc.raster.face_culling = GS_GRAPHICS_FACE_CULLING_FRONT_AND_BACK; - else - { - gs_parse_warning("PIPELINE::RASTER::face culling type %.*s not valid.", token.len, token.text); - } - } - - // Winding order - if (gs_token_compare_text(&token, "winding_order")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::RASTER::winding order type not found."); - } - - token = lex->current_token; - - if (gs_token_compare_text(&token, "CW")) pdesc->pip_desc.raster.face_culling = GS_GRAPHICS_WINDING_ORDER_CW; - else if (gs_token_compare_text(&token, "CCW")) pdesc->pip_desc.raster.face_culling = GS_GRAPHICS_WINDING_ORDER_CCW; - else - { - gs_parse_warning("PIPELINE::RASTER::winding order type %.*s not valid.", token.len, token.text); - } - } - - // Primtive - if (gs_token_compare_text(&token, "primitive")) - { - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_IDENTIFIER)) - { - gs_parse_error(false, "PIPELINE::RASTER::primitive type not found."); - } - - token = lex->current_token; - - if (gs_token_compare_text(&token, "LINES")) pdesc->pip_desc.raster.primitive = GS_GRAPHICS_PRIMITIVE_LINES; - else if (gs_token_compare_text(&token, "TRIANGLES")) pdesc->pip_desc.raster.primitive = GS_GRAPHICS_PRIMITIVE_TRIANGLES; - else if (gs_token_compare_text(&token, "QUADS")) pdesc->pip_desc.raster.primitive = GS_GRAPHICS_PRIMITIVE_QUADS; - else - { - gs_parse_warning("PIPELINE::RASTER::primitive type %.*s not valid.", token.len, token.text); - } - } - }); -} - -void gs_parse_pipeline(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd) -{ - // Get next identifier - while (lex->can_lex(lex)) - { - gs_token_t token = lex->next_token(lex); - switch (token.type) - { - case GS_TOKEN_IDENTIFIER: - { - if (gs_token_compare_text(&token, "shader")) - { - gs_println("parsing shader"); - gs_parse_shader(lex, desc, ppd); - } - - else if (gs_token_compare_text(&token, "raster")) - { - gs_parse_raster(lex, desc, ppd); - } - - else if (gs_token_compare_text(&token, "depth")) - { - gs_parse_depth(lex, desc, ppd); - } - - else if (gs_token_compare_text(&token, "stencil")) - { - gs_parse_stencil(lex, desc, ppd); - } - - else if (gs_token_compare_text(&token, "blend")) - { - gs_parse_blend(lex, desc, ppd); - } - - } break; - } - } -} - -char* gs_pipeline_generate_shader_code(gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t* ppd, gs_graphics_shader_stage_type stage) -{ - gs_println("GENERATING CODE..."); - - // Shaders - #ifdef GS_PLATFORM_WEB - #define _GS_VERSION_STR "#version 300 es\n" - #else - #define _GS_VERSION_STR "#version 330 core\n" - #endif - - // Source code - char* src = NULL; - uint32_t sidx = 0; - - // Set sidx - switch (stage) - { - case GS_GRAPHICS_SHADER_STAGE_VERTEX: sidx = 0; break; - case GS_GRAPHICS_SHADER_STAGE_FRAGMENT: sidx = 1; break; - case GS_GRAPHICS_SHADER_STAGE_COMPUTE: sidx = 2; break; - } - - // Early out for now... - if (!ppd->code[sidx]) - { - return src; - } - - const char* shader_header = - stage == GS_GRAPHICS_SHADER_STAGE_COMPUTE ? - "#version 430\n" : - _GS_VERSION_STR - "precision mediump float;\n"; - - // Generate shader code - if (ppd->code[sidx]) - { - const size_t header_sz = (size_t)gs_string_length(shader_header); - size_t total_sz = gs_string_length(ppd->code[sidx]) + header_sz + 2048; - src = gs_malloc(total_sz); - memset(src, 0, total_sz); - strncat(src, shader_header, header_sz); - - // Attributes - if (stage == GS_GRAPHICS_SHADER_STAGE_VERTEX) - { - for (uint32_t i = 0; i < gs_dyn_array_size(pdesc->pip_desc.layout.attrs); ++i) - { - const char* aname = pdesc->pip_desc.layout.attrs[i].name; - const char* atype = gs_get_vertex_attribute_string(pdesc->pip_desc.layout.attrs[i].format); - - gs_snprintfc(ATTR, 64, "layout(location = %zu) in %s %s;\n", i, atype, aname); - const size_t sz = gs_string_length(ATTR); - strncat(src, ATTR, sz); - } - } - - // Compute shader image buffer binding - uint32_t img_binding = 0; - - // Uniforms - for (uint32_t i = 0; i < gs_dyn_array_size(pdesc->ublock_desc.layout); ++i) - { - gs_gfxt_uniform_desc_t* udesc = &pdesc->ublock_desc.layout[i]; - - if (udesc->stage != stage) continue; - - switch (stage) - { - case GS_GRAPHICS_SHADER_STAGE_COMPUTE: - { - // Need to go from uniform type to string - const char* utype = gs_uniform_string_from_type(udesc->type); - const char* uname = udesc->name; - - switch (udesc->type) - { - default: - { - gs_snprintfc(TMP, 64, "uniform %s %s;\n", utype, uname); - const size_t sz = gs_string_length(TMP); - strncat(src, TMP, sz); - } break; - - case GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F: - { - gs_snprintfc(TMP, 64, "layout (rgba32f, binding = %zu) uniform image2D %s;\n", img_binding++, uname); - const size_t sz = gs_string_length(TMP); - strncat(src, TMP, sz); - } break; - } - } break; - - default: - { - // Need to go from uniform type to string - const char* utype = gs_uniform_string_from_type(udesc->type); - const char* uname = udesc->name; - gs_snprintfc(TMP, 64, "uniform %s %s;\n", utype, uname); - const size_t sz = gs_string_length(TMP); - strncat(src, TMP, sz); - } break; - } - - } - - // Out - switch (stage) - { - case GS_GRAPHICS_SHADER_STAGE_FRAGMENT: - case GS_GRAPHICS_SHADER_STAGE_VERTEX: - { - for (uint32_t i = 0; i < gs_dyn_array_size(ppd->io_list[sidx]); ++i) - { - gs_shader_io_data_t* out = &ppd->io_list[sidx][i]; - const char* otype = out->type; - const char* oname = out->name; - gs_transient_buffer(TMP, 64); - if (stage == GS_GRAPHICS_SHADER_STAGE_FRAGMENT) - { - gs_snprintf(TMP, 64, "layout(location = %zu) out %s %s;\n", i, otype, oname); - } - else - { - gs_snprintf(TMP, 64, "out %s %s;\n", otype, oname); - } - const size_t sz = gs_string_length(TMP); - strncat(src, TMP, sz); - } - } break; - - default: break; - } - - // In - switch (stage) - { - case GS_GRAPHICS_SHADER_STAGE_FRAGMENT: - { - for (uint32_t i = 0; i < gs_dyn_array_size(ppd->io_list[0]); ++i) - { - gs_shader_io_data_t* out = &ppd->io_list[0][i]; - const char* otype = out->type; - const char* oname = out->name; - gs_snprintfc(TMP, 64, "in %s %s;\n", otype, oname); - const size_t sz = gs_string_length(TMP); - strncat(src, TMP, sz); - } - } break; - - case GS_GRAPHICS_SHADER_STAGE_COMPUTE: - { - gs_snprintfc(TMP, 64, "layout("); - strncat(src, "layout(", 7); - - for (uint32_t i = 0; i < gs_dyn_array_size(ppd->io_list[2]); ++i) - { - gs_shader_io_data_t* out = &ppd->io_list[2][i]; - const char* otype = out->type; - const char* oname = out->name; - gs_snprintfc(TMP, 64, "%s = %s%s", otype, oname, i == gs_dyn_array_size(ppd->io_list[2]) - 1 ? "" : ", "); - const size_t sz = gs_string_length(TMP); - strncat(src, TMP, sz); - } - - strncat(src, ") in;\n", 7); - } break; - - default: break; - } - - // Code - { - const size_t sz = gs_string_length(ppd->code[sidx]); - strncat(src, ppd->code[sidx], sz); - } - } - - return src; -} - -GS_API_DECL bool gs_pipeline_load_resource_from_file(const char* path, gs_asset_t* out, void* user_data) -{ - // Cast to pip - gs_pipeline_t* pip = (gs_pipeline_t *)out; - - // Load file, generate lexer off of file data, parse contents for pipeline information - size_t len = 0; - char* file_data = gs_platform_read_file_contents(path, "r", &len); - gs_assert(file_data); - - gs_ppd_t ppd = {0}; - gs_gfxt_pipeline_desc_t pdesc = {0}; - pdesc.pip_desc.raster.index_buffer_element_size = sizeof(uint32_t); - - gs_lexer_t lex = gs_lexer_c_ctor(file_data); - while (lex.can_lex(&lex)) - { - gs_token_t token = lex.next_token(&lex); - switch (token.type) - { - case GS_TOKEN_IDENTIFIER: - { - if (gs_token_compare_text(&token, "pipeline")) - { - gs_parse_pipeline(&lex, &pdesc, &ppd); - } - } break; - } - } - - // Generate vertex shader code - char* v_src = gs_pipeline_generate_shader_code(&pdesc, &ppd, GS_GRAPHICS_SHADER_STAGE_VERTEX); - - // gs_println("%s", v_src); - - // Generate fragment shader code - char* f_src = gs_pipeline_generate_shader_code(&pdesc, &ppd, GS_GRAPHICS_SHADER_STAGE_FRAGMENT); - - // gs_println("%s", f_src); - - // Generate compute shader code (need to check for this first) - char* c_src = gs_pipeline_generate_shader_code(&pdesc, &ppd, GS_GRAPHICS_SHADER_STAGE_COMPUTE); - // gs_println("%s", c_src); - - // Construct compute shader - if (c_src) - { - pdesc.pip_desc.compute.shader = gs_graphics_shader_create(&(gs_graphics_shader_desc_t){ - .sources = (gs_graphics_shader_source_desc_t[]){ - {.type = GS_GRAPHICS_SHADER_STAGE_COMPUTE, .source = c_src} - }, - .size = 1 * sizeof(gs_graphics_shader_source_desc_t), - .name = path - }); - } - - // Construct raster shader - else - { - pdesc.pip_desc.raster.shader = gs_graphics_shader_create(&(gs_graphics_shader_desc_t){ - .sources = (gs_graphics_shader_source_desc_t[]){ - {.type = GS_GRAPHICS_SHADER_STAGE_VERTEX, .source = v_src}, - {.type = GS_GRAPHICS_SHADER_STAGE_FRAGMENT, .source = f_src} - }, - .size = 2 * sizeof(gs_graphics_shader_source_desc_t), - .name = path - }); - } - - - // Set up layout - pdesc.pip_desc.layout.size = gs_dyn_array_size(pdesc.pip_desc.layout.attrs) * sizeof(gs_graphics_vertex_attribute_desc_t); - - // Set up ublock - pdesc.ublock_desc.size = gs_dyn_array_size(pdesc.ublock_desc.layout) * sizeof(gs_gfxt_uniform_desc_t); - - // Create pipeline - pip->pipeline = gs_gfxt_pipeline_create(&pdesc); - - // Create mesh layout - if (ppd.mesh_layout) - { - for (uint32_t i = 0; i < gs_dyn_array_size(ppd.mesh_layout); ++i) - { - gs_dyn_array_push(pip->mesh_layout, ppd.mesh_layout[i]); - } - } - - // Free all malloc'd data - if (v_src) gs_free(v_src); - if (f_src) gs_free(f_src); - if (c_src) gs_free(c_src); - gs_free(file_data); - gs_dyn_array_free(pdesc.pip_desc.layout.attrs); - gs_dyn_array_free(pdesc.ublock_desc.layout); - gs_dyn_array_free(ppd.mesh_layout); - - for (uint32_t i = 0; i < 3; ++i) - { - if (ppd.code[i]) gs_free(ppd.code[i]); - gs_dyn_array_free(ppd.io_list[i]); - } - - return true; -} - -GS_API_DECL gs_gfxt_mesh_import_options_t gs_pipeline_get_mesh_import_options(const gs_pipeline_t* pipe) -{ - // Get pipeline descriptor - gs_graphics_pipeline_desc_t pdesc = gs_default_val(); - gs_graphics_pipeline_desc_query(pipe->pipeline.hndl, &pdesc); - - // Construct mesh import options - gs_gfxt_mesh_import_options_t options = gs_default_val(); - options.index_buffer_element_size = pdesc.raster.index_buffer_element_size; - - // Copy mesh layout from pipeline - for (uint32_t i = 0; i < gs_dyn_array_size(pipe->mesh_layout); ++i) - { - gs_dyn_array_push(options.layout, pipe->mesh_layout[i]); - } - options.size = sizeof(gs_gfxt_mesh_layout_t) * gs_dyn_array_size(options.layout); - - // Free pipeline descriptor - gs_dyn_array_free(pdesc.layout.attrs); - - return options; -} - #endif // GS_ASSET_IMPL #endif // GS_ASSET_H diff --git a/gs_core/source/gs_config.c b/gs_core/source/gs_config.c index e4a2c73..4ee7fdb 100644 --- a/gs_core/source/gs_config.c +++ b/gs_core/source/gs_config.c @@ -41,13 +41,14 @@ */ #define GS_IMPL +#define GS_NO_SHORT_NAME // avoids gs_core name conflicts #include #define GS_IMMEDIATE_DRAW_IMPL #include #define GS_GUI_IMPL -#include " +#include #define GS_GFXT_IMPL #include diff --git a/gs_core/source/gs_graphics.h b/gs_core/source/gs_graphics.h index 1264b37..0fc849b 100644 --- a/gs_core/source/gs_graphics.h +++ b/gs_core/source/gs_graphics.h @@ -67,8 +67,8 @@ int32_t gs_quad_compare(const void* a, const void* b) typedef struct gs_quad_batch_t { gs_dyn_array(gs_quad_t) quads;// Array of quads - gs_vbo vbo; // Vertex buffer handle - gs_ibo ibo; // Index buffer handle + gs_handle(gs_graphics_vertex_buffer_t) vbo; // Vertex buffer handle + gs_handle(gs_graphics_index_buffer_t) ibo; // Index buffer handle uint32_t material_hndl; // Reference to a material asset uint32_t count; // Total index buffer count for upload } gs_quad_batch_t; diff --git a/gs_core/source/proj_gen/main.c b/gs_core/source/proj_gen/main.c index 8fd1538..d7cdc44 100644 --- a/gs_core/source/proj_gen/main.c +++ b/gs_core/source/proj_gen/main.c @@ -55,7 +55,7 @@ GS_API_DECL gs_token_t gs_lexer_gen_next_token(gs_lexer_t* lex) case ')': {t.type = GS_TOKEN_RPAREN; lex->at++;} break; case '<': {t.type = GS_TOKEN_LTHAN; lex->at++;} break; case '>': {t.type = GS_TOKEN_GTHAN; lex->at++;} break; - case ';': {t.type = GS_TOKEN_SEMI_COLON; lex->at++;} break; + case ';': {t.type = GS_TOKEN_SEMICOLON; lex->at++;} break; case ':': {t.type = GS_TOKEN_COLON; lex->at++;} break; case ',': {t.type = GS_TOKEN_COMMA; lex->at++;} break; case '=': {t.type = GS_TOKEN_EQUAL; lex->at++;} break; diff --git a/gs_core/source/proj_gen/templates/app.h b/gs_core/source/proj_gen/templates/app.h index dab57f8..1160ad4 100644 --- a/gs_core/source/proj_gen/templates/app.h +++ b/gs_core/source/proj_gen/templates/app.h @@ -29,7 +29,7 @@ GS_API_DECL void %APP_NAME%_shutdown(); GS_API_DECL void %APP_NAME%_init() { // Initialize core - %APP_NAME%_t* app = gs_engine_user_data(%APP_NAME%_t); + %APP_NAME%_t* app = gs_user_data(%APP_NAME%_t); app->core = gs_core_new(); // Register reflection for %APP_NAME% @@ -42,7 +42,7 @@ GS_API_DECL void %APP_NAME%_init() GS_API_DECL void %APP_NAME%_update() { // Cache app/core pointers - %APP_NAME%_t* app = gs_engine_user_data(%APP_NAME%_t); + %APP_NAME%_t* app = gs_user_data(%APP_NAME%_t); gs_core_t* core = app->core; gs_command_buffer_t* cb = &core->cb; gs_immediate_draw_t* gsi = &core->gsi; @@ -54,7 +54,7 @@ GS_API_DECL void %APP_NAME%_update() const gs_vec2 ws = gs_platform_window_sizev(gs_platform_main_window()); // Process input (closing window) - if (gs_platform_key_pressed(GS_KEYCODE_ESC)) gs_engine_quit(); + if (gs_platform_key_pressed(GS_KEYCODE_ESC)) gs_quit(); // Update entity manager gs_entities_update(em); @@ -69,15 +69,15 @@ GS_API_DECL void %APP_NAME%_update() gsi_rectvd(gsi, gs_v2(150.f, 150.f), gs_v2(500.f, 500.f * 0.18f), gs_v2s(0.f), gs_v2s(1.f), GS_COLOR_WHITE, GS_GRAPHICS_PRIMITIVE_TRIANGLES); // Submit immediate draw render pass - gsi_render_pass_submit(gsi, cb, gs_color(10, 10, 10, 255)); + gsi_renderpass_submit(gsi, cb, gs_color(10, 10, 10, 255)); // Submit command buffer for rendering - gs_graphics_submit_command_buffer(cb); + gs_graphics_command_buffer_submit(cb); } GS_API_DECL void %APP_NAME%_shutdown() { - %APP_NAME%_t* app = gs_engine_user_data(%APP_NAME%_t); + %APP_NAME%_t* app = gs_user_data(%APP_NAME%_t); gs_core_delete(app->core); } diff --git a/gs_core/source/reflection/main.c b/gs_core/source/reflection/main.c index 056494a..4b943ed 100644 --- a/gs_core/source/reflection/main.c +++ b/gs_core/source/reflection/main.c @@ -569,7 +569,7 @@ void parse_struct_field(reflection_data_t* refl, meta_class_t* c, gs_lexer_t* le memcpy(p.name, t.text, t.len); // Require semi colon - if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_SEMI_COLON)) gs_assert(false); + if (!gs_lexer_find_next_token_type(lex, GS_TOKEN_SEMICOLON)) gs_assert(false); // Add to class properties gs_dyn_array_push(c->properties, p); @@ -577,7 +577,7 @@ void parse_struct_field(reflection_data_t* refl, meta_class_t* c, gs_lexer_t* le else { // Move to the semicolon - gs_lexer_find_next_token_type(lex, GS_TOKEN_SEMI_COLON); + gs_lexer_find_next_token_type(lex, GS_TOKEN_SEMICOLON); } } @@ -615,7 +615,7 @@ void parse_struct(reflection_data_t* refl, gs_lexer_t* lex) } // Parse to semi colon (if identifier found, store name) - while (lex->can_lex(lex) && t.type != GS_TOKEN_SEMI_COLON) + while (lex->can_lex(lex) && t.type != GS_TOKEN_SEMICOLON) { t = lex->next_token(lex); switch (t.type) @@ -674,7 +674,7 @@ void parse_enum(reflection_data_t* refl, gs_lexer_t* lex) } // Find semi colon - while (lex->can_lex(lex) && t.type != GS_TOKEN_SEMI_COLON) + while (lex->can_lex(lex) && t.type != GS_TOKEN_SEMICOLON) { t = lex->next_token(lex); switch (t.type) diff --git a/gs_core/third_party/include/gs b/gs_core/third_party/include/gs index 42ad228..1e3dd13 160000 --- a/gs_core/third_party/include/gs +++ b/gs_core/third_party/include/gs @@ -1 +1 @@ -Subproject commit 42ad22853331cb97ead5645c114c4408ff5686d1 +Subproject commit 1e3dd134c4d9b9e0d16a29e14264cd17cf21e894 diff --git a/gs_editor/bin/Reflection.ilk b/gs_editor/bin/Reflection.ilk deleted file mode 100644 index 4a1d799..0000000 Binary files a/gs_editor/bin/Reflection.ilk and /dev/null differ diff --git a/gs_editor/bin/Reflection.pdb b/gs_editor/bin/Reflection.pdb deleted file mode 100644 index 1a16e0f..0000000 Binary files a/gs_editor/bin/Reflection.pdb and /dev/null differ diff --git a/gs_editor/bin/gs_editor.ilk b/gs_editor/bin/gs_editor.ilk deleted file mode 100644 index 1405328..0000000 Binary files a/gs_editor/bin/gs_editor.ilk and /dev/null differ diff --git a/gs_editor/bin/gs_editor.pdb b/gs_editor/bin/gs_editor.pdb deleted file mode 100644 index 57ff1ae..0000000 Binary files a/gs_editor/bin/gs_editor.pdb and /dev/null differ diff --git a/gs_editor/bin/gs_editor_main.obj b/gs_editor/bin/gs_editor_main.obj deleted file mode 100644 index 34cc6e6..0000000 Binary files a/gs_editor/bin/gs_editor_main.obj and /dev/null differ diff --git a/gs_editor/bin/main.obj b/gs_editor/bin/main.obj deleted file mode 100644 index 42fa4d5..0000000 Binary files a/gs_editor/bin/main.obj and /dev/null differ diff --git a/gs_editor/bin/vc140.pdb b/gs_editor/bin/vc140.pdb deleted file mode 100644 index c263e12..0000000 Binary files a/gs_editor/bin/vc140.pdb and /dev/null differ diff --git a/gs_editor/source/gs_editor.h b/gs_editor/source/gs_editor.h index 8bfe189..50109b5 100644 --- a/gs_editor/source/gs_editor.h +++ b/gs_editor/source/gs_editor.h @@ -280,13 +280,13 @@ void gui_button_cb(struct gs_gui_context_t* ctx, gs_gui_rect_t r, gs_gui_id id, } if (label) {gs_gui_draw_control_text(ctx, label, r, GS_GUI_COLOR_TEXT, opt);} - if (icon) {gs_gui_draw_icon(ctx, icon, r, ctx->style->colors[GS_GUI_COLOR_TEXT]);} + // if (icon) {gs_gui_draw_icon(ctx, icon, r, ctx->style->colors[GS_GUI_COLOR_TEXT]);} } GS_API_DECL void gs_editor_init() { // Initialize core - gs_editor_t* app = gs_engine_user_data(gs_editor_t); + gs_editor_t* app = gs_user_data(gs_editor_t); app->core = gs_core_new(); // Register reflection for gs_editor @@ -345,7 +345,7 @@ GS_API_DECL void gs_editor_init() app->rand = gs_rand_seed((uint64_t)time(NULL)); // Add gui callback for button rendering - // app->core->gsgui.callbacks.button = gui_button_cb; + app->core->gsgui.callbacks.button = gui_button_cb; } /* @@ -419,11 +419,11 @@ static void write_log(char* logbuf, const char* text, bool* updated) { static void dockspace(gs_gui_context_t* ctx) { int32_t opt = GS_GUI_OPT_NOCLIP | GS_GUI_OPT_NOFRAME | GS_GUI_OPT_FORCESETRECT | GS_GUI_OPT_NOTITLE | GS_GUI_OPT_DOCKSPACE | GS_GUI_OPT_FULLSCREEN | GS_GUI_OPT_NOMOVE | GS_GUI_OPT_NOBRINGTOFRONT | GS_GUI_OPT_NOFOCUS | GS_GUI_OPT_NORESIZE; - gs_gui_begin_window_ex(ctx, "Dockspace", gs_gui_rect(350, 40, 600, 500), opt); + gs_gui_window_begin_ex(ctx, "Dockspace", gs_gui_rect(350, 40, 600, 500), NULL, NULL, opt); { // Empty dockspace... } - gs_gui_end_window(ctx); + gs_gui_window_end(ctx); } static void test_window(gs_gui_context_t *ctx) @@ -432,7 +432,7 @@ static void test_window(gs_gui_context_t *ctx) static float bg[3] = {90, 95, 100}; /* do window */ - if (gs_gui_begin_window(ctx, "Demo", gs_gui_rect(40, 40, 300, 450))) + if (gs_gui_window_begin(ctx, "Demo", gs_gui_rect(40, 40, 300, 450))) { if (gs_gui_header(ctx, "Window Info")) { @@ -445,7 +445,7 @@ static void test_window(gs_gui_context_t *ctx) gs_snprintf(buf, 64, "%.2f, %.2f", win->rect.w, win->rect.h); gs_gui_label(ctx, buf); } - if (gs_gui_header_ex(ctx, "Test Buttons", 0x00)) + if (gs_gui_header_ex(ctx, "Test Buttons", NULL, 0x00)) { gs_gui_layout_row(ctx, 3, (int[]) { 120, 100, 100 }, 0); gs_gui_label(ctx, "Test buttons 1:"); @@ -455,94 +455,94 @@ static void test_window(gs_gui_context_t *ctx) if (gs_gui_button(ctx, "Button 3")) { write_log(logbuf, "Pressed button 3", &logbuf_updated); } if (gs_gui_button(ctx, "Popup")) { - gs_gui_open_popup(ctx, "Test Popup"); + gs_gui_popup_open(ctx, "Test Popup"); } gs_vec2 ws = gs_platform_window_sizev(ctx->window_hndl); - if (gs_gui_begin_popup_ex( ctx, "Test Popup", gs_gui_rect((ws.x - 400) / 2.f, (ws.y - 100) / 2.f, 400, 100), GS_GUI_OPT_NORESIZE | GS_GUI_OPT_FORCESETRECT | GS_GUI_OPT_NOTITLE)) + if (gs_gui_popup_begin_ex( ctx, "Test Popup", gs_gui_rect((ws.x - 400) / 2.f, (ws.y - 100) / 2.f, 400, 100), NULL, GS_GUI_OPT_NORESIZE | GS_GUI_OPT_FORCESETRECT | GS_GUI_OPT_NOTITLE)) { gs_gui_container_t* cnt = gs_gui_get_current_container(ctx); gs_gui_layout_row(ctx, 1, (int[]) { -1 }, 20); - gs_gui_text(ctx, "Close the text box.", 0); + gs_gui_text(ctx, "Close the text box."); gs_gui_layout_row(ctx, 2, (int[]) { -200, -1 }, 20); if (gs_gui_button(ctx, "Okay") || gs_gui_button(ctx, "Cancel")) { cnt->open = 0; } - gs_gui_end_popup(ctx); + gs_gui_popup_end(ctx); } } - if (gs_gui_header_ex(ctx, "Tree and Text", 0x00)) + if (gs_gui_header_ex(ctx, "Tree and Text", NULL, 0x00)) { gs_gui_layout_row(ctx, 2, (int[]) { 250, -1 }, 0); - gs_gui_layout_begin_column(ctx); - if (gs_gui_begin_treenode(ctx, "Test 1")) { - if (gs_gui_begin_treenode(ctx, "Test 1a")) { + gs_gui_layout_column_begin(ctx); + if (gs_gui_treenode_begin(ctx, "Test 1")) { + if (gs_gui_treenode_begin(ctx, "Test 1a")) { gs_gui_label(ctx, "Hello"); gs_gui_label(ctx, "world"); - gs_gui_end_treenode(ctx); + gs_gui_treenode_end(ctx); } - if (gs_gui_begin_treenode(ctx, "Test 1b")) { + if (gs_gui_treenode_begin(ctx, "Test 1b")) { if (gs_gui_button(ctx, "Button 1")) { write_log(logbuf, "Pressed button 1", &logbuf_updated); } if (gs_gui_button(ctx, "Button 2")) { write_log(logbuf, "Pressed button 2", &logbuf_updated); } - gs_gui_end_treenode(ctx); + gs_gui_treenode_end(ctx); } - gs_gui_end_treenode(ctx); + gs_gui_treenode_end(ctx); } - if (gs_gui_begin_treenode(ctx, "Test 2")) + if (gs_gui_treenode_begin(ctx, "Test 2")) { gs_gui_layout_row(ctx, 3, (int[]) { 65, 65, 65 }, 0); if (gs_gui_button(ctx, "Button 3")) { write_log(logbuf, "Pressed button 3", &logbuf_updated); } if (gs_gui_button(ctx, "Button 4")) { write_log(logbuf, "Pressed button 4", &logbuf_updated); } if (gs_gui_button(ctx, "Button 5")) { write_log(logbuf, "Pressed button 5", &logbuf_updated); } if (gs_gui_button(ctx, "Button 6")) { write_log(logbuf, "Pressed button 6", &logbuf_updated); } - gs_gui_end_treenode(ctx); + gs_gui_treenode_end(ctx); } - if (gs_gui_begin_treenode(ctx, "Test 3")) + if (gs_gui_treenode_begin(ctx, "Test 3")) { static int checks[3] = { 1, 0, 1 }; gs_gui_checkbox(ctx, "Checkbox 1", &checks[0]); gs_gui_checkbox(ctx, "Checkbox 2", &checks[1]); gs_gui_checkbox(ctx, "Checkbox 3", &checks[2]); - gs_gui_end_treenode(ctx); + gs_gui_treenode_end(ctx); } - gs_gui_layout_end_column(ctx); + gs_gui_layout_column_end(ctx); - gs_gui_layout_begin_column(ctx); + gs_gui_layout_column_begin(ctx); gs_gui_layout_row(ctx, 1, (int[]) { -1 }, 0); gs_gui_text(ctx, "Lorem ipsum dolor sit amet, consectetur adipiscing " "elit. Maecenas lacinia, sem eu lacinia molestie, mi risus faucibus " - "ipsum, eu varius magna felis a nulla.", 1); - gs_gui_layout_end_column(ctx); + "ipsum, eu varius magna felis a nulla."); + gs_gui_layout_column_end(ctx); } - if (gs_gui_header_ex(ctx, "Background Color", 0x00)) + if (gs_gui_header_ex(ctx, "Background Color", NULL, 0x00)) { gs_gui_layout_row(ctx, 2, (int[]) { -78, -1 }, 74); - gs_gui_layout_begin_column(ctx); + gs_gui_layout_column_begin(ctx); gs_gui_layout_row(ctx, 2, (int[]) { 46, -1 }, 0); gs_gui_label(ctx, "Red:"); gs_gui_slider(ctx, &bg[0], 0, 255); gs_gui_label(ctx, "Green:"); gs_gui_slider(ctx, &bg[1], 0, 255); gs_gui_label(ctx, "Blue:"); gs_gui_slider(ctx, &bg[2], 0, 255); - gs_gui_layout_end_column(ctx); + gs_gui_layout_column_end(ctx); gs_gui_rect_t r = gs_gui_layout_next(ctx); gs_gui_draw_rect(ctx, r, gs_color(bg[0], bg[1], bg[2], 255)); char buf[32]; gs_snprintf(buf, 32, "#%02X%02X%02X", (int) bg[0], (int) bg[1], (int) bg[2]); - gs_gui_draw_control_text(ctx, buf, r, GS_GUI_COLOR_TEXT, GS_GUI_OPT_ALIGNCENTER); + gs_gui_draw_control_text(ctx, buf, r, GS_GUI_COLOR_TEXT, GS_GUI_ALIGN_CENTER); } - if (gs_gui_header_ex(ctx, "Shapes", 0x00)) + if (gs_gui_header_ex(ctx, "Shapes", NULL, 0x00)) { - gs_editor_t* app = gs_engine_user_data(gs_editor_t); + gs_editor_t* app = gs_user_data(gs_editor_t); gs_texture_t* tex = gs_asset_handle_get(&app->tex); gs_texture_t* ntex = gs_asset_handle_get(&app->nine_tex); gs_gui_container_t* cnt = gs_gui_get_current_container(ctx); gs_gui_layout_row(ctx, 1, (int[]) { -1 }, 400); - gs_gui_begin_panel_ex(ctx, "!panel", GS_GUI_OPT_NOSCROLL); + gs_gui_panel_begin_ex(ctx, "!panel", NULL, GS_GUI_OPT_NOSCROLL); { gs_gui_layout_row(ctx, 4, (int[]) { 20, 10, 10, -1 }, 0); @@ -565,24 +565,24 @@ static void test_window(gs_gui_context_t *ctx) float rh = h + _t * (float)s * 0.2f; gs_gui_draw_nine_rect(ctx, ntex->texture.hndl, gs_gui_rect(next.x, next.y + 40.f, (uint32_t)rw, (uint32_t)rh), gs_v2s(0.f), gs_v2s(1.f), m, m, m, m, GS_COLOR_WHITE); } - gs_gui_end_panel(ctx); + gs_gui_panel_end(ctx); } - gs_gui_end_window(ctx); + gs_gui_window_end(ctx); } } static void log_window(gs_gui_context_t* ctx) { - if (gs_gui_begin_window_ex(ctx, "Log Window", gs_gui_rect(350, 40, 300, 200), GS_GUI_OPT_NOSCROLL)) + if (gs_gui_window_begin_ex(ctx, "Log Window", gs_gui_rect(350, 40, 300, 200), NULL, NULL, GS_GUI_OPT_NOSCROLL)) { gs_gui_container_t* cnt = gs_gui_get_current_container(ctx); gs_gui_layout_row(ctx, 1, (int[]) { -1 }, gs_max(cnt->rect.h - 80, 80)); - gs_gui_begin_panel_ex(ctx, "Panel", GS_GUI_OPT_NOSCROLL); + gs_gui_panel_begin_ex(ctx, "Panel", NULL, GS_GUI_OPT_NOSCROLL); gs_gui_container_t* panel = gs_gui_get_current_container(ctx); gs_gui_layout_row(ctx, 1, (int[]) { -1 }, -1); - gs_gui_text(ctx, logbuf, 0); - gs_gui_end_panel(ctx); + gs_gui_text(ctx, logbuf); + gs_gui_panel_end(ctx); if (logbuf_updated) { // panel->scroll.y = panel->content_size.y; logbuf_updated = 0; @@ -601,21 +601,10 @@ static void log_window(gs_gui_context_t* ctx) write_log(logbuf, buf, &logbuf_updated); buf[0] = '\0'; } - gs_gui_end_window(ctx); + gs_gui_window_end(ctx); } } -static int uint8_slider(gs_gui_context_t *ctx, unsigned char *value, int low, int high) { - static float tmp; - gs_gui_push_id(ctx, &value, sizeof(value)); - tmp = *value; - int res = gs_gui_slider_ex(ctx, &tmp, low, high, 0, "%.0f", GS_GUI_OPT_ALIGNCENTER); - *value = tmp; - gs_gui_pop_id(ctx); - return res; -} - - static void style_window(gs_gui_context_t *ctx) { static struct { const char *label; int idx; } colors[] = { @@ -638,27 +627,27 @@ static void style_window(gs_gui_context_t *ctx) { NULL } }; - if (gs_gui_begin_window(ctx, "Style Editor", gs_gui_rect(350, 250, 300, 240))) + if (gs_gui_window_begin(ctx, "Style Editor", gs_gui_rect(350, 250, 300, 240))) { int sw = gs_gui_get_current_container(ctx)->body.w * 0.14; gs_gui_layout_row(ctx, 6, (int[]) { 80, sw, sw, sw, sw, -1 }, 0); for (int i = 0; colors[i].label; i++) { gs_gui_label(ctx, colors[i].label); - uint8_slider(ctx, &ctx->style->colors[i].r, 0, 255); - uint8_slider(ctx, &ctx->style->colors[i].g, 0, 255); - uint8_slider(ctx, &ctx->style->colors[i].b, 0, 255); - uint8_slider(ctx, &ctx->style->colors[i].a, 0, 255); + uint8_slider(ctx, &ctx->style->colors[i].r, 0, 255, NULL, NULL); + uint8_slider(ctx, &ctx->style->colors[i].g, 0, 255, NULL, NULL); + uint8_slider(ctx, &ctx->style->colors[i].b, 0, 255, NULL, NULL); + uint8_slider(ctx, &ctx->style->colors[i].a, 0, 255, NULL, NULL); gs_gui_draw_rect(ctx, gs_gui_layout_next(ctx), ctx->style->colors[i]); } - gs_gui_end_window(ctx); + gs_gui_window_end(ctx); } } GS_API_DECL void gs_editor_update() { // Cache app/core pointers - gs_editor_t* app = gs_engine_user_data(gs_editor_t); + gs_editor_t* app = gs_user_data(gs_editor_t); gs_core_t* core = app->core; gs_command_buffer_t* cb = &core->cb; gs_immediate_draw_t* gsi = &core->gsi; @@ -680,9 +669,9 @@ GS_API_DECL void gs_editor_update() const gs_vec2 ws = gs_platform_window_sizev(gs_platform_main_window()); // Process input (closing window) - if (gs_platform_key_pressed(GS_KEYCODE_ESC)) gs_engine_quit(); + if (gs_platform_key_pressed(GS_KEYCODE_ESC)) gs_quit(); - gs_gui_begin(gsgui); + gs_gui_begin(gsgui, NULL); // Update entity manager gs_entities_update(em); @@ -693,13 +682,13 @@ GS_API_DECL void gs_editor_update() gs_vec2 ts = gs_v2(500.f, 500.f * 0.18f); // Render hello to screen - gsi_camera2D(gsi); + gsi_camera2D(gsi, fb.x, fb.y); gsi_text(gsi, (fb.x - td.x) * 0.5f, (fb.y - td.y) * 0.5f, "Project: gs_editor", NULL, false, 255, 255, 255, 255); gsi_texture(gsi, tex->texture.hndl); gsi_rectvd(gsi, gs_v2((fb.x - ts.x) * 0.5f, (fb.y - ts.y) * 0.5f - td.y - 50.f), ts, gs_v2s(0.f), gs_v2s(1.f), GS_COLOR_WHITE, GS_GRAPHICS_PRIMITIVE_TRIANGLES); // Submit immediate draw render pass - gsi_render_pass_submit(gsi, cb, gs_color(10, 10, 10, 255)); + gsi_renderpass_submit(gsi, cb, (gs_vec4){0.,0., ws.x, ws.y}, gs_color(10, 10, 10, 255)); #define WIN_CNT 10 @@ -723,7 +712,7 @@ GS_API_DECL void gs_editor_update() r.h = 300.f; #endif - if (gs_gui_begin_window(gsgui, TMP, r)) + if (gs_gui_window_begin(gsgui, TMP, r)) { static char BUF[256] = {0}; if (gs_gui_textbox(gsgui, BUF, 256)) @@ -739,7 +728,7 @@ GS_API_DECL void gs_editor_update() } } - gs_gui_end_window(gsgui); + gs_gui_window_end(gsgui); } } @@ -752,17 +741,17 @@ GS_API_DECL void gs_editor_update() gs_gui_render(gsgui, cb); gs_timed_action(60, { - gs_println("frame: %.2f", gs_engine_subsystem(platform)->time.frame); + gs_println("frame: %.2f", gs_platform_frame_time()); }); // Submit command buffer for rendering - gs_graphics_submit_command_buffer(cb); + gs_graphics_command_buffer_submit(cb); } GS_API_DECL void gs_editor_shutdown() { - gs_editor_t* app = gs_engine_user_data(gs_editor_t); + gs_editor_t* app = gs_user_data(gs_editor_t); gs_core_delete(app->core); } @@ -770,8 +759,8 @@ GS_API_DECL gs_app_desc_t gs_editor_main(int32_t argc, char** argv) { return (gs_app_desc_t) { - .window_width = 1200, - .window_height = 700, + .window.width = 1200, + .window.height = 700, .init = gs_editor_init, .update = gs_editor_update, .shutdown = gs_editor_shutdown,