Browse Source

ObjImporter: Use AnyImageImporter

Signed-off-by: Squareys <squareys@googlemail.com>
pull/205/head
Squareys 8 years ago
parent
commit
4503b01c4b
  1. 26
      src/MagnumPlugins/ObjImporter/CMakeLists.txt
  2. 4
      src/MagnumPlugins/ObjImporter/ObjImporter.cpp

26
src/MagnumPlugins/ObjImporter/CMakeLists.txt

@ -60,6 +60,9 @@ if(BUILD_STATIC_PIC)
set_target_properties(ObjImporter PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(ObjImporter PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif() endif()
target_link_libraries(ObjImporter Magnum MagnumMeshTools) target_link_libraries(ObjImporter Magnum MagnumMeshTools)
if(CORRADE_TARGET_WINDOWS)
target_link_libraries(ObjImporter AnyImageImporter)
endif()
install(FILES ${ObjImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/ObjImporter) install(FILES ${ObjImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/ObjImporter)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/configure.h DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/ObjImporter) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/configure.h DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/ObjImporter)
@ -73,11 +76,26 @@ if(BUILD_PLUGINS_STATIC)
endif() endif()
if(BUILD_TESTS) if(BUILD_TESTS)
add_library(MagnumObjImporterTestLib STATIC # On Win32 we need to avoid dllimporting AnyImageImporter symbols, because
$<TARGET_OBJECTS:ObjImporterObjects> # it would search for the symbols in some DLL even when they were linked
${PROJECT_SOURCE_DIR}/src/dummy.cpp) # XCode workaround, see file comment for details # statically. However it apparently doesn't matter that they were
# dllexported when building the static library. EH. And because the
# -DObjImporterObjects_EXPORTS is no longer set in this case, we need
# to avoid dllimporting ObjImporter symbols as well.
if(CORRADE_TARGET_WINDOWS)
add_library(MagnumObjImporterTestLib STATIC
${ObjImporter_SRCS}
${ObjImporter_HEADERS})
target_compile_definitions(MagnumObjImporterTestLib PRIVATE
"MAGNUM_ANYIMAGEIMPORTER_BUILD_STATIC"
"MAGNUM_OBJIMPORTER_BUILD_STATIC")
else()
add_library(MagnumObjImporterTestLib STATIC
$<TARGET_OBJECTS:ObjImporterObjects>
${PROJECT_SOURCE_DIR}/src/dummy.cpp) # XCode workaround, see file comment for details
endif()
set_target_properties(MagnumObjImporterTestLib PROPERTIES FOLDER "MagnumPlugins/ObjImporter") set_target_properties(MagnumObjImporterTestLib PROPERTIES FOLDER "MagnumPlugins/ObjImporter")
target_link_libraries(MagnumObjImporterTestLib Magnum MagnumMeshTools) target_link_libraries(MagnumObjImporterTestLib Magnum MagnumMeshTools MagnumAnyImageImporterTestLib)
add_subdirectory(Test) add_subdirectory(Test)
endif() endif()

4
src/MagnumPlugins/ObjImporter/ObjImporter.cpp

@ -44,7 +44,7 @@
#include "Magnum/Trade/ImageData.h" #include "Magnum/Trade/ImageData.h"
#include "Magnum/Trade/PhongMaterialData.h" #include "Magnum/Trade/PhongMaterialData.h"
#include "MagnumPlugins/TgaImporter/TgaImporter.h" #include "MagnumPlugins/AnyImageImporter/AnyImageImporter.h"
using namespace Corrade::Containers; using namespace Corrade::Containers;
@ -929,7 +929,7 @@ UnsignedInt ObjImporter::doImage2DCount() const { return _state->textures.size()
std::optional<ImageData2D> ObjImporter::doImage2D(UnsignedInt id) { std::optional<ImageData2D> ObjImporter::doImage2D(UnsignedInt id) {
CORRADE_ASSERT(manager(), "Trade::ObjImporter::image2D(): the plugin must be instantiated with access to plugin manager in order to open image files", {}); CORRADE_ASSERT(manager(), "Trade::ObjImporter::image2D(): the plugin must be instantiated with access to plugin manager in order to open image files", {});
std::unique_ptr<AbstractImporter> imageImporter = manager()->loadAndInstantiate("TgaImporter"); // probably AnyImageImporter would be the way to go here... AnyImageImporter imageImporter = AnyImageImporter{manager()}
if(!imageImporter->openFile(_state->fileRoot + _state->textures[id])) { if(!imageImporter->openFile(_state->fileRoot + _state->textures[id])) {
return std::nullopt; return std::nullopt;
} }

Loading…
Cancel
Save