Skip to content

Commit

Permalink
bimg: Add texturec and cmake macro
Browse files Browse the repository at this point in the history
  • Loading branch information
bwrsandman committed Jan 15, 2023
1 parent c1640a6 commit 95a0a20
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 16 deletions.
38 changes: 37 additions & 1 deletion .cmake-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
'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},
Expand All @@ -43,7 +61,25 @@
'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 = {}
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
147 changes: 147 additions & 0 deletions cmake/bgfxToolUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmake/bimg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
21 changes: 14 additions & 7 deletions cmake/tools/texturec.cmake → cmake/bimg/texturec.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <[email protected]>

#
# 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()
2 changes: 1 addition & 1 deletion cmake/bx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

include(bx.cmake)

if(BGFX_BUILD_TOOLS)
if(BGFX_BUILD_TOOLS_BIN2C)
include(bin2c.cmake)
endif()

Expand Down
10 changes: 10 additions & 0 deletions cmake/bx/bin2c.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 0 additions & 6 deletions cmake/tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

0 comments on commit 95a0a20

Please sign in to comment.