Privacy
An open-source, flexible 3D physical simulation framework
shader-function.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016, DFKI GmbH Robotics Innovation Center
3  *
4  * This file is part of the MARS simulation framework.
5  *
6  * MARS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3
9  * of the License, or (at your option) any later version.
10  *
11  * MARS 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 MARS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 #include "shader-function.h"
23 #include <sstream>
24 #include <queue>
25 
26 namespace osg_material_manager {
27 
28  using namespace std;
29 
31  minVersion = max(minVersion, u->minVersion);
32  for(vector< FunctionCall >::iterator it = u->funcs.begin();
33  it != u->funcs.end(); ++it)
34  funcs.push_back( *it );
35  for(vector< PrioritizedLine >::iterator it = u->snippets.begin();
36  it != u->snippets.end(); ++it)
37  snippets.push_back( *it );
38  for(set<string>::iterator it = u->getEnabledExtensions().begin();
39  it != u->getEnabledExtensions().end(); ++it)
40  enabledExtensions.insert(*it);
41  for(set<string>::iterator it = u->getDisabledExtensions().begin();
42  it != u->getDisabledExtensions().end(); ++it)
43  disabledExtensions.insert(*it);
44  for(set<GLSLUniform>::iterator it = u->getUniforms().begin();
45  it != u->getUniforms().end(); ++it)
46  uniforms.insert(*it);
47  for(set<GLSLConstant>::iterator it = u->getConstants().begin();
48  it != u->getConstants().end(); ++it)
49  constants.insert(*it);
50  for(set<GLSLVarying>::iterator it = u->getVaryings().begin();
51  it != u->getVaryings().end(); ++it)
52  varyings.insert(*it);
53  for(set<GLSLAttribute>::iterator it = u->getAttributes().begin();
54  it != u->getAttributes().end(); ++it)
55  attributes.insert(*it);
56  std::vector< std::pair<std::string,std::string> > uDeps = u->getDeps();
57  for(vector< pair<string,string> >::iterator it = uDeps.begin();
58  it != uDeps.end(); ++it)
59  deps[it->first] = it->second;
60  for(list<MainVar>::const_iterator it = u->getMainVars().begin();
61  it != u->getMainVars().end(); ++it)
62  mainVars.push_back(*it);
63  for(set<GLSLAttribute>::const_iterator it = u->getMainVarDecs().begin();
64  it != u->getMainVarDecs().end(); ++it) {
65  mainVarDecs.insert(*it);
66  }
67  for(vector<GLSLExport>::const_iterator it = u->getExports().begin();
68  it != u->getExports().end(); ++it)
69  exports.push_back(*it);
70  for(set<GLSLSuffix>::iterator it = u->getSuffixes().begin();
71  it != u->getSuffixes().end(); ++it)
72  suffixes.insert(*it);
73  shaderCode += "\n" + u->generateFunctionCode();
74  }
75 
77  std::priority_queue<FunctionCall> funcs_sorted;
78  std::vector<FunctionCall>::iterator it = funcs.begin();
79  for (;it!=funcs.end();it++) { // better way to initialize already with the vector as argument in constructor?
80  funcs_sorted.push(*it.base());
81  }
82  vector<string> calls;
83 
84  while(!funcs_sorted.empty()) {
85  FunctionCall func = funcs_sorted.top();
86  string call = func.name + "( ";
87  std::vector<std::string> args = func.arguments;
88  unsigned long numArgs = args.size();
89 
90  if(numArgs > 0) {
91  call += args[0];
92  for(int i=1; i<numArgs; ++i) {
93  call += ", " + args[i];
94  }
95  }
96  call += " );";
97  calls.push_back(call);
98  funcs_sorted.pop();
99  }
100  return calls;
101  }
102 
103 } // end of namespace osg_material_manager
const std::list< MainVar > & getMainVars() const
const std::set< std::string > & getDisabledExtensions() const
const std::set< GLSLSuffix > & getSuffixes() const
const std::set< GLSLAttribute > & getAttributes() const
std::vector< std::pair< std::string, std::string > > getDeps() const
std::vector< PrioritizedLine > snippets
const std::set< std::string > & getEnabledExtensions() const
const std::set< GLSLUniform > & getUniforms() const
std::vector< std::string > generateFunctionCall()
const std::set< GLSLAttribute > & getMainVarDecs() const
std::vector< FunctionCall > funcs
#define max(x, y)
Definition: envmap.cpp:33
const std::set< GLSLVarying > & getVaryings() const
std::vector< std::string > arguments
Definition: shader-types.h:67
const std::set< GLSLConstant > & getConstants() const
const std::vector< GLSLExport > & getExports() const