summaryrefslogtreecommitdiff
path: root/src/objects
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2020-10-21 18:58:37 -0400
committerAndrew Opalach <andrew@akon.city> 2020-10-21 18:58:37 -0400
commitf3a2a07b3bd7984f851f9f4816e115043b76e923 (patch)
tree97657f8528189a10a3508adde1cb102477923038 /src/objects
parenta0d9d214d20c236682b20f18e4250c5f5f4e654d (diff)
downloadmauri-f3a2a07b3bd7984f851f9f4816e115043b76e923.tar.gz
mauri-f3a2a07b3bd7984f851f9f4816e115043b76e923.tar.bz2
mauri-f3a2a07b3bd7984f851f9f4816e115043b76e923.zip
wip gif
Diffstat (limited to 'src/objects')
-rw-r--r--src/objects/object.cc8
-rw-r--r--src/objects/object.h4
-rw-r--r--src/objects/pass.cc83
-rw-r--r--src/objects/pass.h1
4 files changed, 47 insertions, 49 deletions
diff --git a/src/objects/object.cc b/src/objects/object.cc
index 600e2a6..8e6cc3d 100644
--- a/src/objects/object.cc
+++ b/src/objects/object.cc
@@ -30,10 +30,12 @@ Object::Object(Parser &p, json &root)
p.get_value<vec2>(root, "size", &size, vec2(0.f));
p.get_value<vec3>(root, "scale", &scale, vec3(0.f));
p.get_value<vec3>(root, "origin", &origin, vec3(0.f));
- origin[2] = 0.f;
+ //origin[2] = 0.f;
p.get_value<s32>(root, "colorBlendMode", &color_blend_mode, 0);
+ p.get_value<f32>(root, "alpha", &alpha, 1.f);
+
p.get_value<bool>(root, "visible", &visible, true);
auto _image = root["image"];
@@ -56,8 +58,7 @@ void Object::get_model(f32 width, f32 height, bool flip)
{
model = mat4x4(1.f);
- model = glm::translate(model, vec3{-width, -height, 0.f});
-
+ model = glm::translate(model, vec3{-width, -height, -origin[2]});
model = glm::translate(model, origin * 2.f);
model = glm::rotate(model, angles[0], vec3{1.f, 0.f, 0.f});
@@ -66,6 +67,7 @@ void Object::get_model(f32 width, f32 height, bool flip)
model = glm::scale(model, scale);
+ //mat4x4 _ortho = glm::ortho(-width, width, height, -height, 0.0099999997764825821f, 10000.f);
mat4x4 _ortho = glm::ortho(-width, width, height, -height, 0.f, 1.f);
if (flip)
diff --git a/src/objects/object.h b/src/objects/object.h
index 00cfe86..47fe2cc 100644
--- a/src/objects/object.h
+++ b/src/objects/object.h
@@ -52,6 +52,9 @@ class Object
s32 color_blend_mode;
+ f32 alpha;
+ vec3 color;
+
std::string get_target_buffer() const;
std::string get_texture_buffer() const;
@@ -72,7 +75,6 @@ class Object
Model *image = nullptr;
vec3 angles;
- vec3 color;
vec3 origin;
vec3 scale;
diff --git a/src/objects/pass.cc b/src/objects/pass.cc
index 96a349a..2d9edf5 100644
--- a/src/objects/pass.cc
+++ b/src/objects/pass.cc
@@ -31,7 +31,8 @@ Pass::Pass(Parser &p, json &root, PassStage stage)
for (auto &value : _uniforms.items())
{
uniforms.emplace_back(
- new UniformOverride({vec4(0.f), value.key()}));
+ new UniformOverride({vec4(0.f), value.key()})
+ );
p.get_value<vec4>(_uniforms, value.key(), &uniforms.back()->value, vec4(0.f));
}
@@ -75,13 +76,23 @@ Pass::Pass(Parser &p, json &root, PassStage stage)
break;
}
- for (int i = 0; i < MAX_TEXTURES; i++)
+ auto _textures = root["textures"];
+
+ for (int i = 0; i < _textures.size(); i++)
{
- auto texture = root["textures"][i];
+ auto texture = _textures[i];
if (texture.is_string())
{
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())
@@ -97,6 +108,10 @@ 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];
}
@@ -184,9 +199,15 @@ RenderPass::RenderPass(Engine *engine, Pass *pass)
for (int i = 0; i < MAX_TEXTURES; i++)
{
- // If there is no texture at "i" use default shader from the texture.
- if (pass->textures[i].empty() && !shader->textures[i].empty())
- pass->textures[i] = shader->textures[i];
+ 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 (!shader->texture_combos[i].empty() && !pass->textures[i].empty())
+ pass->combos.push_back(Combo { shader->texture_combos[i], 1 });
+ }
if (pass->textures[i].empty())
continue;
@@ -207,7 +228,6 @@ RenderPass::RenderPass(Engine *engine, Pass *pass)
for (auto &shader_uniform : shader->uniforms)
{
- auto default_value = true;
for (auto &uniform_override : pass->uniforms)
{
if (shader_uniform->name.empty())
@@ -218,33 +238,9 @@ RenderPass::RenderPass(Engine *engine, Pass *pass)
// to the value stored in the parser. This allows changing that value
// to have instant effect.
shader_uniform->value = &uniform_override->value;
- default_value = false;
break;
}
}
- if (default_value)
- shader_uniform->value = &shader_uniform->default_value;
- }
-
- for (auto &uniform : shader->uniforms)
- {
- // ex: g_Texture2Resolution (vec4)
- // ^ index
- if (uniform->uname.compare(0, 9, "g_Texture") == 0 &&
- uniform->uname.compare(10, 10, "Resolution") == 0)
- {
- auto index = uniform->uname[9] - '0';
- if (textures[index] != nullptr)
- uniform->value = &textures[index]->texture_res;
- else
- {
- // If there is no texture at this index we assume this texture will
- // be the previous framebuffer.
- auto texture = engine->get_framebuffer_texture(object->get_texture_buffer());
- if (texture != nullptr)
- uniform->value = &texture->texture_res;
- }
- }
}
for (auto &pass_combo : pass->combos)
@@ -348,26 +344,25 @@ void RenderPass::draw(Engine *engine)
_target->buffer->bind();
- shader->bind(engine, model);
- robject->bind();
-
for (int i = 0; i < shader->texture_count; i++)
{
- if (textures[i] != nullptr)
- textures[i]->bind(i);
- else
+ if (textures[i] != nullptr && !textures[i]->dynamic)
+ continue;
+
+ auto texture = engine->get_framebuffer_texture(object->get_texture_buffer());
+
+ if (texture != nullptr)
{
- // Assume this index will be the previous framebuffer.
- auto texture = engine->get_framebuffer_texture(object->get_texture_buffer());
- if (texture != nullptr)
- texture->bind(i);
+ texture->dynamic = true;
+ textures[i] = texture;
}
}
+ shader->bind(engine, object, model, &textures);
+ robject->bind();
+
if (target == nullptr)
- {
object->swap_buffer();
- }
if (combine)
{
@@ -387,7 +382,7 @@ void RenderPass::draw(Engine *engine)
#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(2));
+ std::this_thread::sleep_for(std::chrono::seconds(1));
#endif
break;
diff --git a/src/objects/pass.h b/src/objects/pass.h
index 6b8f2a9..b84fbf3 100644
--- a/src/objects/pass.h
+++ b/src/objects/pass.h
@@ -77,7 +77,6 @@ class RenderPass
RenderPass(Engine *engine, Pass *pass);
~RenderPass();
-
Shader *shader = nullptr;
void draw(Engine *engine);