Example #1
0
const gl::ProgramPtr & GlUtils::getProgram(Resource vs, Resource fs) {
  typedef ShaderInfo<GL_VERTEX_SHADER> VShader;
  typedef ShaderInfo<GL_FRAGMENT_SHADER> FShader;
  typedef std::unordered_map<Resource, VShader> VMap;
  typedef std::unordered_map<Resource, FShader> FMap;
  static VMap vShaders;
  static FMap fShaders;
  typedef std::unordered_map<std::string, gl::ProgramPtr> ProgramMap;
  static ProgramMap programs;
  gl::shader_error lastError(0, "none");
  VShader & vsi = vShaders[vs];
  FShader & fsi = fShaders[fs];
  std::string key = Resources::getResourcePath(vs) + ":" +
    Resources::getResourcePath(fs);
  try {
    bool relink = vsi.update(vs) | fsi.update(fs);
    if (relink || programs.end() == programs.find(key)) {
      std::cerr << "Relinking " + key << std::endl;
      programs[key] = gl::ProgramPtr(new gl::Program(vsi.shader, fsi.shader));
    }
  } catch (const gl::shader_error & error) {
    lastError = error;
  }
  if (!programs[key]) {
    throw lastError;
  }
  const gl::ProgramPtr & ptr = programs[key];
  //GL_CHECK_ERROR;
  return ptr;
}
Example #2
0
	void CMesh::SetupGLSurfaces(ProgramMap& shaders)
	{
		_glSurfaces.clear();
		_glSurfaces.reserve(surfaces.size());
		for (long i = 0; i < surfaces.size(); i++)
		{

			CGLSurface glSrf(surfaces[i]);
			// Shader program
			Surface * pSrf = &surfaces[i];
			CGLProgram * program = PrgOverride(*pSrf);
			if (NULL != program)
				glSrf._program = program;
			else
			{
				ProgramMap::const_iterator shaderIt = shaders.find(std::string(pSrf->program_name));
				if (shaderIt != shaders.end())
				{
					glSrf._program = shaderIt->second;
					std::string surf_name(pSrf->name);
					m_Editors.push_back(new CEditor(surf_name + ": " + shaderIt->first, std::string(((*shaderIt->second).vs.GetLines() == NULL) ? "<Shader not loaded...>" : (*shaderIt->second).vs.GetLines())));
					m_Editors.push_back(new CEditor(surf_name + ": " + shaderIt->first, std::string(((*shaderIt->second).fs.GetLines() == NULL) ? "<Shader not loaded...>" : (*shaderIt->second).fs.GetLines())));
				}
				else
				{
					glSrf._program = &fixedFunc;
					Log::CLog::Write("CMesh::SetupGLSurfaces: WARNING: Could not find any suitable shader with name: %s\r\n", pSrf->program_name);
				}
			}
			_glSurfaces.push_back(glSrf);
		}
	}
Example #3
0
 ProgramPtr Platform::getProgram(const string & vs, const string & fs) {
     typedef ShaderInfo<GL_VERTEX_SHADER> VShader;
     typedef ShaderInfo<GL_FRAGMENT_SHADER> FShader;
     typedef map<string, VShader> VMap;
     typedef map<string, FShader> FMap;
     static VMap vShaders;
     static FMap fShaders;
     VShader & vsi = vShaders[vs];
     FShader & fsi = fShaders[fs];
     bool relink = vsi.update(vs) | fsi.update(fs);
     typedef map<string, ProgramPtr> ProgramMap;
     string key = vs + ":" + fs;
     static ProgramMap programs;
     if (relink || programs.end() == programs.find(key)) {
         cerr << "Relinking " + key << endl;
         programs[key] = ProgramPtr(new Program(vsi.shader, fsi.shader));
     }
     return programs[key];
 }
Example #4
0
TEST(ForgetOperator,ProgramAndAtomGoodDeletion) {
    LiteralsStack stack;
    VariableMap variableMap;
    ProgramMap programMap;
    Lexer *lexer = new Lexer();
    lexer->addDefinition(new WhitespaceLiteralDefinition());
    lexer->addDefinition(new NumericLiteralDefinition);
    lexer->addDefinition(new OperatorNumericLiteralDefinition);
    lexer->addDefinition(new OperatorEqualComparisonLiteralDefinition);
    lexer->addDefinition(new OperatorStrictComparisonLiteralDefinition);
    lexer->addDefinition(new ExpressionLiteralDefinition);
    lexer->addDefinition(new ProgramLiteralDefinition);
    lexer->addDefinition(new AtomLiteralDefinition);
    stack.push(LiteralPointer(new ProgramLiteral("[1 1 +]")));
    stack.push(LiteralPointer(new ExpressionLiteral("'AFR'")));

    EXPECT_EQ(2, stack.size());

    StoOperator stoOperator(variableMap,programMap,*lexer);
    stoOperator.apply(stack);

    EXPECT_EQ(0, stack.size());
    EXPECT_EQ(1,programMap.size());
    std::unordered_map<string, LiteralVector>::const_iterator it = programMap.begin();
    string value;

    for(LiteralVector::const_iterator it2 = it->second.begin();it2!=it->second.end();++it2)
    {
        value += (*it2)->toString() + " ";
    }
    EXPECT_EQ("[1 1 +] ",value);

    stack.push(LiteralPointer(new ExpressionLiteral("'AFR'")));

    EXPECT_EQ(1, stack.size());

    ForgetOperator forgetOperator(variableMap,programMap);
    forgetOperator.apply(stack);

    EXPECT_EQ(0,programMap.size());
}
void ProgramToSave::saveIntoMap(ProgramMap& iMap, const ExeStats& iFinalStats) {
  LOG_DEBUG("Saving into past execution history " << size() << " states");
  LOG_DEBUG("If program halts, need to adjust the execution stats of saved states : " << iFinalStats);

  // TODO optim adding 1 by 1 can be improved with a bulk insert
  for (auto it = begin(), last = end(); it != last; ++it) {
    InnerItem item = *it;
    item.second.stops = iFinalStats.stops;
    item.second.reachedMaxIt = iFinalStats.reachedMaxIt;

    if (iFinalStats.stops) {
      item.second.iterations = iFinalStats.iterations - item.second.iterations;
      item.second.output = iFinalStats.output - item.second.output;
      item.second.stops = true;
    }
    else {
      item.second.reachedMaxIt = iFinalStats.reachedMaxIt;
    }
    iMap.addCopy(item.first, item.second);
  }
}