MeVisLab Resolution Independence API
Loading...
Searching...
No Matches
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:
29 {
30
31 bool isValid() const
32 {
33 return code.size() > 0;
34 }
35
36 std::string version;
37 std::string code;
39 };
40
41 const SourceInfo& lookup(const std::string name) const;
42
43 void insert(const std::string name, const SourceInfo& info);
44
45 void addSource(const char* data);
46
47private:
48 typedef std::map<std::string, SourceInfo> SourceInfoMap;
49
50 SourceInfoMap _repository;
51 SourceInfo _emptyInfo;
52};
53
55
57{
58public:
64
66
68 void addSource(const char* data);
69
72
74 std::string createShader(const std::string name,
75 const std::vector<std::string>& directives = std::vector<std::string>(),
76 SoShaderRepository* repository = nullptr);
77
81 const std::vector<std::string>& directives = std::vector<std::string>(),
82 SoShaderRepository* repository = nullptr,
83 int directivesFlag = FRAGMENT_SHADER | GEOMETRY_SHADER | VERTEX_SHADER);
84
85private:
86 struct ShaderString
87 {
88
89 std::ostringstream directives;
90 std::ostringstream header;
91 std::ostringstream body;
92
93 void addDirectived(const std::vector<std::string>& directives);
94
95 std::string toString();
96
97 std::set<std::string> usedIncludes;
98 };
99
100 const SoShaderRepository::SourceInfo& lookup(const std::string name) const;
101
102 void addCode(const SoShaderRepository::SourceInfo& code, ShaderString& result);
103
104 std::vector<SoShaderRepository*> _repositories;
105 SoShaderRepository _defaultRepository;
106
108};
109
110#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)
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)