diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-16 13:01:43 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-17 08:27:53 -0700 |
commit | 0dca6cd9bfdb1fb77f7755d639f92a6a1ba06dc1 (patch) | |
tree | c6fac4540cd77f4e815580fcc1f584860d815132 | |
parent | 9544dcc4834bf816e9e75f0aa9937a1562b2353f (diff) | |
download | qtlocation-mapboxgl-0dca6cd9bfdb1fb77f7755d639f92a6a1ba06dc1.tar.gz |
[core] Don't need to use normalized attributes anymore
-rw-r--r-- | cmake/core-files.cmake | 1 | ||||
-rw-r--r-- | src/mbgl/gl/attribute.cpp | 47 | ||||
-rw-r--r-- | src/mbgl/gl/normalization.hpp | 35 | ||||
-rw-r--r-- | src/mbgl/programs/attributes.hpp | 9 |
4 files changed, 5 insertions, 87 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index a22523331e..b10d7cff6c 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 ff313fdcd0..eacaa37457 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -1,13 +1,10 @@ #include <mbgl/gl/attribute.hpp> #include <mbgl/gl/context.hpp> #include <mbgl/gl/gl.hpp> -#include <mbgl/gl/normalization.hpp> namespace mbgl { namespace gl { -static_assert(offsetof(Normalized<uint8_t>, 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<uint32_t> = DataType::UnsignedInteger; template <> DataType DataTypeOf<float> = DataType::Float; -template <class T> bool IsNormalized = false; -template <class T> bool IsNormalized<Normalized<T>> = true; -template <class T> DataType DataTypeOf<Normalized<T>> = DataTypeOf<T>; - template <class T, std::size_t N> void VariableAttributeBinding<T, N>::bind(Context& context, AttributeLocation location, @@ -40,7 +33,7 @@ void VariableAttributeBinding<T, N>::bind(Context& context, location, static_cast<GLint>(attributeSize), static_cast<GLenum>(DataTypeOf<T>), - static_cast<GLboolean>(IsNormalized<T>), + static_cast<GLboolean>(false), static_cast<GLsizei>(vertexSize), reinterpret_cast<GLvoid*>(attributeOffset + (vertexSize * vertexOffset)))); } @@ -50,11 +43,6 @@ template class VariableAttributeBinding<uint8_t, 2>; template class VariableAttributeBinding<uint8_t, 3>; template class VariableAttributeBinding<uint8_t, 4>; -template class VariableAttributeBinding<Normalized<uint8_t>, 1>; -template class VariableAttributeBinding<Normalized<uint8_t>, 2>; -template class VariableAttributeBinding<Normalized<uint8_t>, 3>; -template class VariableAttributeBinding<Normalized<uint8_t>, 4>; - template class VariableAttributeBinding<uint16_t, 1>; template class VariableAttributeBinding<uint16_t, 2>; template class VariableAttributeBinding<uint16_t, 3>; @@ -104,39 +92,6 @@ void ConstantAttributeBinding<uint8_t, 4>::bind(Context&, AttributeLocation loca template <> -void ConstantAttributeBinding<Normalized<uint8_t>, 1>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<Normalized<uint8_t>, 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<Normalized<uint8_t>, 2>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<Normalized<uint8_t>, 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<Normalized<uint8_t>, 3>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<Normalized<uint8_t>, 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<Normalized<uint8_t>, 4>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<Normalized<uint8_t>, 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<uint16_t, 1>::bind(Context&, AttributeLocation location, optional<VariableAttributeBinding<uint16_t, 1>>& oldBinding, std::size_t) const { assert(location != 0); oldBinding = {}; diff --git a/src/mbgl/gl/normalization.hpp b/src/mbgl/gl/normalization.hpp deleted file mode 100644 index 83fa67a3ec..0000000000 --- a/src/mbgl/gl/normalization.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include <mbgl/math/clamp.hpp> - -#include <cassert> -#include <limits> - -namespace mbgl { -namespace gl { - -template <class T> -class Normalized { -public: - T value; - - Normalized() : value(0) {} - - explicit Normalized(float f) - : value(static_cast<T>(std::numeric_limits<T>::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<T>::max(); - } -}; - -template <class T> -bool operator==(const Normalized<T>& lhs, const Normalized<T>& 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 a2e0772762..b015c06366 100644 --- a/src/mbgl/programs/attributes.hpp +++ b/src/mbgl/programs/attributes.hpp @@ -2,7 +2,6 @@ #include <mbgl/gl/attribute.hpp> #include <mbgl/gl/uniform.hpp> -#include <mbgl/gl/normalization.hpp> #include <cstdint> @@ -122,19 +121,19 @@ struct a_outline_color : gl::Attribute<float, 2> { } }; -struct a_opacity : gl::Attribute<gl::Normalized<uint8_t>, 1> { +struct a_opacity : gl::Attribute<float, 1> { static auto name() { return "a_opacity"; } static Value value(float opacity) { - return {{ gl::Normalized<uint8_t>(opacity) }}; + return {{ opacity }}; } }; -struct a_stroke_opacity : gl::Attribute<gl::Normalized<uint8_t>, 1> { +struct a_stroke_opacity : gl::Attribute<float, 1> { static auto name() { return "a_stroke_opacity"; } static Value value(float opacity) { - return {{ gl::Normalized<uint8_t>(opacity) }}; + return {{ opacity }}; } }; |