<commit_before>#include <vector>
#include "platform.h"
#include "scene.h"
#include "sceneLoader.h"
#include "lights.h"
#include "clientGeoJsonSource.h"
#include "geoJsonSource.h"
#include "material.h"
#include "mvtSource.h"
#include "polygonStyle.h"
#include "polylineStyle.h"
#include "textStyle.h"
#include "debugStyle.h"
#include "debugTextStyle.h"
#include "pointStyle.h"
#include "filters.h"
#include "sceneLayer.h"
#include "scene/dataLayer.h"
#include "text/fontContext.h"
#include "util/yamlHelper.h"

#include "yaml-cpp/yaml.h"

#include <algorithm>
#include <iterator>
#include <unordered_map>

using YAML::Node;
using YAML::NodeType;
using YAML::BadConversion;

namespace Tangram {

// TODO: make this configurable: 16MB default in-memory DataSource cache:
constexpr size_t CACHE_SIZE = 16 * (1024 * 1024);

bool SceneLoader::loadScene(const std::string& _sceneString, Scene& _scene) {

    try {
        Node config = YAML::Load(_sceneString);

        loadSources(config["sources"], _scene);
        loadTextures(config["textures"], _scene);
        loadStyles(config["styles"], _scene);
        loadLayers(config["layers"], _scene);
        loadCameras(config["cameras"], _scene);
        loadLights(config["lights"], _scene);
        loadBackground(config["scene"]["background"], _scene);

        for (auto& style : _scene.styles()) {
            style->build(_scene.lights());
        }

        // Styles that are opaque must be ordered first in the scene so that they are rendered 'under' styles that require blending
        std::sort(_scene.styles().begin(), _scene.styles().end(),
                  [](std::unique_ptr<Style>& a, std::unique_ptr<Style>& b) {
                      return a->blendMode() == Blending::none;
                  });

        return true;

    } catch (YAML::ParserException e) {
        logMsg("Error: Parsing scene config '%s'\n", e.what());
    } catch (YAML::RepresentationException e) {
        logMsg("Error: Parsing scene config '%s'\n", e.what());
    }
    return false;
}

void SceneLoader::loadShaderConfig(Node shaders, Style& style, Scene& scene) {

    auto& shader = *(style.getShaderProgram());

    if (!shaders) { return; }

    if (Node extensionsNode = shaders["extensions"]) {
        if(extensionsNode.IsSequence()) {
            for (const auto& extNode : extensionsNode) {
                const char* extTemplate = "#ifdef %s\n    #extension %s : enable\n    #define TANGRAM_EXTENSION_%s\n#endif";
                auto extName = "GL_" + extNode.as<std::string>();
                size_t bufSize = std::snprintf(nullptr, 0, extTemplate, extName.c_str(), extName.c_str(), extName.c_str());
                std::vector<char> buffer(bufSize + 1);
                std::snprintf(&buffer[0], buffer.size(), extTemplate, extName.c_str(), extName.c_str(), extName.c_str());
                shader.addSourceBlock("extensions", std::string(buffer.begin(), buffer.end()-1));
            }
        }
    }

    if (Node definesNode = shaders["defines"]) {<commit_msg>fix extension injection TANGRAM define<commit_after>#include <vector>
#include "platform.h"
#include "scene.h"
#include "sceneLoader.h"
#include "lights.h"
#include "clientGeoJsonSource.h"
#include "geoJsonSource.h"
#include "material.h"
#include "mvtSource.h"
#include "polygonStyle.h"
#include "polylineStyle.h"
#include "textStyle.h"
#include "debugStyle.h"
#include "debugTextStyle.h"
#include "pointStyle.h"
#include "filters.h"
#include "sceneLayer.h"
#include "scene/dataLayer.h"
#include "text/fontContext.h"
#include "util/yamlHelper.h"

#include "yaml-cpp/yaml.h"

#include <algorithm>
#include <iterator>
#include <unordered_map>

using YAML::Node;
using YAML::NodeType;
using YAML::BadConversion;

namespace Tangram {

// TODO: make this configurable: 16MB default in-memory DataSource cache:
constexpr size_t CACHE_SIZE = 16 * (1024 * 1024);

bool SceneLoader::loadScene(const std::string& _sceneString, Scene& _scene) {

    try {
        Node config = YAML::Load(_sceneString);

        loadSources(config["sources"], _scene);
        loadTextures(config["textures"], _scene);
        loadStyles(config["styles"], _scene);
        loadLayers(config["layers"], _scene);
        loadCameras(config["cameras"], _scene);
        loadLights(config["lights"], _scene);
        loadBackground(config["scene"]["background"], _scene);

        for (auto& style : _scene.styles()) {
            style->build(_scene.lights());
        }

        // Styles that are opaque must be ordered first in the scene so that they are rendered 'under' styles that require blending
        std::sort(_scene.styles().begin(), _scene.styles().end(),
                  [](std::unique_ptr<Style>& a, std::unique_ptr<Style>& b) {
                      return a->blendMode() == Blending::none;
                  });

        return true;

    } catch (YAML::ParserException e) {
        logMsg("Error: Parsing scene config '%s'\n", e.what());
    } catch (YAML::RepresentationException e) {
        logMsg("Error: Parsing scene config '%s'\n", e.what());
    }
    return false;
}

void SceneLoader::loadShaderConfig(Node shaders, Style& style, Scene& scene) {

    auto& shader = *(style.getShaderProgram());

    if (!shaders) { return; }

    if (Node extensionsNode = shaders["extensions"]) {
        if(extensionsNode.IsSequence()) {
            for (const auto& extNode : extensionsNode) {
                const char* extTemplate = "#ifdef GL_%s\n    #extension GL_%s : enable\n    #define TANGRAM_EXTENSION_%s\n#endif";
                auto extName = extNode.as<std::string>();
                size_t bufSize = std::snprintf(nullptr, 0, extTemplate, extName.c_str(), extName.c_str(), extName.c_str());
                std::vector<char> buffer(bufSize + 1);
                std::snprintf(&buffer[0], buffer.size(), extTemplate, extName.c_str(), extName.c_str(), extName.c_str());
                shader.addSourceBlock("extensions", std::string(buffer.begin(), buffer.end()-1));
            }
        }
    }

    if (Node definesNode = shaders["defines"]) {
{'fraction_non_alphanumeric': 0.15193415637860083, 'fraction_numerical': 0.005267489711934157, 'mean_word_length': 3.324555160142349, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '901731', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1852, 'n_words': 429}