summaryrefslogtreecommitdiff
path: root/src/renderer/OpenGL.zig
diff options
context:
space:
mode:
authorjulia <me@juliapaci.com>2025-01-14 10:13:09 +1100
committerMitchell Hashimoto <m@mitchellh.com>2025-01-20 10:36:02 -0800
commit4cc1fa2111848a78536e54ea34d9720d4f995dac (patch)
tree6ce08b86d2e673721a9df4bea6434f15509dfc74 /src/renderer/OpenGL.zig
parenta2445359c40ba66f36157359c0ae92509b7f005d (diff)
render consecutive shaders to the fbo
not that big. see comments
Diffstat (limited to 'src/renderer/OpenGL.zig')
-rw-r--r--src/renderer/OpenGL.zig22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig
index e5dec6b2b..8b6552bb9 100644
--- a/src/renderer/OpenGL.zig
+++ b/src/renderer/OpenGL.zig
@@ -2350,11 +2350,9 @@ pub fn drawFrame(self: *OpenGL, surface: *apprt.Surface) !void {
}
/// Draw the custom shaders.
-fn drawCustomPrograms(
- self: *OpenGL,
- custom_state: *custom.State,
-) !void {
+fn drawCustomPrograms(self: *OpenGL, custom_state: *custom.State) !void {
_ = self;
+ assert(custom_state.programs.len > 0);
// Bind our state that is global to all custom shaders
const custom_bind = try custom_state.bind();
@@ -2363,8 +2361,22 @@ fn drawCustomPrograms(
// Setup the new frame
try custom_state.newFrame();
+ // To allow programs to retrieve each other via a texture
+ // then we must render the next shaders to the screen fbo.
+ // However, the first shader must be run while the default fbo
+ // is attached
+ {
+ const bind = try custom_state.programs[0].bind();
+ defer bind.unbind();
+ try bind.draw();
+ if (custom_state.programs.len == 1) return;
+ }
+
+ const fbobind = try custom_state.fbo.bind(.framebuffer);
+ defer fbobind.unbind();
+
// Go through each custom shader and draw it.
- for (custom_state.programs) |program| {
+ for (custom_state.programs[1..]) |program| {
// Bind our cell program state, buffers
const bind = try program.bind();
defer bind.unbind();