-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* -*-c++-*- */ | ||
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph | ||
* Copyright 2008-2014 Pelican Mapping | ||
* http://osgearth.org | ||
* | ||
* osgEarth is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
#ifndef OSGEARTH_SHADER_LOADER_H | ||
#define OSGEARTH_SHADER_LOADER_H 1 | ||
|
||
#include <osgEarth/Common> | ||
#include <osgDB/Options> | ||
#include <map> | ||
|
||
namespace osgEarth | ||
{ | ||
class VirtualProgram; | ||
|
||
/** | ||
* Functions to help load shader code. | ||
*/ | ||
class OSGEARTH_EXPORT ShaderPackage | ||
{ | ||
public: | ||
/** | ||
* Adds a function from this package to the VirtualProgram. | ||
*/ | ||
bool loadFunction( | ||
VirtualProgram* vp, | ||
const std::string& filename, | ||
const osgDB::Options* dbOptions =0L ) const; | ||
|
||
/** | ||
* Removes a function loaded by loadFunction from the VirtualProgram. | ||
*/ | ||
bool unloadFunction( | ||
VirtualProgram* vp, | ||
const std::string& filename, | ||
const osgDB::Options* dbOptions =0L ) const; | ||
|
||
public: | ||
typedef std::map<std::string, std::string> SourceMap; | ||
const SourceMap& context() const { return _sources; } | ||
|
||
protected: | ||
SourceMap _sources; | ||
}; | ||
|
||
/** | ||
* Base class for local shader file/source pairs. | ||
*/ | ||
class OSGEARTH_EXPORT ShaderLoader | ||
{ | ||
public: | ||
/** | ||
* Loads shader source from the specified filename, and calls | ||
* setFunction() on the virtual program to install the shader. | ||
* The shader much include #pragma definitions for both its | ||
* entry point and its location, e.g.: | ||
* | ||
* #pragma vp_entryPoint "oe_my_shader" | ||
* #pargma vp_location "VERTEX_VIEW" | ||
*/ | ||
static bool loadFunction( | ||
VirtualProgram* vp, | ||
const std::string& filename, | ||
const ShaderPackage& package, | ||
const osgDB::Options* dbOptions =0L ); | ||
|
||
/** | ||
* Removes a function loaded by loadFunction from the VirtualProgram. | ||
*/ | ||
static bool unloadFunction( | ||
VirtualProgram* vp, | ||
const std::string& filename, | ||
const ShaderPackage& package, | ||
const osgDB::Options* dbOptions =0L ); | ||
|
||
/** | ||
* Loads shader source from the specified filename. If the | ||
* file can't be found in the OSG file path, use the source | ||
* provided in backupSource. | ||
*/ | ||
static std::string load( | ||
const std::string& filename, | ||
const std::string& backupSource, | ||
const osgDB::Options* dbOptions =0L ); | ||
|
||
static std::string load( | ||
const std::string& filename, | ||
const ShaderPackage& package, | ||
const osgDB::Options* dbOptions =0L ); | ||
}; | ||
|
||
} // namespace osgEarth | ||
|
||
#endif // OSGEARTH_SHADER_LOADER |
Oops, something went wrong.