summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-04-18 10:06:46 +0300
committerAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-04-18 11:32:43 +0300
commit125e3138ef240099df922a39f4b3d8bfebf54b48 (patch)
tree817127e9422988d63e5d2646d0af579f04baa954
parentd5569f4b01ea82ebb9221ef9ed9df71ba8ba5dd9 (diff)
downloadqtlocation-mapboxgl-125e3138ef240099df922a39f4b3d8bfebf54b48.tar.gz
Remove re-linking programs approach
Remove re-linking programs as redundant. It costs (cheaper to link once than twice) and is not that common GL API usage pattern (subjective). Initial idea was to enable work on optimization what would reduce number of attrib setup calls in case that VAO is not available (#9433). As such optimization is not implemented, we can remove re-linking. Related to closed PR #9433 and PR #11583.
-rw-r--r--src/mbgl/gl/attribute.cpp37
-rw-r--r--src/mbgl/gl/attribute.hpp25
-rw-r--r--src/mbgl/gl/program.hpp10
3 files changed, 14 insertions, 58 deletions
diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp
index 4983a8c204..5e6269b6ac 100644
--- a/src/mbgl/gl/attribute.cpp
+++ b/src/mbgl/gl/attribute.cpp
@@ -7,41 +7,14 @@ namespace gl {
using namespace platform;
-void bindAttributeLocation(Context& context, ProgramID id, AttributeLocation location, const char* name) {
- // We're using sequentially numberered attribute locations starting with 0. Therefore we can use
- // the location as a proxy for the number of attributes.
- if (location >= context.maximumVertexBindingCount) {
- // Don't bind the location on this hardware since it exceeds the limit (otherwise we'd get
- // an OpenGL error). This means we'll see rendering errors, and possibly slow rendering due
- // to unbound attributes.
+optional<AttributeLocation> queryLocation(ProgramID id, const char* name) {
+ GLint attributeLocation = MBGL_CHECK_ERROR(glGetAttribLocation(id, name));
+ if (attributeLocation != -1) {
+ return attributeLocation;
} else {
- MBGL_CHECK_ERROR(glBindAttribLocation(id, location, name));
+ return {};
}
}
-std::set<std::string> getActiveAttributes(ProgramID id) {
- std::set<std::string> activeAttributes;
-
- 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);
-
- 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
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp
index c7f9ba3fd4..34b923d3c6 100644
--- a/src/mbgl/gl/attribute.hpp
+++ b/src/mbgl/gl/attribute.hpp
@@ -24,6 +24,7 @@ using NamedAttributeLocations = std::vector<std::pair<const std::string, Attribu
class Context;
void bindAttributeLocation(Context&, ProgramID, AttributeLocation, const char * name);
std::set<std::string> getActiveAttributes(ProgramID);
+optional<AttributeLocation> queryLocation(ProgramID id, const char* name);
template <class>
class AttributeLocations;
@@ -37,24 +38,7 @@ private:
Locations locations;
public:
- AttributeLocations(Context& context, const ProgramID& id)
- : locations([&] {
- std::set<std::string> activeAttributes = getActiveAttributes(id);
-
- AttributeLocation location = 0;
- auto maybeBindLocation = [&](const char* name) -> optional<AttributeLocation> {
- if (activeAttributes.count(name)) {
- bindAttributeLocation(context, id, location, name);
- return location++;
- } else {
- return {};
- }
- };
-
- return Locations{ maybeBindLocation(
- concat_literals<&string_literal<'a', '_'>::value, &As::name>::value())... };
- }()) {
- }
+ AttributeLocations() = default;
template <class BinaryProgram>
AttributeLocations(const BinaryProgram& program)
@@ -62,6 +46,11 @@ public:
concat_literals<&string_literal<'a', '_'>::value, &As::name>::value())... } {
}
+ void queryLocations(const ProgramID& id) {
+ locations = Locations{
+ queryLocation(id, concat_literals<&string_literal<'a', '_'>::value, &As::name>::value())... };
+ }
+
NamedAttributeLocations getNamedLocations() const {
NamedAttributeLocations result;
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp
index 3757c442de..e9f47694a6 100644
--- a/src/mbgl/gl/program.hpp
+++ b/src/mbgl/gl/program.hpp
@@ -49,15 +49,9 @@ public:
const std::initializer_list<const char*>& fragmentSource)
: program(context.createProgram(
context.createShader(ShaderType::Vertex, vertexSource),
- context.createShader(ShaderType::Fragment, fragmentSource))),
- attributeLocations(context, program) {
- // Re-link program after manually binding only active attributes in Attributes::queryLocations
- context.linkProgram(program);
-
- // We have to re-initialize the uniforms state from the bindings as the uniform locations
- // get shifted on some implementations
+ context.createShader(ShaderType::Fragment, fragmentSource))) {
+ attributeLocations.queryLocations(program);
uniformStates.queryLocations(program);
-
// Texture units are specified via uniforms as well, so we need query their locations
textureStates.queryLocations(program);
}