2023-02-01 15:23:51 +00:00
|
|
|
/************************************************************//**
|
|
|
|
*
|
|
|
|
* @file: graphics_internal.h
|
|
|
|
* @author: Martin Fouilleul
|
|
|
|
* @date: 23/01/2023
|
|
|
|
* @revision:
|
|
|
|
*
|
|
|
|
*****************************************************************/
|
|
|
|
#ifndef __GRAPHICS_INTERNAL_H_
|
|
|
|
#define __GRAPHICS_INTERNAL_H_
|
|
|
|
|
|
|
|
#include"graphics.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2023-02-20 15:49:44 +00:00
|
|
|
//---------------------------------------------------------------
|
|
|
|
// surface data
|
|
|
|
//---------------------------------------------------------------
|
2023-02-01 15:23:51 +00:00
|
|
|
typedef struct mg_surface_data mg_surface_data;
|
|
|
|
|
|
|
|
typedef void (*mg_surface_destroy_proc)(mg_surface_data* surface);
|
|
|
|
typedef void (*mg_surface_prepare_proc)(mg_surface_data* surface);
|
|
|
|
typedef void (*mg_surface_present_proc)(mg_surface_data* surface);
|
2023-02-08 10:49:00 +00:00
|
|
|
typedef void (*mg_surface_swap_interval_proc)(mg_surface_data* surface, int swap);
|
2023-02-08 17:22:54 +00:00
|
|
|
typedef vec2 (*mg_surface_contents_scaling_proc)(mg_surface_data* surface);
|
2023-02-01 15:23:51 +00:00
|
|
|
typedef mp_rect (*mg_surface_get_frame_proc)(mg_surface_data* surface);
|
|
|
|
typedef void (*mg_surface_set_frame_proc)(mg_surface_data* surface, mp_rect frame);
|
|
|
|
typedef bool (*mg_surface_get_hidden_proc)(mg_surface_data* surface);
|
|
|
|
typedef void (*mg_surface_set_hidden_proc)(mg_surface_data* surface, bool hidden);
|
|
|
|
|
|
|
|
typedef struct mg_surface_data
|
|
|
|
{
|
|
|
|
mg_backend_id backend;
|
|
|
|
|
|
|
|
mg_surface_destroy_proc destroy;
|
|
|
|
mg_surface_prepare_proc prepare;
|
|
|
|
mg_surface_present_proc present;
|
2023-02-08 10:49:00 +00:00
|
|
|
mg_surface_swap_interval_proc swapInterval;
|
2023-02-08 17:22:54 +00:00
|
|
|
mg_surface_contents_scaling_proc contentsScaling;
|
2023-02-01 15:23:51 +00:00
|
|
|
mg_surface_get_frame_proc getFrame;
|
|
|
|
mg_surface_set_frame_proc setFrame;
|
|
|
|
mg_surface_get_hidden_proc getHidden;
|
|
|
|
mg_surface_set_hidden_proc setHidden;
|
|
|
|
|
|
|
|
} mg_surface_data;
|
|
|
|
|
|
|
|
mg_surface mg_surface_alloc_handle(mg_surface_data* surface);
|
|
|
|
mg_surface_data* mg_surface_data_from_handle(mg_surface handle);
|
|
|
|
|
|
|
|
//---------------------------------------------------------------
|
|
|
|
// graphics 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;
|
2023-02-25 11:59:49 +00:00
|
|
|
mp_rect srcRegion;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
|
|
|
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;
|
2023-02-25 13:20:07 +00:00
|
|
|
mg_mat2x3 transform;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
mg_path_descriptor path;
|
|
|
|
mp_rect rect;
|
|
|
|
mg_rounded_rect roundedRect;
|
|
|
|
utf32 codePoint;
|
|
|
|
u32 jump;
|
2023-02-25 13:20:07 +00:00
|
|
|
mg_mat2x3 matrix; //TODO remove when we use transform everywhere
|
2023-02-01 15:23:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} 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;
|
|
|
|
u32 generation;
|
2023-02-23 16:07:41 +00:00
|
|
|
vec2 size;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
|
|
|
} 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;
|
|
|
|
u32 maxIndexCount;
|
|
|
|
|
|
|
|
char* posBuffer;
|
|
|
|
u32 posStride;
|
|
|
|
|
|
|
|
char* cubicBuffer;
|
|
|
|
u32 cubicStride;
|
|
|
|
|
2023-02-24 17:50:46 +00:00
|
|
|
char* uvTransformBuffer;
|
|
|
|
u32 uvTransformStride;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
|
|
|
char* colorBuffer;
|
|
|
|
u32 colorStride;
|
|
|
|
|
2023-02-09 15:14:15 +00:00
|
|
|
char* shapeIndexBuffer;
|
|
|
|
u32 shapeIndexStride;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
|
|
|
char* clipBuffer;
|
|
|
|
u32 clipStride;
|
|
|
|
|
|
|
|
char* indexBuffer;
|
|
|
|
u32 indexStride;
|
|
|
|
|
|
|
|
} mg_vertex_layout;
|
|
|
|
|
|
|
|
typedef struct mg_canvas_backend mg_canvas_backend;
|
|
|
|
|
|
|
|
typedef void (*mg_canvas_backend_destroy_proc)(mg_canvas_backend* backend);
|
2023-02-02 17:57:57 +00:00
|
|
|
typedef void (*mg_canvas_backend_begin_proc)(mg_canvas_backend* backend);
|
|
|
|
typedef void (*mg_canvas_backend_end_proc)(mg_canvas_backend* backend);
|
|
|
|
typedef void (*mg_canvas_backend_clear_proc)(mg_canvas_backend* backend, mg_color clearColor);
|
2023-02-24 11:01:00 +00:00
|
|
|
typedef void (*mg_canvas_backend_draw_batch_proc)(mg_canvas_backend* backend, mg_image_data* imageData, u32 vertexCount, u32 shapeCount, u32 indexCount);
|
2023-02-23 16:07:41 +00:00
|
|
|
|
|
|
|
|
2023-02-01 15:23:51 +00:00
|
|
|
typedef void (*mg_canvas_backend_atlas_upload_proc)(mg_canvas_backend* backend, mp_rect rect, u8* bytes);
|
2023-02-23 16:07:41 +00:00
|
|
|
typedef mg_image_data* (*mg_canvas_backend_image_create_proc)(mg_canvas_backend* backend, vec2 size);
|
|
|
|
typedef void (*mg_canvas_backend_image_destroy_proc)(mg_canvas_backend* backend, mg_image_data* image);
|
|
|
|
typedef void (*mg_canvas_backend_image_upload_region_proc)(mg_canvas_backend* backend, mg_image_data* image, mp_rect region, u8* pixels);
|
2023-02-01 15:23:51 +00:00
|
|
|
|
|
|
|
typedef struct mg_canvas_backend
|
|
|
|
{
|
|
|
|
mg_vertex_layout vertexLayout;
|
|
|
|
|
|
|
|
mg_canvas_backend_destroy_proc destroy;
|
2023-02-02 17:57:57 +00:00
|
|
|
mg_canvas_backend_begin_proc begin;
|
|
|
|
mg_canvas_backend_end_proc end;
|
|
|
|
mg_canvas_backend_clear_proc clear;
|
|
|
|
mg_canvas_backend_draw_batch_proc drawBatch;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
2023-02-23 16:07:41 +00:00
|
|
|
mg_canvas_backend_image_create_proc imageCreate;
|
|
|
|
mg_canvas_backend_image_destroy_proc imageDestroy;
|
|
|
|
mg_canvas_backend_image_upload_region_proc imageUploadRegion;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
2023-02-23 16:07:41 +00:00
|
|
|
mg_canvas_backend_atlas_upload_proc atlasUpload;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
2023-02-23 16:07:41 +00:00
|
|
|
} mg_canvas_backend;
|
2023-02-01 15:23:51 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif //__GRAPHICS_INTERNAL_H_
|