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

Bitmap Text World Space and Screen Space Test #93

Merged
merged 14 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,562 changes: 1,562 additions & 0 deletions gdb/.gdbhistory

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gdb/.gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ source ./gdb/vulkan_render_pass_description.py
source ./gdb/vulkan_attachment_type.py
source ./gdb/VkPipelineStageFlags.py
source ./gdb/VkAccessFlags.py
source ./gdb/glsl_glyph_render_data.py
23 changes: 23 additions & 0 deletions gdb/glsl_glyph_render_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import gdb

class GLSLGlyphRenderData:

def __init__(self, val):
self.val = val

def to_string(self):
output = PrintOpenBrace()
output += PrintValue(self, 'ofst')
output += PrintValue(self, 'indx')
output += PrintValue(self, 'rotn')
output += PrintValue(self, 'stid')
output += PrintValue(self, 'scal')
output += PrintCloseBrace()
return output

def GLSLGlyphRenderDataPrintHandler(val):
if str(val.type) == 'glsl_glyph_render_data_t': return GLSLGlyphRenderData(val)


gdb.pretty_printers.append(GLSLGlyphRenderDataPrintHandler)
22 changes: 15 additions & 7 deletions include/renderer/bitmap_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@
typedef metal_bitmap_glyph_atlas_texture_t bitmap_glyph_atlas_texture_t;
#endif

#include <renderer/rect.h> // rect2d_t
#include <renderer/rect.h> // rect2d_t and rect3d_t
#include <hpml/mat4.h> // mat4_t
#include <hpml/vec3.h> // vec3_t

typedef enum bitmap_text_render_space_type_t
{
BITMAP_TEXT_RENDER_SPACE_TYPE_2D,
BITMAP_TEXT_RENDER_SPACE_TYPE_3D
} bitmap_text_render_space_type_t;

typedef enum bitmap_text_render_surface_type_t
{
BITMAP_TEXT_RENDER_SURFACE_TYPE_CAMERA,
BITMAP_TEXT_RENDER_SURFACE_TYPE_SCREEN
} bitmap_text_render_surface_type_t;

BEGIN_CPP_COMPATIBLE

