source/Platform/Win32/Win32GLContext.cpp: use GLAD
This commit is contained in:
parent
e2195c1d49
commit
a1804cd3df
1 changed files with 28 additions and 38 deletions
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/wglew.h>
|
||||
#include "glad_wgl.h"
|
||||
|
||||
#include <Platform/PlatformDisplay.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
|
|
@ -9,14 +8,20 @@
|
|||
#include "Win32GLContext.h"
|
||||
|
||||
// Ensure that OpenGL extensions are loaded.
|
||||
static void ensureExtensionsLoaded()
|
||||
static void ensureExtensionsLoaded(HDC dc)
|
||||
{
|
||||
glewExperimental = GL_TRUE;
|
||||
GLenum ret = glewInit();
|
||||
if (ret != GLEW_OK) {
|
||||
log("Win32: Could not initialize GLEW %s\n",
|
||||
glewGetErrorString(ret));
|
||||
return;
|
||||
static bool init = false;
|
||||
|
||||
if (!init) {
|
||||
init = true;
|
||||
|
||||
if (!gladLoadWGL(dc)) {
|
||||
log("Win32: Could not load WGL extensions\n");
|
||||
}
|
||||
|
||||
if (!gladLoadGL()) {
|
||||
log("Win32: Could not load OpenGL extensions\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,42 +94,31 @@ void Win32GLContext::createGLContext()
|
|||
tmpDC = ::wglCreateContext(m_deviceContext);
|
||||
::wglMakeCurrent(m_deviceContext, tmpDC);
|
||||
|
||||
ensureExtensionsLoaded();
|
||||
ensureExtensionsLoaded(m_deviceContext);
|
||||
|
||||
// Dont need to old one anymore.
|
||||
wglMakeCurrent(m_deviceContext, NULL);
|
||||
::wglDeleteContext(tmpDC);
|
||||
|
||||
// Have new CreateContextAttribs function.
|
||||
if (WGLEW_ARB_create_context_profile) {
|
||||
// TODO: For now.. We force 3.2 Core but this should not be implementation specific.
|
||||
// The Display class should force that for all GLContext Implementations.
|
||||
|
||||
// TODO: For now.. We force 3.2 Core but this should not be implementation specific.
|
||||
// The Display class should force that for all GLContext Implementations.
|
||||
int attriblist[] = {
|
||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
|
||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
0, 0
|
||||
};
|
||||
|
||||
int attriblist[] = {
|
||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
|
||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
0, 0
|
||||
};
|
||||
|
||||
// Create real context.
|
||||
m_renderContext = ::wglCreateContextAttribsARB(m_deviceContext, 0, attriblist);
|
||||
|
||||
}
|
||||
// Could create a old context, but anything below 3.2 is so so old.
|
||||
else {
|
||||
log("Win32 - OpenGL 3.2 is not available!\n");
|
||||
}
|
||||
// Create real context.
|
||||
m_renderContext = ::wglCreateContextAttribsARB(m_deviceContext, 0, attriblist);
|
||||
}
|
||||
|
||||
bool Win32GLContext::activate()
|
||||
{
|
||||
// Make sure we have dc and rc before calling MakeCurrent.
|
||||
if (m_deviceContext && m_renderContext) {
|
||||
bool ret = ::wglMakeCurrent(m_deviceContext, m_renderContext);
|
||||
ensureExtensionsLoaded();
|
||||
return ret;
|
||||
return ::wglMakeCurrent(m_deviceContext, m_renderContext);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -141,13 +135,9 @@ bool Win32GLContext::isActive() const
|
|||
|
||||
bool Win32GLContext::setSwapInterval(int interval)
|
||||
{
|
||||
ensureExtensionsLoaded();
|
||||
ensureExtensionsLoaded(m_deviceContext);
|
||||
|
||||
if (WGLEW_EXT_swap_control) {
|
||||
return wglSwapIntervalEXT(interval);
|
||||
}
|
||||
log("wglSwapInterval: function is not supported\n");
|
||||
return false;
|
||||
return wglSwapIntervalEXT(interval);
|
||||
}
|
||||
|
||||
void Win32GLContext::setSize(unsigned int width, unsigned int height)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue