Browse Source

Use glLoadGen instead of GLEW.

Removed all known GLEW workarounds, added one small workaround for
missing ARB_texture_compression_bptc. I didn't want to patch glLoadGen
for just four enum values, this way it's possible to use stock one
without any patching (except for missing OpenGL 2.1 support, as stated
in external/OpenGL/GL/README.md).

As one file now replaces both `glew.h` and `glcorearb.h` and it has the
same size as `glcorearb.h` alone , it saves approximately 18k LOC,
resulting in 15 second shorter compilation time (5:03 before, 4:48 now).
Not bad.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
519f9f7c32
  1. 3
      CMakeLists.txt
  2. 12
      doc/building.dox
  3. 2
      doc/cmake.dox
  4. 1
      doc/getting-started.dox
  5. 5
      external/OpenGL/GL/CMakeLists.txt
  6. 3255
      external/OpenGL/GL/glcorearb.h
  7. 67
      modules/FindGLEW.cmake
  8. 12
      modules/FindMagnum.cmake
  9. 9
      src/CMakeLists.txt
  10. 3
      src/OpenGL.h
  11. 11
      src/Platform/AbstractContextHandler.h
  12. 2
      src/Platform/AbstractXApplication.cpp
  13. 18
      src/Platform/ExtensionWrangler.cpp
  14. 8
      src/Platform/ExtensionWrangler.h
  15. 5
      src/Platform/GlxContextHandler.h
  16. 4
      src/Platform/Sdl2Application.cpp
  17. 3
      src/Platform/WindowlessGlxApplication.cpp
  18. 4
      src/RenderbufferFormat.h
  19. 24
      src/TextureFormat.h

3
CMakeLists.txt

@ -92,9 +92,6 @@ elseif(TARGET_GLES2)
else()
find_package(OpenGLES3 REQUIRED)
endif()
if(NOT TARGET_GLES)
find_package(GLEW REQUIRED)
endif()
# Configuration variables (saved later to corradeConfigure.h)
if(TARGET_GLES)

12
doc/building.dox

@ -41,7 +41,6 @@ Minimal set of tools and libraries required for building is:
>= 3.1. On Windows you can use **MinGW**, Visual Studio compiler still lacks
some needed features.
- **CMake** >= 2.8.8
- **GLEW** - OpenGL extension wrangler (only if targeting desktop OpenGL)
- **Corrade** - Plugin management and utility library. See
@ref building-corrade "Corrade download and installation guide" for more
information.
@ -118,12 +117,6 @@ have installed them to MinGW directory, point to `CMAKE_FIND_ROOT_PATH` to
MinGW installation prefix, e.g. specify `-DCMAKE_FIND_ROOT_PATH=C:/MinGW/`
CMake parameter.
If building fails with GLEW linking errors (`undefined reference to glew...`),
you have to set `GLEW_LIBRARY_DLL` and `GLEW_LIBRARY_LIB` CMake variables
manually. One of them should point to `glew32.dll` and the other to
`glew32.lib`. CMake currently isn't able to distinguish between them and in
most cases points both to the same location.
See also Corrade's @ref building-corrade-windows-troubleshooting "troubleshooting section".
@subsection building-features Enabling or disabling features
@ -251,12 +244,11 @@ flags.
this system there is also prepared `mingw32-magnum` development package in
root, named `PKGBUILD-mingw32`.
You will need MinGW32 versions of the compiler and all libraries (GLEW,
Corrade), i.e. these ArchLinux packages:
You will need MinGW32 versions of the compiler and all dependent libraries
(Corrade), i.e. these ArchLinux packages:
- `mingw32-gcc`, which depends on `mingw32-w32api` containing OpenGL headers
- `mingw32-runtime`
- `mingw32-glew`
- `mingw32-corrade`
Make sure you have `toolchains` submodule updated, as

2
doc/cmake.dox