RENDERER_API bitmap_text_t* bitmap_text_new(memory_allocator_t* allocator);
Expand All @@ -40,17 +52,13 @@ RENDERER_API bitmap_text_string_handle_t bitmap_text_string_create(bitmap_text_t
RENDERER_API void bitmap_text_string_destroyH(bitmap_text_t* text, bitmap_text_string_handle_t handle);

/* setters */
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_scaleH(bitmap_text_t* text, bitmap_text_string_handle_t handle, vec3_t scale);
RENDERER_API void bitmap_text_string_set_positionH(bitmap_text_t* text, bitmap_text_string_handle_t handle, vec3_t position);
RENDERER_API void bitmap_text_string_set_rotationH(bitmap_text_t* text, bitmap_text_string_handle_t handle, vec3_t rotation);
RENDERER_API void bitmap_text_string_set_transformH(bitmap_text_t* text, bitmap_text_string_handle_t handle, mat4_t transform);

/* setters */
RENDERER_API const char* bitmap_text_string_getH(bitmap_text_t* text, bitmap_text_string_handle_t handle);
RENDERER_API vec3_t bitmap_text_string_get_scaleH(bitmap_text_t* text, bitmap_text_string_handle_t handle);
RENDERER_API vec3_t bitmap_text_string_get_positionH(bitmap_text_t* text, bitmap_text_string_handle_t handle);
RENDERER_API vec3_t bitmap_text_string_get_rotationH(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
8 changes: 4 additions & 4 deletions include/renderer/defines.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: defines.h is a part of VulkanRenderer
Expand All @@ -20,10 +20,10 @@
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

#include <common/defines.h>
Expand Down
9 changes: 9 additions & 0 deletions include/renderer/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ RENDERER_API void font_get_glyph_info(font_t* font, utf32_t unicode, font_glyph_
/* fills 'info' with information of the glyph only but calls font_load_glyph internally if required (be careful) */
RENDERER_API void font_get_glyph_info2(font_t* font, utf32_t unicode, font_glyph_info_t OUT info);

/* returns the ascender of the face (the ascender of the glyph having heighest value in the face) */
RENDERER_API f32 font_get_ascender(font_t* font);

/* returns the units (in point size) per EM */
RENDERER_API f32 font_get_units_per_em(font_t* font);

/* returns the point size of the characters in the font */
static INLINE_IF_RELEASE_MODE f32 font_get_char_size(font_t* font) { return font->point_size; }

static INLINE_IF_RELEASE_MODE f32 get_inches_from_point_size(u32 point_size)
{
/* 72 points make 1 inch */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ static INLINE_IF_RELEASE_MODE font_t* vulkan_bitmap_glyph_atlas_texture_get_font
{
return bitmap_glyph_pool_get_font(&texture->pool);
}
/* 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)
* returns true if either the internal buffers, images and image views has been updated or recreated */
RENDERER_API bool vulkan_bitmap_glyph_atlas_texture_commit(vulkan_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 */
Expand Down
45 changes: 32 additions & 13 deletions include/renderer/internal/vulkan/vulkan_bitmap_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@
#include <renderer/internal/vulkan/vulkan_instance_buffer.h>
#include <renderer/internal/vulkan/vulkan_mesh.h>
#include <renderer/dictionary.h>
#include <renderer/types.h>
#include <renderer/event.h> // event_subscription_handle_t
#include <renderer/rect.h> // rect2d_t
#include <hpml/mat4.h> // mat4_t
#include <hpml/vec3.h> // vec3_t
#include <glslcommon/glsl_types.h>

typedef enum vulkan_bitmap_text_render_space_type_t
{
/* selects the 'screen projection matrix' from the camera's projection matrices */
VULKAN_BITMAP_TEXT_RENDER_SPACE_TYPE_2D,
/* selects the 'orthographic/perspective matrix' from the camera's projection matrices */
VULKAN_BITMAP_TEXT_RENDER_SPACE_TYPE_3D
} vulkan_bitmap_text_render_space_type_t;

typedef enum vulkan_bitmap_text_render_surface_type_t
{
/* the text will be rendered on to the camera's view */
VULKAN_BITMAP_TEXT_RENDER_SURFACE_TYPE_CAMERA,
/* the text will be rendered on to the screen (i.e. will not be affected by the any camera's transformations or projections) */
VULKAN_BITMAP_TEXT_RENDER_SURFACE_TYPE_SCREEN
} vulkan_bitmap_text_render_surface_type_t;

/* element of Glyph Texture Coordinate (GTC) buffer */
typedef struct glsl_glyph_texcoord_t
Expand Down Expand Up @@ -43,7 +59,7 @@ typedef struct glsl_glyph_render_data_t
/* index of the string's transform to which this glyph instance belongs into the String Transform Buffer (ST Buffer) */
/* per_instance [BTM_TXT_STID_BND, BTM_TXT_STID_LOC, BTM_TXT_STID_COMP] in uint stid; */
glsl_uint_t stid;
/* scale of this glyph instance
/* scale of this glyph instance
* per_instance [BTM_TXT_SCAL_BND, BTM_TXT_SCAL_LOC, BTM_TXT_SCAL_COMP] in vec3 scal; */
glsl_vec3_t scal;
} glsl_glyph_render_data_t ALIGN_AS(GLSL_TYPE_VEC4_ALIGN);
Expand All @@ -62,6 +78,8 @@ typedef struct vulkan_bitmap_text_string_t
{
/* handle to the next free string if this string is in the free list or inuse string if this is in the inuse list */
vulkan_bitmap_text_string_handle_t next;
/* handle to this string */
vulkan_bitmap_text_string_handle_t handle;
sub_buffer_handle_t render_data_handle;
/* string */
char_buffer_t chars;
Expand All @@ -70,8 +88,6 @@ typedef struct vulkan_bitmap_text_string_t
struct { offset3d_t offset; extent2d_t extent; } rect;
/* transform matrix applied to this string */
mat4_t transform;
/* id assigned to this string */
u32 index;
} vulkan_bitmap_text_string_t;

typedef struct vulkan_bitmap_glyph_atlas_texture_t vulkan_bitmap_glyph_atlas_texture_t;
Expand All @@ -96,11 +112,18 @@ typedef dictionary_t glyph_texcoord_index_table_t;

typedef struct vulkan_material_t vulkan_material_t;

typedef struct font_t font_t;

typedef struct vulkan_bitmap_text_t
{
vulkan_renderer_t* renderer;
vulkan_material_t* material;

/* render space type of this text */
vulkan_bitmap_text_render_space_type_t render_space_type;
/* render surface type of this text */
vulkan_bitmap_text_render_surface_type_t render_surface_type;

/* CPU side */

/* strings derived from this bitmap text */
Expand All @@ -112,8 +135,8 @@ typedef struct vulkan_bitmap_text_t

/* GPU side */

union
{
union
{
vulkan_bitmap_glyph_atlas_texture_t* glyph_atlas_texture;
vulkan_bitmap_glyph_atlas_texture_t* texture;
};
Expand Down Expand Up @@ -151,18 +174,14 @@ RENDERER_API vulkan_bitmap_text_string_handle_t vulkan_bitmap_text_string_create
RENDERER_API void vulkan_bitmap_text_string_destroyH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle);

/* setters */
RENDERER_API void vulkan_bitmap_text_set_render_space_type(vulkan_bitmap_text_t* text, vulkan_bitmap_text_render_space_type_t space_type);
RENDERER_API void vulkan_bitmap_text_set_render_surface_type(vulkan_bitmap_text_t* text, vulkan_bitmap_text_render_surface_type_t surface_type);
RENDERER_API void vulkan_bitmap_text_string_setH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle, const char* string);
RENDERER_API void vulkan_bitmap_text_string_set_scaleH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle, vec3_t scale);
RENDERER_API void vulkan_bitmap_text_string_set_positionH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle, vec3_t position);
RENDERER_API void vulkan_bitmap_text_string_set_rotationH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle, vec3_t rotation);
RENDERER_API void vulkan_bitmap_text_string_set_transformH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle, mat4_t transform);

