whoa/src/gx/glsdl/GLSDLContext.cpp
Phaneron 706c8903a1
feat(gx): add incomplete 'CGxDeviceGLSDL' (#2)
* chore(build): add vendored SDL 3.0.0 library

* chore(build): add vendored glew-cmake-2.2.0 library

* feat(console): in the presence of -opengl launch flag, change GxApi to OpenGl

* feat(gx): add uncompleted CGxDeviceGLSDL targeting Windows and Linux

* chore(build): change SDL3 linkage from shared (bad) to to static (good)
2023-11-18 10:50:16 -05:00

49 lines
1.3 KiB
C++

#include "gx/glsdl/GLSDLContext.hpp"
#include <bc/Debug.hpp>
#include <storm/Error.hpp>
static bool s_GLEW_Initialized = false;
void GLSDLContext::Create(GLSDLWindow* window) {
BLIZZARD_ASSERT(this->m_sdlGLContext == nullptr);
this->m_sdlGLContext = SDL_GL_CreateContext(window->m_sdlWindow);
BLIZZARD_ASSERT(this->m_sdlGLContext != nullptr);
if (s_GLEW_Initialized == false) {
glewExperimental = true;
auto glewError = glewInit();
if (glewError != GLEW_OK) {
SErrDisplayAppFatal("Error initializing GLEW: %s\n", glewGetErrorString(glewError));
}
s_GLEW_Initialized = true;
}
}
void GLSDLContext::Destroy() {
BLIZZARD_ASSERT(this->m_sdlGLContext != nullptr);
SDL_GL_DeleteContext(this->m_sdlGLContext);
this->m_sdlGLContext = nullptr;
}
bool GLSDLContext::IsCurrentContext() {
return this->m_sdlGLContext == SDL_GL_GetCurrentContext();
}
void GLSDLContext::MakeCurrent(GLSDLWindow* window) {
auto status = SDL_GL_MakeCurrent(window->m_sdlWindow, this->m_sdlGLContext);
BLIZZARD_ASSERT(status == 0);
}
int32_t GLSDLContext::GetSampleCount() {
int samples;
auto status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples);
BLIZZARD_ASSERT(status == 0);
return static_cast<int32_t>(samples);
}