Compare commits
59 Commits
old_engine
...
main
Author | SHA1 | Date | |
---|---|---|---|
2049a6f7b9 | |||
889c6f9826 | |||
a316febd9f | |||
e779e77922 | |||
588b78be69 | |||
70c15206b8 | |||
6d89abf64e | |||
bfd1ac6953 | |||
7c3225fe10 | |||
f574b60856 | |||
ba305de596 | |||
afa6a1a036 | |||
fe69d85fab | |||
f5958f2879 | |||
e10aea20a1 | |||
2b36a12335 | |||
698aeb2afc | |||
c87f13b063 | |||
b5958189cf | |||
b3c2e0114f | |||
ccd5b36965 | |||
d1d7d46826 | |||
7628f33c25 | |||
876d4c4198 | |||
872e79e4fb | |||
cf9af3a818 | |||
f98be769e7 | |||
d35fba24fa | |||
4e0bb5caa9 | |||
7c68b7bc8b | |||
68f6453da6 | |||
8469da79d0 | |||
250754af0a | |||
9d91fa6435 | |||
e6672945ae | |||
a4774e6189 | |||
223bbed232 | |||
a6ac4f029e | |||
5998037994 | |||
68fab7c94d | |||
7989be5fe7 | |||
e660fade95 | |||
9fd4c2399f | |||
2af55041c8 | |||
ac0f0e86c5 | |||
4dccd7d969 | |||
bcbc8796da | |||
f4120095ed | |||
e91b1983c8 | |||
98f2f3e955 | |||
91caebd385 | |||
4914ec6168 | |||
de55029356 | |||
a2c841288d | |||
274c96bb64 | |||
aefbe17786 | |||
cfa9e0e99a | |||
f8c008fd45 | |||
a02e87c3fa |
56
.github/workflows/build-helloworld-vita.yml
vendored
56
.github/workflows/build-helloworld-vita.yml
vendored
@@ -1,56 +0,0 @@
|
||||
name: build-helloworld-vita
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
VITASDK: /usr/local/vitasdk
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Cache VITASDK
|
||||
id: cache-vitasdk-restore
|
||||
uses: actions/cache/restore@v3
|
||||
with:
|
||||
path: /usr/local/vitasdk
|
||||
key: ${{ runner.os }}-vitasdk
|
||||
|
||||
- name: Install Vita Toolchain
|
||||
if: steps.cache-vitasdk.outputs.cache-hit != 'true'
|
||||
run: ./ci/install-vita-toolchain.sh
|
||||
|
||||
- name: Save VITASDK
|
||||
id: cache-vitasdk-save
|
||||
uses: actions/cache/save@v3
|
||||
with:
|
||||
path: /usr/local/vitasdk
|
||||
key: ${{ steps.cache-vitasdk-restore.outputs.cache-primary-key }}
|
||||
|
||||
- name: Install Libraries
|
||||
run: ./ci/install-libraries.sh
|
||||
|
||||
- name: Build Tools
|
||||
run: ./ci/build-tools.sh
|
||||
|
||||
- name: Build Game
|
||||
run: |
|
||||
export PATH=$VITASDK/bin:$PATH
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DDAWN_BUILD_TARGET=target-helloworld-vita -DCMAKE_BUILD_TYPE=Debug
|
||||
make
|
||||
|
||||
- name: Deploying
|
||||
env:
|
||||
DAWN_SSH_KEY: ${{ secrets.DAWN_SSH_KEY }}
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo -e "${DAWN_SSH_KEY}" > ~/.ssh/id_rsa
|
||||
chmod og-rwx ~/.ssh/id_rsa
|
||||
ssh-keyscan -H wish.moe >> ~/.ssh/known_hosts
|
||||
ssh -t yourwishes@wish.moe "mkdir -p /home/yourwishes/Dawn/vita/debug"
|
||||
scp ./build/src/dawnvita/HelloWorld.vpk yourwishes@wish.moe:/home/yourwishes/Dawn/vita/debug/
|
26
.github/workflows/build-liminal-glfw-linux64.yml
vendored
26
.github/workflows/build-liminal-glfw-linux64.yml
vendored
@@ -1,26 +0,0 @@
|
||||
name: build-liminal-glfw-linux64
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Toolchain
|
||||
run: ./ci/install-linux-toolchain.sh
|
||||
|
||||
- name: Install Libraries
|
||||
run: ./ci/install-libraries.sh
|
||||
|
||||
- name: Build Tools
|
||||
run: ./ci/build-tools.sh
|
||||
|
||||
- name: Build Game
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DDAWN_BUILD_TARGET=target-liminial-linux64-glfw
|
||||
make
|
21
.gitmodules
vendored
21
.gitmodules
vendored
@@ -1,21 +0,0 @@
|
||||
[submodule "lib/glfw"]
|
||||
path = lib/glfw
|
||||
url = https://github.com/glfw/glfw.git
|
||||
[submodule "lib/glm"]
|
||||
path = lib/glm
|
||||
url = https://github.com/g-truc/glm.git
|
||||
[submodule "lib/SDL"]
|
||||
path = lib/SDL
|
||||
url = https://github.com/libsdl-org/SDL.git
|
||||
[submodule "lib/openal-soft"]
|
||||
path = lib/openal-soft
|
||||
url = https://github.com/kcat/openal-soft
|
||||
[submodule "lib/AudioFile"]
|
||||
path = lib/AudioFile
|
||||
url = https://github.com/adamstark/AudioFile.git
|
||||
[submodule "lib/freetype"]
|
||||
path = lib/freetype
|
||||
url = https://gitlab.freedesktop.org/freetype/freetype.git
|
||||
[submodule "lib/libarchive"]
|
||||
path = lib/libarchive
|
||||
url = https://github.com/libarchive/libarchive
|
@@ -7,38 +7,10 @@ cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Variable Caches
|
||||
set(DAWN_CACHE_TARGET "dawn-target")
|
||||
|
||||
# Set Common Build Variables
|
||||
set(DAWN_ROOT_DIR "${CMAKE_SOURCE_DIR}")
|
||||
set(DAWN_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
||||
set(DAWN_SOURCES_DIR "${DAWN_ROOT_DIR}/src")
|
||||
set(DAWN_TOOLS_DIR "${DAWN_ROOT_DIR}/tools")
|
||||
set(DAWN_ASSETS_SOURCE_DIR "${DAWN_ROOT_DIR}/assets")
|
||||
set(DAWN_ASSETS_BUILD_DIR "${DAWN_BUILD_DIR}/assets")
|
||||
set(DAWN_GENERATED_DIR "${DAWN_BUILD_DIR}/generated")
|
||||
set(DAWN_TEMP_DIR "${DAWN_BUILD_DIR}/temp")
|
||||
|
||||
# Add CMake Tools
|
||||
add_subdirectory(cmake)
|
||||
|
||||
set(DAWN_BUILD_BINARY ${DAWN_BUILD_DIR}/src/${DAWN_BUILDING}/${DAWN_TARGET_NAME})
|
||||
|
||||
# Initialize Project First.
|
||||
project(Dawn
|
||||
VERSION 1.0.0
|
||||
LANGUAGES C CXX
|
||||
add_library(dawn STATIC
|
||||
src/funcs.c
|
||||
)
|
||||
|
||||
# Add tools
|
||||
add_subdirectory(tools)
|
||||
|
||||
# Add Libraries
|
||||
add_subdirectory(lib)
|
||||
|
||||
# Add Project Files
|
||||
add_subdirectory(src)
|
||||
target_include_directories(dawn PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
mkdir tools
|
||||
cd tools
|
||||
cmake .. -DDAWN_BUILD_TARGET=target-tools
|
||||
make
|
@@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
git submodule update --init --recursive
|
@@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
sudo apt install build-essential
|
@@ -1,38 +0,0 @@
|
||||
#!/bin/bash
|
||||
sudo apt-get install cmake libarchive-tools
|
||||
git clone https://github.com/vitasdk/vdpm ~/vdpm
|
||||
cd ~/vdpm
|
||||
./bootstrap-vitasdk.sh
|
||||
export PATH=$VITASDK/bin:$PATH
|
||||
|
||||
git clone https://github.com/vitasdk/packages.git ~/vitapackages
|
||||
cd ~/vitapackages
|
||||
|
||||
dir_array=(
|
||||
zlib
|
||||
bzip2
|
||||
henkaku
|
||||
taihen
|
||||
kubridge
|
||||
openal-soft
|
||||
openssl
|
||||
curl
|
||||
curlpp
|
||||
expat
|
||||
opus
|
||||
opusfile
|
||||
glm
|
||||
kuio
|
||||
vitaShaRK
|
||||
libmathneon
|
||||
vitaGL
|
||||
SceShaccCgExt
|
||||
)
|
||||
|
||||
curdir=$(pwd)
|
||||
for d in "${dir_array[@]}";do
|
||||
echo "${curdir}${d}"
|
||||
cd "${curdir}/${d}"
|
||||
vita-makepkg
|
||||
vdpm *-arm.tar.xz
|
||||
done
|
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
mkdir -p vita/build
|
||||
cd vita/build
|
||||
if [ ! -d "src" ]
|
||||
then
|
||||
cmake ../.. -DDAWN_BUILD_TARGET=target-helloworld-vita -DCMAKE_BUILD_TYPE=Debug
|
||||
fi
|
||||
make
|
||||
cp ./src/dawnvita/*.vpk ../
|
||||
cd ../..
|
@@ -1,8 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
add_subdirectory(hosts)
|
||||
add_subdirectory(targets)
|
@@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Check for build target, or default
|
||||
if(WIN32)
|
||||
set(DAWN_BUILD_HOST "build-host-win32")
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
set(DAWN_BUILD_HOST "build-host-linux")
|
||||
elseif(UNIX AND APPLE)
|
||||
set(DAWN_BUILD_HOST "build-host-osx")
|
||||
endif()
|
||||
|
||||
add_subdirectory(${DAWN_BUILD_HOST})
|
@@ -1,4 +0,0 @@
|
||||
# CMake Hosts
|
||||
CMake Hosts help the build system define how a HOST (Not the target/client) does
|
||||
its building. Host would be the system you are using, right now, to do the build
|
||||
with.
|
@@ -1,6 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
set(DAWN_BUILD_HOST_LIBS "m" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
@@ -1,6 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
@@ -1,6 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
@@ -1,49 +0,0 @@
|
||||
find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h
|
||||
HINTS
|
||||
ENV GLFWDIR
|
||||
PATHS
|
||||
"/usr"
|
||||
"/usr/local"
|
||||
"~/Library/Frameworks"
|
||||
"/Library/Frameworks"
|
||||
"/opt"
|
||||
"$ENV{PROGRAMFILES}/glfw"
|
||||
"$ENV{PROGRAMFILES}/glfw3"
|
||||
PATH_SUFFIXES
|
||||
include
|
||||
)
|
||||
|
||||
# Search for the library
|
||||
FIND_LIBRARY(GLFW_LIBRARY
|
||||
NAMES
|
||||
glfw glfw3 GLFW GLFW3
|
||||
HINTS
|
||||
ENV GLFWDIR
|
||||
PATHS
|
||||
"/usr"
|
||||
"/usr/local"
|
||||
"~/Library/Frameworks"
|
||||
"/Library/Frameworks"
|
||||
"/opt"
|
||||
"$ENV{PROGRAMFILES}/glfw"
|
||||
"$ENV{PROGRAMFILES}/glfw3"
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
lib32
|
||||
lib64
|
||||
libs
|
||||
lib-vc2012
|
||||
lib-vc2013
|
||||
lib-vc2015
|
||||
lib-vc2017
|
||||
lib-vc2019
|
||||
lib-vc2022
|
||||
)
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
|
||||
GLFW
|
||||
REQUIRED_VARS GLFW_LIBRARY GLFW_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(GLFW_LIBRARY GLFW_INCLUDE_DIR)
|
@@ -1,49 +0,0 @@
|
||||
find_path(OPENAL_INCLUDE_DIR al.h
|
||||
HINTS
|
||||
ENV OPENALDIR
|
||||
PATHS
|
||||
"/usr"
|
||||
"/usr/local"
|
||||
"~/Library/Frameworks"
|
||||
"/Library/Frameworks"
|
||||
"/opt"
|
||||
"$ENV{PROGRAMFILES}/openal"
|
||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]"
|
||||
PATH_SUFFIXES
|
||||
include/AL
|
||||
AL/AL
|
||||
include/OpenAL
|
||||
include
|
||||
AL
|
||||
OpenAL
|
||||
)
|
||||
|
||||
# Search for the library
|
||||
FIND_LIBRARY(OPENAL_LIBRARY
|
||||
NAMES
|
||||
OpenAL al openal OpenAL32
|
||||
HINTS
|
||||
ENV OPENALDIR
|
||||
PATHS
|
||||
"/usr"
|
||||
"/usr/local"
|
||||
"~/Library/Frameworks"
|
||||
"/Library/Frameworks"
|
||||
"/opt"
|
||||
"$ENV{PROGRAMFILES}/openal"
|
||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir]"
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
lib32
|
||||
lib64
|
||||
libs
|
||||
${_OpenAL_ARCH_DIR}
|
||||
)
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
|
||||
OpenAL
|
||||
REQUIRED_VARS OPENAL_LIBRARY OPENAL_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
|
@@ -1,14 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Now validate we have a build target for real
|
||||
if(NOT DEFINED DAWN_BUILD_TARGET)
|
||||
set(DAWN_BUILD_TARGET "target-rpg-linux-glfw" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
endif()
|
||||
|
||||
message("Building target ${DAWN_BUILD_TARGET}")
|
||||
|
||||
# Include the build target
|
||||
add_subdirectory(${DAWN_BUILD_TARGET})
|
@@ -1,40 +0,0 @@
|
||||
# CMake Targets
|
||||
CMake Targets decide what you are intending to build. Targets are (usually) a
|
||||
specific system, like vita, 3ds, switch, or a specific OS with a library, e.g.
|
||||
targetting vulkan on linux vs targetting opengl on linux, or targetting opengl
|
||||
on windows, etc.
|
||||
|
||||
In addition the target also decides what project(s) to build. Usually this is
|
||||
just the specific game and/or systems to be built, so if you are building a VN
|
||||
game the target would need to let the build system know you want to rollup the
|
||||
VN parts of the engine also.
|
||||
|
||||
Note this is one of the very few build args that is required during the
|
||||
configuration of cmake to make it build properly, failure to specify a target
|
||||
will result in a build error.
|
||||
|
||||
```
|
||||
-DDAWN_BUILD_TARGET=target-helloworld-linux64-glfw
|
||||
```
|
||||
|
||||
## Target Systems
|
||||
- vita
|
||||
- linux
|
||||
- osx
|
||||
- windows
|
||||
- emscripten (Web)
|
||||
|
||||
## Target Libraries
|
||||
- vita (Includes OGL)
|
||||
- glfw (Includes OGL)
|
||||
- sdl2 (Includes OGL)
|
||||
|
||||
## Target games
|
||||
- liminal
|
||||
- helloworld
|
||||
|
||||
## Target Arcitectures
|
||||
- vita (form of armv7)
|
||||
- linux (x64 only)
|
||||
- windows (x64 only)
|
||||
- osx (targetting arm64 currently)
|
@@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
set(DAWN_BUILDING dawnhelloworld CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_EMSCRIPTEN true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_NAME "HelloWorld" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
|
||||
set(DAWN_EMSCRIPTEN_FLAGS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
|
||||
# Ensures a .HTML file is generated.
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
@@ -1,10 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
set(DAWN_BUILDING dawnhelloworld CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_LINUX true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_NAME "HelloWorld" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_ARCHIVE true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
@@ -1,21 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
set(DAWN_BUILDING dawnhelloworld CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_VITA true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_BUILD_HOST_LIBS "" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_NAME "HelloWorld" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
|
||||
# Properties
|
||||
set(DAWN_VITA_APP_NAME "Hello Vita" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_VITA_TITLEID "DAWN00000" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_VITA_VERSION "01.00" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
|
||||
# Toolchain
|
||||
if(DEFINED ENV{VITASDK})
|
||||
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
else()
|
||||
message(FATAL_ERROR "VITASDK Environment variable is missing! Either you do not have the VITASDK installed, or it is not set up with the env vars correctly.")
|
||||
endif()
|
@@ -1,11 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
set(DAWN_BUILDING dawnrpg CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_LINUX true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_NAME "DawnRPG" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_ARCHIVE true CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(DAWN_TARGET_TRUETYPE false CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
@@ -1,340 +0,0 @@
|
||||
# Compiling, Debugging and Running
|
||||
This document's purpose is to explain how to compile, debug and run the project
|
||||
on your machine. It is assumed that you have a basic understanding of the
|
||||
fundamentals of your operating system and how to use a terminal.
|
||||
|
||||
## Preamble
|
||||
The Dawn project is written almost entirely in C and C++. This includes all of
|
||||
the tooling used to generate the project and assets. The only non-C/C++ code is
|
||||
used by CMake to generate the output compilation files. This provides the Dawn
|
||||
project an extremely high level of portability not typically seen in other
|
||||
projects.
|
||||
|
||||
## TLDR; Version
|
||||
This document is going to go over the installation and configuration of the
|
||||
following items. If you are already familiar with these tools, you can skip to
|
||||
the "Downloading the Source Code" section.
|
||||
- C/C++ Compiler
|
||||
- CMake
|
||||
- Git
|
||||
- IDE
|
||||
You may also need *python*, since we depend on third-party libraries that may use
|
||||
python scripts to generate their own build files. This is not required for the
|
||||
Dawn project itself.
|
||||
|
||||
## Pre-Configuration
|
||||
In order to compile the Dawn project, you are required to have the following
|
||||
tools installed on your machine.
|
||||
|
||||
### 1. A C/C++ Compiler
|
||||
The exact tool(s) will depend on your specific scenario. The compiler is used to
|
||||
take the .cpp/.hpp files and generating binaries that execute on the target
|
||||
machine. Typically you will use your own C/C++ compiler for the machine that you
|
||||
are currently running, e.g. if you are running Windows, you will use the Visual
|
||||
Studio compiler. If you are running Linux, you will use GCC or Clang. If you are
|
||||
running macOS, you will use Clang, and so-on.
|
||||
|
||||
If you are intending to compile on a different machine than the one you are
|
||||
currently running, you will need to use a cross-compiler that is specific for
|
||||
your use-case. You will also need to refer to the documentation for creating a
|
||||
new Dawn engine target.
|
||||
|
||||
Please follow the instructions for your specific operating system to install the
|
||||
appropriate C/C++ compiler.
|
||||
|
||||
**Windows**
|
||||
You will need to download and install [Visual Studio](https://visualstudio.microsoft.com/downloads/).
|
||||
Visual Studio (not to be confused with Visual Studio Code) is a full IDE that
|
||||
bundles the official Microsoft C/C++ compiler. It is the recommended compiler
|
||||
for building the Dawn project on Windows.
|
||||
|
||||
Advanced used can also use [MinGW](http://www.mingw.org/) or another compiler if
|
||||
they wish, however this is not officially supported.
|
||||
|
||||
After installing Visual Studio, you will need to install the C++ development
|
||||
tools. This can be done by opening the Visual Studio Installer and selecting
|
||||
the "Desktop development with C++" workload.
|
||||
|
||||
**Linux**
|
||||
You will need to install the GCC and Clang compilers. The compilers are usually
|
||||
installed either by default or by installing the necessary packages for your
|
||||
Linux distribution.
|
||||
|
||||
For example, on Ubuntu, you can install the GCC and Clang compilers by running
|
||||
the following command:
|
||||
```bash
|
||||
sudo apt install build-essential clang
|
||||
```
|
||||
|
||||
On Arch Linux, you can install the GCC and Clang compilers by running the
|
||||
following command:
|
||||
```bash
|
||||
sudo pacman -S base-devel clang
|
||||
```
|
||||
|
||||
And on Fedora, you can install the GCC and Clang compilers by running the
|
||||
following command:
|
||||
```bash
|
||||
sudo dnf install @development-tools clang
|
||||
```
|
||||
|
||||
For other distributions, please refer to your distribution's documentation.
|
||||
|
||||
**macOS**
|
||||
You will need to install the Xcode command line tools. This can be done by done
|
||||
by running the following command in your terminal:
|
||||
```bash
|
||||
xcode-select --install
|
||||
```
|
||||
|
||||
Afterwards you will need to install and enable [Brew](https://brew.sh/). This
|
||||
can be done by running the following command in your terminal:
|
||||
```bash
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
```
|
||||
|
||||
|
||||
### 2. CMake
|
||||
CMake is a tool that is used to generate the compilation files for the Dawn
|
||||
project. In short this is used to create versions of the Dawn project that can
|
||||
be compiled on all different sets of compilers, so if you are compiling on, for
|
||||
example, Windows, you can use CMake to generate the compilation files for the
|
||||
Visual Studio compiler, or if you are compiling on Linux, you can use CMake to
|
||||
generate the compilation files for the GCC or Clang compilers, and so-on.
|
||||
|
||||
To install CMake, please follow the instructions for your specific operating
|
||||
system. All other operating systems can be found on the [CMake downloads page](https://cmake.org/download/).
|
||||
|
||||
**Windows**
|
||||
You will need to download and install [CMake](https://cmake.org/download/). The
|
||||
installer will guide you through the installation process and will install the
|
||||
CMake executable to your system. It is recommended that you add CMake to your
|
||||
system PATH if requested by the installer.
|
||||
|
||||
**Linux**
|
||||
Like installing the C/C++ compilers, you will need to install CMake using your
|
||||
specific Linux distribution's package manager, there is also a chance that CMake
|
||||
can be installed using flatpak or snap. Please refer to your distribution's
|
||||
documentation for more information.
|
||||
|
||||
For Ubuntu and other Debian-based distributions, you can install CMake by using
|
||||
the following command:
|
||||
```bash
|
||||
sudo apt install cmake
|
||||
```
|
||||
|
||||
For Arch Linux, you can install CMake by using the following command:
|
||||
```bash
|
||||
sudo pacman -S cmake
|
||||
```
|
||||
|
||||
And for Fedora, you can install CMake by using the following command:
|
||||
```bash
|
||||
sudo dnf install cmake
|
||||
```
|
||||
|
||||
**macOS**
|
||||
You will install CMake using brew. We detailed how to install brew in the C/C++
|
||||
compiler section. To install CMake, run the following command in your terminal:
|
||||
```bash
|
||||
brew install cmake
|
||||
```
|
||||
|
||||
### 3. Git
|
||||
Git is a version control system that is used to manage the Dawn project's source
|
||||
code. It is used to download the source code, and to update the source code to
|
||||
the latest version. It is also used to manage the project's dependencies. Git is
|
||||
a standard tool in the programming industry and is used to manage complex
|
||||
projects, especially those that are worked on by multiple people.
|
||||
|
||||
Git, like all of the above tools, is installed slightly differently depending on
|
||||
your operating system. Please follow the instructions for your specific
|
||||
operating system.
|
||||
|
||||
**Windows**
|
||||
You will need to download and install [Git](https://git-scm.com/downloads). The
|
||||
installer will guide you through the installation process and will install the
|
||||
Git executable to your system. It is recommended that you add Git to your system
|
||||
PATH if requested by the installer. You do not need to add the Context-menu
|
||||
items to your system.
|
||||
|
||||
**Linux**
|
||||
Like installing the C/C++ compilers, you will need to install Git using your
|
||||
specific Linux distribution's package manager. It is also likely that git would
|
||||
have been installed by default. Please refer to your distribution's docs for
|
||||
more information.
|
||||
|
||||
For Ubuntu and other Debian-based distributions, you can install Git by using
|
||||
the following command:
|
||||
```bash
|
||||
sudo apt install git
|
||||
```
|
||||
|
||||
For Arch Linux, you can install Git by using the following command:
|
||||
```bash
|
||||
sudo pacman -S git
|
||||
```
|
||||
|
||||
And for Fedora, you can install Git by using the following command:
|
||||
```bash
|
||||
sudo dnf install git
|
||||
```
|
||||
|
||||
**macOS**
|
||||
You will install Git using brew. We detailed how to install brew in the C/C++
|
||||
compiler section. To install Git, run the following command in your terminal:
|
||||
```bash
|
||||
brew install git
|
||||
```
|
||||
|
||||
### 4. An IDE
|
||||
An IDE (Integrated Development Environment) is a tool that is used to view and
|
||||
edit code of projects. While it is not required to use an IDE, it is recommended
|
||||
since it can make the process of editing and running the project much easier.
|
||||
|
||||
There are many different IDEs available, and often people chose an IDE that will
|
||||
suit their preferences and needs, however if you are unsure of which IDE you
|
||||
should be using, the Dawn project recommends using [Visual Studio Code](https://code.visualstudio.com/),
|
||||
not to be confused with Visual Studio.
|
||||
|
||||
Visual Studio Code is a free and open-source IDE that is widely used in the
|
||||
industry for its simple, modern and configurable interface. For example you can
|
||||
configure VSCode to work on Web Projects, Game Projects, and more. It acts like
|
||||
a text editor with a bunch of extra tools.
|
||||
|
||||
In addition to installing the VSCode IDE, we will add several recommended
|
||||
plugins that will make editing the Dawn project easier and more seamless.
|
||||
|
||||
To install VSCode follow the instructions for your specific operating system on
|
||||
the [VSCode downloads page](https://code.visualstudio.com/download), as it can
|
||||
vary a lot between operating systems.
|
||||
|
||||
After installing VSCode, you will need to install the following plugins, by
|
||||
clicking on the "Extensions" icon on the left-hand side of the VSCode window,
|
||||
and searching for the following plugins. You may also be able to click on the
|
||||
following links to install the plugins directly, but it may not work.
|
||||
- [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
|
||||
- [CMake](https://marketplace.visualstudio.com/items?itemName=twxs.cmake)
|
||||
- [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools)
|
||||
|
||||
## Downloading the Source Code
|
||||
Now that you have all of the necessary tools installed, you can download the
|
||||
source code of the project and using it to build. The source code contains all
|
||||
of the code of the project, as well as the assets and the build scripts. This is
|
||||
confidential information and should not be shared with anyone.
|
||||
|
||||
### 1. Cloning the Repository
|
||||
We previously installed the git tool, which is used to download the source code
|
||||
of the project, and some third-party libraries. To download the source code, you
|
||||
will need to open a terminal and navigate to the directory where you want to
|
||||
download the source code to.
|
||||
|
||||
Afterwards, you will need to run the following command:
|
||||
```bash
|
||||
git clone https://git.wish.moe/YourWishes/Dawn.git
|
||||
```
|
||||
This will download the source code of the project to a new subdirectory called
|
||||
"Dawn" and put all of the projects' source code within there.
|
||||
|
||||
### 2. Installing the Dependencies / Libraries.
|
||||
I try to keep dependencies on third-party libraries to a minimum, however there
|
||||
are a few libraries that are required to build the Dawn project. These libraries
|
||||
are not included in the source code, and must be downloaded separately. This is
|
||||
done using the git tool.
|
||||
|
||||
After you have cloned the above repository, you will need to open a terminal and
|
||||
navigate to the directory where you downloaded the source code to. Afterwards,
|
||||
you will need to run the following command:
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
This will fetch all of the third-party libraries that are required to build the
|
||||
Dawn project. This may take a while depending on your internet connection.
|
||||
|
||||
### 3. Loading the Project
|
||||
This step is semi-optional. We are aiming to build the project using CMake, and
|
||||
the easiest way to do this is to use the CMake Tools plugin for VSCode that we
|
||||
installed earlier. This plugin will automatically detect the CMake files in the
|
||||
project and will allow us to build the project using the VSCode interface.
|
||||
|
||||
If you opted out of using VSCode, you will need to set up your CMake environment
|
||||
to suit your IDE or needs. This is outside of the scope of this document, and
|
||||
you will need to refer to your IDE's documentation for more information.
|
||||
|
||||
To load the project, you will need to open VSCode and open the Dawn project
|
||||
directory. Most operating systems will allow you to do this by dragging the
|
||||
Dawn project directory onto the VSCode window. If this does not work, you can
|
||||
open VSCode and click on the "File" menu, and click on "Open Folder". You will
|
||||
then need to navigate to the Dawn project directory and click "Open".
|
||||
|
||||
Afterwards you will likely be prompted autometically to configure the CMake
|
||||
Tools plugin. If you are not, you can click on the "CMake" icon on the left-hand
|
||||
side of the VSCode window, and click on "Configure". This will configure the
|
||||
CMake Tools plugin to use the CMake files in the Dawn project directory.
|
||||
|
||||
You may also be asked to select a compiler. If you are using Windows, you will
|
||||
need to select the Visual Studio compiler. If you are using Linux, you will need
|
||||
to select the GCC or Clang compiler. If you are using macOS, you will need to
|
||||
select the Clang compiler. If you are using a different compiler, you will need
|
||||
to select the appropriate compiler.
|
||||
|
||||
If prompted to select a build type, select "Debug".
|
||||
|
||||
## Compiling the Project
|
||||
Now that we have the project loaded into our IDE, we can compile the project.
|
||||
This is done using the CMake Tools plugin for VSCode. If you are not using
|
||||
VSCode you will need to refer to your IDE's documentation for more information.
|
||||
|
||||
Firstly, you will need to create a settings file to configure the project. In
|
||||
VSCode you can create a new folder called `.vscode` (Including the leading `.`)
|
||||
in the Dawn project root directory. Afterwards, you will need to create a new
|
||||
file called `settings.json` in the `.vscode` directory. You will then need to
|
||||
paste the following into the file:
|
||||
```json
|
||||
{
|
||||
"cmake.configureArgs": [
|
||||
"-DDAWN_BUILD_TOOLS=true",
|
||||
"-DDAWN_BUILD_TARGET=target-liminal-win32-glfw",
|
||||
"-DDAWN_DEBUG_BUILD=true"
|
||||
]
|
||||
}
|
||||
```
|
||||
And save the file. You may want to alter the values to suit your needs. For
|
||||
example, if you are compiling on Linux, you will need to change
|
||||
`target-liminal-win32-glfw` to `target-liminal-linux-glfw`. If you are compiling
|
||||
on macOS, you will need to change it to `target-liminal-osx-glfw`. The specific
|
||||
configure arguments are outside of the scope of this document, and you will need
|
||||
to refer to the specific target documentation for more information.
|
||||
|
||||
After you have created the settings file, you will need to configure and build
|
||||
the project. To perform the build you need to click "Build" button the bottom of
|
||||
the VSCode window. This will compile the project and will output the resulting
|
||||
binaries in to a "build" directory within the Dawn project directory.
|
||||
|
||||
Upon clicking the "Build" button, you will see an output panel appear at the
|
||||
bottom of the VSCode window. This will show the process of the build, and will
|
||||
show any errors that may occur. This is used to debug and fix any issues that
|
||||
may occur during the build process.
|
||||
|
||||
If the build was successful, you will see a "Build finished" message in the
|
||||
output panel, typically read as;
|
||||
```bash
|
||||
[build] Build finished with exit code 0
|
||||
```
|
||||
If you do not see this message, or if the exit code is not 0, you will need to
|
||||
debug the issue. The output panel will show the error message which is helpful
|
||||
so we can debug the issue. If you are unable to debug the issue, you can ask for
|
||||
help in the Discord server.
|
||||
|
||||
## Running the built project
|
||||
After the build process succeeds you will be able to run the project. This is
|
||||
done by clicking on the Run icon, which looks like a play button, on the bottom
|
||||
of the VSCode window. This will run the project in production mode and will not
|
||||
show any debug information.
|
||||
|
||||
If the program hangs, crashes or does not run, you can click the Debug icon,
|
||||
which looks like a ladybug, on the bottom of the VSCode window. This will run
|
||||
the project in debug mode and will show debug information and HALT the program
|
||||
if there is an error detected. If program HALTS in debug mode you can use this
|
||||
information to debug the issue. If you are unable to debug the issue, you can
|
||||
ask for help in the Discord server.
|
Submodule lib/AudioFile deleted from 004065d01e
@@ -1,53 +0,0 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# GLFW
|
||||
if(DAWN_TARGET_GLFW)
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
|
||||
set(DAWN_EMSCRIPTEN_FLAGS "${DAWN_EMSCRIPTEN_FLAGS} -s USE_GLFW=3" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
add_subdirectory(glad)
|
||||
else()
|
||||
add_subdirectory(glad)
|
||||
add_subdirectory(glfw)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# SDL
|
||||
if(DAWN_TARGET_SDL2)
|
||||
add_subdirectory(glad)
|
||||
add_subdirectory(SDL)
|
||||
endif()
|
||||
|
||||
# GLM
|
||||
add_subdirectory(glm)
|
||||
|
||||
# FreeType
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
|
||||
set(DAWN_EMSCRIPTEN_FLAGS "${DAWN_EMSCRIPTEN_FLAGS} -s USE_FREETYPE=1" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
else()
|
||||
add_subdirectory(freetype)
|
||||
endif()
|
||||
|
||||
# LibArchive
|
||||
if(DAWN_TARGET_ARCHIVE)
|
||||
add_subdirectory(libarchive)
|
||||
endif()
|
||||
|
||||
# OpenAL
|
||||
if(DAWN_TARGET_OPENAL)
|
||||
set(LIBTYPE "STATIC")
|
||||
add_subdirectory(openal-soft)
|
||||
|
||||
set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
|
||||
set(BUILD_EXAMPLES OFF CACHE BOOL "Build examples" FORCE)
|
||||
add_subdirectory(AudioFile)
|
||||
endif()
|
||||
|
||||
# Emscripten (TESTING ONLY)
|
||||
if(DEFINED DAWN_EMSCRIPTEN_FLAGS)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${DAWN_EMSCRIPTEN_FLAGS}" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
endif()
|
1
lib/SDL
1
lib/SDL
Submodule lib/SDL deleted from fb1497566c
Submodule lib/freetype deleted from 7ff43d3e9f
@@ -1,12 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.11)
|
||||
project(glad)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
src/glad.c
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
@@ -1,290 +0,0 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef _WIN64
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
File diff suppressed because it is too large
Load Diff
2522
lib/glad/src/glad.c
2522
lib/glad/src/glad.c
File diff suppressed because it is too large
Load Diff
1
lib/glfw
1
lib/glfw
Submodule lib/glfw deleted from b35641f4a3
1
lib/glm
1
lib/glm
Submodule lib/glm deleted from 45008b225e
Submodule lib/libarchive deleted from 313aa1fa10
Submodule lib/openal-soft deleted from d3875f333f
@@ -1,77 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Custom variables
|
||||
set(
|
||||
DAWN_TARGET_DEPENDENCIES_LAST
|
||||
CACHE INTERNAL ${DAWN_CACHE_TARGET}
|
||||
)
|
||||
|
||||
# Build Project
|
||||
add_executable(${DAWN_TARGET_NAME})
|
||||
|
||||
# Change what we are building. Pulled from the cmake/targets dir.
|
||||
if(DEFINED DAWN_BUILDING)
|
||||
add_subdirectory(${DAWN_BUILDING})
|
||||
endif()
|
||||
|
||||
# Validate game project includes the target name
|
||||
if(DEFINED DAWN_TARGET_NAME)
|
||||
# Add in base library
|
||||
add_subdirectory(dawn)
|
||||
|
||||
# Compile entry targets
|
||||
if(DAWN_TARGET_WIN32)
|
||||
add_subdirectory(dawnwin32)
|
||||
elseif(DAWN_TARGET_LINUX)
|
||||
add_subdirectory(dawnlinux)
|
||||
elseif(DAWN_TARGET_OSX)
|
||||
add_subdirectory(dawnosx)
|
||||
elseif(DAWN_TARGET_VITA)
|
||||
add_subdirectory(dawnvita)
|
||||
elseif(DAWN_TARGET_EMSCRIPTEN)
|
||||
add_subdirectory(dawnemscripten)
|
||||
else()
|
||||
message(FATAL_ERROR "You need to define an entry target")
|
||||
endif()
|
||||
|
||||
# Host Libraries
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
)
|
||||
|
||||
# Compile support targets
|
||||
if(DAWN_TARGET_GLFW)
|
||||
add_subdirectory(dawnglfw)
|
||||
add_subdirectory(dawnopengl)
|
||||
endif()
|
||||
|
||||
if(DAWN_TARGET_TRUETYPE)
|
||||
add_subdirectory(dawntruetype)
|
||||
endif()
|
||||
|
||||
if(DAWN_TARGET_SDL2)
|
||||
add_subdirectory(dawnsdl2)
|
||||
add_subdirectory(dawnopengl)
|
||||
endif()
|
||||
|
||||
if(DAWN_TARGET_VITA)
|
||||
add_subdirectory(dawnopengl)
|
||||
endif()
|
||||
|
||||
if(DAWN_TARGET_OPENAL)
|
||||
add_subdirectory(dawnopenal)
|
||||
endif()
|
||||
|
||||
# Late definitions, used by tools
|
||||
if(NOT DAWN_TARGET_DEPENDENCIES_LAST)
|
||||
else()
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${DAWN_TARGET_DEPENDENCIES_LAST})
|
||||
endif()
|
||||
|
||||
# Compress the game assets.
|
||||
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
||||
endif()
|
@@ -1,37 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Libraries
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
glm
|
||||
archive_static
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(asset)
|
||||
add_subdirectory(audio)
|
||||
add_subdirectory(component)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(environment)
|
||||
add_subdirectory(game)
|
||||
# add_subdirectory(games)
|
||||
# add_subdirectory(input)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(prefab)
|
||||
# add_subdirectory(physics)
|
||||
add_subdirectory(save)
|
||||
add_subdirectory(scene)
|
||||
# add_subdirectory(state)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(ui)
|
@@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
assert.cpp
|
||||
)
|
@@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert.hpp"
|
||||
|
||||
void assertTrueImplement(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *func,
|
||||
const bool_t result,
|
||||
const char *message,
|
||||
...
|
||||
) {
|
||||
if(result) return;
|
||||
|
||||
// Print file info.
|
||||
fprintf(
|
||||
stderr,
|
||||
"Assert failed in %s:%i :: %s\n",
|
||||
file,
|
||||
line,
|
||||
func
|
||||
);
|
||||
|
||||
va_list argptr;
|
||||
va_start(argptr, message);
|
||||
vfprintf(stderr, message, argptr);
|
||||
va_end(argptr);
|
||||
fprintf(stderr, "\n");
|
||||
throw std::runtime_error("Assert failed.");
|
||||
}
|
@@ -1,115 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
/**
|
||||
* Asserts that a given statement must evaluate to true or the assertion fails
|
||||
* and the game will close semi-gracefully.
|
||||
*
|
||||
* @param file String filename of the file that has the assertion.
|
||||
* @param line Integer line number within the file that the assertion is on.
|
||||
* @param func Called function that has the assertion.
|
||||
* @param result The statement that must equate to true.
|
||||
* @param message Message (sprintf format) to send to the stdout.
|
||||
* @param ... Varargs of the sprintf arguments.
|
||||
*/
|
||||
void assertTrueImplement(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *func,
|
||||
const bool_t result,
|
||||
const char *message,
|
||||
...
|
||||
);
|
||||
|
||||
/**
|
||||
* Asserts that a statement must be true in order for the assertion to not cause
|
||||
* an error. Basically this is a throw statement in disguise.
|
||||
*
|
||||
* @param statement Statement of the assertion.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertTrue(...) assertTrueImplement( \
|
||||
__FILE__, __LINE__, __func__, __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that a statement must be false in order for the assertion to not
|
||||
* cause an error.
|
||||
*
|
||||
* @param statement Statement of the assertion.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertFalse(x, ...) assertTrue(!(x), __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Asserts that a specified piece of code should be entirely unreachable.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertUnreachable(...) assertTrue(false, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Asserts that a given pointer is not null.
|
||||
* @param x Pointer to check.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertNotNull(x, ...) assertTrue(x != nullptr, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Asserts that a given pointer is null.
|
||||
* @param x Pointer to check.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertNull(x, ...) assertTrue(x == nullptr, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Asserts that a given map has a specific key.
|
||||
* @param map Map to check.
|
||||
* @param key Key to check for.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertMapHasKey(map, key, ...) assertTrue( \
|
||||
map.find(key) != map.end(), __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that a given value has a specific flag turned off.
|
||||
*
|
||||
* @param value Value to check.
|
||||
* @param flag Flag to check for.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertFlagOff(value, flag, ...) assertTrue( \
|
||||
(value & flag) == 0, __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that a given value has a specific flag turned on.
|
||||
*
|
||||
* @param value Value to check.
|
||||
* @param flag Flag to check for.
|
||||
* @param message Message (sprintf format) to send to the logger.
|
||||
* @param args Optional TParam args for the sprintf message to accept.
|
||||
*/
|
||||
#define assertFlagOn(value, flag, ...) assertTrue( \
|
||||
(value & flag) == flag, __VA_ARGS__ \
|
||||
)
|
||||
|
||||
/**
|
||||
* Asserts that the current code is deprecated and should not be used anymore.
|
||||
* @deprecated
|
||||
*/
|
||||
#define assertDeprecated(...) assertUnreachable(__VA_ARGS__)
|
@@ -1,200 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
#include "AssetDataLoader.hpp"
|
||||
#include "util/Math.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
ssize_t assetDataLoaderArchiveRead(
|
||||
struct archive *archive,
|
||||
void *d,
|
||||
const void **buffer
|
||||
) {
|
||||
assertNotNull(archive, "Archive is NULL!");
|
||||
assertNotNull(d, "Data is NULL!");
|
||||
assertNotNull(buffer, "Buffer is NULL!");
|
||||
AssetDataLoader *loader = (AssetDataLoader*)d;
|
||||
|
||||
*buffer = loader->buffer;
|
||||
size_t read = fread(
|
||||
loader->buffer, 1, ASSET_LOADER_BUFFER_SIZE, loader->assetArchiveFile
|
||||
);
|
||||
if(ferror(loader->assetArchiveFile)) return ARCHIVE_FATAL;
|
||||
return read;
|
||||
}
|
||||
|
||||
int64_t assetDataLoaderArchiveSeek(
|
||||
struct archive *archive,
|
||||
void *d,
|
||||
int64_t offset,
|
||||
int32_t whence
|
||||
) {
|
||||
assertNotNull(archive, "Archive is NULL!");
|
||||
assertNotNull(d, "Data is NULL!");
|
||||
assertTrue(offset > 0, "Offset must be greater than 0!");
|
||||
AssetDataLoader *loader = (AssetDataLoader*)d;
|
||||
int32_t ret = fseek(loader->assetArchiveFile, offset, whence);
|
||||
assertTrue(ret == 0, "Failed to seek!");
|
||||
return ftell(loader->assetArchiveFile);
|
||||
}
|
||||
|
||||
int32_t assetDataLoaderArchiveOpen(struct archive *a, void *d) {
|
||||
assertNotNull(a, "Archive is NULL!");
|
||||
assertNotNull(d, "Data is NULL!");
|
||||
AssetDataLoader *loader = (AssetDataLoader*)d;
|
||||
|
||||
int32_t ret = fseek(loader->assetArchiveFile, 0, SEEK_SET);
|
||||
assertTrue(ret == 0, "Failed to seek to start of file!");
|
||||
return ARCHIVE_OK;
|
||||
}
|
||||
|
||||
int32_t assetDataLoaderArchiveClose(struct archive *a, void *d) {
|
||||
assertNotNull(a, "Archive is NULL!");
|
||||
assertNotNull(d, "Data is NULL!");
|
||||
return assetDataLoaderArchiveOpen(a, d);
|
||||
}
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
AssetDataLoader::AssetDataLoader(std::string fileName) : fileName(fileName) {
|
||||
assertTrue(
|
||||
fileName.size() > 0,
|
||||
"IAssetDataLoader::IAssetDataLoader: fileName must be greater than 0"
|
||||
);
|
||||
}
|
||||
|
||||
void AssetDataLoader::open() {
|
||||
assertNull(this->assetArchiveFile, "AssetDataLoader::open: File is already open");
|
||||
assertNull(this->assetArchive, "AssetDataLoader::open: Archive is already open");
|
||||
assertNull(this->assetArchiveEntry, "AssetDataLoader::open: Entry is already open");
|
||||
|
||||
this->assetArchiveFile = this->openAssetArchiveFile();
|
||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::open: Failed to open archive file!");
|
||||
|
||||
// Open archive reader
|
||||
assetArchive = archive_read_new();
|
||||
assertNotNull(assetArchive, "AssetDataLoader::open: Failed to create archive reader");
|
||||
|
||||
// Set up the reader
|
||||
archive_read_support_format_tar(assetArchive);
|
||||
|
||||
// Open reader
|
||||
archive_read_set_open_callback(assetArchive, &assetDataLoaderArchiveOpen);
|
||||
archive_read_set_read_callback(assetArchive, &assetDataLoaderArchiveRead);
|
||||
archive_read_set_seek_callback(assetArchive, &assetDataLoaderArchiveSeek);
|
||||
archive_read_set_close_callback(assetArchive, &assetDataLoaderArchiveClose);
|
||||
archive_read_set_callback_data(assetArchive, this);
|
||||
|
||||
int32_t ret = archive_read_open1(assetArchive);
|
||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::open: Failed to open archive!");
|
||||
position = 0;
|
||||
|
||||
// Iterate over each file to find the one for this asset loader.
|
||||
while(archive_read_next_header(assetArchive, &assetArchiveEntry) == ARCHIVE_OK) {
|
||||
const char_t *headerFile = (char_t*)archive_entry_pathname(assetArchiveEntry);
|
||||
if(std::string(headerFile) == this->fileName) return;
|
||||
int32_t ret = archive_read_data_skip(assetArchive);
|
||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::open: Failed to skip data!");
|
||||
}
|
||||
|
||||
assertUnreachable("AssetDataLoader::open: Failed to find file!");
|
||||
}
|
||||
|
||||
int32_t AssetDataLoader::close() {
|
||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::close: File is NULL");
|
||||
assertNotNull(this->assetArchive, "AssetDataLoader::close: Archive is NULL!");
|
||||
assertNotNull(this->assetArchiveEntry, "AssetDataLoader::close: Entry is NULL!");
|
||||
|
||||
// Close the archive
|
||||
int32_t ret = archive_read_free(this->assetArchive);
|
||||
assertTrue(ret == ARCHIVE_OK, "AssetDataLoader::close: Failed to close archive!");
|
||||
|
||||
this->assetArchive = nullptr;
|
||||
this->assetArchiveEntry = nullptr;
|
||||
|
||||
// Close the file
|
||||
int32_t res = fclose(this->assetArchiveFile);
|
||||
this->assetArchiveFile = nullptr;
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::read(uint8_t *buffer, size_t size) {
|
||||
assertNotNull(buffer, "Buffer is NULL!");
|
||||
assertTrue(size > 0, "Size must be greater than 0!");
|
||||
assertNotNull(this->assetArchive, "assetRead: Archive is NULL!");
|
||||
assertNotNull(this->assetArchiveEntry, "assetRead: Entry is NULL!");
|
||||
|
||||
ssize_t read = archive_read_data(this->assetArchive, buffer, size);
|
||||
this->position += read;
|
||||
|
||||
if(read == ARCHIVE_FATAL) {
|
||||
assertUnreachable(archive_error_string(this->assetArchive));
|
||||
}
|
||||
|
||||
assertTrue(read != ARCHIVE_RETRY, "assetRead: Failed to read data (RETRY)!");
|
||||
assertTrue(read != ARCHIVE_WARN, "assetRead: Failed to read data (WARN)!");
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::readUntil(
|
||||
uint8_t *buffer,
|
||||
const size_t maxSize,
|
||||
const char_t delimiter
|
||||
) {
|
||||
size_t totalRead = this->read(buffer, maxSize);
|
||||
size_t i = 0;
|
||||
while(i < totalRead) {
|
||||
if(buffer[i] == delimiter) break;
|
||||
i++;
|
||||
}
|
||||
buffer[i++] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::getSize() {
|
||||
assertTrue(this->assetArchiveEntry != nullptr, "AssetDataLoader::getSize: Entry is NULL!");
|
||||
assertTrue(archive_entry_size_is_set(assetArchiveEntry), "assetGetSize: Entry size is not set!");
|
||||
return archive_entry_size(assetArchiveEntry);
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::skip(size_t n) {
|
||||
assertTrue(n >= 0, "AssetDataLoader::skip: Byte count must be greater than 0.");
|
||||
|
||||
uint8_t dumpBuffer[ASSET_LOADER_BUFFER_SIZE];
|
||||
size_t skipped = 0;
|
||||
size_t n2, n3;
|
||||
while(n != 0) {
|
||||
n2 = Math::min<size_t>(n, ASSET_LOADER_BUFFER_SIZE);
|
||||
n3 = this->read(dumpBuffer, n2);
|
||||
assertTrue(n3 == n2, "AssetDataLoader::skip: Failed to skip bytes!");
|
||||
n -= n3;
|
||||
}
|
||||
|
||||
return skipped;
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::setPosition(const size_t position) {
|
||||
assertTrue(position >= 0, "Position must be greater than or equal to 0");
|
||||
this->rewind();
|
||||
return this->skip(position);
|
||||
}
|
||||
|
||||
void AssetDataLoader::rewind() {
|
||||
// TODO: See if I can optimize this
|
||||
this->close();
|
||||
this->open();
|
||||
}
|
||||
|
||||
size_t AssetDataLoader::getPosition() {
|
||||
assertNotNull(this->assetArchiveFile, "AssetDataLoader::getPosition: File is not open!");
|
||||
return this->position;
|
||||
}
|
||||
|
||||
AssetDataLoader::~AssetDataLoader() {
|
||||
if(this->assetArchiveFile != nullptr) this->close();
|
||||
}
|
@@ -1,166 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
}
|
||||
|
||||
#define ASSET_LOADER_BUFFER_SIZE 32768
|
||||
|
||||
/**
|
||||
* Method invoked by the libarchive internals to read bytes from the archive
|
||||
* file pointer.
|
||||
*
|
||||
* @param archive Archive requesting the read.
|
||||
* @param data Data pointer passed to the archive.
|
||||
* @param buffer Pointer to where the buffer pointer should be stored.
|
||||
* @return Count of bytes read.
|
||||
*/
|
||||
ssize_t assetDataLoaderArchiveRead(
|
||||
struct archive *archive,
|
||||
void *data,
|
||||
const void **buffer
|
||||
);
|
||||
|
||||
/**
|
||||
* Method invoked by the libarchive internals to seek the archive file pointer.
|
||||
*
|
||||
* @param archive Archive requesting the seek.
|
||||
* @param data Data pointer passed to the archive.
|
||||
* @param offset Offset to seek to.
|
||||
* @param whence Whence to seek from.
|
||||
* @return The new offset.
|
||||
*/
|
||||
int64_t assetDataLoaderArchiveSeek(
|
||||
struct archive *archive,
|
||||
void *data,
|
||||
int64_t offset,
|
||||
int32_t whence
|
||||
);
|
||||
|
||||
/**
|
||||
* Method invoked by the libarchive internals to open the archive file pointer.
|
||||
*
|
||||
* @param archive Archive requesting the open.
|
||||
* @param data Data pointer passed to the archive.
|
||||
* @return 0 if success, otherwise for failure.
|
||||
*/
|
||||
int32_t assetDataLoaderArchiveOpen(struct archive *a, void *data);
|
||||
|
||||
/**
|
||||
* Method invoked by the libarchive internals to close the archive file pointer.
|
||||
*
|
||||
* @param archive Archive requesting the close.
|
||||
* @param data Data pointer passed to the archive.
|
||||
* @return 0 if success, otherwise for failure.
|
||||
*/
|
||||
int32_t assetDataLoaderArchiveClose(struct archive *a, void *data);
|
||||
|
||||
namespace Dawn {
|
||||
class AssetDataLoader {
|
||||
protected:
|
||||
struct archive *assetArchive = nullptr;
|
||||
struct archive_entry *assetArchiveEntry = nullptr;
|
||||
size_t position;
|
||||
std::string fileName;
|
||||
|
||||
public:
|
||||
uint8_t buffer[ASSET_LOADER_BUFFER_SIZE];
|
||||
FILE *assetArchiveFile = nullptr;
|
||||
|
||||
/**
|
||||
* Unimplemented method intended to be implemented by the platform that
|
||||
* will be used to request a File pointer to the asset.
|
||||
*
|
||||
* @return Pointer to the opened asset archive.
|
||||
*/
|
||||
FILE * openAssetArchiveFile();
|
||||
|
||||
/**
|
||||
* Create a new asset loader. Asset Loaders can be used to load data from
|
||||
* a file in a myriad of ways.
|
||||
*
|
||||
* @param fileName File name of the asset that is to be loaded.
|
||||
*/
|
||||
AssetDataLoader(std::string filename);
|
||||
|
||||
/**
|
||||
* Platform-centric method to open a file buffer to an asset.
|
||||
*/
|
||||
void open();
|
||||
|
||||
/**
|
||||
* Closes the previously ppened asset.
|
||||
* @return 0 if successful, otherwise false.
|
||||
*/
|
||||
int32_t close();
|
||||
|
||||
/**
|
||||
* Read bytes from buffer.
|
||||
* @param buffer Pointer to a ubyte array to buffer data into.
|
||||
* @param size Length of the data buffer (How many bytes to read).
|
||||
* @return The count of bytes read.
|
||||
*/
|
||||
size_t read(uint8_t *buffer, size_t size);
|
||||
|
||||
/**
|
||||
* Reads bytes from the buffer until a given delimiter is found. Returned
|
||||
* position will be the index of the delimiter within the buffer.
|
||||
*
|
||||
* @param buffer Buffer to read into.
|
||||
* @param maxSize Maximum size of the buffer.
|
||||
* @param delimiter Delimiter to read until.
|
||||
* @return The count of bytes read (including null terminator)
|
||||
*/
|
||||
size_t readUntil(
|
||||
uint8_t *buffer,
|
||||
const size_t maxSize,
|
||||
const char_t delimiter
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the size of the asset.
|
||||
* @return The size of the asset in bytes.
|
||||
*/
|
||||
size_t getSize();
|
||||
|
||||
/**
|
||||
* Skips the read head forward to a given position.
|
||||
*
|
||||
* @param n Count of bytes to progress the read head by.
|
||||
* @return Count of bytes progressed.
|
||||
*/
|
||||
size_t skip(size_t n);
|
||||
|
||||
/**
|
||||
* Rewind the read head to the beginning of the file.
|
||||
*/
|
||||
void rewind();
|
||||
|
||||
/**
|
||||
* Sets the absolute position of the read head within the buffer of the
|
||||
* file.
|
||||
*
|
||||
* @param absolutePosition Absolute position to set the read head to.
|
||||
*/
|
||||
size_t setPosition(const size_t absolutePosition);
|
||||
|
||||
/**
|
||||
* Returns the current position of the read head.
|
||||
*
|
||||
* @return The current read head position.
|
||||
*/
|
||||
size_t getPosition();
|
||||
|
||||
/**
|
||||
* Cleanup the asset loader.
|
||||
*/
|
||||
virtual ~AssetDataLoader();
|
||||
};
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AssetLoader.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
AssetLoader::AssetLoader(const std::string name) : name(name) {
|
||||
assertTrue(name.size() > 0, "Asset::Asset: Name cannot be empty");
|
||||
}
|
||||
|
||||
AssetLoader::~AssetLoader() {
|
||||
this->loaded = false;
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class AssetLoader {
|
||||
public:
|
||||
const std::string name;
|
||||
bool_t loaded = false;
|
||||
|
||||
/**
|
||||
* Create an abstract Asset object.
|
||||
*
|
||||
* @param name Name of the asset.
|
||||
*/
|
||||
AssetLoader(const std::string name);
|
||||
|
||||
/**
|
||||
* Virtual function that will be called by the asset manager on a
|
||||
* synchronous basis. This will only trigger if the blocks are false and
|
||||
* the loaded is also false.
|
||||
*/
|
||||
virtual void updateSync() = 0;
|
||||
|
||||
/**
|
||||
* Virtual function called by the asset manager asynchronously every tick.
|
||||
* This will only trigger if blocks are false and the loaded state is also
|
||||
* false.
|
||||
*/
|
||||
virtual void updateAsync() = 0;
|
||||
|
||||
/**
|
||||
* Dispose the asset item.
|
||||
*/
|
||||
virtual ~AssetLoader();
|
||||
};
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AssetManager.hpp"
|
||||
#include "loaders/TextureLoader.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void AssetManager::init() {
|
||||
|
||||
}
|
||||
|
||||
void AssetManager::update() {
|
||||
auto itPending = pendingAssetLoaders.begin();
|
||||
while(itPending != pendingAssetLoaders.end()) {
|
||||
auto loader = *itPending;
|
||||
loader->updateSync();
|
||||
loader->updateAsync();
|
||||
if(loader->loaded) {
|
||||
finishedAssetLoaders.push_back(loader);
|
||||
itPending = pendingAssetLoaders.erase(itPending);
|
||||
} else {
|
||||
itPending++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AssetManager::removeExisting(const std::string filename) {
|
||||
auto existing = std::find_if(
|
||||
pendingAssetLoaders.begin(), pendingAssetLoaders.end(),
|
||||
[&](auto &loader) {
|
||||
return loader->name == filename;
|
||||
}
|
||||
);
|
||||
if(existing != pendingAssetLoaders.end()) {
|
||||
pendingAssetLoaders.erase(existing);
|
||||
}
|
||||
|
||||
existing = std::find_if(
|
||||
finishedAssetLoaders.begin(), finishedAssetLoaders.end(),
|
||||
[&](auto &loader) {
|
||||
return loader->name == filename;
|
||||
}
|
||||
);
|
||||
if(existing != finishedAssetLoaders.end()) {
|
||||
finishedAssetLoaders.erase(existing);
|
||||
}
|
||||
}
|
||||
|
||||
bool_t AssetManager::isEverythingLoaded() {
|
||||
return pendingAssetLoaders.size() == 0;
|
||||
}
|
||||
|
||||
bool_t AssetManager::isLoaded(const std::string filename) {
|
||||
auto existing = this->getExisting<AssetLoader>(filename);
|
||||
if(existing) return existing->loaded;
|
||||
return false;
|
||||
}
|
||||
|
||||
AssetManager::~AssetManager() {
|
||||
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "asset/AssetLoader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class AssetManager final {
|
||||
private:
|
||||
std::vector<std::shared_ptr<AssetLoader>> pendingAssetLoaders;
|
||||
std::vector<std::shared_ptr<AssetLoader>> finishedAssetLoaders;
|
||||
|
||||
/**
|
||||
* Returns an existing asset loader if it exists.
|
||||
*
|
||||
* @param filename The filename of the asset to get.
|
||||
* @return The asset loader if it exists, otherwise nullptr.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> getExisting(const std::string filename) {
|
||||
auto existing = std::find_if(
|
||||
pendingAssetLoaders.begin(), pendingAssetLoaders.end(),
|
||||
[&](auto &loader) {
|
||||
return loader->name == filename;
|
||||
}
|
||||
);
|
||||
|
||||
if(existing == finishedAssetLoaders.end()) {
|
||||
existing = std::find_if(
|
||||
finishedAssetLoaders.begin(), finishedAssetLoaders.end(),
|
||||
[&](auto &loader) {
|
||||
return loader->name == filename;
|
||||
}
|
||||
);
|
||||
|
||||
if(existing == finishedAssetLoaders.end()) return nullptr;
|
||||
}
|
||||
|
||||
return std::static_pointer_cast<T>(*existing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an existing asset loader if it exists.
|
||||
*
|
||||
* @param filename The filename of the asset to remove.
|
||||
*/
|
||||
void removeExisting(const std::string filename);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Initializes this asset manager so it can begin accepting assets.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Updates the asset manager.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Returns whether the asset manager has loaded all of the currently
|
||||
* managed assets.
|
||||
*
|
||||
* @return True if all assets have been loaded.
|
||||
*/
|
||||
bool_t isEverythingLoaded();
|
||||
|
||||
/**
|
||||
* Returns whether the asset manager has loaded the given asset.
|
||||
*
|
||||
* @param filename The filename of the asset to check.
|
||||
* @return True if the asset has been loaded.
|
||||
*/
|
||||
bool_t isLoaded(const std::string filename);
|
||||
|
||||
/**
|
||||
* Returns the asset loader for the given asset.
|
||||
*
|
||||
* @param filename The filename of the asset to get.
|
||||
* @return The asset loader for the given asset.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> get(const std::string filename);
|
||||
|
||||
/**
|
||||
* Returns the asset loader for the given asset.
|
||||
*
|
||||
* @param filename The filename of the asset to get.
|
||||
* @param fontSize The font size to get the truetype asset of.
|
||||
* @return The asset loader for the given asset.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> get(
|
||||
const std::string filename,
|
||||
const uint32_t fontSize
|
||||
);
|
||||
|
||||
/**
|
||||
* Dispose the asset manager, and all attached assets.
|
||||
*/
|
||||
~AssetManager();
|
||||
};
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
AssetLoader.cpp
|
||||
AssetDataLoader.cpp
|
||||
AssetManager.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(loaders)
|
@@ -1,10 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TextureLoader.cpp
|
||||
)
|
@@ -1,147 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TextureLoader.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TextureLoader::TextureLoader(const std::string name) :
|
||||
AssetLoader(name),
|
||||
loader(name + ".texture"),
|
||||
state(TextureLoaderLoadState::INITIAL)
|
||||
{
|
||||
sharedTexture = std::make_shared<Texture>();
|
||||
weakTexture = sharedTexture;
|
||||
}
|
||||
|
||||
void TextureLoader::updateAsync() {
|
||||
if(this->state != TextureLoaderLoadState::INITIAL) return;
|
||||
this->state = TextureLoaderLoadState::ASYNC_LOADING;
|
||||
this->loader.open();
|
||||
|
||||
// Read in the header.
|
||||
uint8_t buffer[TEXTURE_LOADER_HEADER_SIZE];
|
||||
size_t pos = 0;
|
||||
|
||||
// Read Version
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
std::string version = std::string((char*)buffer);
|
||||
assertTrue(version == "DT_2.00", "Invalid Texture Version!");
|
||||
|
||||
// Read Texture Width
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
width = std::stoi(std::string((char*)buffer));
|
||||
assertTrue(width > 0, "Invalid Texture Width!");
|
||||
|
||||
// Read Texture Height
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
height = std::stoi(std::string((char*)buffer));
|
||||
assertTrue(height > 0, "Invalid Texture Height!");
|
||||
|
||||
// Texture Format (RGBA, RGB, etc)
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iFormat = std::stoi(std::string((char*)buffer));
|
||||
switch(iFormat) {
|
||||
case 1: format = TextureFormat::R; break;
|
||||
case 2: format = TextureFormat::RG; break;
|
||||
case 3: format = TextureFormat::RGB; break;
|
||||
case 4: format = TextureFormat::RGBA; break;
|
||||
default: assertUnreachable("Invalid Texture Format %i!", iFormat);
|
||||
}
|
||||
|
||||
// Wrap X
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iWrapX = std::stoi(std::string((char*)buffer));
|
||||
switch(iWrapX) {
|
||||
case 0: wrapX = TextureWrapMode::REPEAT; break;
|
||||
case 1: wrapX = TextureWrapMode::MIRRORED_REPEAT; break;
|
||||
case 2: wrapX = TextureWrapMode::CLAMP_TO_EDGE; break;
|
||||
case 3: wrapX = TextureWrapMode::CLAMP_TO_BORDER; break;
|
||||
default: assertUnreachable("Invalid Texture Wrap X %i!", iWrapX);
|
||||
}
|
||||
|
||||
// Wrap Y
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iWrapY = std::stoi(std::string((char*)buffer));
|
||||
switch(iWrapY) {
|
||||
case 0: wrapY = TextureWrapMode::REPEAT; break;
|
||||
case 1: wrapY = TextureWrapMode::MIRRORED_REPEAT; break;
|
||||
case 2: wrapY = TextureWrapMode::CLAMP_TO_EDGE; break;
|
||||
case 3: wrapY = TextureWrapMode::CLAMP_TO_BORDER; break;
|
||||
default: assertUnreachable("Invalid Texture Wrap Y %i!", iWrapY);
|
||||
}
|
||||
|
||||
// Filter Min
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iFilterMin = std::stoi(std::string((char*)buffer));
|
||||
switch(iFilterMin) {
|
||||
case 0: filterMin = TextureFilterMode::NEAREST; break;
|
||||
case 1: filterMin = TextureFilterMode::LINEAR; break;
|
||||
default: assertUnreachable("Invalid Texture Filter Min %i!", iFilterMin);
|
||||
}
|
||||
|
||||
// Filter Mag
|
||||
this->loader.setPosition(pos);
|
||||
pos += this->loader.readUntil(buffer, TEXTURE_LOADER_HEADER_SIZE, '|');
|
||||
int32_t iFilterMag = std::stoi(std::string((char*)buffer));
|
||||
switch(iFilterMag) {
|
||||
case 0: filterMag = TextureFilterMode::NEAREST; break;
|
||||
case 1: filterMag = TextureFilterMode::LINEAR; break;
|
||||
default: assertUnreachable("Invalid Texture Filter Mag %i!", iFilterMag);
|
||||
}
|
||||
|
||||
// Data begins here. This part is done synchronously directly to the GPU.
|
||||
this->loader.setPosition(pos);
|
||||
size_t bufferSize = width * height * iFormat;
|
||||
data = new uint8_t[bufferSize];
|
||||
assertNotNull(data, "Failed to allocate texture data!");
|
||||
this->loader.read(data, bufferSize);
|
||||
|
||||
// Handoff to sync to buffer to GPU.
|
||||
this->state = TextureLoaderLoadState::ASYNC_DONE;
|
||||
}
|
||||
|
||||
void TextureLoader::updateSync() {
|
||||
if(this->state != TextureLoaderLoadState::ASYNC_DONE) return;
|
||||
this->state = TextureLoaderLoadState::SYNC_LOADING;
|
||||
|
||||
assertNotNull(this->sharedTexture, "Texture is null!");
|
||||
assertNotNull(this->data, "Texture data is null!");
|
||||
|
||||
// Setup Texture
|
||||
this->sharedTexture->setSize(
|
||||
this->width,
|
||||
this->height,
|
||||
this->format,
|
||||
TextureDataFormat::UNSIGNED_BYTE
|
||||
);
|
||||
this->sharedTexture->buffer(this->data);
|
||||
|
||||
// Free data buffer
|
||||
delete[] this->data;
|
||||
this->data = nullptr;
|
||||
|
||||
// Leat go of the held pointer
|
||||
this->sharedTexture = nullptr;
|
||||
|
||||
// Hand off and call done
|
||||
this->state = TextureLoaderLoadState::SYNC_DONE;
|
||||
this->loaded = true;
|
||||
}
|
||||
|
||||
TextureLoader::~TextureLoader() {
|
||||
if(this->data != nullptr) {
|
||||
delete[] this->data;
|
||||
this->data = nullptr;
|
||||
}
|
||||
this->sharedTexture = nullptr;
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "asset/AssetLoader.hpp"
|
||||
#include "asset/AssetDataLoader.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
#define TEXTURE_LOADER_HEADER_SIZE 256
|
||||
|
||||
namespace Dawn {
|
||||
enum class TextureLoaderLoadState {
|
||||
INITIAL,
|
||||
ASYNC_LOADING,
|
||||
ASYNC_DONE,
|
||||
SYNC_LOADING,
|
||||
SYNC_DONE
|
||||
};
|
||||
|
||||
class TextureLoader : public AssetLoader {
|
||||
protected:
|
||||
AssetDataLoader loader;
|
||||
enum TextureLoaderLoadState state;
|
||||
uint8_t *data = nullptr;
|
||||
int32_t width = -1, height = -1;
|
||||
enum TextureFormat format;
|
||||
enum TextureWrapMode wrapX;
|
||||
enum TextureWrapMode wrapY;
|
||||
enum TextureFilterMode filterMin;
|
||||
enum TextureFilterMode filterMag;
|
||||
|
||||
public:
|
||||
std::shared_ptr<Texture> sharedTexture;
|
||||
std::weak_ptr<Texture> weakTexture;
|
||||
|
||||
/**
|
||||
* Constructs a texture asset loader. You should instead use the parent
|
||||
* asset managers' abstracted load method
|
||||
*
|
||||
* @param name File name asset to load, omitting the extension.
|
||||
*/
|
||||
TextureLoader(const std::string name);
|
||||
|
||||
void updateSync() override;
|
||||
void updateAsync() override;
|
||||
|
||||
/**
|
||||
* Dispose / Cleanup the texture asset. Will also dispose the underlying
|
||||
* texture itself.
|
||||
*/
|
||||
~TextureLoader();
|
||||
};
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
IAudioManager.cpp
|
||||
)
|
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "IAudioManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
IAudioManager::IAudioManager() {
|
||||
}
|
||||
|
||||
IAudioManager::~IAudioManager() {
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class IAudioManager {
|
||||
public:
|
||||
/**
|
||||
* Construct a new IAudioManager.
|
||||
*/
|
||||
IAudioManager();
|
||||
|
||||
/**
|
||||
* Initializes the audio manager system.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* Ticks/Update the audio manager system.
|
||||
*/
|
||||
virtual void update() = 0;
|
||||
|
||||
/**
|
||||
* Deinitializes the audio manager system.
|
||||
*/
|
||||
virtual ~IAudioManager();
|
||||
};
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
SimpleComponent.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(ui)
|
@@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SimpleComponent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void SimpleComponent::onInit() {
|
||||
this->initMethod(*this, events);
|
||||
}
|
||||
|
||||
void SimpleComponent::onDispose() {
|
||||
for(auto &event : events) {
|
||||
event();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SimpleComponent> Dawn::addSimpleComponent(
|
||||
std::shared_ptr<SceneItem> item,
|
||||
std::function<void(SceneComponent&, std::vector<std::function<void()>>&)> init
|
||||
) {
|
||||
auto cmp = item->addComponent<SimpleComponent>();
|
||||
cmp->initMethod = init;
|
||||
return cmp;
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/Scene.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleComponent final : public SceneComponent {
|
||||
private:
|
||||
std::vector<std::function<void()>> events;
|
||||
|
||||
public:
|
||||
std::function<void(
|
||||
SceneComponent&,
|
||||
std::vector<std::function<void()>>&
|
||||
)> initMethod;
|
||||
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
};
|
||||
|
||||
std::shared_ptr<SimpleComponent> addSimpleComponent(
|
||||
std::shared_ptr<SceneItem> item,
|
||||
std::function<void(
|
||||
SceneComponent&,
|
||||
std::vector<std::function<void()>>&
|
||||
)> init
|
||||
);
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Camera.cpp
|
||||
MeshRenderer.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(material)
|
@@ -1,67 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
#include "Camera.hpp"
|
||||
#include "game/Game.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void Camera::onInit() {
|
||||
this->onResizeListener = this->getRenderTarget()->onResize.listen([&](
|
||||
float_t width, float_t height
|
||||
) {
|
||||
this->onResize.emit(this->getRenderTarget(), width, height);
|
||||
});
|
||||
}
|
||||
|
||||
void Camera::onDispose() {
|
||||
renderTarget = nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderTarget> Camera::getRenderTarget() {
|
||||
if(this->renderTarget) return this->renderTarget;
|
||||
return getGame()->renderHost.getBackBufferRenderTarget();
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getProjection() {
|
||||
switch(this->type) {
|
||||
case CameraType::ORTHOGONAL:
|
||||
return glm::ortho(
|
||||
(float_t)this->orthoLeft,
|
||||
(float_t)this->orthoRight,
|
||||
(float_t)this->orthoBottom,
|
||||
(float_t)this->orthoTop,
|
||||
(float_t)this->clipNear,
|
||||
(float_t)this->clipFar
|
||||
);
|
||||
|
||||
case CameraType::PERSPECTIVE:
|
||||
return glm::perspective(
|
||||
(float_t)this->fov,
|
||||
this->getAspect(),
|
||||
(float_t)this->clipNear,
|
||||
(float_t)this->clipFar
|
||||
);
|
||||
}
|
||||
|
||||
assertUnreachable("Invalid Camera Type!");
|
||||
return glm::mat4(1.0f);
|
||||
}
|
||||
|
||||
float_t Camera::getAspect() {
|
||||
auto rt = this->getRenderTarget();
|
||||
return rt->getWidth() / rt->getHeight();
|
||||
}
|
||||
|
||||
void Camera::setRenderTarget(std::shared_ptr<RenderTarget> renderTarget) {
|
||||
onResizeListener();
|
||||
this->renderTarget = renderTarget;
|
||||
this->onResizeListener = this->getRenderTarget()->onResize.listen([&](
|
||||
float_t width, float_t height
|
||||
) {
|
||||
this->onResize.emit(this->getRenderTarget(), width, height);
|
||||
});
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItem.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum CameraType {
|
||||
PERSPECTIVE,
|
||||
ORTHOGONAL
|
||||
};
|
||||
|
||||
class Camera final : public SceneComponent {
|
||||
private:
|
||||
std::shared_ptr<RenderTarget> renderTarget;
|
||||
std::function<void()> onResizeListener;
|
||||
|
||||
public:
|
||||
Event<std::shared_ptr<RenderTarget>, float_t, float_t> onResize;
|
||||
float_t clipNear = 0.01f;
|
||||
float_t clipFar = 1000.0f;
|
||||
enum CameraType type = CameraType::PERSPECTIVE;
|
||||
|
||||
float_t fov = 0.785398f;
|
||||
|
||||
float_t orthoLeft = -1.0f;
|
||||
float_t orthoRight = 1.0f;
|
||||
float_t orthoBottom = -1.0f;
|
||||
float_t orthoTop = 1.0f;
|
||||
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
|
||||
/**
|
||||
* Returns the aspect ratio that the camera is using. In future I may
|
||||
* allow you to specify a custom ratio for stylistic reasons but for now I
|
||||
* just take the ratio of the specific frame buffer.
|
||||
*
|
||||
* @return The aspect ratio as a ratio of w/h.
|
||||
*/
|
||||
float_t getAspect();
|
||||
|
||||
/**
|
||||
* Returns the render target for this camera.
|
||||
*
|
||||
* @return Render target.
|
||||
*/
|
||||
std::shared_ptr<RenderTarget> getRenderTarget();
|
||||
|
||||
/**
|
||||
* Returns the projection matrix for this camera.
|
||||
*
|
||||
* @return Projection matrix.
|
||||
*/
|
||||
glm::mat4 getProjection();
|
||||
|
||||
/**
|
||||
* Sets the render target for this camera.
|
||||
*
|
||||
* @param renderTarget The render target to set.
|
||||
*/
|
||||
void setRenderTarget(std::shared_ptr<RenderTarget> renderTarget);
|
||||
};
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/pass/RenderPass.hpp"
|
||||
#include "display/pass/RenderPassContext.hpp"
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class IRenderableComponent {
|
||||
public:
|
||||
/**
|
||||
* Retreive the list of render passes for this component.
|
||||
*
|
||||
* @param ctx Context for the render pass.
|
||||
* @return List of render passes.
|
||||
*/
|
||||
virtual std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Short-hand function to create a render pass.
|
||||
*
|
||||
* @tparam S Shader type.
|
||||
* @tparam D Shader's data type
|
||||
* @param self Instance of the IRenderableComponent that is creating the pass.
|
||||
* @param data Data to use for the render pass.
|
||||
* @return Created render pass.
|
||||
*/
|
||||
template<class S, typename D>
|
||||
std::shared_ptr<IRenderPass> createRenderPass(
|
||||
SceneComponent &self,
|
||||
const D data,
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures = {},
|
||||
const std::shared_ptr<Mesh> mesh = nullptr,
|
||||
const enum MeshDrawMode drawMode = MeshDrawMode::TRIANGLES,
|
||||
int32_t indiceStart = 0,
|
||||
int32_t indiceCount = -1
|
||||
) {
|
||||
return std::make_shared<RenderPass<S,D>>(
|
||||
self,
|
||||
data,
|
||||
textures,
|
||||
mesh,
|
||||
drawMode,
|
||||
indiceStart,
|
||||
indiceCount
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "MeshRenderer.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void MeshRenderer::onInit() {
|
||||
|
||||
}
|
||||
|
||||
void MeshRenderer::onDispose() {
|
||||
mesh = nullptr;
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
#include "scene/SceneItem.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class MeshRenderer final : public SceneComponent {
|
||||
public:
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
};
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Material.cpp
|
||||
SimpleTexturedMaterial.cpp
|
||||
)
|
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Material.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void Material::onInit() {
|
||||
|
||||
}
|
||||
|
||||
void Material::onDispose() {
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneComponent.hpp"
|
||||
#include "component/display/IRenderableComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Material :
|
||||
public SceneComponent,
|
||||
public IRenderableComponent
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
};
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SimpleTexturedMaterial.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
struct Color SimpleTexturedMaterial::getColor() {
|
||||
return this->data.color;
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> SimpleTexturedMaterial::getTexture() {
|
||||
return this->texture;
|
||||
}
|
||||
|
||||
void SimpleTexturedMaterial::setTexture(std::shared_ptr<Texture> texture) {
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
void SimpleTexturedMaterial::setColor(const struct Color color) {
|
||||
this->data.color = color;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> SimpleTexturedMaterial::getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) {
|
||||
this->data.model = this->getItem()->getWorldTransform();
|
||||
this->data.projection = ctx.camera->getProjection();
|
||||
this->data.view = ctx.camera->getItem()->getWorldTransform();
|
||||
auto textures = std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
>();
|
||||
|
||||
if(this->texture) {
|
||||
this->data.hasTexture = true;
|
||||
this->data.texture = 0;
|
||||
textures[this->data.texture] = this->texture;
|
||||
} else {
|
||||
this->data.hasTexture = false;
|
||||
}
|
||||
|
||||
return {
|
||||
createRenderPass<SimpleTexturedShader, struct SimpleTexturedShaderData>(
|
||||
*this,
|
||||
data,
|
||||
textures
|
||||
)
|
||||
};
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "component/display/material/Material.hpp"
|
||||
#include "display/shader/SimpleTexturedShader.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleTexturedMaterial : public Material {
|
||||
private:
|
||||
struct SimpleTexturedShaderData data;
|
||||
std::shared_ptr<Texture> texture;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the color of this material.
|
||||
*/
|
||||
struct Color getColor();
|
||||
|
||||
/**
|
||||
* Returns the texture of this material.
|
||||
*
|
||||
* @return The texture of this material.
|
||||
*/
|
||||
std::shared_ptr<Texture> getTexture();
|
||||
|
||||
/**
|
||||
* Sets the texture of this material.
|
||||
*
|
||||
* @param texture The texture to set.
|
||||
*/
|
||||
void setTexture(std::shared_ptr<Texture> texture);
|
||||
|
||||
/**
|
||||
* Sets the color of this material.
|
||||
*
|
||||
* @param color The color to set.
|
||||
*/
|
||||
void setColor(const struct Color color);
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) override;
|
||||
};
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UICanvas.cpp
|
||||
)
|
@@ -1,144 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UICanvas.hpp"
|
||||
#include "display/pass/RenderPass.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
#include "ui/UIElement.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void UICanvas::onInit() {
|
||||
mesh = std::make_shared<Mesh>();
|
||||
mesh->createBuffers(
|
||||
QUAD_VERTICE_COUNT * UI_SHADER_QUAD_COUNT,
|
||||
QUAD_INDICE_COUNT * UI_SHADER_QUAD_COUNT
|
||||
);
|
||||
|
||||
for(int32_t i = 0; i < UI_SHADER_QUAD_COUNT; i++) {
|
||||
QuadMesh::bufferWithIndex(
|
||||
mesh,
|
||||
glm::vec4(0, 0, 1, 1),
|
||||
glm::vec4(0, 0, 1, 1),
|
||||
i * QUAD_VERTICE_COUNT,
|
||||
i * QUAD_INDICE_COUNT,
|
||||
i * QUAD_VERTICE_COUNT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void UICanvas::onDispose() {
|
||||
mesh = nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> UICanvas::getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) {
|
||||
if(this->elements.empty()) return {};
|
||||
|
||||
glm::mat4 projection;
|
||||
glm::mat4 view;
|
||||
|
||||
// Setup the projection and views
|
||||
data.projection = glm::ortho(
|
||||
0.0f, ctx.renderTarget->getWidth(),
|
||||
ctx.renderTarget->getHeight(), 0.0f,
|
||||
0.0f, 1.0f
|
||||
);
|
||||
data.view = glm::mat4(1.0f);
|
||||
data.model = glm::mat4(1.0f);
|
||||
|
||||
// Reset the passes
|
||||
this->passes.clear();
|
||||
this->textureBindings.clear();
|
||||
this->textures.clear();
|
||||
quadCount = 0;
|
||||
nextBinding = 0;
|
||||
|
||||
// Alignment root
|
||||
const glm::vec2 rootPosition = { 0, 0 };
|
||||
const glm::vec2 rootSize = {
|
||||
ctx.renderTarget->getWidth(),
|
||||
ctx.renderTarget->getHeight()
|
||||
};
|
||||
const float_t rootScale = 1.0f;
|
||||
|
||||
// Get the quads for each component
|
||||
auto itComponents = elements.begin();
|
||||
auto self = std::ref(*this);
|
||||
while(itComponents != elements.end()) {
|
||||
auto component = *itComponents;
|
||||
component->updateAlignment(rootPosition, rootSize, rootScale);
|
||||
component->getQuads(self);
|
||||
++itComponents;
|
||||
}
|
||||
|
||||
// Flush the remaining quads
|
||||
flushPass();
|
||||
return passes;
|
||||
}
|
||||
|
||||
void UICanvas::addQuad(
|
||||
const glm::vec4 quad,
|
||||
const glm::vec4 uvs,
|
||||
const struct Color color,
|
||||
const enum UIShaderQuadStyle style,
|
||||
const std::shared_ptr<Texture> text
|
||||
) {
|
||||
glm::vec4 styleData;
|
||||
styleData[0] = (float_t)style;
|
||||
|
||||
if(text == nullptr) {
|
||||
styleData[1] = -1;
|
||||
} else {
|
||||
shadertexturebinding_t texture;
|
||||
auto bindingIt = textureBindings.find(text);
|
||||
if(bindingIt == textureBindings.end()) {
|
||||
if(nextBinding >= UI_SHADER_TEXTURE_COUNT) {
|
||||
flushPass();
|
||||
}
|
||||
textureBindings[text] = nextBinding;
|
||||
textures[nextBinding] = text;
|
||||
data.textures[nextBinding] = nextBinding;
|
||||
texture = nextBinding++;
|
||||
} else {
|
||||
texture = bindingIt->second;
|
||||
}
|
||||
styleData[1] = (float_t)texture;
|
||||
}
|
||||
|
||||
data.quads[quadCount] = {
|
||||
quad,
|
||||
uvs,
|
||||
color,
|
||||
styleData
|
||||
};
|
||||
quadCount++;
|
||||
if(quadCount == UI_SHADER_QUAD_COUNT) flushPass();
|
||||
}
|
||||
|
||||
void UICanvas::flushPass() {
|
||||
if(quadCount == 0) return;
|
||||
|
||||
auto pass = createRenderPass<UIShader, UIShaderData>(
|
||||
std::ref(*this),
|
||||
data,
|
||||
textures,
|
||||
mesh,
|
||||
MeshDrawMode::TRIANGLES,
|
||||
0,
|
||||
quadCount * QUAD_INDICE_COUNT
|
||||
);
|
||||
passes.push_back(pass);
|
||||
|
||||
quadCount = 0;
|
||||
nextBinding = 0;
|
||||
textures.clear();
|
||||
textureBindings.clear();
|
||||
}
|
||||
|
||||
void UICanvas::addElement(std::shared_ptr<UIElement> element) {
|
||||
elements.push_back(element);
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItem.hpp"
|
||||
#include "component/display/IRenderableComponent.hpp"
|
||||
#include "display/shader/UIShader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIElement;
|
||||
|
||||
class UICanvas :
|
||||
public SceneComponent,
|
||||
public IRenderableComponent
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
UIShaderData data;
|
||||
std::vector<std::shared_ptr<UIElement>> elements;
|
||||
|
||||
size_t quadCount = 0;
|
||||
shadertexturebinding_t nextBinding = 0;
|
||||
std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures;
|
||||
std::map<
|
||||
std::shared_ptr<Texture>, shadertexturebinding_t
|
||||
> textureBindings;
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> passes;
|
||||
|
||||
protected:
|
||||
virtual void onInit() override;
|
||||
virtual void onDispose() override;
|
||||
|
||||
/**
|
||||
* Flushes all pending quads to the render pass. This doesn't actually
|
||||
* render anything, it just flushes the data buffer to a new pass.
|
||||
*/
|
||||
void flushPass();
|
||||
|
||||
public:
|
||||
std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) override;
|
||||
|
||||
/**
|
||||
* Adds a quad to the canvas and performs a flush if necessary.
|
||||
*
|
||||
* @param quad The quad to add.
|
||||
* @param uvs The UVs to use for the quad.
|
||||
* @param color The color to use for the quad.
|
||||
* @param style Style that the quad should be rendered in.
|
||||
* @param texture The texture to use for the quad, can be null.
|
||||
*/
|
||||
void addQuad(
|
||||
const glm::vec4 quad,
|
||||
const glm::vec4 uvs,
|
||||
const struct Color color,
|
||||
const enum UIShaderQuadStyle style,
|
||||
const std::shared_ptr<Texture> texture = nullptr
|
||||
);
|
||||
|
||||
/**
|
||||
* Adds a component to the canvas.
|
||||
*
|
||||
* @param component The component to add.
|
||||
*/
|
||||
void addElement(std::shared_ptr<UIElement> component);
|
||||
};
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
// Static Libs
|
||||
extern "C" {
|
||||
// Standard Libs
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
|
||||
typedef bool bool_t;
|
||||
typedef char char_t;
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <cstdarg>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
// #include <glm/gtx/component_wise.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
// #include <glm/gtx/intersect.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL 1
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
@@ -1,16 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Color.cpp
|
||||
RenderPipeline.cpp
|
||||
IRenderHost.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(mesh)
|
||||
add_subdirectory(shader)
|
@@ -1,84 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Color.hpp"
|
||||
#include "util/String.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
struct Color Color::fromString(const std::string str) {
|
||||
// Convert to lowercase
|
||||
auto lower = String::toLowercase(str);
|
||||
|
||||
if(String::includes(lower, "cornflower")) {
|
||||
return COLOR_CORNFLOWER_BLUE;
|
||||
|
||||
} else if(String::includes(lower, "magenta")) {
|
||||
return COLOR_MAGENTA;
|
||||
|
||||
} else if(String::includes(lower, "white")) {
|
||||
return COLOR_WHITE;
|
||||
|
||||
} else if(String::includes(lower, "black")) {
|
||||
return COLOR_BLACK;
|
||||
|
||||
} else if(String::includes(lower, "red")) {
|
||||
return COLOR_RED;
|
||||
|
||||
} else if(String::includes(lower, "green")) {
|
||||
return COLOR_GREEN;
|
||||
|
||||
} else if(String::includes(lower, "blue")) {
|
||||
return COLOR_BLUE;
|
||||
|
||||
} else if(String::includes(lower, "transparent")) {
|
||||
return COLOR_TRANSPARENT;
|
||||
}
|
||||
|
||||
// Hex code?
|
||||
if(lower[0] == '#') {
|
||||
// Remove the hash
|
||||
lower = lower.substr(1);
|
||||
|
||||
// Convert to RGB
|
||||
if(lower.length() == 3) {
|
||||
// Convert to 6 digit hex
|
||||
lower = lower[0] + lower[0] + lower[1] + lower[1] + lower[2] + lower[2];
|
||||
}
|
||||
|
||||
// Convert to RGB
|
||||
return {
|
||||
(float_t)std::stoi(lower.substr(0, 2), nullptr, 16) / 255.0f,
|
||||
(float_t)std::stoi(lower.substr(2, 2), nullptr, 16) / 255.0f,
|
||||
(float_t)std::stoi(lower.substr(4, 2), nullptr, 16) / 255.0f,
|
||||
1.0f
|
||||
};
|
||||
}
|
||||
|
||||
// Split by comma
|
||||
auto splitByComma = String::split(str, ",");
|
||||
if(splitByComma.size() == 3) {
|
||||
// RGB
|
||||
return {
|
||||
(float_t)std::stof(splitByComma[0]),
|
||||
(float_t)std::stof(splitByComma[1]),
|
||||
(float_t)std::stof(splitByComma[2]),
|
||||
1.0f
|
||||
};
|
||||
} else if(splitByComma.size() == 4) {
|
||||
// RGBA
|
||||
return {
|
||||
(float_t)std::stof(splitByComma[0]),
|
||||
(float_t)std::stof(splitByComma[1]),
|
||||
(float_t)std::stof(splitByComma[2]),
|
||||
(float_t)std::stof(splitByComma[3])
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Parse other kinds of colors
|
||||
assertUnreachable("Failed to find a color match for %s", str);
|
||||
return {};
|
||||
}
|
@@ -1,89 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct ColorU8 {
|
||||
uint8_t r, g, b, a;
|
||||
};
|
||||
|
||||
struct Color final {
|
||||
/**
|
||||
* Returns a color from a string.
|
||||
*
|
||||
* @param str String to parse.
|
||||
* @return Color parsed.
|
||||
*/
|
||||
static struct Color fromString(const std::string str);
|
||||
|
||||
float_t r, g, b, a;
|
||||
|
||||
const struct Color& operator = (const struct Color &val) {
|
||||
this->r = val.r;
|
||||
this->g = val.g;
|
||||
this->b = val.b;
|
||||
this->a = val.a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
struct Color operator * (const float_t &x) {
|
||||
return {
|
||||
r * x,
|
||||
g * x,
|
||||
b * x,
|
||||
a * x
|
||||
};
|
||||
}
|
||||
|
||||
struct Color operator - (const struct Color &color) {
|
||||
return {
|
||||
r - color.r,
|
||||
g - color.g,
|
||||
b - color.b,
|
||||
a - color.a
|
||||
};
|
||||
}
|
||||
|
||||
struct Color operator + (const struct Color &color) {
|
||||
return {
|
||||
r + color.r,
|
||||
g + color.g,
|
||||
b + color.b,
|
||||
a + color.a
|
||||
};
|
||||
}
|
||||
|
||||
const bool_t operator == (const struct Color &other) {
|
||||
return r == other.r && g == other.g && b == other.b && a == other.a;
|
||||
}
|
||||
|
||||
operator struct ColorU8() const {
|
||||
return {
|
||||
(uint8_t)(r * 255),
|
||||
(uint8_t)(g * 255),
|
||||
(uint8_t)(b * 255),
|
||||
(uint8_t)(a * 255)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
#define COLOR_DEF(r,g,b,a) { r, g, b, a }
|
||||
#define COLOR_WHITE COLOR_DEF(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
#define COLOR_RED COLOR_DEF(1.0f, 0, 0, 1.0f)
|
||||
#define COLOR_GREEN COLOR_DEF(0, 1.0f, 0, 1.0f)
|
||||
#define COLOR_BLUE COLOR_DEF(0, 0, 1.0f, 1.0f)
|
||||
#define COLOR_BLACK COLOR_DEF(0, 0, 0, 1.0f)
|
||||
#define COLOR_MAGENTA COLOR_DEF(1.0f, 0, 1.0f, 1.0f)
|
||||
#define COLOR_DARK_GREY COLOR_DEF(0.2f, 0.2f, 0.2f, 1.0f)
|
||||
#define COLOR_LIGHT_GREY COLOR_DEF(0.8f, 0.8f, 0.8f, 1.0f)
|
||||
#define COLOR_CORNFLOWER_BLUE COLOR_DEF(0.4f, 0.6f, 0.9f, 1.0f)
|
||||
#define COLOR_WHITE_TRANSPARENT COLOR_DEF(1.0f, 1.0f, 1.0f, 0.0f)
|
||||
#define COLOR_BLACK_TRANSPARENT COLOR_DEF(0.0f, 0.0f, 0.0f, 0.0f)
|
||||
#define COLOR_YELLOW COLOR_DEF(1.0f, 1.0f, 0.0f, 1.0f)
|
||||
#define COLOR_CYAN COLOR_DEF(0.0f, 1.0f, 1.0f, 1.0f)
|
||||
#define COLOR_TRANSPARENT COLOR_WHITE_TRANSPARENT
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "IRenderHost.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
IRenderHost::IRenderHost() : renderPipeline(), shaderManager() {
|
||||
}
|
||||
|
||||
IRenderHost::~IRenderHost() {
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
#include "display/RenderPipeline.hpp"
|
||||
#include "display/shader/ShaderManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Game;
|
||||
|
||||
class IRenderHost {
|
||||
public:
|
||||
RenderPipeline renderPipeline;
|
||||
ShaderManager shaderManager;
|
||||
|
||||
/**
|
||||
* Creates a render host.
|
||||
*/
|
||||
IRenderHost();
|
||||
|
||||
/**
|
||||
* Initializes the render host, called by the game during the initial
|
||||
* set up of the engine.
|
||||
*
|
||||
* @param game Game that requested the render host to initialize.
|
||||
*/
|
||||
virtual void init(const std::shared_ptr<Game> game) = 0;
|
||||
|
||||
/**
|
||||
* Performs an update/tick of the render host. This would be the game
|
||||
* asking the RenderHost to do the rendering.
|
||||
*/
|
||||
virtual void update(const std::shared_ptr<Game> game) = 0;
|
||||
|
||||
/**
|
||||
* Overridable request from the game that asks if the RenderHost has any
|
||||
* reason that it should need to close. For most libraries this would be
|
||||
* whether or not the window was closed.
|
||||
*
|
||||
* @return True if the render host requests the game to gracefully exit.
|
||||
*/
|
||||
virtual bool_t isCloseRequested() = 0;
|
||||
|
||||
/**
|
||||
* Returns the back buffer render target. This is the render target that
|
||||
* is used to render to the screen.
|
||||
*
|
||||
* @return The back buffer render target.
|
||||
*/
|
||||
virtual std::shared_ptr<RenderTarget> getBackBufferRenderTarget() = 0;
|
||||
|
||||
/**
|
||||
* Destroys the render host.
|
||||
*/
|
||||
virtual ~IRenderHost();
|
||||
};
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/Color.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class TextureFormat {
|
||||
R = 1,
|
||||
RG = 2,
|
||||
RGB = 3,
|
||||
RGBA = 4
|
||||
};
|
||||
|
||||
enum class TextureWrapMode {
|
||||
REPEAT = 0,
|
||||
MIRRORED_REPEAT = 1,
|
||||
CLAMP_TO_EDGE = 2,
|
||||
CLAMP_TO_BORDER = 3
|
||||
};
|
||||
|
||||
enum class TextureFilterMode {
|
||||
NEAREST = 0,
|
||||
LINEAR = 1
|
||||
};
|
||||
|
||||
enum class TextureDataFormat {
|
||||
UNSIGNED_BYTE = sizeof(uint8_t),
|
||||
FLOAT = sizeof(float_t)
|
||||
};
|
||||
|
||||
class ITexture {
|
||||
public:
|
||||
enum TextureWrapMode wrapModeX = TextureWrapMode::REPEAT;
|
||||
enum TextureWrapMode wrapModeY = TextureWrapMode::REPEAT;
|
||||
enum TextureFilterMode filterModeMin = TextureFilterMode::NEAREST;
|
||||
enum TextureFilterMode filterModeMag = TextureFilterMode::NEAREST;
|
||||
enum TextureFilterMode mipMapFilterModeMin = TextureFilterMode::NEAREST;
|
||||
enum TextureFilterMode mipMapFilterModeMag = TextureFilterMode::NEAREST;
|
||||
|
||||
/**
|
||||
* Returns the width of the texture.
|
||||
*
|
||||
* @return Width of the texture.
|
||||
*/
|
||||
virtual int32_t getWidth() = 0;
|
||||
|
||||
/**
|
||||
* Returns the height of the texture.
|
||||
*
|
||||
* @return Height of the texture.
|
||||
*/
|
||||
virtual int32_t getHeight() = 0;
|
||||
|
||||
/**
|
||||
* Initializes a texture.
|
||||
*
|
||||
* @param width Width of the texture (in pixels).
|
||||
* @param height Height of the texture (in pixels).
|
||||
* @param format Data format of the texture to use.
|
||||
* @param dataFormat Data format of the texture to use.
|
||||
*/
|
||||
virtual void setSize(
|
||||
const int32_t width,
|
||||
const int32_t height,
|
||||
const enum TextureFormat format,
|
||||
const enum TextureDataFormat dataFormat
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Returns true only when the texture has been loaded, sized and put on
|
||||
* the gpu for rendering.
|
||||
*
|
||||
* @return True if ready, otherwise false.
|
||||
*/
|
||||
virtual bool_t isReady() = 0;
|
||||
|
||||
/**
|
||||
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
|
||||
* avoid doing this too often.
|
||||
*
|
||||
* @param pixels Array of pixels you're trying to buffer.
|
||||
*/
|
||||
virtual void buffer(const struct ColorU8 pixels[]) = 0;
|
||||
|
||||
/**
|
||||
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
|
||||
* avoid doing this too often.
|
||||
*
|
||||
* @param pixels Array of pixels you're trying to buffer.
|
||||
*/
|
||||
virtual void buffer(const struct Color pixels[]) = 0;
|
||||
|
||||
/**
|
||||
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
|
||||
* avoid doing this too often.
|
||||
*
|
||||
* @param pixels Array of pixels you're trying to buffer.
|
||||
*/
|
||||
virtual void buffer(const uint8_t pixels[]) = 0;
|
||||
|
||||
/**
|
||||
* Binds the texture to the given slot (for use by the shaders).
|
||||
*
|
||||
* @param slot Slot to bind to.
|
||||
*/
|
||||
virtual void bind(const uint8_t slot) = 0;
|
||||
|
||||
/**
|
||||
* Disposes of the texture.
|
||||
*/
|
||||
virtual ~ITexture() {
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
#include "RenderPipeline.hpp"
|
||||
#include "game/Game.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "component/display/Camera.hpp"
|
||||
#include "component/display/IRenderableComponent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
RenderPipeline::RenderPipeline() {
|
||||
|
||||
}
|
||||
|
||||
void RenderPipeline::render(
|
||||
const std::shared_ptr<Game> game
|
||||
) {
|
||||
assertNotNull(game, "Game cannot be null");
|
||||
|
||||
auto scene = game->getCurrentScene();
|
||||
if(!scene) return;
|
||||
|
||||
this->renderScene(game, scene);
|
||||
}
|
||||
|
||||
void RenderPipeline::renderScene(
|
||||
const std::shared_ptr<Game> game,
|
||||
const std::shared_ptr<Scene> scene
|
||||
) {
|
||||
assertNotNull(game, "Game cannot be null");
|
||||
assertNotNull(scene, "Scene cannot be null");
|
||||
|
||||
// TODO: Render Subscenes First
|
||||
|
||||
// Get a list of all cameras in the scene
|
||||
auto cameras = scene->findComponents<Camera>();
|
||||
auto backBuffer = scene->getGame()->renderHost.getBackBufferRenderTarget();
|
||||
|
||||
std::shared_ptr<Camera> backbufferCamera = nullptr;
|
||||
for(auto camera : cameras) {
|
||||
auto rt = camera->getRenderTarget();
|
||||
// Is this camera the backbuffer camera?
|
||||
if(rt == backBuffer) {
|
||||
backbufferCamera = camera;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Render scene with this camera
|
||||
renderSceneCamera(game, scene, camera, rt);
|
||||
}
|
||||
|
||||
if(backbufferCamera) {
|
||||
// Render the backbuffer camera
|
||||
renderSceneCamera(game, scene, backbufferCamera, backBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPipeline::renderSceneCamera(
|
||||
const std::shared_ptr<Game> game,
|
||||
const std::shared_ptr<Scene> scene,
|
||||
const std::shared_ptr<Camera> camera,
|
||||
const std::shared_ptr<RenderTarget> renderTarget
|
||||
) {
|
||||
assertNotNull(game, "Game cannot be null");
|
||||
assertNotNull(scene, "Scene cannot be null");
|
||||
assertNotNull(camera, "Camera cannot be null");
|
||||
assertNotNull(renderTarget, "RenderTarget cannot be null");
|
||||
|
||||
struct RenderPassContext ctx = {
|
||||
game,
|
||||
scene,
|
||||
camera,
|
||||
renderTarget
|
||||
};
|
||||
|
||||
// Get list of renderables
|
||||
std::vector<std::shared_ptr<IRenderPass>> renderPasses;
|
||||
auto renderables = scene->findComponents<IRenderableComponent>();
|
||||
for(auto renderable : renderables) {
|
||||
auto rp = renderable->getPasses(ctx);
|
||||
renderPasses.insert(renderPasses.end(), rp.begin(), rp.end());
|
||||
}
|
||||
|
||||
// TODO: Make clearing the buffers editable!
|
||||
renderTarget->bind();
|
||||
renderTarget->clear(
|
||||
RENDER_TARGET_CLEAR_COLOR |
|
||||
RENDER_TARGET_CLEAR_DEPTH
|
||||
);
|
||||
|
||||
for(auto renderPass : renderPasses) {
|
||||
renderPass->bind();
|
||||
renderPass->setData();
|
||||
renderPass->upload();
|
||||
renderPass->draw();
|
||||
}
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Game;
|
||||
class Scene;
|
||||
class Camera;
|
||||
class RenderTarget;
|
||||
|
||||
class RenderPipeline {
|
||||
public:
|
||||
/**
|
||||
* Creates a new RenderPipeline.
|
||||
*/
|
||||
RenderPipeline();
|
||||
|
||||
/**
|
||||
* Renders the game. This will render the current scene.
|
||||
*
|
||||
* @param game Game to render.
|
||||
*/
|
||||
void render(
|
||||
const std::shared_ptr<Game> game
|
||||
);
|
||||
|
||||
/**
|
||||
* Renders a specific scene. This will render all cameras within the
|
||||
* scene.
|
||||
*
|
||||
* @param game Game to render.
|
||||
* @param scene Scene to render.
|
||||
*/
|
||||
void renderScene(
|
||||
const std::shared_ptr<Game> game,
|
||||
const std::shared_ptr<Scene> scene
|
||||
);
|
||||
|
||||
/**
|
||||
* Renders a specific scene with a specific camera.
|
||||
*
|
||||
* @param game Game to render.
|
||||
* @param scene Scene to render.
|
||||
* @param camera Camera to render.
|
||||
* @param renderTarget Render target to render to.
|
||||
*/
|
||||
void renderSceneCamera(
|
||||
const std::shared_ptr<Game> game,
|
||||
const std::shared_ptr<Scene> scene,
|
||||
const std::shared_ptr<Camera> camera,
|
||||
const std::shared_ptr<RenderTarget> renderTarget
|
||||
);
|
||||
|
||||
/**
|
||||
* Destroys the RenderPipeline.
|
||||
*/
|
||||
virtual ~RenderPipeline();
|
||||
};
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "event/Event.hpp"
|
||||
|
||||
#define RENDER_TARGET_CLEAR_COLOR (1 << 0)
|
||||
#define RENDER_TARGET_CLEAR_DEPTH (1 << 1)
|
||||
|
||||
namespace Dawn {
|
||||
class RenderTarget {
|
||||
public:
|
||||
Event<float_t, float_t> onResize;
|
||||
|
||||
/**
|
||||
* Return the width of the render target.
|
||||
*
|
||||
* @return The width of the render target.
|
||||
*/
|
||||
virtual float_t getWidth() = 0;
|
||||
|
||||
/**
|
||||
* Return the height of the render target.
|
||||
*
|
||||
* @return The height of the render target.
|
||||
*/
|
||||
virtual float_t getHeight() = 0;
|
||||
|
||||
/**
|
||||
* Returns the scale (as in pixel density) of the render target. This is
|
||||
* typically 1.0f, but on high DPI displays this may be 2.0f or higher.
|
||||
*
|
||||
* @return The scale of the render target.
|
||||
*/
|
||||
virtual float_t getScale() = 0;
|
||||
|
||||
/**
|
||||
* Sets the clear color of the render target when the clear method for
|
||||
* the color buffer is requested.
|
||||
*
|
||||
* @param color Color to use for the clear operation.
|
||||
*/
|
||||
virtual void setClearColor(const struct Color color) = 0;
|
||||
|
||||
/**
|
||||
* Request the existing data in the render target to be cleared out. We
|
||||
* typically assume the render target can support multiple buffer types,
|
||||
* so you can opt to only clear certain buffer types.
|
||||
*
|
||||
* @param clearFlags Flags to request what is going to be cleared.
|
||||
*/
|
||||
virtual void clear(const int32_t clearFlags) = 0;
|
||||
|
||||
/**
|
||||
* Bind the render target for rendering to. The proceeding render requests
|
||||
* will want to render to this render target directly. In future I may
|
||||
* see if we can have multiple render targets bound at once to make this
|
||||
* operation perform faster.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Destroys the render target.
|
||||
*/
|
||||
virtual ~RenderTarget() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
CubeMesh.cpp
|
||||
QuadMesh.cpp
|
||||
)
|
@@ -1,70 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CubeMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void CubeMesh::buffer(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec3 pos,
|
||||
const glm::vec3 size,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart
|
||||
) {
|
||||
glm::vec3 positions[CUBE_VERTICE_COUNT] = {
|
||||
pos,
|
||||
glm::vec3(pos.x+size.x, pos.y, pos.z),
|
||||
glm::vec3(pos.x, pos.y+size.y, pos.z),
|
||||
glm::vec3(pos.x+size.x, pos.y+size.y, pos.z),
|
||||
|
||||
glm::vec3(pos.x, pos.y, pos.z+size.z),
|
||||
glm::vec3(pos.x+size.x, pos.y, pos.z+size.z),
|
||||
glm::vec3(pos.x, pos.y+size.y, pos.z+size.z),
|
||||
pos + size
|
||||
};
|
||||
|
||||
glm::vec2 coordinates[CUBE_VERTICE_COUNT] = {
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(1, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 1),
|
||||
|
||||
glm::vec2(0, 0),
|
||||
glm::vec2(1, 0),
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(1, 1)
|
||||
};
|
||||
|
||||
int32_t indices[CUBE_INDICE_COUNT] = {
|
||||
// Back
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3,
|
||||
|
||||
// Right
|
||||
verticeStart + 1, verticeStart + 5, verticeStart + 7,
|
||||
verticeStart + 1, verticeStart + 3, verticeStart + 7,
|
||||
|
||||
// Left
|
||||
verticeStart + 4, verticeStart, verticeStart + 2,
|
||||
verticeStart + 4, verticeStart + 6, verticeStart + 2,
|
||||
|
||||
// Front
|
||||
verticeStart + 5, verticeStart + 4, verticeStart + 6,
|
||||
verticeStart + 5, verticeStart + 7, verticeStart + 6,
|
||||
|
||||
// Top
|
||||
verticeStart + 7, verticeStart + 2, verticeStart + 6,
|
||||
verticeStart + 7, verticeStart + 3, verticeStart + 2,
|
||||
|
||||
// Bottom
|
||||
verticeStart + 1, verticeStart, verticeStart + 4,
|
||||
verticeStart + 1, verticeStart + 4, verticeStart + 5
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, positions, CUBE_VERTICE_COUNT);
|
||||
mesh->bufferCoordinates(verticeStart, coordinates, CUBE_VERTICE_COUNT);
|
||||
mesh->bufferIndices(indiceStart, indices, CUBE_INDICE_COUNT);
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
#define CUBE_VERTICE_COUNT 8
|
||||
#define CUBE_INDICE_COUNT 36
|
||||
|
||||
namespace Dawn {
|
||||
class CubeMesh {
|
||||
public:
|
||||
/**
|
||||
* Buffers cube mesh vertices and indices into the given mesh.
|
||||
*
|
||||
* @param size The size of the cube.
|
||||
* @param verticeStart The starting index of the vertices.
|
||||
* @param indiceStart The starting index of the indices.
|
||||
*/
|
||||
static void buffer(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec3 pos,
|
||||
const glm::vec3 size,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart
|
||||
);
|
||||
};
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum MeshDrawMode {
|
||||
TRIANGLES,
|
||||
TRIANGLE_STRIP,
|
||||
TRIANGLE_FAN,
|
||||
LINES,
|
||||
POINTS
|
||||
// LINE_STRIP,
|
||||
};
|
||||
|
||||
class IMesh {
|
||||
protected:
|
||||
/** How many vertices are in the mesh */
|
||||
int32_t verticeCount = -1;
|
||||
/** How many indices are in the mesh */
|
||||
int32_t indiceCount = -1;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a new set of buffers for the mesh to use.
|
||||
*
|
||||
* @param verticeCount How many Vertices will this buffer support.
|
||||
* @param indiceCount How many Indices will this buffer support.
|
||||
*/
|
||||
virtual void createBuffers(
|
||||
const int32_t verticeCount,
|
||||
const int32_t indiceCount
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Cleanup the buffers on a given mesh. This is useful if you intend to
|
||||
* expand the count of vertices your mesh supports.
|
||||
*/
|
||||
virtual void disposeBuffers() = 0;
|
||||
|
||||
/**
|
||||
* Write vertice positions to the mesh.
|
||||
*
|
||||
* @param pos Position, within the buffer, to write to.
|
||||
* @param vertices Array of positions to write.
|
||||
* @param len How many positions are in the array.
|
||||
*/
|
||||
virtual void bufferPositions(
|
||||
const int32_t pos,
|
||||
const glm::vec3 positions[],
|
||||
const int32_t len
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Write vertice coordinates to the mesh.
|
||||
*
|
||||
* @param pos Position, within the buffer, to write to.
|
||||
* @param coordinates Array of coordinates to write.
|
||||
* @param len How many coordinates are in the array.
|
||||
*/
|
||||
virtual void bufferCoordinates(
|
||||
const int32_t pos,
|
||||
const glm::vec2 coordinates[],
|
||||
const int32_t len
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Write indices to the mesh.
|
||||
*
|
||||
* @param pos Position, within the buffer, to write to.
|
||||
* @param indices Array of indices to write.
|
||||
* @param len How many indices are in the array.
|
||||
*/
|
||||
virtual void bufferIndices(
|
||||
const int32_t pos,
|
||||
const int32_t indices[],
|
||||
const int32_t len
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Draw a primitive. Primitives are drawn by their indices.
|
||||
*
|
||||
* @param drawMode Which drawing mode to use to draw the primitive.
|
||||
* @param start Start indice (index) to draw.
|
||||
* @param count Count of indices to draw. Use -1 to draw all.
|
||||
*/
|
||||
virtual void draw(
|
||||
const enum MeshDrawMode drawMode,
|
||||
const int32_t start,
|
||||
const int32_t count
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Cleanup a previously initiated mesh.
|
||||
*/
|
||||
virtual ~IMesh() {
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "QuadMesh.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void QuadMesh::buffer(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const float_t depth
|
||||
) {
|
||||
glm::vec3 vertices[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec3(positions.x, positions.y, depth),
|
||||
glm::vec3(positions.z, positions.y, depth),
|
||||
glm::vec3(positions.x, positions.w, depth),
|
||||
glm::vec3(positions.z, positions.w, depth)
|
||||
};
|
||||
|
||||
glm::vec2 coords[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec2(coordinates.x, coordinates.y),
|
||||
glm::vec2(coordinates.z, coordinates.y),
|
||||
glm::vec2(coordinates.x, coordinates.w),
|
||||
glm::vec2(coordinates.z, coordinates.w)
|
||||
};
|
||||
|
||||
int32_t indices[QUAD_INDICE_COUNT] = {
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, vertices, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferCoordinates(verticeStart, coords, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
|
||||
}
|
||||
|
||||
void QuadMesh::bufferWithIndex(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const int32_t indexOffset
|
||||
) {
|
||||
glm::vec3 vertices[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec3(positions.x, positions.y, indexOffset),
|
||||
glm::vec3(positions.z, positions.y, indexOffset + 1),
|
||||
glm::vec3(positions.x, positions.w, indexOffset + 2),
|
||||
glm::vec3(positions.z, positions.w, indexOffset + 3)
|
||||
};
|
||||
|
||||
glm::vec2 coords[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec2(coordinates.x, coordinates.y),
|
||||
glm::vec2(coordinates.z, coordinates.y),
|
||||
glm::vec2(coordinates.x, coordinates.w),
|
||||
glm::vec2(coordinates.z, coordinates.w)
|
||||
};
|
||||
|
||||
int32_t indices[QUAD_INDICE_COUNT] = {
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, vertices, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferCoordinates(verticeStart, coords, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
#define QUAD_VERTICE_COUNT 4
|
||||
#define QUAD_INDICE_COUNT 6
|
||||
|
||||
namespace Dawn {
|
||||
class QuadMesh {
|
||||
public:
|
||||
/**
|
||||
* Buffers quad mesh vertices and indices into the given mesh.
|
||||
*
|
||||
* @param mesh The mesh to buffer into.
|
||||
* @param positions The positions of the vertices.
|
||||
* @param coordinates The coordinates of the vertices.
|
||||
* @param verticeStart The starting index of the vertices.
|
||||
* @param indiceStart The starting index of the indices.
|
||||
* @param depth The depth of the vertices (Z coordinate).
|
||||
*/
|
||||
static void buffer(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const float_t depth = 0.0f
|
||||
);
|
||||
|
||||
/**
|
||||
* Buffers quad mesh vertices and indices into the given mesh. This will
|
||||
* store the index of the vertice in the Z component, allowing you to find
|
||||
* which vertex ID you are rendering in your shader.
|
||||
*
|
||||
* @param mesh The mesh to buffer into.
|
||||
* @param positions The positions of the vertices.
|
||||
* @param coordinates The coordinates of the vertices.
|
||||
* @param verticeStart The starting index of the vertices.
|
||||
* @param indiceStart The starting index of the indices.
|
||||
* @param indexOffset The offset to add to the index of each vertex.
|
||||
*/
|
||||
static void bufferWithIndex(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const int32_t indexOffset = 0
|
||||
);
|
||||
};
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class IRenderPass {
|
||||
public:
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
|
||||
/**
|
||||
* Binds the shader for this render pass.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Sets the data for this render pass to the shader.
|
||||
*/
|
||||
virtual void setData() = 0;
|
||||
|
||||
/**
|
||||
* Uploads the data to the GPU.
|
||||
*/
|
||||
virtual void upload() = 0;
|
||||
|
||||
/**
|
||||
* Draws the mesh for this render pass.
|
||||
*/
|
||||
virtual void draw() = 0;
|
||||
|
||||
/**
|
||||
* Cleans up the render pass.
|
||||
*/
|
||||
virtual ~IRenderPass() {
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "game/Game.hpp"
|
||||
#include "display/pass/IRenderPass.hpp"
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
#include "component/display/MeshRenderer.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
template<class S, typename D>
|
||||
class RenderPass : public IRenderPass {
|
||||
private:
|
||||
std::shared_ptr<S> shader;
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures;
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
const enum MeshDrawMode drawMode;
|
||||
const int32_t indiceStart;
|
||||
const int32_t indiceCount;
|
||||
const D data;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a new RenderPass.
|
||||
*
|
||||
* @param self Self component instance that is creating this render pass.
|
||||
* @param d The data to use for this render pass.
|
||||
* @param mesh The mesh to use for this render pass.
|
||||
* @param drawMode The draw mode to use for this render pass.
|
||||
* @param indiceStart The indice to start drawing from.
|
||||
* @param indiceCount The number of indices to draw.
|
||||
*/
|
||||
RenderPass(
|
||||
SceneComponent &self,
|
||||
const D d,
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures,
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const enum MeshDrawMode drawMode,
|
||||
const int32_t indiceStart,
|
||||
const int32_t indiceCount
|
||||
) :
|
||||
data(d),
|
||||
textures(textures),
|
||||
mesh(mesh),
|
||||
drawMode(drawMode),
|
||||
indiceStart(indiceStart),
|
||||
indiceCount(indiceCount)
|
||||
{
|
||||
//Get the shader
|
||||
shader = (
|
||||
self.getGame()->renderHost.shaderManager.getShader<S>()
|
||||
);
|
||||
assertNotNull(shader, "Shader cannot be null!");
|
||||
|
||||
// Need mesh?
|
||||
if(!this->mesh) {
|
||||
auto meshRenderer = self.getItem()->getComponent<MeshRenderer>();
|
||||
if(meshRenderer) this->mesh = meshRenderer->mesh;
|
||||
}
|
||||
}
|
||||
|
||||
void bind() override {
|
||||
shader->bind();
|
||||
}
|
||||
|
||||
void setData() override {
|
||||
shader->setData(data);
|
||||
}
|
||||
|
||||
void upload() override {
|
||||
for(auto &pair : textures) {
|
||||
if(!pair.second->isReady()) continue;
|
||||
pair.second->bind(pair.first);
|
||||
}
|
||||
shader->upload();
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
if(mesh) {
|
||||
mesh->draw(drawMode, indiceStart, indiceCount);
|
||||
}
|
||||
}
|
||||
|
||||
~RenderPass() override {
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "game/Game.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "component/display/Camera.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct RenderPassContext {
|
||||
std::shared_ptr<Game> game;
|
||||
std::shared_ptr<Scene> scene;
|
||||
std::shared_ptr<Camera> camera;
|
||||
std::shared_ptr<RenderTarget> renderTarget;
|
||||
};
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
IShader.cpp
|
||||
IShaderStage.cpp
|
||||
)
|
@@ -1,46 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "display/shader/Shader.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "display/Color.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
size_t shaderParameterTypeGetSize(const enum ShaderParameterType type) {
|
||||
switch(type) {
|
||||
case ShaderParameterType::VEC2:
|
||||
return sizeof(glm::vec2);
|
||||
|
||||
case ShaderParameterType::VEC3:
|
||||
return sizeof(glm::vec3);
|
||||
|
||||
case ShaderParameterType::VEC4:
|
||||
return sizeof(glm::vec4);
|
||||
|
||||
case ShaderParameterType::MAT3:
|
||||
return sizeof(glm::mat3);
|
||||
|
||||
case ShaderParameterType::MAT4:
|
||||
return sizeof(glm::mat4);
|
||||
|
||||
case ShaderParameterType::COLOR:
|
||||
return sizeof(struct Color);
|
||||
|
||||
case ShaderParameterType::FLOAT:
|
||||
return sizeof(float);
|
||||
|
||||
case ShaderParameterType::INT:
|
||||
return sizeof(int32_t);
|
||||
|
||||
case ShaderParameterType::TEXTURE:
|
||||
return sizeof(shadertexturebinding_t);
|
||||
|
||||
default:
|
||||
assertUnreachable("Unknown ShaderParameterType");
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class ShaderParameterType {
|
||||
VEC2,
|
||||
VEC3,
|
||||
VEC4,
|
||||
MAT3,
|
||||
MAT4,
|
||||
COLOR,
|
||||
FLOAT,
|
||||
INT,
|
||||
TEXTURE,
|
||||
BOOLEAN
|
||||
};
|
||||
|
||||
class IShaderBase {
|
||||
public:
|
||||
virtual ~IShaderBase() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class IShader : public IShaderBase {
|
||||
protected:
|
||||
T data;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the currently uploaded data on the Shader.
|
||||
*
|
||||
* @return The uploaded data.
|
||||
*/
|
||||
T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entire data to be uploaded.
|
||||
*
|
||||
* @param data Data to be uploaded.
|
||||
*/
|
||||
void setData(const T data) {
|
||||
this->data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the shader, this needs to be called before the shader can
|
||||
* be used.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* Binds the shader as the current one, does not upload any data, somewhat
|
||||
* relies on something else uploading the data.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Uploads the data to the GPU.
|
||||
*/
|
||||
virtual void upload() = 0;
|
||||
|
||||
/**
|
||||
* Disposes of the shader.
|
||||
*/
|
||||
virtual ~IShader() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the ShaderParameterType.
|
||||
*
|
||||
* @param type The type to get the size of.
|
||||
* @return Size of the type.
|
||||
*/
|
||||
size_t shaderParameterTypeGetSize(const enum Dawn::ShaderParameterType type);
|
@@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "IShaderStage.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
IShaderStage::IShaderStage(const enum ShaderStageType type) :
|
||||
type(type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
IShaderStage::~IShaderStage() {
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class ShaderStageType {
|
||||
VERTEX,
|
||||
FRAGMENT,
|
||||
// COMPUTE
|
||||
};
|
||||
|
||||
class IShaderStage {
|
||||
public:
|
||||
const enum ShaderStageType type;
|
||||
|
||||
/**
|
||||
* Constructs a new Shader Stage.
|
||||
*
|
||||
* @param type Type of shader stage.
|
||||
*/
|
||||
IShaderStage(const enum ShaderStageType type);
|
||||
|
||||
/**
|
||||
* Destroy the IShaderStage object
|
||||
*/
|
||||
virtual ~IShaderStage();
|
||||
};
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/shader/Shader.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class ShaderManager {
|
||||
private:
|
||||
std::vector<std::shared_ptr<IShaderBase>> shaders;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Retreives an instance of the shader from the shader manager. If the
|
||||
* shader does not exist it will be created.
|
||||
*
|
||||
* @tparam T Type of shader to retreive.
|
||||
* @return Shader instance.
|
||||
*/
|
||||
template<class T>
|
||||
std::shared_ptr<T> getShader() {
|
||||
auto itShaders = shaders.begin();
|
||||
while(itShaders != shaders.end()) {
|
||||
// auto shader = itShaders->lock();
|
||||
// if(!shader) {
|
||||
// itShaders = shaders.erase(itShaders);
|
||||
// continue;
|
||||
// }
|
||||
// std::shared_ptr<T> casted = std::dynamic_pointer_cast<T>(shader);
|
||||
|
||||
auto shader = *itShaders;
|
||||
std::shared_ptr<T> casted = std::dynamic_pointer_cast<T>(shader);
|
||||
if(casted) return casted;
|
||||
itShaders++;
|
||||
}
|
||||
|
||||
auto newShader = std::make_shared<T>();
|
||||
shaders.push_back(newShader);
|
||||
newShader->init();
|
||||
return newShader;
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Environment.cpp
|
||||
)
|
@@ -1,31 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Environment.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Environment environment;
|
||||
|
||||
bool_t Environment::hasVariable(const std::string &key) {
|
||||
assertTrue(key.length() > 0, "Key must be at least 1 character long.");
|
||||
return this->variables.find(key) != this->variables.end();
|
||||
}
|
||||
|
||||
void Environment::setVariable(
|
||||
const std::string &key,
|
||||
const std::string &value
|
||||
) {
|
||||
assertTrue(key.length() > 0, "Key must be at least 1 character long.");
|
||||
|
||||
this->variables[key] = value;
|
||||
}
|
||||
|
||||
std::string Environment::getVariable(const std::string &key) {
|
||||
assertTrue(key.length() > 0, "Key must be at least 1 character long.");
|
||||
assertTrue(this->hasVariable(key), "Variable does not exist.");
|
||||
return this->variables[key];
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Environment {
|
||||
private:
|
||||
std::map<std::string, std::string> variables;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Checks if the environment has a variable.
|
||||
*
|
||||
* @param key Variable key to check.
|
||||
* @return True if the variable exists, false otherwise.
|
||||
*/
|
||||
bool_t hasVariable(const std::string &key);
|
||||
|
||||
/**
|
||||
* Sets a variable in the environment.
|
||||
*
|
||||
* @param key Variable key to set.
|
||||
* @param value Variable value to set.
|
||||
*/
|
||||
void setVariable(const std::string &key, const std::string &value);
|
||||
|
||||
/**
|
||||
* Gets a variable from the environment.
|
||||
*
|
||||
* @param key Variable key to get.
|
||||
* @return Variable value, or empty string if not found.
|
||||
*/
|
||||
std::string getVariable(const std::string &key);
|
||||
};
|
||||
}
|
||||
|
||||
extern Dawn::Environment environment;
|
@@ -1,141 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class CustomEventResult {
|
||||
NOTHING,
|
||||
REMOVE,
|
||||
INVOKE,
|
||||
INVOKE_AND_REMOVE
|
||||
};
|
||||
|
||||
template<
|
||||
typename InternalData,
|
||||
typename InternalListenerData,
|
||||
typename ListenerArgument,
|
||||
typename ...InvokeArgs
|
||||
>
|
||||
class CustomEvent {
|
||||
private:
|
||||
int32_t nextId = 0;
|
||||
std::unordered_map<
|
||||
int32_t,
|
||||
std::pair<InternalListenerData, std::function<void(InvokeArgs...)>>
|
||||
> listeners;
|
||||
|
||||
protected:
|
||||
InternalData internalData;
|
||||
|
||||
/**
|
||||
* Custom event filter. Decides whether or not the event should be emitted
|
||||
* to the listener.
|
||||
*
|
||||
* @param listenerData Data for this listener.
|
||||
* @param args The arguments to pass to the listeners.
|
||||
* @return The result of the filter.
|
||||
*/
|
||||
virtual enum CustomEventResult shouldEmit(
|
||||
const InternalListenerData &listenerData,
|
||||
const InvokeArgs... args
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Transform the arguments for listener data when the listener is first
|
||||
* subscribed.
|
||||
*
|
||||
* @param argument The argument to transform.
|
||||
* @return The transformed argument into an internal data format.
|
||||
*/
|
||||
virtual InternalListenerData transformData(
|
||||
const ListenerArgument &argument
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Transform the data for listener data after the event has been emitted.
|
||||
*
|
||||
* @param internalData The internal data to transform.
|
||||
* @return Updated/Transformed internal data.
|
||||
*/
|
||||
virtual InternalListenerData transformDataAfterEmit(
|
||||
const InternalListenerData &internalData
|
||||
) {
|
||||
return internalData;
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Emits the event.
|
||||
* @param args The arguments to pass to the listeners.
|
||||
*/
|
||||
void emit(InvokeArgs... args) {
|
||||
auto copy = listeners;
|
||||
for(auto &pair : copy) {
|
||||
// Check emit test.
|
||||
auto result = this->shouldEmit(
|
||||
pair.second.first,
|
||||
args...
|
||||
);
|
||||
if(
|
||||
result == CustomEventResult::INVOKE ||
|
||||
result == CustomEventResult::INVOKE_AND_REMOVE
|
||||
) {
|
||||
pair.second.second(args...);
|
||||
}
|
||||
|
||||
if(
|
||||
result == CustomEventResult::REMOVE ||
|
||||
result == CustomEventResult::INVOKE_AND_REMOVE
|
||||
) {
|
||||
listeners.erase(pair.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(
|
||||
result == CustomEventResult::INVOKE ||
|
||||
result == CustomEventResult::INVOKE_AND_REMOVE
|
||||
) {
|
||||
// Update the internal data.
|
||||
listeners[pair.first].first = transformDataAfterEmit(
|
||||
pair.second.first
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to the event.
|
||||
*
|
||||
* @param data Listener data to use.
|
||||
* @param listener The listener to add.
|
||||
* @returns A function that can be called to remove the listener.
|
||||
*/
|
||||
std::function<void()> listen(
|
||||
const ListenerArgument &data,
|
||||
const std::function<void(InvokeArgs...)> listener
|
||||
) {
|
||||
int32_t id = nextId++;
|
||||
|
||||
auto pair = std::make_pair(
|
||||
transformData(data),
|
||||
listener
|
||||
);
|
||||
|
||||
listeners[id] = pair;
|
||||
return [this, id]() {
|
||||
listeners.erase(id);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the custom event.
|
||||
*/
|
||||
virtual ~CustomEvent() {
|
||||
listeners.clear();
|
||||
}
|
||||
};
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user