@ -47,7 +47,7 @@ variables:
- `MAGNUM_PLUGINS_IMPORTER_DIR` -- Directory with importer plugins
However, this command will try to find only the base library, not the optional
components. The base library depends on %Corrade, OpenGL and GLEW libraries (or
components. The base library depends on %Corrade and OpenGL libraries (or
OpenGL ES libraries). Additional dependencies are specified by the components.
The optional components are:

1
doc/getting-started.dox

@ -58,7 +58,6 @@ CMake build system, see @ref cmake for more information.
modules/FindCorrade.cmake
modules/FindMagnum.cmake
modules/FindGLEW.cmake
src/MyApplication.cpp
src/CMakeLists.txt
CMakeLists.txt

5
external/OpenGL/GL/CMakeLists.txt vendored

@ -22,4 +22,7 @@
# DEALINGS IN THE SOFTWARE.
#
install(FILES glcorearb.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/OpenGL/GL)
add_library(MagnumGLLoadGenObjects OBJECT gl_magnum.c)
set_target_properties(MagnumGLLoadGenObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}")
install(FILES gl_magnum.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/OpenGL/GL)

3255
external/OpenGL/GL/glcorearb.h vendored

File diff suppressed because it is too large Load Diff

67
modules/FindGLEW.cmake

@ -1,67 +0,0 @@
# Find GLEW - OpenGL Extension Wrangler handling module for CMake
#
# This module defines:
#
# GLEW_FOUND - True if GLEW library is found
# GLEW_LIBRARIES - GLEW libraries
# GLEW_INCLUDE_DIR - Include dir
#
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Include dir
find_path(GLEW_INCLUDE_DIR
NAMES GL/glew.h)
# Library
if(NOT WIN32)
find_library(GLEW_LIBRARY GLEW)
set(GLEW_LIBRARIES_ GLEW_LIBRARY)
mark_as_advanced(GLEW_LIBRARY)
else()
find_library(GLEW_LIBRARY_DLL glew32)
find_library(GLEW_LIBRARY_LIB glew32)
set(GLEW_LIBRARIES_ GLEW_LIBRARY_DLL GLEW_LIBRARY_LIB)
mark_as_advanced(GLEW_LIBRARY_DLL GLEW_LIBRARY_LIB)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("GLEW" DEFAULT_MSG
${GLEW_LIBRARIES_}
GLEW_INCLUDE_DIR)
if(NOT GLEW_FOUND)
return()
endif()
unset(GLEW_LIBRARIES_)
if(NOT WIN32)
set(GLEW_LIBRARIES ${GLEW_LIBRARY})
mark_as_advanced(GLEW_LIBRARY)
else()
set(GLEW_LIBRARIES ${GLEW_LIBRARY_DLL} ${GLEW_LIBRARY_LIB})
mark_as_advanced(GLEW_LIBRARY_DLL GLEW_LIBRARY_LIB)
endif()

12
modules/FindMagnum.cmake

@ -17,9 +17,9 @@
# MAGNUM_PLUGINS_IMPORTER_DIR - Directory with importer plugins
# MAGNUM_PLUGINS_AUDIOIMPORTER_DIR - Directory with audio importer plugins
# This command will try to find only the base library, not the optional
# components. The base library depends on Corrade, OpenGL and GLEW
# libraries. Additional dependencies are specified by the components. The
# optional components are:
# components. The base library depends on Corrade and OpenGL libraries (or
# OpenGL ES libraries). Additional dependencies are specified by the
# components. The optional components are:
# Audio - Audio library (depends on OpenAL library)
# DebugTools - DebugTools library (depends on MeshTools, Primitives,
# SceneGraph, Shaders and Shapes components)
@ -149,9 +149,6 @@ if(NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES)
else()
find_package(OpenGLES2 REQUIRED)
endif()
if(NOT MAGNUM_TARGET_GLES)
find_package(GLEW REQUIRED)
endif()
# On Windows and in static builds, *Application libraries need to have
# ${MAGNUM_LIBRARIES} listed in dependencies also after all other library names
@ -334,9 +331,6 @@ if(NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES)
else()
set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} ${OPENGLES2_LIBRARY})
endif()
if(NOT MAGNUM_TARGET_GLES)
set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} ${GLEW_LIBRARIES})
endif()
# Installation dirs
include(CorradeLibSuffix)

9
src/CMakeLists.txt

