shared_ptr<GlShader> getShader(const string& filename, GLenum shaderType) {
		string f = filename;
		if (g_Gl2Compatible) { // if compatible, change -gl3 to -gl2 in the end of the filename
			size_t pos = f.rfind("-gl3");
			if (pos != string::npos) {
				f[pos+3] = '2';
			}
		}

		GlShaderMap::key_type key(f, shaderType);

		GlShaderMap::iterator i = shaderMap.find(key);
		if (i == shaderMap.end()) {
			shared_ptr<GlShader> shader(new GlShader(shaderType));

			try {
				readAndCompileSingleShader(*shader, f.c_str());
			}
			catch (const runtime_error & error ) {
				std::cout << error.what() << endl;
				messageFile << "compile shader:" << error.what() << endl;
			}
    
			shaderMap[key] = shader;
			return shader;
		}
		else {
			return i->second;
		}
	}
예제 #2
0
  shared_ptr<GlShader> getShader(const string& filename, GLenum shaderType) {
    string f = filename;
    if (g_Gl2Compatible) { // optionally change -gl3 to -gl3 in the end of the filename
      size_t pos = f.rfind("-gl3");
      if (pos != string::npos) {
        f[pos+3] = '2';
      }
    }

    GlShaderMap::key_type key(f, shaderType);
    GlShaderMap::iterator i = shaderMap.find(key);
    if (i == shaderMap.end()) {
      shared_ptr<GlShader> shader(new GlShader(shaderType));
      readAndCompileSingleShader(*shader, f.c_str());
      shaderMap[key] = shader;
      return shader;
    }
    else {
      return i->second;
    }
  }