mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
get rid of gb_math and create matrices from scratch
This commit is contained in:
@ -140,8 +140,6 @@ fn addDeps(
|
||||
b: *std.build.Builder,
|
||||
step: *std.build.LibExeObjStep,
|
||||
) !void {
|
||||
step.addIncludeDir("src/");
|
||||
step.addCSourceFile("src/gb_math.c", &.{});
|
||||
step.addIncludeDir("vendor/glad/include/");
|
||||
step.addCSourceFile("vendor/glad/src/gl.c", &.{});
|
||||
|
||||
|
24
src/Grid.zig
24
src/Grid.zig
@ -10,9 +10,9 @@ const font = @import("font/font.zig");
|
||||
const terminal = @import("terminal/main.zig");
|
||||
const Terminal = terminal.Terminal;
|
||||
const gl = @import("opengl.zig");
|
||||
const gb = @import("gb_math.zig");
|
||||
const trace = @import("tracy").trace;
|
||||
const Config = @import("config.zig").Config;
|
||||
const math = @import("math.zig");
|
||||
|
||||
const log = std.log.scoped(.grid);
|
||||
|
||||
@ -442,20 +442,20 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
|
||||
/// Set the screen size for rendering. This will update the projection
|
||||
/// used for the shader so that the scaling of the grid is correct.
|
||||
pub fn setScreenSize(self: *Grid, dim: ScreenSize) !void {
|
||||
// Create a 2D orthographic projection matrix with the full width/height.
|
||||
var projection: gb.gbMat4 = undefined;
|
||||
gb.gb_mat4_ortho2d(
|
||||
&projection,
|
||||
0,
|
||||
@intToFloat(f32, dim.width),
|
||||
@intToFloat(f32, dim.height),
|
||||
0,
|
||||
);
|
||||
|
||||
// Update the projection uniform within our shader
|
||||
const bind = try self.program.use();
|
||||
defer bind.unbind();
|
||||
try self.program.setUniform("projection", projection);
|
||||
try self.program.setUniform(
|
||||
"projection",
|
||||
|
||||
// 2D orthographic projection with the full w/h
|
||||
math.ortho2d(
|
||||
0,
|
||||
@intToFloat(f32, dim.width),
|
||||
@intToFloat(f32, dim.height),
|
||||
0,
|
||||
),
|
||||
);
|
||||
|
||||
// Recalculate the rows/columns.
|
||||
self.size.update(dim, self.cell_size);
|
||||
|
@ -1,6 +0,0 @@
|
||||
// This file defines the implementation of gb_math and is compiled using clang.
|
||||
// gb_math.zig then imports gb_math.h without the implementation define set
|
||||
// so that it can just get the function prototypes.
|
||||
|
||||
#define GB_MATH_IMPLEMENTATION
|
||||
#include "gb_math.h"
|
2234
src/gb_math.h
2234
src/gb_math.h
File diff suppressed because it is too large
Load Diff
@ -1,3 +0,0 @@
|
||||
pub usingnamespace @cImport({
|
||||
@cInclude("gb_math.h");
|
||||
});
|
24
src/math.zig
Normal file
24
src/math.zig
Normal file
@ -0,0 +1,24 @@
|
||||
pub const F32x4 = @Vector(4, f32);
|
||||
|
||||
/// Matrix type
|
||||
pub const Mat = [4]F32x4;
|
||||
|
||||
/// Identity matrix
|
||||
pub fn identity() Mat {
|
||||
return .{
|
||||
.{ 1.0, 0.0, 0.0, 0.0 },
|
||||
.{ 0.0, 1.0, 0.0, 0.0 },
|
||||
.{ 0.0, 0.0, 1.0, 0.0 },
|
||||
.{ 0.0, 0.0, 0.0, 1.0 },
|
||||
};
|
||||
}
|
||||
|
||||
pub fn ortho2d(left: f32, right: f32, bottom: f32, top: f32) Mat {
|
||||
var mat = identity();
|
||||
mat[0][0] = 2 / (right - left);
|
||||
mat[1][1] = 2 / (top - bottom);
|
||||
mat[2][2] = -1.0;
|
||||
mat[3][0] = -(right + left) / (right - left);
|
||||
mat[3][1] = -(top + bottom) / (top - bottom);
|
||||
return mat;
|
||||
}
|
@ -4,7 +4,6 @@ const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const log = std.log.scoped(.opengl);
|
||||
|
||||
const gb = @import("../gb_math.zig");
|
||||
const c = @import("c.zig");
|
||||
const Shader = @import("Shader.zig");
|
||||
const errors = @import("errors.zig");
|
||||
@ -87,7 +86,7 @@ pub inline fn setUniform(p: Program, n: [:0]const u8, value: anytype) !void {
|
||||
@Vector(2, f32) => c.glUniform2f(loc, value[0], value[1]),
|
||||
@Vector(3, f32) => c.glUniform3f(loc, value[0], value[1], value[2]),
|
||||
@Vector(4, f32) => c.glUniform4f(loc, value[0], value[1], value[2], value[3]),
|
||||
gb.gbMat4 => c.glUniformMatrix4fv(
|
||||
[4]@Vector(4, f32) => c.glUniformMatrix4fv(
|
||||
loc,
|
||||
1,
|
||||
c.GL_FALSE,
|
||||
|
Reference in New Issue
Block a user