[core] Don't need to use normalized attributes anymore

This commit is contained in:
John Firebaugh
2017-03-16 13:01:43 -07:00
parent 9544dcc483
commit 0dca6cd9bf
4 changed files with 5 additions and 87 deletions

View File

@@ -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

View File

@@ -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>;
@@ -103,39 +91,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);

View File

@@ -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

View File

@@ -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 }};
}
};