mirror of https://github.com/axmolengine/axmol.git
Use modern gl/gles loader 'glad' to instead 'glew'
This commit is contained in:
parent
1d551a1897
commit
1f9f27d63f
|
@ -101,6 +101,7 @@ endif()
|
|||
PUBLIC _UNICODE
|
||||
PUBLIC _CRT_SECURE_NO_WARNINGS
|
||||
PUBLIC _SCL_SECURE_NO_WARNINGS
|
||||
PUBLIC GLAD_GLAPI_EXPORT
|
||||
)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(${target}
|
||||
|
|
|
@ -200,7 +200,6 @@ static keyCodeItem g_keyCodeStructArray[] = {
|
|||
|
||||
GLViewImpl::GLViewImpl(bool initglfw)
|
||||
: _captured(false)
|
||||
, _supportTouch(false)
|
||||
, _isInRetinaMonitor(false)
|
||||
, _isRetinaEnabled(false)
|
||||
, _retinaFactor(1)
|
||||
|
@ -357,6 +356,8 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
|
|||
setFrameSize(rect.size.width, rect.size.height);
|
||||
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||
|
||||
loadGL();
|
||||
|
||||
// check OpenGL version at first
|
||||
const GLubyte* glVersion = glGetString(GL_VERSION);
|
||||
|
@ -371,14 +372,18 @@ bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float fram
|
|||
return false;
|
||||
}
|
||||
|
||||
initGlew();
|
||||
|
||||
// Enable point size by default.
|
||||
#if defined(GL_VERSION_2_0)
|
||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
#else
|
||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
|
||||
#endif
|
||||
|
||||
if(_glContextAttrs.multisamplingCount > 0)
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// // GLFW v3.2 no longer emits "onGLFWWindowSizeFunCallback" at creation time. Force default viewport:
|
||||
// setViewPortInPoints(0, 0, neededWidth, neededHeight);
|
||||
//
|
||||
|
@ -941,9 +946,8 @@ void GLViewImpl::onGLFWWindowFocusCallback(GLFWwindow* /*window*/, int focused)
|
|||
}
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
static bool glew_dynamic_binding()
|
||||
{
|
||||
const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
||||
static bool loadFboExtensions() {
|
||||
const char* gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
||||
|
||||
// If the current opengl driver doesn't have framebuffers methods, check if an extension exists
|
||||
if (glGenFramebuffers == nullptr)
|
||||
|
@ -953,45 +957,62 @@ static bool glew_dynamic_binding()
|
|||
{
|
||||
log("OpenGL: ARB_framebuffer_object is supported");
|
||||
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbuffer");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbuffer");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffers");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffers");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorage");
|
||||
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameteriv");
|
||||
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebuffer");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebuffer");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffers");
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffers");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatus");
|
||||
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1D");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2D");
|
||||
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3D");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbuffer");
|
||||
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameteriv");
|
||||
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmap");
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)glfwGetProcAddress("glIsRenderbuffer");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)glfwGetProcAddress("glBindRenderbuffer");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)glfwGetProcAddress("glDeleteRenderbuffers");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)glfwGetProcAddress("glGenRenderbuffers");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)glfwGetProcAddress("glRenderbufferStorage");
|
||||
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)glfwGetProcAddress("glGetRenderbufferParameteriv");
|
||||
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)glfwGetProcAddress("glIsFramebuffer");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)glfwGetProcAddress("glBindFramebuffer");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)glfwGetProcAddress("glDeleteFramebuffers");
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)glfwGetProcAddress("glGenFramebuffers");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)glfwGetProcAddress("glCheckFramebufferStatus");
|
||||
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)glfwGetProcAddress("glFramebufferTexture1D");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)glfwGetProcAddress("glFramebufferTexture2D");
|
||||
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)glfwGetProcAddress("glFramebufferTexture3D");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)glfwGetProcAddress("glFramebufferRenderbuffer");
|
||||
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)glfwGetProcAddress("glGetFramebufferAttachmentParameteriv");
|
||||
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)glfwGetProcAddress("glGenerateMipmap");
|
||||
}
|
||||
else
|
||||
if (strstr(gl_extensions, "EXT_framebuffer_object"))
|
||||
else if (strstr(gl_extensions, "EXT_framebuffer_object"))
|
||||
{
|
||||
log("OpenGL: EXT_framebuffer_object is supported");
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffersEXT");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorageEXT");
|
||||
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameterivEXT");
|
||||
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebufferEXT");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebufferEXT");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffersEXT");
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffersEXT");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatusEXT");
|
||||
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1DEXT");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2DEXT");
|
||||
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3DEXT");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbufferEXT");
|
||||
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameterivEXT");
|
||||
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmapEXT");
|
||||
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)glfwGetProcAddress("glIsRenderbufferEXT");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)glfwGetProcAddress("glBindRenderbufferEXT");
|
||||
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)glfwGetProcAddress("glDeleteRenderbuffersEXT");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)glfwGetProcAddress("glGenRenderbuffersEXT");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)glfwGetProcAddress("glRenderbufferStorageEXT");
|
||||
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)glfwGetProcAddress("glGetRenderbufferParameterivEXT");
|
||||
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)glfwGetProcAddress("glIsFramebufferEXT");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)glfwGetProcAddress("glBindFramebufferEXT");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)glfwGetProcAddress("glDeleteFramebuffersEXT");
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)glfwGetProcAddress("glGenFramebuffersEXT");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)glfwGetProcAddress("glCheckFramebufferStatusEXT");
|
||||
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)glfwGetProcAddress("glFramebufferTexture1DEXT");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)glfwGetProcAddress("glFramebufferTexture2DEXT");
|
||||
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)glfwGetProcAddress("glFramebufferTexture3DEXT");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)glfwGetProcAddress("glFramebufferRenderbufferEXT");
|
||||
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)glfwGetProcAddress("glGetFramebufferAttachmentParameterivEXT");
|
||||
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)glfwGetProcAddress("glGenerateMipmapEXT");
|
||||
}
|
||||
else if (strstr(gl_extensions, "GL_ANGLE_framebuffer_blit")) {
|
||||
log("OpenGL: GL_ANGLE_framebuffer_object is supported");
|
||||
glIsRenderbufferOES = (PFNGLISRENDERBUFFERPROC)glfwGetProcAddress("glIsRenderbufferOES");
|
||||
glBindRenderbufferOES = (PFNGLBINDRENDERBUFFERPROC)glfwGetProcAddress("glBindRenderbufferOES");
|
||||
glDeleteRenderbuffersOES = (PFNGLDELETERENDERBUFFERSPROC)glfwGetProcAddress("glDeleteRenderbuffersOES");
|
||||
glGenRenderbuffersOES = (PFNGLGENRENDERBUFFERSPROC)glfwGetProcAddress("glGenRenderbuffersOES");
|
||||
glRenderbufferStorageOES = (PFNGLRENDERBUFFERSTORAGEPROC)glfwGetProcAddress("glRenderbufferStorageOES");
|
||||
// glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)glfwGetProcAddress("glGetRenderbufferParameterivOES");
|
||||
glIsFramebufferOES = (PFNGLISFRAMEBUFFERPROC)glfwGetProcAddress("glIsFramebufferOES");
|
||||
glBindFramebufferOES = (PFNGLBINDFRAMEBUFFERPROC)glfwGetProcAddress("glBindFramebufferOES");
|
||||
glDeleteFramebuffersOES = (PFNGLDELETEFRAMEBUFFERSPROC)glfwGetProcAddress("glDeleteFramebuffersOES");
|
||||
glGenFramebuffersOES = (PFNGLGENFRAMEBUFFERSPROC)glfwGetProcAddress("glGenFramebuffersOES");
|
||||
glCheckFramebufferStatusOES = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)glfwGetProcAddress("glCheckFramebufferStatusOES");
|
||||
glFramebufferRenderbufferOES = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)glfwGetProcAddress("glFramebufferRenderbufferOES");
|
||||
glFramebufferTexture2DOES = (PFNGLFRAMEBUFFERTEXTURE2DPROC)glfwGetProcAddress("glFramebufferTexture2DOES");
|
||||
glGetFramebufferAttachmentParameterivOES = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)glfwGetProcAddress("glGetFramebufferAttachmentParameterivOES");
|
||||
glGenerateMipmapOES = (PFNGLGENERATEMIPMAPPROC)glfwGetProcAddress("glGenerateMipmapOES");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1005,19 +1026,18 @@ static bool glew_dynamic_binding()
|
|||
#endif
|
||||
|
||||
// helper
|
||||
bool GLViewImpl::initGlew()
|
||||
bool GLViewImpl::loadGL()
|
||||
{
|
||||
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||
GLenum GlewInitResult = glewInit();
|
||||
if (GLEW_OK != GlewInitResult)
|
||||
|
||||
// glad: load all OpenGL function pointers
|
||||
// ---------------------------------------
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
ccMessageBox((char *)glewGetErrorString(GlewInitResult), "OpenGL error");
|
||||
log("glad: Failed to Load GL");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
|
||||
{
|
||||
if (GL_ARB_vertex_shader && GL_ARB_fragment_shader) {
|
||||
log("Ready for GLSL");
|
||||
}
|
||||
else
|
||||
|
@ -1025,25 +1045,15 @@ bool GLViewImpl::initGlew()
|
|||
log("Not totally ready :(");
|
||||
}
|
||||
|
||||
if (glewIsSupported("GL_VERSION_2_0"))
|
||||
{
|
||||
log("Ready for OpenGL 2.0");
|
||||
}
|
||||
else
|
||||
{
|
||||
log("OpenGL 2.0 not supported");
|
||||
}
|
||||
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
if(glew_dynamic_binding() == false)
|
||||
{
|
||||
ccMessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error");
|
||||
if (!loadFboExtensions())
|
||||
return false;
|
||||
}
|
||||
#endif //#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
// close _vsync_ default for nvidia display card
|
||||
::glfwSwapInterval(0);
|
||||
#endif
|
||||
|
||||
#endif //#if (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -133,12 +133,12 @@ protected:
|
|||
GLViewImpl(bool initglfw = true);
|
||||
virtual ~GLViewImpl();
|
||||
|
||||
bool initGlew();
|
||||
|
||||
bool initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor, bool resizable);
|
||||
bool initWithFullScreen(const std::string& viewName);
|
||||
bool initWithFullscreen(const std::string& viewname, const GLFWvidmode &videoMode, GLFWmonitor *monitor);
|
||||
|
||||
bool loadGL();
|
||||
|
||||
void updateFrameSize();
|
||||
|
||||
// GLFW callbacks
|
||||
|
@ -155,7 +155,6 @@ protected:
|
|||
void onGLFWWindowFocusCallback(GLFWwindow* window, int focused);
|
||||
|
||||
bool _captured;
|
||||
bool _supportTouch;
|
||||
bool _isInRetinaMonitor;
|
||||
bool _isRetinaEnabled;
|
||||
int _retinaFactor; // Should be 1 or 2
|
||||
|
|
|
@ -25,6 +25,6 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "GL/glew.h"
|
||||
#include "glad/glad.h"
|
||||
|
||||
#define CC_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "v29",
|
||||
"version": "v30",
|
||||
"zip_file_size": "107642814",
|
||||
"repo_name": "engine-v5-3rd",
|
||||
"repo_parent": "https://github.com/c4games/",
|
||||
|
|
Loading…
Reference in New Issue