diff --git a/CMakeLists.txt b/CMakeLists.txt index 64ac120..d607656 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(Myosotis VERSION 0.1) set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) set( CMAKE_VERBOSE_MAKEFILE OFF ) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) +set( CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE ) configure_file( ${PROJECT_SOURCE_DIR}/config/version.h.in diff --git a/extern/miniply/miniply.cpp b/extern/miniply/miniply.cpp index 04a2dfe..0a4630a 100644 --- a/extern/miniply/miniply.cpp +++ b/extern/miniply/miniply.cpp @@ -558,7 +558,7 @@ namespace miniply { uint32_t propIdx = listPropIdx + 1 + i; PLYProperty& itemProp = properties[propIdx]; - snprintf(nameBuf, sizeof(nameBuf), "%s_%u", oldListProp.name.c_str(), i); + snprintf(nameBuf, nameBufSize, "%s_%u", oldListProp.name.c_str(), i); itemProp.name = nameBuf; itemProp.type = oldListProp.type; itemProp.countType = PLYPropertyType::None; diff --git a/include/hash_table.h b/include/hash_table.h index ea60533..5e668f7 100644 --- a/include/hash_table.h +++ b/include/hash_table.h @@ -69,13 +69,6 @@ static inline size_t hash_lookup(K *keys, size_t buckets, H hasher, K key) return 0; } -static size_t hashtable_buckets(size_t n) -{ - size_t ret = 1; - while (ret < n) ret *= 2; - return ret; -} - template HashTable::HashTable(size_t expected_keys, H hasher) { diff --git a/include/myosotis.h b/include/myosotis.h index aad6f2c..3fbdcc1 100644 --- a/include/myosotis.h +++ b/include/myosotis.h @@ -11,7 +11,7 @@ struct MyosotisCfg bool smooth_shading = true; bool vsync = true; float camera_fov = 45.0f; - ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + ImVec4 clear_color = ImVec4(0.25f, 0.22f, 0.15f, 1.00f); }; struct Myosotis { @@ -30,17 +30,3 @@ struct Myosotis { }; -static void -resize_window_callback(GLFWwindow* window, int width, int height); - -static void -mouse_button_callback(GLFWwindow* window, int button, int action, int mods); - -static void -cursor_position_callback(GLFWwindow* window, double xpos, double ypos); - -static void -scroll_callback(GLFWwindow* window, double xoffset, double yoffset); - -static void -key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); diff --git a/include/ndc.h b/include/ndc.h index ddde4cf..f8519a3 100644 --- a/include/ndc.h +++ b/include/ndc.h @@ -53,7 +53,7 @@ constexpr bool reversed_y = NDC_REVERSED_Y ? true : false; constexpr bool reversed_z = NDC_REVERSED_Z ? true : false; constexpr bool z_zero_one = NDC_Z_ZERO_ONE ? true : false; -constexpr Vec3 nwd_to_ndc(float x, float y, float depth) +inline Vec3 nwd_to_ndc(float x, float y, float depth) { Vec3 ndc {0, 0, 0}; diff --git a/include/quat.h b/include/quat.h index c45b56e..f041931 100644 --- a/include/quat.h +++ b/include/quat.h @@ -21,7 +21,6 @@ struct alignas(4 * sizeof(T)) TQuat { /* Constructors */ TQuat() = default; - constexpr TQuat(const TQuat& q); constexpr TQuat(T x, T y, T z, T w); constexpr TQuat(TVec3 xyz, T w); @@ -71,9 +70,6 @@ TQuat slerp(TQuat& q0, TQuatq1, T t); /* Methods implementation */ -template -inline constexpr TQuat::TQuat(const TQuat& q): xyz{q.xyz}, w{q.w} {} - template inline constexpr TQuat::TQuat(T x, T y, T z, T w): x{x}, y{y}, z{z}, w{w} {} @@ -157,11 +153,14 @@ inline T norm(const TQuat& a) template TQuat pow(TQuat& q, T t) { - double omega = acos((double)q.w); - T w = cos(t * omega); - T mult = sin(omega) ? sin(t * omega) / sin(omega) : t; - - return {mult * q.xyz, w}; + T qw = q.w < -1 ? -1 : q.w > 1 ? 1 : q.w; + T omega = acos(qw); + T cto = cos(t * omega); + T sto = sin(t * omega); + T so = sin(omega); + T mult = (so != 0) ? sto / so : t; + + return {mult * q.xyz, cto}; } template diff --git a/include/vec2.h b/include/vec2.h index 18910db..0262502 100644 --- a/include/vec2.h +++ b/include/vec2.h @@ -12,9 +12,8 @@ struct TVec2 { /* Constructors */ constexpr TVec2() = default; - constexpr TVec2(const TVec2& a); constexpr TVec2(T x, T y); - explicit TVec2(const T* t); + explicit TVec2(const T* t); /* Index Accessor */ T& operator[] (int n); @@ -66,9 +65,6 @@ TVec2 normalized(const TVec2& a); /* Functions implementations */ -template -inline constexpr TVec2::TVec2(const TVec2& a): x{a.x}, y{a.y} {} - template inline constexpr TVec2::TVec2(T x, T y): x{x}, y{y} {} diff --git a/include/vec3.h b/include/vec3.h index b6e9d9d..0dcc93a 100644 --- a/include/vec3.h +++ b/include/vec3.h @@ -13,7 +13,6 @@ struct TVec3 { /* Constructors */ constexpr TVec3() = default; - constexpr TVec3(const TVec3& a); constexpr TVec3(T x, T y, T z); explicit TVec3(const T* t); @@ -68,9 +67,6 @@ TVec3 normalized(const TVec3& a); /* Functions implementations */ -template -inline constexpr TVec3::TVec3(const TVec3& a): x{a.x}, y{a.y}, z{a.z} {} - template inline constexpr TVec3::TVec3(T x, T y, T z): x{x}, y{y}, z{z} {} diff --git a/include/vec4.h b/include/vec4.h index d02ea40..05323a6 100644 --- a/include/vec4.h +++ b/include/vec4.h @@ -21,7 +21,6 @@ struct alignas(4 * sizeof(T)) TVec4 { /* Constructors */ constexpr TVec4() = default; - constexpr TVec4(const TVec4& a); constexpr TVec4(T x, T y, T z, T w); constexpr TVec4(const TVec3& xyz, T w); explicit TVec4(const T* t); @@ -73,10 +72,6 @@ const TVec4 TVec4::Zero {0, 0, 0}; /* Functions implementations */ -template -inline constexpr TVec4::TVec4(const TVec4& a): - x{a.x}, y{a.y}, z{a.z}, w{a.w} {} - template inline constexpr TVec4::TVec4(T x, T y, T z, T w): x{x}, y{y}, z{z}, w{w} {} diff --git a/make.sh b/make.sh index 9f722bf..87c3b85 100755 --- a/make.sh +++ b/make.sh @@ -1,11 +1,11 @@ echo "Building DEBUG version." echo "-----------------------" -make --no-print-directory -C build/debug +make --no-print-directory -C build/debug -j 4 echo echo "Building RELEASE version." echo "-----------------------" -make --no-print-directory -C build/release +make --no-print-directory -C build/release -j 4 mkdir -p bin echo diff --git a/shaders/default.frag b/shaders/default.frag index 480cc2b..5a0d46f 100644 --- a/shaders/default.frag +++ b/shaders/default.frag @@ -12,12 +12,12 @@ layout (location = 3) uniform bool smooth_shading; layout (location = 0) out vec4 color; #define AMBIENT_COLOR vec3(1.f, 0.8f, 1.f) -#define Ka 0.2f -#define DIFFUSE_COLOR vec3(1.f, 1.f, 1.f) -#define Kd 0.6f -#define SPECULAR_COLOR vec3(.8f, .8f, 1.f) +#define Ka 0.1f +#define DIFFUSE_COLOR vec3(.88f, .75f, 0.43f) +#define Kd .7f +#define SPECULAR_COLOR vec3(1.f, 1.f, 1.f) #define Ks 0.2f -#define shininess 80 +#define shininess 8 void main() { @@ -49,10 +49,10 @@ void main() { //vec3 R = 2.f * dot(N, L) * N - L; vec3 R = reflect(-L, N); float ca = max(dot(R, V), 0.f); - Is = pow(ca, shininess); + Is = pow(ca, shininess) * shininess / 4; } vec3 full = Ka * AMBIENT_COLOR; - full += Kd * Id * DIFFUSE_COLOR; - full += Ks * Is * SPECULAR_COLOR; + full += Kd * Id * DIFFUSE_COLOR; + full += Ks * Is * SPECULAR_COLOR; color = vec4(full, 1.0f); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 78693cf..2e373c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ add_executable(main ../extern/imgui/imgui_impl_opengl3.cpp ) -target_compile_features(main PUBLIC cxx_std_20) +target_compile_features(main PRIVATE cxx_std_17) +target_compile_options(main PRIVATE -Wall -Wextra) target_link_libraries(main OpenGL glfw ${CMAKE_DL_LIBS}) diff --git a/src/chrono.cpp b/src/chrono.cpp index 1b60a3c..5b2e175 100644 --- a/src/chrono.cpp +++ b/src/chrono.cpp @@ -15,8 +15,6 @@ void timer_stop(const char *str = "") gettimeofday(&tv1, NULL); unsigned int mus = 1000000 * (tv1.tv_sec - tv0.tv_sec); mus += (tv1.tv_usec - tv0.tv_usec); - int s = mus >= 1000000; - int ms = mus >= 1000; printf("Timer %s: ", str); if (mus >= 1000000) { diff --git a/src/main.cpp b/src/main.cpp index c075246..5701208 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,7 +91,6 @@ int main(int argc, char **argv) { timer_start(); int level = atoi(argv[2]); - Vec3 extent = bbox.max - bbox.min; float cube_size = model_size; Grid grid = {bbox.min, cube_size / (1 << level)}; MeshData data2; @@ -105,7 +104,7 @@ int main(int argc, char **argv) /* Main window and context */ Myosotis app; - if (!app.init(200, 100)) + if (!app.init(1920, 1080)) { return (EXIT_FAILURE); } @@ -121,8 +120,8 @@ int main(int argc, char **argv) GLuint idx, pos, nml, tex, vao; glEnable(GL_DEBUG_OUTPUT); - glDisable(GL_CULL_FACE); - //glEnable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); + glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glEnable(GL_BLEND); diff --git a/src/mesh_io.cpp b/src/mesh_io.cpp index 4857e03..ea72870 100644 --- a/src/mesh_io.cpp +++ b/src/mesh_io.cpp @@ -67,7 +67,8 @@ int obj_to_mesh(const fastObjMesh& obj, MeshData& data, Mesh& mesh) data.reserve_indices(index_count); - bool has_normals, has_uv; + bool has_normals = false; + bool has_uv = false; for (size_t i = 0; i < obj_vertex_count; ++i) { has_normals |= (obj.indices[i].n != 0); diff --git a/src/myosotis.cpp b/src/myosotis.cpp index 6dad340..ebf3b3f 100644 --- a/src/myosotis.cpp +++ b/src/myosotis.cpp @@ -12,12 +12,30 @@ #include "myosotis.h" #include "viewer.h" +static void +resize_window_callback(GLFWwindow* window, int width, int height); + +static void +mouse_button_callback(GLFWwindow* window, int button, int action, int mods); + +static void +cursor_position_callback(GLFWwindow* window, double xpos, double ypos); + +static void +scroll_callback(GLFWwindow* window, double xoffset, double yoffset); + +static void +key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); static void GL_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* user_param) { + (void) source; + (void) length; + (void) user_param; + (void) id; if (type == GL_DEBUG_TYPE_ERROR) { printf("GL CALLBACK: %s type = 0x%x, severity = 0x%x,\ @@ -45,8 +63,10 @@ bool Myosotis::init(int width, int height) glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); - window = glfwCreateWindow(mode->width, mode->height, "Myosotis", - glfwGetPrimaryMonitor(), NULL); + //window = glfwCreateWindow(mode->width, mode->height, "Myosotis", + //glfwGetPrimaryMonitor(), NULL); + window = glfwCreateWindow(width, height, "Myosotis", NULL, NULL); + if (!window) { return (false); @@ -190,6 +210,8 @@ scroll_callback(GLFWwindow* window, double xoffset, double yoffset) static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { + (void) scancode; + (void) mods; Myosotis* app = (Myosotis*)glfwGetWindowUserPointer(window); if (app->io->WantCaptureKeyboard) diff --git a/src/viewer.cpp b/src/viewer.cpp index 99c370c..208091d 100644 --- a/src/viewer.cpp +++ b/src/viewer.cpp @@ -123,7 +123,7 @@ void Viewer3D::mouse_move(float px, float py) void Viewer3D::mouse_scroll(float xoffset, float yoffset) { - + (void)xoffset; Vec3 old_pos = camera.get_position(); Vec3 new_pos = target + exp(-ZOOM_SENSITIVITY * yoffset) * (old_pos - target); camera.set_position(new_pos); @@ -131,4 +131,6 @@ void Viewer3D::mouse_scroll(float xoffset, float yoffset) void Viewer3D::key_pressed(int key, int action) { + (void)key; + (void)action; }