mirror of
https://github.com/bkaradzic/bgfx.cmake.git
synced 2026-02-17 13:02:33 +01:00
bimg: Add texturec and cmake macro
This commit is contained in:
@@ -35,6 +35,24 @@ with section("parse"):
|
||||
'DISASM',
|
||||
'WERROR'],
|
||||
'nargs': '1+'}},
|
||||
'_bgfx_texturec_parse': { 'kwargs': { 'AS': 1,
|
||||
'FILE': 1,
|
||||
'FORMAT': 1,
|
||||
'MAX': 1,
|
||||
'MIPSKIP': 1,
|
||||
'OUTPUT': 1,
|
||||
'QUALITY': 1,
|
||||
'RADIANCE': 1,
|
||||
'REF': 1},
|
||||
'pargs': { 'flags': [ 'MIPS',
|
||||
'NORMALMAP',
|
||||
'EQUIRECT',
|
||||
'STRIP',
|
||||
'SDF',
|
||||
'IQA',
|
||||
'PMA',
|
||||
'LINEAR'],
|
||||
'nargs': '*'}},
|
||||
'bgfx_compile_binary_to_header': { 'kwargs': { 'ARRAY_NAME': 1,
|
||||
'INPUT_FILE': 1,
|
||||
'OUTPUT_FILE': 1},
|
||||
@@ -43,7 +61,25 @@ with section("parse"):
|
||||
'SHADERS': '+',
|
||||
'TYPE': 1,
|
||||
'VARYING_DEF': 1},
|
||||
'pargs': {'flags': [], 'nargs': '*'}}}
|
||||
'pargs': {'flags': [], 'nargs': '*'}},
|
||||
'bgfx_compile_texture': { 'kwargs': { 'AS': 1,
|
||||
'FILE': 1,
|
||||
'FORMAT': 1,
|
||||
'MAX': 1,
|
||||
'MIPSKIP': 1,
|
||||
'OUTPUT': 1,
|
||||
'QUALITY': 1,
|
||||
'RADIANCE': 1,
|
||||
'REF': 1},
|
||||
'pargs': { 'flags': [ 'MIPS',
|
||||
'NORMALMAP',
|
||||
'EQUIRECT',
|
||||
'STRIP',
|
||||
'SDF',
|
||||
'IQA',
|
||||
'PMA',
|
||||
'LINEAR'],
|
||||
'nargs': '*'}}}
|
||||
|
||||
# Override configurations per-command where available
|
||||
override_spec = {}
|
||||
|
||||
@@ -94,6 +94,10 @@ endif()
|
||||
|
||||
# sets project version from api ver / git rev
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cmake)
|
||||
if(BGFX_BUILD_TOOLS AND BGFX_CUSTOM_TARGETS)
|
||||
add_custom_target(tools)
|
||||
set_target_properties(tools PROPERTIES FOLDER "bgfx/tools")
|
||||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/shared.cmake)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake/bx)
|
||||
|
||||
24
README.md
24
README.md
@@ -60,6 +60,30 @@ target_include_directories(myLib ${CMAKE_BINARY_DIR}/include/generated/images)
|
||||
#include <image.png.h>
|
||||
```
|
||||
|
||||
### `bgfx_compile_texture`
|
||||
Add a build rule for a texture to the generated build system be compiled using texturec.
|
||||
```cmake
|
||||
bgfx_compile_texture(
|
||||
FILE filename
|
||||
OUTPUT filename
|
||||
[FORMAT format]
|
||||
[QUALITY default|fastest|highest]
|
||||
[MIPS]
|
||||
[MIPSKIP N]
|
||||
[NORMALMAP]
|
||||
[EQUIRECT]
|
||||
[STRIP]
|
||||
[SDF]
|
||||
[REF alpha]
|
||||
[IQA]
|
||||
[PMA]
|
||||
[LINEAR]
|
||||
[MAX max size]
|
||||
[RADIANCE model]
|
||||
[AS extension]
|
||||
)
|
||||
```
|
||||
|
||||
### `bgfx_compile_shader_to_header`
|
||||
Add a build rule for a `*.sc` shader to the generated build system using shaderc.
|
||||
```cmake
|
||||
|
||||
@@ -26,8 +26,8 @@ if(@CMAKE_CROSSCOMPILING@)
|
||||
endmacro()
|
||||
|
||||
_bgfx_crosscompile_use_host_tool(bin2c)
|
||||
_bgfx_crosscompile_use_host_tool(shaderc)
|
||||
_bgfx_crosscompile_use_host_tool(texturec)
|
||||
_bgfx_crosscompile_use_host_tool(shaderc)
|
||||
_bgfx_crosscompile_use_host_tool(texturev)
|
||||
_bgfx_crosscompile_use_host_tool(geometryv)
|
||||
endif()
|
||||
|
||||
@@ -59,6 +59,153 @@ function(bgfx_compile_binary_to_header)
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# _bgfx_texturec_parse(
|
||||
# FILE filename
|
||||
# OUTPUT filename
|
||||
# [FORMAT format]
|
||||
# [QUALITY default|fastest|highest]
|
||||
# [MIPS]
|
||||
# [MIPSKIP N]
|
||||
# [NORMALMAP]
|
||||
# [EQUIRECT]
|
||||
# [STRIP]
|
||||
# [SDF]
|
||||
# [REF alpha]
|
||||
# [IQA]
|
||||
# [PMA]
|
||||
# [LINEAR]
|
||||
# [MAX max size]
|
||||
# [RADIANCE model]
|
||||
# [AS extension]
|
||||
# )
|
||||
function(_bgfx_texturec_parse ARG_OUT)
|
||||
cmake_parse_arguments(
|
||||
ARG "MIPS;NORMALMAP;EQUIRECT;STRIP;SDF;IQA;PMA;LINEAR" "FILE;OUTPUT;FORMAT;QUALITY;MIPSKIP;REF;MAX;RADIANCE;AS"
|
||||
"" ${ARGN}
|
||||
)
|
||||
set(CLI "")
|
||||
|
||||
# -f
|
||||
if(ARG_FILE)
|
||||
list(APPEND CLI "-f" "${ARG_FILE}")
|
||||
endif()
|
||||
|
||||
# -o
|
||||
if(ARG_OUTPUT)
|
||||
list(APPEND CLI "-o" "${ARG_OUTPUT}")
|
||||
endif()
|
||||
|
||||
# -t
|
||||
if(ARG_FORMAT)
|
||||
list(APPEND CLI "-t" "${ARG_FORMAT}")
|
||||
endif()
|
||||
|
||||
# -q
|
||||
if(ARG_QUALITY)
|
||||
list(APPEND CLI "-q" "${ARG_QUALITY}")
|
||||
endif()
|
||||
|
||||
# --mips
|
||||
if(ARG_MIPS)
|
||||
list(APPEND CLI "--mips")
|
||||
endif()
|
||||
|
||||
# --mipskip
|
||||
if(ARG_MIPSKIP)
|
||||
list(APPEND CLI "--mipskip" "${ARG_MIPSKIP}")
|
||||
endif()
|
||||
|
||||
# --normalmap
|
||||
if(ARG_NORMALMAP)
|
||||
list(APPEND CLI "--normalmap")
|
||||
endif()
|
||||
|
||||
# --equirect
|
||||
if(ARG_EQUIRECT)
|
||||
list(APPEND CLI "--equirect")
|
||||
endif()
|
||||
|
||||
# --strip
|
||||
if(ARG_STRIP)
|
||||
list(APPEND CLI "--strip")
|
||||
endif()
|
||||
|
||||
# --sdf
|
||||
if(ARG_SDF)
|
||||
list(APPEND CLI "--sdf")
|
||||
endif()
|
||||
|
||||
# --ref
|
||||
if(ARG_REF)
|
||||
list(APPEND CLI "--ref" "${ARG_REF}")
|
||||
endif()
|
||||
|
||||
# --iqa
|
||||
if(ARG_IQA)
|
||||
list(APPEND CLI "--iqa")
|
||||
endif()
|
||||
|
||||
# --pma
|
||||
if(ARG_PMA)
|
||||
list(APPEND CLI "--pma")
|
||||
endif()
|
||||
|
||||
# --linear
|
||||
if(ARG_LINEAR)
|
||||
list(APPEND CLI "--linear")
|
||||
endif()
|
||||
|
||||
# --max
|
||||
if(ARG_MAX)
|
||||
list(APPEND CLI "--max" "${ARG_MAX}")
|
||||
endif()
|
||||
|
||||
# --radiance
|
||||
if(ARG_RADIANCE)
|
||||
list(APPEND CLI "--radiance" "${ARG_RADIANCE}")
|
||||
endif()
|
||||
|
||||
# --as
|
||||
if(ARG_AS)
|
||||
list(APPEND CLI "--as" "${ARG_AS}")
|
||||
endif()
|
||||
|
||||
set(${ARG_OUT} ${CLI} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# bgfx_compile_texture(
|
||||
# FILE filename
|
||||
# OUTPUT filename
|
||||
# [FORMAT format]
|
||||
# [QUALITY default|fastest|highest]
|
||||
# [MIPS]
|
||||
# [MIPSKIP N]
|
||||
# [NORMALMAP]
|
||||
# [EQUIRECT]
|
||||
# [STRIP]
|
||||
# [SDF]
|
||||
# [REF alpha]
|
||||
# [IQA]
|
||||
# [PMA]
|
||||
# [LINEAR]
|
||||
# [MAX max size]
|
||||
# [RADIANCE model]
|
||||
# [AS extension]
|
||||
# )
|
||||
#
|
||||
function(bgfx_compile_texture)
|
||||
cmake_parse_arguments(
|
||||
ARG "MIPS;NORMALMAP;EQUIRECT;STRIP;SDF;IQA;PMA;LINEAR" "FILE;OUTPUT;FORMAT;QUALITY;MIPSKIP;REF;MAX;RADIANCE;AS"
|
||||
"" ${ARGN}
|
||||
)
|
||||
_bgfx_texturec_parse(CLI ${ARGV})
|
||||
add_custom_command(
|
||||
OUTPUT ${ARG_OUTPUT} #
|
||||
COMMAND bgfx::texturec ${CLI} #
|
||||
MAIN_DEPENDENCY ${ARG_INPUT} #
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# _bgfx_shaderc_parse(
|
||||
# FILE filename
|
||||
# OUTPUT filename
|
||||
|
||||
@@ -22,3 +22,7 @@ include(3rdparty/miniz.cmake)
|
||||
include(bimg.cmake)
|
||||
include(bimg_decode.cmake)
|
||||
include(bimg_encode.cmake)
|
||||
|
||||
if(BGFX_BUILD_TOOLS_TEXTURE)
|
||||
include(texturec.cmake)
|
||||
endif()
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
# bgfx.cmake - bgfx building in cmake
|
||||
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
|
||||
|
||||
#
|
||||
# To the extent possible under law, the author(s) have dedicated all copyright
|
||||
# and related and neighboring rights to this software to the public domain
|
||||
# worldwide. This software is distributed without any warranty.
|
||||
|
||||
#
|
||||
# You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
include(CMakeParseArguments)
|
||||
add_executable(texturec)
|
||||
|
||||
add_executable(texturec ${BIMG_DIR}/tools/texturec/texturec.cpp)
|
||||
set_target_properties(texturec PROPERTIES FOLDER "bgfx/tools")
|
||||
# Grab the texturec source files
|
||||
file(GLOB_RECURSE TEXTUREC_SOURCES #
|
||||
${BIMG_DIR}/tools/texturec/*.cpp #
|
||||
${BIMG_DIR}/tools/texturec/*.h #
|
||||
)
|
||||
|
||||
target_sources(texturec PRIVATE ${TEXTUREC_SOURCES})
|
||||
target_link_libraries(texturec PRIVATE bimg_decode bimg_encode bimg)
|
||||
if(BGFX_CUSTOM_TARGETS)
|
||||
set_target_properties(texturec PROPERTIES FOLDER "bgfx/tools")
|
||||
|
||||
if(BGFX_BUILD_TOOLS AND BGFX_CUSTOM_TARGETS)
|
||||
add_dependencies(tools texturec)
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
target_link_libraries(texturec log)
|
||||
target_link_libraries(texturec PRIVATE log)
|
||||
elseif(IOS)
|
||||
set_target_properties(texturec PROPERTIES MACOSX_BUNDLE ON MACOSX_BUNDLE_GUI_IDENTIFIER texturec)
|
||||
endif()
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
include(bx.cmake)
|
||||
|
||||
if(BGFX_BUILD_TOOLS)
|
||||
if(BGFX_BUILD_TOOLS_BIN2C)
|
||||
include(bin2c.cmake)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -19,3 +19,13 @@ file(GLOB_RECURSE BIN2C_SOURCES #
|
||||
target_sources(bin2c PRIVATE ${BIN2C_SOURCES})
|
||||
target_link_libraries(bin2c PRIVATE bx)
|
||||
set_target_properties(bin2c PROPERTIES FOLDER "bgfx/tools")
|
||||
|
||||
if(BGFX_BUILD_TOOLS AND BGFX_CUSTOM_TARGETS)
|
||||
add_dependencies(tools bin2c)
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
target_link_libraries(bin2c PRIVATE log)
|
||||
elseif(IOS)
|
||||
set_target_properties(bin2c PROPERTIES MACOSX_BUNDLE ON MACOSX_BUNDLE_GUI_IDENTIFIER bin2c)
|
||||
endif()
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
# You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
if(BGFX_CUSTOM_TARGETS)
|
||||
add_custom_target(tools)
|
||||
set_target_properties(tools PROPERTIES FOLDER "bgfx/tools")
|
||||
endif()
|
||||
|
||||
if(BGFX_BUILD_TOOLS_SHADER)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/tools/shaderc.cmake)
|
||||
endif()
|
||||
@@ -23,6 +18,5 @@ if(BGFX_BUILD_TOOLS_GEOMETRY)
|
||||
endif()
|
||||
|
||||
if(BGFX_BUILD_TOOLS_TEXTURE)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/tools/texturec.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/tools/texturev.cmake)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user