bool GLLibraryEGL::EnsureInitialized(bool forceAccel, nsACString* const out_failureId) { if (mInitialized) { return true; } mozilla::ScopedGfxFeatureReporter reporter("EGL"); #ifdef MOZ_B2G if (!sCurrentContext.init()) MOZ_CRASH("GFX: Tls init failed"); #endif #ifdef XP_WIN if (!mEGLLibrary) { // On Windows, the GLESv2, EGL and DXSDK libraries are shipped with libxul and // we should look for them there. We have to load the libs in this // order, because libEGL.dll depends on libGLESv2.dll which depends on the DXSDK // libraries. This matters especially for WebRT apps which are in a different directory. // See bug 760323 and bug 749459 // Also note that we intentionally leak the libs we load. do { // Windows 8.1 has d3dcompiler_47.dll in the system directory. // Try it first. Note that _46 will never be in the system // directory and we ship with at least _43. So there is no point // trying _46 and _43 in the system directory. if (LoadLibrarySystem32(L"d3dcompiler_47.dll")) break; #ifdef MOZ_D3DCOMPILER_VISTA_DLL if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_VISTA_DLL)))) break; #endif #ifdef MOZ_D3DCOMPILER_XP_DLL if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_XP_DLL)))) break; #endif MOZ_ASSERT(false, "d3dcompiler DLL loading failed."); } while (false); LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libGLESv2.dll")); mEGLLibrary = LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libEGL.dll")); if (!mEGLLibrary) return false; } #else // !Windows // On non-Windows (Android) we use system copies of libEGL. We look for // the APITrace lib, libEGL.so, and libEGL.so.1 in that order. #if defined(ANDROID) if (!mEGLLibrary) mEGLLibrary = LoadApitraceLibrary(); #endif if (!mEGLLibrary) { printf_stderr("Attempting load of libEGL.so\n"); mEGLLibrary = PR_LoadLibrary("libEGL.so"); } #if defined(XP_UNIX) if (!mEGLLibrary) { mEGLLibrary = PR_LoadLibrary("libEGL.so.1"); } #endif if (!mEGLLibrary) { NS_WARNING("Couldn't load EGL LIB."); return false; } #endif // !Windows #define SYMBOL(name) \ { (PRFuncPtr*) &mSymbols.f##name, { "egl" #name, nullptr } } GLLibraryLoader::SymLoadStruct earlySymbols[] = { SYMBOL(GetDisplay), SYMBOL(Terminate), SYMBOL(GetCurrentSurface), SYMBOL(GetCurrentContext), SYMBOL(MakeCurrent), SYMBOL(DestroyContext), SYMBOL(CreateContext), SYMBOL(DestroySurface), SYMBOL(CreateWindowSurface), SYMBOL(CreatePbufferSurface), SYMBOL(CreatePixmapSurface), SYMBOL(BindAPI), SYMBOL(Initialize), SYMBOL(ChooseConfig), SYMBOL(GetError), SYMBOL(GetConfigs), SYMBOL(GetConfigAttrib), SYMBOL(WaitNative), SYMBOL(GetProcAddress), SYMBOL(SwapBuffers), SYMBOL(CopyBuffers), SYMBOL(QueryString), SYMBOL(QueryContext), SYMBOL(BindTexImage), SYMBOL(ReleaseTexImage), SYMBOL(QuerySurface), { nullptr, { nullptr } } }; if (!GLLibraryLoader::LoadSymbols(mEGLLibrary, &earlySymbols[0])) { NS_WARNING("Couldn't find required entry points in EGL library (early init)"); return false; } GLLibraryLoader::SymLoadStruct optionalSymbols[] = { // On Android 4.3 and up, certain features like ANDROID_native_fence_sync // can only be queried by using a special eglQueryString. { (PRFuncPtr*) &mSymbols.fQueryStringImplementationANDROID, { "_Z35eglQueryStringImplementationANDROIDPvi", nullptr } }, { nullptr, { nullptr } } }; // Do not warn about the failure to load this - see bug 1092191 Unused << GLLibraryLoader::LoadSymbols(mEGLLibrary, &optionalSymbols[0], nullptr, nullptr, false); #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18 MOZ_RELEASE_ASSERT(mSymbols.fQueryStringImplementationANDROID, "GFX: Couldn't find eglQueryStringImplementationANDROID"); #endif InitClientExtensions(); const auto lookupFunction = (GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress; // Client exts are ready. (But not display exts!) if (IsExtensionSupported(ANGLE_platform_angle_d3d)) { GLLibraryLoader::SymLoadStruct d3dSymbols[] = { { (PRFuncPtr*)&mSymbols.fANGLEPlatformInitialize, { "ANGLEPlatformInitialize", nullptr } }, { (PRFuncPtr*)&mSymbols.fANGLEPlatformShutdown, { "ANGLEPlatformShutdown", nullptr } }, { (PRFuncPtr*)&mSymbols.fGetPlatformDisplayEXT, { "eglGetPlatformDisplayEXT", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &d3dSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANGLE_platform_angle_d3d without exposing its functions!"); MarkExtensionUnsupported(ANGLE_platform_angle_d3d); mSymbols.fGetPlatformDisplayEXT = nullptr; } } // Check the ANGLE support the system has nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); mIsANGLE = IsExtensionSupported(ANGLE_platform_angle); EGLDisplay chosenDisplay = nullptr; if (IsExtensionSupported(ANGLE_platform_angle_d3d)) { nsCString accelAngleFailureId; bool accelAngleSupport = IsAccelAngleSupported(gfxInfo, &accelAngleFailureId); bool shouldTryAccel = forceAccel || accelAngleSupport; bool shouldTryWARP = !forceAccel; // Only if ANGLE not supported or fails // If WARP preferred, will override ANGLE support if (gfxPrefs::WebGLANGLEForceWARP()) { shouldTryWARP = true; shouldTryAccel = false; if (accelAngleFailureId.IsEmpty()) { accelAngleFailureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_FORCE_WARP"); } } // Hardware accelerated ANGLE path (supported or force accel) if (shouldTryAccel) { chosenDisplay = GetAndInitDisplayForAccelANGLE(*this, out_failureId); } // Report the acceleration status to telemetry if (!chosenDisplay) { if (accelAngleFailureId.IsEmpty()) { Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_ACCL_FAILURE_ID, NS_LITERAL_CSTRING("FEATURE_FAILURE_ACCL_ANGLE_UNKNOWN")); } else { Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_ACCL_FAILURE_ID, accelAngleFailureId); } } else { Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_ACCL_FAILURE_ID, NS_LITERAL_CSTRING("SUCCESS")); } // Fallback to a WARP display if ANGLE fails, or if WARP is forced if (!chosenDisplay && shouldTryWARP) { chosenDisplay = GetAndInitWARPDisplay(*this, EGL_DEFAULT_DISPLAY); if (!chosenDisplay) { if (out_failureId->IsEmpty()) { *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WARP_FALLBACK"); } NS_ERROR("Fallback WARP context failed to initialize."); return false; } mIsWARP = true; } } else { chosenDisplay = GetAndInitDisplay(*this, EGL_DEFAULT_DISPLAY); } if (!chosenDisplay) { if (out_failureId->IsEmpty()) { *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_NO_DISPLAY"); } NS_WARNING("Failed to initialize a display."); return false; } mEGLDisplay = chosenDisplay; InitDisplayExtensions(); //////////////////////////////////// // Alright, load display exts. if (IsExtensionSupported(KHR_lock_surface)) { GLLibraryLoader::SymLoadStruct lockSymbols[] = { { (PRFuncPtr*) &mSymbols.fLockSurface, { "eglLockSurfaceKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fUnlockSurface, { "eglUnlockSurfaceKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &lockSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_lock_surface without exposing its functions!"); MarkExtensionUnsupported(KHR_lock_surface); mSymbols.fLockSurface = nullptr; mSymbols.fUnlockSurface = nullptr; } } if (IsExtensionSupported(ANGLE_surface_d3d_texture_2d_share_handle)) { GLLibraryLoader::SymLoadStruct d3dSymbols[] = { { (PRFuncPtr*) &mSymbols.fQuerySurfacePointerANGLE, { "eglQuerySurfacePointerANGLE", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &d3dSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANGLE_surface_d3d_texture_2d_share_handle without exposing its functions!"); MarkExtensionUnsupported(ANGLE_surface_d3d_texture_2d_share_handle); mSymbols.fQuerySurfacePointerANGLE = nullptr; } } if (IsExtensionSupported(KHR_fence_sync)) { GLLibraryLoader::SymLoadStruct syncSymbols[] = { { (PRFuncPtr*) &mSymbols.fCreateSync, { "eglCreateSyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fDestroySync, { "eglDestroySyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fClientWaitSync, { "eglClientWaitSyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fGetSyncAttrib, { "eglGetSyncAttribKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &syncSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_fence_sync without exposing its functions!"); MarkExtensionUnsupported(KHR_fence_sync); mSymbols.fCreateSync = nullptr; mSymbols.fDestroySync = nullptr; mSymbols.fClientWaitSync = nullptr; mSymbols.fGetSyncAttrib = nullptr; } } if (IsExtensionSupported(KHR_image) || IsExtensionSupported(KHR_image_base)) { GLLibraryLoader::SymLoadStruct imageSymbols[] = { { (PRFuncPtr*) &mSymbols.fCreateImage, { "eglCreateImageKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fDestroyImage, { "eglDestroyImageKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &imageSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_image(_base) without exposing its functions!"); MarkExtensionUnsupported(KHR_image); MarkExtensionUnsupported(KHR_image_base); MarkExtensionUnsupported(KHR_image_pixmap); mSymbols.fCreateImage = nullptr; mSymbols.fDestroyImage = nullptr; } } else { MarkExtensionUnsupported(KHR_image_pixmap); } if (IsExtensionSupported(ANDROID_native_fence_sync)) { GLLibraryLoader::SymLoadStruct nativeFenceSymbols[] = { { (PRFuncPtr*) &mSymbols.fDupNativeFenceFDANDROID, { "eglDupNativeFenceFDANDROID", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &nativeFenceSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANDROID_native_fence_sync without exposing its functions!"); MarkExtensionUnsupported(ANDROID_native_fence_sync); mSymbols.fDupNativeFenceFDANDROID = nullptr; } } mInitialized = true; reporter.SetSuccessful(); return true; }
bool GLLibraryEGL::EnsureInitialized() { if (mInitialized) { return true; } #ifdef XP_WIN #ifdef MOZ_WEBGL if (!mEGLLibrary) { // On Windows, the GLESv2, EGL and DXSDK libraries are shipped with libxul and // we should look for them there. We have to load the libs in this // order, because libEGL.dll depends on libGLESv2.dll which depends on the DXSDK // libraries. This matters especially for WebRT apps which are in a different directory. // See bug 760323 and bug 749459 #ifndef MOZ_D3DCOMPILER_DLL #error MOZ_D3DCOMPILER_DLL should have been defined by the Makefile #endif LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_DLL))); // intentionally leak the D3DCOMPILER_DLL library LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libGLESv2.dll")); // intentionally leak the libGLESv2.dll library mEGLLibrary = LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libEGL.dll")); if (!mEGLLibrary) return false; } #endif // MOZ_WEBGL #else // !Windows // On non-Windows (Android) we use system copies of libEGL. We look for // the APITrace lib, libEGL.so, and libEGL.so.1 in that order. #if defined(ANDROID) if (!mEGLLibrary) mEGLLibrary = LoadApitraceLibrary(); #endif if (!mEGLLibrary) { printf_stderr("Attempting load of libEGL.so\n"); mEGLLibrary = PR_LoadLibrary("libEGL.so"); } #if defined(XP_UNIX) if (!mEGLLibrary) { mEGLLibrary = PR_LoadLibrary("libEGL.so.1"); } #endif if (!mEGLLibrary) { NS_WARNING("Couldn't load EGL LIB."); return false; } #endif // !Windows #define SYMBOL(name) \ { (PRFuncPtr*) &mSymbols.f##name, { "egl" #name, NULL } } GLLibraryLoader::SymLoadStruct earlySymbols[] = { SYMBOL(GetDisplay), SYMBOL(GetCurrentSurface), SYMBOL(GetCurrentContext), SYMBOL(MakeCurrent), SYMBOL(DestroyContext), SYMBOL(CreateContext), SYMBOL(DestroySurface), SYMBOL(CreateWindowSurface), SYMBOL(CreatePbufferSurface), SYMBOL(CreatePixmapSurface), SYMBOL(BindAPI), SYMBOL(Initialize), SYMBOL(ChooseConfig), SYMBOL(GetError), SYMBOL(GetConfigs), SYMBOL(GetConfigAttrib), SYMBOL(WaitNative), SYMBOL(GetProcAddress), SYMBOL(SwapBuffers), SYMBOL(CopyBuffers), SYMBOL(QueryString), SYMBOL(QueryContext), SYMBOL(BindTexImage), SYMBOL(ReleaseTexImage), SYMBOL(QuerySurface), { NULL, { NULL } } }; if (!GLLibraryLoader::LoadSymbols(mEGLLibrary, &earlySymbols[0])) { NS_WARNING("Couldn't find required entry points in EGL library (early init)"); return false; } mEGLDisplay = fGetDisplay(EGL_DEFAULT_DISPLAY); if (!fInitialize(mEGLDisplay, NULL, NULL)) return false; const char *vendor = (const char*) fQueryString(mEGLDisplay, LOCAL_EGL_VENDOR); if (vendor && (strstr(vendor, "TransGaming") != 0 || strstr(vendor, "Google Inc.") != 0)) { mIsANGLE = true; } InitExtensions(); GLLibraryLoader::PlatformLookupFunction lookupFunction = (GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress; if (IsExtensionSupported(KHR_lock_surface)) { GLLibraryLoader::SymLoadStruct lockSymbols[] = { { (PRFuncPtr*) &mSymbols.fLockSurface, { "eglLockSurfaceKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fUnlockSurface, { "eglUnlockSurfaceKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &lockSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_lock_surface without exposing its functions!"); MarkExtensionUnsupported(KHR_lock_surface); mSymbols.fLockSurface = nullptr; mSymbols.fUnlockSurface = nullptr; } } if (IsExtensionSupported(ANGLE_surface_d3d_texture_2d_share_handle)) { GLLibraryLoader::SymLoadStruct d3dSymbols[] = { { (PRFuncPtr*) &mSymbols.fQuerySurfacePointerANGLE, { "eglQuerySurfacePointerANGLE", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &d3dSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANGLE_surface_d3d_texture_2d_share_handle without exposing its functions!"); MarkExtensionUnsupported(ANGLE_surface_d3d_texture_2d_share_handle); mSymbols.fQuerySurfacePointerANGLE = nullptr; } } if (IsExtensionSupported(KHR_fence_sync)) { GLLibraryLoader::SymLoadStruct syncSymbols[] = { { (PRFuncPtr*) &mSymbols.fCreateSync, { "eglCreateSyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fDestroySync, { "eglDestroySyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fClientWaitSync, { "eglClientWaitSyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fGetSyncAttrib, { "eglGetSyncAttribKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &syncSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_fence_sync without exposing its functions!"); MarkExtensionUnsupported(KHR_fence_sync); mSymbols.fCreateSync = nullptr; mSymbols.fDestroySync = nullptr; mSymbols.fClientWaitSync = nullptr; mSymbols.fGetSyncAttrib = nullptr; } } if (IsExtensionSupported(KHR_image) || IsExtensionSupported(KHR_image_base)) { GLLibraryLoader::SymLoadStruct imageSymbols[] = { { (PRFuncPtr*) &mSymbols.fCreateImage, { "eglCreateImageKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fDestroyImage, { "eglDestroyImageKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &imageSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_image(_base) without exposing its functions!"); MarkExtensionUnsupported(KHR_image); MarkExtensionUnsupported(KHR_image_base); MarkExtensionUnsupported(KHR_image_pixmap); mSymbols.fCreateImage = nullptr; mSymbols.fDestroyImage = nullptr; } } else { MarkExtensionUnsupported(KHR_image_pixmap); } mInitialized = true; return true; }
void COGLGraphicsContext::InitOGLExtension(void) { #if SDL_VIDEO_OPENGL // important extension features, it is very bad not to have these feature m_bSupportMultiTexture = IsExtensionSupported(OSAL_GL_ARB_MULTITEXTURE); m_bSupportTextureEnvCombine = IsExtensionSupported("GL_EXT_texture_env_combine"); m_bSupportSeparateSpecularColor = IsExtensionSupported("GL_EXT_separate_specular_color"); m_bSupportSecondColor = IsExtensionSupported("GL_EXT_secondary_color"); m_bSupportFogCoord = IsExtensionSupported("GL_EXT_fog_coord"); m_bSupportTextureObject = IsExtensionSupported("GL_EXT_texture_object"); // Optional extension features m_bSupportRescaleNormal = IsExtensionSupported("GL_EXT_rescale_normal"); m_bSupportLODBias = IsExtensionSupported("GL_EXT_texture_lod_bias"); m_bSupportAnisotropicFiltering = IsExtensionSupported("GL_EXT_texture_filter_anisotropic"); #else m_bSupportMultiTexture = true; m_bSupportFogCoord = true; m_bSupportAnisotropicFiltering = true; #endif // Compute maxAnisotropicFiltering m_maxAnisotropicFiltering = 0; if( m_bSupportAnisotropicFiltering && (options.anisotropicFiltering == 2 || options.anisotropicFiltering == 4 || options.anisotropicFiltering == 8 || options.anisotropicFiltering == 16)) { //Get the max value of aniso that the graphic card support glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &m_maxAnisotropicFiltering); OPENGL_CHECK_ERRORS; // If user want more aniso than hardware can do if(options.anisotropicFiltering > (uint32) m_maxAnisotropicFiltering) { DebugMessage(M64MSG_INFO, "A value of '%i' is set for AnisotropicFiltering option but the hardware has a maximum value of '%i' so this will be used", options.anisotropicFiltering, m_maxAnisotropicFiltering); } //check if user want less anisotropy than hardware can do if((uint32) m_maxAnisotropicFiltering > options.anisotropicFiltering) m_maxAnisotropicFiltering = options.anisotropicFiltering; } #if SDL_VIDEO_OPENGL // Nvidia only extension features (optional) m_bSupportNVRegisterCombiner = IsExtensionSupported("GL_NV_register_combiners"); m_bSupportTextureMirrorRepeat = IsExtensionSupported("GL_IBM_texture_mirrored_repeat") || IsExtensionSupported("ARB_texture_mirrored_repeat"); m_supportTextureMirror = m_bSupportTextureMirrorRepeat; m_bSupportTextureLOD = IsExtensionSupported("GL_EXT_texture_lod"); m_bSupportBlendColor = IsExtensionSupported("GL_EXT_blend_color"); m_bSupportBlendSubtract = IsExtensionSupported("GL_EXT_blend_subtract"); m_bSupportNVTextureEnvCombine4 = IsExtensionSupported("GL_NV_texture_env_combine4"); #else m_supportTextureMirror = true; #endif }
bool GLLibraryEGL::EnsureInitialized() { if (mInitialized) { return true; } mozilla::ScopedGfxFeatureReporter reporter("EGL"); #ifdef MOZ_B2G if (!sCurrentContext.init()) MOZ_CRASH("Tls init failed"); #endif #ifdef XP_WIN if (!mEGLLibrary) { // On Windows, the GLESv2, EGL and DXSDK libraries are shipped with libxul and // we should look for them there. We have to load the libs in this // order, because libEGL.dll depends on libGLESv2.dll which depends on the DXSDK // libraries. This matters especially for WebRT apps which are in a different directory. // See bug 760323 and bug 749459 // Also note that we intentionally leak the libs we load. do { // Windows 8.1 has d3dcompiler_47.dll in the system directory. // Try it first. Note that _46 will never be in the system // directory and we ship with at least _43. So there is no point // trying _46 and _43 in the system directory. if (LoadLibrarySystem32(L"d3dcompiler_47.dll")) break; #ifdef MOZ_D3DCOMPILER_VISTA_DLL if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_VISTA_DLL)))) break; #endif #ifdef MOZ_D3DCOMPILER_XP_DLL if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_XP_DLL)))) break; #endif MOZ_ASSERT(false, "d3dcompiler DLL loading failed."); } while (false); LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libGLESv2.dll")); mEGLLibrary = LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libEGL.dll")); if (!mEGLLibrary) return false; } #else // !Windows // On non-Windows (Android) we use system copies of libEGL. We look for // the APITrace lib, libEGL.so, and libEGL.so.1 in that order. #if defined(ANDROID) if (!mEGLLibrary) mEGLLibrary = LoadApitraceLibrary(); #endif if (!mEGLLibrary) { printf_stderr("Attempting load of libEGL.so\n"); mEGLLibrary = PR_LoadLibrary("libEGL.so"); } #if defined(XP_UNIX) if (!mEGLLibrary) { mEGLLibrary = PR_LoadLibrary("libEGL.so.1"); } #endif if (!mEGLLibrary) { NS_WARNING("Couldn't load EGL LIB."); return false; } #endif // !Windows #define SYMBOL(name) \ { (PRFuncPtr*) &mSymbols.f##name, { "egl" #name, nullptr } } GLLibraryLoader::SymLoadStruct earlySymbols[] = { SYMBOL(GetDisplay), SYMBOL(Terminate), SYMBOL(GetCurrentSurface), SYMBOL(GetCurrentContext), SYMBOL(MakeCurrent), SYMBOL(DestroyContext), SYMBOL(CreateContext), SYMBOL(DestroySurface), SYMBOL(CreateWindowSurface), SYMBOL(CreatePbufferSurface), SYMBOL(CreatePixmapSurface), SYMBOL(BindAPI), SYMBOL(Initialize), SYMBOL(ChooseConfig), SYMBOL(GetError), SYMBOL(GetConfigs), SYMBOL(GetConfigAttrib), SYMBOL(WaitNative), SYMBOL(GetProcAddress), SYMBOL(SwapBuffers), SYMBOL(CopyBuffers), SYMBOL(QueryString), SYMBOL(QueryContext), SYMBOL(BindTexImage), SYMBOL(ReleaseTexImage), SYMBOL(QuerySurface), { nullptr, { nullptr } } }; if (!GLLibraryLoader::LoadSymbols(mEGLLibrary, &earlySymbols[0])) { NS_WARNING("Couldn't find required entry points in EGL library (early init)"); return false; } GLLibraryLoader::SymLoadStruct optionalSymbols[] = { // On Android 4.3 and up, certain features like ANDROID_native_fence_sync // can only be queried by using a special eglQueryString. { (PRFuncPtr*) &mSymbols.fQueryStringImplementationANDROID, { "_Z35eglQueryStringImplementationANDROIDPvi", nullptr } }, { nullptr, { nullptr } } }; // Do not warn about the failure to load this - see bug 1092191 GLLibraryLoader::LoadSymbols(mEGLLibrary, &optionalSymbols[0], nullptr, nullptr, false); #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18 MOZ_RELEASE_ASSERT(mSymbols.fQueryStringImplementationANDROID, "Couldn't find eglQueryStringImplementationANDROID"); #endif mEGLDisplay = GetAndInitDisplay(*this, EGL_DEFAULT_DISPLAY); const char* vendor = (char*)fQueryString(mEGLDisplay, LOCAL_EGL_VENDOR); if (vendor && (strstr(vendor, "TransGaming") != 0 || strstr(vendor, "Google Inc.") != 0)) { mIsANGLE = true; } if (mIsANGLE) { EGLDisplay newDisplay = EGL_NO_DISPLAY; // D3D11 ANGLE only works with OMTC; there's a bug in the non-OMTC layer // manager, and it's pointless to try to fix it. We also don't try // D3D11 ANGLE if the layer manager is prefering D3D9 (hrm, do we care?) if (gfxPrefs::LayersOffMainThreadCompositionEnabled() && !gfxPrefs::LayersPreferD3D9()) { if (gfxPrefs::WebGLANGLEForceD3D11()) { newDisplay = GetAndInitDisplay(*this, LOCAL_EGL_D3D11_ONLY_DISPLAY_ANGLE); } else if (gfxPrefs::WebGLANGLETryD3D11() && gfxPlatform::CanUseDirect3D11ANGLE()) { newDisplay = GetAndInitDisplay(*this, LOCAL_EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE); } } if (newDisplay != EGL_NO_DISPLAY) { DebugOnly<EGLBoolean> success = fTerminate(mEGLDisplay); MOZ_ASSERT(success == LOCAL_EGL_TRUE); mEGLDisplay = newDisplay; vendor = (char*)fQueryString(mEGLDisplay, LOCAL_EGL_VENDOR); } } InitExtensions(); GLLibraryLoader::PlatformLookupFunction lookupFunction = (GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress; if (IsExtensionSupported(KHR_lock_surface)) { GLLibraryLoader::SymLoadStruct lockSymbols[] = { { (PRFuncPtr*) &mSymbols.fLockSurface, { "eglLockSurfaceKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fUnlockSurface, { "eglUnlockSurfaceKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &lockSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_lock_surface without exposing its functions!"); MarkExtensionUnsupported(KHR_lock_surface); mSymbols.fLockSurface = nullptr; mSymbols.fUnlockSurface = nullptr; } } if (IsExtensionSupported(ANGLE_surface_d3d_texture_2d_share_handle)) { GLLibraryLoader::SymLoadStruct d3dSymbols[] = { { (PRFuncPtr*) &mSymbols.fQuerySurfacePointerANGLE, { "eglQuerySurfacePointerANGLE", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &d3dSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANGLE_surface_d3d_texture_2d_share_handle without exposing its functions!"); MarkExtensionUnsupported(ANGLE_surface_d3d_texture_2d_share_handle); mSymbols.fQuerySurfacePointerANGLE = nullptr; } } //XXX: use correct extension name if (IsExtensionSupported(ANGLE_surface_d3d_texture_2d_share_handle)) { GLLibraryLoader::SymLoadStruct d3dSymbols[] = { { (PRFuncPtr*)&mSymbols.fSurfaceReleaseSyncANGLE, { "eglSurfaceReleaseSyncANGLE", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &d3dSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANGLE_surface_d3d_texture_2d_share_handle without exposing its functions!"); MarkExtensionUnsupported(ANGLE_surface_d3d_texture_2d_share_handle); mSymbols.fSurfaceReleaseSyncANGLE = nullptr; } } if (IsExtensionSupported(KHR_fence_sync)) { GLLibraryLoader::SymLoadStruct syncSymbols[] = { { (PRFuncPtr*) &mSymbols.fCreateSync, { "eglCreateSyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fDestroySync, { "eglDestroySyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fClientWaitSync, { "eglClientWaitSyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fGetSyncAttrib, { "eglGetSyncAttribKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &syncSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_fence_sync without exposing its functions!"); MarkExtensionUnsupported(KHR_fence_sync); mSymbols.fCreateSync = nullptr; mSymbols.fDestroySync = nullptr; mSymbols.fClientWaitSync = nullptr; mSymbols.fGetSyncAttrib = nullptr; } } if (IsExtensionSupported(KHR_image) || IsExtensionSupported(KHR_image_base)) { GLLibraryLoader::SymLoadStruct imageSymbols[] = { { (PRFuncPtr*) &mSymbols.fCreateImage, { "eglCreateImageKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fDestroyImage, { "eglDestroyImageKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &imageSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_image(_base) without exposing its functions!"); MarkExtensionUnsupported(KHR_image); MarkExtensionUnsupported(KHR_image_base); MarkExtensionUnsupported(KHR_image_pixmap); mSymbols.fCreateImage = nullptr; mSymbols.fDestroyImage = nullptr; } } else { MarkExtensionUnsupported(KHR_image_pixmap); } if (IsExtensionSupported(ANDROID_native_fence_sync)) { GLLibraryLoader::SymLoadStruct nativeFenceSymbols[] = { { (PRFuncPtr*) &mSymbols.fDupNativeFenceFDANDROID, { "eglDupNativeFenceFDANDROID", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &nativeFenceSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANDROID_native_fence_sync without exposing its functions!"); MarkExtensionUnsupported(ANDROID_native_fence_sync); mSymbols.fDupNativeFenceFDANDROID = nullptr; } } mInitialized = true; reporter.SetSuccessful(); return true; }
void GLSLProgram::Create( char *vfile, char *gfile, char *ffile ) { CanDoFragmentShader = IsExtensionSupported( "GL_ARB_fragment_shader" ); CanDoGeometryShader = IsExtensionSupported( "GL_EXT_geometry_shader4" ); CanDoVertexShader = IsExtensionSupported( "GL_ARB_vertex_shader" ); InputTopology = GL_TRIANGLES; OutputTopology = GL_TRIANGLE_STRIP; Vshader = Gshader = Fshader = 0; Program = 0; AttributeLocs.clear(); UniformLocs.clear(); Verbose = false; this->Program = glCreateProgram(); CheckGlErrors( "glCreateProgram" ); if( vfile != NULL && vfile[0] != '\0' ) { if( ! CanDoVertexShader ) { fprintf( stderr, "Warning: this system cannot handle vertex shaders\n" ); } this->Vshader = LoadVertexShader( vfile ); int status = CompileShader( this->Vshader ); if( status != 0 ) { if( this->Verbose ) fprintf( stderr, "Shader '%s' compiled.\n", vfile ); AttachShader( this->Vshader ); } else { fprintf( stderr, "Shader '%s' did not compile.\n", vfile ); } } if( gfile != NULL && gfile[0] != '\0' ) { if( ! CanDoGeometryShader ) { fprintf( stderr, "Warning: this system cannot handle geometry shaders\n" ); } this->Gshader = LoadGeometryShader( gfile ); int status = CompileShader( this->Gshader ); if( status != 0 ) { if( this->Verbose ) fprintf( stderr, "Shader '%s' compiled.\n", gfile ); AttachShader( Gshader ); } else { fprintf( stderr, "Shader '%s' did not compile.\n", gfile ); } } if( ffile != NULL && ffile[0] != '\0' ) { if( ! CanDoFragmentShader ) { fprintf( stderr, "Warning: this system cannot handle fragment shaders\n" ); } this->Fshader = LoadFragmentShader( ffile ); int status = CompileShader( this->Fshader ); if( status != 0 ) { if( this->Verbose ) fprintf( stderr, "Shader '%s' compiled.\n", ffile ); AttachShader( Fshader ); } else { fprintf( stderr, "Shader '%s' did not compile.\n", ffile ); } } LinkProgram(); };
void Gl::GreOpenGlInit() { if(Initialized) return; // Those are required functions... GetIntegerv = (PFNGLGETINTEGERVPROC) GlGetProcAddress("glGetIntegerv"); GetString = (PFNGLGETSTRINGPROC) GlGetProcAddress("glGetString"); GetStringi = (PFNGLGETSTRINGIPROC) GlGetProcAddress("glGetStringi"); ClearColor = (PFNGLCLEARCOLORPROC) GlGetProcAddress("glClearColor"); ClearDepth = (PFNGLCLEARDEPTHPROC) GlGetProcAddress("glClearDepth"); Viewport = (PFNGLVIEWPORTPROC) GlGetProcAddress("glViewport"); Clear = (PFNGLCLEARPROC) GlGetProcAddress("glClear"); Enable = (PFNGLENABLEPROC) GlGetProcAddress("glEnable"); Disable = (PFNGLDISABLEPROC) GlGetProcAddress("glDisable"); Flush = (PFNGLFLUSHPROC) GlGetProcAddress("glFlush"); DepthFunc = (PFNGLDEPTHFUNCPROC) GlGetProcAddress("glDepthFunc"); ActiveTexture = (PFNGLACTIVETEXTUREPROC) GlGetProcAddress("glActiveTexture"); if(GetString) { GreOpenGlVersionInit(); } #ifdef GreIsDebugMode else { GreDebugPretty() << "No glGlobalContext->getGl().GetString function found to initialize Gl Version." << std::endl; throw GreOpenGlVersionInitException ("glGlobalContext->getGl().GetString not found."); } #endif if(GetStringi && GetIntegerv) { GreOpenGl3ExtensionInit(); } #ifdef GreIsDebugMode else { GreDebugPretty() << "No glGlobalContext->getGl().GetStringi function found... Please update your drivers. glGetStringi is supported from OpenGl " << "3.0 version." << std::endl; throw GreOpenGl3ExtensionInitException ("glGlobalContext->getGl().GetStringi not found."); } #endif if(VersionMajor >= 3 || IsExtensionSupported("GL_ARB_framebuffer_object")) { GenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) GlGetProcAddress("glGenFramebuffers"); DeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) GlGetProcAddress("glDeleteFramebuffers"); BindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) GlGetProcAddress("glBindFramebuffer"); FramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC) GlGetProcAddress("glFramebufferTexture"); } else if(IsExtensionSupported("GL_EXT_framebuffer_object")) { GenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) GlGetProcAddress("glGenFramebuffersEXT"); DeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) GlGetProcAddress("glDeleteFramebuffersEXT"); BindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) GlGetProcAddress("glBindFramebufferEXT"); FramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC) GlGetProcAddress("glFramebufferTextureEXT"); } else { GenFramebuffers = nullptr; DeleteFramebuffers = nullptr; BindFramebuffer = nullptr; FramebufferTexture = nullptr; #ifdef GreIsDebugMode GreDebugPretty() << "Extension 'GL_ARB_framebuffer_object' is not supported but may be required." << std::endl; #endif } if(VersionMajor >= 3 || IsExtensionSupported("GL_ARB_vertex_array_object")) { GenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) GlGetProcAddress("glGenVertexArrays"); DeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC) GlGetProcAddress("glDeleteVertexArrays"); BindVertexArray = (PFNGLBINDVERTEXARRAYPROC) GlGetProcAddress("glBindVertexArray"); } else if(IsExtensionSupported("GL_APPLE_vertex_array_object")) { GenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) GlGetProcAddress("glGenVertexArraysAPPLE"); DeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC) GlGetProcAddress("glDeleteVertexArraysAPPLE"); BindVertexArray = (PFNGLBINDVERTEXARRAYPROC) GlGetProcAddress("glBindVertexArrayAPPLE"); } else { GenVertexArrays = nullptr; DeleteVertexArrays = nullptr; BindVertexArray = nullptr; #ifdef GreIsDebugMode GreDebugPretty() << "Extension 'GL_ARB_vertex_array_object' is not supported but may be required." << std::endl; #endif } if(VersionMajor >= 2) { VertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) GlGetProcAddress("glVertexAttribPointer"); EnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC) GlGetProcAddress("glEnableVertexAttribArray"); DisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) GlGetProcAddress("glDisableVertexAttribArray"); } else if(IsExtensionSupported("GL_ARB_vertex_program")) { VertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) GlGetProcAddress("glVertexAttribPointerARB"); EnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC) GlGetProcAddress("glEnableVertexAttribArrayARB"); DisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) GlGetProcAddress("glDisableVertexAttribArrayARB"); } else if(IsExtensionSupported("GL_NV_vertex_program")) { VertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) GlGetProcAddress("glVertexAttribPointerNV"); EnableVertexAttribArray = nullptr; DisableVertexAttribArray = nullptr; } else { VertexAttribPointer = nullptr; EnableVertexAttribArray = nullptr; DisableVertexAttribArray = nullptr; #ifdef GreIsDebugMode GreDebugPretty() << "Extension 'GL_ARB_vertex_program' is not supported but may be required." << std::endl; #endif } // VersionMajor >= 2 Uniform4fv = (PFNGLUNIFORM4FVPROC) GlGetProcAddress("glUniform4fv"); if(!Uniform4fv) Uniform4fv = (PFNGLUNIFORM4FVPROC) GlGetProcAddress("glUniform4fvARB"); CreateShader = (PFNGLCREATESHADERPROC) GlGetProcAddress("glCreateShader"); if(!CreateShader) CreateShader = (PFNGLCREATESHADERPROC) GlGetProcAddress("glCreateShaderObjectARB"); ShaderSource = (PFNGLSHADERSOURCEPROC) GlGetProcAddress("glShaderSource"); if(!ShaderSource) ShaderSource = (PFNGLSHADERSOURCEPROC) GlGetProcAddress("glShaderSourceARB"); CompileShader = (PFNGLCOMPILESHADERPROC) GlGetProcAddress("glCompileShader"); if(!CompileShader) CompileShader = (PFNGLCOMPILESHADERPROC) GlGetProcAddress("glCompileShaderARB"); UniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) GlGetProcAddress("glUniformMatrix4fv"); if(!UniformMatrix4fv) UniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) GlGetProcAddress("glUniformMatrix4fvARB"); GetShaderiv = (PFNGLGETSHADERIVPROC) GlGetProcAddress("glGetShaderiv"); if(!GetShaderiv) GetShaderiv = (PFNGLGETSHADERIVPROC) GlGetProcAddress("glGetObjectParameterivARB"); if(!GetShaderiv) GetShaderiv = (PFNGLGETSHADERIVPROC) GlGetProcAddress("glGetObjectParameterivAPPLE"); GetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) GlGetProcAddress("glGetProgramInfoLog"); if(!GetProgramInfoLog) GetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) GlGetProcAddress("glGetInfoLogARB"); DeleteShader = (PFNGLDELETESHADERPROC) GlGetProcAddress("glDeleteShader"); if(!DeleteShader) DeleteShader = (PFNGLDELETESHADERPROC) GlGetProcAddress("glDeleObjectARB"); CreateProgram = (PFNGLCREATEPROGRAMPROC) GlGetProcAddress("glCreateProgram"); if(!CreateProgram) CreateProgram = (PFNGLCREATEPROGRAMPROC) GlGetProcAddress("glCreateProgramObjectARB"); AttachShader = (PFNGLATTACHSHADERPROC) GlGetProcAddress("glAttachShader"); if(!AttachShader) AttachShader = (PFNGLATTACHSHADERPROC) GlGetProcAddress("glAttachObjectARB"); LinkProgram = (PFNGLLINKPROGRAMPROC) GlGetProcAddress("glLinkProgram"); if(!LinkProgram) LinkProgram = (PFNGLLINKPROGRAMPROC) GlGetProcAddress("glLinkProgramARB"); GetProgramiv = (PFNGLGETPROGRAMIVPROC) GlGetProcAddress("glGetProgramiv"); if(!GetProgramiv) GetProgramiv = (PFNGLGETPROGRAMIVPROC) GlGetProcAddress("glGetProgramivARB"); if(!GetProgramiv) GetProgramiv = (PFNGLGETPROGRAMIVPROC) GlGetProcAddress("glGetProgramivNV"); if(!GetProgramiv) GetProgramiv = (PFNGLGETPROGRAMIVPROC) GlGetProcAddress("glGetObjectParameterivARB"); if(!GetProgramiv) GetProgramiv = (PFNGLGETPROGRAMIVPROC) GlGetProcAddress("glGetObjectParameterivAPPLE"); DetachShader = (PFNGLDETACHSHADERPROC) GlGetProcAddress("glDetachShader"); if(!DetachShader) DetachShader = (PFNGLDETACHSHADERPROC) GlGetProcAddress("glDetachObjectARB"); DeleteProgram = (PFNGLDELETEPROGRAMPROC) GlGetProcAddress("glDeleteProgram"); if(!DeleteProgram) DeleteProgram = (PFNGLDELETEPROGRAMPROC) GlGetProcAddress("glDeleteObjectARB"); UseProgram = (PFNGLUSEPROGRAMPROC) GlGetProcAddress("glUseProgram"); if(!UseProgram) UseProgram = (PFNGLUSEPROGRAMPROC) GlGetProcAddress("glUseProgramObjectARB"); GetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) GlGetProcAddress("glGetUniformLocation"); if(!GetUniformLocation) GetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) GlGetProcAddress("glGetUniformLocationARB"); GetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC) GlGetProcAddress("glGetAttribLocation"); if(!GetAttribLocation) GetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC) GlGetProcAddress("glGetAttribLocationARB"); GenTextures = (PFNGLGENTEXTURESPROC) GlGetProcAddress("glGenTextures"); if(!GenTextures) GenTextures = (PFNGLGENTEXTURESEXTPROC) GlGetProcAddress("glGenTexturesEXT"); PixelStorei = (PFNGLPIXELSTOREIPROC) GlGetProcAddress("glPixelStorei"); BindTexture = (PFNGLBINDTEXTUREPROC) GlGetProcAddress("glBindTexture"); if(!BindTexture) BindTexture = (PFNGLBINDTEXTUREPROC) GlGetProcAddress("glBindTextureEXT"); TexParameteri = (PFNGLTEXPARAMETERIPROC) GlGetProcAddress("glTexParameteri"); TexImage2D = (PFNGLTEXIMAGE2DPROC) GlGetProcAddress("glTexImage2D"); DeleteTextures = (PFNGLDELETETEXTURESPROC) GlGetProcAddress("glDeleteTextures"); if(!DeleteTextures) DeleteTextures = (PFNGLDELETETEXTURESPROC) GlGetProcAddress("glDeleteTexturesEXT"); GenBuffers = (PFNGLGENBUFFERSPROC) GlGetProcAddress("glGenBuffers"); if(!GenBuffers) GenBuffers = (PFNGLGENBUFFERSPROC) GlGetProcAddress("glGenBuffersARB"); BindBuffer = (PFNGLBINDBUFFERPROC) GlGetProcAddress("glBindBuffer"); if(!BindBuffer) BindBuffer = (PFNGLBINDBUFFERPROC) GlGetProcAddress("glBindBufferARB"); DeleteBuffers = (PFNGLDELETEBUFFERSPROC) GlGetProcAddress("glDeleteBuffers"); if(!DeleteBuffers) DeleteBuffers = (PFNGLDELETEBUFFERSPROC) GlGetProcAddress("glDeleteBuffersARB"); BufferData = (PFNGLBUFFERDATAPROC) GlGetProcAddress("glBufferData"); if(!BufferData) BufferData = (PFNGLBUFFERDATAPROC) GlGetProcAddress("glBufferDataARB"); BufferSubData = (PFNGLBUFFERSUBDATAPROC) GlGetProcAddress("glBufferSubData"); if(!BufferSubData) BufferSubData = (PFNGLBUFFERSUBDATAPROC) GlGetProcAddress("glBufferSubDataARB"); TexSubImage2D = (PFNGLTEXSUBIMAGE2DPROC) GlGetProcAddress("glTexSubImage2D"); if(!TexSubImage2D) TexSubImage2D = (PFNGLTEXSUBIMAGE2DPROC) GlGetProcAddress("glTexSubImage2DEXT"); Initialized = true; }
void COGLGraphicsContext::InitOGLExtension(void) { // important extension features, it is very bad not to have these feature m_bSupportMultiTexture = IsExtensionSupported("GL_ARB_multitexture"); m_bSupportTextureEnvCombine = IsExtensionSupported("GL_EXT_texture_env_combine"); m_bSupportSeparateSpecularColor = IsExtensionSupported("GL_EXT_separate_specular_color"); m_bSupportSecondColor = IsExtensionSupported("GL_EXT_secondary_color"); m_bSupportFogCoord = IsExtensionSupported("GL_EXT_fog_coord"); m_bSupportTextureObject = IsExtensionSupported("GL_EXT_texture_object"); // Optional extension features m_bSupportRescaleNormal = IsExtensionSupported("GL_EXT_rescale_normal"); m_bSupportLODBias = IsExtensionSupported("GL_EXT_texture_lod_bias"); // Nvidia only extension features (optional) m_bSupportNVRegisterCombiner = IsExtensionSupported("GL_NV_register_combiners"); m_bSupportTextureMirrorRepeat = IsExtensionSupported("GL_IBM_texture_mirrored_repeat") || IsExtensionSupported("ARB_texture_mirrored_repeat"); m_supportTextureMirror = m_bSupportTextureMirrorRepeat; m_bSupportTextureLOD = IsExtensionSupported("GL_EXT_texture_lod"); m_bSupportBlendColor = IsExtensionSupported("GL_EXT_blend_color"); m_bSupportBlendSubtract = IsExtensionSupported("GL_EXT_blend_subtract"); m_bSupportNVTextureEnvCombine4 = IsExtensionSupported("GL_NV_texture_env_combine4"); }
void OpenGL::SetupContext() { #if defined(HAVE_DYNAMIC_EGL) egl = EGLInit(); #endif texture_non_power_of_two = SupportsNonPowerOfTwoTextures(); #ifdef HAVE_OES_DRAW_TEXTURE oes_draw_texture = CheckOESDrawTexture(); #endif #ifdef ANDROID native_view->SetTexturePowerOfTwo(texture_non_power_of_two); vertex_buffer_object = EnableVBO(); #endif #ifdef HAVE_OES_MAPBUFFER mapbuffer = IsExtensionSupported("GL_OES_mapbuffer"); #endif #ifdef HAVE_DYNAMIC_MAPBUFFER if (mapbuffer) { GLExt::map_buffer = (PFNGLMAPBUFFEROESPROC) eglGetProcAddress("glMapBufferOES"); GLExt::unmap_buffer = (PFNGLUNMAPBUFFEROESPROC) eglGetProcAddress("glUnmapBufferOES"); if (GLExt::map_buffer == nullptr || GLExt::unmap_buffer == nullptr) mapbuffer = false; } #endif #ifdef HAVE_DYNAMIC_MULTI_DRAW_ARRAYS if (IsExtensionSupported("GL_EXT_multi_draw_arrays")) { GLExt::multi_draw_arrays = (PFNGLMULTIDRAWARRAYSEXTPROC) dlsym(RTLD_DEFAULT, "glMultiDrawArraysEXT"); GLExt::multi_draw_elements = (PFNGLMULTIDRAWELEMENTSEXTPROC) dlsym(RTLD_DEFAULT, "glMultiDrawElementsEXT"); } else { GLExt::multi_draw_arrays = nullptr; GLExt::multi_draw_elements = nullptr; } #endif frame_buffer_object = CheckFBO() && FBO::Initialise(); if (frame_buffer_object) { render_buffer_depth_stencil = CheckDepthStencil(); render_buffer_stencil = CheckStencil(); if (!render_buffer_stencil) /* fall back to a packed depth+stencil format */ render_buffer_stencil = render_buffer_depth_stencil; } glDisable(GL_DEPTH_TEST); glDisable(GL_DITHER); #ifndef HAVE_GLES2 glDisable(GL_LIGHTING); #endif #ifndef USE_GLSL glEnableClientState(GL_VERTEX_ARRAY); #endif InitShapes(); #ifdef USE_GLSL InitShaders(); #endif #ifndef HAVE_GLES ::glGetIntegerv(GL_MAX_ATTRIB_STACK_DEPTH, &max_attrib_stack_depth); #endif }
int Application::run(Application* self) { m_self = self; if (!framework::Utils::exists("data/gui")) { Logger::toLog("Error: could not find gui directory. Probably working directory has not been set correctly (especially if you are running from IDE).\n"); return EXIT_FAILURE; } init(); m_isRunning = true; glfwSetErrorCallback(&Application::errorCallback); if (!glfwInit()) { Logger::toLog("Error: glfwInit failed"); return EXIT_FAILURE; } glfwWindowHint(GLFW_VISIBLE, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_RED_BITS, 8); glfwWindowHint(GLFW_GREEN_BITS, 8); glfwWindowHint(GLFW_BLUE_BITS, 8); glfwWindowHint(GLFW_ALPHA_BITS, 0); glfwWindowHint(GLFW_DEPTH_BITS, 32); glfwWindowHint(GLFW_STENCIL_BITS, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, m_info.majorVersion); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, m_info.minorVersion); #ifdef _DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_SAMPLES, m_info.samples); glfwWindowHint(GLFW_STEREO, m_info.flags.stereo ? GL_TRUE : GL_FALSE); // create window m_window = glfwCreateWindow(m_info.windowWidth, m_info.windowHeight, m_info.title.c_str(), m_info.flags.fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL); if (!m_window) { glfwTerminate(); return EXIT_FAILURE; } glfwSetWindowSizeCallback(m_window, &Application::_setWindowSize); glfwSetKeyCallback(m_window, &Application::_onKey); glfwSetCharCallback(m_window, &Application::_onChar); glfwSetMouseButtonCallback(m_window, &Application::_onMouse); glfwSetCursorPosCallback(m_window, &Application::_onCursor); glfwSetScrollCallback(m_window, &Application::_onScroll); glfwSetInputMode(m_window, GLFW_CURSOR, m_info.flags.cursor ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN); // center position GLFWmonitor* primary = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(primary); int posx = (mode->width - m_info.windowWidth) >> 1; int posy = (mode->height - m_info.windowHeight) >> 1; glfwSetWindowPos(m_window, posx, posy); // set vsync glfwMakeContextCurrent(m_window); glfwSwapInterval((int)m_info.flags.vsync); // init GL3w gl3wInit(); std::vector<int> multisamplingLevels; if (!checkOpenGLVersion() || !checkDeviceCapabilities(multisamplingLevels)) { glfwDestroyWindow(m_window); glfwTerminate(); return EXIT_FAILURE; } #ifdef _DEBUG Logger::toLogWithFormat("Video adapter: %s - %s, OpenGL: %s\n", (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER), (const char*)glGetString(GL_VERSION)); #endif if (m_info.flags.debug) { if (gl3wIsSupported(4, 3)) { glDebugMessageCallback(debugCallback, this); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); } else if (IsExtensionSupported("GL_ARB_debug_output")) { glDebugMessageCallbackARB(debugCallback, this); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); } } initGui(); if (!StandardGpuPrograms::init()) { glfwDestroyWindow(m_window); glfwTerminate(); return EXIT_FAILURE; } initAxes(); startup(m_rootWindow); do { glfwMakeContextCurrent(m_window); Texture::beginFrame(); if (fabs(m_lastTime) < 1e-7) { render(0); Texture::endFrame(); renderGui(0); m_lastTime = glfwGetTime(); } else { double curTime = glfwGetTime(); double delta = curTime - m_lastTime; // fps counter measureFps(delta); // rendering render(delta); Texture::endFrame(); renderGui(delta); m_lastTime = curTime; } glfwSwapBuffers(m_window); glfwPollEvents(); if (glfwWindowShouldClose(m_window)) { m_isRunning = GL_FALSE; } m_isRunning &= (glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_RELEASE); } while(m_isRunning); shutdown(); destroyAllDestroyable(); destroyGui(); glfwDestroyWindow(m_window); glfwTerminate(); return EXIT_SUCCESS; }