@ -165,7 +165,8 @@ set_target_properties(MagnumObjects PROPERTIES COMPILE_FLAGS "-DMagnumObjects_EX
# Main library
add_library(Magnum ${SHARED_OR_STATIC}
$<TARGET_OBJECTS:MagnumObjects>
$<TARGET_OBJECTS:MagnumMathObjects>)
$<TARGET_OBJECTS:MagnumMathObjects>
$<TARGET_OBJECTS:MagnumGLLoadGenObjects>)
if(BUILD_STATIC_PIC)
# TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property
set_target_properties(Magnum PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}")
@ -180,9 +181,6 @@ elseif(TARGET_GLES2)
else()
set(Magnum_LIBS ${Magnum_LIBS} ${OPENGLES3_LIBRARY})
endif()
if(NOT TARGET_GLES)
set(Magnum_LIBS ${Magnum_LIBS} ${GLEW_LIBRARIES})
endif()
target_link_libraries(Magnum ${Magnum_LIBS})
install(TARGETS Magnum DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
@ -238,7 +236,8 @@ if(BUILD_TESTS)
add_library(MagnumTestLib ${SHARED_OR_STATIC}
$<TARGET_OBJECTS:MagnumObjects>
$<TARGET_OBJECTS:MagnumMathObjects>)
$<TARGET_OBJECTS:MagnumMathObjects>
$<TARGET_OBJECTS:MagnumGLLoadGenObjects>)
set_target_properties(MagnumTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT)
target_link_libraries(MagnumTestLib ${Magnum_LIBS})

3
src/OpenGL.h

