CoriEngine
Loading...
Searching...
No Matches
GL_GraphicsContext.cpp
Go to the documentation of this file.
2#include <glad/gl.h>
4
5namespace Cori {
6 namespace Graphics {
7 namespace Internal {
9 SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
10 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
11 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
12 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6);
13 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
14 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
15#ifdef DEBUG_BUILD
16 SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
17#endif
18
19 }
20
25
26 void OpenGLContext::Init(SDL_Window* window) {
27 m_Context = SDL_GL_CreateContext(window);
28 CORI_CORE_ASSERT(m_Context, "OpenGL context could not be created! SDL_Error: {}", SDL_GetError());
29
30
31 const int32_t glad_version = gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
32 CORI_CORE_ASSERT(glad_version != 0, "Failed to initialize GLAD");
33
35 CORI_CORE_TRACE_TAGGED({ Logger::Tags::Graphics::Self, Logger::Tags::Graphics::OpenGL, Logger::Tags::Graphics::GraphicsContext }, "Using hardware renderer: \n{4}Vendor: {0}\n{4}Renderer: {1}\n{4}OpenGL Version {2}\n{4}Shading Language Version: {3}",
36 std::string(reinterpret_cast<const char*>(glGetString(GL_VENDOR))),
37 std::string(reinterpret_cast<const char*>(glGetString(GL_RENDERER))),
38 std::string(reinterpret_cast<const char*>(glGetString(GL_VERSION))),
39 std::string(reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION))), CORI_SECOND_LINE_SPACING);
40 }
41
43 SDL_GL_SwapWindow(static_cast<SDL_Window*>(Core::Application::GetWindow().GetNativeWindow()));
44 }
45 }
46 }
47}
#define CORI_CORE_DEBUG_TAGGED(...)
Definition Logger.hpp:1026
const std::string CORI_SECOND_LINE_SPACING
Definition Logger.hpp:1001
#define CORI_CORE_ASSERT(x,...)
Definition Logger.hpp:1029
#define CORI_CORE_TRACE_TAGGED(...)
Definition Logger.hpp:1025
#define CORI_CORE_INFO_TAGGED(...)
Definition Logger.hpp:1027
static Window & GetWindow()
Getter for the main Window.
void Init(SDL_Window *window) override
Almost everything connected to graphics is in this namespace.
Definition Window.hpp:7
Global engine namespace.
static constexpr char GraphicsContext[]
Definition Logger.hpp:61
static constexpr char OpenGL[]
Definition Logger.hpp:49
static constexpr char Self[]
Definition Logger.hpp:47