1/* -*-c++-*- */ 2/* osgEarth - Geospatial SDK for OpenSceneGraph 3 * Copyright 2019 Pelican Mapping 4 * http://osgearth.org 5 * 6 * osgEarth is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/> 18 */ 19#ifndef OSGEARTH_LAYER_SHADER_H 20#define OSGEARTH_LAYER_SHADER_H 1 21 22#include <osgEarth/Config> 23#include <osgEarth/URI> 24#include <osgEarth/TerrainResources> 25#include <osgDB/Options> 26#include <vector> 27#include <string> 28 29namespace osg { 30 class StateSet; 31} 32 33namespace osgEarth 34{ 35 class Layer; 36 37 //! Serializable shader that supports samplers and uniforms 38 //! in an earth file. 39 class ShaderOptions : public ConfigOptions 40 { 41 public: 42 META_ConfigOptions(osgEarth, ShaderOptions, ConfigOptions); 43 44 struct Sampler 45 { 46 std::string _name; 47 std::vector<URI> _uris; 48 }; 49 50 struct Uniform 51 { 52 std::string _name; 53 optional<float> _value; 54 }; 55 56 void apply(osg::StateSet*, Layer*, TerrainResources*, const osgDB::Options*); 57 58 public: 59 std::string& code() { return _code; } 60 const std::string& code() const { return _code; } 61 62 std::vector<Sampler>& samplers() { return _samplers; } 63 const std::vector<Sampler>& samplers() const { return _samplers; } 64 65 std::vector<Uniform>& uniforms() { return _uniforms; } 66 const std::vector<Uniform>& uniforms() const { return _uniforms; } 67 68 public: 69 virtual Config getConfig() const; 70 71 private: 72 void fromConfig(const Config& conf); 73 74 private: 75 std::string _code; 76 std::vector<Sampler> _samplers; 77 std::vector<Uniform> _uniforms; 78 }; 79 80 //! Encapsulates a shader attached to a Layer (or other object). 81 /* internal */ class LayerShader : public osg::Referenced 82 { 83 public: 84 LayerShader(const ShaderOptions& options); 85 86 void install(Layer* layer, TerrainResources* res); 87 88 protected: 89 virtual ~LayerShader(); 90 91 private: 92 const ShaderOptions _options; 93 std::vector<TextureImageUnitReservation> _reservations; 94 }; 95 96} // namespace osgEarth 97OSGEARTH_SPECIALIZE_CONFIG(osgEarth::ShaderOptions); 98 99#endif // OSGEARTH_LAYER_SHADER_H 100 101