Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BasisImporter #62

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Expand Up @@ -42,6 +42,7 @@ include(CMakeDependentOption)

# Plugins to build
option(WITH_ASSIMPIMPORTER "Build AssimpImporter plugin" OFF)
option(WITH_BASISIMPORTER "Build BasisImporter plugin" OFF)
option(WITH_DDSIMPORTER "Build DdsImporter plugin" OFF)
option(WITH_DEVILIMAGEIMPORTER "Build DevIlImageImporter plugin" OFF)
option(WITH_DRFLACAUDIOIMPORTER "Build DrFlacAudioImporter plugin" OFF)
Expand Down Expand Up @@ -121,3 +122,8 @@ set(MAGNUM_LIBRARY_SOVERSION 2)

add_subdirectory(modules)
add_subdirectory(src)

# Build snippets as part of testing
if(BUILD_TESTS)
add_subdirectory(doc/snippets)
endif()
2 changes: 2 additions & 0 deletions doc/building-plugins.dox
Expand Up @@ -289,6 +289,8 @@ By default no plugins are built and you need to select them manually:

- `WITH_ASSIMPIMPORTER` --- Build the @ref Trade::AssimpImporter "AssimpImporter"
plugin. Depends on [Assimp](http://assimp.org/).
- `WITH_BASISIMPORTER` --- Build the @ref Trade::BasisImporter "BasisImporter"
plugin.
- `WITH_DDSIMPORTER` --- Build the @ref Trade::DdsImporter "DdsImporter"
plugin.
- `WITH_DEVILIMAGEIMPORTER` --- Build the
Expand Down
2 changes: 2 additions & 0 deletions doc/changelog-plugins.dox
Expand Up @@ -36,6 +36,8 @@ namespace Magnum {

- New @ref Audio::DrMp3Importer "DrMp3AudioImporter" plugin for importing
MP3 files (see [mosra/magnum-plugins#60](https://github.com/mosra/magnum-plugins/pull/60))
- New @ref Trade::BasisImporter "BasisImporter" plugin for importing
Basis files (see [mosra/magnum-plugins#62](https://github.com/mosra/magnum-plugins/pull/62))

@subsection changelog-plugins-latest-changes Changes and improvements

Expand Down
4 changes: 4 additions & 0 deletions doc/cmake-plugins.dox
Expand Up @@ -72,6 +72,7 @@ This command tries to find Magnum plugins and then defines:
This command will not try to find any actual plugin. The plugins are:

- `AssimpImporter` --- @ref Trade::AssimpImporter "AssimpImporter" plugin
- `BasisImporter` --- @ref Trade::BasisImporter "BasisImporter" plugin
- `DdsImporter` --- @ref Trade::DdsImporter "DdsImporter" plugin
- `DevIlImageImporter` --- @ref Trade::DevIlImageImporter "DevIlImageImporter"
plugin
Expand Down Expand Up @@ -143,6 +144,9 @@ usage documentation.
- [FindAssimp.cmake](https://github.com/mosra/magnum-plugins/blob/master/modules/FindAssimp.cmake)
--- CMake module for finding Assimp. Copy this to your module directory if
you want to find and link to @ref Trade::AssimpImporter.
- [FindBasisUniversal.cmake](https://github.com/mosra/magnum-plugins/blob/master/modules/FindBasisUniversal.cmake)
--- CMake module for finding basis universal sources. Copy this to your module directory if
you want to find and link to @ref Trade::BasisImporter.
- [FindDevIL.cmake](https://github.com/mosra/magnum-plugins/blob/master/modules/FindDevIL.cmake)
--- CMake module for finding DevIL. This is a forked version of the upstream
module that doesn't attempt to find the often not distributed ILUT library.
Expand Down
1 change: 1 addition & 0 deletions doc/credits.dox
Expand Up @@ -47,6 +47,7 @@ namespace Magnum {
fixes for @ref Trade::AssimpImporter "AssimpImporter" workarounds
- **Jonathan Hale** ([\@Squareys](https://github.com/Squareys)) ---
@ref Trade::AssimpImporter "AssimpImporter",
@ref Trade::BasisImporter "BasisImporter",
@ref Trade::DdsImporter "DdsImporter" and
@ref Audio::StbVorbisImporter "StbVorbisAudioImporter" plugins,
improvements to @ref Trade::TinyGltfImporter "TinyGltfImporter"
Expand Down
3 changes: 3 additions & 0 deletions doc/namespaces.dox
Expand Up @@ -29,6 +29,9 @@
/** @dir MagnumPlugins/AssimpImporter
* @brief Plugin @ref Magnum::Trade::AssimpImporter
*/
/** @dir MagnumPlugins/BasisImporter
* @brief Plugin @ref Magnum::Trade::BasisImporter
*/
/** @dir MagnumPlugins/DdsImporter
* @brief Plugin @ref Magnum::Trade::DdsImporter
*/
Expand Down
51 changes: 51 additions & 0 deletions doc/snippets/CMakeLists.txt
@@ -0,0 +1,51 @@
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
# 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.
#

find_package(Corrade REQUIRED PluginManager)

# On MSVC remove /W3, as we are replacing it with /W4
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

set_directory_properties(PROPERTIES
CORRADE_CXX_STANDARD 11
CORRADE_USE_PEDANTIC_FLAGS ON)

# Emscripten needs special flag to use WebGL 2
if(CORRADE_TARGET_EMSCRIPTEN AND NOT TARGET_GLES2)
# TODO: give me INTERFACE_LINK_OPTIONS or something, please
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_WEBGL2=1")
endif()

if(WITH_BASISIMPORTER)
add_library(snippets-BasisImporter STATIC
MagnumPluginsBasisImporter.cpp)
if(BUILD_PLUGINS_STATIC)
target_link_libraries(snippets-BasisImporter PRIVATE BasisImporter)
endif()
target_link_libraries(snippets-BasisImporter PRIVATE Corrade::PluginManager)
set_target_properties(snippets-BasisImporter PROPERTIES FOLDER "Magnum/doc/snippets")
endif()
35 changes: 35 additions & 0 deletions doc/snippets/MagnumPluginsBasisImporter.cpp
@@ -0,0 +1,35 @@
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/ConfigurationGroup.h>

#include <Magnum/Trade/AbstractImporter.h>

using namespace Magnum;

int main() {

{
PluginManager::Manager<Trade::AbstractImporter> manager;
/* [basis-target-format-suffix] */
/* Choose Etc2 target format */
Containers::Pointer<Trade::AbstractImporter> importerEtc2 =
manager.instantiate("BasisImporterEtc2");

/* Choose Bc5 target format */
Containers::Pointer<Trade::AbstractImporter> importerBc5 =
manager.instantiate("BasisImporterBc5");
/* [basis-target-format-suffix] */
}

{
PluginManager::Manager<Trade::AbstractImporter> manager;
/* [basis-target-format-config] */
/* Chooses default Etc2 target format */
Containers::Pointer<Trade::AbstractImporter> importer =
manager.instantiate("BasisImporter");

/* Change to Bc5 */
importer->configuration().setValue("format", "Bc5");
/* [basis-target-format-config] */
}

}
27 changes: 27 additions & 0 deletions doc/snippets/configure.h.cmake
@@ -0,0 +1,27 @@
/*
This file is part of Magnum.

Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
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.
*/

#define MAGNUM_PLUGINS_IMPORTER_DIR "${MAGNUM_PLUGINS_IMPORTER_DIR}"
#define SNIPPETS_DIR "${SNIPPETS_DIR}"
209 changes: 209 additions & 0 deletions modules/FindBasisUniversal.cmake
@@ -0,0 +1,209 @@
#.rst:
# Find BasisUniversal
# -------------------
#
# Finds the BasisUniversal library. This module defines:
#
# BasisUniversal_FOUND - True if BasisUniversal is found
# BasisUniversal::Encoder - Encoder library target
# BasisUniversal::Transcoder - Transcoder library target
#
# Additionally these variables are defined for internal usage:
#
# BasisUniversalTranscoder_INCLUDE_DIR - Transcoder include dir
# BasisUniversalEncoder_INCLUDE_DIR - Encoder include dir
#
# The find module first tries to find ``basisu_transcoder`` and ``basisu_encoder``
# via a CMake config file (which is distributed this way via Vcpkg, for example).
# If that's found, the ``BasisUniversal::Transcoder`` and ``BasisUniversal::Encoder``
# targets are set up as aliases to them.
#
# If ``basisu`` is not found, as a fallback it tries to find the C++ sources.
# You can supply their location via an ``BASISU_DIR`` variable. Once found, the
# ``BasisUniversal::Encoder`` target is set up to compile the sources of the
# encoder and ``BasisUniversal::Transcoder`` the sources of the transcoder as
# static libraries.
#

#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
# Vladimír Vondruš <mosra@centrum.cz>
# Copyright © 2019 Jonathan Hale <squareys@googlemail.com>
#
# 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.
#

# Vcpkg distributes imgui as a library with a config file, so try that first --
# but only if IMGUI_DIR wasn't explicitly passed, in which case we'll look
# there instead
find_package(basisu CONFIG QUIET)
if(basisu_FOUND AND NOT BASISU_DIR)
if(NOT TARGET BasisUniversal::Transcoder)
add_library(BasisUniversal::Transcoder INTERFACE IMPORTED)
set_property(TARGET BasisUniversal::Transcoder APPEND PROPERTY
INTERFACE_LINK_LIBRARIES basisu_transcoder)

# Retrieve include directory for FindPackageHandleStandardArgs later
get_target_property(BasisUniversalTranscoder_INCLUDE_DIR basisu_transcoder
INTERFACE_INCLUDE_DIRECTORIES)
endif()

if(NOT TARGET BasisUniversal::Encoder)
add_library(BasisUniversal::Encoder INTERFACE IMPORTED)
set_property(TARGET BasisUniversal::Encoder APPEND PROPERTY
INTERFACE_LINK_LIBRARIES basisu_encoder)

# Retrieve include directory for FindPackageHandleStandardArgs later
get_target_property(BasisUniversalEncoder_INCLUDE_DIR basisu_encoder
INTERFACE_INCLUDE_DIRECTORIES)
endif()

# Otherwise find the source files and compile them as part of the library they
# get linked to
else()
# Disable the find root path here, it overrides the
# CMAKE_FIND_ROOT_PATH_MODE_INCLUDE setting potentially set in
# toolchains.
find_path(BasisUniversalEncoder_INCLUDE_DIR NAMES basisu_frontend.h HINTS
HINTS "${BASISU_DIR}" "${BASISU_DIR}/encoder"
NO_CMAKE_FIND_ROOT_PATH)
mark_as_advanced(BasisUniversalEncoder_INCLUDE_DIR)

find_path(BasisUniversalTranscoder_INCLUDE_DIR NAMES basisu_transcoder.h
HINTS "${BASISU_DIR}/transcoder" "${BASISU_DIR}"
NO_CMAKE_FIND_ROOT_PATH)
mark_as_advanced(BasisUniversalTranscoder_INCLUDE_DIR)
endif()

list (FIND BasisUniversal_FIND_COMPONENTS "Encoder" _index)
if (${_index} GREATER -1)
list(APPEND BasisUniversal_FIND_COMPONENTS "Transcoder")
list(REMOVE_DUPLICATES BasisUniversal_FIND_COMPONENTS)
endif()

macro(_basis_setup_source_file source)
# Handle export and import of imgui symbols via IMGUI_API
# definition in visibility.h of Magnum ImGuiIntegration.
set_property(SOURCE ${source} APPEND PROPERTY COMPILE_DEFINITIONS
BASISU_NO_ITERATOR_DEBUG_LEVEL)

# Hide warnings from basis source files

# GCC- and Clang-specific flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang"
AND NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") OR CORRADE_TARGET_EMSCRIPTEN)
set_property(SOURCE ${source} APPEND_STRING PROPERTY COMPILE_FLAGS
" -Wno-old-style-cast -Wno-zero-as-null-pointer-constant")
endif()

# GCC-specific flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_property(SOURCE ${source} APPEND_STRING PROPERTY COMPILE_FLAGS
" -Wno-double-promotion")
endif()
endmacro()


# Find components
foreach(_component IN LISTS BasisUniversal_FIND_COMPONENTS)
if(_component STREQUAL "Encoder")
if(NOT TARGET BasisUniversal::Encoder)
find_path(BasisUniversalEncoder_DIR NAMES basisu_frontend.cpp
HINTS "${BASISU_DIR}" "${BASISU_DIR}/encoder"
NO_CMAKE_FIND_ROOT_PATH)
if(BasisUniversalEncoder_DIR)
set(BasisUniversal_Encoder_FOUND TRUE)
else()
message(SEND_ERROR
"Could not find encoder in basis_universal directory.\n"
"Set BASISU_DIR to the root of a directory containing basis_universal source.")
endif()

set(BasisUniversalEncoder_SOURCES
${BasisUniversalEncoder_DIR}/basisu_backend.cpp
${BasisUniversalEncoder_DIR}/basisu_basis_file.cpp
${BasisUniversalEncoder_DIR}/basisu_comp.cpp
${BasisUniversalEncoder_DIR}/basisu_enc.cpp
${BasisUniversalEncoder_DIR}/basisu_etc.cpp
${BasisUniversalEncoder_DIR}/basisu_frontend.cpp
${BasisUniversalEncoder_DIR}/basisu_global_selector_palette_helpers.cpp
${BasisUniversalEncoder_DIR}/basisu_gpu_texture.cpp
${BasisUniversalEncoder_DIR}/basisu_pvrtc1_4.cpp
${BasisUniversalEncoder_DIR}/basisu_resampler.cpp
${BasisUniversalEncoder_DIR}/basisu_resample_filters.cpp
${BasisUniversalEncoder_DIR}/basisu_ssim.cpp
${BasisUniversalEncoder_DIR}/lodepng.cpp)

foreach(_file BasisUniversalEncoder_SOURCES)
_basis_setup_source_file(${_file})
endforeach()

find_package(Threads REQUIRED)

add_library(BasisUniversal::Encoder INTERFACE IMPORTED)
set_property(TARGET BasisUniversal::Encoder APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${BasisUniversalEncoder_INCLUDE_DIR})
set_property(TARGET BasisUniversal::Encoder APPEND PROPERTY
INTERFACE_SOURCES "${BasisUniversalEncoder_SOURCES}")
set_property(TARGET BasisUniversal::Encoder APPEND PROPERTY
INTERFACE_LINK_LIBRARIES BasisUniversal::Transcoder Threads::Threads)
set_property(TARGET BasisUniversal::Encoder APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS "BASISU_NO_ITERATOR_DEBUG_LEVEL")
else()
set(BasisUniversal_Encoder_FOUND TRUE)
endif()

elseif(_component STREQUAL "Transcoder")
if(NOT TARGET BasisUniversal::Transcoder)
find_path(BasisUniversalTranscoder_DIR NAMES basisu_transcoder.cpp
HINTS "${BASISU_DIR}/transcoder" "${BASISU_DIR}"
NO_CMAKE_FIND_ROOT_PATH)
if(BasisUniversalTranscoder_DIR)
set(BasisUniversal_Transcoder_FOUND TRUE)
else()
message(SEND_ERROR
"Could not find transcoder in basis_universal directory.\n"
"Set BASISU_DIR to the root of a directory containing basis_universal source.")
endif()
set(BasisUniversalTranscoder_SOURCES
${BasisUniversalTranscoder_DIR}/basisu_transcoder.cpp)

foreach(_file BasisUniversalTranscoder_SOURCES)
_basis_setup_source_file(${_file})
endforeach()

add_library(BasisUniversal::Transcoder INTERFACE IMPORTED)
set_property(TARGET BasisUniversal::Transcoder APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${BasisUniversalTranscoder_INCLUDE_DIR})
set_property(TARGET BasisUniversal::Transcoder APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS "BASISU_NO_ITERATOR_DEBUG_LEVEL")
set_property(TARGET BasisUniversal::Transcoder APPEND PROPERTY
INTERFACE_SOURCES "${BasisUniversalTranscoder_SOURCES}")
else()
set(BasisUniversal_Transcoder_FOUND TRUE)
endif()
endif()
endforeach()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(BasisUniversal
REQUIRED_VARS BasisUniversalTranscoder_INCLUDE_DIR BasisUniversalEncoder_INCLUDE_DIR
HANDLE_COMPONENTS)