@ -33,8 +33,7 @@
/* Desktop OpenGL */
#ifndef MAGNUM_TARGET_GLES
#include <GL/glew.h>
#include <OpenGL/GL/glcorearb.h>
#include <OpenGL/GL/gl_magnum.h>
/* NaCl has its own gl2.h, the official one causes linker issues. Additionaly
to NaCl's gl2ext.h we are including our own to prevent undeclared symbol

11
src/Platform/AbstractContextHandler.h

@ -28,8 +28,6 @@
* @brief Class Magnum::Platform::AbstractContextHandler
*/
#include "ExtensionWrangler.h"
namespace Magnum { namespace Platform {
/**
@ -58,15 +56,6 @@ template<class Display, class VisualId, class Window> class AbstractContextHandl
/** @brief Create context */
virtual void createContext(Window nativeWindow) = 0;
/**
* @brief Whether to enable experimental extension wrangler features
*
* Default is to disable.
*/
virtual ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const {
return ExtensionWrangler::ExperimentalFeatures::Disable;
}
/** @brief Make the context current */
virtual void makeCurrent() = 0;

2
src/Platform/AbstractXApplication.cpp

@ -97,7 +97,7 @@ void AbstractXApplication::createContext(const Configuration& configuration) {
contextHandler->makeCurrent();
/* Initialize extension wrangler */
ExtensionWrangler::initialize(contextHandler->experimentalExtensionWranglerFeatures());
ExtensionWrangler::initialize();
c = new Context;
}

18
src/Platform/ExtensionWrangler.cpp

@ -32,20 +32,16 @@
namespace Magnum { namespace Platform {
void ExtensionWrangler::initialize(ExperimentalFeatures experimentalFeatures) {
void ExtensionWrangler::initialize() {
#ifndef MAGNUM_TARGET_GLES
/* Enable experimental features */
if(experimentalFeatures == ExperimentalFeatures::Enable)
glewExperimental = true;
/* Init GLEW */
GLenum err = glewInit();
if(err != GLEW_OK) {
Error() << "ExtensionWrangler: cannot initialize GLEW:" << glewGetErrorString(err);
/* Init glLoadGen. Ignore functions that failed to load (described by
`ogl_LOAD_SUCCEEDED + n` return code), as we requested the latest OpenGL
with many vendor extensions and there won't ever be a driver supporting
everything possible. */
if(ogl_LoadFunctions() == ogl_LOAD_FAILED) {
Error() << "ExtensionWrangler: cannot initialize glLoadGen";
std::exit(1);
}
#else
static_cast<void>(experimentalFeatures); /* Shut up about unused parameter */
#endif
}

8
src/Platform/ExtensionWrangler.h

@ -35,14 +35,8 @@ class ExtensionWrangler {
public:
ExtensionWrangler() = delete;
/** @brief Whether to enable or disable experimental features */
enum class ExperimentalFeatures {
Disable,
Enable
};
/** @brief Initialize extension wrangler */
static void initialize(ExperimentalFeatures experimentalFeatures = ExperimentalFeatures::Disable);
static void initialize();
};
}}

5
src/Platform/GlxContextHandler.h

@ -55,11 +55,6 @@ class GlxContextHandler: public AbstractContextHandler<Display*, VisualID, Windo
VisualID getVisualId(Display* nativeDisplay) override;
void createContext(Window nativeWindow) override;
/* This must be enabled, otherwise (on my NVidia) it crashes when creating VAO. WTF. */
ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const override {
return ExtensionWrangler::ExperimentalFeatures::Enable;
}
void makeCurrent() override {
glXMakeCurrent(display, window, context);
}

4
src/Platform/Sdl2Application.cpp

@ -106,9 +106,7 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
return false;
}
/* This must be enabled, otherwise (on my NVidia) it crashes when creating
VAO. WTF. */
ExtensionWrangler::initialize(ExtensionWrangler::ExperimentalFeatures::Enable);
ExtensionWrangler::initialize();
/* Push resize event, so viewportEvent() is called at startup */
SDL_Event* sizeEvent = new SDL_Event;

3
src/Platform/WindowlessGlxApplication.cpp

@ -28,6 +28,7 @@
#include <Utility/Debug.h>
#include "Context.h"
#include "Platform/ExtensionWrangler.h"
#define None 0L // redef Xlib nonsense
@ -103,7 +104,7 @@ void WindowlessGlxApplication::createContext(const Configuration&) {
}
/* Initialize extension wrangler */
ExtensionWrangler::initialize(ExtensionWrangler::ExperimentalFeatures::Enable);
ExtensionWrangler::initialize();
c = new Context;
}

4
src/RenderbufferFormat.h

@ -366,12 +366,8 @@ enum class RenderbufferFormat: GLenum {
R11FG11FB10F = GL_R11F_G11F_B10F,
#endif
/* 1.5.6 <= GLEW < 1.8.0 doesn't have this, even if there is
GL_ARB_ES2_compatibility */
#if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT)
/** RGB, normalized unsigned, red and blue 5bit, green 6bit. */
RGB565 = GL_RGB565,
#endif
/**
* sRGBA, each component normalized unsigned byte.

24
src/TextureFormat.h

@ -519,13 +519,7 @@ enum class TextureFormat: GLenum {
* RGB, normalized unsigned, red and blue component 5bit, green 6bit.
* @requires_gles30 %Extension @es_extension{OES,required_internalformat}
*/
/* 1.5.6 <= GLEW < 1.8.0 doesn't have this, even if there is
GL_ARB_ES2_compatibility */
#ifdef GL_RGB565
RGB565 = GL_RGB565,
#else
RGB565 = 0x8D62,
#endif
#ifndef MAGNUM_TARGET_GLES3
/**
@ -722,39 +716,37 @@ enum class TextureFormat: GLenum {
*/
CompressedSignedRGRgtc2 = GL_COMPRESSED_SIGNED_RG_RGTC2,
/* These are named with _ARB suffix, because glcorearb.h doesn't
have suffixless version (?!) and GLEW has it without suffix as
late as of 1.8.0 { */
/**
* BPTC compressed RGB, unsigned float.
* @requires_gl42 %Extension @extension{ARB,texture_compression_bptc}
* @requires_gl BPTC texture compression is not available in OpenGL ES.
* @todo Remove workaround when glLoadGen has `GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT`
*/
CompressedRGBBptcUnsignedFloat = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB,
CompressedRGBBptcUnsignedFloat = 0x8E8F,//GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
/**
* BPTC compressed RGB, signed float.
* @requires_gl42 %Extension @extension{ARB,texture_compression_bptc}
* @requires_gl BPTC texture compression is not available in OpenGL ES.
* @todo Remove workaround when glLoadGen has `GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT`
*/
CompressedRGBBptcSignedFloat = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB,
CompressedRGBBptcSignedFloat = 0x8E8E,//GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
/**
* BPTC compressed RGBA, normalized unsigned.
* @requires_gl42 %Extension @extension{ARB,texture_compression_bptc}
* @requires_gl BPTC texture compression is not available in OpenGL ES.
* @todo Remove workaround when glLoadGen has `GL_COMPRESSED_RGBA_BPTC_UNORM`
*/
CompressedRGBABptcUnorm = GL_COMPRESSED_RGBA_BPTC_UNORM_ARB,
CompressedRGBABptcUnorm = 0x8E8C,//GL_COMPRESSED_RGBA_BPTC_UNORM,
/**
* BPTC compressed sRGBA, normalized unsigned.
* @requires_gl42 %Extension @extension{ARB,texture_compression_bptc}
* @requires_gl BPTC texture compression is not available in OpenGL ES.
* @todo Remove workaround when glLoadGen has `GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM`
*/
CompressedSRGBAlphaBptcUnorm = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB,
/*}*/
CompressedSRGBAlphaBptcUnorm = 0x8E8D,//GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
#endif
/**

Loading…
Cancel
Save