From: Daniel Karbach Date: Thu, 17 Dec 2015 16:22:42 +0000 (+0100) Subject: save a little bandwidth X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=f071bb512a09cece895e65ca48eba2a7155d6593;p=blank.git save a little bandwidth --- diff --git a/src/graphics/BlockMesh.hpp b/src/graphics/BlockMesh.hpp index e62b601..399ff32 100644 --- a/src/graphics/BlockMesh.hpp +++ b/src/graphics/BlockMesh.hpp @@ -15,7 +15,7 @@ class BlockMesh { public: using Position = glm::vec3; using TexCoord = glm::vec3; - using ColorMod = glm::vec3; + using ColorMod = glm::tvec3; using Light = float; using Index = unsigned int; diff --git a/src/graphics/EntityMesh.hpp b/src/graphics/EntityMesh.hpp index 6b894f9..804bb6e 100644 --- a/src/graphics/EntityMesh.hpp +++ b/src/graphics/EntityMesh.hpp @@ -15,7 +15,7 @@ class EntityMesh { public: using Position = glm::vec3; using TexCoord = glm::vec3; - using ColorMod = glm::vec3; + using ColorMod = glm::tvec3; using Normal = glm::vec3; using Index = unsigned int; diff --git a/src/graphics/PrimitiveMesh.hpp b/src/graphics/PrimitiveMesh.hpp index 013bf37..6a8b696 100644 --- a/src/graphics/PrimitiveMesh.hpp +++ b/src/graphics/PrimitiveMesh.hpp @@ -16,7 +16,7 @@ class PrimitiveMesh { public: using Position = glm::vec3; - using Color = glm::vec4; + using Color = glm::tvec4; using Index = unsigned short; using Positions = std::vector; @@ -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) ); }; diff --git a/src/graphics/VertexArray.hpp b/src/graphics/VertexArray.hpp index c1c7495..5f70f42 100644 --- a/src/graphics/VertexArray.hpp +++ b/src/graphics/VertexArray.hpp @@ -27,7 +27,7 @@ public: void Bind() const noexcept; template - void PushAttribute(std::size_t which, const std::vector &data) noexcept; + void PushAttribute(std::size_t which, const std::vector &data, bool normalized = false) noexcept; template void PushIndices(std::size_t which, const std::vector &indices) noexcept; @@ -41,7 +41,7 @@ private: template void AttributeData(const std::vector &) noexcept; template - 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 diff --git a/src/graphics/VertexArray.inl b/src/graphics/VertexArray.inl index 1b532b7..36c8fc2 100644 --- a/src/graphics/VertexArray.inl +++ b/src/graphics/VertexArray.inl @@ -48,11 +48,11 @@ void VertexArray::Bind() const noexcept { template template -void VertexArray::PushAttribute(std::size_t which, const std::vector &data) noexcept { +void VertexArray::PushAttribute(std::size_t which, const std::vector &data, bool normalized) noexcept { BindAttribute(which); AttributeData(data); EnableAttribute(which); - AttributePointer(which); + AttributePointer(which, normalized); } template @@ -75,12 +75,12 @@ void VertexArray::AttributeData(const std::vector &buf) noexcept { template template -void VertexArray::AttributePointer(std::size_t which) noexcept { +void VertexArray::AttributePointer(std::size_t which, bool normalized) noexcept { glVertexAttribPointer( which, // program location gl_traits::size, // element size gl_traits::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 ); diff --git a/src/graphics/mesh.cpp b/src/graphics/mesh.cpp index 5cd3883..9cb8c92 100644 --- a/src/graphics/mesh.cpp +++ b/src/graphics/mesh.cpp @@ -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); } diff --git a/src/model/Part.hpp b/src/model/Part.hpp index 9774346..3a17f20 100644 --- a/src/model/Part.hpp +++ b/src/model/Part.hpp @@ -56,8 +56,8 @@ private: std::vector tex_map; mutable std::unique_ptr mesh; State initial; - glm::vec3 hsl_mod; - glm::vec3 rgb_mod; + glm::tvec3 hsl_mod; + glm::tvec3 rgb_mod; std::uint16_t id; }; diff --git a/src/model/model.cpp b/src/model/model.cpp index db44cbf..ed44313 100644 --- a/src/model/model.cpp +++ b/src/model/model.cpp @@ -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(color_conv * 255.0f); } else if (name == "rgb_mod") { - in.ReadVec(rgb_mod); + in.ReadVec(color_conv); + rgb_mod = glm::tvec3(color_conv * 255.0f); } else if (name == "textures") { in.Skip(Token::BRACKET_OPEN); while (in.HasMore() && in.Peek().type != Token::BRACKET_CLOSE) { diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index be4ca9f..5f60d44 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -295,7 +295,7 @@ HUD::HUD(Environment &env, Config &config, const Player &player) buf.indices = std::vector({ 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); } diff --git a/src/world/BlockType.hpp b/src/world/BlockType.hpp index ef328d4..3ca170a 100644 --- a/src/world/BlockType.hpp +++ b/src/world/BlockType.hpp @@ -24,9 +24,9 @@ struct BlockType { const Shape *shape; std::vector textures; - glm::vec3 hsl_mod; - glm::vec3 rgb_mod; - glm::vec3 outline_color; + glm::tvec3 hsl_mod; + glm::tvec3 rgb_mod; + glm::tvec3 outline_color; /// gravity configuration or null if not emitting gravity std::unique_ptr gravity; diff --git a/src/world/block.cpp b/src/world/block.cpp index e99c5be..c861893 100644 --- a/src/world/block.cpp +++ b/src/world/block.cpp @@ -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(color_conv * 255.0f); } else if (name == "hsl_mod") { - in.ReadVec(hsl_mod); + in.ReadVec(color_conv); + hsl_mod = glm::tvec3(color_conv * 255.0f); } else if (name == "outline") { - in.ReadVec(outline_color); + in.ReadVec(color_conv); + outline_color = glm::tvec3(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(outline_color, 255)); } diff --git a/src/world/world.cpp b/src/world/world.cpp index 243fb8a..bf68a9e 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -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(255, 0, 0, 255)); debug_mesh.Update(debug_buf); prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords())); debug_mesh.DrawLines();