/* setters */
/* getters */
RENDERER_API const char* vulkan_bitmap_text_string_getH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle);
RENDERER_API vec3_t vulkan_bitmap_text_string_get_scaleH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle);
RENDERER_API vec3_t vulkan_bitmap_text_string_get_positionH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle);
RENDERER_API vec3_t vulkan_bitmap_text_string_get_rotationH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle);
RENDERER_API mat4_t vulkan_bitmap_text_string_get_transformH(vulkan_bitmap_text_t* text, vulkan_bitmap_text_string_handle_t handle);

RENDERER_API font_t* vulkan_bitmap_text_get_font(vulkan_bitmap_text_t* text);

END_CPP_COMPATIBLE
6 changes: 6 additions & 0 deletions include/renderer/internal/vulkan/vulkan_descriptor_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ enum
// bindings for GLOBAL_SET
VULKAN_DESCRIPTOR_BINDING_CAMERA = 0,
VULKAN_DESCRIPTOR_BINDING_LIGHT = 1,
/* holds information related to the screen such as:
* 1. display resolution (width x height, in pixels)
* 2. display dpi (horizontal_dpi x vertical_dpi, in pixels / inch)
* 3. window size (width x height, in pixels)
* 4. screen_matrix */
VULKAN_DESCRIPTOR_BINDING_SCREEN = 2,

// bindings for SUB_RENDER_SET
VULKAN_DESCRIPTOR_BINDING_INPUT_ATTACHMENT0 = 0,
Expand Down
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: vulkan_graphics_pipeline_description.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/>.
*/


Expand Down Expand Up @@ -66,6 +66,7 @@ typedef struct vulkan_graphics_pipeline_description_t

} vulkan_graphics_pipeline_description_t;

#define VULKAN_GRAPHICS_PIPELINE_DESCRIPTION(ptr) CAST_TO(vulkan_graphics_pipeline_description_t*, ptr)

