#include #include #include #include namespace mbgl { namespace gl { AttributeLocation bindAttributeLocation(ProgramID id, AttributeLocation location, const char* name) { assert(location < 8); MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name)); return location; } int32_t getActiveAttributeCount(ProgramID id) { GLint numAttributes; MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTES, &numAttributes)); return numAttributes; } int32_t getMaxAttributeNameLength(ProgramID id) { GLint nameLength; MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &nameLength)); return nameLength; } std::string getAttributeName(ProgramID id, int32_t maxLength, AttributeLocation location) { std::string attributeName; attributeName.resize(maxLength); GLsizei actualLength; GLint size; GLenum type; MBGL_CHECK_ERROR(glGetActiveAttrib(id, static_cast(location), static_cast(maxLength), &actualLength, &size, &type, const_cast(attributeName.data()))); attributeName.resize(actualLength); return attributeName; } std::set getActiveAttributes(ProgramID id) { std::set activeAttributes; GLint attributeCount = getActiveAttributeCount(id); GLint maxAttributeLength = getMaxAttributeNameLength(id); for (int32_t i = 0; i < attributeCount; i++) { activeAttributes.emplace(getAttributeName(id, maxAttributeLength, i)); } return activeAttributes; } void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t) const { MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); } template DataType DataTypeOf = static_cast(0); template <> DataType DataTypeOf< int8_t> = DataType::Byte; template <> DataType DataTypeOf = DataType::UnsignedByte; template <> DataType DataTypeOf< int16_t> = DataType::Short; template <> DataType DataTypeOf = DataType::UnsignedShort; template <> DataType DataTypeOf< int32_t> = DataType::Integer; template <> DataType DataTypeOf = DataType::UnsignedInteger; template <> DataType DataTypeOf = DataType::Float; template void AttributeBinding::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(attributeSize), static_cast(DataTypeOf), static_cast(false), static_cast(vertexSize), reinterpret_cast(attributeOffset + (vertexSize * vertexOffset)))); } template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; template class AttributeBinding; } // namespace gl } // namespace mbgl