diff --git a/.appveyor.yml b/.appveyor.yml index f0d09e100..be657f8cd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -54,7 +54,7 @@ install: - vcpkg remove lua:x86-windows - vcpkg install luajit:x86-windows - vcpkg install fmt:x86-windows -- vcpkg install glew:x86-windows +- vcpkg install libepoxy:x86-windows - vcpkg install eigen3:x86-windows - vcpkg install freetype:x86-windows - git pull @@ -70,7 +70,7 @@ build_script: cd build - cmake -DCMAKE_PREFIX_PATH=%Qt5_DIR% -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TTF=ON -DENABLE_TESTS=ON .. + cmake -DCMAKE_PREFIX_PATH=%Qt5_DIR% -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TTF=ON -DENABLE_TESTS=ON -DENABLE_GLEW=OFF .. cmake --build . --config Release -- /maxcpucount:4 /nologo diff --git a/.travis.yml b/.travis.yml index a6746271f..45fdee19f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,12 +30,12 @@ matrix: before_script: - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt install -y liblua${LUA}-dev; fi -- if [ "$TRAVIS_OS_NAME" == "osx" ] ; then brew install glew --build-from-source; brew link gettext --force; fi +- if [ "$TRAVIS_OS_NAME" == "osx" ] ; then brew link gettext --force; fi - mkdir build - cd build script: -- cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TTF=ON -DENABLE_TESTS=ON .. +- cmake -DENABLE_SPICE=ON -DENABLE_TOOLS=ON -DENABLE_TTF=ON -DENABLE_TESTS=ON -DENABLE_GLEW=OFF .. - make -j $(nproc || echo 4) - CTEST_OUTPUT_ON_FAILURE=1 ctest @@ -43,7 +43,7 @@ addons: apt: packages: - libeigen3-dev - - libglew-dev + - libepoxy-dev - libtheora-dev - libjpeg-dev - libpng-dev @@ -63,4 +63,5 @@ addons: - lua - qt5 - freetype + - libepoxy update: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e94059ce..76e7dd505 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ option(NATIVE_OSX_APP "Support native OSX paths read data from (Default: off)" O option(FAST_MATH "Build with unsafe fast-math compiller option (Default: off)" OFF) option(ENABLE_TTF "Use TrueType fonts instead of TXF (Default: off)" OFF) option(ENABLE_TESTS "Enable unit tests? (Default: off)" OFF) +option(ENABLE_GLEW "Use GLEW instead of libepoxy? (Default: on)" ON) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type." FORCE) @@ -144,9 +145,16 @@ find_package(OpenGL REQUIRED) include_directories(${OPENGL_INCLUDE_DIRS}) link_libraries(${OPENGL_LIBRARIES}) -find_package(GLEW REQUIRED) -link_libraries(GLEW::GLEW) -include_directories(${GLEW_INCLUDE_DIRS}) +if(ENABLE_GLEW) + find_package(GLEW REQUIRED) + link_libraries(GLEW::GLEW) + include_directories(${GLEW_INCLUDE_DIRS}) + add_definitions(-DUSE_GLEW) +else() + find_package(Libepoxy REQUIRED) + link_libraries(libepoxy::libepoxy) + include_directories(${LIBEPOXY_INCLUDE_DIR}) +endif() find_package(Eigen3 3.3 NO_MODULE) # -DEigen3_DIR=... if(TARGET Eigen3::Eigen) diff --git a/cmake/FindLibepoxy.cmake b/cmake/FindLibepoxy.cmake new file mode 100644 index 000000000..f53254c91 --- /dev/null +++ b/cmake/FindLibepoxy.cmake @@ -0,0 +1,59 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#.rst: +# FindLibepoxy +# -------- +# +# Find the epoxy headers and libraries. +# +# This module reports information about the epoxy +# installation in several variables. General variables:: +# +# LIBEPOXY_FOUND - true if the epoxy headers and libraries were found +# LIBEPOXY_INCLUDE_DIRS - the directory containing the epoxy headers +# LIBEPOXY_LIBRARIES - epoxy libraries to be linked +# +# The following cache variables may also be set:: +# +# LIBEPOXY_INCLUDE_DIR - the directory containing the epoxy headers +# LIBEPOXY_LIBRARY - the epoxy library (if any) + +# Find include directory + +# TODO: use pkgconfig + +find_path(LIBEPOXY_INCLUDE_DIR + NAMES epoxy/gl.h + HINTS LIBEPOXY_DIR + DOC "epoxy headers") +mark_as_advanced(LIBEPOXY_INCLUDE_DIR) + +find_library(LIBEPOXY_LIBRARY + NAMES epoxy + HINTS LIBEPOXY_DIR + DOC "epoxy libraries") +mark_as_advanced(LIBEPOXY_LIBRARY) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libepoxy + FOUND_VAR LIBEPOXY_FOUND + REQUIRED_VARS LIBEPOXY_INCLUDE_DIR LIBEPOXY_LIBRARY + FAIL_MESSAGE "Failed to find epoxy") + +if(LIBEPOXY_FOUND) + set(LIBEPOXY_INCLUDE_DIRS "${LIBEPOXY_INCLUDE_DIR}") + if(LIBEPOXY_LIBRARY) + set(LIBEPOXY_LIBRARIES "${LIBEPOXY_LIBRARY}") + else() + unset(LIBEPOXY_LIBRARIES) + endif() + + if(NOT TARGET libepoxy::libepoxy) + add_library(libepoxy::libepoxy UNKNOWN IMPORTED) + set_target_properties(libepoxy::libepoxy PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBEPOXY_INCLUDE_DIRS}") + set_target_properties(libepoxy::libepoxy PROPERTIES + IMPORTED_LOCATION "${LIBEPOXY_LIBRARY}") + endif() +endif() diff --git a/src/celengine/CMakeLists.txt b/src/celengine/CMakeLists.txt index 218cf1449..5fe1de6c1 100644 --- a/src/celengine/CMakeLists.txt +++ b/src/celengine/CMakeLists.txt @@ -53,6 +53,8 @@ set(CELENGINE_SOURCES globular.h glshader.cpp glshader.h + glsupport.cpp + glsupport.h hash.cpp hash.h #hdrfuncrender.cpp diff --git a/src/celengine/asterism.cpp b/src/celengine/asterism.cpp index 28e9f02b2..5bcb72eb8 100644 --- a/src/celengine/asterism.cpp +++ b/src/celengine/asterism.cpp @@ -8,7 +8,6 @@ // of the License, or (at your option) any later version. #include -#include #include #include #include "stardb.h" diff --git a/src/celengine/axisarrow.cpp b/src/celengine/axisarrow.cpp index c74a0755d..44484372c 100644 --- a/src/celengine/axisarrow.cpp +++ b/src/celengine/axisarrow.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include "glsupport.h" #include "vecgl.h" #include "axisarrow.h" #include "selection.h" diff --git a/src/celengine/body.h b/src/celengine/body.h index feb54748d..cb4e0dace 100644 --- a/src/celengine/body.h +++ b/src/celengine/body.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include "glsupport.h" #include #include #include diff --git a/src/celengine/console.cpp b/src/celengine/console.cpp index 79127b9df..696d46e29 100644 --- a/src/celengine/console.cpp +++ b/src/celengine/console.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include "glsupport.h" #include "vecgl.h" #include "console.h" #if NO_TTF diff --git a/src/celengine/curveplot.cpp b/src/celengine/curveplot.cpp index a70bcc4c8..56880c8e8 100644 --- a/src/celengine/curveplot.cpp +++ b/src/celengine/curveplot.cpp @@ -34,8 +34,8 @@ #define USE_VERTEX_BUFFER 1 #endif +#include "glsupport.h" #include "curveplot.h" -#include "GL/glew.h" #include #include diff --git a/src/celengine/dds.cpp b/src/celengine/dds.cpp index 88ebeed3a..4f0d9d947 100644 --- a/src/celengine/dds.cpp +++ b/src/celengine/dds.cpp @@ -13,12 +13,12 @@ #include #include #include -#include +#include "glsupport.h" +using namespace celestia; using namespace std; - struct DDPixelFormat { uint32_t size; @@ -186,7 +186,7 @@ Image* LoadDDSImage(const fs::path& filename) format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT || format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) { - if (!GLEW_EXT_texture_compression_s3tc) + if (!gl::EXT_texture_compression_s3tc) return nullptr; } diff --git a/src/celengine/framebuffer.h b/src/celengine/framebuffer.h index 3510d6cab..d39fdbd1b 100644 --- a/src/celengine/framebuffer.h +++ b/src/celengine/framebuffer.h @@ -10,7 +10,7 @@ #pragma once -#include +#include "glsupport.h" class FramebufferObject { diff --git a/src/celengine/glcontext.cpp b/src/celengine/glcontext.cpp index 447246f86..b581a04e6 100644 --- a/src/celengine/glcontext.cpp +++ b/src/celengine/glcontext.cpp @@ -10,7 +10,7 @@ #include #include #include "glcontext.h" -#include +#include "glsupport.h" using namespace std; diff --git a/src/celengine/glmarker.cpp b/src/celengine/glmarker.cpp index bb4382ddd..e49a7f36e 100644 --- a/src/celengine/glmarker.cpp +++ b/src/celengine/glmarker.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include "glsupport.h" #include #include "render.h" #include "vertexobject.h" diff --git a/src/celengine/glshader.cpp b/src/celengine/glshader.cpp index 77647fe2e..c8f7e6ac9 100644 --- a/src/celengine/glshader.cpp +++ b/src/celengine/glshader.cpp @@ -9,7 +9,6 @@ #include #include "glshader.h" -#include using namespace std; diff --git a/src/celengine/glshader.h b/src/celengine/glshader.h index 160812469..f0361de5c 100644 --- a/src/celengine/glshader.h +++ b/src/celengine/glshader.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include "glsupport.h" class GLShaderLoader; diff --git a/src/celengine/glsupport.cpp b/src/celengine/glsupport.cpp new file mode 100644 index 000000000..7e0518c85 --- /dev/null +++ b/src/celengine/glsupport.cpp @@ -0,0 +1,57 @@ +#include "glsupport.h" + +namespace celestia +{ +namespace gl +{ + +bool ARB_shader_texture_lod = false; +bool ARB_vertex_array_object = false; +bool EXT_framebuffer_object = false; +bool EXT_texture_compression_s3tc = false; +bool EXT_texture_filter_anisotropic = false; + +namespace +{ + inline bool has_extension(const char* name) noexcept + { +#ifdef USE_GLEW + return glewIsSupported(name); +#else + return epoxy_has_gl_extension(name); +#endif + } +} + +bool init() noexcept +{ +#ifdef USE_GLEW + GLenum glewErr = glewInit(); + if (glewErr != GLEW_OK) + return false; +#endif + ARB_shader_texture_lod = has_extension("GL_ARB_shader_texture_lod"); + ARB_vertex_array_object = has_extension("GL_ARB_vertex_array_object"); + EXT_framebuffer_object = has_extension("GL_EXT_framebuffer_object"); + EXT_texture_compression_s3tc = has_extension("GL_EXT_texture_compression_s3tc"); + EXT_texture_filter_anisotropic = has_extension("GL_EXT_texture_filter_anisotropic"); + + return true; +} + +bool checkVersion(int v) noexcept +{ +#ifdef USE_GLEW + switch (v) + { + case GL_2_1: + return GLEW_VERSION_2_1 != GL_FALSE; + default: + return false; + } +#else + return epoxy_gl_version() >= v; +#endif +} +} // gl +} // celestia diff --git a/src/celengine/glsupport.h b/src/celengine/glsupport.h new file mode 100644 index 000000000..cb56be5ad --- /dev/null +++ b/src/celengine/glsupport.h @@ -0,0 +1,33 @@ +#pragma once + +#ifdef USE_GLEW +#include +#else +#ifdef _WIN32 +#include +#endif +#include +#ifdef __APPLE__ +#include +#else +#include +#endif +#endif + +namespace celestia +{ +namespace gl +{ + +constexpr const int GL_2_1 = 21; + +extern bool ARB_shader_texture_lod; +extern bool ARB_vertex_array_object; +extern bool EXT_framebuffer_object; +extern bool EXT_texture_compression_s3tc; +extern bool EXT_texture_filter_anisotropic; + +bool init() noexcept; +bool checkVersion(int) noexcept; +} // gl +} // celestia diff --git a/src/celengine/image.cpp b/src/celengine/image.cpp index 556ce8946..24419ba49 100644 --- a/src/celengine/image.cpp +++ b/src/celengine/image.cpp @@ -21,7 +21,7 @@ extern "C" { } #include -#include +#include "glsupport.h" #include #include diff --git a/src/celengine/lodspheremesh.cpp b/src/celengine/lodspheremesh.cpp index ceeae4cfb..32f9499ea 100644 --- a/src/celengine/lodspheremesh.cpp +++ b/src/celengine/lodspheremesh.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include "glsupport.h" #include "lodspheremesh.h" #include "shadermanager.h" diff --git a/src/celengine/overlay.cpp b/src/celengine/overlay.cpp index af0c99385..666e54053 100644 --- a/src/celengine/overlay.cpp +++ b/src/celengine/overlay.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include "glsupport.h" #include #include #include diff --git a/src/celengine/particlesystem.cpp b/src/celengine/particlesystem.cpp index 1541aadf3..4b776d1c5 100644 --- a/src/celengine/particlesystem.cpp +++ b/src/celengine/particlesystem.cpp @@ -17,7 +17,7 @@ #include #include "modelgeometry.h" #include "particlesystem.h" -#include +#include "glsupport.h" #include "vecgl.h" #include "rendcontext.h" #include "texmanager.h" diff --git a/src/celengine/pointstarvertexbuffer.cpp b/src/celengine/pointstarvertexbuffer.cpp index ad3e5cade..ff31efb8d 100644 --- a/src/celengine/pointstarvertexbuffer.cpp +++ b/src/celengine/pointstarvertexbuffer.cpp @@ -8,7 +8,7 @@ // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -#include +#include "glsupport.h" #include #include "objectrenderer.h" #include "shadermanager.h" diff --git a/src/celengine/rendcontext.cpp b/src/celengine/rendcontext.cpp index aa5678059..f190178b3 100644 --- a/src/celengine/rendcontext.cpp +++ b/src/celengine/rendcontext.cpp @@ -13,7 +13,7 @@ #include "texmanager.h" #include "modelgeometry.h" #include "body.h" -#include +#include "glsupport.h" #include "render.h" using namespace cmod; diff --git a/src/celengine/render.cpp b/src/celengine/render.cpp index 498ab8d62..b801dd160 100644 --- a/src/celengine/render.cpp +++ b/src/celengine/render.cpp @@ -80,7 +80,7 @@ std::ofstream hdrlog; #else #include #endif -#include +#include "glsupport.h" #ifdef VIDEO_SYNC #ifdef _WIN32 #include @@ -103,6 +103,7 @@ std::ofstream hdrlog; using namespace cmod; using namespace Eigen; using namespace std; +using namespace celestia; using namespace celmath; #define FOV 45.0f @@ -778,7 +779,7 @@ bool Renderer::init( #endif #ifdef ENABLE_SELF_SHADOW - if (GLEW_EXT_framebuffer_object) + if (gl::EXT_framebuffer_object) { shadowFbo = new FramebufferObject(1024, 1024, FramebufferObject::DepthAttachment); if (!shadowFbo->isValid()) @@ -4414,7 +4415,7 @@ void Renderer::renderPlanet(Body& body, // us explicitly set the LOD. But, they do all have an optional lodBias parameter // for the textureXD instruction. The bias is just the difference between the // area light LOD and the approximate GPU calculated LOD. - if (!GLEW_ARB_shader_texture_lod) + if (!gl::ARB_shader_texture_lod) lod = max(0.0f, lod - gpuLod); lights.ringShadows[li].texLod = lod; } @@ -6761,12 +6762,9 @@ bool Renderer::getInfo(map& info) const glGetFloatv(GL_SMOOTH_POINT_SIZE_GRANULARITY, &pointSizeGran); info["PointSizeGran"] = to_string(pointSizeGran); - if (GLEW_EXT_texture_cube_map) - { - GLint maxCubeMapSize = 0; - glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &maxCubeMapSize); - info["MaxCubeMapSize"] = to_string(maxCubeMapSize); - } + GLint maxCubeMapSize = 0; + glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &maxCubeMapSize); + info["MaxCubeMapSize"] = to_string(maxCubeMapSize); s = reinterpret_cast(glGetString(GL_EXTENSIONS)); if (s != nullptr) diff --git a/src/celengine/shadermanager.cpp b/src/celengine/shadermanager.cpp index fa50505c9..81d4d3ada 100644 --- a/src/celengine/shadermanager.cpp +++ b/src/celengine/shadermanager.cpp @@ -11,7 +11,7 @@ #include #include #include "shadermanager.h" -#include +#include "glsupport.h" #include #include #include @@ -21,6 +21,7 @@ #include #include +using namespace celestia; using namespace Eigen; using namespace std; @@ -1220,7 +1221,7 @@ BeginLightSourceShadows(const ShaderProperties& props, unsigned int light) if (props.hasRingShadowForLight(light)) { - if (GLEW_ARB_shader_texture_lod) + if (gl::ARB_shader_texture_lod) { source += mulAssign("shadow", (1.0f - texture2DLod(sampler2D("ringTex"), vec2(ringShadowTexCoord(light), 0.0f), indexedUniform("ringShadowLOD", light))["a"])); @@ -1918,7 +1919,7 @@ ShaderManager::buildFragmentShader(const ShaderProperties& props) // Without GL_ARB_shader_texture_lod enabled one can use texture2DLod // in vertext shaders only - if (GLEW_ARB_shader_texture_lod) + if (gl::ARB_shader_texture_lod) source += "#extension GL_ARB_shader_texture_lod : enable\n"; string diffTexCoord("diffTexCoord"); diff --git a/src/celengine/spheremesh.cpp b/src/celengine/spheremesh.cpp index 0f35bbceb..aa3409527 100644 --- a/src/celengine/spheremesh.cpp +++ b/src/celengine/spheremesh.cpp @@ -14,7 +14,7 @@ #include "spheremesh.h" #include -#include +#include "glsupport.h" #include using namespace Eigen; diff --git a/src/celengine/texture.cpp b/src/celengine/texture.cpp index c0cf26287..d29ce1622 100644 --- a/src/celengine/texture.cpp +++ b/src/celengine/texture.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include "glsupport.h" #include #include @@ -25,6 +25,7 @@ #include "virtualtex.h" +using namespace celestia; using namespace Eigen; using namespace std; @@ -94,7 +95,7 @@ static const TextureCaps& GetTextureCaps() glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texCaps.maxTextureSize); texCaps.preferredAnisotropy = 1; - if (GLEW_EXT_texture_filter_anisotropic) + if (gl::EXT_texture_filter_anisotropic) { GLint maxAnisotropy = 1; glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); @@ -388,7 +389,7 @@ ImageTexture::ImageTexture(Image& img, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); - if (GLEW_EXT_texture_filter_anisotropic && texCaps.preferredAnisotropy > 1) + if (gl::EXT_texture_filter_anisotropic && texCaps.preferredAnisotropy > 1) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, texCaps.preferredAnisotropy); } @@ -400,7 +401,7 @@ ImageTexture::ImageTexture(Image& img, bool genMipmaps = mipmap && !precomputedMipMaps; #ifdef NO_GLU - if (genMipmaps && !GLEW_EXT_framebuffer_object) + if (genMipmaps && !gl::EXT_framebuffer_object) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); #endif @@ -434,7 +435,7 @@ ImageTexture::ImageTexture(Image& img, LoadMiplessTexture(img, GL_TEXTURE_2D); } #ifdef NO_GLU - if (genMipmaps && GLEW_EXT_framebuffer_object) + if (genMipmaps && gl::EXT_framebuffer_object) glGenerateMipmapEXT(GL_TEXTURE_2D); #endif DumpTextureMipmapInfo(GL_TEXTURE_2D); @@ -538,7 +539,7 @@ TiledTexture::TiledTexture(Image& img, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); - if (GLEW_EXT_texture_filter_anisotropic && texCaps.preferredAnisotropy > 1) + if (gl::EXT_texture_filter_anisotropic && texCaps.preferredAnisotropy > 1) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, texCaps.preferredAnisotropy); } @@ -619,7 +620,7 @@ TiledTexture::TiledTexture(Image& img, if (mipmap) { #ifdef NO_GLU - if (GLEW_EXT_framebuffer_object) + if (gl::EXT_framebuffer_object) { LoadMiplessTexture(*tile, GL_TEXTURE_2D); glGenerateMipmapEXT(GL_TEXTURE_2D); @@ -749,7 +750,7 @@ CubeMap::CubeMap(Image* faces[]) : bool genMipmaps = mipmap && !precomputedMipMaps; #ifdef NO_GLU - if (genMipmaps && !GLEW_EXT_framebuffer_object) + if (genMipmaps && !gl::EXT_framebuffer_object) glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE); #endif @@ -784,7 +785,7 @@ CubeMap::CubeMap(Image* faces[]) : } } #ifdef NO_GLU - if (genMipmaps && GLEW_EXT_framebuffer_object) + if (genMipmaps && gl::EXT_framebuffer_object) glGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP); #endif DumpTextureMipmapInfo(GL_TEXTURE_CUBE_MAP_POSITIVE_X); diff --git a/src/celengine/vecgl.h b/src/celengine/vecgl.h index 08f75f15f..baafd7533 100644 --- a/src/celengine/vecgl.h +++ b/src/celengine/vecgl.h @@ -14,7 +14,7 @@ #define _CELENGINE_VECGL_H_ #include -#include +#include "glsupport.h" #include #include diff --git a/src/celengine/vertexobject.cpp b/src/celengine/vertexobject.cpp index 81942ebcb..20eebe0c6 100644 --- a/src/celengine/vertexobject.cpp +++ b/src/celengine/vertexobject.cpp @@ -11,6 +11,8 @@ #include "vertexobject.h" +using namespace celestia; + namespace celgl { VertexObject::VertexObject(GLenum bufferType) : @@ -29,7 +31,7 @@ VertexObject::~VertexObject() { delete m_attribParams; - if (m_vaoId != 0 && GLEW_ARB_vertex_array_object) + if (m_vaoId != 0 && gl::ARB_vertex_array_object) glDeleteVertexArrays(1, &m_vaoId); if (m_vboId != 0) @@ -40,7 +42,7 @@ void VertexObject::bind() noexcept { if ((m_state & State::Initialize) != 0) { - if (GLEW_ARB_vertex_array_object) + if (gl::ARB_vertex_array_object) { glGenVertexArrays(1, &m_vaoId); glBindVertexArray(m_vaoId); @@ -50,7 +52,7 @@ void VertexObject::bind() noexcept } else { - if (GLEW_ARB_vertex_array_object) + if (gl::ARB_vertex_array_object) { glBindVertexArray(m_vaoId); if ((m_state & State::Update) != 0) @@ -72,7 +74,7 @@ void VertexObject::bindWritable() noexcept void VertexObject::unbind() noexcept { - if (GLEW_ARB_vertex_array_object) + if (gl::ARB_vertex_array_object) { if ((m_state & (State::Initialize | State::Update)) != 0) glBindBuffer(m_bufferType, 0); diff --git a/src/celengine/vertexobject.h b/src/celengine/vertexobject.h index 0f4c866ee..3f7ddc6ef 100644 --- a/src/celengine/vertexobject.h +++ b/src/celengine/vertexobject.h @@ -11,7 +11,7 @@ #pragma once -#include +#include "glsupport.h" #include #include diff --git a/src/celengine/virtualtex.cpp b/src/celengine/virtualtex.cpp index 9889cbf7b..7cd857fb5 100644 --- a/src/celengine/virtualtex.cpp +++ b/src/celengine/virtualtex.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include "glsupport.h" #include #include #include diff --git a/src/celestia/avicapture.cpp b/src/celestia/avicapture.cpp index 84750cc9e..0b89075f5 100644 --- a/src/celestia/avicapture.cpp +++ b/src/celestia/avicapture.cpp @@ -9,7 +9,6 @@ #include -#include #include #include #include "avicapture.h" diff --git a/src/celestia/celestiacore.cpp b/src/celestia/celestiacore.cpp index 0cba21238..cc0e1a900 100644 --- a/src/celestia/celestiacore.cpp +++ b/src/celestia/celestiacore.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include diff --git a/src/celestia/celestiacore.h b/src/celestia/celestiacore.h index 5075935e3..8f4200ece 100644 --- a/src/celestia/celestiacore.h +++ b/src/celestia/celestiacore.h @@ -21,7 +21,6 @@ #include #include #include -#include #include "configfile.h" #include "favorites.h" #include "destination.h" diff --git a/src/celestia/glut/glutmain.cpp b/src/celestia/glut/glutmain.cpp index fd8ccaa71..dfee2910e 100644 --- a/src/celestia/glut/glutmain.cpp +++ b/src/celestia/glut/glutmain.cpp @@ -18,7 +18,9 @@ #include #include #include -#include + +// celengine/glsupport.h must be included before GL/glut.h / GL/gl.h +#include #ifndef MACOSX #include #else @@ -35,6 +37,7 @@ #include "popt.h" */ +using namespace celestia; using namespace std; @@ -513,12 +516,10 @@ int main(int argc, char* argv[]) initMenus(); #endif - GLenum glewErr = glewInit(); - if (glewErr != GLEW_OK) + if (!gl::init() || !gl::checkVersion(gl::GL_2_1)) { - fmt::fprintf(std::cerr, - _("Celestia was unable to initialize OpenGL extensions (error %i). Graphics quality will be reduced."), - glewErr); + cout << _("Celestia was unable to initialize OpenGL 2.1.\n"); + return 1; } // GL should be all set up, now initialize the renderer. diff --git a/src/celestia/gtk/actions.cpp b/src/celestia/gtk/actions.cpp index 23b748e13..748bb6191 100644 --- a/src/celestia/gtk/actions.cpp +++ b/src/celestia/gtk/actions.cpp @@ -11,7 +11,6 @@ */ #include -#include #include #include #include @@ -22,7 +21,7 @@ #endif /* GNOME */ #include - +#include #include #include #include diff --git a/src/celestia/gtk/main.cpp b/src/celestia/gtk/main.cpp index c28ee4de2..f573932fe 100644 --- a/src/celestia/gtk/main.cpp +++ b/src/celestia/gtk/main.cpp @@ -24,12 +24,12 @@ #include #endif /* WIN32 */ -#include #include #include #include #include +#include #include #include #include @@ -60,6 +60,7 @@ #endif /* DEBUG */ +using namespace celestia; using namespace std; @@ -242,17 +243,17 @@ public: * that require the glArea to be set up. */ static void initRealize(GtkWidget* widget, AppData* app) { - GLenum glewErr = glewInit(); - if (GLEW_OK != glewErr) + if (!gl::init() || !gl::checkVersion(gl::GL_2_1)) { GtkWidget *message; message = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "Celestia was unable to initialize OpenGL."); + "Celestia was unable to initialize OpenGL 2.1."); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); + exit(1); } app->core->setAlerter(new GtkAlerter(app)); diff --git a/src/celestia/oggtheoracapture.cpp b/src/celestia/oggtheoracapture.cpp index b9affc2ef..df3142fae 100644 --- a/src/celestia/oggtheoracapture.cpp +++ b/src/celestia/oggtheoracapture.cpp @@ -67,7 +67,6 @@ #include #include #include -#include #include #include diff --git a/src/celestia/qt/qtappwin.cpp b/src/celestia/qt/qtappwin.cpp index 6b287fc08..e950962bb 100644 --- a/src/celestia/qt/qtappwin.cpp +++ b/src/celestia/qt/qtappwin.cpp @@ -74,6 +74,7 @@ #define CONFIG_DATA_DIR "./" #endif +using namespace celestia; using namespace std; @@ -257,11 +258,10 @@ void CelestiaAppWindow::init(const QString& qConfigFileName, glWidget = new CelestiaGlWidget(nullptr, "Celestia", m_appCore); glWidget->makeCurrent(); - GLenum glewErr = glewInit(); - if (glewErr != GLEW_OK) + if (!gl::init() || !gl::checkVersion(gl::GL_2_1)) { - QMessageBox::critical(0, "Celestia", - QString(_("Celestia was unable to initialize OpenGL extensions (error %1). Graphics quality will be reduced.")).arg(glewErr)); + QMessageBox::critical(0, "Celestia", _("Celestia was unable to initialize OpenGL 2.1.")); + exit(1); } m_appCore->setCursorHandler(glWidget); diff --git a/src/celestia/qt/qtglwidget.h b/src/celestia/qt/qtglwidget.h index 04e41fafe..b6f579aa7 100644 --- a/src/celestia/qt/qtglwidget.h +++ b/src/celestia/qt/qtglwidget.h @@ -14,8 +14,6 @@ #ifndef QTGLWIDGET_H #define QTGLWIDGET_H -#include - #include #include "celestia/celestiacore.h" diff --git a/src/celestia/win32/wglext.cpp b/src/celestia/win32/wglext.cpp index ecf7afaba..0d61b20c2 100644 --- a/src/celestia/win32/wglext.cpp +++ b/src/celestia/win32/wglext.cpp @@ -9,7 +9,7 @@ // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -#include +#include //#define WGL_WGLEXT_PROTOTYPES 1 #include "wglext.h" #include diff --git a/src/celestia/win32/winmain.cpp b/src/celestia/win32/winmain.cpp index a04cc86bc..e63adc50c 100644 --- a/src/celestia/win32/winmain.cpp +++ b/src/celestia/win32/winmain.cpp @@ -27,6 +27,8 @@ #include #include +#include + #include #include #include @@ -34,10 +36,7 @@ #include #include #include -#include -#include -#include #include "celestia/celestiacore.h" #include "celestia/avicapture.h" #include "celestia/helper.h" @@ -62,6 +61,7 @@ #include #include +using namespace celestia; using namespace std; typedef pair IntStrPair; @@ -1947,10 +1947,11 @@ HWND CreateOpenGLWindow(int x, int y, int width, int height, if (firstContext) { - GLenum glewErr = glewInit(); - if (glewErr != GLEW_OK) + if (!gl::init() || !gl::checkVersion(gl::GL_2_1)) { - MessageBox(NULL, "Could not set up OpenGL extensions.", "Fatal Error", + MessageBox(NULL, + _("You system doesn't support OpenGL 2.1!"), + "Fatal Error", MB_OK | MB_ICONERROR); return NULL; } diff --git a/src/celscript/lua/celx_gl.cpp b/src/celscript/lua/celx_gl.cpp index 6085c698f..c79abb28f 100644 --- a/src/celscript/lua/celx_gl.cpp +++ b/src/celscript/lua/celx_gl.cpp @@ -12,7 +12,7 @@ #include "celx.h" #include "celx_internal.h" #include "celx_object.h" -#include +#include // ==================== OpenGL ==================== diff --git a/src/celttf/truetypefont.cpp b/src/celttf/truetypefont.cpp index a4cbacf9b..d1d22f516 100644 --- a/src/celttf/truetypefont.cpp +++ b/src/celttf/truetypefont.cpp @@ -12,9 +12,9 @@ #include #include #include -#include #include #include +#include #include #include #include FT_FREETYPE_H diff --git a/src/celtxf/texturefont.cpp b/src/celtxf/texturefont.cpp index a4966cce1..11b9e6f28 100644 --- a/src/celtxf/texturefont.cpp +++ b/src/celtxf/texturefont.cpp @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include #include "texturefont.h" using namespace std; diff --git a/src/tools/cmod/cmodview/CMakeLists.txt b/src/tools/cmod/cmodview/CMakeLists.txt index 7518c4e3e..710b0549e 100644 --- a/src/tools/cmod/cmodview/CMakeLists.txt +++ b/src/tools/cmod/cmodview/CMakeLists.txt @@ -18,5 +18,5 @@ set(CMAKE_AUTOMOC ON) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) -build_cmod_tool(cmodview WIN32 cmodview.cpp glframebuffer.cpp glshader.cpp mainwindow.cpp materialwidget.cpp modelviewwidget.cpp) +build_cmod_tool(cmodview WIN32 cmodview.cpp glframebuffer.cpp glshader.cpp mainwindow.cpp materialwidget.cpp modelviewwidget.cpp glsupport.cpp) qt5_use_modules(cmodview ${QT_LIBS}) diff --git a/src/tools/cmod/cmodview/glframebuffer.h b/src/tools/cmod/cmodview/glframebuffer.h index f805dbe32..c25fe5f9e 100644 --- a/src/tools/cmod/cmodview/glframebuffer.h +++ b/src/tools/cmod/cmodview/glframebuffer.h @@ -12,7 +12,7 @@ #ifndef _GLFRAMEBUFFER_H_ #define _GLFRAMEBUFFER_H_ -#include +#include "glsupport.h" class GLFrameBufferObject diff --git a/src/tools/cmod/cmodview/glshader.cpp b/src/tools/cmod/cmodview/glshader.cpp index 053539655..dd08b9034 100644 --- a/src/tools/cmod/cmodview/glshader.cpp +++ b/src/tools/cmod/cmodview/glshader.cpp @@ -11,6 +11,7 @@ #include "glshader.h" +using namespace celestia; using namespace std; @@ -177,7 +178,7 @@ GLShaderProgram::link() bool GLShaderProgram::hasOpenGLShaderPrograms() { - return GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100; + return gl::ARB_shader_objects && gl::ARB_shading_language_100; } diff --git a/src/tools/cmod/cmodview/glshader.h b/src/tools/cmod/cmodview/glshader.h index a86dffaec..eb4827fb7 100644 --- a/src/tools/cmod/cmodview/glshader.h +++ b/src/tools/cmod/cmodview/glshader.h @@ -9,7 +9,7 @@ // // C++ wrapper for OpenGL shaders and shader programs -#include +#include "glsupport.h" #include #include diff --git a/src/tools/cmod/cmodview/glsupport.cpp b/src/tools/cmod/cmodview/glsupport.cpp new file mode 100644 index 000000000..4b8df4aa8 --- /dev/null +++ b/src/tools/cmod/cmodview/glsupport.cpp @@ -0,0 +1,53 @@ +#include "glsupport.h" + +namespace celestia +{ +namespace gl +{ + +bool ARB_shader_objects = false; +bool ARB_shading_language_100 = false; +bool EXT_framebuffer_object = false; + +namespace +{ + inline bool has_extension(const char* name) noexcept + { +#ifdef USE_GLEW + return glewIsSupported(name); +#else + return epoxy_has_gl_extension(name); +#endif + } +} + +bool init() noexcept +{ +#ifdef USE_GLEW + GLenum glewErr = glewInit(); + if (glewErr != GLEW_OK) + return false; +#endif + ARB_shader_objects = has_extension("GL_ARB_shader_objects"); + ARB_shading_language_100 = has_extension("GL_ARB_shading_language_100"); + EXT_framebuffer_object = has_extension("GL_EXT_framebuffer_object"); + + return true; +} + +bool checkVersion(int v) noexcept +{ +#ifdef USE_GLEW + switch (v) + { + case GL_2_1: + return GLEW_VERSION_2_1 != GL_FALSE; + default: + return false; + } +#else + return epoxy_gl_version() >= v; +#endif +} +} // gl +} // celestia diff --git a/src/tools/cmod/cmodview/glsupport.h b/src/tools/cmod/cmodview/glsupport.h new file mode 100644 index 000000000..c744b379c --- /dev/null +++ b/src/tools/cmod/cmodview/glsupport.h @@ -0,0 +1,31 @@ +#pragma once + +#ifdef USE_GLEW +#include +#else +#ifdef _WIN32 +#include +#endif +#include +#ifdef __APPLE__ +#include +#else +#include +#endif +#endif + +namespace celestia +{ +namespace gl +{ + +constexpr const int GL_2_1 = 21; + +extern bool ARB_shader_objects; +extern bool ARB_shading_language_100; +extern bool EXT_framebuffer_object; + +bool init() noexcept; +bool checkVersion(int) noexcept; +} // gl +} // celestia diff --git a/src/tools/cmod/cmodview/materialwidget.cpp b/src/tools/cmod/cmodview/materialwidget.cpp index 3eeee7916..3902ce26b 100644 --- a/src/tools/cmod/cmodview/materialwidget.cpp +++ b/src/tools/cmod/cmodview/materialwidget.cpp @@ -7,7 +7,7 @@ // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -#include +#include "glsupport.h" #include "materialwidget.h" #include #include diff --git a/src/tools/cmod/cmodview/modelviewwidget.cpp b/src/tools/cmod/cmodview/modelviewwidget.cpp index c20862927..c314e0d64 100644 --- a/src/tools/cmod/cmodview/modelviewwidget.cpp +++ b/src/tools/cmod/cmodview/modelviewwidget.cpp @@ -8,7 +8,7 @@ // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -#include +#include "glsupport.h" #include "modelviewwidget.h" #include "glframebuffer.h" #include @@ -19,6 +19,7 @@ #include #include +using namespace celestia; using namespace cmod; using namespace Eigen; @@ -545,7 +546,7 @@ ModelViewWidget::setBackgroundColor(const QColor& color) void ModelViewWidget::initializeGL() { - glewInit(); + gl::init(); emit contextCreated(); } @@ -878,7 +879,7 @@ ModelViewWidget::setAmbientLight(bool enable) void ModelViewWidget::setShadows(bool enable) { - if (!GLEW_EXT_framebuffer_object) + if (!gl::EXT_framebuffer_object) { return; }