<commit_before>#include "pch.h"

#include "gfx_gl.h"
#include "console.h"

// --------------------------------------------------------------------------------------------------------------------
GfxBaseApi *CreateGfxOpenGLGeneric() { return new GfxApiOpenGLGeneric; }
GfxBaseApi *CreateGfxOpenGLCore() { return new GfxApiOpenGLCore; }

std::tuple<std::string, std::string> versionSplit(const std::string& _srcString);

// --------------------------------------------------------------------------------------------------------------------
static SDL_Window* CreateGLWindow(const char* _title, int _x, int _y, int _width, int _height)
{
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

    SDL_Window* retWnd = SDL_CreateWindow(_title, _x, _y, _width, _height, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);

    return retWnd;
}

// --------------------------------------------------------------------------------------------------------------------
static void APIENTRY ErrorCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char* message, const void* userParam)
{
    if (source == GL_DEBUG_SOURCE_API && type == GL_DEBUG_TYPE_OTHER && severity == GL_DEBUG_SEVERITY_LOW && strstr(message, "DRAW_INDIRECT_BUFFER") == nullptr) {
        return;
    }
    
    console::debug("%s", message);
}

// --------------------------------------------------------------------------------------------------------------------
GfxApiOpenGLBase::GfxApiOpenGLBase()
: mGLrc()
{ }

// --------------------------------------------------------------------------------------------------------------------
GfxApiOpenGLBase::~GfxApiOpenGLBase()
{ }

// --------------------------------------------------------------------------------------------------------------------
bool GfxApiOpenGLBase::Init(const std::string& _title, int _x, int _y, int _width, int _height)
{
    if (!GfxBaseApi::Init(_title, _x, _y, _width, _height)) {
        return false;
    }

    mWnd = CreateGLWindow(_title.c_str(), _x, _y, _width, _height);
    if (!mWnd) {
        console::warn("Unable to create SDL Window, which is required for GL.");
        return false;
    }

    mGLrc = SDL_GL_CreateContext(mWnd);
    if (mGLrc == 0) {
        console::warn("Unable to create a GL context, which is required for GL.");
        return false;
    }

    if (SDL_GL_MakeCurrent(mWnd, mGLrc) != 0) {
        console::warn("Unable to MakeCurrent on GL context.");
        return false;
    }

    console::log("GL created successfully! Info follows.");
    console::log("Vendor: %s", glGetString(GL_VENDOR));
    console::log("Renderer: %s", glGetString(GL_RENDERER));
    console::log("Version: %s", glGetString(GL_VERSION));
    console::log("Shading Language Version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
<commit_msg>In debug builds, pass SDL the debug GL context creation flag<commit_after>#include "pch.h"

#include "gfx_gl.h"
#include "console.h"

// --------------------------------------------------------------------------------------------------------------------
GfxBaseApi *CreateGfxOpenGLGeneric() { return new GfxApiOpenGLGeneric; }
GfxBaseApi *CreateGfxOpenGLCore() { return new GfxApiOpenGLCore; }

std::tuple<std::string, std::string> versionSplit(const std::string& _srcString);

// --------------------------------------------------------------------------------------------------------------------
static SDL_Window* CreateGLWindow(const char* _title, int _x, int _y, int _width, int _height)
{
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

    SDL_Window* retWnd = SDL_CreateWindow(_title, _x, _y, _width, _height, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);

    return retWnd;
}

// --------------------------------------------------------------------------------------------------------------------
static void APIENTRY ErrorCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char* message, const void* userParam)
{
    if (source == GL_DEBUG_SOURCE_API && type == GL_DEBUG_TYPE_OTHER && severity == GL_DEBUG_SEVERITY_LOW && strstr(message, "DRAW_INDIRECT_BUFFER") == nullptr) {
        return;
    }
    
    console::debug("%s", message);
}

// --------------------------------------------------------------------------------------------------------------------
GfxApiOpenGLBase::GfxApiOpenGLBase()
: mGLrc()
{ }

// --------------------------------------------------------------------------------------------------------------------
GfxApiOpenGLBase::~GfxApiOpenGLBase()
{ }

// --------------------------------------------------------------------------------------------------------------------
bool GfxApiOpenGLBase::Init(const std::string& _title, int _x, int _y, int _width, int _height)
{
#if defined(_DEBUG)
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
#endif

    if (!GfxBaseApi::Init(_title, _x, _y, _width, _height)) {
        return false;
    }

    mWnd = CreateGLWindow(_title.c_str(), _x, _y, _width, _height);
    if (!mWnd) {
        console::warn("Unable to create SDL Window, which is required for GL.");
        return false;
    }

    mGLrc = SDL_GL_CreateContext(mWnd);
    if (mGLrc == 0) {
        console::warn("Unable to create a GL context, which is required for GL.");
        return false;
    }

    if (SDL_GL_MakeCurrent(mWnd, mGLrc) != 0) {
        console::warn("Unable to MakeCurrent on GL context.");
        return false;
    }

    console::log("GL created successfully! Info follows.");
    console::log("Vendor: %s", glGetString(GL_VENDOR));
    console::log("Renderer: %s", glGetString(GL_RENDERER));
    console::log("Version: %s", glGetString(GL_VERSION));
    console::log("Shading Language Version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));

{'fraction_non_alphanumeric': 0.33775735919686917, 'fraction_numerical': 0.0017015484090522376, 'mean_word_length': 1.625279142474319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2066536', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1578, 'n_words': 361}