summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/attribute.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/gl/attribute.cpp')
-rw-r--r--src/mbgl/gl/attribute.cpp71
1 files changed, 25 insertions, 46 deletions
diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp
index e05ca75866..bb5b2ddc34 100644
--- a/src/mbgl/gl/attribute.cpp
+++ b/src/mbgl/gl/attribute.cpp
@@ -1,60 +1,39 @@
#include <mbgl/gl/attribute.hpp>
-#include <mbgl/gl/context.hpp>
#include <mbgl/gl/gl.hpp>
namespace mbgl {
namespace gl {
-AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) {
+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;
}
-void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t) const {
- MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
-}
+std::set<std::string> getActiveAttributes(ProgramID id) {
+ std::set<std::string> activeAttributes;
-template <class T> DataType DataTypeOf = static_cast<DataType>(0);
-template <> DataType DataTypeOf< int8_t> = DataType::Byte;
-template <> DataType DataTypeOf<uint8_t> = DataType::UnsignedByte;
-template <> DataType DataTypeOf< int16_t> = DataType::Short;
-template <> DataType DataTypeOf<uint16_t> = DataType::UnsignedShort;
-template <> DataType DataTypeOf< int32_t> = DataType::Integer;
-template <> DataType DataTypeOf<uint32_t> = DataType::UnsignedInteger;
-template <> DataType DataTypeOf<float> = DataType::Float;
-
-template <class T, std::size_t N>
-void AttributeBinding<T, N>::bind(Context& context, AttributeLocation location, std::size_t vertexOffset) const {
- 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))));
-}
+ GLint attributeCount;
+ MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &attributeCount));
+
+ GLint maxAttributeLength;
+ MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeLength));
+
+ std::string attributeName;
+ attributeName.resize(maxAttributeLength);
-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>;
+ GLsizei actualLength;
+ GLint size;
+ GLenum type;
+
+ for (int32_t i = 0; i < attributeCount; i++) {
+ MBGL_CHECK_ERROR(glGetActiveAttrib(id, i, maxAttributeLength, &actualLength, &size, &type, &attributeName[0]));
+ activeAttributes.emplace(std::string(attributeName, 0, actualLength));
+ }
+
+ return activeAttributes;
+}
} // namespace gl
} // namespace mbgl