]> git.localhorst.tv Git - blank.git/blobdiff - src/model/model.cpp
allow hsl color shifts for blocks and entities
[blank.git] / src / model / model.cpp
index 72de1dadfa304f9d0026e30411def46cc022a839..cc6e20e788d2ca6e721c943f871b209920dfdac5 100644 (file)
@@ -1,8 +1,11 @@
 #include "BlockModel.hpp"
 #include "EntityModel.hpp"
 #include "OutlineModel.hpp"
+#include "SkyBoxModel.hpp"
 #include "SpriteModel.hpp"
 
+#include "shapes.hpp"
+
 #include <algorithm>
 #include <iostream>
 
@@ -14,8 +17,11 @@ void EntityModel::Update(const Buffer &buf) noexcept {
        if (buf.tex_coords.size() < buf.vertices.size()) {
                std::cerr << "EntityModel: not enough tex coords!" << std::endl;
        }
-       if (buf.colors.size() < buf.vertices.size()) {
-               std::cerr << "EntityModel: not enough colors!" << std::endl;
+       if (buf.hsl_mods.size() < buf.vertices.size()) {
+               std::cerr << "BlockModel: not enough HSL modifiers!" << std::endl;
+       }
+       if (buf.rgb_mods.size() < buf.vertices.size()) {
+               std::cerr << "BlockModel: not enough RGB modifiers!" << std::endl;
        }
        if (buf.normals.size() < buf.vertices.size()) {
                std::cerr << "EntityModel: not enough normals!" << std::endl;
@@ -25,7 +31,8 @@ void EntityModel::Update(const Buffer &buf) noexcept {
        vao.Bind();
        vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
        vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
-       vao.PushAttribute(ATTRIB_COLOR, buf.colors);
+       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
+       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
        vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
        vao.PushIndices(ATTRIB_INDEX, buf.indices);
 }
@@ -41,8 +48,11 @@ void BlockModel::Update(const Buffer &buf) noexcept {
        if (buf.tex_coords.size() < buf.vertices.size()) {
                std::cerr << "BlockModel: not enough tex coords!" << std::endl;
        }
-       if (buf.colors.size() < buf.vertices.size()) {
-               std::cerr << "BlockModel: not enough colors!" << std::endl;
+       if (buf.hsl_mods.size() < buf.vertices.size()) {
+               std::cerr << "BlockModel: not enough HSL modifiers!" << std::endl;
+       }
+       if (buf.rgb_mods.size() < buf.vertices.size()) {
+               std::cerr << "BlockModel: not enough RGB modifiers!" << std::endl;
        }
        if (buf.lights.size() < buf.vertices.size()) {
                std::cerr << "BlockModel: not enough lights!" << std::endl;
@@ -52,7 +62,8 @@ void BlockModel::Update(const Buffer &buf) noexcept {
        vao.Bind();
        vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
        vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
-       vao.PushAttribute(ATTRIB_COLOR, buf.colors);
+       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
+       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
        vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
        vao.PushIndices(ATTRIB_INDEX, buf.indices);
 }
@@ -84,6 +95,24 @@ void OutlineModel::Draw() noexcept {
 }
 
 
+void SkyBoxModel::LoadUnitBox() {
+       Buffer buffer;
+       CuboidShape shape({{ -1, -1, -1 }, { 1, 1, 1 }});
+       shape.Vertices(buffer);
+       Update(buffer);
+}
+
+void SkyBoxModel::Update(const Buffer &buf) noexcept {
+       vao.Bind();
+       vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
+       vao.PushIndices(ATTRIB_INDEX, buf.indices);
+}
+
+void SkyBoxModel::Draw() const noexcept {
+       vao.DrawTriangleElements();
+}
+
+
 void SpriteModel::Buffer::LoadRect(
        float w, float h,
        const glm::vec2 &pivot,