[update] Added Context methods related to framebuffers.

This commit is contained in:
falsycat 2019-10-09 00:00:00 +00:00
parent 93ac2c1e2a
commit e485bf4ef5
3 changed files with 32 additions and 8 deletions

View File

@ -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_;

View File

@ -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);
}

View File

@ -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;
}