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 "glad_wgl.h"
|
||||||
#include <GL/wglew.h>
|
|
||||||
|
|
||||||
#include <Platform/PlatformDisplay.h>
|
#include <Platform/PlatformDisplay.h>
|
||||||
#include <Spectre/System/Log.h>
|
#include <Spectre/System/Log.h>
|
||||||
|
|
@ -9,14 +8,20 @@
|
||||||
#include "Win32GLContext.h"
|
#include "Win32GLContext.h"
|
||||||
|
|
||||||
// Ensure that OpenGL extensions are loaded.
|
// Ensure that OpenGL extensions are loaded.
|
||||||
static void ensureExtensionsLoaded()
|
static void ensureExtensionsLoaded(HDC dc)
|
||||||
{
|
{
|
||||||
glewExperimental = GL_TRUE;
|
static bool init = false;
|
||||||
GLenum ret = glewInit();
|
|
||||||
if (ret != GLEW_OK) {
|
if (!init) {
|
||||||
log("Win32: Could not initialize GLEW %s\n",
|
init = true;
|
||||||
glewGetErrorString(ret));
|
|
||||||
return;
|
if (!gladLoadWGL(dc)) {
|
||||||
|
log("Win32: Could not load WGL extensions\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gladLoadGL()) {
|
||||||
|
log("Win32: Could not load OpenGL extensions\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,15 +94,12 @@ void Win32GLContext::createGLContext()
|
||||||
tmpDC = ::wglCreateContext(m_deviceContext);
|
tmpDC = ::wglCreateContext(m_deviceContext);
|
||||||
::wglMakeCurrent(m_deviceContext, tmpDC);
|
::wglMakeCurrent(m_deviceContext, tmpDC);
|
||||||
|
|
||||||
ensureExtensionsLoaded();
|
ensureExtensionsLoaded(m_deviceContext);
|
||||||
|
|
||||||
// Dont need to old one anymore.
|
// Dont need to old one anymore.
|
||||||
wglMakeCurrent(m_deviceContext, NULL);
|
wglMakeCurrent(m_deviceContext, NULL);
|
||||||
::wglDeleteContext(tmpDC);
|
::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.
|
// 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.
|
// The Display class should force that for all GLContext Implementations.
|
||||||
|
|
||||||
|
|
@ -110,21 +112,13 @@ void Win32GLContext::createGLContext()
|
||||||
|
|
||||||
// Create real context.
|
// Create real context.
|
||||||
m_renderContext = ::wglCreateContextAttribsARB(m_deviceContext, 0, attriblist);
|
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32GLContext::activate()
|
bool Win32GLContext::activate()
|
||||||
{
|
{
|
||||||
// Make sure we have dc and rc before calling MakeCurrent.
|
// Make sure we have dc and rc before calling MakeCurrent.
|
||||||
if (m_deviceContext && m_renderContext) {
|
if (m_deviceContext && m_renderContext) {
|
||||||
bool ret = ::wglMakeCurrent(m_deviceContext, m_renderContext);
|
return ::wglMakeCurrent(m_deviceContext, m_renderContext);
|
||||||
ensureExtensionsLoaded();
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -141,14 +135,10 @@ bool Win32GLContext::isActive() const
|
||||||
|
|
||||||
bool Win32GLContext::setSwapInterval(int interval)
|
bool Win32GLContext::setSwapInterval(int interval)
|
||||||
{
|
{
|
||||||
ensureExtensionsLoaded();
|
ensureExtensionsLoaded(m_deviceContext);
|
||||||
|
|
||||||
if (WGLEW_EXT_swap_control) {
|
|
||||||
return wglSwapIntervalEXT(interval);
|
return wglSwapIntervalEXT(interval);
|
||||||
}
|
}
|
||||||
log("wglSwapInterval: function is not supported\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Win32GLContext::setSize(unsigned int width, unsigned int height)
|
void Win32GLContext::setSize(unsigned int width, unsigned int height)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue