mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-10-26 22:06:06 +03:00
51 lines
1.3 KiB
C++
51 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) {
|
|
BC_ASSERT(this->m_sdlGLContext == nullptr);
|
|
|
|
this->m_sdlGLContext = SDL_GL_CreateContext(window->m_sdlWindow);
|
|
|
|
BC_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() {
|
|
BC_ASSERT(this->m_sdlGLContext != nullptr);
|
|
|
|
SDL_GL_DestroyContext(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);
|
|
BC_ASSERT(status);
|
|
}
|
|
|
|
int32_t GLSDLContext::GetSampleCount() {
|
|
int samples;
|
|
auto status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples);
|
|
if (status != 0) {
|
|
return 1;
|
|
}
|
|
return static_cast<int32_t>(samples);
|
|
}
|