Skip to content

Commit

Permalink
[graphics]: added GS_GRAPHICS_UNIFORM_USAMPLER2D, added GS_GRAPHICS_T…
Browse files Browse the repository at this point in the history
…EXTURE_FORMAT_R32
  • Loading branch information
MrFrenik committed Sep 14, 2023
1 parent ff836ef commit e098029
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 19 deletions.
24 changes: 20 additions & 4 deletions gs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ GS_API_DECL void gs_paged_allocator_clear(gs_paged_allocator_t* pa);

#define gs_v2s(__S) gs_vec2_ctor((__S), (__S))
#define gs_v3s(__S) gs_vec3_ctor((__S), (__S), (__S))
#define gs_v4s(__S) gs_vec4_ctor((__S), (__S), (__S), (__S))
#define gs_v4s(__S) gs_vec4_ctor((__S), (__S), (__S), (__S))

#define gs_v4_xy_v(__X, __Y, __V) gs_vec4_ctor((__X), (__Y), (__V).x, (__V).y)
#define gs_v4_xyz_s(__XYZ, __S) gs_vec4_ctor((__XYZ).x, (__XYZ).y, (__XYZ).z, (__S))
Expand Down Expand Up @@ -2791,6 +2791,13 @@ gs_vec2_ctor(f32 _x, f32 _y)
return v;
}

gs_inline bool
gs_vec2_nan(gs_vec2 v)
{
if (v.x != v.x || v.y != v.y) return true;
return false;
}

