MeVisLab Resolution Independence API
SoShaderBuilder.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2011, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef SO_SHADER_BUILDER_H
14#define SO_SHADER_BUILDER_H
15
16#include "SoShaderSystem.h"
17
18#include <string>
19#include <map>
20#include <sstream>
21#include <set>
22
23typedef std::vector<std::string> StringVector;
24
26{
27public:
28 struct SourceInfo {
29
30 bool isValid() const { return code.size()>0; }
31
32 std::string version;
33 std::string code;
35 };
36
37 const SourceInfo& lookup(const std::string name) const;
38
39 void insert(const std::string name, const SourceInfo& info);
40
41 void addSource(const char* data);
42
43private:
44 typedef std::map<std::string, SourceInfo> SourceInfoMap;
45
46 SourceInfoMap _repository;
47 SourceInfo _emptyInfo;
48};
49
51
53{
54public:
56 FRAGMENT_SHADER = 1,
57 VERTEX_SHADER = 2,
58 GEOMETRY_SHADER = 4
59 };
60
62
64 void addSource(const char* data);
65
68
70 std::string createShader(const std::string name, const std::vector<std::string>& directives = std::vector<std::string>(), SoShaderRepository* repository = nullptr);
71
74 SoGLCompleteShader* createCompleteShader(const std::string name, const std::vector<std::string>& directives = std::vector<std::string>(),
75 SoShaderRepository* repository = nullptr, int directivesFlag = FRAGMENT_SHADER | GEOMETRY_SHADER | VERTEX_SHADER);
76
77private:
78
79 struct ShaderString {
80
81 std::ostringstream directives;
82 std::ostringstream header;
83 std::ostringstream body;
84
85 void addDirectived(const std::vector<std::string>& directives);
86
87 std::string toString();
88
89 std::set<std::string> usedIncludes;
90 };
91
92 const SoShaderRepository::SourceInfo& lookup(const std::string name) const;
93
94 void addCode(const SoShaderRepository::SourceInfo& code, ShaderString& result);
95
96 std::vector<SoShaderRepository*> _repositories;
97 SoShaderRepository _defaultRepository;
98
100};
101
102#endif
std::vector< std::string > StringVector
#define INVENTOR_SHADER_API
Define class export specifier.
Shader class which directly takes src for vertex, geometry and/or fragment shader,...
SoGLCompleteShader * createCompleteShader(const std::string name, const std::vector< std::string > &directives=std::vector< std::string >(), SoShaderRepository *repository=nullptr, int directivesFlag=FRAGMENT_SHADER|GEOMETRY_SHADER|VERTEX_SHADER)
Creates a complete shader from the given name (.VS, .FS and .GS are appended, VS and FS are required!...
std::string createShader(const std::string name, const std::vector< std::string > &directives=std::vector< std::string >(), SoShaderRepository *repository=nullptr)
Creates the shader source for the given shader.
void addRepository(SoShaderRepository *repository)
Adds the given repository, ownership stays with the caller.
void addSource(const char *data)
adds the given source to the default repository
void addSource(const char *data)
const SourceInfo & lookup(const std::string name) const
void insert(const std::string name, const SourceInfo &info)