gfx: use Mat4x4.projection2D once again

Helps hexops/mach#1103

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-01-06 13:10:54 -07:00
parent 0d938ef6be
commit fc24a1148a
2 changed files with 24 additions and 24 deletions

View file

@ -303,9 +303,9 @@ pub const local = struct {
var uv_transforms_offset: usize = 0; var uv_transforms_offset: usize = 0;
var sizes_offset: usize = 0; var sizes_offset: usize = 0;
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
var transforms = archetype.slice(.mach_gfx_sprite, .transform); const transforms = archetype.slice(.mach_gfx_sprite, .transform);
var uv_transforms = archetype.slice(.mach_gfx_sprite, .uv_transform); const uv_transforms = archetype.slice(.mach_gfx_sprite, .uv_transform);
var sizes = archetype.slice(.mach_gfx_sprite, .size); const sizes = archetype.slice(.mach_gfx_sprite, .size);
// TODO: confirm the lifetime of these slices is OK for writeBuffer, how long do they need // TODO: confirm the lifetime of these slices is OK for writeBuffer, how long do they need
// to live? // to live?
@ -333,16 +333,16 @@ pub const local = struct {
const pipeline = sprite_mod.state.pipelines.get(pipeline_id).?; const pipeline = sprite_mod.state.pipelines.get(pipeline_id).?;
// Update uniform buffer // Update uniform buffer
const ortho = Mat4x4.ortho( const proj = Mat4x4.projection2D(.{
-@as(f32, @floatFromInt(core.size().width)) / 2, .left = -@as(f32, @floatFromInt(core.size().width)) / 2,
@as(f32, @floatFromInt(core.size().width)) / 2, .right = @as(f32, @floatFromInt(core.size().width)) / 2,
-@as(f32, @floatFromInt(core.size().height)) / 2, .bottom = -@as(f32, @floatFromInt(core.size().height)) / 2,
@as(f32, @floatFromInt(core.size().height)) / 2, .top = @as(f32, @floatFromInt(core.size().height)) / 2,
-0.1, .near = -0.1,
100000, .far = 100000,
); });
const uniforms = Uniforms{ const uniforms = Uniforms{
.view_projection = ortho, .view_projection = proj,
// TODO: dimensions of other textures, number of textures present // TODO: dimensions of other textures, number of textures present
.texture_size = vec2( .texture_size = vec2(
@as(f32, @floatFromInt(pipeline.texture.getWidth())), @as(f32, @floatFromInt(pipeline.texture.getWidth())),

View file

@ -374,7 +374,7 @@ pub const local = struct {
// var colors_offset: usize = 0; // var colors_offset: usize = 0;
var texture_update = false; var texture_update = false;
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
var transforms = archetype.slice(.mach_gfx_text, .transform); const transforms = archetype.slice(.mach_gfx_text, .transform);
// var colors = archetype.slice(.mach_gfx_text, .color); // var colors = archetype.slice(.mach_gfx_text, .color);
// TODO: confirm the lifetime of these slices is OK for writeBuffer, how long do they need // TODO: confirm the lifetime of these slices is OK for writeBuffer, how long do they need
@ -392,7 +392,7 @@ pub const local = struct {
const px_density = 2.0; const px_density = 2.0;
// var font_names = archetype.slice(.mach_gfx_text, .font_name); // var font_names = archetype.slice(.mach_gfx_text, .font_name);
// var font_sizes = archetype.slice(.mach_gfx_text, .font_size); // var font_sizes = archetype.slice(.mach_gfx_text, .font_size);
var texts = archetype.slice(.mach_gfx_text, .text); const texts = archetype.slice(.mach_gfx_text, .text);
for (texts) |text| { for (texts) |text| {
var origin_x: f32 = 0.0; var origin_x: f32 = 0.0;
var origin_y: f32 = 0.0; var origin_y: f32 = 0.0;
@ -418,7 +418,7 @@ pub const local = struct {
const codepoint = segment.string[glyph.cluster]; const codepoint = segment.string[glyph.cluster];
// TODO: use flags(?) to detect newline, or at least something more reliable? // TODO: use flags(?) to detect newline, or at least something more reliable?
if (codepoint != '\n') { if (codepoint != '\n') {
var region = try pipeline.regions.getOrPut(engine.allocator, .{ const region = try pipeline.regions.getOrPut(engine.allocator, .{
.index = glyph.glyph_index, .index = glyph.glyph_index,
.size = @bitCast(segment.style.font_size), .size = @bitCast(segment.style.font_size),
}); });
@ -508,16 +508,16 @@ pub const local = struct {
const pipeline = text_mod.state.pipelines.get(pipeline_id).?; const pipeline = text_mod.state.pipelines.get(pipeline_id).?;
// Update uniform buffer // Update uniform buffer
const ortho = Mat4x4.ortho( const proj = Mat4x4.projection2D(.{
-@as(f32, @floatFromInt(core.size().width)) / 2, .left = -@as(f32, @floatFromInt(core.size().width)) / 2,
@as(f32, @floatFromInt(core.size().width)) / 2, .right = @as(f32, @floatFromInt(core.size().width)) / 2,
-@as(f32, @floatFromInt(core.size().height)) / 2, .bottom = -@as(f32, @floatFromInt(core.size().height)) / 2,
@as(f32, @floatFromInt(core.size().height)) / 2, .top = @as(f32, @floatFromInt(core.size().height)) / 2,
-0.1, .near = -0.1,
100000, .far = 100000,
); });
const uniforms = Uniforms{ const uniforms = Uniforms{
.view_projection = ortho, .view_projection = proj,
// TODO: dimensions of other textures, number of textures present // TODO: dimensions of other textures, number of textures present
.texture_size = vec2( .texture_size = vec2(
@as(f32, @floatFromInt(pipeline.texture.getWidth())), @as(f32, @floatFromInt(pipeline.texture.getWidth())),