text_editor: replace sprites with triangle strips
This commit is contained in:
parent
4d3e53eebb
commit
21701d90aa
@ -30,7 +30,7 @@ constexpr inline int32_t int_26_6(int32_t n)
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor_advance render_primary_buffer(ta_parameter_writer& parameter,
|
cursor_advance render_primary_buffer(ta_parameter_writer& writer,
|
||||||
const font * font,
|
const font * font,
|
||||||
const glyph * glyphs,
|
const glyph * glyphs,
|
||||||
const gap_buffer& gb,
|
const gap_buffer& gb,
|
||||||
@ -42,6 +42,9 @@ cursor_advance render_primary_buffer(ta_parameter_writer& parameter,
|
|||||||
int32_t h_advance = 0;
|
int32_t h_advance = 0;
|
||||||
int32_t v_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;
|
int32_t init_i = first_line >= 0 ? gb.line.offsets[first_line] + 1 : 0;
|
||||||
for (int32_t i = init_i; i <= gb.size; i++) {
|
for (int32_t i = init_i; i <= gb.size; i++) {
|
||||||
if (i == gb.gap_start) {
|
if (i == gb.gap_start) {
|
||||||
@ -68,9 +71,9 @@ cursor_advance render_primary_buffer(ta_parameter_writer& parameter,
|
|||||||
auto& glyph = glyphs[ix];
|
auto& glyph = glyphs[ix];
|
||||||
|
|
||||||
if (x + int_26_6(glyph.metrics.horiAdvance) <= window.box.x1) {
|
if (x + int_26_6(glyph.metrics.horiAdvance) <= window.box.x1) {
|
||||||
transform_glyph(parameter,
|
transform_glyph(writer,
|
||||||
font->texture_width,
|
r_texture_width,
|
||||||
font->texture_height,
|
r_texture_height,
|
||||||
glyph,
|
glyph,
|
||||||
x,
|
x,
|
||||||
y
|
y
|
||||||
@ -100,7 +103,7 @@ void render_cursor(ta_parameter_writer& parameter,
|
|||||||
float width = int_26_6(cursor.width);
|
float width = int_26_6(cursor.width);
|
||||||
float height = int_26_6(cursor.height);
|
float height = int_26_6(cursor.height);
|
||||||
|
|
||||||
transform_sprite(parameter,
|
transform_cursor(parameter,
|
||||||
x, // x
|
x, // x
|
||||||
y, // y
|
y, // y
|
||||||
width,
|
width,
|
||||||
@ -114,6 +117,10 @@ void render(ta_parameter_writer& writer,
|
|||||||
const gap_buffer& gb,
|
const gap_buffer& gb,
|
||||||
const viewport_window& window)
|
const viewport_window& window)
|
||||||
{
|
{
|
||||||
|
glyph_begin(writer,
|
||||||
|
font->texture_width,
|
||||||
|
font->texture_height);
|
||||||
|
|
||||||
cursor_advance cursor = render_primary_buffer(writer, font, glyphs, gb, window);
|
cursor_advance cursor = render_primary_buffer(writer, font, glyphs, gb, window);
|
||||||
|
|
||||||
render_cursor(writer, cursor, window);
|
render_cursor(writer, cursor, window);
|
||||||
|
@ -29,13 +29,43 @@ const struct vertex strip_vertices[4] = {
|
|||||||
};
|
};
|
||||||
constexpr uint32_t strip_length = (sizeof (strip_vertices)) / (sizeof (struct vertex));
|
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>() =
|
||||||
|
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>() =
|
||||||
|
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>() =
|
||||||
|
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>() =
|
||||||
|
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_x,
|
||||||
const float origin_y,
|
const float origin_y,
|
||||||
const float width,
|
const float width,
|
||||||
const float height)
|
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
|
| para_control::list_type::translucent
|
||||||
| obj_control::col_type::packed_color;
|
| 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::dst_alpha_instr::zero
|
||||||
| tsp_instruction_word::fog_control::no_fog;
|
| tsp_instruction_word::fog_control::no_fog;
|
||||||
|
|
||||||
constexpr uint32_t base_color = 0xffffffff;
|
|
||||||
parameter.append<ta_global_parameter::sprite>() =
|
const uint32_t texture_control_word = 0;
|
||||||
ta_global_parameter::sprite(parameter_control_word,
|
|
||||||
isp_tsp_instruction_word,
|
writer.append<ta_global_parameter::polygon_type_0>() =
|
||||||
tsp_instruction_word,
|
ta_global_parameter::polygon_type_0(parameter_control_word,
|
||||||
0, // texture_control_word
|
isp_tsp_instruction_word,
|
||||||
base_color,
|
tsp_instruction_word,
|
||||||
0, // offset_color
|
texture_control_word,
|
||||||
0, // data_size_for_sort_dma
|
0, // data_size_for_sort_dma
|
||||||
0 // next_address_for_sort_dma
|
0 // next_address_for_sort_dma
|
||||||
);
|
);
|
||||||
|
|
||||||
const float z = 0.1f;
|
const float z = 0.1f;
|
||||||
parameter.append<ta_vertex_parameter::sprite_type_0>() =
|
|
||||||
ta_vertex_parameter::sprite_type_0(para_control::para_type::vertex_parameter,
|
transfer_quad_type_0(writer,
|
||||||
strip_vertices[0].x * width + origin_x,
|
strip_vertices[0].x * width + origin_x,
|
||||||
strip_vertices[0].y * height + origin_y,
|
strip_vertices[0].y * height + origin_y,
|
||||||
z,
|
strip_vertices[1].x * width + origin_x,
|
||||||
strip_vertices[1].x * width + origin_x,
|
strip_vertices[1].y * height + origin_y,
|
||||||
strip_vertices[1].y * height + origin_y,
|
strip_vertices[2].x * width + origin_x,
|
||||||
z,
|
strip_vertices[2].y * height + origin_y,
|
||||||
strip_vertices[2].x * width + origin_x,
|
strip_vertices[3].x * width + origin_x,
|
||||||
strip_vertices[2].y * height + origin_y,
|
strip_vertices[3].y * height + origin_y,
|
||||||
z,
|
z
|
||||||
strip_vertices[3].x * width + origin_x,
|
);
|
||||||
strip_vertices[3].y * height + origin_y
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void transform_glyph(ta_parameter_writer& parameter,
|
void glyph_begin(ta_parameter_writer& writer,
|
||||||
const uint32_t texture_width, uint32_t texture_height,
|
const uint32_t texture_width, uint32_t texture_height)
|
||||||
const glyph& glyph,
|
|
||||||
const float origin_x,
|
|
||||||
const float origin_y)
|
|
||||||
{
|
{
|
||||||
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
|
| para_control::list_type::translucent
|
||||||
| obj_control::col_type::packed_color
|
| obj_control::col_type::packed_color
|
||||||
| obj_control::texture
|
| obj_control::texture;
|
||||||
| obj_control::_16bit_uv;
|
|
||||||
|
|
||||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::always
|
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::always
|
||||||
| isp_tsp_instruction_word::culling_mode::no_culling;
|
| 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::palette_selector8(0)
|
||||||
| texture_control_word::texture_address(texture_address / 8);
|
| texture_control_word::texture_address(texture_address / 8);
|
||||||
|
|
||||||
parameter.append<ta_global_parameter::sprite>() =
|
writer.append<ta_global_parameter::polygon_type_0>() =
|
||||||
ta_global_parameter::sprite(parameter_control_word,
|
ta_global_parameter::polygon_type_0(parameter_control_word,
|
||||||
isp_tsp_instruction_word,
|
isp_tsp_instruction_word,
|
||||||
tsp_instruction_word,
|
tsp_instruction_word,
|
||||||
texture_control_word,
|
texture_control_word,
|
||||||
0, // base_color
|
0, // data_size_for_sort_dma
|
||||||
0, // offset_color
|
0 // next_address_for_sort_dma
|
||||||
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>() =
|
||||||
|
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>() =
|
||||||
|
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>() =
|
||||||
|
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>() =
|
||||||
|
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];
|
struct vertex out[strip_length];
|
||||||
for (uint32_t i = 0; i < strip_length; i++) {
|
for (uint32_t i = 0; i < strip_length; i++) {
|
||||||
float x = strip_vertices[i].x;
|
float x = strip_vertices[i].x;
|
||||||
@ -121,8 +183,6 @@ void transform_glyph(ta_parameter_writer& parameter,
|
|||||||
|
|
||||||
x *= glyph.bitmap.width;
|
x *= glyph.bitmap.width;
|
||||||
y *= glyph.bitmap.height;
|
y *= glyph.bitmap.height;
|
||||||
//x *= texture_width;
|
|
||||||
//y *= texture_height;
|
|
||||||
x += origin_x + float_26_6(glyph.metrics.horiBearingX);
|
x += origin_x + float_26_6(glyph.metrics.horiBearingX);
|
||||||
y += origin_y - float_26_6(glyph.metrics.horiBearingY);
|
y += origin_y - float_26_6(glyph.metrics.horiBearingY);
|
||||||
|
|
||||||
@ -132,8 +192,8 @@ void transform_glyph(ta_parameter_writer& parameter,
|
|||||||
v *= glyph.bitmap.height;
|
v *= glyph.bitmap.height;
|
||||||
u += glyph.bitmap.x;
|
u += glyph.bitmap.x;
|
||||||
v += glyph.bitmap.y;
|
v += glyph.bitmap.y;
|
||||||
u = u / static_cast<float>(texture_width);
|
u = u * r_texture_width;
|
||||||
v = v / static_cast<float>(texture_height);
|
v = v * r_texture_height;
|
||||||
|
|
||||||
out[i].x = x;
|
out[i].x = x;
|
||||||
out[i].y = y;
|
out[i].y = y;
|
||||||
@ -142,21 +202,5 @@ void transform_glyph(ta_parameter_writer& parameter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const float z = 0.1f;
|
const float z = 0.1f;
|
||||||
parameter.append<ta_vertex_parameter::sprite_type_1>() =
|
transfer_quad_type_1(writer, out[0], out[1], out[2], out[3], z);
|
||||||
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)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,18 @@
|
|||||||
#include "holly/ta_parameter.hpp"
|
#include "holly/ta_parameter.hpp"
|
||||||
#include "font/font.h"
|
#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_x,
|
||||||
const float origin_y,
|
const float origin_y,
|
||||||
const float width,
|
const float width,
|
||||||
const float height);
|
const float height);
|
||||||
|
|
||||||
void transform_glyph(ta_parameter_writer& parameter,
|
void glyph_begin(ta_parameter_writer& writer,
|
||||||
const uint32_t texture_width, uint32_t texture_height,
|
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 glyph& glyph,
|
||||||
const float origin_x,
|
const float origin_x,
|
||||||
const float origin_y);
|
const float origin_y);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user