summaryrefslogtreecommitdiff
path: root/src/objects
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2020-10-29 16:49:28 -0400
committerAndrew Opalach <andrew@akon.city> 2020-10-29 16:49:28 -0400
commit96d9a4f8b0b252a185e7e685fbb7efb446699778 (patch)
tree7b82e7c5a897ab73e7c1252d84d5df5b81d2c0d8 /src/objects
parent99c22028164d423377a37873572cb1654756591f (diff)
downloadmauri-96d9a4f8b0b252a185e7e685fbb7efb446699778.tar.gz
mauri-96d9a4f8b0b252a185e7e685fbb7efb446699778.tar.bz2
mauri-96d9a4f8b0b252a185e7e685fbb7efb446699778.zip
fix alternating framebuffers on objects, add toggleable drawing
Diffstat (limited to 'src/objects')
-rw-r--r--src/objects/object.cc25
-rw-r--r--src/objects/object.h3
-rw-r--r--src/objects/pass.cc57
-rw-r--r--src/objects/pass.h7
-rw-r--r--src/objects/scene.cc4
5 files changed, 49 insertions, 47 deletions
diff --git a/src/objects/object.cc b/src/objects/object.cc
index ab6d7d1..d7d7aaa 100644
--- a/src/objects/object.cc
+++ b/src/objects/object.cc
@@ -27,11 +27,13 @@ Object::Object(Parser &p, json &root)
for (auto &id : root["dependencies"])
deps.push_back(id);
- // Filter deps that are either the same as this objects
- // id or repeated. This could be handled be sorting objects
+ // Filter deps that are either have the same id as this
+ // object or are repeated. This could be handled be sorting objects
// on the scene in order of deps but I'm not sure if that would
// break other things.
- for (auto it = deps.begin(); it != deps.end();)
+ std::vector<int>::const_iterator it = deps.begin();
+
+ while (it != deps.end())
{
bool remove = false;
@@ -50,7 +52,7 @@ Object::Object(Parser &p, json &root)
}
if (remove) deps.erase(it);
- else it++;
+ else ++it;
}
p.get_value<vec3>(root, "angles", &angles, vec3(0.f));
@@ -79,6 +81,7 @@ Object::Object(Parser &p, json &root)
for (auto &effect : root["effects"])
{
effects.emplace_back(new Effect(p, effect));
+
}
}
@@ -107,7 +110,7 @@ void Object::get_model(f32 width, f32 height, bool flip)
void Object::load(Engine *engine)
{
- if (loaded_as_dep)
+ if (loaded_as_dep || loaded)
return;
for (auto &dep : deps)
@@ -144,7 +147,6 @@ void Object::load(Engine *engine)
origin[1] = size[1] / 2.f;
}
-
std::stringstream _buffer_a, _buffer_b;
_buffer_a << "_rt_imageLayerComposite_" << id << "_a";
@@ -195,9 +197,11 @@ void Object::load(Engine *engine)
{
// If there are effects but no visible effects, make sure
// combine is set on the background pass.
- this->passes.back()->combine = true;
+ passes.back()->combine = true;
}
}
+
+ loaded = true;
}
void Object::update(Engine *engine)
@@ -208,13 +212,18 @@ void Object::draw(Engine *engine)
{
for (auto &dep : deps)
{
- //engine->scene->get_object_by_id(dep)->draw(engine);
+ engine->scene->get_object_by_id(dep)->draw(engine);
}
#if FRAME_STEP
std::cout << name << " (model):\n";
#endif
+ // Reset this every frame so avoid passes that target one of
+ // this objects buffers to get a different result every other
+ // frame.
+ buffer_switch = true;
+
for (auto &pass : passes)
{
#if FRAME_STEP
diff --git a/src/objects/object.h b/src/objects/object.h
index 138c6e0..3250b31 100644
--- a/src/objects/object.h
+++ b/src/objects/object.h
@@ -69,6 +69,7 @@ class Object
std::vector<Effect *> effects;
+ bool loaded = false;
bool loaded_as_dep = false;
void load(Engine *engine);
@@ -83,7 +84,7 @@ class Object
std::string buffer_a;
std::string buffer_b;
- bool buffer_switch = false;
+ bool buffer_switch;
Model *image = nullptr;
};
diff --git a/src/objects/pass.cc b/src/objects/pass.cc
index 00a5eae..f3a3509 100644
--- a/src/objects/pass.cc
+++ b/src/objects/pass.cc
@@ -62,6 +62,8 @@ Pass::Pass(Parser &p, json &root, PassStage stage)
if (_source.is_string())
source = _source;
+ binds[0] = "previous";
+
for (auto &bind : root["bind"])
{
u32 index = bind["index"];
@@ -78,13 +80,6 @@ Pass::Pass(Parser &p, json &root, PassStage stage)
auto _textures = root["textures"];
- /*
- if (_textures.is_array())
- {
- textures.fill("null");
- }
- */
-
for (int i = 0; i < _textures.size(); i++)
{
auto texture = _textures[i];
@@ -92,14 +87,6 @@ Pass::Pass(Parser &p, json &root, PassStage stage)
{
textures[i] = texture;
}
- else
- {
- // "null" in this case is different that empty
- // because it means that this texture was listed
- // in the pass, whereas empty strings where not.
- // "null" means use default and apply combos
- textures[i] = "null";
- }
}
for (auto &combo : root["combos"].items())
@@ -115,10 +102,6 @@ void Pass::load(Engine *engine, PassStage stage, Pass *pass)
if (textures[i].empty())
continue;
- // Only set pass->textures[i] to "null" if its not already set.
- if (textures[i] == "null" && !pass->textures[i].empty())
- continue;
-
pass->textures[i] = textures[i];
}
@@ -149,10 +132,10 @@ void Pass::load(Engine *engine, PassStage stage, Pass *pass)
if (binds[i].empty())
continue;
- if (binds[i] == "previous")
- pass->textures[i] = "";
- else
- pass->textures[i] = binds[i] + pass->effect->buffer_id;
+ pass->textures[i] = binds[i];
+
+ if (pass->textures[i] != "previous")
+ pass->textures[i] += pass->effect->buffer_id;
}
if (material != nullptr)
@@ -209,8 +192,8 @@ RenderPass::RenderPass(Engine *engine, Pass *pass)
if (!shader->textures[i].empty())
{
// If there is no texture at "i" use default shader from the texture.
- if (pass->textures[i] == "null")
- pass->textures[i] = shader->textures[i];
+ //if (pass->textures[i].empty())
+ // pass->textures[i] = shader->textures[i];
if (!shader->texture_combos[i].empty() && !pass->textures[i].empty())
pass->combos.push_back(Combo { shader->texture_combos[i], 1 });
@@ -219,6 +202,14 @@ RenderPass::RenderPass(Engine *engine, Pass *pass)
if (pass->textures[i].empty())
continue;
+ if (pass->textures[i] == "previous")
+ {
+ texture_types[i] = PREVIOUS;
+ continue;
+ }
+
+ texture_types[i] = STATIC;
+
// Check if texture is referencing a framebuffer.
textures[i] = engine->get_framebuffer_texture(pass->textures[i]);
@@ -367,15 +358,9 @@ void RenderPass::draw(Engine *engine)
for (int i = 0; i < shader->texture_count; i++)
{
- if (textures[i] != nullptr && !textures[i]->dynamic)
- continue;
-
- auto texture = engine->get_framebuffer_texture(object->get_texture_buffer());
-
- if (texture != nullptr)
+ if (texture_types[i] == PREVIOUS)
{
- texture->dynamic = true;
- textures[i] = texture;
+ textures[i] = engine->get_framebuffer_texture(object->get_texture_buffer());
}
}
@@ -401,9 +386,9 @@ void RenderPass::draw(Engine *engine)
robject->draw();
#if FRAME_STEP
- _target->buffer->blit(0, engine->context->width, engine->context->height);
- engine->context->swap_buffers();
- std::this_thread::sleep_for(std::chrono::seconds(1));
+ _target->buffer->blit(0, context()->width, context()->height);
+ context()->swap_buffers();
+ std::this_thread::sleep_for(std::chrono::seconds(2));
#endif
break;
diff --git a/src/objects/pass.h b/src/objects/pass.h
index ad645bf..cf31ca8 100644
--- a/src/objects/pass.h
+++ b/src/objects/pass.h
@@ -31,6 +31,12 @@ enum PassCommand
COPY
};
+enum TextureType
+{
+ STATIC,
+ PREVIOUS
+};
+
struct UniformOverride
{
vec4 value;
@@ -82,6 +88,7 @@ class RenderPass
Shader *shader = nullptr;
std::array<Texture *, MAX_TEXTURES> textures = {0};
+ std::array<TextureType, MAX_TEXTURES> texture_types;
void draw(Engine *engine);
diff --git a/src/objects/scene.cc b/src/objects/scene.cc
index b39921c..97b9f58 100644
--- a/src/objects/scene.cc
+++ b/src/objects/scene.cc
@@ -75,8 +75,8 @@ void Scene::draw(Engine *engine)
{
for (auto &object : objects)
{
- //if (object->loaded_as_dep)
- // continue;
+ if (object->loaded_as_dep)
+ continue;
object->draw(engine);
}
}