diff options
author | Jaebaek Seo <jaebaek@google.com> | 2019-07-24 16:12:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-24 16:12:59 -0400 |
commit | 6bdbb5fa50b1b82b0676cf9a91729c0f0f7f9e14 (patch) | |
tree | dfc35b0e7aeb05404f49543b3dd60ce9448771ef | |
parent | 6e5c1c43ab8caf2ede9a75d8037c1715c2ce8a0f (diff) | |
download | amber-6bdbb5fa50b1b82b0676cf9a91729c0f0f7f9e14.tar.gz |
Optional PNG support (#596)
As discussed in #591, this CL sets lodepng as an optional library.
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | samples/CMakeLists.txt | 9 | ||||
-rw-r--r-- | samples/amber.cc | 9 | ||||
-rw-r--r-- | third_party/CMakeLists.txt | 2 |
5 files changed, 29 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 92d8184..aa09507 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ option(AMBER_SKIP_SHADERC "Skip building Shaderc into the library" ${AMBER_SKIP_SHADERC}) option(AMBER_SKIP_SAMPLES "Skip building sample application" ${AMBER_SKIP_SAMPLES}) +option(AMBER_SKIP_LODEPNG + "Skip building lodepng into the library" ${AMBER_SKIP_LODEPNG}) option(AMBER_USE_DXC "Enable DXC integration" ${AMBER_USE_DXC}) option(AMBER_USE_LOCAL_VULKAN "Build with vulkan in third_party" OFF) option(AMBER_USE_CLSPV "Build with Clspv support" OFF) @@ -80,6 +82,12 @@ else() set(AMBER_ENABLE_SAMPLES TRUE) endif() +if (${AMBER_SKIP_LODEPNG}) + set(AMBER_ENABLE_LODEPNG FALSE) +else() + set(AMBER_ENABLE_LODEPNG TRUE) +endif() + if (${AMBER_ENABLE_SWIFTSHADER}) # Swiftshader requires the loader to be built. set(AMBER_USE_LOCAL_VULKAN TRUE) @@ -106,6 +114,7 @@ message(STATUS "Amber enable SPIRV-Tools: ${AMBER_ENABLE_SPIRV_TOOLS}") message(STATUS "Amber enable Shaderc: ${AMBER_ENABLE_SHADERC}") message(STATUS "Amber enable tests: ${AMBER_ENABLE_TESTS}") message(STATUS "Amber enable samples: ${AMBER_ENABLE_SAMPLES}") +message(STATUS "Amber enable lodepng: ${AMBER_ENABLE_LODEPNG}") message(STATUS "Amber enable SwiftShader: ${AMBER_ENABLE_SWIFTSHADER}") message(STATUS "Amber enable DXC: ${AMBER_ENABLE_DXC}") message(STATUS "Amber enable Clspv: ${AMBER_ENABLE_CLSPV}") @@ -130,6 +139,7 @@ add_definitions(-DAMBER_ENABLE_SPIRV_TOOLS=$<BOOL:${AMBER_ENABLE_SPIRV_TOOLS}>) add_definitions(-DAMBER_ENABLE_SHADERC=$<BOOL:${AMBER_ENABLE_SHADERC}>) add_definitions(-DAMBER_ENABLE_DXC=$<BOOL:${AMBER_ENABLE_DXC}>) add_definitions(-DAMBER_ENABLE_CLSPV=$<BOOL:${AMBER_ENABLE_CLSPV}>) +add_definitions(-DAMBER_ENABLE_LODEPNG=$<BOOL:${AMBER_ENABLE_LODEPNG}>) set(CMAKE_DEBUG_POSTFIX "") @@ -196,6 +196,9 @@ out/Debug/amber tests/cases/clear.vkscript The sample app returns a value of 0 on success or non-zero on error. Any issues encountered should be displayed on the console. +By default, `out/Debug/amber` supports saving the output image into '.png' +file. You can disable this by passing `-DAMBER_SKIP_LODEPNG=true` to cmake. + ## Contributing Please see the [CONTRIBUTING](CONTRIBUTING.md) and diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 3831b8b..d41ee21 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -19,12 +19,16 @@ set(AMBER_SOURCES config_helper.cc log.cc ppm.cc - png.cc timestamp.cc ${CMAKE_BINARY_DIR}/src/build-versions.h.fake ) -set(AMBER_EXTRA_LIBS "lodepng") +set(AMBER_EXTRA_LIBS "") + +if (${AMBER_ENABLE_LODEPNG}) + set(AMBER_SOURCES ${AMBER_SOURCES} png.cc) + list(APPEND AMBER_EXTRA_LIBS "lodepng") +endif() if (${Vulkan_FOUND}) set(AMBER_SOURCES ${AMBER_SOURCES} config_helper_vulkan.cc) @@ -45,6 +49,7 @@ endif() add_executable(amber ${AMBER_SOURCES}) target_include_directories(amber PRIVATE "${CMAKE_BINARY_DIR}") + set_target_properties(amber PROPERTIES OUTPUT_NAME "amber") target_link_libraries(amber libamber ${AMBER_EXTRA_LIBS}) amber_default_compile_options(amber) diff --git a/samples/amber.cc b/samples/amber.cc index 0f68a9f..8c945b1 100644 --- a/samples/amber.cc +++ b/samples/amber.cc @@ -25,12 +25,15 @@ #include "amber/recipe.h" #include "samples/config_helper.h" -#include "samples/png.h" #include "samples/ppm.h" #include "samples/timestamp.h" #include "src/build-versions.h" #include "src/make_unique.h" +#if AMBER_ENABLE_LODEPNG +#include "samples/png.h" +#endif // AMBER_ENABLE_LODEPNG + namespace { const char* kGeneratedColorBuffer = "framebuffer"; @@ -431,8 +434,12 @@ int main(int argc, const char** argv) { for (const amber::BufferInfo& buffer_info : amber_options.extractions) { if (buffer_info.buffer_name == options.fb_name) { if (usePNG) { +#if AMBER_ENABLE_LODEPNG result = png::ConvertToPNG(buffer_info.width, buffer_info.height, buffer_info.values, &out_buf); +#else // AMBER_ENABLE_LODEPNG + result = amber::Result("PNG support not enabled"); +#endif // AMBER_ENABLE_LODEPNG } else { ppm::ConvertToPPM(buffer_info.width, buffer_info.height, buffer_info.values, &out_buf); diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index f23cdb0..db865ad 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -41,7 +41,7 @@ if (${AMBER_ENABLE_SHADERC}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/shaderc) endif() -if (${AMBER_ENABLE_SAMPLES}) +if (${AMBER_ENABLE_SAMPLES} AND ${AMBER_ENABLE_LODEPNG}) # Lodepng set(LODEPNG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lodepng/lodepng.cpp) add_library(lodepng STATIC ${LODEPNG_SOURCES}) |