//
// Created by sfd on 25-4-21.
//

#include "OpenGLContext.h"

#include <Hazel/Core/Log.h>
#include <Hazel/Debug/Instrumentor.h>
#include <SDL3/SDL_opengl.h>


namespace Hazel
{
    OpenGLContext::OpenGLContext(SDL_Window* windowHandle) : m_windowHandle(windowHandle)
    {
    }

    void OpenGLContext::Init()
    {
        HZ_PROFILE_FUNCTION();
        m_GLContext = SDL_GL_CreateContext(m_windowHandle);
        if (!m_GLContext)
        {
            HZ_CORE_ERROR("Could not create OpenGL context: {}", SDL_GetError());
            exit(EXIT_FAILURE);
        }

        const GLubyte* vender = glGetString(GL_VENDOR);
        const GLubyte* renderer = glGetString(GL_RENDERER);
        const GLubyte* version = glGetString(GL_VERSION);
		HZ_CORE_INFO("OpenGL info: ");
		HZ_CORE_INFO("  Vender: {0}", reinterpret_cast<const char*>(vender));
		HZ_CORE_INFO("  Renderer: {0}", reinterpret_cast<const char*>(renderer));
        HZ_CORE_INFO("  Version: {0}", reinterpret_cast<const char*>(version));
    }

    void OpenGLContext::SwapBuffers()
    {
        HZ_PROFILE_FUNCTION();
        SDL_GL_SwapWindow(m_windowHandle);
    }

    void* OpenGLContext::GetGLContext()
    {
        return m_GLContext;
    }
}
