diff --git a/src/graphics.c b/src/graphics.c index 9e0b591..011937e 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -22,8 +22,135 @@ #define LOG_SUBSYSTEM "Graphics" //------------------------------------------------------------------------ -// graphics handles structs +// canvas structs //------------------------------------------------------------------------ +typedef enum { MG_PATH_MOVE, + MG_PATH_LINE, + MG_PATH_QUADRATIC, + MG_PATH_CUBIC } mg_path_elt_type; + +typedef struct mg_path_elt +{ + mg_path_elt_type type; + vec2 p[3]; + +} mg_path_elt; + +typedef struct mg_path_descriptor +{ + u32 startIndex; + u32 count; + vec2 startPoint; + +} mg_path_descriptor; + +typedef struct mg_attributes +{ + f32 width; + f32 tolerance; + mg_color color; + mg_joint_type joint; + f32 maxJointExcursion; + mg_cap_type cap; + + mg_font font; + f32 fontSize; + + mg_image image; + mp_rect srcRegion; + + mp_rect clip; + +} mg_attributes; + +typedef struct mg_rounded_rect +{ + f32 x; + f32 y; + f32 w; + f32 h; + f32 r; +} mg_rounded_rect; + +typedef enum { MG_CMD_CLEAR = 0, + MG_CMD_FILL, + MG_CMD_STROKE, + MG_CMD_RECT_FILL, + MG_CMD_RECT_STROKE, + MG_CMD_ROUND_RECT_FILL, + MG_CMD_ROUND_RECT_STROKE, + MG_CMD_ELLIPSE_FILL, + MG_CMD_ELLIPSE_STROKE, + MG_CMD_JUMP, + MG_CMD_CLIP_PUSH, + MG_CMD_CLIP_POP, + } mg_primitive_cmd; + +typedef struct mg_primitive +{ + mg_primitive_cmd cmd; + mg_attributes attributes; + mg_mat2x3 transform; + + union + { + mg_path_descriptor path; + mp_rect rect; + mg_rounded_rect roundedRect; + utf32 codePoint; + u32 jump; + mg_mat2x3 matrix; //TODO remove when we use transform everywhere + }; + +} mg_primitive; + +typedef struct mg_glyph_map_entry +{ + unicode_range range; + u32 firstGlyphIndex; + +} mg_glyph_map_entry; + +typedef struct mg_glyph_data +{ + bool exists; + utf32 codePoint; + mg_path_descriptor pathDescriptor; + mg_text_extents extents; + //... + +} mg_glyph_data; + +enum +{ + MG_STREAM_MAX_COUNT = 128, + MG_IMAGE_MAX_COUNT = 128 +}; + +enum +{ + MG_MATRIX_STACK_MAX_DEPTH = 64, + MG_CLIP_STACK_MAX_DEPTH = 64, + MG_MAX_PATH_ELEMENT_COUNT = 2<<20, + MG_MAX_PRIMITIVE_COUNT = 8<<10 +}; + +typedef struct mg_font_data +{ + list_elt freeListElt; + u32 generation; + + u32 rangeCount; + u32 glyphCount; + u32 outlineCount; + mg_glyph_map_entry* glyphMap; + mg_glyph_data* glyphs; + mg_path_elt* outlines; + + f32 unitsPerEm; + mg_font_extents extents; + +} mg_font_data; typedef struct mg_canvas_data mg_canvas_data; @@ -113,12 +240,6 @@ typedef struct mg_canvas_data } mg_canvas_data; -enum -{ - MG_ATLAS_SIZE = 8192, -}; - - static mg_data __mgData = {0}; diff --git a/src/graphics_internal.h b/src/graphics_internal.h index 8191e3e..387b9c1 100644 --- a/src/graphics_internal.h +++ b/src/graphics_internal.h @@ -16,7 +16,7 @@ extern "C" { #endif //--------------------------------------------------------------- -// surface data +// surface interface //--------------------------------------------------------------- typedef struct mg_surface_data mg_surface_data; @@ -50,111 +50,8 @@ mg_surface mg_surface_alloc_handle(mg_surface_data* surface); mg_surface_data* mg_surface_data_from_handle(mg_surface handle); //--------------------------------------------------------------- -// graphics structs +// canvas backend interface //--------------------------------------------------------------- -typedef enum { MG_PATH_MOVE, - MG_PATH_LINE, - MG_PATH_QUADRATIC, - MG_PATH_CUBIC } mg_path_elt_type; - -typedef struct mg_path_elt -{ - mg_path_elt_type type; - vec2 p[3]; - -} mg_path_elt; - -typedef struct mg_path_descriptor -{ - u32 startIndex; - u32 count; - vec2 startPoint; - -} mg_path_descriptor; - -typedef struct mg_attributes -{ - f32 width; - f32 tolerance; - mg_color color; - mg_joint_type joint; - f32 maxJointExcursion; - mg_cap_type cap; - - mg_font font; - f32 fontSize; - - mg_image image; - mp_rect srcRegion; - - mp_rect clip; - -} mg_attributes; - -typedef struct mg_rounded_rect -{ - f32 x; - f32 y; - f32 w; - f32 h; - f32 r; -} mg_rounded_rect; - -typedef enum { MG_CMD_CLEAR = 0, - MG_CMD_FILL, - MG_CMD_STROKE, - MG_CMD_RECT_FILL, - MG_CMD_RECT_STROKE, - MG_CMD_ROUND_RECT_FILL, - MG_CMD_ROUND_RECT_STROKE, - MG_CMD_ELLIPSE_FILL, - MG_CMD_ELLIPSE_STROKE, - MG_CMD_JUMP, - MG_CMD_CLIP_PUSH, - MG_CMD_CLIP_POP, - } mg_primitive_cmd; - -typedef struct mg_primitive -{ - mg_primitive_cmd cmd; - mg_attributes attributes; - mg_mat2x3 transform; - - union - { - mg_path_descriptor path; - mp_rect rect; - mg_rounded_rect roundedRect; - utf32 codePoint; - u32 jump; - mg_mat2x3 matrix; //TODO remove when we use transform everywhere - }; - -} mg_primitive; - -typedef struct mg_glyph_map_entry -{ - unicode_range range; - u32 firstGlyphIndex; - -} mg_glyph_map_entry; - -typedef struct mg_glyph_data -{ - bool exists; - utf32 codePoint; - mg_path_descriptor pathDescriptor; - mg_text_extents extents; - //... - -} mg_glyph_data; - -enum -{ - MG_STREAM_MAX_COUNT = 128, - MG_IMAGE_MAX_COUNT = 128 -}; - typedef struct mg_image_data { list_elt listElt; @@ -163,31 +60,6 @@ typedef struct mg_image_data } mg_image_data; -enum -{ - MG_MATRIX_STACK_MAX_DEPTH = 64, - MG_CLIP_STACK_MAX_DEPTH = 64, - MG_MAX_PATH_ELEMENT_COUNT = 2<<20, - MG_MAX_PRIMITIVE_COUNT = 8<<10 -}; - -typedef struct mg_font_data -{ - list_elt freeListElt; - u32 generation; - - u32 rangeCount; - u32 glyphCount; - u32 outlineCount; - mg_glyph_map_entry* glyphMap; - mg_glyph_data* glyphs; - mg_path_elt* outlines; - - f32 unitsPerEm; - mg_font_extents extents; - -} mg_font_data; - typedef struct mg_vertex_layout { u32 maxVertexCount;