Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/MrFrenik/gunslinger
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFrenik committed Apr 26, 2024
2 parents 23f7fa4 + 970863f commit b86f742
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 43 deletions.
10 changes: 5 additions & 5 deletions gs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8249,7 +8249,7 @@ gs_asset_texture_load_from_file(const char* path, void* out, gs_graphics_texture
stbi_set_flip_vertically_on_load(t->desc.flip_y);
*t->desc.data = (uint8_t*)stbi_load_from_file(f, (int32_t*)&t->desc.width, (int32_t*)&t->desc.height, (int32_t*)&comp, STBI_rgb_alpha);

if (!t->desc.data) {
if (!*t->desc.data) {
fclose(f);
return false;
}
Expand Down Expand Up @@ -8296,7 +8296,7 @@ bool gs_asset_texture_load_from_memory(const void* memory, size_t sz, void* out,
// Load texture data
int32_t num_comps = 0;
bool32_t loaded = gs_util_load_texture_data_from_memory(memory, sz, (int32_t*)&t->desc.width,
(int32_t*)&t->desc.height, (uint32_t*)&num_comps, (void**)&t->desc.data, t->desc.flip_y);
(int32_t*)&t->desc.height, (uint32_t*)&num_comps, t->desc.data, t->desc.flip_y);

if (!loaded) {
return false;
Expand All @@ -8305,7 +8305,7 @@ bool gs_asset_texture_load_from_memory(const void* memory, size_t sz, void* out,
t->hndl = gs_graphics_texture_create(&t->desc);

if (!keep_data) {
gs_free(t->desc.data);
gs_free(*t->desc.data);
*t->desc.data = NULL;
}

Expand Down Expand Up @@ -9045,7 +9045,7 @@ gs_lexer_c_next_token(gs_lexer_t* lex)
)
{
// Grab decimal
num_decimals = lex->at[0] == '.' ? num_decimals++ : num_decimals;
num_decimals = lex->at[0] == '.' ? num_decimals + 1 : num_decimals;

//Increment
lex->at++;
Expand Down Expand Up @@ -9142,7 +9142,7 @@ gs_lexer_c_next_token(gs_lexer_t* lex)
)
{
// Grab decimal
num_decimals = lex->at[0] == '.' ? num_decimals++ : num_decimals;
num_decimals = lex->at[0] == '.' ? num_decimals + 1 : num_decimals;

//Increment
lex->at++;
Expand Down
28 changes: 12 additions & 16 deletions impl/gs_graphics_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ gs_graphics_uniform_create_impl(const gs_graphics_uniform_desc_t* desc)
gsgl_data_t* ogl = (gsgl_data_t*)gs_subsystem(graphics)->user_data;

// Assert if data isn't named
if (desc->name == NULL) {
if (*desc->name == 0) {
gs_println("Warning: Uniform must be named for OpenGL.");
return gs_handle_invalid(gs_graphics_uniform_t);
}
Expand Down Expand Up @@ -920,7 +920,7 @@ gs_graphics_storage_buffer_create_impl(const gs_graphics_storage_buffer_desc_t*
gs_handle(gs_graphics_storage_buffer_t) hndl = gs_default_val();
gsgl_storage_buffer_t sbo = gs_default_val();

if (desc->name == NULL) {
if (*desc->name == 0) {
gs_println("Warning: Storage buffer must be named for Opengl.");
}

Expand Down Expand Up @@ -1282,14 +1282,14 @@ gs_graphics_texture_desc_query(gs_handle(gs_graphics_texture_t) hndl, gs_graphic
gsgl_texture_t* tex = gs_slot_array_getp(ogl->textures, hndl.id);

// Read back pixels
if (out->data && out->read.width && out->read.height)
if (out->read.width && out->read.height)
{
uint32_t type = gsgl_texture_format_to_gl_data_type(tex->desc.format);
uint32_t format = gsgl_texture_format_to_gl_texture_format(tex->desc.format);
CHECK_GL_CORE(
glActiveTexture(GL_TEXTURE0);
glGetTextureSubImage(tex->id, 0, out->read.x, out->read.y, 0, out->read.width, out->read.height, 1, format, type, out->read.size, out->data);
);
glActiveTexture(GL_TEXTURE0);
glGetTextureSubImage(tex->id, 0, out->read.x, out->read.y, 0, out->read.width, out->read.height, 1, format, type, out->read.size, out->data);
);
}

*out = tex->desc;
Expand Down Expand Up @@ -1373,7 +1373,6 @@ gs_graphics_index_buffer_update_impl(gs_handle(gs_graphics_index_buffer_t) hndl,
int32_t glusage = gsgl_buffer_usage_to_gl_enum(desc->usage);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
switch (desc->update.type) {
l:
case GS_GRAPHICS_BUFFER_UPDATE_SUBDATA: glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, desc->update.offset, desc->size, desc->data); break;
default: glBufferData(GL_ELEMENT_ARRAY_BUFFER, desc->size, desc->data, glusage); break;
}
Expand Down Expand Up @@ -1994,14 +1993,11 @@ void gs_graphics_command_buffer_submit_impl(gs_command_buffer_t* cb)
// Construct temp name, concat with base name + uniform field name
char name[256] = gs_default_val();
memcpy(name, ul->name, 64);
if (u->name)
{
gs_snprintfc(UTMP, 256, "%s%s", ul->name, u->name);
memcpy(name, UTMP, 256);
}
gs_snprintfc(UTMP, 256, "%s%s", ul->name, u->name);
memcpy(name, UTMP, 256);

// Grab location of uniform based on name
u->location = glGetUniformLocation(shader, name ? name : "__EMPTY_UNIFORM_NAME");
u->location = glGetUniformLocation(shader, *name ? name : "__EMPTY_UNIFORM_NAME");

if (u->location >= UINT32_MAX) {
gs_println("Warning: Bind Uniform: Uniform not found: \"%s\"", name);
Expand Down Expand Up @@ -2193,7 +2189,7 @@ void gs_graphics_command_buffer_submit_impl(gs_command_buffer_t* cb)
gsgl_shader_t shader = gs_slot_array_get(ogl->shaders, sid);

// Get uniform location based on name and bound shader
u->location = glGetUniformBlockIndex(shader, u->name ? u->name : "__EMPTY_UNIFORM_NAME");
u->location = glGetUniformBlockIndex(shader, *u->name ? u->name : "__EMPTY_UNIFORM_NAME");

// Set binding for uniform block
glUniformBlockBinding(shader, u->location, binding);
Expand Down Expand Up @@ -2257,7 +2253,7 @@ void gs_graphics_command_buffer_submit_impl(gs_command_buffer_t* cb)
{
// Get uniform location based on name and bound shader
CHECK_GL_CORE(
sbo->block_idx = glGetProgramResourceIndex(shader, GL_SHADER_STORAGE_BLOCK, sbo->name ? sbo->name : "__EMPTY_BUFFER_NAME");
sbo->block_idx = glGetProgramResourceIndex(shader, GL_SHADER_STORAGE_BLOCK, *sbo->name ? sbo->name : "__EMPTY_BUFFER_NAME");
int32_t params[1];
GLenum props[1] = {GL_BUFFER_BINDING};
glGetProgramResourceiv(shader, GL_SHADER_STORAGE_BLOCK, sbo->block_idx, 1, props, 1, NULL, params);
Expand Down Expand Up @@ -2483,7 +2479,7 @@ void gs_graphics_command_buffer_submit_impl(gs_command_buffer_t* cb)
gsgl_buffer_t vbo = vdecl.vbo;

// Manual override. If you manually set divisor/stride/offset, then will not automatically calculate any of those.
bool is_manual = pip->layout[i].stride | pip->layout[i].divisor | pip->layout[i].offset | vdecl.data_type == GS_GRAPHICS_VERTEX_DATA_NONINTERLEAVED;
bool is_manual = pip->layout[i].stride | pip->layout[i].divisor | pip->layout[i].offset | (vdecl.data_type == GS_GRAPHICS_VERTEX_DATA_NONINTERLEAVED);

// Bind buffer
glBindBuffer(GL_ARRAY_BUFFER, vbo);
Expand Down
18 changes: 10 additions & 8 deletions util/gs_gfxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2349,33 +2349,34 @@ bool gs_parse_code(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd
{
case GS_TOKEN_IDENTIFIER:
{
// evil replace a const char*
if (gs_token_compare_text(&tkn, "GS_GFXT_UNIFORM_MODEL_VIEW_PROJECTION_MATRIX"))
{
gs_util_string_replace(tkn.text, tkn.len, GS_GFXT_UNIFORM_MODEL_VIEW_PROJECTION_MATRIX, (char)32);
gs_util_string_replace((char*)tkn.text, tkn.len, GS_GFXT_UNIFORM_MODEL_VIEW_PROJECTION_MATRIX, (char)32);
}
else if (gs_token_compare_text(&tkn, "GS_GFXT_UNIFORM_VIEW_PROJECTION_MATRIX"))
{
gs_util_string_replace(tkn.text, tkn.len, GS_GFXT_UNIFORM_VIEW_PROJECTION_MATRIX, (char)32);
gs_util_string_replace((char*)tkn.text, tkn.len, GS_GFXT_UNIFORM_VIEW_PROJECTION_MATRIX, (char)32);
}
else if (gs_token_compare_text(&tkn, "GS_GFXT_UNIFORM_MODEL_MATRIX"))
{
gs_util_string_replace(tkn.text, tkn.len, GS_GFXT_UNIFORM_MODEL_MATRIX, (char)32);
gs_util_string_replace((char*)tkn.text, tkn.len, GS_GFXT_UNIFORM_MODEL_MATRIX, (char)32);
}
else if (gs_token_compare_text(&tkn, "GS_GFXT_UNIFORM_INVERSE_MODEL_MATRIX"))
{
gs_util_string_replace(tkn.text, tkn.len, GS_GFXT_UNIFORM_INVERSE_MODEL_MATRIX, (char)32);
gs_util_string_replace((char*)tkn.text, tkn.len, GS_GFXT_UNIFORM_INVERSE_MODEL_MATRIX, (char)32);
}
else if (gs_token_compare_text(&tkn, "GS_GFXT_UNIFORM_VIEW_MATRIX"))
{
gs_util_string_replace(tkn.text, tkn.len, GS_GFXT_UNIFORM_VIEW_MATRIX, (char)32);
gs_util_string_replace((char*)tkn.text, tkn.len, GS_GFXT_UNIFORM_VIEW_MATRIX, (char)32);
}
else if (gs_token_compare_text(&tkn, "GS_GFXT_UNIFORM_PROJECTION_MATRIX"))
{
gs_util_string_replace(tkn.text, tkn.len, GS_GFXT_UNIFORM_PROJECTION_MATRIX, (char)32);
gs_util_string_replace((char*)tkn.text, tkn.len, GS_GFXT_UNIFORM_PROJECTION_MATRIX, (char)32);
}
else if (gs_token_compare_text(&tkn, "GS_GFXT_UNIFORM_TIME"))
{
gs_util_string_replace(tkn.text, tkn.len, GS_GFXT_UNIFORM_TIME, (char)32);
gs_util_string_replace((char*)tkn.text, tkn.len, GS_GFXT_UNIFORM_TIME, (char)32);
}
} break;

Expand All @@ -2397,7 +2398,8 @@ bool gs_parse_code(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t* ppd
if (tkn.type == GS_TOKEN_STRING)
{
memcpy(includes[iidx], tkn.text + 1, tkn.len - 2);
gs_util_string_replace(tkn.text - ilen, tkn.len + ilen,
// evil replace a const char*
gs_util_string_replace((char*)tkn.text - ilen, tkn.len + ilen,
" ", (char)32);
iidx++;
}
Expand Down
24 changes: 10 additions & 14 deletions util/gs_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -5476,7 +5476,7 @@ gs_gui_draw_text(gs_gui_context_t* ctx, gs_asset_font_t* font, const char *str,
} while (0)

// Draw shadow
if (shadow_x || shadow_y && shadow_color.a)
if ((shadow_x || shadow_y) && shadow_color.a)
{
DRAW_TEXT(str, gs_gui_rect(pos.x + (float)shadow_x, pos.y + (float)shadow_y, td.x, td.y), shadow_color);
}
Expand Down Expand Up @@ -6315,7 +6315,7 @@ gs_gui_label_ex(gs_gui_context_t* ctx, const char* label, const gs_gui_selector_
gs_gui_parse_id_tag(ctx, label, id_tag, sizeof(id_tag), opt);
gs_gui_parse_label_tag(ctx, label, label_tag, sizeof(label_tag));

if (id_tag) gs_gui_push_id(ctx, id_tag, strlen(id_tag));
gs_gui_push_id(ctx, id_tag, strlen(id_tag));

gs_gui_style_t style = gs_default_val();
gs_gui_animation_t* anim = gs_gui_get_animation(ctx, id, desc, elementid);
Expand All @@ -6339,7 +6339,7 @@ gs_gui_label_ex(gs_gui_context_t* ctx, const char* label, const gs_gui_selector_
gs_gui_update_control(ctx, id, r, 0x00);
gs_gui_draw_control_text(ctx, label_tag, r, &style, 0x00);
gs_gui_pop_style(ctx, save);
if (id_tag) gs_gui_pop_id(ctx);
gs_gui_pop_id(ctx);

/* handle click */
if (
Expand Down Expand Up @@ -6523,9 +6523,7 @@ gs_gui_button_ex(gs_gui_context_t* ctx, const char* label, const gs_gui_selector
gs_gui_animation_t* anim = gs_gui_get_animation(ctx, id, desc, GS_GUI_ELEMENT_BUTTON);

// Push id if tag available
if (id_tag) {
gs_gui_push_id(ctx, id_tag, strlen(id_tag));
}
gs_gui_push_id(ctx, id_tag, strlen(id_tag));

// Update anim (keep states locally within animation, only way to do this)
if (anim)
Expand Down Expand Up @@ -6565,7 +6563,7 @@ gs_gui_button_ex(gs_gui_context_t* ctx, const char* label, const gs_gui_selector

gs_gui_pop_style(ctx, save);

if (id_tag) gs_gui_pop_id(ctx);
gs_gui_pop_id(ctx);

return res;
}
Expand Down Expand Up @@ -6997,7 +6995,7 @@ static int32_t _gs_gui_header(gs_gui_context_t *ctx, const char *label, int32_t
gs_gui_id id = gs_gui_get_id(ctx, id_tag, strlen(id_tag));
int32_t idx = gs_gui_pool_get(ctx, ctx->treenode_pool, GS_GUI_TREENODEPOOL_SIZE, id);

if (id_tag) gs_gui_push_id(ctx, id_tag, strlen(id_tag));
gs_gui_push_id(ctx, id_tag, strlen(id_tag));

active = (idx >= 0);
expanded = (opt & GS_GUI_OPT_EXPANDED) ? !active : active;
Expand Down Expand Up @@ -7058,7 +7056,7 @@ static int32_t _gs_gui_header(gs_gui_context_t *ctx, const char *label, int32_t
r.w -= r.h - ctx->style->padding[GS_GUI_PADDING_BOTTOM];
gs_gui_draw_control_text(ctx, label_tag, r, &ctx->style_sheet->styles[GS_GUI_ELEMENT_TEXT][0x00], 0);

if (id_tag) gs_gui_pop_id(ctx);
gs_gui_pop_id(ctx);

return expanded ? GS_GUI_RES_ACTIVE : 0;
}
Expand Down Expand Up @@ -7158,9 +7156,7 @@ gs_gui_window_begin_ex(gs_gui_context_t * ctx, const char* title, gs_gui_rect_t
}

// Push id flag
if (id_tag) {
// cnt->flags |= GS_GUI_WINDOW_FLAGS_PUSH_ID;
}
// cnt->flags |= GS_GUI_WINDOW_FLAGS_PUSH_ID;

if (cnt->flags & GS_GUI_WINDOW_FLAGS_FIRST_INIT) {
memcpy(cnt->name, label_tag, 256);
Expand Down Expand Up @@ -7244,8 +7240,8 @@ gs_gui_window_begin_ex(gs_gui_context_t * ctx, const char* title, gs_gui_rect_t
if (tab_bar->focus == tab_item->idx)
{
cnt->flags |= GS_GUI_WINDOW_FLAGS_VISIBLE;
cnt->opt &= !GS_GUI_OPT_NOINTERACT;
cnt->opt &= !GS_GUI_OPT_NOHOVER;
cnt->opt &= ~GS_GUI_OPT_NOINTERACT;
cnt->opt &= ~GS_GUI_OPT_NOHOVER;
}
else
{
Expand Down

0 comments on commit b86f742

Please sign in to comment.