From 0dca6cd9bfdb1fb77f7755d639f92a6a1ba06dc1 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 16 Mar 2017 13:01:43 -0700 Subject: [PATCH] [core] Don't need to use normalized attributes anymore --- cmake/core-files.cmake | 1 - src/mbgl/gl/attribute.cpp | 47 +------------------------------- src/mbgl/gl/normalization.hpp | 35 ------------------------ src/mbgl/programs/attributes.hpp | 9 +++--- 4 files changed, 5 insertions(+), 87 deletions(-) delete mode 100644 src/mbgl/gl/normalization.hpp diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index a22523331..b10d7cff6 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -70,7 +70,6 @@ set(MBGL_CORE_FILES src/mbgl/gl/framebuffer.hpp src/mbgl/gl/gl.cpp src/mbgl/gl/index_buffer.hpp - src/mbgl/gl/normalization.hpp src/mbgl/gl/object.cpp src/mbgl/gl/object.hpp src/mbgl/gl/primitives.hpp diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index ff313fdcd..eacaa3745 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -1,13 +1,10 @@ #include #include #include -#include namespace mbgl { namespace gl { -static_assert(offsetof(Normalized, value) == 0, "unexpected normalized offset"); - AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) { MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name)); return location; @@ -22,10 +19,6 @@ template <> DataType DataTypeOf< int32_t> = DataType::Integer; template <> DataType DataTypeOf = DataType::UnsignedInteger; template <> DataType DataTypeOf = DataType::Float; -template bool IsNormalized = false; -template bool IsNormalized> = true; -template DataType DataTypeOf> = DataTypeOf; - template void VariableAttributeBinding::bind(Context& context, AttributeLocation location, @@ -40,7 +33,7 @@ void VariableAttributeBinding::bind(Context& context, location, static_cast(attributeSize), static_cast(DataTypeOf), - static_cast(IsNormalized), + static_cast(false), static_cast(vertexSize), reinterpret_cast(attributeOffset + (vertexSize * vertexOffset)))); } @@ -50,11 +43,6 @@ template class VariableAttributeBinding; template class VariableAttributeBinding; template class VariableAttributeBinding; -template class VariableAttributeBinding, 1>; -template class VariableAttributeBinding, 2>; -template class VariableAttributeBinding, 3>; -template class VariableAttributeBinding, 4>; - template class VariableAttributeBinding; template class VariableAttributeBinding; template class VariableAttributeBinding; @@ -103,39 +91,6 @@ void ConstantAttributeBinding::bind(Context&, AttributeLocation loca } -template <> -void ConstantAttributeBinding, 1>::bind(Context&, AttributeLocation location, optional, 1>>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib1f(location, value[0].denormalized())); -} - -template <> -void ConstantAttributeBinding, 2>::bind(Context&, AttributeLocation location, optional, 2>>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib2f(location, value[0].denormalized(), value[1].denormalized())); -} - -template <> -void ConstantAttributeBinding, 3>::bind(Context&, AttributeLocation location, optional, 3>>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib3f(location, value[0].denormalized(), value[1].denormalized(), value[2].denormalized())); -} - -template <> -void ConstantAttributeBinding, 4>::bind(Context&, AttributeLocation location, optional, 4>>& oldBinding, std::size_t) const { - assert(location != 0); - oldBinding = {}; - MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); - MBGL_CHECK_ERROR(glVertexAttrib4f(location, value[0].denormalized(), value[1].denormalized(), value[2].denormalized(), value[3].denormalized())); -} - - template <> void ConstantAttributeBinding::bind(Context&, AttributeLocation location, optional>& oldBinding, std::size_t) const { assert(location != 0); diff --git a/src/mbgl/gl/normalization.hpp b/src/mbgl/gl/normalization.hpp deleted file mode 100644 index 83fa67a3e..000000000 --- a/src/mbgl/gl/normalization.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include - -#include -#include - -namespace mbgl { -namespace gl { - -template -class Normalized { -public: - T value; - - Normalized() : value(0) {} - - explicit Normalized(float f) - : value(static_cast(std::numeric_limits::max() * util::clamp(f, 0.0f, 1.0f))) { - assert(f >= 0.0f); - assert(f <= 1.0f); - } - - float denormalized() const { - return float(value) / std::numeric_limits::max(); - } -}; - -template -bool operator==(const Normalized& lhs, const Normalized& rhs) { - return lhs.value == rhs.value; -} - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp index a2e077276..b015c0636 100644 --- a/src/mbgl/programs/attributes.hpp +++ b/src/mbgl/programs/attributes.hpp @@ -2,7 +2,6 @@ #include #include -#include #include @@ -122,19 +121,19 @@ struct a_outline_color : gl::Attribute { } }; -struct a_opacity : gl::Attribute, 1> { +struct a_opacity : gl::Attribute { static auto name() { return "a_opacity"; } static Value value(float opacity) { - return {{ gl::Normalized(opacity) }}; + return {{ opacity }}; } }; -struct a_stroke_opacity : gl::Attribute, 1> { +struct a_stroke_opacity : gl::Attribute { static auto name() { return "a_stroke_opacity"; } static Value value(float opacity) { - return {{ gl::Normalized(opacity) }}; + return {{ opacity }}; } };