Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text mesh refactoring #94

Merged
merged 10 commits into from
Oct 17, 2023
2 changes: 1 addition & 1 deletion dependencies/Common
2 changes: 1 addition & 1 deletion dependencies/HPML
Submodule HPML updated 1 files
+8 −10 include/hpml/defines.h
7 changes: 4 additions & 3 deletions include/renderer/bitmap_glyph_atlas_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ RENDERER_API void bitmap_glyph_atlas_texture_release_resources(bitmap_glyph_atla
RENDERER_API bitmap_glyph_pool_t* bitmap_glyph_atlas_texture_get_pool(bitmap_glyph_atlas_texture_t* texture);
/* returns the font used by this BGA texture */
RENDERER_API font_t* bitmap_glyph_atlas_texture_get_font(bitmap_glyph_atlas_texture_t* texture);
/* flushes the host side font bitmap to the GPU side memory (it might also destroy and create VkDeviceMemory)
/* flushes the host side font bitmap to the GPU side memory (it might also destroy and create VkDeviceMemory)
* is_resized: true if internal GPU and host memory has been resized
* returns: true if internal API objects recreated or GPU side memory has been updated */
RENDERER_API bool bitmap_glyph_atlas_texture_commit(bitmap_glyph_atlas_texture_t* texture, bool OUT is_resized);
/* quality: quality of the rasterized glyph, ranges from 0 to 255 inclusive
/* quality: quality of the rasterized glyph, ranges from 0 to 255 inclusive
* unicode: glyph's unicode value to rasterize
* texcoords: the texture coordinates (list of 4 vec2(s)), filled by this function if the glyph has graphical representation
* returns: true if the glyph has graphical representation and there are no errors */
RENDERER_API bool bitmap_glyph_atlas_texture_get_texcoord(bitmap_glyph_atlas_texture_t* texture, utf32_t unicode, glyph_texcoord_t OUT texcoord);
RENDERER_API bool bitmap_glyph_atlas_texture_get_texcoord(bitmap_glyph_atlas_texture_t* texture, pair_t(utf32_t, u32) unicode, glyph_texcoord_t OUT texcoord);
#ifdef GLOBAL_DEBUG
RENDERER_API void bitmap_glyph_atlas_texture_dump(bitmap_glyph_atlas_texture_t* texture, const char* file_path);
RENDERER_API void bitmap_glyph_atlas_texture_dump_bb(bitmap_glyph_atlas_texture_t* texture, const char* file_path);
#endif /* GLOBAL_DEBUG */
END_CPP_COMPATIBLE
8 changes: 4 additions & 4 deletions include/renderer/bitmap_glyph_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ static INLINE_IF_RELEASE_MODE void bitmap_glyph_pool_clear(bitmap_glyph_pool_t*
/* returns the font used by this bitmap glyph pool */
static INLINE_IF_RELEASE_MODE font_t* bitmap_glyph_pool_get_font(bitmap_glyph_pool_t* pool) { return pool->font; }
/* returns true if the glyph has graphical representation and no errors,
* outputs the texture coordinates of the glyph represented by the unicode encoding 'unicode' */
RENDERER_API bool bitmap_glyph_pool_get_texcoord(bitmap_glyph_pool_t* pool, utf32_t unicode, glyph_texcoord_t OUT texcoord, bool OUT is_resized);
/* returns true if this pool has a rasterized graphical representation of a glyph represented by unicode encoding 'unicode'*/
RENDERER_API bool bitmap_glyph_pool_contains_texcoord(bitmap_glyph_pool_t* pool, utf32_t unicode);
* outputs the texture coordinates of the glyph represented by the unicode encoding 'unicode' and with point size 'point_size' */
RENDERER_API bool bitmap_glyph_pool_get_texcoord(bitmap_glyph_pool_t* pool, pair_t(utf32_t, u32) unicode, glyph_texcoord_t OUT texcoord, bool OUT is_resized);
/* returns true if this pool has a rasterized graphical representation of a glyph represented by unicode encoding 'unicode' and with point size 'point_size' */
RENDERER_API bool bitmap_glyph_pool_contains_texcoord(bitmap_glyph_pool_t* pool, pair_t(utf32_t, u32) unicode);

#ifdef GLOBAL_DEBUG
/* creates a file and dumps the colors values in the bitmap to the file (.bmp) */
Expand Down
13 changes: 12 additions & 1 deletion include/renderer/bitmap_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
typedef vulkan_bitmap_text_t bitmap_text_t;
typedef vulkan_bitmap_text_string_handle_t bitmap_text_string_handle_t;
typedef vulkan_bitmap_glyph_atlas_texture_t bitmap_glyph_atlas_texture_t;
typedef vulkan_material_t material_t;
#elif defined(RENDERER_OPENGL_DRIVER)
#include <renderer/internal/opengl/opengl_bitmap_text.h>
typedef opengl_bitmap_text_t bitmap_text_t;
typedef opengl_bitmap_text_string_handle_t bitmap_text_string_handle_t;
typedef opengl_bitmap_glyph_atlas_texture_t bitmap_glyph_atlas_texture_t;
typedef opengl_material_t material_t;
#elif defined(RENDERER_DIRECTX_DRIVER)
#include <renderer/internal/directx/directx_bitmap_text.h>
typedef directx_bitmap_text_t bitmap_text_t;
typedef directx_bitmap_text_string_handle_t bitmap_text_string_handle_t;
typedef directx_bitmap_glyph_atlas_texture_t bitmap_glyph_atlas_texture_t;
typedef directx_material_t material_t;
#elif defined(RENDERER_METAL_DRIVER)
#include <renderer/internal/metal/metal_bitmap_text.h>
typedef metal_bitmap_text_t bitmap_text_t;
typedef metal_bitmap_text_string_handle_t bitmap_text_string_handle_t;
typedef metal_bitmap_glyph_atlas_texture_t bitmap_glyph_atlas_texture_t;
typedef metal_material_t material_t;
#endif

#include <renderer/rect.h> // rect2d_t and rect3d_t
Expand All @@ -48,17 +52,24 @@ RENDERER_API void bitmap_text_create_no_alloc(renderer_t* renderer, bitmap_glyph
RENDERER_API void bitmap_text_destroy(bitmap_text_t* text);
RENDERER_API void bitmap_text_release_resources(bitmap_text_t* text);

RENDERER_API void bitmap_text_draw(bitmap_text_t* text);

RENDERER_API bitmap_text_string_handle_t bitmap_text_string_create(bitmap_text_t* text);
RENDERER_API void bitmap_text_string_destroyH(bitmap_text_t* text, bitmap_text_string_handle_t handle);

/* setters */
RENDERER_API void bitmap_text_set_point_size(bitmap_text_t* text, u32 point_size);
RENDERER_API void bitmap_text_set_material(bitmap_text_t* text, material_t* material);
RENDERER_API void bitmap_text_set_render_space_type(bitmap_text_t* text, bitmap_text_render_space_type_t space_type);
RENDERER_API void bitmap_text_set_render_surface_type(bitmap_text_t* text, bitmap_text_render_surface_type_t surface_type);
RENDERER_API void bitmap_text_string_setH(bitmap_text_t* text, bitmap_text_string_handle_t handle, const char* string);
RENDERER_API void bitmap_text_string_set_point_sizeH(bitmap_text_t* text, bitmap_text_string_handle_t handle, u32 point_size);
RENDERER_API void bitmap_text_string_set_transformH(bitmap_text_t* text, bitmap_text_string_handle_t handle, mat4_t transform);

/* setters */
/* getters */
RENDERER_API u32 bitmap_text_get_point_size(bitmap_text_t* text);
RENDERER_API const char* bitmap_text_string_getH(bitmap_text_t* text, bitmap_text_string_handle_t handle);
RENDERER_API u32 bitmap_text_string_get_point_sizeH(bitmap_text_t* text, bitmap_text_string_handle_t handle);
RENDERER_API mat4_t bitmap_text_string_get_transformH(bitmap_text_t* text, bitmap_text_string_handle_t handle);

END_CPP_COMPATIBLE
19 changes: 18 additions & 1 deletion include/renderer/buffer2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,17 @@ typedef hash_table_t filled_rect_info_table_t;
/* list of rect2d_info_t objects which can be looked up in constant time */
typedef hash_table_t vacant_rect_info_table_t;

typedef void (*packed_rect_relocate_callback_t)(const rect2d_info_t* before, const rect2d_info_t* after, void* user_data);

typedef struct buffer2d_t
{
memory_allocator_t* allocator;

#if DBG_ENABLED(BUFFER2D_RESIZE)
packed_rect_relocate_callback_t packed_rect_relocate_callback;
void* packed_rect_relocate_callback_handler_user_data;
#endif /* DBG_BUFFER2D_RESIZE */

/* linear buffer */
buffer_t* buffer;
/* 2d view of the linear buffer */
Expand All @@ -93,6 +101,7 @@ typedef struct buffer2d_t
u32 counter;
} buffer2d_t;

typedef buffer2d_t* buffer2d_ptr_t;

BEGIN_CPP_COMPATIBLE

Expand All @@ -112,7 +121,7 @@ RENDERER_API void buffer2d_get_rect_data(buffer2d_t* buffer, filled_rect_info_t*
#ifdef GLOBAL_DEBUG
RENDERER_API bool buffer2d_push_debug(buffer2d_t* buffer, void* key, void* value, u32 width, u32 height);
#endif /* GLOBAL_DEBUG */
/* creates a buffer2d element and adds a value with a key and size (width, height)
/* creates a buffer2d element and adds a value with a key and size (width, height)
* returns true if the size has been resized, otherwise false */
RENDERER_API bool buffer2d_push(buffer2d_t* buffer, void* key, void* value, u32 width, u32 height PARAM_IF_DEBUG(icolor3_t color));
/* creates a buffer2d element and broadcasts a value of size 'size' to the entire rect with a key
Expand All @@ -129,4 +138,12 @@ RENDERER_API f32 buffer2d_get_packing_efficiency(buffer2d_t* buffer);
RENDERER_API void buffer2d_dump(buffer2d_t* buffer, const char* file_name);
#endif /* GLOBAL_DEBUG */

#if DBG_ENABLED(BUFFER2D_RESIZE)
static INLINE_IF_RELEASE_MODE void buffer2d_set_packed_rect_relocate_callback_handler(buffer2d_t* buffer, packed_rect_relocate_callback_t handler, void* user_data)
{
buffer->packed_rect_relocate_callback = handler;
buffer->packed_rect_relocate_callback_handler_user_data = user_data;
}
#endif /* DBG_BUFFER_RESIZE */

END_CPP_COMPATIBLE
2 changes: 2 additions & 0 deletions include/renderer/buffer2d_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ typedef struct buffer2d_view_t
iextent2d_t size;
} buffer2d_view_t;

typedef buffer2d_view_t* buffer2d_view_ptr_t;

#define BUFFER2D_VIEW(ptr) DYNAMIC_CAST(buffer2d_view_t*, ptr)


Expand Down
44 changes: 44 additions & 0 deletions include/renderer/debug_switches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

/* switches */
#define ENABLE_DBG_VULKAN_BITMAP_TEXT_STRING_SETH 0
#define ENABLE_DBG_BUFFER2D_RESIZE 1
#define ENABLE_DBG_EVENT_PUBLISH 0

#define DBG_ENABLED(x) (ENABLE_DBG_##x == 1)

#if defined(GLOBAL_DEBUG)
# if DBG_ENABLED(VULKAN_BITMAP_TEXT_STRING_SETH)
# define DBG_VULKAN_BITMAP_TEXT_STRING_SETH(x) x
# define DBG_ARG_VULKAN_BITMAP_TEXT_STRING_SETH(x) , x
# define NOT_DBG_VULKAN_BITMAP_TEXT_STRING_SETH(x) /* nothing */
# define NOT_DBG_ARG_VULKAN_BITMAP_TEXT_STRING_SETH(x) /* nothing */
# else
# define DBG_VULKAN_BITMAP_TEXT_STRING_SETH(x) /* nothing */
# define DBG_ARG_VULKAN_BITMAP_TEXT_STRING_SETH(x) /* nothing */
# define NOT_DBG_VULKAN_BITMAP_TEXT_STRING_SETH(x) x
# define NOT_DBG_ARG_VULKAN_BITMAP_TEXT_STRING_SETH(x) , x
# endif /* ENABLE_DBG_VULKAN_BITMAP_TEXT_STRING_SETH */
# if DBG_ENABLED(BUFFER2D_RESIZE)
# define DBG_BUFFER2D_RESIZE(x) x
# define DBG_ARG_BUFFER2D_RESIZE(x) , x
# define NOT_DBG_BUFFER2D_RESIZE(x) /* nothing */
# define NOT_DBG_ARG_BUFFER2D_RESIZE(x) /* nothing */
# else
# define DBG_BUFFER2D_RESIZE(x) /* nothing */
# define DBG_ARG_BUFFER2D_RESIZE(x) /* nothing */
# define NOT_DBG_BUFFER2D_RESIZE(x) x
# define NOT_DBG_ARG_BUFFER2D_RESIZE(x) , x
# endif /* ENABLE_DBG_BUFFER2D_RESIZE */
# if DBG_ENABLED(EVENT_PUBLISH)
# define DBG_EVENT_PUBLISH(x) x
# define DBG_ARG_EVENT_PUBLISH(x) , x
# define NOT_DBG_EVENT_PUBLISH(x)
# define NOT_DBG_ARG_EVENT_PUBLISH(x)
# else
# define DBG_EVENT_PUBLISH(x)
# define DBG_ARG_EVENT_PUBLISH(x)
# define NOT_DBG_EVENT_PUBLISH(x) x
# define NOT_DBG_ARG_EVENT_PUBLISH(x) , x
# endif
#endif /* GLOBAL_DEBUG */
29 changes: 23 additions & 6 deletions include/renderer/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#pragma once

#include <common/defines.h>
#if GLOBAL_DEBUG
# include <renderer/debug_switches.h>
#endif

#define INTERNAL

Expand Down Expand Up @@ -110,17 +113,31 @@ static INLINE_IF_RELEASE_MODE u32 min(u32 v1, u32 v2) { return (v1 < v2) ? v1 :

#define DYNAMIC_CAST(target_type, ptr) CAST_TO(target_type, ptr)

#define typedef_pair_t(T1, T2) struct __pair_##T1_##T2_t { T1 first; T2 second; }
#define pair_t(T1, T2) struct __pair_##T1_##T2_t
#define typedef_pair_t(T1, T2) struct __pair_##T1##_##T2##_t { T1 first; T2 second; }
#define pair_t(T1, T2) struct __pair_##T1##_##T2##_t
#define make_pair(T1, T2) (pair_t(T1, T2))

#define typedef_tuple2_t(T1, T2) struct __tuple_##T1_##T2_t { T1 first; T2 second; }
#define tuple2_t(T1, T2) struct __tuple_##T1_##T2_t
#define typedef_tuple2_t(T1, T2) struct __tuple_##T1##_##T2##_t { T1 first; T2 second; }
#define tuple2_t(T1, T2) struct __tuple_##T1##_##T2##_t
#define make_tuple2(T1, T2) (tuple2_t(T1, T2))

#define typedef_tuple3_t(T1, T2, T3) struct __tuple_##T1_##T2_##T3_t { T1 first; T2 second; T3 third; }
#define tuple3_t(T1, T2, T3) struct __tuple_##T1_##T2_##T3_t
#define typedef_tuple3_t(T1, T2, T3) struct __tuple_##T1##_##T2##_##T3##_t { T1 first; T2 second; T3 third; }
#define tuple3_t(T1, T2, T3) struct __tuple_##T1##_##T2##_##T3##_t
#define make_tuple3(T1, T2, T3) (tuple3_t(T1, T2))

#define SIZEOF_ARRAY(array) (sizeof(array) / sizeof((array)[0]))
#define DREF_VOID_PTR(ptr) CAST_TO(void*, DREF_TO(u8*, (void**)(ptr)))

#define U32_TO_U64(src) _u32_to_u64(sizeof(src), src)
static INLINE_IF_RELEASE_MODE u64 _u32_to_u64(u32 src_size, u32 src)
{
IF_DEBUG_MODE(_debug_assert__(src_size == sizeof(u32)));
return CAST_TO(u64, src);
}

#define U64_TO_U32(src) _u64_to_u32(sizeof(src), src)
static INLINE_IF_RELEASE_MODE u32 _u64_to_u32(u32 src_size, u64 src)
{
IF_DEBUG_MODE(_debug_assert__(src_size == sizeof(u64)));
return CAST_TO(u32, src);
}
18 changes: 10 additions & 8 deletions include/renderer/event.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
***This is computer generated notice - Do not modify it***

VulkanRenderer (inclusive of its dependencies and subprojects
such as toolchains written by the same author) is a software to render
VulkanRenderer (inclusive of its dependencies and subprojects
such as toolchains written by the same author) is a software to render
2D & 3D geometries by writing C/C++ code and shaders.

File: event.h is a part of VulkanRenderer
Expand All @@ -20,7 +20,7 @@
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once
Expand Down Expand Up @@ -59,7 +59,7 @@ typedef enum signal_bits_t
SIGNAL_ALL_BIT = BIT32(SIGNAL_ALL)
} signal_bits_t;

/* publisher_data: pointer to the data owned by the publisher of the event
/* publisher_data: pointer to the data owned by the publisher of the event
* handler_data: pointer to the same data during the event subscription */
typedef void (*__event_handler_t)(void* publisher_data, void* handler_data);

Expand Down Expand Up @@ -111,12 +111,14 @@ typedef struct event_t
memory_allocator_t* allocator;
/* pointer to the string builder (created internally) */
string_builder_t* string_builder;
/* pointer to the data of the publisher (which calls event_publish()),
/* name of the event_t */
IF_DEBUG( char name[256]; )
/* pointer to the data of the publisher (which calls event_publish()),
* passed as the first parameter in each handler invocation */
void* publisher_data;
/* pointer to the signal table (list of u32 of size SIGNAL_ALL), (created internally) */
u32* signal_table;;
/* pointer to the temporary signal table (list of u32 of size SIGNAL_ALL), (created internally)
/* pointer to the temporary signal table (list of u32 of size SIGNAL_ALL), (created internally)
* it is used during the call to event_publish() to execute the invocations in ordered manner based
* on the waiting and signalling signals. */
u32* stage_signal_table;
Expand All @@ -142,8 +144,8 @@ BEGIN_CPP_COMPATIBLE

/* constructors and destructors */
RENDERER_API event_t* event_new(memory_allocator_t* allocator);
RENDERER_API event_t* event_create(memory_allocator_t* allocator, void* publisher_data);
RENDERER_API void event_create_no_alloc(memory_allocator_t* allocator, void* publisher_data, event_t OUT event);
RENDERER_API event_t* event_create(memory_allocator_t* allocator, void* publisher_data PARAM_IF_DEBUG(const char* name));
RENDERER_API void event_create_no_alloc(memory_allocator_t* allocator, void* publisher_data PARAM_IF_DEBUG(const char* name), event_t OUT event);
RENDERER_API void event_destroy(event_t* event);
RENDERER_API void event_release_resources(event_t* event);

Expand Down
66 changes: 0 additions & 66 deletions include/renderer/event_system.h

This file was deleted.

Loading