[update] Updated PostEffect that can be shared with else scenes of PlayScene.

This commit is contained in:
falsycat 2019-10-16 00:00:00 +00:00
parent d3026b1fb7
commit 673c2dfe94
10 changed files with 65 additions and 48 deletions

View File

@ -28,10 +28,9 @@ import sjplayer.Actor,
class Context {
public:
///
this(ParametersBlock[] params, vec2i window_size, ProgramSet programs) {
this(ParametersBlock[] params, PostEffect posteffect, 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_);
@ -47,7 +46,7 @@ class Context {
),
tuple(
"posteffect",
PostEffectControllerFactory(varstore, posteffect_),
PostEffectControllerFactory(varstore, posteffect),
),
tuple(
@ -94,7 +93,6 @@ class Context {
drawers_.each!destroy;
elements_.each!destroy;
posteffect_.destroy();
background_.destroy();
actor_.destroy();
}
@ -116,10 +114,6 @@ class Context {
controllers_.each!(x => x.Operate(time));
}
///
void StartDrawing() {
posteffect_.BindFramebuffer();
}
///
void DrawBackground() {
background_.Draw();
@ -132,11 +126,6 @@ class Context {
void DrawActor() {
actor_.Draw();
}
///
void EndDrawing() {
posteffect_.UnbindFramebuffer();
posteffect_.DrawFramebuffer();
}
///
@property inout(ActorControllerInterface) actor() inout {
@ -170,7 +159,6 @@ class Context {
Actor actor_;
Background background_;
PostEffect posteffect_;
ElementInterface[] elements_;
ElementDrawerInterface[] drawers_;

View File

@ -28,6 +28,7 @@ class PostEffect {
program_ = program;
fb_ = Framebuffer.Create();
tex_ = TextureRect.Create();
depth_ = Renderbuffer.Create();
sampler_ = Sampler.Create();
with (TextureRectAllocator()) {
@ -38,7 +39,11 @@ class PostEffect {
data = null;
Allocate(tex_);
}
with (RenderbufferAllocator()) {
format = GL_DEPTH_COMPONENT;
size = sz;
Allocate(depth_);
}
with (SamplerConfigurer()) {
filterMin = GL_NEAREST;
filterMag = GL_NEAREST;
@ -48,6 +53,9 @@ class PostEffect {
fb_.Bind();
fb_.attachment!(GL_COLOR_ATTACHMENT0, 0, GL_TEXTURE_RECTANGLE) = tex_;
fb_.attachmentOrder = [GL_COLOR_ATTACHMENT0];
fb_.attachment!GL_DEPTH_ATTACHMENT = depth_;
fb_.Validate();
fb_.Unbind();
}
@ -78,6 +86,8 @@ class PostEffect {
TextureRectRef tex_;
RenderbufferRef depth_;
SamplerRef sampler_;
}

View File

@ -9,16 +9,17 @@ public {
import sjscript : ScriptException;
import sjplayer.Context,
sjplayer.PostEffect,
sjplayer.ProgramSet,
sjplayer.ScriptRuntimeException;
}
///
Context CreateContextFromText(string src, vec2i window_size, ProgramSet programs) {
return src.CreateScriptAst().CreateContextFromScriptAst(window_size, programs);
Context CreateContextFromText(string src, PostEffect posteffect, ProgramSet programs) {
return src.CreateScriptAst().CreateContextFromScriptAst(posteffect, programs);
}
///
Context CreateContextFromScriptAst(
ParametersBlock[] params, vec2i window_size, ProgramSet programs) {
return new Context(params, window_size, programs);
ParametersBlock[] params, PostEffect posteffect, ProgramSet programs) {
return new Context(params, posteffect, programs);
}

View File

@ -94,8 +94,6 @@ private auto CreateWindow(ref in Args args) {
sfWindow_setActive(win, true).enforce;
gl.ApplyContext();
gl.Enable(GL_BLEND);
gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
static struct Window {
public:

View File

@ -21,7 +21,6 @@ class AbstractGame {
}
///
void Draw() {
gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
scene_.Draw();
}

View File

@ -7,6 +7,10 @@ import std.algorithm,
std.json,
std.path;
import gl4d;
static import sjplayer;
import sj.AbstractGame,
sj.Args,
sj.FontSet,
@ -35,11 +39,15 @@ class Game : AbstractGame {
fonts_ = new FontSet;
programs_ = new ProgramSet;
posteffect_ = new sjplayer.PostEffect(
programs_.Get!(sjplayer.PostEffectProgram),
vec2i(args.window_size, args.window_size));
lobby_ = new LobbyWorld(programs_);
title_ = new TitleScene(lobby_, programs_);
select_ = new SelectScene(lobby_, programs_, fonts_, music_list_);
load_ = new LoadingScene(args, lobby_, programs_, fonts_);
load_ = new LoadingScene(lobby_, posteffect_, programs_, fonts_);
play_ = new PlayScene;
result_ = new ResultScene(lobby_, programs_, fonts_);
@ -59,6 +67,11 @@ class Game : AbstractGame {
title_.Initialize();
super(title_);
}
// setup OpenGL
gl.Enable(GL_BLEND);
gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl.Disable(GL_DEPTH_TEST);
}
~this() {
@ -69,6 +82,7 @@ class Game : AbstractGame {
result_.destroy();
lobby_.destroy();
posteffect_.destroy();
fonts_.destroy();
programs_.destroy();
@ -76,13 +90,26 @@ class Game : AbstractGame {
music_list_.each!destroy();
}
override void Draw() {
gl.Clear(GL_COLOR_BUFFER_BIT);
posteffect_.BindFramebuffer();
gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
super.Draw();
posteffect_.UnbindFramebuffer();
posteffect_.DrawFramebuffer();
}
private:
Music[] music_list_;
FontSet fonts_;
ProgramSet programs_;
LobbyWorld lobby_;
sjplayer.PostEffect posteffect_;
LobbyWorld lobby_;
TitleScene title_;
SelectScene select_;

View File

@ -3,8 +3,9 @@ module sj.LoadingScene;
import gl4d;
import sj.Args,
sj.FontSet,
static import sjplayer;
import sj.FontSet,
sj.KeyInput,
sj.LobbyWorld,
sj.Music,
@ -17,14 +18,14 @@ class LoadingScene : SceneInterface {
public:
///
this(
in ref Args args,
LobbyWorld lobby,
ProgramSet programs,
FontSet fonts) {
args_ = args;
lobby_ = lobby;
programs_ = programs;
fonts_ = fonts;
LobbyWorld lobby,
sjplayer.PostEffect posteffect,
ProgramSet programs,
FontSet fonts) {
lobby_ = lobby;
posteffect_ = posteffect;
programs_ = programs;
fonts_ = fonts;
}
~this() {
}
@ -44,8 +45,7 @@ class LoadingScene : SceneInterface {
override SceneInterface Update(KeyInput input) {
if (first_drawn_) {
// TODO: parallelize context creation
auto context = music_.CreatePlayerContext(
vec2i(args_.window_size, args_.window_size), programs_.player);
auto context = music_.CreatePlayerContext(posteffect_, programs_.player);
play_scene_.Initialize(music_, context, offset_beat_);
return play_scene_;
}
@ -57,9 +57,7 @@ class LoadingScene : SceneInterface {
}
private:
const Args args_;
PlayScene play_scene_;
sjplayer.PostEffect posteffect_;
ProgramSet programs_;
@ -67,6 +65,8 @@ class LoadingScene : SceneInterface {
LobbyWorld lobby_;
PlayScene play_scene_;
Music music_;
float offset_beat_;

View File

@ -37,15 +37,13 @@ class LobbyWorld {
///
void Draw() {
gl.Disable(GL_DEPTH_TEST);
gl.DepthMask(false);
background_.Draw();
gl.Enable(GL_DEPTH_TEST);
gl.DepthMask(true);
cube_program_.Draw(
CreateCubes(cube_matrix.Create(), cube_interval)[],
Projection, view.Create(), light_pos, cube_material);
gl.Disable(GL_DEPTH_TEST);
}
///

View File

@ -83,9 +83,9 @@ class Music {
///
sjplayer.Context CreatePlayerContext(
vec2i winsz, sjplayer.ProgramSet programs) const {
sjplayer.PostEffect posteffect, sjplayer.ProgramSet programs) const {
return sjplayer.CreateContextFromText(
script_path_.readText, winsz, programs);
script_path_.readText, posteffect, programs);
}
///

View File

@ -74,14 +74,10 @@ class PlayScene : SceneInterface {
return this;
}
override void Draw() {
context_.StartDrawing();
context_.DrawBackground();
context_.DrawElements();
context_.DrawActor();
context_.EndDrawing();
if (beat_ >= context_.length) {
context_.destroy();
}