diff --git a/text_editor/render.cpp b/text_editor/render.cpp index 4937440..148fb5f 100644 --- a/text_editor/render.cpp +++ b/text_editor/render.cpp @@ -30,7 +30,7 @@ constexpr inline int32_t int_26_6(int32_t n) return v; } -cursor_advance render_primary_buffer(ta_parameter_writer& parameter, +cursor_advance render_primary_buffer(ta_parameter_writer& writer, const font * font, const glyph * glyphs, const gap_buffer& gb, @@ -42,6 +42,9 @@ cursor_advance render_primary_buffer(ta_parameter_writer& parameter, int32_t h_advance = 0; int32_t v_advance = 0; + const float r_texture_width = 1.0f / font->texture_width; + const float r_texture_height = 1.0f / font->texture_height; + int32_t init_i = first_line >= 0 ? gb.line.offsets[first_line] + 1 : 0; for (int32_t i = init_i; i <= gb.size; i++) { if (i == gb.gap_start) { @@ -68,9 +71,9 @@ cursor_advance render_primary_buffer(ta_parameter_writer& parameter, auto& glyph = glyphs[ix]; if (x + int_26_6(glyph.metrics.horiAdvance) <= window.box.x1) { - transform_glyph(parameter, - font->texture_width, - font->texture_height, + transform_glyph(writer, + r_texture_width, + r_texture_height, glyph, x, y @@ -100,7 +103,7 @@ void render_cursor(ta_parameter_writer& parameter, float width = int_26_6(cursor.width); float height = int_26_6(cursor.height); - transform_sprite(parameter, + transform_cursor(parameter, x, // x y, // y width, @@ -114,6 +117,10 @@ void render(ta_parameter_writer& writer, const gap_buffer& gb, const viewport_window& window) { + glyph_begin(writer, + font->texture_width, + font->texture_height); + cursor_advance cursor = render_primary_buffer(writer, font, glyphs, gb, window); render_cursor(writer, cursor, window); diff --git a/text_editor/transform.cpp b/text_editor/transform.cpp index c36af0e..935f244 100644 --- a/text_editor/transform.cpp +++ b/text_editor/transform.cpp @@ -29,13 +29,43 @@ const struct vertex strip_vertices[4] = { }; constexpr uint32_t strip_length = (sizeof (strip_vertices)) / (sizeof (struct vertex)); -void transform_sprite(ta_parameter_writer& parameter, +static inline void transfer_quad_type_0(ta_parameter_writer& writer, + float ax, float ay, + float bx, float by, + float cx, float cy, + float dx, float dy, + float z) +{ + uint32_t base_color = 0xffffffff; + + writer.append() = + ta_vertex_parameter::polygon_type_0(polygon_vertex_parameter_control_word(false), + ax, ay, z, + base_color); + + writer.append() = + ta_vertex_parameter::polygon_type_0(polygon_vertex_parameter_control_word(false), + bx, by, z, + base_color); + + writer.append() = + ta_vertex_parameter::polygon_type_0(polygon_vertex_parameter_control_word(false), + dx, dy, z, + base_color); + + writer.append() = + ta_vertex_parameter::polygon_type_0(polygon_vertex_parameter_control_word(true), + cx, cy, z, + base_color); +} + +void transform_cursor(ta_parameter_writer& writer, const float origin_x, const float origin_y, const float width, const float height) { - const uint32_t parameter_control_word = para_control::para_type::sprite + const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume | para_control::list_type::translucent | obj_control::col_type::packed_color; @@ -46,46 +76,40 @@ void transform_sprite(ta_parameter_writer& parameter, | tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::fog_control::no_fog; - constexpr uint32_t base_color = 0xffffffff; - parameter.append() = - ta_global_parameter::sprite(parameter_control_word, - isp_tsp_instruction_word, - tsp_instruction_word, - 0, // texture_control_word - base_color, - 0, // offset_color - 0, // data_size_for_sort_dma - 0 // next_address_for_sort_dma - ); + + const uint32_t texture_control_word = 0; + + writer.append() = + ta_global_parameter::polygon_type_0(parameter_control_word, + isp_tsp_instruction_word, + tsp_instruction_word, + texture_control_word, + 0, // data_size_for_sort_dma + 0 // next_address_for_sort_dma + ); const float z = 0.1f; - parameter.append() = - ta_vertex_parameter::sprite_type_0(para_control::para_type::vertex_parameter, - strip_vertices[0].x * width + origin_x, - strip_vertices[0].y * height + origin_y, - z, - strip_vertices[1].x * width + origin_x, - strip_vertices[1].y * height + origin_y, - z, - strip_vertices[2].x * width + origin_x, - strip_vertices[2].y * height + origin_y, - z, - strip_vertices[3].x * width + origin_x, - strip_vertices[3].y * height + origin_y - ); + + transfer_quad_type_0(writer, + strip_vertices[0].x * width + origin_x, + strip_vertices[0].y * height + origin_y, + strip_vertices[1].x * width + origin_x, + strip_vertices[1].y * height + origin_y, + strip_vertices[2].x * width + origin_x, + strip_vertices[2].y * height + origin_y, + strip_vertices[3].x * width + origin_x, + strip_vertices[3].y * height + origin_y, + z + ); } -void transform_glyph(ta_parameter_writer& parameter, - const uint32_t texture_width, uint32_t texture_height, - const glyph& glyph, - const float origin_x, - const float origin_y) +void glyph_begin(ta_parameter_writer& writer, + const uint32_t texture_width, uint32_t texture_height) { - const uint32_t parameter_control_word = para_control::para_type::sprite + const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume | para_control::list_type::translucent | obj_control::col_type::packed_color - | obj_control::texture - | obj_control::_16bit_uv; + | obj_control::texture; const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::always | isp_tsp_instruction_word::culling_mode::no_culling; @@ -103,17 +127,55 @@ void transform_glyph(ta_parameter_writer& parameter, | texture_control_word::palette_selector8(0) | texture_control_word::texture_address(texture_address / 8); - parameter.append() = - ta_global_parameter::sprite(parameter_control_word, - isp_tsp_instruction_word, - tsp_instruction_word, - texture_control_word, - 0, // base_color - 0, // offset_color - 0, // data_size_for_sort_dma - 0 // next_address_for_sort_dma - ); + writer.append() = + ta_global_parameter::polygon_type_0(parameter_control_word, + isp_tsp_instruction_word, + tsp_instruction_word, + texture_control_word, + 0, // data_size_for_sort_dma + 0 // next_address_for_sort_dma + ); +} +static inline void transfer_quad_type_1(ta_parameter_writer& writer, + struct vertex va, struct vertex vb, struct vertex vc, struct vertex vd, float z) +{ + writer.append() = + ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(false), + va.x, va.y, z, + va.u, va.v, + 0, // base_color + 0); // offset_color + + writer.append() = + ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(false), + vb.x, vb.y, z, + vb.u, vb.v, + 0, // base_color + 0); // offset_color + + writer.append() = + ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(false), + vd.x, vd.y, z, + vd.u, vd.v, + 0, // base_color + 0); // offset_color + + writer.append() = + ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(true), + vc.x, vc.y, z, + vc.u, vc.v, + 0, // base_color + 0); // offset_color +} + +void transform_glyph(ta_parameter_writer& writer, + const float r_texture_width, + const float r_texture_height, + const glyph& glyph, + const float origin_x, + const float origin_y) +{ struct vertex out[strip_length]; for (uint32_t i = 0; i < strip_length; i++) { float x = strip_vertices[i].x; @@ -121,8 +183,6 @@ void transform_glyph(ta_parameter_writer& parameter, x *= glyph.bitmap.width; y *= glyph.bitmap.height; - //x *= texture_width; - //y *= texture_height; x += origin_x + float_26_6(glyph.metrics.horiBearingX); y += origin_y - float_26_6(glyph.metrics.horiBearingY); @@ -132,8 +192,8 @@ void transform_glyph(ta_parameter_writer& parameter, v *= glyph.bitmap.height; u += glyph.bitmap.x; v += glyph.bitmap.y; - u = u / static_cast(texture_width); - v = v / static_cast(texture_height); + u = u * r_texture_width; + v = v * r_texture_height; out[i].x = x; out[i].y = y; @@ -142,21 +202,5 @@ void transform_glyph(ta_parameter_writer& parameter, } const float z = 0.1f; - parameter.append() = - ta_vertex_parameter::sprite_type_1(para_control::para_type::vertex_parameter, - out[0].x, - out[0].y, - z, - out[1].x, - out[1].y, - z, - out[2].x, - out[2].y, - z, - out[3].x, - out[3].y, - uv_16bit(out[0].u, out[0].v), - uv_16bit(out[1].u, out[1].v), - uv_16bit(out[2].u, out[2].v) - ); + transfer_quad_type_1(writer, out[0], out[1], out[2], out[3], z); } diff --git a/text_editor/transform.hpp b/text_editor/transform.hpp index e864dcf..28330a2 100644 --- a/text_editor/transform.hpp +++ b/text_editor/transform.hpp @@ -5,14 +5,18 @@ #include "holly/ta_parameter.hpp" #include "font/font.h" -void transform_sprite(ta_parameter_writer& parameter, +void transform_cursor(ta_parameter_writer& writer, const float origin_x, const float origin_y, const float width, const float height); -void transform_glyph(ta_parameter_writer& parameter, - const uint32_t texture_width, uint32_t texture_height, +void glyph_begin(ta_parameter_writer& writer, + const uint32_t texture_width, uint32_t texture_height); + +void transform_glyph(ta_parameter_writer& writer, + const float r_texture_width, + const float r_texture_height, const glyph& glyph, const float origin_x, const float origin_y);