1 /*
2     glutil.h: Represents the state of an OpenGL shader together with attached
3     buffers. The entire state can be serialized and unserialized from a file,
4     which is useful for debugging.
5 
6     This file is part of the implementation of
7 
8         Instant Field-Aligned Meshes
9         Wenzel Jakob, Daniele Panozzo, Marco Tarini, and Olga Sorkine-Hornung
10         In ACM Transactions on Graphics (Proc. SIGGRAPH Asia 2015)
11 
12     All rights reserved. Use of this source code is governed by a
13     BSD-style license that can be found in the LICENSE.txt file.
14 */
15 
16 #pragma once
17 
18 #include "serializer.h"
19 #include <nanogui/glutil.h>
20 #include <half.hpp>
21 
22 class SerializableGLShader : public nanogui::GLShader {
23 public:
SerializableGLShader()24     SerializableGLShader() : nanogui::GLShader() { }
25 
26     void load(const Serializer &serializer);
27     void save(Serializer &serializer) const;
28 
29      // Upload an Eigen matrix and convert to half precision
30      template <typename Matrix> void uploadAttrib_half(const std::string &name, const Matrix &_M, int version = -1) {
31          Eigen::Matrix<half_float::half, Eigen::Dynamic, Eigen::Dynamic> M = _M.template cast<half_float::half>();
32          uploadAttrib(name, M, version);
33      }
34 };
35