restructured project
This commit is contained in:
parent
b68a05bcb1
commit
e137549b2e
@ -1,19 +1,17 @@
|
||||
cmake_minimum_required (VERSION 3.16)
|
||||
|
||||
# Dependencies
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
|
||||
set(USE_SYSTEM_OCCT ON CACHE INTERNAL "")
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/glad.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/stb.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/imgui.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/occt.cmake)
|
||||
|
||||
|
||||
# Main project
|
||||
project(
|
||||
hyporo
|
||||
VERSION 0.20.0
|
||||
project-hyporo
|
||||
VERSION 0.10.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
@ -22,16 +20,12 @@ option(WITH_GTESTS "Enable GTest unit testing" ON)
|
||||
enable_testing()
|
||||
|
||||
if(WITH_GTESTS)
|
||||
option(INSTALL_GMOCK "" OFF)
|
||||
option(INSTALL_GTEST "" OFF)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/googletest.cmake)
|
||||
include(GoogleTest)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
add_definitions(-DPRECISION_DOUBLE)
|
||||
|
||||
add_subdirectory(source)
|
||||
|
||||
add_subdirectory(docs)
|
||||
#add_subdirectory(docs)
|
@ -9,7 +9,7 @@ CPMAddPackage(
|
||||
)
|
||||
|
||||
if(imgui_external_ADDED)
|
||||
project(imgui)
|
||||
set(EXTERNAL_PROJECT_NAME imgui)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
@ -18,7 +18,7 @@ if(imgui_external_ADDED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
pkg_search_module(GLFW REQUIRED glfw3)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC
|
||||
add_library(${EXTERNAL_PROJECT_NAME} STATIC
|
||||
${imgui_external_SOURCE_DIR}/imgui.cpp
|
||||
${imgui_external_SOURCE_DIR}/imgui_demo.cpp
|
||||
${imgui_external_SOURCE_DIR}/imgui_draw.cpp
|
||||
@ -31,11 +31,11 @@ if(imgui_external_ADDED)
|
||||
${imgui_external_SOURCE_DIR}/misc/freetype/imgui_freetype.cpp
|
||||
${imgui_external_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp
|
||||
)
|
||||
add_library(imgui::imgui ALIAS ${PROJECT_NAME})
|
||||
add_library(imgui::imgui ALIAS ${EXTERNAL_PROJECT_NAME})
|
||||
|
||||
add_compile_definitions(IMGUI_IMPL_OPENGL_LOADER_GLAD)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
target_include_directories(${EXTERNAL_PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${imgui_external_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${imgui_external_SOURCE_DIR}/backends>
|
||||
@ -46,14 +46,14 @@ if(imgui_external_ADDED)
|
||||
${GLFW_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
target_link_libraries(${EXTERNAL_PROJECT_NAME}
|
||||
PUBLIC
|
||||
Freetype::Freetype
|
||||
glfw
|
||||
OpenGL::GL
|
||||
)
|
||||
|
||||
set_target_properties(${PROJECT_NAME}
|
||||
set_target_properties(${EXTERNAL_PROJECT_NAME}
|
||||
PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
OUTPUT_NAME imgui
|
||||
@ -63,21 +63,21 @@ if(imgui_external_ADDED)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
||||
TARGETS ${EXTERNAL_PROJECT_NAME}
|
||||
EXPORT ${EXTERNAL_PROJECT_NAME}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${EXTERNAL_PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
EXPORT ${EXTERNAL_PROJECT_NAME}Targets
|
||||
FILE ${EXTERNAL_PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${EXTERNAL_PROJECT_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXTERNAL_PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY ${imgui_external_SOURCE_DIR}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${EXTERNAL_PROJECT_NAME}
|
||||
COMPONENT devel
|
||||
FILES_MATCHING
|
||||
PATTERN "*.h"
|
||||
|
52
cmake/macros.cmake
Normal file
52
cmake/macros.cmake
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
macro(add_component_library COMPONENT LIBRARY_TYPE COMPONENT_SOURCES)
|
||||
add_library(${COMPONENT} ${LIBRARY_TYPE} ${COMPONENT_SOURCES})
|
||||
add_library(${PROJECT_NAME}::${COMPONENT} ALIAS ${COMPONENT})
|
||||
endmacro()
|
||||
|
||||
macro(install_component_source COMPONENT)
|
||||
set_target_properties(${COMPONENT}
|
||||
PROPERTIES
|
||||
VERSION ${${PROJECT_NAME}_VERSION}
|
||||
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR}
|
||||
OUTPUT_NAME ${PROJECT_NAME}-${COMPONENT}
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS ${COMPONENT}
|
||||
EXPORT ${COMPONENT}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT ${COMPONENT}Targets
|
||||
FILE ${COMPONENT}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
)
|
||||
endmacro()
|
||||
|
||||
macro(install_component_headers COMPONENT)
|
||||
|
||||
#target_include_directories(${COMPONENT}
|
||||
# PUBLIC
|
||||
# $<INSTALL_INTERFACE:include>
|
||||
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>#/${CMAKE_PROJECT_NAME}>#/include>
|
||||
# )
|
||||
|
||||
install(
|
||||
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}#/${COMPONENT}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}#/${COMPONENT}
|
||||
COMPONENT devel
|
||||
FILES_MATCHING
|
||||
PATTERN "*.h"
|
||||
PATTERN "*.hpp"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_SOURCE_DIR}/../${COMPONENT}.hpp
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}#/${COMPONENT}
|
||||
COMPONENT devel
|
||||
)
|
||||
|
||||
endmacro()
|
@ -8,17 +8,17 @@ CPMAddPackage(
|
||||
)
|
||||
|
||||
if(stb_external_ADDED)
|
||||
project(stb)
|
||||
set(EXTERNAL_PROJECT_NAME stb)
|
||||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
add_library(stb::stb ALIAS ${PROJECT_NAME})
|
||||
add_library(${EXTERNAL_PROJECT_NAME} INTERFACE)
|
||||
add_library(stb::stb ALIAS ${EXTERNAL_PROJECT_NAME})
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
target_include_directories(${EXTERNAL_PROJECT_NAME}
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${stb_external_SOURCE_DIR}>
|
||||
)
|
||||
|
||||
set_target_properties(${PROJECT_NAME}
|
||||
set_target_properties(${EXTERNAL_PROJECT_NAME}
|
||||
PROPERTIES
|
||||
OUTPUT_NAME stb
|
||||
)
|
||||
@ -26,21 +26,21 @@ if(stb_external_ADDED)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
||||
TARGETS ${EXTERNAL_PROJECT_NAME}
|
||||
EXPORT ${EXTERNAL_PROJECT_NAME}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${EXTERNAL_PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
EXPORT ${EXTERNAL_PROJECT_NAME}Targets
|
||||
FILE ${EXTERNAL_PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${EXTERNAL_PROJECT_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXTERNAL_PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY ${stb_external_SOURCE_DIR}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${EXTERNAL_PROJECT_NAME}
|
||||
COMPONENT devel
|
||||
FILES_MATCHING
|
||||
PATTERN "*.h"
|
||||
|
@ -1,3 +1,3 @@
|
||||
add_subdirectory(hyporo)
|
||||
add_subdirectory(hpr)
|
||||
add_subdirectory(creator)
|
||||
add_subdirectory(applications)
|
||||
#add_subdirectory(applications)
|
208
source/applications/periodic/lattice.hpp
Normal file
208
source/applications/periodic/lattice.hpp
Normal file
@ -0,0 +1,208 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../hyporo/hyplib/scalar/scalar.hpp"
|
||||
#include "../../hyporo/hyplib/vector/vector.hpp"
|
||||
#include "../../hyporo/hyplib/array/array.hpp"
|
||||
#include "../../hyporo/hyplib/matrix/matrix.hpp"
|
||||
#include "../../hyporo/csg/csg.hpp"
|
||||
|
||||
|
||||
namespace hpr::csg
|
||||
{
|
||||
void prints(scalar point)
|
||||
{
|
||||
std::cout << point << std::endl;
|
||||
}
|
||||
class Lattice : public csg::Shape
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum class System
|
||||
{
|
||||
Triclinic,
|
||||
Monoclinic,
|
||||
Orthorhombic,
|
||||
Tetragonal,
|
||||
Rhombohedral,
|
||||
Hexagonal,
|
||||
Cubic,
|
||||
Unknown
|
||||
};
|
||||
|
||||
enum class Type
|
||||
{
|
||||
Primitive,
|
||||
BaseCentered,
|
||||
BodyCentered,
|
||||
FaceCentered,
|
||||
Unknown
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
vec3 p_lengths;
|
||||
vec3 p_angles;
|
||||
Type p_type;
|
||||
scalar p_radius;
|
||||
darray<vec3> p_controlPoints;
|
||||
|
||||
public:
|
||||
|
||||
Lattice() = delete;
|
||||
|
||||
Lattice(const vec3& lengths, const vec3& angles, scalar radius, Type type) :
|
||||
csg::Shape {},
|
||||
p_lengths {lengths},
|
||||
p_angles {angles},
|
||||
p_radius {radius},
|
||||
p_type {type}
|
||||
{
|
||||
generateControlPoints();
|
||||
darray<csg::Shape> spheres;
|
||||
for (const auto& point : controlPoints()) {
|
||||
spheres.push(csg::sphere(point, p_radius));
|
||||
print(point);
|
||||
}
|
||||
|
||||
p_shape = csg::Compound(spheres).tshape();//csg::fuse({spheres.front()}, spheres.slice(spheres.begin() + 1, spheres.end())).tshape();
|
||||
}
|
||||
|
||||
darray<vec3> controlPoints() const
|
||||
{
|
||||
return p_controlPoints;
|
||||
}
|
||||
|
||||
vec3 lengths() const
|
||||
{
|
||||
return p_lengths;
|
||||
}
|
||||
|
||||
vec3 angles() const
|
||||
{
|
||||
return p_angles;
|
||||
}
|
||||
|
||||
void generateControlPoints()
|
||||
{
|
||||
if (p_type == Type::Unknown)
|
||||
throw std::runtime_error("Unknown type of lattice");
|
||||
p_controlPoints.resize(14);
|
||||
//
|
||||
vec3 ox {1, 0, 0};
|
||||
vec3 oy {0, 1, 0};
|
||||
vec3 oz {0, 0, 1};
|
||||
vec3 ox1 = hpr::rotate(ox, oz, radians(-p_angles[2]));
|
||||
p_controlPoints.push(vec3{0, 0, 0});
|
||||
p_controlPoints.push(vec3{0, p_lengths[0], 0});
|
||||
vec3 t1 = hpr::translate(p_controlPoints.back(), ox1 * p_lengths[1]);
|
||||
p_controlPoints.push(t1);
|
||||
p_controlPoints.push(hpr::translate(p_controlPoints.front(), ox1 * p_lengths[1]));
|
||||
print(t1);
|
||||
print(ox1);
|
||||
scalar c1 = cos(radians(p_angles[2])), c2 = cos(radians(p_angles[1])), c3 = cos(radians(p_angles[0]));
|
||||
scalar D1 = sqrt(mat3(
|
||||
1, cos(radians(p_angles[2])), cos(radians(p_angles[1])),
|
||||
cos(radians(p_angles[2])), 1, cos(radians(p_angles[0])),
|
||||
cos(radians(p_angles[1])), cos(radians(p_angles[0])), 1).det());
|
||||
scalar volume = 1. / 6. * p_lengths[0] * p_lengths[1] * p_lengths[2] *
|
||||
D1;
|
||||
scalar s1 = sqrt(std::pow(p_lengths[0], 2) + std::pow(p_lengths[1], 2) - 2 *
|
||||
p_lengths[0] * p_lengths[1] * cos(radians(p_angles[2])));
|
||||
scalar s2 = sqrt(std::pow(p_lengths[1], 2) + std::pow(p_lengths[2], 2) - 2 *
|
||||
p_lengths[1] * p_lengths[2] * cos(radians(p_angles[1])));
|
||||
scalar s3 = sqrt(std::pow(p_lengths[0], 2) + std::pow(p_lengths[2], 2) - 2 *
|
||||
p_lengths[0] * p_lengths[2] * cos(radians(p_angles[0])));
|
||||
scalar area = 1. / 2. * p_lengths[0] * p_lengths[1] *
|
||||
sqrt(mat2{1, cos(radians(p_angles[2])), cos(radians(p_angles[2])), 1}.det());
|
||||
scalar h1 = 3 * volume / area;
|
||||
scalar a1 = asin(h1 / p_lengths[2]);
|
||||
scalar sh1 = sqrt(std::pow(p_lengths[2], 2) - std::pow(h1, 2));
|
||||
scalar sh2 = p_lengths[2] * cos(radians(p_angles[0]));
|
||||
scalar a2 = acos(sh2 / sh1);
|
||||
|
||||
vec3 ox2 = hpr::rotate(ox, oy, a1);
|
||||
if (!std::isnan(a2))
|
||||
ox2 = hpr::rotate(ox2, oz, a2);
|
||||
print(ox2);
|
||||
for (auto n = 0; n < 4; ++n)
|
||||
p_controlPoints.push(hpr::translate(p_controlPoints[n], ox2 * p_lengths[2]));
|
||||
|
||||
/*p_controlPoints.push(vec3{p_lengths[0], p_lengths[1], 0});
|
||||
p_controlPoints.push(vec3{p_lengths[0], 0, 0});
|
||||
|
||||
p_controlPoints.push(vec3{0, 0, p_lengths[2]});
|
||||
p_controlPoints.push(vec3{0, p_lengths[1], p_lengths[2]});
|
||||
p_controlPoints.push(vec3{p_lengths[0], p_lengths[1], p_lengths[2]});
|
||||
p_controlPoints.push(vec3{p_lengths[0], 0, p_lengths[2]});
|
||||
|
||||
// central points on base faces
|
||||
if (p_type == Type::BaseCentered || p_type == Type::FaceCentered)
|
||||
{
|
||||
for (int n = 0; n < 2; ++n)
|
||||
{
|
||||
vec3 center;
|
||||
for (int k = 0; k < 4; ++k)
|
||||
center += p_controlPoints[k + 4 * n];
|
||||
p_controlPoints.push(center * 0.25);
|
||||
}
|
||||
}
|
||||
|
||||
// central point (center of mass)
|
||||
if (p_type == Type::BodyCentered)
|
||||
{
|
||||
vec3 center;
|
||||
for (const auto& point : p_controlPoints)
|
||||
center += point;
|
||||
p_controlPoints.push(center / p_controlPoints.size());
|
||||
}
|
||||
|
||||
// central points on side faces
|
||||
if (p_type == Type::FaceCentered)
|
||||
{
|
||||
for (int n = 0; n < 3; ++n)
|
||||
{
|
||||
vec3 center;
|
||||
for (int k = 0; k < 2; ++k)
|
||||
{
|
||||
center += p_controlPoints[n + k];
|
||||
center += p_controlPoints[n + k + 4];
|
||||
}
|
||||
p_controlPoints.push(center * 0.25);
|
||||
}
|
||||
vec3 center;
|
||||
for (int n = 0; n < 2; ++n)
|
||||
{
|
||||
center += p_controlPoints[n * 3];
|
||||
center += p_controlPoints[4 + n * 3];
|
||||
}
|
||||
p_controlPoints.push(center * 0.25);
|
||||
}
|
||||
|
||||
mat4 trans = mat4::identity();
|
||||
vec3 ox {1, 0, 0};
|
||||
vec3 oy {0, 1, 0};
|
||||
vec3 oz {0, 0, 1};
|
||||
int n = 0;
|
||||
for (auto& point : p_controlPoints)
|
||||
{
|
||||
if (n == 0 || n == 3)
|
||||
{
|
||||
++n;
|
||||
continue;
|
||||
}
|
||||
trans.row(3, vec4(point, 0));
|
||||
trans = hpr::rotate(trans, oz, -radians(90 - p_angles[2]));
|
||||
if (n >= 4 && n <= 7)
|
||||
{
|
||||
trans = hpr::rotate(trans, ox, -radians(90 - p_angles[1]));
|
||||
trans = hpr::rotate(trans, oy, -radians(90 - p_angles[0]));
|
||||
}
|
||||
point = vec3(trans.row(3)[0], trans.row(3)[1], trans.row(3)[2]);
|
||||
++n;
|
||||
}*/
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -144,6 +144,7 @@ public:
|
||||
lattice = lattice.scale({0, 0, 0}, 1e-2);
|
||||
}
|
||||
|
||||
std::cout << (int)lattice.type() << std::endl;
|
||||
return lattice;
|
||||
}
|
||||
|
||||
@ -200,6 +201,7 @@ public:
|
||||
face.label("periodic-up");
|
||||
}
|
||||
|
||||
std::cout << (int)cell.type() << std::endl;
|
||||
return cell;
|
||||
}
|
||||
|
||||
@ -228,12 +230,17 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#include "lattice.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Simple simple {0.01, {1., 0., 0.}};
|
||||
/*Simple simple {0.01, {1., 0., 0.}};
|
||||
simple.build();
|
||||
|
||||
//simple.dump("simpleTest.step", csg::Shape::Format::STEP);
|
||||
std::cout << (int)simple.type() << std::endl;
|
||||
std::cout << simple.volume() << std::endl;
|
||||
*/
|
||||
csg::Lattice lattice {{2, 2, 2}, {90, 90, 90}, 1, csg::Lattice::Type::Primitive};
|
||||
lattice.dump("latticeTest.step", csg::Shape::Format::STEP);
|
||||
return 0;
|
||||
}
|
@ -1,22 +1,37 @@
|
||||
|
||||
include_directories(
|
||||
../hyporo/hyplib
|
||||
../hyporo/window_system
|
||||
../hyporo/gpu
|
||||
../hyporo/hmesh
|
||||
project(
|
||||
hyporo
|
||||
VERSION 0.1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(hyporo
|
||||
# Source files
|
||||
# Compiler options
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
|
||||
# Project options
|
||||
include(GNUInstallDirs)
|
||||
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
creator.cpp
|
||||
|
||||
../hpr/window_system/window_system.cpp
|
||||
../hpr/window_system/monitor.cpp
|
||||
../hpr/window_system/window.cpp
|
||||
../hpr/window_system/glfw/window_system.cpp
|
||||
../hpr/window_system/glfw/monitor.cpp
|
||||
../hpr/window_system/glfw/window.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(hyporo
|
||||
PUBLIC
|
||||
hyporo-hyplib
|
||||
hyporo-window-system
|
||||
hyporo-gpu
|
||||
hyporo-mesh
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/imgui.cmake)
|
||||
message(STATUS "project name: ${PROJECT_NAME}")
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
hpr::hpr
|
||||
imgui
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
../
|
||||
)
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "../window_system/window_system.hpp"
|
||||
#include "../window_system/glfw/window.hpp"
|
||||
#include "../gpu/device.hpp"
|
||||
#include "../gpu/opengl/device.hpp"
|
||||
#include "../hmesh/mesh.hpp"
|
||||
#include "../hyplib/matrix/matrix.hpp"
|
||||
#include "../hyplib/vector/vector.hpp"
|
||||
#include "hpr/window_system/window_system.hpp"
|
||||
#include "hpr/window_system/glfw/window_system.hpp"
|
||||
#include "hpr/window_system/glfw/window.hpp"
|
||||
#include "hpr/gpu.hpp"
|
||||
#include "hpr/math.hpp"
|
||||
#include "hpr/mesh.hpp"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
|
131
source/hpr/CMakeLists.txt
Normal file
131
source/hpr/CMakeLists.txt
Normal file
@ -0,0 +1,131 @@
|
||||
|
||||
project(
|
||||
hpr
|
||||
VERSION 0.10.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
# Compiler options
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
|
||||
add_definitions(-DPRECISION_DOUBLE)
|
||||
|
||||
# Project options
|
||||
include(GNUInstallDirs)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/macros.cmake)
|
||||
|
||||
option(WITH_CSG "Build with CSG component" ON)
|
||||
option(WITH_GPU "Build with graphics component" ON)
|
||||
option(WITH_MESH "Build with mesh utils component" ON)
|
||||
option(WITH_WS "Build with window system component" ON)
|
||||
|
||||
# containers
|
||||
file(GLOB containers_hpp "containers.hpp" "containers/*.hpp" "containers/array/*.hpp")
|
||||
file(GLOB containers_cpp "containers/*.cpp" "containers/array/*.cpp")
|
||||
|
||||
# math
|
||||
file(GLOB math_hpp "math.hpp" "math/*.hpp" "math/scalar/*.hpp" "math/vector/*.hpp" "math/matrix/*.hpp")
|
||||
file(GLOB math_cpp "math/*.cpp" "math/scalar/*.cpp" "math/vector/*.cpp" "math/matrix/*.cpp")
|
||||
|
||||
# io
|
||||
file(GLOB io_hpp "io.hpp" "io/*.hpp")
|
||||
file(GLOB io_cpp "io/*.cpp")
|
||||
|
||||
# csg
|
||||
file(GLOB csg_hpp "csg.hpp" "csg/*.hpp")
|
||||
file(GLOB csg_cpp "csg/*.cpp")
|
||||
|
||||
# gpu
|
||||
file(GLOB gpu_hpp "gpu.hpp" "gpu/*.hpp")
|
||||
file(GLOB gpu_cpp "gpu/*.cpp")
|
||||
file(GLOB gpu_opengl_hpp "gpu/opengl/*.hpp")
|
||||
file(GLOB gpu_opengl_cpp "gpu/opengl/*.cpp")
|
||||
|
||||
# mesh
|
||||
file(GLOB mesh_hpp "mesh.hpp" "mesh/*.hpp")
|
||||
file(GLOB mesh_cpp "mesh/*.cpp")
|
||||
|
||||
# window system
|
||||
file(GLOB window_system_hpp "window_system.hpp" "window_system/*.hpp")
|
||||
file(GLOB window_system_cpp "window_system/*.cpp")
|
||||
file(GLOB window_system_glfw_hpp "window_system/glfw/*.hpp")
|
||||
file(GLOB window_system_glfw_cpp "window_system/glfw/*.cpp")
|
||||
|
||||
#
|
||||
list(APPEND hpr_INCLUDE
|
||||
${containers_hpp}
|
||||
${math_hpp}
|
||||
${io_hpp}
|
||||
)
|
||||
list(APPEND hpr_SOURCES
|
||||
${containers_cpp}
|
||||
${math_cpp}
|
||||
${io_cpp}
|
||||
)
|
||||
list(APPEND hpr_LIBRARIES "")
|
||||
list(APPEND hpr_INCLUDE_DIRS "")
|
||||
|
||||
if (WITH_CSG)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/occt.cmake)
|
||||
|
||||
list(APPEND hpr_INCLUDE ${csg_hpp})
|
||||
list(APPEND hpr_SOURCES ${csg_cpp})
|
||||
list(APPEND hpr_LIBRARIES ${OCCT_LIBRARIES})
|
||||
|
||||
list(APPEND hpr_INCLUDE_DIRS ${OCCT_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
if (WITH_GPU)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/glad.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/stb.cmake)
|
||||
|
||||
list(APPEND hpr_INCLUDE ${gpu_hpp} ${gpu_opengl_hpp})
|
||||
list(APPEND hpr_SOURCES ${gpu_cpp} ${gpu_opengl_cpp})
|
||||
list(APPEND hpr_LIBRARIES glad stb)
|
||||
endif()
|
||||
|
||||
if (WITH_WS)
|
||||
list(APPEND hpr_INCLUDE ${window_system_hpp} ${window_system_glfw_hpp})
|
||||
list(APPEND hpr_SOURCES ${window_system_cpp} ${window_system_glfw_cpp})
|
||||
list(APPEND hpr_LIBRARIES glfw)
|
||||
endif()
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
hpr.cpp
|
||||
${hpr_SOURCES}
|
||||
)
|
||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${hpr_LIBRARIES}
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
${hpr_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Install library
|
||||
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
include(CPack)
|
||||
|
||||
#
|
||||
message(STATUS "Components:")
|
||||
message(STATUS " Core: ON")
|
||||
message(STATUS " CSG: ${WITH_CSG}")
|
||||
message(STATUS " GPU: ${WITH_GPU}")
|
||||
message(STATUS " Mesh: ${WITH_MESH}")
|
||||
message(STATUS " WindowSystem: ${WITH_WS}")
|
3
source/hpr/containers.hpp
Normal file
3
source/hpr/containers.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "containers/array.hpp"
|
28
source/hpr/containers/CMakeLists.txt
Normal file
28
source/hpr/containers/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
set(COMPONENT_NAME containers)
|
||||
|
||||
add_component_library(${COMPONENT_NAME} INTERFACE ""
|
||||
)
|
||||
|
||||
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||
# array/dynamic_array.hpp
|
||||
# array.hpp
|
||||
# array/iterator.hpp
|
||||
# array/static_array.hpp
|
||||
#)
|
||||
|
||||
install_component_headers(${COMPONENT_NAME})
|
||||
install_component_source(${COMPONENT_NAME})
|
||||
|
||||
if (WITH_GTEST)
|
||||
add_executable(${COMPONENT_NAME}-test
|
||||
tests/${COMPONENT_NAME}-test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}-test
|
||||
${CMAKE_PROJECT_NAME}::${COMPONENT_NAME}
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||
endif()
|
4
source/hpr/containers/array.hpp
Normal file
4
source/hpr/containers/array.hpp
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include "array/dynamic_array.hpp"
|
||||
#include "array/static_array.hpp"
|
@ -358,6 +358,7 @@ public:
|
||||
p_size = newSize;
|
||||
p_end = p_start + p_size;
|
||||
}
|
||||
|
||||
/*virtual
|
||||
void remove(const value_type& value)
|
||||
{
|
||||
@ -418,4 +419,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// Aliases
|
||||
|
||||
template <typename Type>
|
||||
using darray = DynamicArray<Type>;
|
||||
|
||||
}
|
@ -248,4 +248,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// Aliases
|
||||
|
||||
template <typename Type, size_t Size>
|
||||
using sarray = StaticArray<Type, Size>;
|
||||
|
||||
}
|
37
source/hpr/containers/tests/containers-test.cpp
Normal file
37
source/hpr/containers/tests/containers-test.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../array.hpp"
|
||||
|
||||
|
||||
TEST(containers, StaticArray)
|
||||
{
|
||||
hpr::StaticArray<float, 3> arr {1, 3, 2};
|
||||
hpr::StaticArray<float, 4> sarr {arr, 5};
|
||||
hpr::StaticArray<float, 4> sarr2 {1, 3, 2, 5};
|
||||
EXPECT_EQ(sarr, sarr2);
|
||||
}
|
||||
|
||||
TEST(containers, DynamicArray)
|
||||
{
|
||||
hpr::DynamicArray<float> arr {1, 3, 2};
|
||||
hpr::DynamicArray<float> arr2 {1, 3, 2};
|
||||
EXPECT_EQ(arr, arr2);
|
||||
arr.remove(1);
|
||||
EXPECT_EQ(arr, hpr::darray<float>({1, 2}));
|
||||
auto iter = arr2.begin();
|
||||
++iter;
|
||||
arr2.remove(iter);
|
||||
EXPECT_EQ(arr2, hpr::darray<float>({1, 2}));
|
||||
|
||||
hpr::DynamicArray<float> arr3 {1, 3, 0, 2, 9, 0, 5};
|
||||
arr3.remove([](float num) { return num == 0; });
|
||||
EXPECT_EQ(arr3, hpr::darray<float>({1, 3, 2, 9, 5}));
|
||||
EXPECT_EQ(arr3.size(), 5);
|
||||
|
||||
hpr::DynamicArray<float*> arr4;
|
||||
arr4.push(new float(5));
|
||||
arr4.push(new float(7));
|
||||
arr4.push(new float(9));
|
||||
EXPECT_EQ(*arr4[0], 5.f);
|
||||
EXPECT_EQ(*arr4[2], 9.f);
|
||||
}
|
12
source/hpr/csg.hpp
Normal file
12
source/hpr/csg.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "csg/shape.hpp"
|
||||
#include "csg/vertex.hpp"
|
||||
#include "csg/edge.hpp"
|
||||
#include "csg/wire.hpp"
|
||||
#include "csg/face.hpp"
|
||||
#include "csg/shell.hpp"
|
||||
#include "csg/solid.hpp"
|
||||
#include "csg/compound.hpp"
|
||||
#include "csg/geometry.hpp"
|
||||
#include "csg/surface.hpp"
|
35
source/hpr/csg/CMakeLists.txt
Normal file
35
source/hpr/csg/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
set(COMPONENT_NAME csg)
|
||||
|
||||
add_component_library(${COMPONENT_NAME} STATIC
|
||||
shape.cpp
|
||||
)
|
||||
|
||||
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||
|
||||
#)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}
|
||||
${OCCT_LIBRARIES}
|
||||
)
|
||||
|
||||
target_include_directories(${COMPONENT_NAME}
|
||||
PUBLIC
|
||||
${OCCT_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
install_component_headers(${COMPONENT_NAME})
|
||||
install_component_source(${COMPONENT_NAME})
|
||||
|
||||
if (0)
|
||||
add_executable(${COMPONENT_NAME}-test
|
||||
tests/${COMPONENT_NAME}-test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}-test
|
||||
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||
endif()
|
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../hyplib/scalar/scalar.hpp"
|
||||
#include "../hyplib/vector/vector.hpp"
|
||||
#include "../containers/array.hpp"
|
||||
#include "../math/scalar.hpp"
|
||||
#include "../math/vector.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "../csg.hpp"
|
||||
#include "../../csg.hpp"
|
||||
|
||||
TEST(csgTest, Shape)
|
||||
{
|
15
source/hpr/gpu.hpp
Normal file
15
source/hpr/gpu.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "gpu/context.hpp"
|
||||
#include "gpu/shader.hpp"
|
||||
#include "gpu/shader_program.hpp"
|
||||
#include "gpu/buffer.hpp"
|
||||
#include "gpu/device.hpp"
|
||||
#include "gpu/texture.hpp"
|
||||
|
||||
#include "gpu/opengl/context.hpp"
|
||||
#include "gpu/opengl/shader.hpp"
|
||||
#include "gpu/opengl/shader_program.hpp"
|
||||
#include "gpu/opengl/buffer.hpp"
|
||||
#include "gpu/opengl/device.hpp"
|
||||
#include "gpu/opengl/texture.hpp"
|
42
source/hpr/gpu/CMakeLists.txt
Normal file
42
source/hpr/gpu/CMakeLists.txt
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
set(COMPONENT_NAME gpu)
|
||||
|
||||
add_component_library(${COMPONENT_NAME} STATIC
|
||||
buffer.cpp
|
||||
context.cpp
|
||||
device.cpp
|
||||
shader.cpp
|
||||
shader_program.cpp
|
||||
texture.cpp
|
||||
opengl/buffer.cpp
|
||||
opengl/context.cpp
|
||||
opengl/device.cpp
|
||||
opengl/shader.cpp
|
||||
opengl/shader_program.cpp
|
||||
opengl/texture.cpp
|
||||
)
|
||||
|
||||
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||
|
||||
#)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}
|
||||
glad
|
||||
stb
|
||||
)
|
||||
|
||||
install_component_headers(${COMPONENT_NAME})
|
||||
install_component_source(${COMPONENT_NAME})
|
||||
|
||||
if (0)
|
||||
add_executable(${COMPONENT_NAME}-test
|
||||
tests/${COMPONENT_NAME}-test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}-test
|
||||
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||
endif()
|
@ -1,36 +1,36 @@
|
||||
|
||||
#include "buffer.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
Buffer::Buffer() :
|
||||
Context {DeviceAPI::Unknown},
|
||||
p_type {BufferType::Undefined},
|
||||
p_size {0},
|
||||
p_stride {0}
|
||||
{}
|
||||
|
||||
Buffer::Buffer(DeviceAPI api) :
|
||||
Context {api},
|
||||
p_type {BufferType::Undefined},
|
||||
p_size {0},
|
||||
p_stride {0}
|
||||
{}
|
||||
|
||||
Buffer::~Buffer() = default;
|
||||
|
||||
// Member functions
|
||||
|
||||
int Buffer::size() const
|
||||
{
|
||||
return p_size;
|
||||
}
|
||||
|
||||
Buffer::BufferType Buffer::type() const
|
||||
{
|
||||
return p_type;
|
||||
}
|
||||
|
||||
|
||||
#include "buffer.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
Buffer::Buffer() :
|
||||
Context {DeviceAPI::Unknown},
|
||||
p_type {BufferType::Undefined},
|
||||
p_size {0},
|
||||
p_stride {0}
|
||||
{}
|
||||
|
||||
Buffer::Buffer(DeviceAPI api) :
|
||||
Context {api},
|
||||
p_type {BufferType::Undefined},
|
||||
p_size {0},
|
||||
p_stride {0}
|
||||
{}
|
||||
|
||||
Buffer::~Buffer() = default;
|
||||
|
||||
// Member functions
|
||||
|
||||
int Buffer::size() const
|
||||
{
|
||||
return p_size;
|
||||
}
|
||||
|
||||
Buffer::BufferType Buffer::type() const
|
||||
{
|
||||
return p_type;
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
class Buffer : public Context
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
public:
|
||||
|
||||
enum class BufferType
|
||||
{
|
||||
Undefined,
|
||||
Vertex,
|
||||
Index,
|
||||
Uniform,
|
||||
BufferTypeCount
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
BufferType p_type;
|
||||
int p_size;
|
||||
int p_stride;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Buffer();
|
||||
|
||||
explicit
|
||||
Buffer(DeviceAPI api);
|
||||
|
||||
~Buffer() override;
|
||||
|
||||
// Member functions
|
||||
|
||||
[[nodiscard]]
|
||||
int size() const;
|
||||
|
||||
[[nodiscard]]
|
||||
BufferType type() const;
|
||||
};
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
class Buffer : public Context
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
public:
|
||||
|
||||
enum class BufferType
|
||||
{
|
||||
Undefined,
|
||||
Vertex,
|
||||
Index,
|
||||
Uniform,
|
||||
BufferTypeCount
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
BufferType p_type;
|
||||
int p_size;
|
||||
int p_stride;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Buffer();
|
||||
|
||||
explicit
|
||||
Buffer(DeviceAPI api);
|
||||
|
||||
~Buffer() override;
|
||||
|
||||
// Member functions
|
||||
|
||||
[[nodiscard]]
|
||||
int size() const;
|
||||
|
||||
[[nodiscard]]
|
||||
BufferType type() const;
|
||||
};
|
||||
|
||||
} // end namespace hpr::gpu
|
@ -1,244 +1,244 @@
|
||||
|
||||
#include "device.hpp"
|
||||
#include "opengl/device.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
Device::Device() :
|
||||
Context {DeviceAPI::Unknown},
|
||||
p_currentVertexBuffer {},
|
||||
p_currentIndexBuffer {},
|
||||
p_currentUniformBuffer {},
|
||||
p_currentShaderProgram {}
|
||||
{}
|
||||
|
||||
Device::Device(DeviceAPI api) :
|
||||
Context {api},
|
||||
p_currentVertexBuffer {},
|
||||
p_currentIndexBuffer {},
|
||||
p_currentUniformBuffer {},
|
||||
p_currentShaderProgram {}
|
||||
{}
|
||||
|
||||
Device::~Device()
|
||||
{
|
||||
for (auto& shader : p_shaders)
|
||||
delete shader;
|
||||
for (auto& buffer : p_buffers)
|
||||
delete buffer;
|
||||
for (auto& shaderProgram : p_shaderPrograms)
|
||||
delete shaderProgram;
|
||||
for (auto& texture : p_textures)
|
||||
delete texture;
|
||||
}
|
||||
|
||||
// Global functions
|
||||
|
||||
void Device::create(Device** device, DeviceAPI api)
|
||||
{
|
||||
if (device == nullptr)
|
||||
throw std::invalid_argument("Invalid parameter 'nullptr'");
|
||||
if (api == DeviceAPI::Unknown)
|
||||
throw std::invalid_argument("Cannot create device for 'Unknown'");
|
||||
|
||||
*device = nullptr;
|
||||
|
||||
if (api == DeviceAPI::OpenGL)
|
||||
*device = new opengl::Device;
|
||||
else
|
||||
throw std::invalid_argument("Unsupported device");
|
||||
}
|
||||
|
||||
// Render targets
|
||||
|
||||
void Device::moveRenderTarget(RenderTarget* target, int x, int y)
|
||||
{
|
||||
if (target == nullptr)
|
||||
throw std::invalid_argument("Invalid parameter");
|
||||
target->p_posX = x;
|
||||
target->p_posY = y;
|
||||
}
|
||||
|
||||
void Device::scaleRenderTarget(RenderTarget* target, int width, int height)
|
||||
{
|
||||
if (target == nullptr)
|
||||
throw std::invalid_argument("Invalid parameter");
|
||||
target->p_width = width;
|
||||
target->p_height = height;
|
||||
}
|
||||
|
||||
void Device::destroyRenderTarget(RenderTarget*& target)
|
||||
{
|
||||
if (!target)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
|
||||
for (auto iter = p_renderTargets.begin(); iter != p_renderTargets.end(); ++iter)
|
||||
if (*iter == target)
|
||||
{
|
||||
delete target;
|
||||
target = nullptr;
|
||||
p_renderTargets.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Buffers
|
||||
|
||||
void Device::useVertexBuffer(Buffer* buffer, int stride, int offset)
|
||||
{
|
||||
if (buffer)
|
||||
{
|
||||
if (buffer->p_type == Buffer::BufferType::Vertex)
|
||||
{
|
||||
p_currentVertexBuffer = buffer;
|
||||
p_currentVertexBuffer->p_stride = stride;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("Incompatible buffer");
|
||||
}
|
||||
else
|
||||
p_currentVertexBuffer = nullptr;
|
||||
}
|
||||
|
||||
void Device::useIndexBuffer(Buffer* buffer, int offset)
|
||||
{
|
||||
if (buffer)
|
||||
{
|
||||
if (buffer->p_type == Buffer::BufferType::Index)
|
||||
{
|
||||
p_currentIndexBuffer = buffer;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("Incompatible buffer");
|
||||
}
|
||||
else
|
||||
p_currentIndexBuffer = nullptr;
|
||||
}
|
||||
|
||||
void Device::useUniformBuffer(Buffer* buffer, int slot)
|
||||
{
|
||||
if (buffer)
|
||||
{
|
||||
if (buffer->p_type == Buffer::BufferType::Uniform)
|
||||
p_currentUniformBuffer = buffer;
|
||||
else
|
||||
throw std::runtime_error("Incompatible buffer");
|
||||
}
|
||||
else
|
||||
p_currentUniformBuffer = nullptr;
|
||||
}
|
||||
|
||||
void Device::destroyBuffer(Buffer*& buffer)
|
||||
{
|
||||
if (!buffer)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
|
||||
for (auto iter = p_buffers.begin(); iter != p_buffers.end(); ++iter)
|
||||
if (*iter == buffer)
|
||||
{
|
||||
delete buffer;
|
||||
buffer = nullptr;
|
||||
p_buffers.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Buffer* Device::activeBuffer(Buffer::BufferType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Buffer::BufferType::Vertex:
|
||||
return p_currentVertexBuffer;
|
||||
case Buffer::BufferType::Index:
|
||||
return p_currentIndexBuffer;
|
||||
case Buffer::BufferType::Uniform:
|
||||
return p_currentUniformBuffer;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Shaders
|
||||
|
||||
void Device::destroyShader(Shader* shader)
|
||||
{
|
||||
if (shader == nullptr)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
|
||||
for (auto iter = p_shaders.begin(); iter != p_shaders.end(); ++iter)
|
||||
if (*iter == shader)
|
||||
{
|
||||
delete shader;
|
||||
shader = nullptr;
|
||||
p_shaders.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Shader programs
|
||||
|
||||
void Device::attachShader(ShaderProgram *program, Shader *shader)
|
||||
{
|
||||
if (program == nullptr || shader == nullptr)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
if (program->p_isLinked)
|
||||
throw std::runtime_error("Shader program already linked");
|
||||
|
||||
program->p_slots[(int)shader->p_type] = shader;
|
||||
}
|
||||
|
||||
void Device::linkProgram(ShaderProgram *program)
|
||||
{
|
||||
if (program == nullptr)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
if (program->p_isLinked)
|
||||
throw std::runtime_error("Shader program already linked");
|
||||
|
||||
program->p_isLinked = true;
|
||||
}
|
||||
|
||||
void Device::useShaderProgram(ShaderProgram *program)
|
||||
{
|
||||
if (program != nullptr)
|
||||
if (!program->p_isLinked)
|
||||
throw std::runtime_error("Shader program is not linked");
|
||||
|
||||
p_currentShaderProgram = program;
|
||||
}
|
||||
|
||||
void Device::destroyShaderProgram(ShaderProgram *&program, bool withShaders)
|
||||
{
|
||||
if (program == p_currentShaderProgram)
|
||||
useShaderProgram(nullptr);
|
||||
|
||||
if (withShaders)
|
||||
for (size_t n = 0; n < (size_t)Shader::ShaderType::ShaderTypeCount; n++)
|
||||
destroyShader(program->p_slots[n]);
|
||||
|
||||
for (auto iter = p_shaderPrograms.begin(); iter != p_shaderPrograms.end(); ++iter)
|
||||
if (*iter == program)
|
||||
{
|
||||
delete program;
|
||||
program = nullptr;
|
||||
p_shaderPrograms.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Textures
|
||||
|
||||
void Device::destroyTexture(Texture *&texture)
|
||||
{
|
||||
for (auto iter = p_textures.begin(); iter != p_textures.end(); ++iter)
|
||||
if (*iter == texture)
|
||||
{
|
||||
delete texture;
|
||||
texture = nullptr;
|
||||
p_textures.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include "device.hpp"
|
||||
#include "opengl/device.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
Device::Device() :
|
||||
Context {DeviceAPI::Unknown},
|
||||
p_currentVertexBuffer {},
|
||||
p_currentIndexBuffer {},
|
||||
p_currentUniformBuffer {},
|
||||
p_currentShaderProgram {}
|
||||
{}
|
||||
|
||||
Device::Device(DeviceAPI api) :
|
||||
Context {api},
|
||||
p_currentVertexBuffer {},
|
||||
p_currentIndexBuffer {},
|
||||
p_currentUniformBuffer {},
|
||||
p_currentShaderProgram {}
|
||||
{}
|
||||
|
||||
Device::~Device()
|
||||
{
|
||||
for (auto& shader : p_shaders)
|
||||
delete shader;
|
||||
for (auto& buffer : p_buffers)
|
||||
delete buffer;
|
||||
for (auto& shaderProgram : p_shaderPrograms)
|
||||
delete shaderProgram;
|
||||
for (auto& texture : p_textures)
|
||||
delete texture;
|
||||
}
|
||||
|
||||
// Global functions
|
||||
|
||||
void Device::create(Device** device, DeviceAPI api)
|
||||
{
|
||||
if (device == nullptr)
|
||||
throw std::invalid_argument("Invalid parameter 'nullptr'");
|
||||
if (api == DeviceAPI::Unknown)
|
||||
throw std::invalid_argument("Cannot create device for 'Unknown'");
|
||||
|
||||
*device = nullptr;
|
||||
|
||||
if (api == DeviceAPI::OpenGL)
|
||||
*device = new opengl::Device;
|
||||
else
|
||||
throw std::invalid_argument("Unsupported device");
|
||||
}
|
||||
|
||||
// Render targets
|
||||
|
||||
void Device::moveRenderTarget(RenderTarget* target, int x, int y)
|
||||
{
|
||||
if (target == nullptr)
|
||||
throw std::invalid_argument("Invalid parameter");
|
||||
target->p_posX = x;
|
||||
target->p_posY = y;
|
||||
}
|
||||
|
||||
void Device::scaleRenderTarget(RenderTarget* target, int width, int height)
|
||||
{
|
||||
if (target == nullptr)
|
||||
throw std::invalid_argument("Invalid parameter");
|
||||
target->p_width = width;
|
||||
target->p_height = height;
|
||||
}
|
||||
|
||||
void Device::destroyRenderTarget(RenderTarget*& target)
|
||||
{
|
||||
if (!target)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
|
||||
for (auto iter = p_renderTargets.begin(); iter != p_renderTargets.end(); ++iter)
|
||||
if (*iter == target)
|
||||
{
|
||||
delete target;
|
||||
target = nullptr;
|
||||
p_renderTargets.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Buffers
|
||||
|
||||
void Device::useVertexBuffer(Buffer* buffer, int stride, int offset)
|
||||
{
|
||||
if (buffer)
|
||||
{
|
||||
if (buffer->p_type == Buffer::BufferType::Vertex)
|
||||
{
|
||||
p_currentVertexBuffer = buffer;
|
||||
p_currentVertexBuffer->p_stride = stride;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("Incompatible buffer");
|
||||
}
|
||||
else
|
||||
p_currentVertexBuffer = nullptr;
|
||||
}
|
||||
|
||||
void Device::useIndexBuffer(Buffer* buffer, int offset)
|
||||
{
|
||||
if (buffer)
|
||||
{
|
||||
if (buffer->p_type == Buffer::BufferType::Index)
|
||||
{
|
||||
p_currentIndexBuffer = buffer;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("Incompatible buffer");
|
||||
}
|
||||
else
|
||||
p_currentIndexBuffer = nullptr;
|
||||
}
|
||||
|
||||
void Device::useUniformBuffer(Buffer* buffer, int slot)
|
||||
{
|
||||
if (buffer)
|
||||
{
|
||||
if (buffer->p_type == Buffer::BufferType::Uniform)
|
||||
p_currentUniformBuffer = buffer;
|
||||
else
|
||||
throw std::runtime_error("Incompatible buffer");
|
||||
}
|
||||
else
|
||||
p_currentUniformBuffer = nullptr;
|
||||
}
|
||||
|
||||
void Device::destroyBuffer(Buffer*& buffer)
|
||||
{
|
||||
if (!buffer)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
|
||||
for (auto iter = p_buffers.begin(); iter != p_buffers.end(); ++iter)
|
||||
if (*iter == buffer)
|
||||
{
|
||||
delete buffer;
|
||||
buffer = nullptr;
|
||||
p_buffers.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Buffer* Device::activeBuffer(Buffer::BufferType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Buffer::BufferType::Vertex:
|
||||
return p_currentVertexBuffer;
|
||||
case Buffer::BufferType::Index:
|
||||
return p_currentIndexBuffer;
|
||||
case Buffer::BufferType::Uniform:
|
||||
return p_currentUniformBuffer;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Shaders
|
||||
|
||||
void Device::destroyShader(Shader* shader)
|
||||
{
|
||||
if (shader == nullptr)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
|
||||
for (auto iter = p_shaders.begin(); iter != p_shaders.end(); ++iter)
|
||||
if (*iter == shader)
|
||||
{
|
||||
delete shader;
|
||||
shader = nullptr;
|
||||
p_shaders.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Shader programs
|
||||
|
||||
void Device::attachShader(ShaderProgram *program, Shader *shader)
|
||||
{
|
||||
if (program == nullptr || shader == nullptr)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
if (program->p_isLinked)
|
||||
throw std::runtime_error("Shader program already linked");
|
||||
|
||||
program->p_slots[(int)shader->p_type] = shader;
|
||||
}
|
||||
|
||||
void Device::linkProgram(ShaderProgram *program)
|
||||
{
|
||||
if (program == nullptr)
|
||||
throw std::runtime_error("Invalid parameter");
|
||||
if (program->p_isLinked)
|
||||
throw std::runtime_error("Shader program already linked");
|
||||
|
||||
program->p_isLinked = true;
|
||||
}
|
||||
|
||||
void Device::useShaderProgram(ShaderProgram *program)
|
||||
{
|
||||
if (program != nullptr)
|
||||
if (!program->p_isLinked)
|
||||
throw std::runtime_error("Shader program is not linked");
|
||||
|
||||
p_currentShaderProgram = program;
|
||||
}
|
||||
|
||||
void Device::destroyShaderProgram(ShaderProgram *&program, bool withShaders)
|
||||
{
|
||||
if (program == p_currentShaderProgram)
|
||||
useShaderProgram(nullptr);
|
||||
|
||||
if (withShaders)
|
||||
for (size_t n = 0; n < (size_t)Shader::ShaderType::ShaderTypeCount; n++)
|
||||
destroyShader(program->p_slots[n]);
|
||||
|
||||
for (auto iter = p_shaderPrograms.begin(); iter != p_shaderPrograms.end(); ++iter)
|
||||
if (*iter == program)
|
||||
{
|
||||
delete program;
|
||||
program = nullptr;
|
||||
p_shaderPrograms.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Textures
|
||||
|
||||
void Device::destroyTexture(Texture *&texture)
|
||||
{
|
||||
for (auto iter = p_textures.begin(); iter != p_textures.end(); ++iter)
|
||||
if (*iter == texture)
|
||||
{
|
||||
delete texture;
|
||||
texture = nullptr;
|
||||
p_textures.remove(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,148 +1,148 @@
|
||||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
#include "buffer.hpp"
|
||||
#include "shader.hpp"
|
||||
#include "shader_program.hpp"
|
||||
#include "texture.hpp"
|
||||
#include "render_target.hpp"
|
||||
|
||||
#include "../hyplib/array/array.hpp"
|
||||
|
||||
#include "../window_system/window_system.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
class Device : public Context
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum class CullMode
|
||||
{
|
||||
Front,
|
||||
Back,
|
||||
FrontAndBack,
|
||||
None
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
darray<Buffer*> p_buffers;
|
||||
darray<Shader*> p_shaders;
|
||||
darray<ShaderProgram*> p_shaderPrograms;
|
||||
darray<Texture*> p_textures;
|
||||
|
||||
Buffer* p_currentVertexBuffer;
|
||||
Buffer* p_currentIndexBuffer;
|
||||
Buffer* p_currentUniformBuffer;
|
||||
ShaderProgram* p_currentShaderProgram;
|
||||
|
||||
darray<RenderTarget*> p_renderTargets;
|
||||
protected:
|
||||
|
||||
// Constructors
|
||||
|
||||
Device();
|
||||
|
||||
explicit
|
||||
Device(DeviceAPI api);
|
||||
|
||||
~Device() override;
|
||||
|
||||
public:
|
||||
|
||||
// Global functions
|
||||
|
||||
static
|
||||
void create(Device** device, DeviceAPI api);
|
||||
|
||||
// Member functions
|
||||
|
||||
// Setup
|
||||
|
||||
virtual
|
||||
bool initialize() = 0;
|
||||
virtual
|
||||
bool destroy() = 0;
|
||||
|
||||
// State
|
||||
|
||||
virtual
|
||||
void faceCulling(bool enableFaceCulling, CullMode faceCullingMode) = 0;
|
||||
|
||||
// Render targets
|
||||
|
||||
virtual
|
||||
void createScreenRenderTarget(RenderTarget** target, Window* window) = 0;
|
||||
virtual
|
||||
void createFramebufferRenderTarget(RenderTarget** target, int width, int height) = 0;
|
||||
virtual
|
||||
void createSubRenderTarget(RenderTarget** target, RenderTarget* parent, int x, int y, int width, int height) = 0;
|
||||
virtual
|
||||
void moveRenderTarget(RenderTarget* target, int x, int y);
|
||||
virtual
|
||||
void scaleRenderTarget(RenderTarget* target, int width, int height);
|
||||
virtual
|
||||
void destroyRenderTarget(RenderTarget*& target);
|
||||
|
||||
// Buffers
|
||||
|
||||
virtual
|
||||
void createVertexBuffer(Buffer **buffer, int size, char* data) = 0;
|
||||
virtual
|
||||
void createIndexBuffer(Buffer **buffer, int size, char* data) = 0;
|
||||
virtual
|
||||
void createUniformBuffer(Buffer **buffer, int size, char* data) = 0;
|
||||
virtual
|
||||
void useVertexBuffer(Buffer* buffer, int stride, int offset);
|
||||
virtual
|
||||
void useIndexBuffer(Buffer* buffer, int offset);
|
||||
virtual
|
||||
void useUniformBuffer(Buffer* buffer, int slot);
|
||||
virtual
|
||||
void editBuffer(Buffer* buffer, char* data, int size, int offset) = 0;
|
||||
virtual
|
||||
void editBuffer(Buffer* buffer, char* data) = 0;
|
||||
virtual
|
||||
void destroyBuffer(Buffer*& buffer);
|
||||
Buffer* activeBuffer(Buffer::BufferType type);
|
||||
|
||||
|
||||
// Shaders
|
||||
|
||||
virtual
|
||||
void createVertexShader(Shader** shader, const std::string& filename, const std::string& label) = 0;
|
||||
virtual
|
||||
void createFragmentShader(Shader** shader, const std::string& filename, const std::string& label) = 0;
|
||||
virtual
|
||||
void createGeometryShader(Shader** shader, const std::string& filename, const std::string& label) = 0;
|
||||
virtual
|
||||
void destroyShader(Shader* shader);
|
||||
|
||||
// Shader programs
|
||||
|
||||
virtual
|
||||
void createShaderProgram(ShaderProgram** program) = 0;
|
||||
virtual
|
||||
void attachShader(ShaderProgram* program, Shader* shader);
|
||||
virtual
|
||||
void linkProgram(ShaderProgram* program);
|
||||
virtual
|
||||
void useShaderProgram(ShaderProgram* program);
|
||||
virtual
|
||||
void destroyShaderProgram(ShaderProgram*& program, bool withShaders);
|
||||
|
||||
// Textures
|
||||
|
||||
virtual
|
||||
void createTexture(Texture** texture, const std::string& filename) = 0;
|
||||
virtual
|
||||
void useTexture(Texture* texture, int slot) = 0;
|
||||
virtual
|
||||
void destroyTexture(Texture*& texture);
|
||||
};
|
||||
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
#include "buffer.hpp"
|
||||
#include "shader.hpp"
|
||||
#include "shader_program.hpp"
|
||||
#include "texture.hpp"
|
||||
#include "render_target.hpp"
|
||||
|
||||
#include "../containers/array.hpp"
|
||||
|
||||
#include "../window_system/window_system.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
class Device : public Context
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum class CullMode
|
||||
{
|
||||
Front,
|
||||
Back,
|
||||
FrontAndBack,
|
||||
None
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
darray<Buffer*> p_buffers;
|
||||
darray<Shader*> p_shaders;
|
||||
darray<ShaderProgram*> p_shaderPrograms;
|
||||
darray<Texture*> p_textures;
|
||||
|
||||
Buffer* p_currentVertexBuffer;
|
||||
Buffer* p_currentIndexBuffer;
|
||||
Buffer* p_currentUniformBuffer;
|
||||
ShaderProgram* p_currentShaderProgram;
|
||||
|
||||
darray<RenderTarget*> p_renderTargets;
|
||||
protected:
|
||||
|
||||
// Constructors
|
||||
|
||||
Device();
|
||||
|
||||
explicit
|
||||
Device(DeviceAPI api);
|
||||
|
||||
~Device() override;
|
||||
|
||||
public:
|
||||
|
||||
// Global functions
|
||||
|
||||
static
|
||||
void create(Device** device, DeviceAPI api);
|
||||
|
||||
// Member functions
|
||||
|
||||
// Setup
|
||||
|
||||
virtual
|
||||
bool initialize() = 0;
|
||||
virtual
|
||||
bool destroy() = 0;
|
||||
|
||||
// State
|
||||
|
||||
virtual
|
||||
void faceCulling(bool enableFaceCulling, CullMode faceCullingMode) = 0;
|
||||
|
||||
// Render targets
|
||||
|
||||
virtual
|
||||
void createScreenRenderTarget(RenderTarget** target, Window* window) = 0;
|
||||
virtual
|
||||
void createFramebufferRenderTarget(RenderTarget** target, int width, int height) = 0;
|
||||
virtual
|
||||
void createSubRenderTarget(RenderTarget** target, RenderTarget* parent, int x, int y, int width, int height) = 0;
|
||||
virtual
|
||||
void moveRenderTarget(RenderTarget* target, int x, int y);
|
||||
virtual
|
||||
void scaleRenderTarget(RenderTarget* target, int width, int height);
|
||||
virtual
|
||||
void destroyRenderTarget(RenderTarget*& target);
|
||||
|
||||
// Buffers
|
||||
|
||||
virtual
|
||||
void createVertexBuffer(Buffer **buffer, int size, char* data) = 0;
|
||||
virtual
|
||||
void createIndexBuffer(Buffer **buffer, int size, char* data) = 0;
|
||||
virtual
|
||||
void createUniformBuffer(Buffer **buffer, int size, char* data) = 0;
|
||||
virtual
|
||||
void useVertexBuffer(Buffer* buffer, int stride, int offset);
|
||||
virtual
|
||||
void useIndexBuffer(Buffer* buffer, int offset);
|
||||
virtual
|
||||
void useUniformBuffer(Buffer* buffer, int slot);
|
||||
virtual
|
||||
void editBuffer(Buffer* buffer, char* data, int size, int offset) = 0;
|
||||
virtual
|
||||
void editBuffer(Buffer* buffer, char* data) = 0;
|
||||
virtual
|
||||
void destroyBuffer(Buffer*& buffer);
|
||||
Buffer* activeBuffer(Buffer::BufferType type);
|
||||
|
||||
|
||||
// Shaders
|
||||
|
||||
virtual
|
||||
void createVertexShader(Shader** shader, const std::string& filename, const std::string& label) = 0;
|
||||
virtual
|
||||
void createFragmentShader(Shader** shader, const std::string& filename, const std::string& label) = 0;
|
||||
virtual
|
||||
void createGeometryShader(Shader** shader, const std::string& filename, const std::string& label) = 0;
|
||||
virtual
|
||||
void destroyShader(Shader* shader);
|
||||
|
||||
// Shader programs
|
||||
|
||||
virtual
|
||||
void createShaderProgram(ShaderProgram** program) = 0;
|
||||
virtual
|
||||
void attachShader(ShaderProgram* program, Shader* shader);
|
||||
virtual
|
||||
void linkProgram(ShaderProgram* program);
|
||||
virtual
|
||||
void useShaderProgram(ShaderProgram* program);
|
||||
virtual
|
||||
void destroyShaderProgram(ShaderProgram*& program, bool withShaders);
|
||||
|
||||
// Textures
|
||||
|
||||
virtual
|
||||
void createTexture(Texture** texture, const std::string& filename) = 0;
|
||||
virtual
|
||||
void useTexture(Texture* texture, int slot) = 0;
|
||||
virtual
|
||||
void destroyTexture(Texture*& texture);
|
||||
};
|
||||
|
||||
}
|
@ -1,31 +1,31 @@
|
||||
|
||||
#include "buffer.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
Buffer::Buffer() :
|
||||
gpu::Buffer(DeviceAPI::OpenGL),
|
||||
p_bufferIndex {0},
|
||||
p_vertexArrayIndex {0}
|
||||
{}
|
||||
|
||||
Buffer::~Buffer() = default;
|
||||
|
||||
int Buffer::target() const
|
||||
{
|
||||
switch (p_type)
|
||||
{
|
||||
case BufferType::Vertex:
|
||||
return GL_ARRAY_BUFFER;
|
||||
case BufferType::Index:
|
||||
return GL_ELEMENT_ARRAY_BUFFER;
|
||||
default:
|
||||
return GL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include "buffer.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
Buffer::Buffer() :
|
||||
gpu::Buffer(DeviceAPI::OpenGL),
|
||||
p_bufferIndex {0},
|
||||
p_vertexArrayIndex {0}
|
||||
{}
|
||||
|
||||
Buffer::~Buffer() = default;
|
||||
|
||||
int Buffer::target() const
|
||||
{
|
||||
switch (p_type)
|
||||
{
|
||||
case BufferType::Vertex:
|
||||
return GL_ARRAY_BUFFER;
|
||||
case BufferType::Index:
|
||||
return GL_ELEMENT_ARRAY_BUFFER;
|
||||
default:
|
||||
return GL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "../buffer.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
class Buffer : public gpu::Buffer
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
protected:
|
||||
unsigned int p_bufferIndex;
|
||||
unsigned int p_vertexArrayIndex;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Buffer();
|
||||
|
||||
virtual ~Buffer();
|
||||
|
||||
// Member functions
|
||||
|
||||
int target() const;
|
||||
};
|
||||
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include "../buffer.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
class Buffer : public gpu::Buffer
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
protected:
|
||||
unsigned int p_bufferIndex;
|
||||
unsigned int p_vertexArrayIndex;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Buffer();
|
||||
|
||||
virtual ~Buffer();
|
||||
|
||||
// Member functions
|
||||
|
||||
int target() const;
|
||||
};
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Created by L-Nafaryus on 10/3/2022.
|
||||
//
|
||||
|
||||
#include "context.hpp"
|
||||
//
|
||||
// Created by L-Nafaryus on 10/3/2022.
|
||||
//
|
||||
|
||||
#include "context.hpp"
|
@ -1,8 +1,8 @@
|
||||
//
|
||||
// Created by L-Nafaryus on 10/3/2022.
|
||||
//
|
||||
|
||||
#ifndef HYPORO_CONTEXT_HPP
|
||||
#define HYPORO_CONTEXT_HPP
|
||||
|
||||
#endif //HYPORO_CONTEXT_HPP
|
||||
//
|
||||
// Created by L-Nafaryus on 10/3/2022.
|
||||
//
|
||||
|
||||
#ifndef HYPORO_CONTEXT_HPP
|
||||
#define HYPORO_CONTEXT_HPP
|
||||
|
||||
#endif //HYPORO_CONTEXT_HPP
|
File diff suppressed because it is too large
Load Diff
@ -1,88 +1,106 @@
|
||||
#pragma once
|
||||
|
||||
#include "../device.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
class Device : public gpu::Device
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
bool p_isInitialized;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Device();
|
||||
|
||||
~Device() override;
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Setup
|
||||
|
||||
bool initialize() override;
|
||||
bool destroy() override;
|
||||
|
||||
static
|
||||
bool loadLoader();
|
||||
|
||||
// State
|
||||
|
||||
void faceCulling(bool enableFaceCulling, CullMode faceCullingMode) override;
|
||||
|
||||
// Render targets
|
||||
|
||||
void createScreenRenderTarget(RenderTarget** target, Window* window) override;
|
||||
void createFramebufferRenderTarget(RenderTarget** target, int width, int height) override;
|
||||
void createSubRenderTarget(RenderTarget** target, RenderTarget* parent, int x, int y, int width, int height) override;
|
||||
void moveRenderTarget(RenderTarget* target, int x, int y) override;
|
||||
void scaleRenderTarget(RenderTarget* target, int width, int height) override;
|
||||
void destroyRenderTarget(RenderTarget*& target) override;
|
||||
|
||||
// Buffers
|
||||
|
||||
void createVertexBuffer(Buffer **buffer, int size, char* data) override;
|
||||
void createIndexBuffer(Buffer **buffer, int size, char* data) override;
|
||||
void createUniformBuffer(Buffer **buffer, int size, char* data) override;
|
||||
void useVertexBuffer(Buffer* buffer, int stride, int offset) override;
|
||||
void useIndexBuffer(Buffer* buffer, int offset) override;
|
||||
void useUniformBuffer(Buffer* buffer, int slot) override;
|
||||
void editBuffer(Buffer* buffer, char* data, int size, int offset) override;
|
||||
void editBuffer(Buffer* buffer, char* data) override;
|
||||
void destroyBuffer(Buffer*& buffer) override;
|
||||
|
||||
// Shaders
|
||||
|
||||
void createVertexShader(Shader** shader, const std::string& filename, const std::string& label) override;
|
||||
void createFragmentShader(Shader** shader, const std::string& filename, const std::string& label) override;
|
||||
void createGeometryShader(Shader** shader, const std::string& filename, const std::string& label) override;
|
||||
void destroyShader(Shader* shader) override;
|
||||
|
||||
// Shader programs
|
||||
|
||||
void createShaderProgram(ShaderProgram** program) override;
|
||||
void attachShader(ShaderProgram* program, Shader* shader) override;
|
||||
void linkProgram(ShaderProgram* program) override;
|
||||
void useShaderProgram(ShaderProgram* program) override;
|
||||
void destroyShaderProgram(ShaderProgram*& program, bool withShaders) override;
|
||||
|
||||
// Textures
|
||||
|
||||
void createTexture(Texture** texture, const std::string& filename) override;
|
||||
void useTexture(Texture* texture, int slot) override;
|
||||
void destroyTexture(Texture*& texture) override;
|
||||
|
||||
//
|
||||
|
||||
void Draw(int numFaces, int indexOffset, int vertexOffset);
|
||||
};
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../device.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
class Device : public gpu::Device
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
bool p_isInitialized;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Device();
|
||||
|
||||
~Device() override;
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Setup
|
||||
|
||||
bool initialize() override;
|
||||
bool destroy() override;
|
||||
|
||||
static
|
||||
bool loadLoader();
|
||||
|
||||
// State
|
||||
|
||||
void faceCulling(bool enableFaceCulling, CullMode faceCullingMode) override;
|
||||
|
||||
// Render targets
|
||||
|
||||
void createScreenRenderTarget(RenderTarget** target, Window* window) override;
|
||||
void createFramebufferRenderTarget(RenderTarget** target, int width, int height) override;
|
||||
void createSubRenderTarget(RenderTarget** target, RenderTarget* parent, int x, int y, int width, int height) override;
|
||||
void moveRenderTarget(RenderTarget* target, int x, int y) override;
|
||||
void scaleRenderTarget(RenderTarget* target, int width, int height) override;
|
||||
void destroyRenderTarget(RenderTarget*& target) override;
|
||||
|
||||
// Buffers
|
||||
|
||||
virtual
|
||||
void createVertexBuffer(Buffer **buffer, int size, char* data);
|
||||
virtual
|
||||
void createIndexBuffer(Buffer **buffer, int size, char* data);
|
||||
virtual
|
||||
void createUniformBuffer(Buffer **buffer, int size, char* data);
|
||||
virtual
|
||||
void useVertexBuffer(Buffer* buffer, int stride, int offset);
|
||||
virtual
|
||||
void useIndexBuffer(Buffer* buffer, int offset);
|
||||
virtual
|
||||
void useUniformBuffer(Buffer* buffer, int slot);
|
||||
virtual
|
||||
void editBuffer(Buffer* buffer, char* data, int size, int offset);
|
||||
virtual
|
||||
void editBuffer(Buffer* buffer, char* data);
|
||||
virtual
|
||||
void destroyBuffer(Buffer*& buffer);
|
||||
|
||||
// Shaders
|
||||
|
||||
virtual
|
||||
void createVertexShader(Shader** shader, const std::string& filename, const std::string& label);
|
||||
virtual
|
||||
void createFragmentShader(Shader** shader, const std::string& filename, const std::string& label);
|
||||
virtual
|
||||
void createGeometryShader(Shader** shader, const std::string& filename, const std::string& label);
|
||||
virtual
|
||||
void destroyShader(Shader* shader);
|
||||
|
||||
// Shader programs
|
||||
|
||||
virtual
|
||||
void createShaderProgram(ShaderProgram** program);
|
||||
virtual
|
||||
void attachShader(ShaderProgram* program, Shader* shader);
|
||||
virtual
|
||||
void linkProgram(ShaderProgram* program);
|
||||
virtual
|
||||
void useShaderProgram(ShaderProgram* program);
|
||||
virtual
|
||||
void destroyShaderProgram(ShaderProgram*& program, bool withShaders);
|
||||
|
||||
// Textures
|
||||
|
||||
void createTexture(Texture** texture, const std::string& filename) override;
|
||||
void useTexture(Texture* texture, int slot) override;
|
||||
void destroyTexture(Texture*& texture) override;
|
||||
|
||||
//
|
||||
|
||||
void Draw(int numFaces, int indexOffset, int vertexOffset);
|
||||
};
|
||||
|
||||
}
|
@ -1,18 +1,18 @@
|
||||
//
|
||||
// Created by L-Nafaryus on 10/3/2022.
|
||||
//
|
||||
|
||||
#include "shader.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
Shader::Shader() :
|
||||
gpu::Shader(DeviceAPI::OpenGL),
|
||||
p_shaderIndex {0}
|
||||
{}
|
||||
|
||||
Shader::~Shader() = default;
|
||||
|
||||
//
|
||||
// Created by L-Nafaryus on 10/3/2022.
|
||||
//
|
||||
|
||||
#include "shader.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
Shader::Shader() :
|
||||
gpu::Shader(DeviceAPI::OpenGL),
|
||||
p_shaderIndex {0}
|
||||
{}
|
||||
|
||||
Shader::~Shader() = default;
|
||||
|
||||
}
|
@ -1,26 +1,26 @@
|
||||
|
||||
#include "../shader.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
class Shader : public gpu::Shader
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int p_shaderIndex;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Shader();
|
||||
|
||||
~Shader() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include "../shader.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
class Shader : public gpu::Shader
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int p_shaderIndex;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Shader();
|
||||
|
||||
~Shader() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -1,22 +1,22 @@
|
||||
|
||||
#include "shader_program.hpp"
|
||||
#include "shader.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
ShaderProgram::ShaderProgram() :
|
||||
gpu::ShaderProgram {DeviceAPI::OpenGL},
|
||||
p_shaderProgramIndex {0}
|
||||
{}
|
||||
|
||||
ShaderProgram::~ShaderProgram()
|
||||
{}
|
||||
|
||||
Shader* ShaderProgram::shader(gpu::Shader::ShaderType type)
|
||||
{
|
||||
return static_cast<opengl::Shader*>(p_slots[(size_t)type]);
|
||||
}
|
||||
|
||||
|
||||
#include "shader_program.hpp"
|
||||
#include "shader.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
ShaderProgram::ShaderProgram() :
|
||||
gpu::ShaderProgram {DeviceAPI::OpenGL},
|
||||
p_shaderProgramIndex {0}
|
||||
{}
|
||||
|
||||
ShaderProgram::~ShaderProgram()
|
||||
{}
|
||||
|
||||
Shader* ShaderProgram::shader(gpu::Shader::ShaderType type)
|
||||
{
|
||||
return static_cast<opengl::Shader*>(p_slots[(size_t)type]);
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "../shader_program.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
|
||||
class Shader;
|
||||
|
||||
//
|
||||
|
||||
class ShaderProgram : public gpu::ShaderProgram
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int p_shaderProgramIndex;
|
||||
|
||||
public:
|
||||
|
||||
ShaderProgram();
|
||||
|
||||
~ShaderProgram();
|
||||
|
||||
protected:
|
||||
|
||||
Shader* shader(gpu::Shader::ShaderType type);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include "../shader_program.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
|
||||
class Shader;
|
||||
|
||||
//
|
||||
|
||||
class ShaderProgram : public gpu::ShaderProgram
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int p_shaderProgramIndex;
|
||||
|
||||
public:
|
||||
|
||||
ShaderProgram();
|
||||
|
||||
~ShaderProgram();
|
||||
|
||||
protected:
|
||||
|
||||
Shader* shader(gpu::Shader::ShaderType type);
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
|
||||
#include "texture.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
Texture::Texture() :
|
||||
gpu::Texture {DeviceAPI::OpenGL},
|
||||
p_textureIndex {0}
|
||||
{}
|
||||
|
||||
Texture::~Texture() = default;
|
||||
|
||||
|
||||
#include "texture.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
Texture::Texture() :
|
||||
gpu::Texture {DeviceAPI::OpenGL},
|
||||
p_textureIndex {0}
|
||||
{}
|
||||
|
||||
Texture::~Texture() = default;
|
||||
|
||||
}
|
@ -1,25 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "../texture.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
class Texture : public gpu::Texture
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int p_textureIndex;
|
||||
|
||||
public:
|
||||
|
||||
Texture();
|
||||
|
||||
~Texture() override;
|
||||
|
||||
};
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../texture.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu::opengl
|
||||
{
|
||||
|
||||
class Texture : public gpu::Texture
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int p_textureIndex;
|
||||
|
||||
public:
|
||||
|
||||
Texture();
|
||||
|
||||
~Texture() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
#include "context.hpp"
|
||||
#include "shader.hpp"
|
||||
|
||||
#include "../hyplib/array/array.hpp"
|
||||
#include "../containers/array.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
@ -1,40 +1,40 @@
|
||||
|
||||
#include "texture.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
Texture::Texture() :
|
||||
Context {DeviceAPI::Unknown},
|
||||
p_filename {},
|
||||
p_width {0},
|
||||
p_height {0}
|
||||
{}
|
||||
|
||||
|
||||
Texture::Texture(DeviceAPI api) :
|
||||
Context {api},
|
||||
p_filename {},
|
||||
p_width {0},
|
||||
p_height {0}
|
||||
{}
|
||||
|
||||
Texture::~Texture() = default;
|
||||
|
||||
std::string Texture::filename() const
|
||||
{
|
||||
return p_filename;
|
||||
}
|
||||
|
||||
int Texture::width() const
|
||||
{
|
||||
return p_width;
|
||||
}
|
||||
|
||||
int Texture::height() const
|
||||
{
|
||||
return p_height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "texture.hpp"
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
Texture::Texture() :
|
||||
Context {DeviceAPI::Unknown},
|
||||
p_filename {},
|
||||
p_width {0},
|
||||
p_height {0}
|
||||
{}
|
||||
|
||||
|
||||
Texture::Texture(DeviceAPI api) :
|
||||
Context {api},
|
||||
p_filename {},
|
||||
p_width {0},
|
||||
p_height {0}
|
||||
{}
|
||||
|
||||
Texture::~Texture() = default;
|
||||
|
||||
std::string Texture::filename() const
|
||||
{
|
||||
return p_filename;
|
||||
}
|
||||
|
||||
int Texture::width() const
|
||||
{
|
||||
return p_width;
|
||||
}
|
||||
|
||||
int Texture::height() const
|
||||
{
|
||||
return p_height;
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
class Texture : public Context
|
||||
{
|
||||
protected:
|
||||
|
||||
std::string p_filename;
|
||||
int p_width;
|
||||
int p_height;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Texture();
|
||||
|
||||
explicit
|
||||
Texture(DeviceAPI api);
|
||||
|
||||
~Texture() override;
|
||||
|
||||
// Member functions
|
||||
|
||||
[[nodiscard]]
|
||||
std::string filename() const;
|
||||
|
||||
[[nodiscard]]
|
||||
int width() const;
|
||||
|
||||
[[nodiscard]]
|
||||
int height() const;
|
||||
};
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace hpr::gpu
|
||||
{
|
||||
|
||||
class Texture : public Context
|
||||
{
|
||||
protected:
|
||||
|
||||
std::string p_filename;
|
||||
int p_width;
|
||||
int p_height;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
Texture();
|
||||
|
||||
explicit
|
||||
Texture(DeviceAPI api);
|
||||
|
||||
~Texture() override;
|
||||
|
||||
// Member functions
|
||||
|
||||
[[nodiscard]]
|
||||
std::string filename() const;
|
||||
|
||||
[[nodiscard]]
|
||||
int width() const;
|
||||
|
||||
[[nodiscard]]
|
||||
int height() const;
|
||||
};
|
||||
|
||||
} // end namespace hpr::gpu
|
1
source/hpr/hpr.cpp
Normal file
1
source/hpr/hpr.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "hpr.hpp"
|
49
source/hpr/hpr.hpp
Normal file
49
source/hpr/hpr.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace hpr
|
||||
{
|
||||
/* Core */
|
||||
// containers
|
||||
// math
|
||||
// io
|
||||
|
||||
/* Graphics */
|
||||
namespace gpu
|
||||
{
|
||||
// gpu
|
||||
// window_system
|
||||
}
|
||||
|
||||
/* Mesh */
|
||||
namespace mesh
|
||||
{
|
||||
// mesh
|
||||
}
|
||||
|
||||
/* CSG */
|
||||
namespace csg
|
||||
{
|
||||
// csg
|
||||
}
|
||||
}
|
||||
|
||||
#include "containers.hpp"
|
||||
#include "math.hpp"
|
||||
#include "io.hpp"
|
||||
|
||||
#if WITH_GPU
|
||||
#include "gpu.hpp"
|
||||
#endif
|
||||
|
||||
#if WITH_WS
|
||||
#include "window_system.hpp"
|
||||
#endif
|
||||
|
||||
#if WITH_MESH
|
||||
#include "mesh.hpp"
|
||||
#endif
|
||||
|
||||
#if WITH_CSG
|
||||
#include "csg.hpp"
|
||||
#endif
|
3
source/hpr/io.hpp
Normal file
3
source/hpr/io.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "io/file.hpp"
|
27
source/hpr/io/CMakeLists.txt
Normal file
27
source/hpr/io/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
set(COMPONENT_NAME io)
|
||||
|
||||
add_component_library(${COMPONENT_NAME} STATIC
|
||||
file.cpp
|
||||
)
|
||||
|
||||
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||
# file.hpp
|
||||
# logger.hpp
|
||||
#)
|
||||
|
||||
install_component_headers(${COMPONENT_NAME})
|
||||
install_component_source(${COMPONENT_NAME})
|
||||
|
||||
if(0)
|
||||
add_executable(${COMPONENT_NAME}-test
|
||||
tests/${COMPONENT_NAME}-test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}-test
|
||||
${CMAKE_PROJECT_NAME}::${COMPONENT_NAME}
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||
endif()
|
5
source/hpr/math.hpp
Normal file
5
source/hpr/math.hpp
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "math/scalar.hpp"
|
||||
#include "math/vector.hpp"
|
||||
#include "math/matrix.hpp"
|
34
source/hpr/math/CMakeLists.txt
Normal file
34
source/hpr/math/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
set(COMPONENT_NAME math)
|
||||
|
||||
add_component_library(${COMPONENT_NAME} STATIC
|
||||
vector/vector_space.cpp
|
||||
matrix/matrix_space.cpp
|
||||
)
|
||||
|
||||
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||
# matrix/clip_space.hpp
|
||||
# matrix.hpp
|
||||
# matrix/matrix_space.hpp
|
||||
# matrix/transform.hpp
|
||||
# scalar.hpp
|
||||
# scalar/scalar.hpp
|
||||
# vector.hpp
|
||||
# vector/vector_space.hpp
|
||||
#)
|
||||
|
||||
install_component_headers(${COMPONENT_NAME})
|
||||
install_component_source(${COMPONENT_NAME})
|
||||
|
||||
if(WITH_GTESTS)
|
||||
add_executable(${COMPONENT_NAME}-test
|
||||
tests/${COMPONENT_NAME}-test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}-test
|
||||
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||
endif()
|
5
source/hpr/math/matrix.hpp
Normal file
5
source/hpr/math/matrix.hpp
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "matrix/matrix_space.hpp"
|
||||
#include "matrix/transform.hpp"
|
||||
#include "matrix/clip_space.hpp"
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "matrix.hpp"
|
||||
#include "../matrix.hpp"
|
||||
|
||||
|
||||
namespace hpr
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../vector/vector.hpp"
|
||||
#include "../vector.hpp"
|
||||
|
||||
|
||||
namespace hpr
|
||||
{
|
||||
@ -20,6 +21,7 @@ public:
|
||||
using pointer = Type*;
|
||||
using reference = Type&;
|
||||
using iterator = Iterator<Type>;
|
||||
using const_reference = Type const&;
|
||||
using const_iterator = Iterator<const Type>;
|
||||
|
||||
protected:
|
||||
@ -47,7 +49,7 @@ public:
|
||||
p_cols {Cols}
|
||||
{}
|
||||
|
||||
inline
|
||||
inline explicit
|
||||
MatrixSpace(const base& ms) :
|
||||
base {ms},
|
||||
p_rows {Rows},
|
||||
@ -61,6 +63,13 @@ public:
|
||||
p_cols {Cols}
|
||||
{}
|
||||
|
||||
inline
|
||||
MatrixSpace& operator=(const MatrixSpace& ms)
|
||||
{
|
||||
base::operator=(ms);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
MatrixSpace(typename base::iterator start, typename base::iterator end) :
|
||||
base {start, end},
|
||||
@ -104,6 +113,16 @@ public:
|
||||
return (*this)[col + p_rows * row];
|
||||
}
|
||||
|
||||
inline
|
||||
const_reference operator()(size_type row, size_type col) const
|
||||
{
|
||||
if (row >= p_rows || std::numeric_limits<size_type>::max() - p_rows < row)
|
||||
throw std::out_of_range("Row index is out of range");
|
||||
if (col >= p_cols || std::numeric_limits<size_type>::max() - p_cols < col)
|
||||
throw std::out_of_range("Column index is out of range");
|
||||
return (*this)[col + p_rows * row];
|
||||
}
|
||||
|
||||
VectorSpace<value_type, Cols> row(size_type row)
|
||||
{
|
||||
VectorSpace<value_type, Cols> vs;
|
||||
@ -112,6 +131,14 @@ public:
|
||||
return vs;
|
||||
}
|
||||
|
||||
VectorSpace<value_type, Cols> row(size_type row) const
|
||||
{
|
||||
VectorSpace<value_type, Cols> vs;
|
||||
for (auto n = 0; n < Cols; ++n)
|
||||
vs[n] = (*this)(row, n);
|
||||
return vs;
|
||||
}
|
||||
|
||||
void row(size_type row, const VectorSpace<value_type, Cols>& vs)
|
||||
{
|
||||
for (auto n = 0; n < Cols; ++n)
|
||||
@ -198,7 +225,7 @@ public:
|
||||
inline
|
||||
MatrixSpace inv()
|
||||
{
|
||||
return adj() / det();
|
||||
return MatrixSpace(adj() / det());
|
||||
}
|
||||
|
||||
// Friend functions
|
||||
@ -225,6 +252,12 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
friend inline
|
||||
VectorSpace<Type, Rows> operator*(const VectorSpace<Type, Rows>& vs, const MatrixSpace& ms)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MatrixSpace& fill(value_type value)
|
||||
{
|
||||
for (auto n = 0; n < this->size(); ++n)
|
||||
@ -245,5 +278,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// Aliases
|
||||
|
||||
template <typename Type, size_t Row, size_t Col>
|
||||
using mat = MatrixSpace<Type, Row, Col>;
|
||||
|
||||
using mat2 = MatrixSpace<scalar, 2, 2>;
|
||||
using mat3 = MatrixSpace<scalar, 3, 3>;
|
||||
using mat4 = MatrixSpace<scalar, 4, 4>;
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "matrix.hpp"
|
||||
#include "../matrix.hpp"
|
||||
|
||||
|
||||
namespace hpr
|
||||
@ -11,40 +11,62 @@ inline
|
||||
mat<Type, 4, 4> translate(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs)
|
||||
{
|
||||
mat<Type, 4, 4> res {ms};
|
||||
res.row(3, ms.row(0) * vs[0] + ms.row(1) * vs[1] + ms.row(2) * vs[2] + ms.row(3));
|
||||
res.col(3, ms.row(0) * vs[0] + ms.row(1) * vs[1] + ms.row(2) * vs[2] + ms.row(3));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline
|
||||
vec<Type, 3> translate(const vec<Type, 3>& vs1, const vec<Type, 3>& vs2)
|
||||
{
|
||||
mat<Type, 4, 4> res = mat<Type, 4, 4>::identity();
|
||||
res.row(3, vec<Type, 4>(vs1, 0.));
|
||||
res = translate(res, vs2);
|
||||
|
||||
return vec<Type, 3>(res.row(3));
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline
|
||||
mat<Type, 4, 4> rotate(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs, Type angle)
|
||||
{
|
||||
const Type cos {cos(angle)};
|
||||
const Type sin {sin(angle)};
|
||||
const Type cosv = cos(angle);
|
||||
const Type sinv = sin(angle);
|
||||
vec<Type, 3> axis {normalize(vs)};
|
||||
vec<Type, 3> temp {(1. - cos) * axis};
|
||||
vec<Type, 3> temp {(1. - cosv) * axis};
|
||||
|
||||
mat<Type, 4, 4> rot;
|
||||
rot(0, 0) = cos + temp[0] * axis[0];
|
||||
rot(0, 1) = temp[0] * axis[1] + sin * axis[2];
|
||||
rot(0, 2) = temp[0] * axis[2] - sin * axis[1];
|
||||
rot(1, 0) = temp[1] * axis[0] - sin * axis[2];
|
||||
rot(1, 1) = cos + temp[1] * axis[1];
|
||||
rot(1, 2) = temp[1] * axis[2] + sin * axis[0];
|
||||
rot(2, 0) = temp[2] * axis[0] + sin * axis[1];
|
||||
rot(2, 1) = temp[2] * axis[1] - sin * axis[0];
|
||||
rot(2, 2) = cos + temp[2] * axis[2];
|
||||
rot(0, 0) = cosv + temp[0] * axis[0];
|
||||
rot(0, 1) = temp[0] * axis[1] + sinv * axis[2];
|
||||
rot(0, 2) = temp[0] * axis[2] - sinv * axis[1];
|
||||
rot(1, 0) = temp[1] * axis[0] - sinv * axis[2];
|
||||
rot(1, 1) = cosv + temp[1] * axis[1];
|
||||
rot(1, 2) = temp[1] * axis[2] + sinv * axis[0];
|
||||
rot(2, 0) = temp[2] * axis[0] + sinv * axis[1];
|
||||
rot(2, 1) = temp[2] * axis[1] - sinv * axis[0];
|
||||
rot(2, 2) = cosv + temp[2] * axis[2];
|
||||
|
||||
mat<Type, 4, 4> res {ms};
|
||||
res.row(0, ms.row(0) * rot(0, 0) + ms.row(1) * rot(0, 1) + ms.row(2) * rot(0, 2));
|
||||
res.row(0, ms.row(0) * rot(1, 0) + ms.row(1) * rot(1, 1) + ms.row(2) * rot(1, 2));
|
||||
res.row(0, ms.row(0) * rot(2, 0) + ms.row(1) * rot(2, 1) + ms.row(2) * rot(2, 2));
|
||||
res.row(1, ms.row(0) * rot(1, 0) + ms.row(1) * rot(1, 1) + ms.row(2) * rot(1, 2));
|
||||
res.row(2, ms.row(0) * rot(2, 0) + ms.row(1) * rot(2, 1) + ms.row(2) * rot(2, 2));
|
||||
res.row(3, ms.row(3));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline
|
||||
vec<Type, 3> rotate(const vec<Type, 3>& vs1, const vec<Type, 3>& vs2, Type angle)
|
||||
{
|
||||
mat<Type, 4, 4> res = mat<Type, 4, 4>::identity();
|
||||
res.row(3, vec<Type, 4>(vs1, 0.));
|
||||
res = rotate(res, vs2, angle);
|
||||
|
||||
return vec<Type, 3>(res.row(3));
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline
|
||||
mat<Type, 4, 4> scale(const mat<Type, 4, 4>& ms, const vec<Type, 3>& vs)
|
3
source/hpr/math/scalar.hpp
Normal file
3
source/hpr/math/scalar.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "scalar/scalar.hpp"
|
47
source/hpr/math/tests/math-test.cpp
Normal file
47
source/hpr/math/tests/math-test.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../vector.hpp"
|
||||
#include "../matrix.hpp"
|
||||
|
||||
|
||||
TEST(math, Vector)
|
||||
{
|
||||
hpr::vec3 v1 {1, 3, 2};
|
||||
hpr::vec3 v2 {5, 7, -1};
|
||||
hpr::vec2 v31 {13, -2};
|
||||
hpr::vec3 v32 {v31, 9};
|
||||
EXPECT_EQ((hpr::vec3(v2.begin(), v2.end())), v2);
|
||||
EXPECT_EQ(v32, hpr::vec3(13, -2, 9));
|
||||
EXPECT_EQ(-v1, hpr::vec3(-1, -3, -2));
|
||||
EXPECT_EQ(v1 + v2, hpr::vec3(6, 10, 1));
|
||||
EXPECT_EQ(v1 - v2, hpr::vec3(-4, -4, 3));
|
||||
EXPECT_EQ((hpr::dot(v1, v2) ), 24);
|
||||
EXPECT_EQ((hpr::cross(hpr::vec3(1, 0, 0), hpr::vec3(0, 1, 0))), hpr::vec3(0, 0, 1));
|
||||
EXPECT_EQ((hpr::angle(hpr::vec3(1, 0, 0), hpr::vec3(0, 0, 1))), hpr::PI * 0.5);
|
||||
EXPECT_EQ((hpr::normalize(hpr::vec3(1, 1, 1))), hpr::vec3(0.5773502691896258, 0.5773502691896258, 0.5773502691896258));
|
||||
}
|
||||
|
||||
TEST(math, Matrix)
|
||||
{
|
||||
hpr::mat2 m1;
|
||||
hpr::vec4 v1;
|
||||
EXPECT_FALSE(v1 == m1);
|
||||
hpr::mat2 m2 {3, 2, 7, 4};
|
||||
hpr::vec2 v2 {2, 4};
|
||||
EXPECT_EQ(m2.col(1), v2);
|
||||
hpr::vec2 v3 {13, 51};
|
||||
m2.col(1, v3);
|
||||
EXPECT_EQ(m2.col(1), v3);
|
||||
hpr::mat3 m4 {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
hpr::mat2 m41 {5, 6, 8, 9};
|
||||
EXPECT_EQ(m41.minor(0, 0), 9);
|
||||
hpr::mat2 m5 {1, 2, 3, 4};
|
||||
|
||||
EXPECT_EQ((m4.det()), 0);
|
||||
EXPECT_EQ(hpr::mat3(-9, 23, 3, 5, 5, 6, 7, -3, 9).det(), -786);
|
||||
|
||||
hpr::mat2 m6 {2, 1, 7, 4};
|
||||
EXPECT_EQ(m6.inv(), hpr::mat2(4, -1, -7, 2));
|
||||
EXPECT_EQ(hpr::mat3(1, 0, 0, 0, 1, 0, 0, 0, 1).det(), 1.);
|
||||
//EXPECT_EQ(m4.det(), 0);
|
||||
}
|
4
source/hpr/math/vector.hpp
Normal file
4
source/hpr/math/vector.hpp
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include "vector/vector_space.hpp"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../scalar/scalar.hpp"
|
||||
#include "../array/array.hpp"
|
||||
#include "../scalar.hpp"
|
||||
#include "../../containers/array/static_array.hpp"
|
||||
|
||||
|
||||
namespace hpr
|
||||
@ -106,6 +106,14 @@ public:
|
||||
(*this)[subvs.size()] = v;
|
||||
}
|
||||
|
||||
template <size_type BiggerSize>
|
||||
inline
|
||||
VectorSpace(const VectorSpace<Type, BiggerSize>& vs) :
|
||||
base {vs.begin(), vs.begin() + Size}
|
||||
{
|
||||
static_assert(BiggerSize > Size, "Size should be bigger");
|
||||
}
|
||||
|
||||
// Member functions
|
||||
|
||||
// vector versus scalar (per element operations)
|
||||
@ -390,4 +398,13 @@ bool all(const VectorSpace<bool, Size>& vs)
|
||||
return res;
|
||||
}
|
||||
|
||||
// Aliases
|
||||
|
||||
template <typename Type, size_t Size>
|
||||
using vec = VectorSpace<Type, Size>;
|
||||
|
||||
using vec2 = VectorSpace<scalar, 2>;
|
||||
using vec3 = VectorSpace<scalar, 3>;
|
||||
using vec4 = VectorSpace<scalar, 4>;
|
||||
|
||||
}
|
3
source/hpr/mesh.hpp
Normal file
3
source/hpr/mesh.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "mesh/mesh.hpp"
|
26
source/hpr/mesh/CMakeLists.txt
Normal file
26
source/hpr/mesh/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
set(COMPONENT_NAME mesh)
|
||||
|
||||
add_component_library(${COMPONENT_NAME} STATIC
|
||||
mesh.cpp
|
||||
)
|
||||
|
||||
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||
|
||||
#)
|
||||
|
||||
install_component_headers(${COMPONENT_NAME})
|
||||
install_component_source(${COMPONENT_NAME})
|
||||
|
||||
if (0)
|
||||
add_executable(${COMPONENT_NAME}-test
|
||||
tests/${COMPONENT_NAME}-test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}-test
|
||||
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||
endif()
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../hyplib/scalar/scalar.hpp"
|
||||
#include "../hyplib/array/array.hpp"
|
||||
#include "../hyplib/vector/vector.hpp"
|
||||
#include "../containers/array.hpp"
|
||||
#include "../math/scalar/scalar.hpp"
|
||||
#include "../math/vector.hpp"
|
||||
|
||||
|
||||
namespace hpr::mesh
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../hyplib/scalar/scalar.hpp"
|
||||
#include "../hyplib/array/array.hpp"
|
||||
#include "../hyplib/vector/vector.hpp"
|
||||
#include "../containers/array.hpp"
|
||||
#include "../math/scalar/scalar.hpp"
|
||||
#include "../math/vector.hpp"
|
||||
|
||||
|
||||
|
||||
namespace hpr::mesh
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../hyplib/scalar/scalar.hpp"
|
||||
#include "../hyplib/array/array.hpp"
|
||||
#include "../hyplib/vector/vector.hpp"
|
||||
#include "../containers/array.hpp"
|
||||
#include "../math/scalar/scalar.hpp"
|
||||
#include "../math/vector.hpp"
|
||||
|
||||
|
||||
|
||||
namespace hpr::mesh
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../hyplib/scalar/scalar.hpp"
|
||||
#include "../hyplib/array/array.hpp"
|
||||
#include "../hyplib/vector/vector.hpp"
|
||||
#include "../containers/array.hpp"
|
||||
#include "../math/scalar/scalar.hpp"
|
||||
#include "../math/vector.hpp"
|
||||
|
||||
#include "vertex.hpp"
|
||||
#include "edge.hpp"
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../hyplib/scalar/scalar.hpp"
|
||||
#include "../hyplib/array/array.hpp"
|
||||
#include "../hyplib/vector/vector.hpp"
|
||||
#include "../containers/array.hpp"
|
||||
#include "../math/scalar/scalar.hpp"
|
||||
#include "../math/vector.hpp"
|
||||
|
||||
|
||||
|
||||
namespace hpr::mesh
|
11
source/hpr/window_system.hpp
Normal file
11
source/hpr/window_system.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "window_system/monitor.hpp"
|
||||
#include "window_system/window_context.hpp"
|
||||
#include "window_system/window.hpp"
|
||||
#include "window_system/window_system.hpp"
|
||||
|
||||
#include "window_system/glfw/monitor.hpp"
|
||||
#include "window_system/glfw/window.hpp"
|
||||
#include "window_system/glfw/window_system.hpp"
|
35
source/hpr/window_system/CMakeLists.txt
Normal file
35
source/hpr/window_system/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
set(COMPONENT_NAME window_system)
|
||||
|
||||
add_component_library(${COMPONENT_NAME} OBJECT
|
||||
window_system.cpp
|
||||
monitor.cpp
|
||||
window.cpp
|
||||
glfw/window_system.cpp
|
||||
glfw/monitor.cpp
|
||||
glfw/window.cpp
|
||||
)
|
||||
|
||||
#target_sources(${COMPONENT_NAME} PUBLIC
|
||||
|
||||
#)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}
|
||||
glfw
|
||||
)
|
||||
|
||||
install_component_headers(${COMPONENT_NAME})
|
||||
install_component_source(${COMPONENT_NAME})
|
||||
|
||||
if (0)
|
||||
add_executable(${COMPONENT_NAME}-test
|
||||
tests/${COMPONENT_NAME}-test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${COMPONENT_NAME}-test
|
||||
${PROJECT_NAME}::${COMPONENT_NAME}
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
gtest_add_tests(TARGET ${COMPONENT_NAME}-test)
|
||||
endif()
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "../monitor.hpp"
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
namespace hpr::gpu::glfw
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user