RENDERER_API void vulkan_graphics_pipeline_description_begin(vulkan_renderer_t* renderer, vulkan_graphics_pipeline_description_t* description);
RENDERER_API void vulkan_graphics_pipeline_description_add_color_blend_state(vulkan_graphics_pipeline_description_t* description, VkBool32 blendEnable);
Expand All @@ -74,6 +75,13 @@ RENDERER_API void vulkan_graphics_pipeline_description_set_depth_bias(vulkan_gra
RENDERER_API void vulkan_graphics_pipeline_description_add_shader(vulkan_graphics_pipeline_description_t* description, const char* file_path, vulkan_shader_type_t type);
RENDERER_API void vulkan_graphics_pipeline_description_end(vulkan_renderer_t* renderer, vulkan_graphics_pipeline_description_t* description);

RENDERER_API VkPipelineRasterizationStateCreateInfo* vulkan_graphics_pipeline_description_get_rasterization(vulkan_graphics_pipeline_description_t* description);

static VkPipelineRasterizationStateCreateInfo* get_rasterization(BUFFER* list)
{
return vulkan_graphics_pipeline_description_get_rasterization(VULKAN_GRAPHICS_PIPELINE_DESCRIPTION(buf_peek_ptr(list)));
}

static void begin_pipeline(vulkan_renderer_t* renderer, BUFFER* list)
{
vulkan_graphics_pipeline_description_begin(renderer, buf_create_element(list));
Expand Down
30 changes: 28 additions & 2 deletions include/renderer/render_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,41 @@
#include <bufferlib/buffer.h>
#include <renderer/event.h>
#include <renderer/type_system.h>
#include <renderer/struct_descriptor.h>

static const type_t TYPE_ID(render_window_t) = TYPE_ID_CREATE(1);

typedef struct render_window_t
{
memory_allocator_t* allocator;

/* handle to the internal GLFWwindow object */
void* handle;
// BUFFER* resize_event;

/* pointer to API specific GPU buffer object */
void* api_buffer;
/* pointer to the memory mapped GPU buffer data of the above object */
void* api_buffer_data_ptr;

/* global_set::screen_info
* {
* uvec2 resolution; // resolution of the display (in pixels)
* uvec2 dpi; // dpi of the display (in pixels per inch)
* uvec2 size; // window size (in pixels)
* mat4 matrix; // matrix to project onto the window/screen
* } */
struct_descriptor_t screen_info_struct;
struct_field_handle_t resolution_field;
struct_field_handle_t dpi_field;
struct_field_handle_t size_field;
struct_field_handle_t matrix_field;

/* width of the window (in pixels) */
u32 width;
/* height of the window (in pixels) */
u32 height;
// void* user_data;

/* event triggered whenever the window resizes */
event_t* on_resize_event;
} render_window_t;

Expand All @@ -51,6 +75,8 @@ RENDERER_API bool render_window_should_close(render_window_t* window);
RENDERER_API void render_window_poll_events(render_window_t* window);
RENDERER_API void render_window_destroy(render_window_t* window);

RENDERER_API void render_window_initialize_api_buffer(render_window_t* window, void* driver);

// getters
RENDERER_API void render_window_get_framebuffer_extent(render_window_t* window, u32* out_width, u32* out_height);

Expand Down
1 change: 1 addition & 0 deletions include/renderer/struct_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ RENDERER_API void struct_descriptor_add_field_array(struct_descriptor_t* descrip
RENDERER_API void struct_descriptor_add_field_array2(struct_descriptor_t* descriptor, const char* name, struct_descriptor_t* record, u32 array_size);

RENDERER_API void struct_descriptor_map(struct_descriptor_t* descriptor, void* ptr);
RENDERER_API void* struct_descriptor_get_mapped(struct_descriptor_t* descriptor);
RENDERER_API void struct_descriptor_unmap(struct_descriptor_t* descriptor);
RENDERER_API void struct_descriptor_recalculate(struct_descriptor_t* descriptor);
RENDERER_API u32 struct_descriptor_sizeof(struct_descriptor_t* descriptor);
Expand Down
11 changes: 11 additions & 0 deletions include/renderer/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

typedef enum text_render_space_type_t
{
/* selects the 'screen projection matrix' from the camera's projection matrices */
TEXT_RENDER_SPACE_TYPE_2D,
/* selects the 'orthographic/perspective matrix' from the camera's projection matrices */
TEXT_RENDER_SPACE_TYPE_3D
} text_render_space_type_t;


Loading