Skip to content
Snippets Groups Projects
Commit 6e06a58a authored by Bastian's avatar Bastian
Browse files

base commit vulkan_rtx

parent 9e8f609a
No related branches found
No related tags found
No related merge requests found
Showing
with 3560 additions and 0 deletions
/BUILD_*/
/INSTALL_*/
*~
*.bak
/resources
CMakeLists.txt.user
/Win32
.vs
.idea
src/config
/cmake-build-*
/build*
clion_*
src/cmake-*
\ No newline at end of file
#!/usr/bin/env python3
# Adapted from https://github.com/SaschaWillems/Vulkan
import sys
from urllib.request import urlretrieve
from zipfile import ZipFile
import os
assets = [
['https://cloud.uni-koblenz-landau.de/s/s65MCEfZiqB3jZm/download','bunny.zip', 'bunny'],
['https://cloud.uni-koblenz-landau.de/s/TTTnfsFcDzicweY/download','vokselia_spawn.zip','vokselia_spawn'],
['https://cloud.uni-koblenz-landau.de/s/STiTAAJACSFrn4R/download','monkey_uv.zip','monkey_uv'],
['https://cloud.uni-koblenz-landau.de/s/ZE7d9Gs25Gorwke/download','cvteapot.zip','cvteapot'],
]
def reporthook(blocknum, blocksize, totalsize):
bytesread = blocknum * blocksize
if totalsize > 0:
percent = bytesread * 1e2 / totalsize
s = "\r%5.1f%% (%*d / %d bytes)" % (percent, len(str(totalsize)), bytesread, totalsize)
sys.stderr.write(s)
if bytesread >= totalsize:
sys.stderr.write("\n")
else:
sys.stderr.write("read %d\n" % (bytesread,))
download_directory = "./resources/download/"
os.makedirs(download_directory)
for asset in assets:
ASSET_PACK_URL = asset[0]
ASSET_PACK_FILE_NAME = download_directory + asset[1]
print("Downloading asset from '%s'" % ASSET_PACK_URL)
urlretrieve(ASSET_PACK_URL, ASSET_PACK_FILE_NAME, reporthook)
print("Download finished")
print("Extracting assets")
zip = ZipFile(ASSET_PACK_FILE_NAME, 'r')
zip.extractall("./resources/%s" % asset[2])
zip.close()
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...
cmake_minimum_required(VERSION 3.11)
project(framework)
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
IF (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
# Allows find scripts to automatically search in environment variables LIBNAME_ROOT
cmake_policy(SET CMP0074 NEW)
ENDIF ()
# Determine if 64 Bit build
if ("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
SET(BUILD_TYPE_64_BIT true)
endif ()
if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
SET(BUILD_TYPE_64_BIT true)
endif ()
if (CMAKE_CL_64)
SET(BUILD_TYPE_64_BIT true)
endif ()
IF (BUILD_TYPE_64_BIT)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
ENDIF ()
include(ProjectSetup)
\ No newline at end of file
cmake_minimum_required(VERSION 3.17)
get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
project(${ProjectId})
# Enables the CMake policy to use environment variables {LIBNAME}_ROOT to search for libraries
EnableCmakeLibEnvironmentRoot()
# Creates an executable from all source and header files in the current directory
# This will also find all dependencies specified in the depdencies.txt and
# link them privately
CreateExecutable(${ProjectId})
set_property(TARGET ${ProjectId} PROPERTY CXX_STANDARD 20)
# Add default dependencies with private visibility, since it is an executable
AddDefaultDependencies(${ProjectId} PRIVATE)
\ No newline at end of file
cmake_minimum_required(VERSION 3.17)
get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
project(${ProjectId})
# Enables the CMake policy to use environment variables {LIBNAME}_ROOT to search for libraries
EnableCmakeLibEnvironmentRoot()
# Creates a library from all source and header files in the current directory
# This will also find all dependencies specified in the depdencies.txt and
# link them publicly
# If it is a header only library, an interface library is created so that cmake
# can process it correctly. In that case IS_INTERFACE is set to true. Further
# linking can use that information accordingly
CreateLibrary(${ProjectId} IS_INTERFACE)
set_property(TARGET ${ProjectId} PROPERTY CXX_STANDARD 20)
# Add default dependencies. Visibility is set whether we are dealing with a
# normal or a header only library
IF (${IS_INTERFACE})
AddDefaultDependencies(${ProjectId} INTERFACE)
ELSE ()
AddDefaultDependencies(${ProjectId} PRIVATE)
ENDIF ()
This diff is collapsed.
string(REPLACE "/" ";" p2list "${CMAKE_SOURCE_DIR}")
string(REPLACE "\\" ";" p2list "${p2list}")
list(REVERSE p2list)
list(GET p2list 0 first)
list(GET p2list 1 ProjectId)
string(REPLACE " " "_" ProjectId ${ProjectId})
message("Project: ${ProjectId}")
# should set the required cpp11 compiler options
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(${ProjectId})
SET(PROJECT_ROOT_DIR ${CMAKE_BINARY_DIR})
SET(PROJECT_RUNTIME_LIBRARIES)
# Create paths config file if it does not exist
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/config/config.json)
MESSAGE("Creating new config file")
FILE(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/config/)
FILE(WRITE ${CMAKE_SOURCE_DIR}/config/config.json "{\n\t\"resources\": \"${CMAKE_SOURCE_DIR}/../resources\",\n\t\"shaders\": \"${CMAKE_SOURCE_DIR}/shaders\"\n}")
ENDIF ()
# Workaround to always copy config files
add_custom_target(COPY_CONFIG_FILES
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/__copy_config
)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/__copy_config
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/bin/
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/config/ ${PROJECT_BINARY_DIR}/bin/config/
COMMAND echo "Copying config"
)
MACRO(REQUIRE_CONFIG targetName)
add_dependencies(${targetName} COPY_CONFIG_FILES)
ENDMACRO()
MACRO(REQUIRE_CONFIG_CUR_DIR)
GetDirProjectName(targetName)
add_dependencies(${targetName} COPY_CONFIG_FILES)
ENDMACRO()
# Special target for MSVC so cmake files show up in the ide...
if (MSVC)
file(GLOB_RECURSE CUSTOM_CMAKE_FILES cmake/* RELATIVE_PATH)
add_custom_target(cmake_sources SOURCES ${CUSTOM_CMAKE_FILES})
IF (EXISTS ${CMAKE_SOURCE_DIR}/config)
file(GLOB_RECURSE CONFIG_FILES ${CMAKE_SOURCE_DIR}/config RELATIVE_PATH)
add_custom_target(config_sources SOURCES ${CONFIG_FILES})
ENDIF ()
endif ()
include(macros)
include(projectTools)
# Process additional project specific dependencies
IF (EXISTS ${CMAKE_SOURCE_DIR}/cmake/projectDefaultsPre.cmake)
include(projectDefaultsPre)
ENDIF ()
SET(OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
## Old variables for visual studio to pick up...
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib)
add_custom_target(COPY_RUNTIME_FILES)
# Copy all resources before build
# This assures changed files will be copied...
IF (PROJECT_RUNTIME_LIBRARIES)
add_custom_command(TARGET COPY_RUNTIME_FILES PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/bin/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_RUNTIME_LIBRARIES} ${PROJECT_BINARY_DIR}/bin)
ENDIF ()
FILE(GLOB_RECURSE ALL_SHADERS RELATIVE ${CMAKE_SOURCE_DIR}/shaders RELATIVE ${CMAKE_SOURCE_DIR}/shaders ${CMAKE_SOURCE_DIR}/shaders/*)
LIST(FILTER ALL_SHADERS EXCLUDE REGEX .*[.]vs.*)
LIST(FILTER ALL_SHADERS EXCLUDE REGEX .*CMakeLists[.]txt)
MACRO(GENERATE_PACKAGES result curdir)
IF (EXISTS ${curdir}/.ignore)
MESSAGE("Skipping ${curdir}")
ELSEIF (EXISTS ${curdir}/CMakeLists.txt)
SET(${result} ${${result}} ${curdir})
message("ADD PROJECT: ${curdir}")
add_subdirectory(${curdir})
ELSE ()
IF (IS_DIRECTORY ${curdir})
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
FOREACH (child ${children})
IF (IS_DIRECTORY ${curdir}/${child})
GENERATE_PACKAGES(${result} ${curdir}/${child})
ENDIF ()
ENDFOREACH ()
ENDIF ()
ENDIF ()
ENDMACRO()
FILE(GLOB startDirList RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/*)
FOREACH (dir ${startDirList})
GENERATE_PACKAGES(projects ${CMAKE_SOURCE_DIR}/${dir})
ENDFOREACH ()
IF (NOT CMAKE_EXTRA_GENERATOR MATCHES "Eclipse CDT4")
add_custom_target(RERUN_CMAKE
COMMAND cmake ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${PROJECT_ROOT_DIR}
)
ENDIF ()
# Process additional project post
IF (EXISTS ${CMAKE_SOURCE_DIR}/cmake/projectDefaultsPost.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/projectDefaultsPost.cmake)
ENDIF ()
# Do not install config, such that local files will be used
\ No newline at end of file
#-- Add an Option to toggle the generation of the API documentation
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
if(BUILD_DOCUMENTATION)
FIND_PACKAGE(Doxygen)
if (NOT DOXYGEN_FOUND)
message(
"Doxygen is needed to build the documentation. Please install it correctly")
else()
#-- Configure the Template Doxyfile for our specific project
configure_file(${CMAKE_MODULE_PATH}/Doxyfile.in
${PROJECT_BINARY_DIR}/Doxyfile @ONLY IMMEDIATE)
#-- Add a custom target to run Doxygen when ever the project is built
add_custom_target (Docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
# IF you do NOT want the documentation to be generated EVERY time you build the project
# then leave out the 'ALL' keyword from the above command.
endif()
endif()
\ No newline at end of file
FILE(GLOB children RELATIVE ${EXTERNAL_DIR} ${EXTERNAL_DIR}/*)
FOREACH(child ${children})
IF(IS_DIRECTORY ${EXTERNAL_DIR}/${child})
IF (NOT ${child} MATCHES "\\..*")
if(EXISTS ${EXTERNAL_DIR}/${child}/.git)
MESSAGE("Pull repository in package: ${child}")
execute_process(COMMAND git pull WORKING_DIRECTORY ${EXTERNAL_DIR}/${child})
ENDIF()
ENDIF()
ENDIF()
ENDFOREACH()
# Checks whether a given path is in the extern source directory reserved for git repositories.
# result will be TRUE, if it is external, FALSE otherwise
MACRO(IS_PATH_IN_EXTERNAL path result)
FILE(RELATIVE_PATH relpath ${CMAKE_SOURCE_DIR} ${path})
STRING(FIND ${relpath} "extern/" index)
IF(${index} EQUAL 0)
SET(${result} TRUE)
ELSE()
SET(${result} FALSE)
ENDIF()
ENDMACRO()
# Checks whether a given package is in the extern source directory reserved for git repositories.
# result will be TRUE, if it is external, FALSE otherwise
MACRO(IS_PACKAGE_EXTERNAL name result)
GET_PACKAGE_DIR(${name} pdir)
IS_PATH_IN_EXTERNAL(${pdir} ${result})
ENDMACRO()
# Add all custom definitions to the current target
MACRO(ADD_CUSTOM_DEFINITIONS targetname visibility)
FOREACH(d ${CUSTOM_DEFINITIONS})
target_compile_options(${targetname} ${visibility} ${d})
ENDFOREACH()
ENDMACRO()
# Filters libs for all dynamic libraries
MACRO(GET_SHARED_LIBS_FROM_LIST libs result)
FOREACH(l ${${libs}})
IF(${l} MATCHES "(.*\\.dll)|(.*\\.so)|(.*\\.dylib)$")
LIST(APPEND ${result} ${l})
ENDIF()
ENDFOREACH()
ENDMACRO()
# Copies all runtime libraries to the binary directory
# Custom runtime libraries can be added to the PROJECT_RUNTIME_LIBRARIES variable
MACRO(COPY_RUNTIME_TO_BINARY)
IF (${CMAKE_EXTRA_GENERATOR} MATCHES "Eclipse CDT4")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
${PROJECT_BINARY_DIR}/bin/
)
FOREACH(l ${PROJECT_RUNTIME_LIBRARIES})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${l}
${PROJECT_BINARY_DIR}/bin/
)
ENDFOREACH()
ELSEIF (MSVC)
FOREACH(l ${PROJECT_RUNTIME_LIBRARIES})
FOREACH (CONFIGURATION_TYPE ${CMAKE_CONFIGURATION_TYPES})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
${PROJECT_BINARY_DIR}/bin/${CONFIGURATION_TYPE}/
)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
${l}
${PROJECT_BINARY_DIR}/bin/${CONFIGURATION_TYPE}/
)
ENDFOREACH()
ENDFOREACH()
ENDIF ()
ENDMACRO()
# Reads a dependency file at the given path
# names will contain the dependency package names
# urls will contain the optional GIT urls. If a dependency does not have a URL, the corresponding entry in the list will be "EMPTY"
MACRO(READ_DEPENDENCY_FILE path names urls)
SET(${names} "")
SET(${urls} "")
IF(EXISTS ${path})
FILE(READ ${path} local_dependencies_raw)
STRING(REGEX REPLACE "\n" ";" local_dependencies_raw "${local_dependencies_raw}")
FOREACH(dep ${local_dependencies_raw})
IF(NOT "${dep}" MATCHES "^%")
STRING(STRIP "${dep}" newDep)
STRING(REGEX REPLACE " " ";" splitDep "${newDep}")
LIST(LENGTH splitDep entryLength)
SET(libURL "EMPTY")
LIST(GET splitDep 0 libName)
IF(${entryLength} GREATER 1)
LIST(GET splitDep 1 libURL)
ENDIF()
LIST(APPEND ${names} ${libName})
LIST(APPEND ${urls} ${libURL})
ENDIF()
ENDFOREACH()
ENDIF()
ENDMACRO()
# Splits a seperated string and stores the resulting list in result
MACRO(SEPERATED_STRING_TO_LIST result)
set (str ${ARGN})
IF(NOT str)
SET(${result} "")
ELSE()
string(REPLACE "??" ";" ${result} "${str}")
ENDIF()
ENDMACRO()
# Converts a list to a string with seperators
MACRO(LIST_TO_SEPERATED_STRING result)
set (ls ${ARGN})
IF(NOT ls)
SET(${result} "")
ELSE()
string(REPLACE ";" "??" ${result} "${ls}")
ENDIF()
ENDMACRO()
MACRO(VALIADATE_PATH result)
set( pathlist "${ARGN}" )
FOREACH(currentpath ${pathlist})
IF(EXISTS ${currentpath})
SET(${result} ${currentpath} CACHE PATH "Project specific path. Set manually if it was not found.")
message("${result} FOUND AT ${currentpath}")
ENDIF()
ENDFOREACH()
IF (NOT ${result})
SET(${result} "PATH-NOTFOUND" CACHE PATH "Project specific path. Set manually if it was not found.")
message("ERROR: ${result} NOT FOUND")
ENDIF ()
ENDMACRO()
# Prints a list of entries with a title
MACRO(PRINT_LIST title l)
LIST(LENGTH ${l} len)
MESSAGE(STATUS "${title} (${len}):")
FOREACH(ll ${${l}})
MESSAGE(STATUS "\t-${ll}")
ENDFOREACH()
ENDMACRO()
# Prints a list of entries with a title if it is not empty
MACRO(PRINT_LIST_NON_EMPTY title l)
LIST(LENGTH ${l} len)
IF(NOT ${len} EQUAL 0)
MESSAGE(STATUS "${title} (${len}):")
FOREACH(ll ${${l}})
MESSAGE(STATUS "\t-${ll}")
ENDFOREACH()
ENDIF()
ENDMACRO()
# some functions (like printf) result in warnings in VS. Calm these warnings:
LIST(APPEND CUSTOM_DEFINITIONS "-D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_DEBUG_POSTFIX "-d")
set(DEFAULT_INCLUDES
)
#Find runtime dependencies
if(EXISTS ${CMAKE_SOURCE_DIR}/../resources)
# copy resources
install(DIRECTORY ${CMAKE_SOURCE_DIR}/../resources DESTINATION bin)
ENDIF()
# copy all found runtime libraries
install(FILES ${PROJECT_RUNTIME_LIBRARIES} DESTINATION bin)
GET_SHARED_LIBS_FROM_LIST(PROJECT_RUNTIME_LIBRARIES sharedLibs)
install(FILES ${sharedLibs} DESTINATION bin)
# Enables the CMake policy to use environment variables {LIBNAME}_ROOT to search for libraries
MACRO(EnableCmakeLibEnvironmentRoot)
IF (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
# Allows find scripts to automatically search in environment variables LIBNAME_ROOT
cmake_policy(SET CMP0074 NEW)
ENDIF ()
ENDMACRO()
MACRO(GetDirProjectName PROJECT_NAME)
get_filename_component(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" ${PROJECT_NAME} ${${PROJECT_NAME}})
ENDMACRO()
# Finds all project files in the current directory recursively and stores them in the given variables
# Dependencies listed in the depdencies.txt file are also added
MACRO(GatherProjectFiles SOURCES HEADER HEADER_IMPLEMENTATION ADDITIONAL_FIILES DEPENDENCIES)
file(GLOB_RECURSE ${SOURCES} *.cpp *.c *.cc RELATIVE_PATH)
file(GLOB_RECURSE ${HEADER} *.h *.hpp RELATIVE_PATH)
file(GLOB_RECURSE ${HEADER_IMPLEMENTATION} *.inl *.icc *.hcc RELATIVE_PATH)
file(GLOB_RECURSE ${ADDITIONAL_FIILES} *.txt RELATIVE_PATH)
FOREACH (a ${ADDITIONAL_FIILES})
SET_SOURCE_FILES_PROPERTIES(${a} PROPERTIES HEADER_FILE_ONLY TRUE)
ENDFOREACH ()
FOREACH (a ${HEADER_IMPLEMENTATION})
SET_SOURCE_FILES_PROPERTIES(${a} PROPERTIES HEADER_FILE_ONLY TRUE)
ENDFOREACH ()
READ_DEPENDENCY_FILE("${CMAKE_CURRENT_SOURCE_DIR}/dependencies.txt" ${DEPENDENCIES} urls)
LIST(FILTER ${DEPENDENCIES} EXCLUDE REGEX "EMPTY")
ENDMACRO()
# Adds default dependencies given by the variables DEFAULT_INCLUDES and DEFAULT_LIBS
# to the given target with a specified visibility
MACRO(AddDefaultDependencies targetName visibility)
target_include_directories(
${targetName} ${visibility}
${DEFAULT_INCLUDES}
)
# link with all dependencies
target_link_libraries(
${targetName} ${visibility}
${DEFAULT_LIBS}
)
ENDMACRO()
# Creates an executable with the given name for the current directory
# This will find all source files and dependencies, create an executable
# with add_executable and then link the dependencies
MACRO(CreateExecutable executableName)
GatherProjectFiles(SOURCES HEADER HEADER_IMPLEMENTATION ADDITIONAL_FIILES DEPENDENCIES)
add_executable(${executableName} ${SOURCES} ${HEADER} ${ADDITIONAL_FIILES} ${HEADER_IMPLEMENTATION})
# link with all dependencies
target_link_libraries(
${executableName}
PRIVATE
${DEPENDENCIES}
)
# First line is a hack since visual studio binary directories and different working directory messes things up
set_target_properties(${executableName}
PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${OUTPUT_DIRECTORY}/bin"
CXX_STANDARD 17
)
target_compile_features(${executableName} PUBLIC cxx_std_17)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(${executableName} PUBLIC
"$<$<CONFIG:Debug>:/bigobj>"
)
else ()
target_compile_options(${executableName} PUBLIC
"$<$<CONFIG:Debug>:-Wa,-mbig-obj>"
)
endif ()
add_dependencies(${executableName} COPY_RUNTIME_FILES)
ADD_CUSTOM_DEFINITIONS(${executableName} PRIVATE)
install(TARGETS ${executableName} DESTINATION bin)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(${executableName} PUBLIC
-static
-static-libgcc -static-libstdc++
)
endif ()
ENDMACRO()
# Creates a library with the given name for the current directory
# This will find all source files and dependencies, create a library
# with add_library and then link the dependencies and add them to the public interface.
# In the case of header only libraries an interface library is created and IS_INTERFACE
# is set to TRUE, otherwise to FALSE
MACRO(CreateLibrary libraryName IS_INTERFACE)
GatherProjectFiles(SOURCES HEADER HEADER_IMPLEMENTATION ADDITIONAL_FIILES DEPENDENCIES)
IF (SOURCES)
SET(${IS_INTERFACE} FALSE)
add_library(${libraryName} ${SOURCES} ${HEADER} ${ADDITIONAL_FIILES} ${HEADER_IMPLEMENTATION})
target_link_libraries(
${libraryName}
PUBLIC
${DEPENDENCIES}
)
target_include_directories(${libraryName} PUBLIC
${DEFAULT_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}/include/
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
ADD_CUSTOM_DEFINITIONS(${libraryName} PRIVATE)
set_target_properties(${libraryName}
PROPERTIES
CXX_STANDARD 17
)
target_compile_features(${libraryName} PUBLIC cxx_std_17)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(${libraryName} PUBLIC
"$<$<CONFIG:Debug>:/bigobj>"
)
else ()
target_compile_options(${libraryName} PUBLIC
"$<$<CONFIG:Debug>:-Wa,-mbig-obj>"
)
endif ()
ELSEIF (HEADER)
SET(${IS_INTERFACE} TRUE)
# In case of a header only library, only make the files show up in the IDE (Only for MSVC?)
if (MSVC)
add_custom_target(${libraryName}_sources SOURCES ${HEADER} ${ADDITIONAL_FIILES} ${HEADER_IMPLEMENTATION})
endif ()
add_library(${libraryName} INTERFACE)
#target_compile_definitions(${libraryName} INTERFACE ${ProjectId}=1)
target_include_directories(${libraryName}
INTERFACE
${local_includes}
${DEFAULT_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}/include/
)
target_link_libraries(${libraryName} INTERFACE ${project_dependencies})
target_sources(${libraryName} INTERFACE
${HEADER}
${ADDITIONAL_FIILES}
${HEADER_IMPLEMENTATION}
)
target_compile_features(${libraryName} INTERFACE cxx_std_17)
ENDIF ()
IF (SOURCES)
# Library output
install(TARGETS ${ProjectId}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
# Include dirs for headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include
FILES_MATCHING PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "*.inl")
ENDIF ()
ENDMACRO()
\ No newline at end of file
#include "AttributeData.h"
AttributeData::AttributeData(const AttributeData& other) {
m_wrapper = other.m_wrapper->copy();
m_components = other.m_components;
m_type = other.m_type;
}
AttributeData& AttributeData::operator=(const AttributeData& other) {
if (&other == this) {
return *this;
}
m_wrapper = other.m_wrapper->copy();
m_components = other.m_components;
m_type = other.m_type;
return *this;
}
AttributeData& AttributeData::operator=(AttributeData&& other) noexcept {
if (&other == this) {
return *this;
}
m_wrapper = std::move(other.m_wrapper);
m_components = other.m_components;
m_type = other.m_type;
return *this;
}
AttributeData::AttributeData(AttributeData&& other) noexcept {
m_wrapper = std::move(other.m_wrapper);
m_components = other.m_components;
m_type = other.m_type;
}
AttributeData::~AttributeData() = default;
size_t AttributeData::components() const { return m_components; }
size_t AttributeData::stride() const { return m_wrapper->element_stride(); }
size_t AttributeData::byte_size() const { return m_wrapper->byte_size(); }
size_t AttributeData::size() const { return byte_size() / stride(); }
AttributeComponentType AttributeData::component_type() const { return m_type; }
const void* AttributeData::data() const { return m_wrapper->data(); }
void AttributeData::copy_to(int start_idx, int num, int destination_idx,
AttributeData& other) {
m_wrapper->copy_to(start_idx, num, destination_idx, *other.m_wrapper);
}
void AttributeData::resize(int num) { m_wrapper->resize(num); }
std::unique_ptr<AttributeData> AttributeData::copy() const {
return std::make_unique<AttributeData>(*this);
}
size_t AttributeData::component_size() const {
return m_wrapper->element_size();
}
#ifndef VULKAN_RTX_ATTRIBUTE_DATA_H_
#define VULKAN_RTX_ATTRIBUTE_DATA_H_
#include <glm/glm.hpp>
#include <memory>
#include <vector>
/**
* Supported Types for Attribute components
* Custom types will use other
*/
enum class AttributeComponentType {
DOUBLE,
FLOAT,
BYTE,
UNSIGNED_BYTE,
SHORT,
UNSIGNED_SHORT,
INTEGER,
UNSIGNED_INTEGER,
OTHER
};
/**
* @class AttributeData
* @brief Contains data to use as a vertex attribute.
* Attribute data does not have mixed types.
*/
class AttributeData {
public:
template <typename T> static AttributeData create(int size = 0);
/**
* @brief Constructs new attribute data by copying values
* Values stored in the given data are assumed to have 1 component
* @tparam The data type. This should be one of the primitive types used in
* OpenGL
* @param The input data
*/
template <typename T> explicit AttributeData(std::vector<T> values);
/**
* @brief Constructs new attribute data by copying values
* Specialized version to take care of vector parameters
* @tparam L The dimensionality of the vector
* @tparam T The underlying vector type
* @tparam P The vector's precision
*
*/
template <glm::length_t L, typename T, glm::precision P>
explicit AttributeData(std::vector<glm::vec<L, T, P>> values);
AttributeData(const AttributeData& other);
AttributeData(AttributeData&& other) noexcept;
AttributeData& operator=(const AttributeData& other);
AttributeData& operator=(AttributeData&& other) noexcept;
~AttributeData();
/**
* Returns the number of components of elements
* @returns The number of components
*/
[[nodiscard]] size_t components() const;
/**
* Returns the stride of the elements in bytes
* @returns The stride
*/
[[nodiscard]] size_t stride() const;
/**
* Returns the stride of the elements in bytes
* @returns The stride
*/
[[nodiscard]] size_t component_size() const;
/**
* Returns the size of the contained data in bytes
* @returns The size in bytes
*/
[[nodiscard]] size_t byte_size() const;
/**
* Returns the number of elements contained
* This corresponds to byteSize()/stride()
* @returns The number of elements
*/
[[nodiscard]] size_t size() const;
/**
* The underlying type of data
* @params The underlying data type
*/
[[nodiscard]] AttributeComponentType component_type() const;
/**
* Checks whether the data is of a specified type
* @tparam T The type to check for
* @returns True, if the data is of type T, false otherwise
*/
template <typename T> [[nodiscard]] bool is_type() const;
/**
* Pointer to the data
* @returns A pointer to the contained data
*/
[[nodiscard]] const void* data() const;
/**
* Accessor for the values.
* If the given type does not match the contained type, this will result in
* illegal access
* @tparam T The type for the values
* @returns A reference to the contained values. This will stay valid, as
* long as this object exists
*/
template <typename T> std::vector<T>& values();
void copy_to(int start_idx, int num, int destination_idx,
AttributeData& other);
void resize(int num);
std::unique_ptr<AttributeData> copy() const;
/**
* Const-Accessor for the values.
* If the given type does not match the contained type, this will result in
* illegal access
* @tparam T The type for the values
* @returns A reference to the contained values. This will stay valid, as
* long as this object exists
*/
template <typename T> const std::vector<T>& values() const;
private:
AttributeComponentType m_type;
size_t m_components;
template <typename T> static AttributeComponentType determine_stream_type();
class AbstractDataWrapper;
template <typename T> class DataWrapper;
std::unique_ptr<AbstractDataWrapper> m_wrapper;
class AbstractDataWrapper {
public:
AbstractDataWrapper() = default;
virtual ~AbstractDataWrapper() = default;
template <typename T> DataWrapper<T>* as();
[[nodiscard]] virtual const void* data() const = 0;
[[nodiscard]] virtual size_t byte_size() const = 0;
[[nodiscard]] virtual size_t element_size() const = 0;
[[nodiscard]] virtual size_t element_stride() const = 0;
[[nodiscard]] virtual std::unique_ptr<AbstractDataWrapper>
copy() const = 0;
[[nodiscard]] virtual int type_id() const = 0;
virtual void copy_to(int start_idx, int num, int destination_idx,
AbstractDataWrapper& other) = 0;
virtual void resize(int num) = 0;
protected:
};
template <typename T> class DataWrapper : public AbstractDataWrapper {
public:
void copy_to(int start_idx, int num, int destination_idx,
AbstractDataWrapper& other) override;
void resize(int num) override;
[[nodiscard]] int type_id() const override;
~DataWrapper() override = default;
explicit DataWrapper(const std::vector<T>& data);
explicit DataWrapper(std::vector<T>&& data);
DataWrapper() = default;
std::vector<T>& values();
size_t element_stride() const override;
const std::vector<T>& values() const;
[[nodiscard]] const void* data() const override;
[[nodiscard]] size_t byte_size() const override;
[[nodiscard]] size_t element_size() const override;
[[nodiscard]] std::unique_ptr<AbstractDataWrapper>
copy() const override;
private:
std::vector<T> m_values;
};
};
#include "detail/AttributeData.inl"
#endif // VULKAN_RTX_ATTRIBUTE_DATA_H_
cmake_minimum_required (VERSION 3.1)
include(DefaultExecutable)
REQUIRE_CONFIG_CUR_DIR()
add_dependencies(${ProjectId} Shaders_Spirv)
\ No newline at end of file
#include "Camera.h"
#include <glm/gtc/matrix_transform.hpp>
#include <cmath>
const glm::vec3& Camera::get_position() const { return m_pos; }
void Camera::set_position(const glm::vec3& pos) { m_pos = pos; }
const glm::vec3& Camera::get_forward() const { return m_forward; }
const glm::vec3& Camera::get_up() const { return m_up; }
const glm::vec3& Camera::get_right() const { return m_right; }
void Camera::update(const CameraUpdateParams& params) {
if (!m_prev_mouse_pressed) {
m_prev_mouse = params.mouse_pos;
}
m_prev_mouse_pressed = params.mouse_pressed;
auto delta = params.mouse_pos - m_prev_mouse;
m_prev_mouse = params.mouse_pos;
delta *= m_sensitivity;
delta *= glm::vec2(2.0f * glm::pi<float>(), glm::pi<float>());
constexpr float theta_border = glm::radians(2.0f);
m_phi -= delta.x;
m_theta += (m_invert_y ? -1.0f : 1.0f) * delta.y;
m_theta =
glm::clamp(m_theta, theta_border, glm::pi<float>() - theta_border);
float update_speed = params.dt * m_speed;
if (params.speed_up) {
update_speed *= m_speed_up_factor;
}
m_pos += m_forward * params.forward_axis * update_speed;
m_pos += m_right * params.right_axis * update_speed;
m_pos += m_up * params.up_axis * update_speed;
update_from_orientation();
}
void Camera::update_from_orientation() {
// conversion standard spherical to y-up
// x <-> z
// y <-> x
// z <-> y
float ct = std::cos(m_theta);
float st = std::sin(m_theta);
float cp = std::cos(m_phi);
float sp = std::sin(m_phi);
m_forward = glm::vec3(sp * st, ct, cp * st);
m_right = glm::normalize(glm::cross(m_forward, m_up));
m_view = glm::lookAt(m_pos, m_pos + m_forward, m_up);
}
Camera::Camera() { update_from_orientation(); }
const glm::mat4& Camera::get_view() const { return m_view; }
void Camera::set_speed(float speed) { m_speed = speed; }
float Camera::get_speed() const { return m_speed; }
void Camera::set_sensitivity(float sensitivity) { m_sensitivity = sensitivity; }
float Camera::get_sensitivity() const { return m_sensitivity; }
void Camera::set_speed_up_factor(float speed_up_factor) {
m_speed_up_factor = speed_up_factor;
}
float Camera::get_speed_up_factor() const { return m_speed_up_factor; }
void Camera::set_invert_y(bool invert_y) { m_invert_y = invert_y; }
bool Camera::is_invert_y() const { return m_invert_y; }
#ifndef VULKAN_RTX_CAMERA_H
#define VULKAN_RTX_CAMERA_H
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
struct CameraUpdateParams {
// mouse position in [0,1]
glm::vec2 mouse_pos = glm::vec2(0.0f);
bool mouse_pressed = false;
float dt = 0.0f;
bool speed_up = false;
float forward_axis = 0.0f;
float right_axis = 0.0f;
float up_axis = 0.0f;
};
class Camera {
public:
Camera();
[[nodiscard]] const glm::vec3& get_position() const;
void set_position(const glm::vec3& pos);
[[nodiscard]] const glm::vec3& get_forward() const;
[[nodiscard]] const glm::vec3& get_up() const;
[[nodiscard]] const glm::vec3& get_right() const;
[[nodiscard]] const glm::mat4& get_view() const;
void update(const CameraUpdateParams& params);
void set_speed(float speed);
[[nodiscard]] float get_speed() const;
void set_sensitivity(float sensitivity);
[[nodiscard]] float get_sensitivity() const;
void set_speed_up_factor(float speed_up_factor);
float get_speed_up_factor() const;
void set_invert_y(bool invert_y);
bool is_invert_y() const;
private:
void update_from_orientation();
float m_theta = 0.5f * glm::pi<float>();
float m_phi = 0.0f;
glm::vec3 m_pos = glm::vec3(0.0f);
glm::vec3 m_forward = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 m_right = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 m_up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::mat4 m_view = glm::mat4(1.0f);
glm::vec2 m_prev_mouse = glm::vec2(0.0f);
bool m_prev_mouse_pressed = false;
float m_sensitivity = 1.0f;
float m_speed = 1.0f;
bool m_invert_y = false;
float m_speed_up_factor = 4.0f;
};
#endif // VULKAN_RTX_CAMERA_H
#include "DeletionQueue.h"
void DeletionQueue::push(std::function<void()> f) {
m_queue.push_back(std::move(f));
}
void DeletionQueue::flush() {
while (!m_queue.empty()) {
m_queue.back()();
m_queue.pop_back();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment