From e485bf4ef5bf69406be2858a52629cada1bb765c Mon Sep 17 00:00:00 2001 From: falsycat Date: Wed, 9 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Added Context methods related to framebuffers. --- sjplayer/src/sjplayer/Context.d | 21 ++++++++++++++++++++- sjplayer/src/sjplayer/package.d | 10 ++++++---- sjplayer/standalone/main.d | 9 ++++++--- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/sjplayer/src/sjplayer/Context.d b/sjplayer/src/sjplayer/Context.d index 20535d0..e2a6863 100644 --- a/sjplayer/src/sjplayer/Context.d +++ b/sjplayer/src/sjplayer/Context.d @@ -15,6 +15,7 @@ import sjplayer.Actor, sjplayer.ContextBuilderInterface, sjplayer.ElementDrawerInterface, sjplayer.ElementInterface, + sjplayer.PostEffect, sjplayer.ProgramSet, sjplayer.ScheduledControllerInterface, sjplayer.VarStore; @@ -23,9 +24,10 @@ import sjplayer.Actor, class Context { public: /// - this(ParametersBlock[] params, ProgramSet programs) { + this(ParametersBlock[] params, vec2i window_size, ProgramSet programs) { actor_ = new Actor(programs.Get!ActorProgram); background_ = new Background(programs.Get!BackgroundProgram); + posteffect_ = new PostEffect(programs.Get!PostEffectProgram, window_size); auto builder = new Builder; auto varstore = new VarStore(actor_); @@ -60,10 +62,14 @@ class Context { /// ~this() { controllers_.each!destroy; + actor_controller_.destroy(); + drawers_.each!destroy; elements_.each!destroy; + actor_.destroy(); background_.destroy(); + posteffect_.destroy(); } /// @@ -80,6 +86,16 @@ class Context { controllers_.each!(x => x.Operate(time)); } + /// + void StartDrawing() { + posteffect_.BindFramebuffer(); + } + /// + void EndDrawing() { + posteffect_.UnbindFramebuffer(); + posteffect_.DrawFramebuffer(); + } + /// void DrawBackground() { background_.Draw(); @@ -119,6 +135,9 @@ class Context { Background background_; invariant(background_); + PostEffect posteffect_; + invariant(posteffect_); + ElementInterface[] elements_; ElementDrawerInterface[] drawers_; diff --git a/sjplayer/src/sjplayer/package.d b/sjplayer/src/sjplayer/package.d index 9993ce7..8cc3f53 100644 --- a/sjplayer/src/sjplayer/package.d +++ b/sjplayer/src/sjplayer/package.d @@ -1,6 +1,8 @@ /// License: MIT module sjplayer; +import gl4d; + import sjscript; public { @@ -9,11 +11,11 @@ public { } /// -Context CreateContextFromText(string src, ProgramSet programs) { - return src.CreateScriptAst().CreateContextFromScriptAst(programs); +Context CreateContextFromText(string src, vec2i window_size, ProgramSet programs) { + return src.CreateScriptAst().CreateContextFromScriptAst(window_size, programs); } /// Context CreateContextFromScriptAst( - ParametersBlock[] params, ProgramSet programs) { - return new Context(params, programs); + ParametersBlock[] params, vec2i window_size, ProgramSet programs) { + return new Context(params, window_size, programs); } diff --git a/sjplayer/standalone/main.d b/sjplayer/standalone/main.d index 551f775..3fd3fe2 100644 --- a/sjplayer/standalone/main.d +++ b/sjplayer/standalone/main.d @@ -25,7 +25,8 @@ int main(string[] args) { auto programs = new ProgramSet; scope(exit) programs.destroy(); - auto context = script_file.readText.CreateContextFromText(programs); + auto context = script_file.readText. + CreateContextFromText(vec2i(600, 600), programs); scope(exit) context.destroy(); while (true) { @@ -39,10 +40,13 @@ int main(string[] args) { context.OperateScheduledControllers(beat); context.UpdateActor(vec2(0, 0)); - gl.Clear(GL_COLOR_BUFFER_BIT); + context.StartDrawing(); + context.DrawBackground(); context.DrawElements(); context.DrawActor(); + + context.EndDrawing(); sfWindow_display(win); } return 0; @@ -70,6 +74,5 @@ sfWindow* Initialize() { gl.ApplyContext(); gl.Enable(GL_BLEND); gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - return win; }