gs_inline gs_vec2
gs_vec2_add(gs_vec2 v0, gs_vec2 v1)
{
Expand Down Expand Up @@ -3185,17 +3192,23 @@ gs_vec4_dist(gs_vec4 v0, gs_vec4 v1)
================================================================================*/

gs_inline
gs_vec3 gs_v4_to_v3(gs_vec4 v)
gs_vec3 gs_v4tov3(gs_vec4 v)
{
return gs_v3(v.x, v.y, v.z);
}

gs_inline
gs_vec2 gs_v3_to_v2(gs_vec3 v)
gs_vec2 gs_v3tov2(gs_vec3 v)
{
return gs_v2(v.x, v.y);
}

gs_inline
gs_vec3 gs_v2tov3(gs_vec2 v)
{
return gs_v3(v.x, v.y, 0.f);
}

/*================================================================================
// Mat3x3
================================================================================*/
Expand Down Expand Up @@ -3810,7 +3823,7 @@ gs_vec4 gs_mat4_mul_vec4(gs_mat4 m, gs_vec4 v)
gs_inline
gs_vec3 gs_mat4_mul_vec3(gs_mat4 m, gs_vec3 v)
{
return gs_v4_to_v3(gs_mat4_mul_vec4(m, gs_v4_xyz_s(v, 1.f)));
return gs_v4tov3(gs_mat4_mul_vec4(m, gs_v4_xyz_s(v, 1.f)));
}


Expand Down Expand Up @@ -5628,6 +5641,7 @@ gs_enum_decl(gs_graphics_uniform_type,
GS_GRAPHICS_UNIFORM_VEC4,
GS_GRAPHICS_UNIFORM_MAT4,
GS_GRAPHICS_UNIFORM_SAMPLER2D,
GS_GRAPHICS_UNIFORM_USAMPLER2D,
GS_GRAPHICS_UNIFORM_SAMPLERCUBE,
GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F,
GS_GRAPHICS_UNIFORM_BLOCK
Expand Down Expand Up @@ -5718,6 +5732,8 @@ gs_enum_decl(gs_graphics_texture_format_type,
GS_GRAPHICS_TEXTURE_FORMAT_RGBA8,
GS_GRAPHICS_TEXTURE_FORMAT_RGB8,
GS_GRAPHICS_TEXTURE_FORMAT_RG8,
GS_GRAPHICS_TEXTURE_FORMAT_R32,
GS_GRAPHICS_TEXTURE_FORMAT_R32F,
GS_GRAPHICS_TEXTURE_FORMAT_RGBA16F,
GS_GRAPHICS_TEXTURE_FORMAT_RGBA32F,
GS_GRAPHICS_TEXTURE_FORMAT_A8,
Expand Down
15 changes: 14 additions & 1 deletion impl/gs_graphics_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ uint32_t gsgl_texture_format_to_gl_data_type(gs_graphics_texture_format_type typ
default:
case GS_GRAPHICS_TEXTURE_FORMAT_A8: format = GL_UNSIGNED_BYTE; break;
case GS_GRAPHICS_TEXTURE_FORMAT_R8: format = GL_UNSIGNED_BYTE; break;
case GS_GRAPHICS_TEXTURE_FORMAT_R32: format = GL_UNSIGNED_INT; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGB8: format = GL_UNSIGNED_BYTE; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA8: format = GL_UNSIGNED_BYTE; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA16F: format = GL_FLOAT; break;
Expand All @@ -274,6 +275,7 @@ uint32_t gsgl_texture_format_to_gl_texture_format(gs_graphics_texture_format_typ
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA8: dt = GL_RGBA; break;
case GS_GRAPHICS_TEXTURE_FORMAT_A8: dt = GL_ALPHA; break;
case GS_GRAPHICS_TEXTURE_FORMAT_R8: dt = GL_RED; break;
case GS_GRAPHICS_TEXTURE_FORMAT_R32: dt = GL_RED_INTEGER; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGB8: dt = GL_RGB; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA16F: dt = GL_RGBA; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA32F: dt = GL_RGBA; break;
Expand All @@ -294,6 +296,7 @@ uint32_t gsgl_texture_format_to_gl_texture_internal_format(gs_graphics_texture_f
switch (type) {
case GS_GRAPHICS_TEXTURE_FORMAT_A8: format = GL_ALPHA; break;
case GS_GRAPHICS_TEXTURE_FORMAT_R8: format = GL_RED; break;
case GS_GRAPHICS_TEXTURE_FORMAT_R32: format = GL_R32UI; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGB8: format = GL_RGB8; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA8: format = GL_RGBA8; break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA16F: format = GL_RGBA16F; break;
Expand Down Expand Up @@ -465,6 +468,7 @@ gsgl_uniform_type gsgl_uniform_type_to_gl_uniform_type(gs_graphics_uniform_type
case GS_GRAPHICS_UNIFORM_VEC3: type = GSGL_UNIFORMTYPE_VEC3; break;
case GS_GRAPHICS_UNIFORM_VEC4: type = GSGL_UNIFORMTYPE_VEC4; break;
case GS_GRAPHICS_UNIFORM_MAT4: type = GSGL_UNIFORMTYPE_MAT4; break;
case GS_GRAPHICS_UNIFORM_USAMPLER2D: type = GSGL_UNIFORMTYPE_SAMPLER2D; break;
case GS_GRAPHICS_UNIFORM_SAMPLER2D: type = GSGL_UNIFORMTYPE_SAMPLER2D; break;
case GS_GRAPHICS_UNIFORM_SAMPLERCUBE: type = GSGL_UNIFORMTYPE_SAMPLERCUBE; break;
}
Expand Down Expand Up @@ -546,6 +550,7 @@ size_t gsgl_uniform_data_size_in_bytes(gs_graphics_uniform_type type)
case GS_GRAPHICS_UNIFORM_VEC4: sz = 4 * sizeof(float); break;
case GS_GRAPHICS_UNIFORM_MAT4: sz = 16 * sizeof(float); break;
case GS_GRAPHICS_UNIFORM_SAMPLER2D: sz = sizeof(gs_handle(gs_graphics_texture_t)); break; // handle size
case GS_GRAPHICS_UNIFORM_USAMPLER2D: sz = sizeof(gs_handle(gs_graphics_texture_t)); break; // handle size
case GS_GRAPHICS_UNIFORM_SAMPLERCUBE: sz = sizeof(gs_handle(gs_graphics_texture_t)); break; // handle size
default: {
sz = 0;
Expand Down Expand Up @@ -683,9 +688,11 @@ gsgl_texture_t gl_texture_update_internal(const gs_graphics_texture_desc_t* desc
{
case GS_GRAPHICS_TEXTURE_FORMAT_A8: glTexImage2D(itarget, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_R8: glTexImage2D(itarget, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_R32: glTexImage2D(itarget, 0, GL_R32UI, width, height, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RG8: glTexImage2D(itarget, 0, GL_RG8, width, height, 0, GL_RG, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGB8: glTexImage2D(itarget, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA8: glTexImage2D(itarget, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_R32F: glTexImage2D(itarget, 0, GL_R32F, width, height, 0, GL_RED, GL_FLOAT, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA16F: glTexImage2D(itarget, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA32F: glTexImage2D(itarget, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_DEPTH8: glTexImage2D(itarget, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, data); break;
Expand All @@ -707,9 +714,11 @@ gsgl_texture_t gl_texture_update_internal(const gs_graphics_texture_desc_t* desc
{
case GS_GRAPHICS_TEXTURE_FORMAT_A8: glTexSubImage2D(itarget, 0, (u32)desc->offset.x, (u32)desc->offset.y, width, height, GL_ALPHA, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_R8: glTexSubImage2D(itarget, 0, (u32)desc->offset.x, (u32)desc->offset.y, width, height, GL_RED, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_R32: glTexImage2D(itarget, 0, GL_R32UI, width, height, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RG8: glTexSubImage2D(itarget, 0, (u32)desc->offset.x, (u32)desc->offset.y, width, height, GL_RG, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGB8: glTexSubImage2D(itarget, 0, (u32)desc->offset.x, (u32)desc->offset.y, width, height, GL_RGB, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA8: glTexSubImage2D(itarget, 0, (u32)desc->offset.x, (u32)desc->offset.y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_R32F: glTexImage2D(itarget, 0, GL_R32F, width, height, 0, GL_RED, GL_FLOAT, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA16F: glTexSubImage2D(itarget, 0, (u32)desc->offset.x, (u32)desc->offset.y, width, height, GL_RGBA, GL_FLOAT, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA32F: glTexSubImage2D(itarget, 0, (u32)desc->offset.x, (u32)desc->offset.y, width, height, GL_RGBA, GL_FLOAT, data); break;
case GS_GRAPHICS_TEXTURE_FORMAT_DEPTH8: glTexSubImage2D(itarget, 0, (u32)desc->offset.x, (u32)desc->offset.y, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, data); break;
Expand Down Expand Up @@ -1499,6 +1508,7 @@ gs_graphics_texture_request_update(gs_command_buffer_t* cb, gs_handle(gs_graphic
case GS_GRAPHICS_TEXTURE_FORMAT_RGB8: num_comps = 3; data_type_size = sizeof(uint8_t); break;
case GS_GRAPHICS_TEXTURE_FORMAT_A8: num_comps = 1; data_type_size = sizeof(uint8_t); break;
case GS_GRAPHICS_TEXTURE_FORMAT_R8: num_comps = 1; data_type_size = sizeof(uint8_t); break;
case GS_GRAPHICS_TEXTURE_FORMAT_R32: num_comps = 1; data_type_size = sizeof(uint32_t); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA16F: num_comps = 4; data_type_size = sizeof(float); break;
case GS_GRAPHICS_TEXTURE_FORMAT_RGBA32F: num_comps = 4; data_type_size = sizeof(float); break;
case GS_GRAPHICS_TEXTURE_FORMAT_DEPTH8: num_comps = 1; data_type_size = sizeof(float); break;
Expand Down Expand Up @@ -2752,7 +2762,10 @@ gs_graphics_init(gs_graphics_t* graphics)
// Work group invocations
glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, (int32_t*)&info->compute.max_work_group_invocations);
}
)
)

const GLubyte* glslv = glGetString(GL_SHADING_LANGUAGE_VERSION);
gs_println("GLSL Version: %s", glslv);

// Set up all function pointers for graphics context

Expand Down
20 changes: 13 additions & 7 deletions util/gs_gfxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ gs_gfxt_uniform_block_create(const gs_gfxt_uniform_block_desc_t* desc)
case GS_GRAPHICS_UNIFORM_VEC4: offset += sizeof(gs_vec4); break;
case GS_GRAPHICS_UNIFORM_MAT4: offset += sizeof(gs_mat4); break;
case GS_GRAPHICS_UNIFORM_SAMPLER2D: offset += sizeof(gs_handle(gs_graphics_texture_t)); break;
case GS_GRAPHICS_UNIFORM_USAMPLER2D: offset += sizeof(gs_handle(gs_graphics_texture_t)); break;
case GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F:
{
image2D_offset += sizeof(gs_handle(gs_graphics_texture_t));
Expand Down Expand Up @@ -1034,7 +1035,8 @@ void gs_gfxt_material_set_uniform(gs_gfxt_material_t* mat, const char* name, con
case GS_GRAPHICS_UNIFORM_MAT4: gs_byte_buffer_write(&mat->uniform_data, gs_mat4, *(gs_mat4*)data); break;

case GS_GRAPHICS_UNIFORM_SAMPLERCUBE:
case GS_GRAPHICS_UNIFORM_SAMPLER2D:
case GS_GRAPHICS_UNIFORM_SAMPLER2D:
case GS_GRAPHICS_UNIFORM_USAMPLER2D:
{
gs_byte_buffer_write(&mat->uniform_data, gs_handle(gs_graphics_texture_t), *(gs_handle(gs_graphics_texture_t)*)data);
} break;
Expand Down Expand Up @@ -2090,6 +2092,7 @@ gs_graphics_uniform_type gs_uniform_type_from_token(const gs_token_t* t)
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, "usampler2D")) return GS_GRAPHICS_UNIFORM_USAMPLER2D;
else if (gs_token_compare_text(t, "samplerCube")) return GS_GRAPHICS_UNIFORM_SAMPLERCUBE;
else if (gs_token_compare_text(t, "img2D_rgba32f")) return GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F;
return (gs_graphics_uniform_type)0x00;
Expand All @@ -2106,6 +2109,7 @@ const char* gs_uniform_string_from_type(gs_graphics_uniform_type type)
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_USAMPLER2D: return "usampler2D"; break;
case GS_GRAPHICS_UNIFORM_SAMPLERCUBE: return "samplerCube"; break;
case GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F: return "image2D"; break;
default: return "UNKNOWN"; break;
Expand Down Expand Up @@ -2200,6 +2204,7 @@ bool gs_parse_uniforms(gs_lexer_t* lex, gs_gfxt_pipeline_desc_t* desc, gs_ppd_t*
default: break;

case GS_GRAPHICS_UNIFORM_SAMPLER2D:
case GS_GRAPHICS_UNIFORM_USAMPLER2D:
case GS_GRAPHICS_UNIFORM_IMAGE2D_RGBA32F:
{
uniform.binding = image_binding++;
Expand Down Expand Up @@ -3144,11 +3149,15 @@ char* gs_pipeline_generate_shader_code(gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t*
{
gs_println("GENERATING CODE...");

// Get major/minor version of shader
gs_graphics_info_t* ginfo = gs_graphics_info();
gs_snprintfc(MAJMINSTR, 128, "#version %zu%zu0\n", ginfo->major_version, ginfo->minor_version);

// Shaders
#ifdef GS_PLATFORM_WEB
#define _GS_VERSION_STR "#version 300 es\n"
#else
#define _GS_VERSION_STR "#version 330 core\n"
#define _GS_VERSION_STR MAJMINSTR
#endif

// Source code
Expand All @@ -3169,11 +3178,8 @@ char* gs_pipeline_generate_shader_code(gs_gfxt_pipeline_desc_t* pdesc, gs_ppd_t*
return src;
}

const char* shader_header =
stage == GS_GRAPHICS_SHADER_STAGE_COMPUTE ?
"#version 430\n" :
_GS_VERSION_STR
"precision mediump float;\n";
// Shader header
gs_snprintfc(shader_header, 512, "%s precision mediump float;\n", stage == GS_GRAPHICS_SHADER_STAGE_COMPUTE ? "#version 430\n" : _GS_VERSION_STR);

// Generate shader code
if (ppd->code[sidx])
Expand Down
86 changes: 80 additions & 6 deletions util/gs_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,8 @@ GS_API_DECL void gs_gui_layout_width(gs_gui_context_t *ctx, int32_t width);
GS_API_DECL void gs_gui_layout_height(gs_gui_context_t *ctx, int32_t height);
GS_API_DECL void gs_gui_layout_column_begin(gs_gui_context_t *ctx);
GS_API_DECL void gs_gui_layout_column_end(gs_gui_context_t *ctx);
GS_API_DECL void gs_gui_layout_set_next(gs_gui_context_t *ctx, gs_gui_rect_t r, int32_t relative);
GS_API_DECL void gs_gui_layout_set_next(gs_gui_context_t *ctx, gs_gui_rect_t r, int32_t relative);
GS_API_DECL gs_gui_rect_t gs_gui_layout_peek_next(gs_gui_context_t *ctx);
GS_API_DECL gs_gui_rect_t gs_gui_layout_next(gs_gui_context_t *ctx);
GS_API_DECL gs_gui_rect_t gs_gui_layout_anchor(const gs_gui_rect_t* parent, int32_t width, int32_t height, int32_t xoff, int32_t yoff, gs_gui_layout_anchor_type type);

Expand Down Expand Up @@ -5636,7 +5637,9 @@ enum {
GS_GUI_ABSOLUTE = 2
};

GS_API_DECL gs_gui_rect_t gs_gui_layout_anchor(const gs_gui_rect_t* p, int32_t width, int32_t height, int32_t xoff, int32_t yoff, gs_gui_layout_anchor_type type)
GS_API_DECL gs_gui_rect_t
gs_gui_layout_anchor(const gs_gui_rect_t* p, int32_t width, int32_t height,
int32_t xoff, int32_t yoff, gs_gui_layout_anchor_type type)
{
float w = (float)width;
float h = (float)height;
Expand Down Expand Up @@ -5768,24 +5771,95 @@ GS_API_DECL void gs_gui_layout_row_ex(gs_gui_context_t *ctx, int32_t items, cons
}
}

GS_API_DECL void gs_gui_layout_width(gs_gui_context_t *ctx, int32_t width)
GS_API_DECL void
gs_gui_layout_width(gs_gui_context_t *ctx, int32_t width)
{
gs_gui_get_layout(ctx)->size.x = (f32)width;
}

GS_API_DECL void gs_gui_layout_height(gs_gui_context_t *ctx, int32_t height)
GS_API_DECL void
gs_gui_layout_height(gs_gui_context_t *ctx, int32_t height)
{
gs_gui_get_layout(ctx)->size.y = (f32)height;
}

GS_API_DECL void gs_gui_layout_set_next(gs_gui_context_t *ctx, gs_gui_rect_t r, int32_t relative)
GS_API_DECL void
gs_gui_layout_set_next(gs_gui_context_t *ctx, gs_gui_rect_t r, int32_t relative)
{
gs_gui_layout_t *layout = gs_gui_get_layout(ctx);
layout->next = r;
layout->next_type = relative ? GS_GUI_RELATIVE : GS_GUI_ABSOLUTE;
}

GS_API_DECL gs_gui_rect_t gs_gui_layout_next(gs_gui_context_t *ctx)
GS_API_DECL gs_gui_rect_t
gs_gui_layout_peek_next(gs_gui_context_t *ctx)
{
gs_gui_layout_t layout = *gs_gui_get_layout(ctx);
gs_gui_style_t* style = ctx->style;
gs_gui_rect_t res;

if (layout.next_type)
{
/* handle rect set by `gs_gui_layout_set_next` */
int32_t type = layout.next_type;
res = layout.next;
if (type == GS_GUI_ABSOLUTE)
{
return res;
}

}
else
{
// handle next row
if (layout.item_index == layout.items)
{
gs_gui_layout_row(ctx, layout.items, NULL, (s32)layout.size.y);
}

const int32_t items = layout.items;
const int32_t idx = layout.item_index;

int32_t ml = style->margin[GS_GUI_MARGIN_LEFT];
int32_t mr = style->margin[GS_GUI_MARGIN_RIGHT];
int32_t mt = style->margin[GS_GUI_MARGIN_TOP];
int32_t mb = style->margin[GS_GUI_MARGIN_BOTTOM];

// position
res.x = layout.position.x + ml;
res.y = layout.position.y + mt;

// size
res.w = layout.items > 0 ? layout.widths[layout.item_index] : layout.size.x;
res.h = layout.size.y;

// default fallbacks
if (res.w == 0) { res.w = style->size[0]; }
if (res.h == 0) { res.h = style->size[1]; }

if (res.w < 0) { res.w += layout.body.w - res.x + 1; }
if (res.h < 0) { res.h += layout.body.h - res.y + 1; }

layout.item_index++;
}

/* update position */
layout.position.x += res.w + style->margin[GS_GUI_MARGIN_RIGHT];
layout.next_row = (s32)gs_max(layout.next_row, res.y + res.h + style->margin[GS_GUI_MARGIN_BOTTOM]);

/* apply body offset */
res.x += layout.body.x;
res.y += layout.body.y;

/* update max position */
layout.max.x = gs_max(layout.max.x, res.x + res.w);
layout.max.y = gs_max(layout.max.y, res.y + res.h);

return res;
}

GS_API_DECL gs_gui_rect_t
gs_gui_layout_next(gs_gui_context_t *ctx)
{
gs_gui_layout_t* layout = gs_gui_get_layout(ctx);
gs_gui_style_t* style = ctx->style;
Expand Down
2 changes: 1 addition & 1 deletion util/gs_physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ typedef struct gs_cone_t
} gs_cone_t;

// 2D shapes
typedef struct gs_circle_t {float r; gs_vec2 c; } gs_circle_t;
// typedef struct gs_rect_t {gs_vec2 min; gs_vec2 max; } gs_rect_t;
// typedef struct gs_circle_t {float r; gs_vec2 c; } gs_circle_t;
// typedef struct gs_triangle_t {gs_vec2 a,b,c; } gs_triangle_t;
// typedef struct gs_pill_t {gs_vec2 base; float r, height; } gs_pill_t;

Expand Down

0 comments on commit e098029

Please sign in to comment.