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

This commit is contained in:
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);
}