diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-11-14 12:11:53 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-11-15 13:55:08 -0800 |
commit | 58877d1b3ddf0e4521d680b85e31b7a4c6287302 (patch) | |
tree | f844c8a12f82e40b1777ae79fe416c1eaa714470 /src/mbgl/gl/context.cpp | |
parent | 0fe8d8d7b4bbf136e8fb0f972cc31a94ddc4b67e (diff) | |
download | qtlocation-mapboxgl-58877d1b3ddf0e4521d680b85e31b7a4c6287302.tar.gz |
[core] Assign attribute locations sequentially
Two reasons to prefer explicit sequential location assignment, rather than relying on the GLSL linker to assign locations:
* For data-driven properties, we want to have the option to use glDisableVertexAttribArray plus glVertexAttrib*. In order to use glDisableVertexAttribArray, we must avoid using attribute location 0, which cannot be disabled.
* We want to use the same VAO in cases where, say, a fill layer might be rendered with FillProgram at first, and then FillPatternProgram later. VAOs do not store the program binding, only the attribute bindings, so as long as the two programs have the same attributes and attribute locations, only a single VAO (per segment) is needed.
Diffstat (limited to 'src/mbgl/gl/context.cpp')
-rw-r--r-- | src/mbgl/gl/context.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index c4485ad0fd..3251be0c87 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -68,19 +68,24 @@ UniqueProgram Context::createProgram(ShaderID vertexShader, ShaderID fragmentSha MBGL_CHECK_ERROR(glAttachShader(result, vertexShader)); MBGL_CHECK_ERROR(glAttachShader(result, fragmentShader)); - MBGL_CHECK_ERROR(glLinkProgram(result)); + + return result; +} + +void Context::linkProgram(ProgramID program_) { + MBGL_CHECK_ERROR(glLinkProgram(program_)); GLint status; - MBGL_CHECK_ERROR(glGetProgramiv(result, GL_LINK_STATUS, &status)); - if (status != 0) { - return result; + MBGL_CHECK_ERROR(glGetProgramiv(program_, GL_LINK_STATUS, &status)); + if (status == GL_TRUE) { + return; } GLint logLength; - MBGL_CHECK_ERROR(glGetProgramiv(result, GL_INFO_LOG_LENGTH, &logLength)); + MBGL_CHECK_ERROR(glGetProgramiv(program_, GL_INFO_LOG_LENGTH, &logLength)); const auto log = std::make_unique<GLchar[]>(logLength); if (logLength > 0) { - MBGL_CHECK_ERROR(glGetProgramInfoLog(result, logLength, &logLength, log.get())); + MBGL_CHECK_ERROR(glGetProgramInfoLog(program_, logLength, &logLength, log.get())); Log::Error(Event::Shader, "Program failed to link: %s", log.get()); } |