Basic window.
This commit is contained in:
9
tools/CMakeLists.txt
Normal file
9
tools/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Tools
|
||||
add_subdirectory(assetstool)
|
||||
add_subdirectory(copytool)
|
||||
add_subdirectory(glsltool)
|
19
tools/assetstool/CMakeLists.txt
Normal file
19
tools/assetstool/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
||||
|
||||
add_custom_target(duskassets
|
||||
COMMAND
|
||||
${Python3_EXECUTABLE}
|
||||
${DUSK_TOOLS_DIR}/assetstool/assetstool.py
|
||||
--input=${DUSK_ASSETS_BUILD_DIR}
|
||||
--output=${DUSK_BUILD_DIR}/dusk.tar
|
||||
COMMENT "Bundling assets..."
|
||||
USES_TERMINAL
|
||||
DEPENDS ${DUSK_ASSETS}
|
||||
)
|
||||
|
||||
add_dependencies(${DUSK_TARGET_NAME} duskassets)
|
67
tools/assetstool/assetstool.py
Executable file
67
tools/assetstool/assetstool.py
Executable file
@ -0,0 +1,67 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
import os
|
||||
import tarfile
|
||||
import argparse
|
||||
|
||||
# Args
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Bundles all assets into the internal archive format.'
|
||||
)
|
||||
parser.add_argument('-i', '--input');
|
||||
parser.add_argument('-o', '--output');
|
||||
args = parser.parse_args()
|
||||
|
||||
# Ensure the directory for the output path exists
|
||||
if not os.path.exists(os.path.dirname(args.output)):
|
||||
os.makedirs(os.path.dirname(args.output))
|
||||
|
||||
# Create a ZIP archive and add the specified directory
|
||||
# archive = tarfile.open(args.output, 'w:bz2') # BZ2 Compression
|
||||
|
||||
# Does the archive already exist?
|
||||
filesInArchive = []
|
||||
|
||||
if os.path.exists(args.output) and False:
|
||||
# if os.path.exists(args.output):
|
||||
# Yes, open it
|
||||
archive = tarfile.open(args.output, 'a:')
|
||||
|
||||
# Get all the files in the archive
|
||||
for member in archive.getmembers():
|
||||
filesInArchive.append(member.name)
|
||||
|
||||
archive.close()
|
||||
|
||||
# Open archive for appending.
|
||||
archive = tarfile.open(args.output, 'a:')
|
||||
else:
|
||||
# No, create it
|
||||
archive = tarfile.open(args.output, 'w:')
|
||||
|
||||
# Add all files in the input directory
|
||||
for foldername, subfolders, filenames in os.walk(args.input):
|
||||
for filename in filenames:
|
||||
|
||||
# Is the file already in the archive?
|
||||
absolute_path = os.path.join(foldername, filename)
|
||||
relative_path = os.path.relpath(absolute_path, args.input)
|
||||
|
||||
if relative_path in filesInArchive:
|
||||
if relative_path.endswith('.texture'):
|
||||
print(f"Skipping {filename}...")
|
||||
continue
|
||||
else:
|
||||
print(f"Overwriting {filename}...")
|
||||
# Does not work in python, throw error
|
||||
exit (1)
|
||||
else:
|
||||
print(f"Archiving asset {filename}...")
|
||||
|
||||
archive.add(absolute_path, arcname=relative_path)
|
||||
|
||||
# Close the archive
|
||||
archive.close()
|
16
tools/copytool/CMakeLists.txt
Normal file
16
tools/copytool/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(copytool file)
|
||||
set(TARGET_NAME "copytool_${file}")
|
||||
|
||||
# Replace slashes with underscores
|
||||
string(REPLACE "/" "_" TARGET_NAME ${TARGET_NAME})
|
||||
|
||||
add_custom_target(${TARGET_NAME}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${DUSK_ASSETS_DIR}/${file} ${DUSK_ASSETS_BUILD_DIR}/${file}
|
||||
)
|
||||
add_dependencies(duskassets ${TARGET_NAME})
|
||||
endfunction()
|
45
tools/glsltool/CMakeLists.txt
Normal file
45
tools/glsltool/CMakeLists.txt
Normal file
@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Path to the CMake script for converting GLSL to header
|
||||
set(DUSK_GLSL_TOOL_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/glsltool.cmake CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
|
||||
# GLSL to C-code
|
||||
function(glsltool GLSL_FILE)
|
||||
get_filename_component(GLSL_FILE_NAME_WE ${GLSL_FILE} NAME_WE)
|
||||
set(GLSL_SOURCE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
|
||||
set(GLSL_FILE_ABSOLUTE ${GLSL_SOURCE_DIRECTORY}/${GLSL_FILE})
|
||||
set(GLSL_FILE_PATH ${CMAKE_CURRENT_LIST_DIR}/${GLSL_FILE})
|
||||
set(GLSL_FILE_HEADER ${DUSK_GENERATED_HEADERS_DIR}/${GLSL_FILE}.h)
|
||||
set(GLSL_MISSING_FILE ${DUSK_GENERATED_HEADERS_DIR}/missing_${GLSL_FILE}.h)
|
||||
|
||||
# Ensure the generated files are recompiled
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${GLSL_FILE_HEADER}
|
||||
${GLSL_MISSING_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${DUSK_GENERATED_HEADERS_DIR}
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DGLSL_FILE_ABSOLUTE=${GLSL_FILE_ABSOLUTE}
|
||||
-DGLSL_FILE_HEADER=${GLSL_FILE_HEADER}
|
||||
-DGLSL_FILE_NAME_WE=${GLSL_FILE_NAME_WE}
|
||||
-DGLSL_SOURCE_DIRECTORY=${GLSL_SOURCE_DIRECTORY}
|
||||
-P ${DUSK_GLSL_TOOL_SCRIPT}
|
||||
DEPENDS ${GLSL_FILE_PATH}
|
||||
COMMENT "Converting ${GLSL_FILE} to header"
|
||||
)
|
||||
|
||||
# Trick to always run the command
|
||||
add_custom_target(GLSL_TOOL_ALWAYS_RUN_${GLSL_FILE}
|
||||
ALL
|
||||
DEPENDS
|
||||
${GLSL_MISSING_FILE}
|
||||
${GLSL_FILE_HEADER}
|
||||
)
|
||||
|
||||
add_dependencies(${DUSK_TARGET_NAME}
|
||||
GLSL_TOOL_ALWAYS_RUN_${GLSL_FILE}
|
||||
)
|
||||
endfunction()
|
36
tools/glsltool/glsltool.cmake
Normal file
36
tools/glsltool/glsltool.cmake
Normal file
@ -0,0 +1,36 @@
|
||||
file(READ ${GLSL_FILE_ABSOLUTE} GLSL_FILE_CONTENTS)
|
||||
|
||||
set(INCLUDED_FILES)
|
||||
|
||||
function(resolve_includes CONTENTS OUTPUT)
|
||||
string(REGEX MATCHALL "#include \"([^\"]+)\"" INCLUDES "${CONTENTS}")
|
||||
|
||||
foreach(INCLUDE ${INCLUDES})
|
||||
string(REGEX REPLACE "#include \"([^\"]+)\"" "\\1" INCLUDE_FILE ${INCLUDE})
|
||||
get_filename_component(INCLUDE_FILE_ABSOLUTE ${GLSL_SOURCE_DIRECTORY}/${INCLUDE_FILE} ABSOLUTE)
|
||||
list(FIND INCLUDED_FILES ${INCLUDE_FILE_ABSOLUTE} INCLUDE_FILE_INDEX)
|
||||
|
||||
if(INCLUDE_FILE_INDEX EQUAL -1)
|
||||
list(APPEND INCLUDED_FILES ${INCLUDE_FILE_ABSOLUTE})
|
||||
file(READ ${INCLUDE_FILE_ABSOLUTE} INCLUDED_FILE_CONTENTS)
|
||||
resolve_includes("${INCLUDED_FILE_CONTENTS}" RESOLVED_CONTENTS)
|
||||
string(REPLACE "${INCLUDE}" "${RESOLVED_CONTENTS}" CONTENTS "${CONTENTS}")
|
||||
else()
|
||||
string(REPLACE "${INCLUDE}" "" CONTENTS "${CONTENTS}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(${OUTPUT} "${CONTENTS}" PARENT_SCOPE)
|
||||
set(INCLUDED_FILES ${INCLUDED_FILES} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
list(APPEND INCLUDED_FILES ${GLSL_FILE_ABSOLUTE})
|
||||
resolve_includes("${GLSL_FILE_CONTENTS}" RESOLVED_GLSL_FILE_CONTENTS)
|
||||
|
||||
# Convert to C string
|
||||
string(REPLACE "\"" "\\\"" RESOLVED_GLSL_FILE_CONTENTS "${RESOLVED_GLSL_FILE_CONTENTS}")
|
||||
string(REPLACE "\n" "\\n\"\n\"" RESOLVED_GLSL_FILE_CONTENTS "${RESOLVED_GLSL_FILE_CONTENTS}")
|
||||
set(RESOLVED_GLSL_FILE_CONTENTS "\"${RESOLVED_GLSL_FILE_CONTENTS}\\n\"")
|
||||
|
||||
# Write to header file
|
||||
file(WRITE ${GLSL_FILE_HEADER} "const char* ${GLSL_FILE_NAME_WE}ShaderSource = ${RESOLVED_GLSL_FILE_CONTENTS};")
|
Reference in New Issue
Block a user