void PolylineStyle::constructShaderProgram() { std::string vertShaderSrcStr = stringFromResource("polyline.vs"); std::string fragShaderSrcStr = stringFromResource("polyline.fs"); m_shaderProgram->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr); }
void DebugStyle::constructShaderProgram() { std::string vertShaderSrcStr = stringFromResource("debug.vs"); std::string fragShaderSrcStr = stringFromResource("debug.fs"); m_shaderProgram->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr); }
void PolygonStyle::constructShaderProgram() { std::string vertShaderSrcStr = stringFromResource("polygon.vs"); std::string fragShaderSrcStr = stringFromResource("polygon.fs"); m_shaderProgram = std::make_shared<ShaderProgram>(); m_shaderProgram->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr); }
void SpriteStyle::constructShaderProgram() { std::string fragShaderSrcStr = stringFromResource("texture.fs"); std::string vertShaderSrcStr = stringFromResource("texture.vs"); m_shaderProgram = std::make_shared<ShaderProgram>(); m_shaderProgram->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr); m_texture = std::shared_ptr<Texture>(new Texture("mapzen-logo.png")); }
void Light::assembleLights(std::map<std::string, std::vector<std::string>>& _sourceBlocks) { // Create strings to contain the assembled lighting source code std::string lightingBlock; // Concatenate all strings at the "__lighting" keys // (struct definitions and function definitions) for (const auto& string : _sourceBlocks["__lighting"]) { lightingBlock += string; } // After lights definitions are all added, add the main lighting functions if (s_mainLightingBlock.empty()) { s_mainLightingBlock = stringFromResource("lights.glsl"); } lightingBlock += s_mainLightingBlock; // The main lighting functions each contain a tag where all light instances should be computed; // Insert all of our "lights_to_compute" at this tag std::string tag = "#pragma tangram: lights_to_compute"; size_t pos = lightingBlock.find(tag) + tag.length(); for (const auto& string : _sourceBlocks["__lights_to_compute"]) { lightingBlock.insert(pos, string); pos += string.length(); } // Place our assembled lighting source code back into the map of "source blocks"; // The assembled strings will then be injected into a shader at the "vertex_lighting" // and "fragment_lighting" tags _sourceBlocks["lighting"] = { lightingBlock }; }
void Skybox::init() { std::string fragShaderSrcStr = stringFromResource("cubemap.fs"); std::string vertShaderSrcStr = stringFromResource("cubemap.vs"); m_shader = std::make_shared<ShaderProgram>(); m_shader->setSourceStrings(fragShaderSrcStr, vertShaderSrcStr); m_texture = std::shared_ptr<Texture>(new TextureCube(m_file)); auto layout = std::shared_ptr<VertexLayout>(new VertexLayout({ {"a_position", 3, GL_FLOAT, false, 0}, })); m_mesh = std::shared_ptr<Mesh>(new Mesh(layout, GL_TRIANGLES)); std::vector<int> indices = { 5, 1, 3, 3, 7, 5, // +x 6, 2, 0, 0, 4, 6, // -x 2, 6, 7, 7, 3, 2, // +y 5, 4, 0, 0, 1, 5, // -y 0, 2, 3, 3, 1, 0, // +z 7, 6, 4, 4, 5, 7 // -z }; std::vector<PosVertex> vertices = { { -1.0, -1.0, 1.0 }, { 1.0, -1.0, 1.0 }, { -1.0, 1.0, 1.0 }, { 1.0, 1.0, 1.0 }, { -1.0, -1.0, -1.0 }, { 1.0, -1.0, -1.0 }, { -1.0, 1.0, -1.0 }, { 1.0, 1.0, -1.0 } }; m_mesh->addVertices(std::move(vertices), std::move(indices)); m_mesh->compileVertexBuffer(); }
std::string Material::getClassBlock() { return stringFromResource("material.glsl") + "\n"; }