<commit_before>
#include "device.h"

#include <algorithm>
#include <exception>
#include <stdexcept>
#include <sstream>

#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>

#include <scm/core/io/tools.h>
#include <scm/core/utilities/foreach.h>

#include <scm/gl_core/config.h>
#include <scm/gl_core/log.h>
#include <scm/gl_core/buffer_objects.h>
#include <scm/gl_core/frame_buffer_objects.h>
#include <scm/gl_core/query_objects.h>
#include <scm/gl_core/render_device/context.h>
#include <scm/gl_core/render_device/opengl/gl_core.h>
#include <scm/gl_core/render_device/opengl/util/assert.h>
#include <scm/gl_core/render_device/opengl/util/error_helper.h>
#include <scm/gl_core/shader_objects/program.h>
#include <scm/gl_core/shader_objects/shader.h>
#include <scm/gl_core/shader_objects/stream_capture.h>
#include <scm/gl_core/state_objects/depth_stencil_state.h>
#include <scm/gl_core/state_objects/rasterizer_state.h>
#include <scm/gl_core/state_objects/sampler_state.h>
#include <scm/gl_core/texture_objects.h>

namespace scm {
namespace gl {

render_device::render_device()
{
    _opengl_api_core.reset(new opengl::gl_core());

    if (!_opengl_api_core->initialize()) {
        std::ostringstream s;
        s << "render_device::render_device(): error initializing gl core.";
        glerr() << log::fatal << s.str() << log::end;
        throw(std::runtime_error(s.str()));
    }
    unsigned req_version_major = SCM_GL_CORE_OPENGL_CORE_VERSION / 100;
    unsigned req_version_minor = (SCM_GL_CORE_OPENGL_CORE_VERSION - req_version_major * 100) / 10;

    if (!_opengl_api_core->version_supported(req_version_major, req_version_minor)) {
        std::ostringstream s;
        s << "render_device::render_device(): error initializing gl core "
          << "(at least OpenGL "
          << req_version_major << "." << req_version_minor
          << " requiered, encountered version "
          << _opengl_api_core->context_information()._version_major << "."
          << _opengl_api_core->context_information()._version_minor << ").";
        glerr() << log::fatal << s.str() << log::end;
        throw(std::runtime_error(s.str()));
    }
    else {
        glout() << log::info << "render_device::render_device(): "
                << "scm_gl_core OpenGL "
                << req_version_major << "." << req_version_minor
                << " support enabled on "
                << _opengl_api_core->context_information()._version_major << "."
                << _opengl_api_core->context_information()._version_minor
                << " context." << log::end;
    }

#ifdef SCM_GL_CORE_USE_DIRECT_STATE_ACCESS
    if (!_opengl_api_core->is_supported("GL_EXT_direct_state_access")) {
        std::ostringstream s;
        s << "render_device::render_device(): error initializing gl core "
          << "(missing requiered extension GL_EXT_direct_state_access).";
        glerr() << log::fatal << s.str() << log::end;
        throw(std::runtime_error(s.str()));
    }
#endif

    init_capabilities();

    // setup main rendering context
    try {
        _main_context.reset(new render_context(*this));
    }
    catch (const std::exception& e) {
        std::ostringstream s;
        s << "render_device::render_device(): error creating main_context (evoking error: "
          << e.what()
          << ").";
        glerr() << log::fatal << s.str() << log::end;
        throw(std::runtime_error(s.str()));
    }
}

render_device::~render_device()
{
    _main_context.reset();

    assert(0 == _registered_resources.size());
}

const opengl::gl_core&
render_device::opengl_api() const
{
    return (*_opengl_api_core);
}

render_context_ptr
render_device::main_context() const
{
    return (_main_context);
}
<commit_msg>minor, apply main context state at init<commit_after>
#include "device.h"

#include <algorithm>
#include <exception>
#include <stdexcept>
#include <sstream>

#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>

#include <scm/core/io/tools.h>
#include <scm/core/utilities/foreach.h>

#include <scm/gl_core/config.h>
#include <scm/gl_core/log.h>
#include <scm/gl_core/buffer_objects.h>
#include <scm/gl_core/frame_buffer_objects.h>
#include <scm/gl_core/query_objects.h>
#include <scm/gl_core/render_device/context.h>
#include <scm/gl_core/render_device/opengl/gl_core.h>
#include <scm/gl_core/render_device/opengl/util/assert.h>
#include <scm/gl_core/render_device/opengl/util/error_helper.h>
#include <scm/gl_core/shader_objects/program.h>
#include <scm/gl_core/shader_objects/shader.h>
#include <scm/gl_core/shader_objects/stream_capture.h>
#include <scm/gl_core/state_objects/depth_stencil_state.h>
#include <scm/gl_core/state_objects/rasterizer_state.h>
#include <scm/gl_core/state_objects/sampler_state.h>
#include <scm/gl_core/texture_objects.h>

namespace scm {
namespace gl {

render_device::render_device()
{
    _opengl_api_core.reset(new opengl::gl_core());

    if (!_opengl_api_core->initialize()) {
        std::ostringstream s;
        s << "render_device::render_device(): error initializing gl core.";
        glerr() << log::fatal << s.str() << log::end;
        throw(std::runtime_error(s.str()));
    }
    unsigned req_version_major = SCM_GL_CORE_OPENGL_CORE_VERSION / 100;
    unsigned req_version_minor = (SCM_GL_CORE_OPENGL_CORE_VERSION - req_version_major * 100) / 10;

    if (!_opengl_api_core->version_supported(req_version_major, req_version_minor)) {
        std::ostringstream s;
        s << "render_device::render_device(): error initializing gl core "
          << "(at least OpenGL "
          << req_version_major << "." << req_version_minor
          << " requiered, encountered version "
          << _opengl_api_core->context_information()._version_major << "."
          << _opengl_api_core->context_information()._version_minor << ").";
        glerr() << log::fatal << s.str() << log::end;
        throw(std::runtime_error(s.str()));
    }
    else {
        glout() << log::info << "render_device::render_device(): "
                << "scm_gl_core OpenGL "
                << req_version_major << "." << req_version_minor
                << " support enabled on "
                << _opengl_api_core->context_information()._version_major << "."
                << _opengl_api_core->context_information()._version_minor
                << " context." << log::end;
    }

#ifdef SCM_GL_CORE_USE_DIRECT_STATE_ACCESS
    if (!_opengl_api_core->is_supported("GL_EXT_direct_state_access")) {
        std::ostringstream s;
        s << "render_device::render_device(): error initializing gl core "
          << "(missing requiered extension GL_EXT_direct_state_access).";
        glerr() << log::fatal << s.str() << log::end;
        throw(std::runtime_error(s.str()));
    }
#endif

    init_capabilities();

    // setup main rendering context
    try {
        _main_context.reset(new render_context(*this));
        _main_context->apply();
    }
    catch (const std::exception& e) {
        std::ostringstream s;
        s << "render_device::render_device(): error creating main_context (evoking error: "
          << e.what()
          << ").";
        glerr() << log::fatal << s.str() << log::end;
        throw(std::runtime_error(s.str()));
    }
}

render_device::~render_device()
{
    _main_context.reset();

    assert(0 == _registered_resources.size());
}

const opengl::gl_core&
render_device::opengl_api() const
{
    return (*_opengl_api_core);
}

render_context_ptr
render_device::main_context() const
{
    return (_main_context);
}

{'fraction_non_alphanumeric': 0.14923036785807461, 'fraction_numerical': 0.002348030263501174, 'mean_word_length': 3.6438522107813447, 'pattern_counts': {'":': 0, '<': 215, '<?xml version=': 0, '>': 70, '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': '7054313', 'n_tokens_mistral': 2676, 'n_tokens_neox': 2616, 'n_words': 391}