<commit_before>#include "OpenGLRenderer.h"

#include OPENGL_FUNCTIONS_INCLUDE
#include "CameraDefinition.h"
#include "OpenGLSharedState.h"
#include "OpenGLSkybox.h"
#include "OpenGLWater.h"
#include "OpenGLTerrain.h"
#include "CloudsRenderer.h"
#include "Scenery.h"
#include "LightingManager.h"
#include "Logs.h"

#include "GL/glu.h" // TEMP

OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
    SoftwareRenderer(scenery)
{
    ready = false;
    paused = false;
    vp_width = 1;
    vp_height = 1;

    render_quality = 3;

    functions = new OpenGLFunctions();
    shared_state = new OpenGLSharedState();

    shared_state->set("viewDistance", 300.0);
    shared_state->set("exposure", 1.2);

    skybox = new OpenGLSkybox(this);
    water = new OpenGLWater(this);
    terrain = new OpenGLTerrain(this);
}

OpenGLRenderer::~OpenGLRenderer()
{
    terrain->interrupt();
    water->interrupt();
    skybox->interrupt();

    delete skybox;
    delete water;
    delete terrain;

    delete functions;
    delete shared_state;
}

void OpenGLRenderer::initialize()
{
    ready = functions->initializeOpenGLFunctions();

    if (ready)
    {
        prepareOpenGLState();

        prepare();

        getCloudsRenderer()->setEnabled(false);
        getLightingManager()->setSpecularity(false);

        skybox->initialize();
        skybox->updateScenery();

        water->initialize();
        water->updateScenery();

        terrain->initialize();
        terrain->updateScenery();

        cameraChangeEvent(render_camera);
    }
    else
    {
        Logs::error() << "Failed to initialize OpenGL bindings" << std::endl;
    }
}

void OpenGLRenderer::prepareOpenGLState()
{
    if (ready)
    {
        functions->glDisable(GL_LIGHTING);

        functions->glFrontFace(GL_CCW);
        functions->glCullFace(GL_BACK);
        functions->glEnable(GL_CULL_FACE);

        functions->glDepthFunc(GL_LESS);
        functions->glDepthMask(1);
        functions->glEnable(GL_DEPTH_TEST);

        functions->glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        functions->glEnable(GL_LINE_SMOOTH);
        functions->glLineWidth(1.0);

        functions->glDisable(GL_FOG);

        functions->glEnable(GL_BLEND);
        functions->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        functions->glClearColor(0.0, 0.0, 0.0, 0.0);
        functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        functions->glViewport(0, 0, vp_width, vp_height);
    }
}

void OpenGLRenderer::setCamera(CameraDefinition *camera)
{
    camera->copy(render_camera);
    getScenery()->keepCameraAboveGround(render_camera);
    cameraChangeEvent(render_camera);
}

void OpenGLRenderer::resize(int width, int height)
{
    vp_width = width;
    vp_height = height;

    getScenery()->getCamera()->setRenderSize(width, height);  // FIXME Should not be needed
    render_camera->setRenderSize(width, height);

    cameraChangeEvent(render_camera);

    prepareOpenGLState();
}

void OpenGLRenderer::paint()
{
    if (ready and not paused)
    {
        functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        skybox->render();
        terrain->render();
        water->render();

        int error_code;
        while ((error_code = glGetError()) != GL_NO_ERROR)
        {
            Logs::warning() << "[OpenGL] ERROR : " << (const char*)gluErrorString(error_code) << std::endl;
        }
    }
}
<commit_msg>Fixed OpenGL rendering ratio being discarded on camera move<commit_after>#include "OpenGLRenderer.h"

#include OPENGL_FUNCTIONS_INCLUDE
#include "CameraDefinition.h"
#include "OpenGLSharedState.h"
#include "OpenGLSkybox.h"
#include "OpenGLWater.h"
#include "OpenGLTerrain.h"
#include "CloudsRenderer.h"
#include "Scenery.h"
#include "LightingManager.h"
#include "Logs.h"

#include "GL/glu.h" // TEMP

OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
    SoftwareRenderer(scenery)
{
    ready = false;
    paused = false;
    vp_width = 1;
    vp_height = 1;

    render_quality = 3;

    functions = new OpenGLFunctions();
    shared_state = new OpenGLSharedState();

    shared_state->set("viewDistance", 300.0);
    shared_state->set("exposure", 1.2);

    skybox = new OpenGLSkybox(this);
    water = new OpenGLWater(this);
    terrain = new OpenGLTerrain(this);
}

OpenGLRenderer::~OpenGLRenderer()
{
    terrain->interrupt();
    water->interrupt();
    skybox->interrupt();

    delete skybox;
    delete water;
    delete terrain;

    delete functions;
    delete shared_state;
}

void OpenGLRenderer::initialize()
{
    ready = functions->initializeOpenGLFunctions();

    if (ready)
    {
        prepareOpenGLState();

        prepare();

        getCloudsRenderer()->setEnabled(false);
        getLightingManager()->setSpecularity(false);

        skybox->initialize();
        skybox->updateScenery();

        water->initialize();
        water->updateScenery();

        terrain->initialize();
        terrain->updateScenery();

        cameraChangeEvent(render_camera);
    }
    else
    {
        Logs::error() << "Failed to initialize OpenGL bindings" << std::endl;
    }
}

void OpenGLRenderer::prepareOpenGLState()
{
    if (ready)
    {
        functions->glDisable(GL_LIGHTING);

        functions->glFrontFace(GL_CCW);
        functions->glCullFace(GL_BACK);
        functions->glEnable(GL_CULL_FACE);

        functions->glDepthFunc(GL_LESS);
        functions->glDepthMask(1);
        functions->glEnable(GL_DEPTH_TEST);

        functions->glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        functions->glEnable(GL_LINE_SMOOTH);
        functions->glLineWidth(1.0);

        functions->glDisable(GL_FOG);

        functions->glEnable(GL_BLEND);
        functions->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        functions->glClearColor(0.0, 0.0, 0.0, 0.0);
        functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        functions->glViewport(0, 0, vp_width, vp_height);
    }
}

void OpenGLRenderer::setCamera(CameraDefinition *camera)
{
    camera->copy(render_camera);
    getScenery()->keepCameraAboveGround(render_camera);
    render_camera->setRenderSize(vp_width, vp_height);
    cameraChangeEvent(render_camera);
}

void OpenGLRenderer::resize(int width, int height)
{
    if (ready)
    {
        vp_width = width;
        vp_height = height;

        render_camera->setRenderSize(width, height);
        cameraChangeEvent(render_camera);

        prepareOpenGLState();
    }
}

void OpenGLRenderer::paint()
{
    if (ready and not paused)
    {
        functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        skybox->render();
        terrain->render();
        water->render();

        int error_code;
        while ((error_code = glGetError()) != GL_NO_ERROR)
        {
            Logs::warning() << "[OpenGL] ERROR : " << (const char*)gluErrorString(error_code) << std::endl;
        }
    }
}

{'fraction_non_alphanumeric': 0.12947139753801593, 'fraction_numerical': 0.006372194062273715, 'mean_word_length': 3.2577065351418004, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 80, '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': '4211898', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2194, 'n_words': 355}