Skip to content

Commit

Permalink
Added Models::Static and its decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
WillisMedwell committed Jan 23, 2024
1 parent 8f40940 commit 2293033
Show file tree
Hide file tree
Showing 19 changed files with 485 additions and 247 deletions.
2 changes: 1 addition & 1 deletion code/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Checks: >
Checks: '-*,readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.MethodCase, value: lower_case }
Expand Down
80 changes: 80 additions & 0 deletions code/CmakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 11,
"patch": 0
},
"configurePresets": [
{
"name": "gcc-ninja-release",
"description": "Build with GCC and Ninja",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/gcc-ninja-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
},
"environment": {
"CC": "gcc",
"CXX": "g++"
}
},
{
"name": "clang-ninja-release",
"description": "Build with Clang and Ninja",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/clang-ninja-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
},
"environment": {
"CC": "clang",
"CXX": "clang++"
}
},
{
"name": "emscripten-ninja-release",
"description": "Build with Emscripten SDK",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/emscripten-ninja-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
},
"environment": {
"CC": "emcc",
"CXX": "em++"
}
},
{
"name": "emscripten-ninja-debug",
"description": "Build with Emscripten SDK",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/emscripten-ninja-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"environment": {
"CC": "emcc",
"CXX": "em++"
}
}
],
"buildPresets": [
{
"name": "gcc-ninja-release",
"configurePreset": "gcc-ninja-release"
},
{
"name": "clang-ninja-release",
"configurePreset": "clang-ninja"
},
{
"name": "emscripten-ninja-release",
"configurePreset": "emscripten-ninja"
},
{
"name": "emscripten-ninja-debug",
"configurePreset": "emscripten-ninja"
}
]
}
11 changes: 3 additions & 8 deletions code/Demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@ file(COPY ${CMAKE_SOURCE_DIR}/.clang-tidy DESTINATION ${CMAKE_CURRENT_BINARY_DIR

add_executable(Demos ${DEMOS_SOURCES} ${DEMOS_HEADERS})

if(DEFINED EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g -s DEMANGLE_SUPPORT=1 -s FORCE_FILESYSTEM=1 -s ASSERTIONS=1 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=2 -s NO_DISABLE_EXCEPTION_CATCHING")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Os")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_WEBGL2=1 -s MAX_WEBGL_VERSION=3 -s USE_GLFW=3 -s FULL_ES3=1 -s FULL_ES2=1")
if(DEFINED EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXPORTED_FUNCTIONS='_main' -s EXPORT_NAME=\"'WasmModuleDemos'\"")

# Move index.html.
file(COPY ${CMAKE_SOURCE_DIR}/index.html DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

Expand All @@ -30,8 +23,10 @@ if(DEFINED EMSCRIPTEN)
endforeach()
message(STATUS "PRELOAD FILES: \"${PRELOAD_FILES}\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PRELOAD_FILES}")
target_compile_options(Demos PRIVATE -msimd128 -mrelaxed-simd -msse -msse2 -mavx)
else()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
target_compile_options(Demos PRIVATE -march=native)
endif()

target_link_libraries(Demos PUBLIC Engine)
Expand Down
38 changes: 19 additions & 19 deletions code/Demos/src/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "App.hpp"
#include "Config.hpp"
#include "Models/Staging.hpp"
#include "Models/Models.hpp"

#include <chrono>
#include <iostream>
Expand All @@ -9,24 +9,24 @@

#include <Utily/Utily.hpp>

auto print_then_quit = [](auto& error) {
std::cerr
<< error.what()
<< std::endl;
exit(1);
};

auto print_num_faces = [](Models::Staging::Model& model) {
std::println("Triangle Count: {}", model.index_data.size() / 3);
};

void timeLoadModel(const std::string& file_path) {
auto start = std::chrono::high_resolution_clock::now();
Models::Staging::loadModel(file_path).on_error(print_then_quit).on_value(print_num_faces);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> duration = end - start;
std::cout << "Loading " << file_path << " took " << duration.count() << " milliseconds." << std::endl;
}
// auto print_then_quit = [](auto& error) {
// std::cerr
// << error.what()
// << std::endl;
// exit(1);
// };

// auto print_num_faces = [](Model::Staging::Model& model) {
// std::println("Triangle Count: {}", model.index_data.size() / 3);
// };

// void timeLoadModel(const std::string& file_path) {
// auto start = std::chrono::high_resolution_clock::now();
// Models::Staging::loadModel(file_path).on_error(print_then_quit).on_value(print_num_faces);
// auto end = std::chrono::high_resolution_clock::now();
// std::chrono::duration<double, std::milli> duration = end - start;
// std::cout << "Loading " << file_path << " took " << duration.count() << " milliseconds." << std::endl;
// }

struct Data {
Cameras::StationaryPerspective camera {
Expand Down
16 changes: 11 additions & 5 deletions code/Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(Utily)

if(NOT MSVC)
target_compile_options(Engine PRIVATE -fexperimental-library -Wall -Wextra -Wpedantic)
endif()

if(DEFINED EMSCRIPTEN)
target_link_libraries(Engine PUBLIC
glm::glm assimp::assimp EnTT::EnTT Utily::Utily lodepng ${BULLET_LIBRARIES}
)
target_include_directories(Engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${Stb_INCLUDE_DIR})
target_compile_options(Engine PUBLIC
"$<$<CONFIG:Debug>:-O0;-g;-sDEMANGLE_SUPPORT=1;-sFORCE_FILESYSTEM=1;-sASSERTIONS=1;-sSAFE_HEAP=1;-sSTACK_OVERFLOW_CHECK=2;-sNO_DISABLE_EXCEPTION_CATCHING;-Wno-unused-command-line-argument>"
"$<$<CONFIG:Release>:-Oz;-sGL_FFP_ONLY;-msimd128;-Wno-unused-command-line-argument>"
)
target_link_options(Engine PUBLIC -sUSE_WEBGL2=1 -sUSE_GLFW=3 -sFULL_ES3=1 -sFULL_ES2=1 -Wno-unused-command-line-argument)
else()
find_package(OpenGL REQUIRED)
find_package(OpenAL CONFIG REQUIRED)
find_package(GLFW3 CONFIG REQUIRED)
find_package(GLEW REQUIRED)
target_link_libraries(Engine PUBLIC
glm::glm assimp::assimp EnTT::EnTT Utily::Utily lodepng ${BULLET_LIBRARIES}
OpenGL::GL GLEW::GLEW glfw
OpenGL::GL OpenAL::OpenAL GLEW::GLEW glfw
)
target_include_directories(Engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${OPENGL_INCLUDE_DIR} ${Stb_INCLUDE_DIR})
endif()

if(NOT MSVC)
target_compile_options(Engine PRIVATE -fexperimental-library -Wall -Wextra -Wpedantic)
endif()
4 changes: 0 additions & 4 deletions code/Engine/include/AppAnalyitics.hpp

This file was deleted.

90 changes: 90 additions & 0 deletions code/Engine/include/AppAnalytics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#pragma once

#include <string>

#include <sstream>

#include "Config.hpp"

class AppAnalytics
{
public:
std::string gpu_info;

auto get_gpu_info() {
std::ostringstream info_stream;

// Basic GPU Information
const GLubyte* vendor = glGetString(GL_VENDOR);
const GLubyte* renderer = glGetString(GL_RENDERER);
const GLubyte* version = glGetString(GL_VERSION);
info_stream << "Vendor: " << vendor << "\n"
<< "Renderer: " << renderer << "\n"
<< "OpenGL Version: " << version << "\n";

// Additional GPU Capabilities
GLint value;

// Max Texture Size
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
info_stream << "Max Texture Size: " << value << "\n";

// Max Number of Texture Image Units
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &value);
info_stream << "Max Texture Image Units: " << value << "\n";

// Max Cube Map Texture Size
glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &value);
info_stream << "Max Cube Map Texture Size: " << value << "\n";

// Max Renderbuffer Size
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &value);
info_stream << "Max Renderbuffer Size: " << value << "\n";

// Max Viewport Dimensions
GLint maxViewportDims[2];
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, maxViewportDims);
info_stream << "Max Viewport Dimensions: " << maxViewportDims[0] << " x " << maxViewportDims[1] << "\n";

// Max Anisotropy
GLfloat maxAniso = 0.0f;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso);
info_stream << "Max Texture Anisotropy: " << maxAniso << "\n";

// Max Samples in Multisample
glGetIntegerv(GL_MAX_SAMPLES, &value);
info_stream << "Max Samples in Multisample: " << value << "\n";

// Max Color Attachments
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &value);
info_stream << "Max Color Attachments: " << value << "\n";

// Max Draw Buffers
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &value);
info_stream << "Max Draw Buffers: " << value << "\n";

glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &value);
info_stream << "Max Vertex Attributes: " << value << "\n";

glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &value);
info_stream << "Max Vertex Uniform Components: " << value << "\n";

glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &value);
info_stream << "Max Fragment Uniform Components: " << value << "\n";

glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &value);
info_stream << "Max Vertex Texture Image Units: " << value << "\n";

glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &value);
info_stream << "Max Combined Texture Image Units: " << value << "\n";

// Fragment Processing
glGetIntegerv(GL_MAX_FRAGMENT_INPUT_COMPONENTS, &value);
info_stream << "Max Fragment Input Components: " << value << "\n";

glGetIntegerv(GL_MAX_TEXTURE_LOD_BIAS, &value);
info_stream << "Max Texture LOD Bias: " << value << "\n";

gpu_info = info_stream.str();
}
};
1 change: 1 addition & 0 deletions code/Engine/include/Models/Animated.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
1 change: 1 addition & 0 deletions code/Engine/include/Models/Dynamic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
4 changes: 3 additions & 1 deletion code/Engine/include/Models/Models.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once

#include "Models/Staging.hpp"
#include "Models/Types.hpp"
#include "Models/Static.hpp"
#include "Models/Animated.hpp"
#include "Models/Dynamic.hpp"
33 changes: 0 additions & 33 deletions code/Engine/include/Models/Staging.hpp

This file was deleted.

32 changes: 13 additions & 19 deletions code/Engine/include/Models/Static.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
#pragma once

#include <string>
#include <vector>
#include <array>
#include "Models/Types.hpp"
#include "Utily/Utily.hpp"

#include <glm/vec3.hpp>
#include <glm/vec2.hpp>
namespace Models {

namespace Models::Static {
struct Vertex {
glm::vec3 position;
glm::vec3 normal;
glm::vec2 uv_coord;
struct Static {
std::array<Vec3, 2> axis_align_bounding_box;
std::unique_ptr<std::byte[]> data;
std::span<Vertex> vertices;
std::span<uint32_t> indices;
};

static_assert(sizeof(Models::Static::Vertex) == sizeof(std::array<float,8>));

struct Model {
std::string name;
std::vector<Vertex> vertex_data;
std::vector<uint32_t> index_data;
};

} // namespace Models::Static
auto decode_as_static_model(
std::span<std::byte> file_data,
Utily::StaticVector<char, 16> file_extension)
-> Utily::Result<Static, Utily::Error>;
}
Loading

0 comments on commit 2293033

Please sign in to comment.