summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/texture.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/gl/texture.hpp')
-rw-r--r--src/mbgl/gl/texture.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/mbgl/gl/texture.hpp b/src/mbgl/gl/texture.hpp
new file mode 100644
index 0000000000..8230be1652
--- /dev/null
+++ b/src/mbgl/gl/texture.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <mbgl/gfx/texture.hpp>
+#include <mbgl/gl/uniform.hpp>
+#include <mbgl/util/ignore.hpp>
+
+#include <vector>
+#include <string>
+
+namespace mbgl {
+namespace gl {
+
+class Context;
+
+void bindTexture(gl::Context&, uint8_t unit, const gfx::TextureBinding&);
+
+template <class>
+class Textures;
+
+template <class... Ts>
+class Textures<TypeList<Ts...>> {
+ using State =
+ IndexedTuple<TypeList<Ts...>, TypeList<ExpandToType<Ts, gl::UniformState<uint8_t>>...>>;
+ using NamedLocations = std::vector<std::pair<const std::string, gl::UniformLocation>>;
+
+public:
+ void queryLocations(const ProgramID& id) {
+ state = State{ gl::uniformLocation(id, Ts::name())... };
+ }
+
+ template <class BinaryProgram>
+ void loadNamedLocations(const BinaryProgram& program) {
+ state = State{ program.textureLocation(Ts::name())... };
+ }
+
+ NamedLocations getNamedLocations() const {
+ return NamedLocations{ { Ts::name(), state.template get<Ts>().location }... };
+ }
+
+ void bind(gl::Context& context, const gfx::TextureBindings<TypeList<Ts...>>& bindings) {
+ util::ignore(
+ { (state.template get<Ts>() = TypeIndex<Ts, Ts...>::value,
+ gl::bindTexture(context, TypeIndex<Ts, Ts...>::value, bindings.template get<Ts>()),
+ 0)... });
+ }
+
+private:
+ State state;
+};
+
+} // namespace gl
+} // namespace mbgl