Esempio n. 1
0
void PolygonStyle::constructShaderProgram() {

    m_shaderSource->setSourceStrings(SHADER_SOURCE(polygon_fs),
                                      SHADER_SOURCE(polygon_vs));

    if (m_texCoordsGeneration) {
        m_shaderSource->addSourceBlock("defines", "#define TANGRAM_USE_TEX_COORDS\n");
    }
}
Esempio n. 2
0
void TextStyle::constructShaderProgram() {

    if (m_sdf) {
        m_shaderProgram->setSourceStrings(SHADER_SOURCE(sdf_fs),
                                          SHADER_SOURCE(point_vs));
    } else {
        m_shaderProgram->setSourceStrings(SHADER_SOURCE(text_fs),
                                          SHADER_SOURCE(point_vs));
    }

    std::string defines = "#define TANGRAM_TEXT\n";

    m_shaderProgram->addSourceBlock("defines", defines);
}
Esempio n. 3
0
void Style::setupRasters(const std::vector<std::shared_ptr<DataSource>>& _dataSources) {
    if (!hasRasters()) {
        return;
    }

    int numRasterSource = 0;
    for (const auto& dataSource : _dataSources) {
        if (dataSource->isRaster()) {
            numRasterSource++;
        }
    }

    if (numRasterSource == 0) {
        return;
    }

    // Inject shader defines for raster sampling and uniforms
    if (m_rasterType == RasterType::normal) {
        m_shaderProgram->addSourceBlock("defines", "#define TANGRAM_RASTER_TEXTURE_NORMAL\n", false);
    } else if (m_rasterType == RasterType::color) {
        m_shaderProgram->addSourceBlock("defines", "#define TANGRAM_RASTER_TEXTURE_COLOR\n", false);
    }

    m_shaderProgram->addSourceBlock("defines", "#define TANGRAM_NUM_RASTER_SOURCES "
            + std::to_string(numRasterSource) + "\n", false);
    m_shaderProgram->addSourceBlock("defines", "#define TANGRAM_MODEL_POSITION_BASE_ZOOM_VARYING\n", false);

    m_shaderProgram->addSourceBlock("raster", SHADER_SOURCE(rasters_glsl));
}
Esempio n. 4
0
void Light::assembleLights(std::map<std::string, std::vector<std::string>>& _sourceBlocks) {

    // Create strings to contain the assembled lighting source code
    std::stringstream lighting;

    // Concatenate all strings at the "__lighting" keys
    // (struct definitions and function definitions)
    for (const auto& string : _sourceBlocks["__lighting"]) {
        lighting << '\n';
        lighting << string;
    }

    // After lights definitions are all added, add the main lighting functions
    std::string lightingBlock = SHADER_SOURCE(lights_glsl);

    // 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";
    std::stringstream lights;
    for (const auto& string : _sourceBlocks["__lights_to_compute"]) {
        lights << '\n';
        lights << string;
    }

    size_t pos = lightingBlock.find(tag) + tag.length();
    lightingBlock.insert(pos, lights.str());

    // 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"] = { lighting.str() + lightingBlock  };
}