summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/attribute.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-07-03 14:05:12 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-07-12 14:48:22 -0700
commitc61041b44cd9181641db2351f4657cc356300226 (patch)
tree6a5d115c1796a52d4270ca48fbb1a0e1ce3a2ad4 /src/mbgl/gl/attribute.cpp
parentfedfaa2f6e582e87b190f5d423302f9f95d147d9 (diff)
downloadqtlocation-mapboxgl-c61041b44cd9181641db2351f4657cc356300226.tar.gz
[core] Rework attribute binding (again)
These changes are necessary for programs whose set of active attributes is not fixed at compile time by a template parameter pack, but rather varies based on the generated shader text at runtime. In such cases, the attribute location of a given named attribute may vary between instances of the same Program. Previously, attribute bindings were implicitly associated with a location based on template parameter order, and -1 was used to indicate an inactive attribute. This left us unable to disable the appropriate attribute when it went from active to inactive. Now, the state tracker for bindings explicitly associates locations and state, and an empty optional is used to indicate an inactive attribute. In addition, a gl::VertexArray class is now exposed, allowing more flexibility in the relationship between Programs, Segments, and attribute bindings. In this commit, that relationship does not change, but the subsequent commit adjusts it to match gl-js, reduce rebinds, and work around buggy VAO implementations. VertexArray uses a pimpl idiom in order to support implementations that lack the VAO extension. In that case, all VertexArrays share global binding state, reflecting the platform reality in the absence of VAOs, while still providing a uniform API.
Diffstat (limited to 'src/mbgl/gl/attribute.cpp')
-rw-r--r--src/mbgl/gl/attribute.cpp63
1 files changed, 4 insertions, 59 deletions
diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp
index 5583cfd916..bb5b2ddc34 100644
--- a/src/mbgl/gl/attribute.cpp
+++ b/src/mbgl/gl/attribute.cpp
@@ -1,16 +1,14 @@
#include <mbgl/gl/attribute.hpp>
-#include <mbgl/gl/context.hpp>
#include <mbgl/gl/gl.hpp>
-#include <cstring>
-
namespace mbgl {
namespace gl {
-AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) {
- assert(location < 8);
+void bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) {
+ if (location >= MAX_ATTRIBUTES) {
+ throw gl::Error("too many vertex attributes");
+ }
MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name));
- return location;
}
std::set<std::string> getActiveAttributes(ProgramID id) {
@@ -37,58 +35,5 @@ std::set<std::string> getActiveAttributes(ProgramID id) {
return activeAttributes;
}
-void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t) const {
- MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
-}
-
-template <class T>
-constexpr DataType DataTypeOf() {
- return std::is_same<T, int8_t>::value ? DataType::Byte :
- std::is_same<T, uint8_t>::value ? DataType::UnsignedByte :
- std::is_same<T, int16_t>::value ? DataType::Short :
- std::is_same<T, uint16_t>::value ? DataType::UnsignedShort :
- std::is_same<T, int32_t>::value ? DataType::Integer :
- std::is_same<T, uint32_t>::value ? DataType::UnsignedInteger :
- std::is_same<T, float>::value ? DataType::Float : static_cast<DataType>(0);
-}
-
-template <class T, std::size_t N>
-void AttributeBinding<T, N>::bind(Context& context, AttributeLocation location, std::size_t vertexOffset) const {
- // FillProgram will attempt to bind at location -1 because it includes
- // a fill-outline-color paint property but does not use it or have an
- // a_outline_color shader attribute - in this case, we have nothing to bind.
- if (location == -1) return;
-
- context.vertexBuffer = vertexBuffer;
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(location));
- MBGL_CHECK_ERROR(glVertexAttribPointer(
- location,
- static_cast<GLint>(attributeSize),
- static_cast<GLenum>(DataTypeOf<T>()),
- static_cast<GLboolean>(false),
- static_cast<GLsizei>(vertexSize),
- reinterpret_cast<GLvoid*>(attributeOffset + (vertexSize * vertexOffset))));
-}
-
-template class AttributeBinding<uint8_t, 1>;
-template class AttributeBinding<uint8_t, 2>;
-template class AttributeBinding<uint8_t, 3>;
-template class AttributeBinding<uint8_t, 4>;
-
-template class AttributeBinding<uint16_t, 1>;
-template class AttributeBinding<uint16_t, 2>;
-template class AttributeBinding<uint16_t, 3>;
-template class AttributeBinding<uint16_t, 4>;
-
-template class AttributeBinding<int16_t, 1>;
-template class AttributeBinding<int16_t, 2>;
-template class AttributeBinding<int16_t, 3>;
-template class AttributeBinding<int16_t, 4>;
-
-template class AttributeBinding<float, 1>;
-template class AttributeBinding<float, 2>;
-template class AttributeBinding<float, 3>;
-template class AttributeBinding<float, 4>;
-
} // namespace gl
} // namespace mbgl