18 #ifndef ION_GFXUTILS_SHADERSOURCECOMPOSER_H_
19 #define ION_GFXUTILS_SHADERSOURCECOMPOSER_H_
63 virtual const std::string GetSource() = 0;
66 virtual bool DependsOn(
const std::string& dependency)
const = 0;
68 virtual const std::string GetDependencySource(
69 const std::string& dependency)
const = 0;
72 virtual bool SetDependencySource(
const std::string& dependency,
73 const std::string& source) = 0;
77 virtual const std::string GetDependencyName(
unsigned int id)
const = 0;
80 virtual const std::vector<std::string> GetDependencyNames()
const = 0;
85 virtual const std::vector<std::string> GetChangedDependencies() = 0;
105 const std::string& source)
106 : dependency_(dependency_name),
109 const std::string
GetSource()
override {
return source_; }
110 bool DependsOn(
const std::string& dependency)
const override {
111 return dependency == dependency_;
114 const std::string& dependency)
const override {
115 return dependency == dependency_ ? source_ : std::string();
118 const std::string& source)
override {
119 if (dependency == dependency_) {
130 std::vector<std::string> names;
131 names.push_back(dependency_);
135 return std::vector<std::string>();
143 std::string dependency_;
162 transformer_(transformer) {}
164 return transformer_(base_->GetSource());
166 bool DependsOn(
const std::string& dependency)
const override {
167 return base_->DependsOn(dependency);
170 const std::string& dependency)
const override {
171 return base_->GetDependencySource(dependency);
174 const std::string& source)
override {
175 return base_->SetDependencySource(dependency, source);
178 return base_->GetDependencyName(
id);
181 return base_->GetDependencyNames();
184 return base_->GetChangedDependencies();
189 StringFilter transformer_;
209 typedef std::function<const std::string(const std::string& name)>
213 typedef std::function<
bool(
const std::string&
name,
216 typedef std::function<
bool(
const std::string& filename,
217 std::chrono::system_clock::time_point* timestamp)>
228 bool insert_line_directives);
231 void SetBasePath(
const std::string& path);
233 const std::string GetSource()
override;
234 bool DependsOn(
const std::string& dependency)
const override;
235 const std::string GetDependencySource(
236 const std::string& dependency)
const override;
237 bool SetDependencySource(
const std::string& dependency,
238 const std::string& source)
override;
239 const std::string GetDependencyName(
unsigned int id)
const override;
240 const std::vector<std::string> GetDependencyNames()
const override;
241 const std::vector<std::string> GetChangedDependencies()
override;
248 class IncludeComposerHelper;
249 std::unique_ptr<IncludeComposerHelper> helper_;
274 #endif // ION_GFXUTILS_SHADERSOURCECOMPOSER_H_
std::function< bool(const std::string &name, const std::string &source)> SourceSaver
A function that saves a string source given a filename.
const std::string GetDependencySource(const std::string &dependency) const override
Returns the source of the passed dependency.
const std::vector< std::string > GetDependencyNames() const override
Returns a vector containing all names that this composer depends on, or an empty vector if there are ...
Loads a shader source from zip asset resources that may $input other zip assets.
const std::vector< std::string > GetDependencyNames() const override
Returns a vector containing all names that this composer depends on, or an empty vector if there are ...
bool DependsOn(const std::string &dependency) const override
Returns whether this composer depends on the named dependency, which might be a filename or some othe...
FilterComposer(const ShaderSourceComposerPtr &base, const StringFilter &transformer)
std::function< bool(const std::string &filename, std::chrono::system_clock::time_point *timestamp)> SourceModificationTime
A function that returns the last time the source in filename was modified.
Simple composer that just returns the string passed to its constructor.
bool SetDependencySource(const std::string &dependency, const std::string &source) override
Requests that the composer set the source of the dependency.
base::ReferentPtr< FilterComposer >::Type FilterComposerPtr
const std::string GetSource() override
Returns the source string of a shader.
Thread-safe abstract base class.
StringComposer(const std::string &dependency_name, const std::string &source)
base::ReferentPtr< StringComposer >::Type StringComposerPtr
const std::string GetSource() override
Returns the source string of a shader.
base::ReferentPtr< ZipAssetComposer >::Type ZipAssetComposerPtr
const std::string GetDependencyName(unsigned int id) const override
Returns the name of a dependency identified by the passed id.
~StringComposer() override
The destructor is protected since this is derived from base::Referent.
std::function< const std::string(const std::string &name)> SourceLoader
A function that returns a string source given a filename.
std::function< std::string(const std::string)> StringFilter
bool SetDependencySource(const std::string &dependency, const std::string &source) override
Requests that the composer set the source of the dependency.
const std::string GetDependencySource(const std::string &dependency) const override
Returns the source of the passed dependency.
Applies a fixed transformation to the output of another composer.
bool DependsOn(const std::string &dependency) const override
Returns whether this composer depends on the named dependency, which might be a filename or some othe...
Loads a shader source from a resource that may include other resources using the special directive '$...
const std::vector< std::string > GetChangedDependencies() override
Determines if any dependencies have changed (e.g., if a file has changed on disk since the last call ...
const std::string GetDependencyName(unsigned int id) const override
Returns the name of a dependency identified by the passed id.
A ShaderSourceComposer is a generic interface for constructing a shader source string.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
base::ReferentPtr< ShaderSourceComposer >::Type ShaderSourceComposerPtr
const std::vector< std::string > GetChangedDependencies() override
Determines if any dependencies have changed (e.g., if a file has changed on disk since the last call ...
base::ReferentPtr< IncludeComposer >::Type IncludeComposerPtr