renderer/opengl: create the screen texture

This commit is contained in:
Mitchell Hashimoto
2023-11-17 20:39:20 -08:00
parent db244da101
commit c8a51a2158
4 changed files with 111 additions and 40 deletions

View File

@@ -1346,11 +1346,11 @@ fn flushAtlas(self: *OpenGL) !void {
atlas.resized = false;
try texbind.image2D(
0,
.Red,
.red,
@intCast(atlas.size),
@intCast(atlas.size),
0,
.Red,
.red,
.UnsignedByte,
atlas.data.ptr,
);
@@ -1361,7 +1361,7 @@ fn flushAtlas(self: *OpenGL) !void {
0,
@intCast(atlas.size),
@intCast(atlas.size),
.Red,
.red,
.UnsignedByte,
atlas.data.ptr,
);
@@ -1380,11 +1380,11 @@ fn flushAtlas(self: *OpenGL) !void {
atlas.resized = false;
try texbind.image2D(
0,
.RGBA,
.rgba,
@intCast(atlas.size),
@intCast(atlas.size),
0,
.BGRA,
.bgra,
.UnsignedByte,
atlas.data.ptr,
);
@@ -1395,7 +1395,7 @@ fn flushAtlas(self: *OpenGL) !void {
0,
@intCast(atlas.size),
@intCast(atlas.size),
.BGRA,
.bgra,
.UnsignedByte,
atlas.data.ptr,
);
@@ -1441,8 +1441,7 @@ fn drawCustomPrograms(
const custom_bind = try custom_state.bind();
defer custom_bind.unbind();
// Sync the uniform data.
// TODO: only do this when the data has changed
// Setup the new frame
try custom_state.newFrame();
// Go through each custom shader and draw it.
@@ -1469,6 +1468,14 @@ fn drawCellProgram(
// are changes to the atlas.
try self.flushAtlas();
// If we have custom shaders, then we draw to the custom
// shader framebuffer.
const fbobind: ?gl.Framebuffer.Binding = fbobind: {
const state = gl_state.custom orelse break :fbobind null;
break :fbobind try state.fbo.bind(.framebuffer);
};
defer if (fbobind) |v| v.unbind();
// Clear the surface
gl.clearColor(
@as(f32, @floatFromInt(self.draw_background.r)) / 255,
@@ -1615,11 +1622,11 @@ const GLState = struct {
try texbind.parameter(.MagFilter, gl.c.GL_LINEAR);
try texbind.image2D(
0,
.Red,
.red,
@intCast(font_group.atlas_greyscale.size),
@intCast(font_group.atlas_greyscale.size),
0,
.Red,
.red,
.UnsignedByte,
font_group.atlas_greyscale.data.ptr,
);
@@ -1636,11 +1643,11 @@ const GLState = struct {
try texbind.parameter(.MagFilter, gl.c.GL_LINEAR);
try texbind.image2D(
0,
.RGBA,
.rgba,
@intCast(font_group.atlas_color.size),
@intCast(font_group.atlas_color.size),
0,
.BGRA,
.bgra,
.UnsignedByte,
font_group.atlas_color.data.ptr,
);