Skip to content

Commit

Permalink
WIP BasisImporter
Browse files Browse the repository at this point in the history
Signed-off-by: Squareys <[email protected]>
  • Loading branch information
Squareys committed Aug 25, 2019
1 parent 33540c9 commit 7d0ce67
Show file tree
Hide file tree
Showing 84 changed files with 41,920 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
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()
3 changes: 2 additions & 1 deletion doc/building-plugins.dox
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
This file is part of Magnum.

Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <[email protected]>

Expand Down Expand Up @@ -289,6 +288,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
50 changes: 50 additions & 0 deletions doc/snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
# Vladimír Vondruš <[email protected]>
#
# 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()
set_target_properties(snippets-BasisImporter PROPERTIES FOLDER "Magnum/doc/snippets")
endif()
44 changes: 44 additions & 0 deletions doc/snippets/MagnumPluginsBasisImporter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/ConfigurationGroup.h>

#include <Magnum/Trade/AbstractImporter.h>

#ifdef __has_include
#if __has_include(<MagnumPlugins/BasisImporter/importStaticPlugin.cpp>)
/* [static-import] */
/* No need to do this if you use CMake */
#include <MagnumPlugins/BasisImporter/importStaticPlugin.cpp>
/* [static-import] */
#endif
#endif

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] */
}

}
15 changes: 15 additions & 0 deletions doc/snippets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Snippets that possibly generate output for Magnum documentation
###############################################################

### "Getting started" image

Displayed by the `getting-started` executable. Run the app and take screenshot
using Spectacle (including decorations, 880x707). Similarly for the gray
version. The resulting files should be resized to half. `pngcrush` to them for
smaller file sizes:

pngcrush -ow getting-started.png
pngcrush -ow getting-started-blue.png

The output printed by the application can be used to update the example output
in `doc/getting-started.dox`.
27 changes: 27 additions & 0 deletions doc/snippets/configure.h.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
This file is part of Magnum.

Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <[email protected]>

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}"
10 changes: 9 additions & 1 deletion modules/FindMagnumPlugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# This command will not try to find any actual plugin. The plugins are:
#
# AssimpImporter - Assimp importer
# BasisImporter - Basis importer
# DdsImporter - DDS importer
# DevIlImageImporter - Image importer using DevIL
# DrFlacAudioImporter - FLAC audio importer using dr_flac
Expand Down Expand Up @@ -69,6 +70,7 @@
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
# Vladimír Vondruš <[email protected]>
# Copyright © 2019 Jonathan Hale <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -121,7 +123,7 @@ mark_as_advanced(MAGNUMPLUGINS_INCLUDE_DIR)
# components from other repositories)
set(_MAGNUMPLUGINS_LIBRARY_COMPONENT_LIST OpenDdl)
set(_MAGNUMPLUGINS_PLUGIN_COMPONENT_LIST
AssimpImporter DdsImporter DevIlImageImporter
AssimpImporter BasisImporter DdsImporter DevIlImageImporter
DrFlacAudioImporter DrMp3AudioImporter DrWavAudioImporter Faad2AudioImporter
FreeTypeFont HarfBuzzFont JpegImageConverter JpegImporter
MiniExrImageConverter OpenGexImporter PngImageConverter PngImporter
Expand Down Expand Up @@ -271,6 +273,12 @@ foreach(_component ${MagnumPlugins_FIND_COMPONENTS})
set_property(TARGET MagnumPlugins::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES Assimp::Assimp)

# BasisImporter plugin dependencies
if(_component STREQUAL BasisImporter)
find_package(BasisUniversal)
set_property(TARGET MagnumPlugins::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES BasisUniversal::Transcoder)

# DdsImporter has no dependencies

# DevIlImageImporter plugin dependencies
Expand Down
44 changes: 44 additions & 0 deletions src/MagnumExternal/BasisUniversal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
project(BasisUniversal)

add_library(basisu_transcoder STATIC
transcoder/basisu_transcoder.cpp)
target_include_directories(basisu_transcoder PUBLIC
${CMAKE_CURRENT_SOURCE_DIR})
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(basisu_transcoder PRIVATE
-Wno-old-style-cast
-Wno-unused-variable
-Wno-unused-const-variable)
endif()
target_compile_definitions(basisu_transcoder PUBLIC BASISU_NO_ITERATOR_DEBUG_LEVEL)
add_library(basisu::transcoder ALIAS basisu_transcoder)

add_library(basisu_encoder STATIC
basisu_backend.cpp
basisu_basis_file.cpp
basisu_comp.cpp
basisu_enc.cpp
basisu_etc.cpp
basisu_frontend.cpp
basisu_global_selector_palette_helpers.cpp
basisu_gpu_texture.cpp
basisu_pvrtc1_4.cpp
basisu_resampler.cpp
basisu_resample_filters.cpp
basisu_ssim.cpp
basisu_tool.cpp
lodepng.cpp)

target_include_directories(basisu_encoder PUBLIC
${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(basisu_encoder PRIVATE basisu::transcoder)
add_library(basisu::encoder ALIAS basisu_encoder)
target_compile_definitions(basisu_encoder PUBLIC BASISU_NO_ITERATOR_DEBUG_LEVEL)

if(BUILD_STATIC_PIC)
set_target_properties(basisu_transcoder
PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(basisu_encoder
PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

Loading

0 comments on commit 7d0ce67

Please sign in to comment.