]> git.localhorst.tv Git - blank.git/commitdiff
save a little bandwidth
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 17 Dec 2015 16:22:42 +0000 (17:22 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 17 Dec 2015 16:22:42 +0000 (17:22 +0100)
12 files changed:
src/graphics/BlockMesh.hpp
src/graphics/EntityMesh.hpp
src/graphics/PrimitiveMesh.hpp
src/graphics/VertexArray.hpp
src/graphics/VertexArray.inl
src/graphics/mesh.cpp
src/model/Part.hpp
src/model/model.cpp
src/ui/ui.cpp
src/world/BlockType.hpp
src/world/block.cpp
src/world/world.cpp

index e62b601fcfa5449be2cbcd9aedf94db5b41a10b6..399ff320ddd8e06bf19387b171ed6b8684d79123 100644 (file)
@@ -15,7 +15,7 @@ class BlockMesh {
 public:
        using Position = glm::vec3;
        using TexCoord = glm::vec3;
-       using ColorMod = glm::vec3;
+       using ColorMod = glm::tvec3<unsigned char>;
        using Light = float;
        using Index = unsigned int;
 
index 6b894f909f075fdd4a230d30c9801823dbf74a0a..804bb6ede5f1a59488fdff2226b9492267c4c36a 100644 (file)
@@ -15,7 +15,7 @@ class EntityMesh {
 public:
        using Position = glm::vec3;
        using TexCoord = glm::vec3;
-       using ColorMod = glm::vec3;
+       using ColorMod = glm::tvec3<unsigned char>;
        using Normal = glm::vec3;
        using Index = unsigned int;
 
index 013bf37bde34175c57b0d13c773fa11334eb3cda..6a8b6967df6606a081ff2b5be69c428bc62ec454 100644 (file)
@@ -16,7 +16,7 @@ class PrimitiveMesh {
 
 public:
        using Position = glm::vec3;
-       using Color = glm::vec4;
+       using Color = glm::tvec4<unsigned char>;
        using Index = unsigned short;
 
        using Positions = std::vector<Position>;
@@ -50,13 +50,13 @@ public:
 
                void FillRect(
                        float w, float h,
-                       const glm::vec4 &color = glm::vec4(0.0f),
+                       const Color &color = Color(0),
                        const glm::vec2 &pivot = glm::vec2(0.0f)
                );
 
                void OutlineBox(
                        const AABB &,
-                       const glm::vec4 &color = glm::vec4(0.0f)
+                       const Color &color = Color(0)
                );
 
        };
index c1c74950e883f2e0f0296d8dfbe18884c7dc27cb..5f70f4227365849f5416b220fd36a679d011f0c7 100644 (file)
@@ -27,7 +27,7 @@ public:
        void Bind() const noexcept;
 
        template <class T>
-       void PushAttribute(std::size_t which, const std::vector<T> &data) noexcept;
+       void PushAttribute(std::size_t which, const std::vector<T> &data, bool normalized = false) noexcept;
 
        template<class T>
        void PushIndices(std::size_t which, const std::vector<T> &indices) noexcept;
@@ -41,7 +41,7 @@ private:
        template <class T>
        void AttributeData(const std::vector<T> &) noexcept;
        template <class T>
-       void AttributePointer(std::size_t which) noexcept;
+       void AttributePointer(std::size_t which, bool normalized = false) noexcept;
 
        void BindIndex(std::size_t which) const noexcept;
        template <class T>
index 1b532b7d4fd9fa8d098dec36e5dad7155067a7af..36c8fc26313157b5c52b0f91e6329d43be0f7bee 100644 (file)
@@ -48,11 +48,11 @@ void VertexArray<N>::Bind() const noexcept {
 
 template<std::size_t N>
 template <class T>
-void VertexArray<N>::PushAttribute(std::size_t which, const std::vector<T> &data) noexcept {
+void VertexArray<N>::PushAttribute(std::size_t which, const std::vector<T> &data, bool normalized) noexcept {
        BindAttribute(which);
        AttributeData(data);
        EnableAttribute(which);
-       AttributePointer<T>(which);
+       AttributePointer<T>(which, normalized);
 }
 
 template<std::size_t N>
@@ -75,12 +75,12 @@ void VertexArray<N>::AttributeData(const std::vector<T> &buf) noexcept {
 
 template<std::size_t N>
 template <class T>
-void VertexArray<N>::AttributePointer(std::size_t which) noexcept {
+void VertexArray<N>::AttributePointer(std::size_t which, bool normalized) noexcept {
        glVertexAttribPointer(
                which,              // program location
                gl_traits<T>::size, // element size
                gl_traits<T>::type, // element type
-               GL_FALSE,           // normalize to [-1,1] or [0,1] for unsigned types
+               normalized,         // normalize to [-1,1] or [0,1] for unsigned types
                0,                  // stride
                nullptr             // offset
        );
index 5cd38832174c4f040d56a6f063ea4405bbddeb2f..9cb8c92ae9736a0337a1c7f681e1a2fe1115f5c1 100644 (file)
@@ -31,8 +31,8 @@ void EntityMesh::Update(const Buffer &buf) noexcept {
        vao.Bind();
        vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
        vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
-       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
-       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
+       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods, true);
+       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods, true);
        vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
        vao.PushIndices(ATTRIB_INDEX, buf.indices);
 }
@@ -62,8 +62,8 @@ void BlockMesh::Update(const Buffer &buf) noexcept {
        vao.Bind();
        vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
        vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
-       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
-       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
+       vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods, true);
+       vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods, true);
        vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
        vao.PushIndices(ATTRIB_INDEX, buf.indices);
 }
@@ -76,7 +76,7 @@ void BlockMesh::Draw() const noexcept {
 
 void PrimitiveMesh::Buffer::FillRect(
        float w, float h,
-       const glm::vec4 &color,
+       const Color &color,
        const glm::vec2 &pivot
 ) {
        Clear();
@@ -92,7 +92,7 @@ void PrimitiveMesh::Buffer::FillRect(
        indices.assign({ 0, 2, 1, 1, 2, 3 });
 }
 
-void PrimitiveMesh::Buffer::OutlineBox(const AABB &box, const glm::vec4 &color) {
+void PrimitiveMesh::Buffer::OutlineBox(const AABB &box, const Color &color) {
        Clear();
        Reserve(8, 24);
 
@@ -124,7 +124,7 @@ void PrimitiveMesh::Update(const Buffer &buf) noexcept {
 
        vao.Bind();
        vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
-       vao.PushAttribute(ATTRIB_COLOR, buf.colors);
+       vao.PushAttribute(ATTRIB_COLOR, buf.colors, true);
        vao.PushIndices(ATTRIB_INDEX, buf.indices);
 }
 
index 97743469a85aba210d12d9048a650e2ed6d39f86..3a17f2046137b39da28699d66452932978843471 100644 (file)
@@ -56,8 +56,8 @@ private:
        std::vector<float> tex_map;
        mutable std::unique_ptr<EntityMesh> mesh;
        State initial;
-       glm::vec3 hsl_mod;
-       glm::vec3 rgb_mod;
+       glm::tvec3<unsigned char> hsl_mod;
+       glm::tvec3<unsigned char> rgb_mod;
        std::uint16_t id;
 
 };
index db44cbf21c0e351c757dcb484027c93dedd81672..ed443138e23e0d5746a551c25fd7e1f6956cf198 100644 (file)
@@ -109,8 +109,8 @@ Part::Part()
 , tex_map()
 , mesh()
 , initial()
-, hsl_mod(0.0f, 1.0f, 1.0f)
-, rgb_mod(1.0f, 1.0f, 1.0f)
+, hsl_mod(0, 255, 255)
+, rgb_mod(255, 255, 255)
 , id(0) {
 
 }
@@ -123,6 +123,7 @@ void Part::Read(TokenStreamReader &in, ResourceIndex &tex_index, const ShapeRegi
        std::string name;
        std::string shape_name;
        std::string tex_name;
+       glm::vec3 color_conv;
        in.Skip(Token::ANGLE_BRACKET_OPEN);
        while (in.HasMore() && in.Peek().type != Token::ANGLE_BRACKET_CLOSE) {
                in.ReadIdentifier(name);
@@ -135,9 +136,11 @@ void Part::Read(TokenStreamReader &in, ResourceIndex &tex_index, const ShapeRegi
                } else if (name == "orientation") {
                        in.ReadQuat(initial.orientation);
                } else if (name == "hsl_mod") {
-                       in.ReadVec(hsl_mod);
+                       in.ReadVec(color_conv);
+                       hsl_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
                } else if (name == "rgb_mod") {
-                       in.ReadVec(rgb_mod);
+                       in.ReadVec(color_conv);
+                       rgb_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
                } else if (name == "textures") {
                        in.Skip(Token::BRACKET_OPEN);
                        while (in.HasMore() && in.Peek().type != Token::BRACKET_CLOSE) {
index be4ca9f2a18072ba29039fbc0daf9f6bd57e0daa..5f60d4401d056e116422b72941965217cd26edce 100644 (file)
@@ -295,7 +295,7 @@ HUD::HUD(Environment &env, Config &config, const Player &player)
        buf.indices = std::vector<PrimitiveMesh::Index>({
                0, 1, 2, 3
        });
-       buf.colors.resize(4, { 10.0f, 10.0f, 10.0f, 1.0f });
+       buf.colors.resize(4, { 255, 255, 255, 255 });
        crosshair.Update(buf);
 }
 
index ef328d4d926feb353cf76df65810274c99939a73..3ca170a200ba65367ff604bfbada3645456714b1 100644 (file)
@@ -24,9 +24,9 @@ struct BlockType {
 
        const Shape *shape;
        std::vector<float> textures;
-       glm::vec3 hsl_mod;
-       glm::vec3 rgb_mod;
-       glm::vec3 outline_color;
+       glm::tvec3<unsigned char> hsl_mod;
+       glm::tvec3<unsigned char> rgb_mod;
+       glm::tvec3<unsigned char> outline_color;
 
        /// gravity configuration or null if not emitting gravity
        std::unique_ptr<BlockGravity> gravity;
index e99c5be254b2fbb16309ca31b946bbf0be215071..c8618939e825bebf690a9f52903493d862b0ccad 100644 (file)
@@ -74,8 +74,8 @@ std::ostream &operator <<(std::ostream &out, const Block::Turn &turn) {
 BlockType::BlockType() noexcept
 : shape(nullptr)
 , textures()
-, hsl_mod(0.0f, 1.0f, 1.0f)
-, rgb_mod(1.0f, 1.0f, 1.0f)
+, hsl_mod(0, 255, 255)
+, rgb_mod(255, 255, 255)
 , outline_color(-1, -1, -1)
 , gravity()
 , name("anonymous")
@@ -142,6 +142,7 @@ void BlockType::Read(
 ) {
        std::string name;
        in.Skip(Token::ANGLE_BRACKET_OPEN);
+       glm::vec3 color_conv;
        while (in.Peek().type != Token::ANGLE_BRACKET_CLOSE) {
                in.ReadIdentifier(name);
                in.Skip(Token::EQUALS);
@@ -163,11 +164,14 @@ void BlockType::Read(
                        }
                        in.Skip(Token::BRACKET_CLOSE);
                } else if (name == "rgb_mod") {
-                       in.ReadVec(rgb_mod);
+                       in.ReadVec(color_conv);
+                       rgb_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
                } else if (name == "hsl_mod") {
-                       in.ReadVec(hsl_mod);
+                       in.ReadVec(color_conv);
+                       hsl_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
                } else if (name == "outline") {
-                       in.ReadVec(outline_color);
+                       in.ReadVec(color_conv);
+                       outline_color = glm::tvec3<unsigned char>(color_conv * 255.0f);
                } else if (name == "gravity") {
                        gravity = BlockGravity::Read(in);
                } else if (name == "label") {
@@ -252,7 +256,7 @@ void BlockType::FillBlockMesh(
 void BlockType::OutlinePrimitiveMesh(PrimitiveMesh::Buffer &buf) const noexcept {
        if (!shape) return;
        shape->Outline(buf);
-       buf.colors.insert(buf.colors.end(), shape->OutlineCount(), glm::vec4(outline_color, 1.0f));
+       buf.colors.insert(buf.colors.end(), shape->OutlineCount(), glm::tvec4<unsigned char>(outline_color, 255));
 }
 
 
index 243fb8a81b439655193b21615a84eddc7b70c389..bf68a9eca412f295c977e486c465e0794025366a 100644 (file)
@@ -1072,7 +1072,7 @@ void World::RenderDebug(Viewport &viewport) {
        PrimitiveMesh debug_mesh;
        PlainColor &prog = viewport.WorldColorProgram();
        for (const Entity &entity : entities) {
-               debug_buf.OutlineBox(entity.Bounds(), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
+               debug_buf.OutlineBox(entity.Bounds(), glm::tvec4<unsigned char>(255, 0, 0, 255));
                debug_mesh.Update(debug_buf);
                prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords()));
                debug_mesh.DrawLines();