summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/program.hpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-03-15 18:43:58 +0100
committerKonstantin Käfer <mail@kkaefer.com>2017-03-22 15:59:10 +0100
commit3c91b6b7de487993e75de552ba44249740644e42 (patch)
tree69b8b2642b3d8496657db92459b0a23e130b501d /src/mbgl/gl/program.hpp
parentd20327844cac88b6bf42b201eac35e816a189a8a (diff)
downloadqtlocation-mapboxgl-3c91b6b7de487993e75de552ba44249740644e42.tar.gz
[core] cache binary shaders on Android
Diffstat (limited to 'src/mbgl/gl/program.hpp')
-rw-r--r--src/mbgl/gl/program.hpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp
index fa0470796e..7d7fca5263 100644
--- a/src/mbgl/gl/program.hpp
+++ b/src/mbgl/gl/program.hpp
@@ -24,11 +24,29 @@ public:
using AttributeBindings = typename Attributes::Bindings;
Program(Context& context, const std::string& vertexSource, const std::string& fragmentSource)
- : vertexShader(context.createShader(ShaderType::Vertex, vertexSource)),
- fragmentShader(context.createShader(ShaderType::Fragment, fragmentSource)),
- program(context.createProgram(vertexShader, fragmentShader)),
- attributeLocations(Attributes::locations(program)),
- uniformsState((context.linkProgram(program), Uniforms::state(program))) {}
+ : program(
+ context.createProgram(context.createShader(ShaderType::Vertex, vertexSource),
+ context.createShader(ShaderType::Fragment, fragmentSource))),
+ attributeLocations(Attributes::bindLocations(program)),
+ uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))) {
+ }
+
+ template <class BinaryProgram>
+ Program(Context& context, const BinaryProgram& binaryProgram)
+ : program(context.createProgram(binaryProgram.format(), binaryProgram.code())),
+ attributeLocations(Attributes::loadNamedLocations(binaryProgram)),
+ uniformsState(Uniforms::loadNamedLocations(binaryProgram)) {
+ }
+
+ template <class BinaryProgram>
+ optional<BinaryProgram> get(Context& context, const std::string& identifier) const {
+ if (auto binaryProgram = context.getBinaryProgram(program)) {
+ return BinaryProgram{ binaryProgram->first, std::move(binaryProgram->second),
+ identifier, Attributes::getNamedLocations(attributeLocations),
+ Uniforms::getNamedLocations(uniformsState) };
+ }
+ return {};
+ }
template <class DrawMode>
void draw(Context& context,
@@ -64,8 +82,6 @@ public:
}
private:
- UniqueShader vertexShader;
- UniqueShader fragmentShader;
UniqueProgram program;
typename Attributes::Locations attributeLocations;