From e065dc736bb26c0f3d3d2290ff064af464d6f7ab Mon Sep 17 00:00:00 2001 From: IlyaShurupov Date: Mon, 18 Mar 2024 10:42:01 +0300 Subject: [PATCH] Fix bugs. Sketch3D stable. --- Containers/public/Map.hpp | 2 +- Graphics/CMakeLists.txt | 2 +- Graphics/private/bindings/Window.cpp | 52 ++++++++++----------- Graphics/private/bindings/WindowContext.hpp | 9 ++++ Modules/public/Common.hpp | 2 +- Sketch3D/private/FrameBuffer.cpp | 2 + Sketch3D/private/Sketch3D.cpp | 4 +- Sketch3D/public/Sketch3DWidget.hpp | 2 +- Strings/public/Strings.hpp | 2 + 9 files changed, 45 insertions(+), 32 deletions(-) diff --git a/Containers/public/Map.hpp b/Containers/public/Map.hpp index 405ca9d..a5c3fb7 100644 --- a/Containers/public/Map.hpp +++ b/Containers/public/Map.hpp @@ -348,7 +348,7 @@ namespace tp { [[nodiscard]] Iterator begin() const { return Iterator(this); } - [[nodiscard]] ualni end() const { return mNSlots; } + [[nodiscard]] ualni end() const { return mNSlots - 1; } template void archiveWrite(Archiver& ar) const { diff --git a/Graphics/CMakeLists.txt b/Graphics/CMakeLists.txt index 823f6cd..47a1788 100644 --- a/Graphics/CMakeLists.txt +++ b/Graphics/CMakeLists.txt @@ -1,7 +1,7 @@ project(Graphics) ### ---------------------- Externals --------------------- ### -set(BINDINGS_INCLUDE ../Externals/glfw/include ${GLEW_INCLUDE_DIR} ../Externals/easytab) +set(BINDINGS_INCLUDE ../Externals/glfw/include ${GLEW_INCLUDE_DIR}) set(BINDINGS_LIBS glfw Imgui Nanovg ${GLEW_LIB}) ### ---------------------- Static Library --------------------- ### diff --git a/Graphics/private/bindings/Window.cpp b/Graphics/private/bindings/Window.cpp index 583e19e..516066d 100644 --- a/Graphics/private/bindings/Window.cpp +++ b/Graphics/private/bindings/Window.cpp @@ -7,8 +7,8 @@ #include -#define EASYTAB_IMPLEMENTATION -#include "easytab.h" +// #define EASYTAB_IMPLEMENTATION +// #include "easytab.h" namespace tp { class Graphics::GL::Context { @@ -83,7 +83,7 @@ void Graphics::draw() { mGui.draw(); } -Window::Window(int width, int height, const char* title) { +tp::Window::Window(int width, int height, const char* title) { mContext = new Context(); glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1); @@ -110,13 +110,13 @@ Window::Window(int width, int height, const char* title) { mEvents.mContext = mContext; #ifdef ENV_OS_WINDOWS - EasyTab_Load(glfwGetWin32Window(mContext->window)); + // EasyTab_Load(glfwGetWin32Window(mContext->window)); #endif } -Window::~Window() { +tp::Window::~Window() { #ifdef ENV_OS_WINDOWS - EasyTab_Unload(); + // EasyTab_Unload(); #endif mGraphics.deinit(); @@ -124,7 +124,7 @@ Window::~Window() { delete mContext; } -Window* Window::createWindow(int width, int height, const char* title) { +tp::Window* tp::Window::createWindow(int width, int height, const char* title) { tp::HeapAllocGlobal::startIgnore(); static int count = 1; @@ -149,23 +149,23 @@ Window* Window::createWindow(int width, int height, const char* title) { return out; } -void Window::destroyWindow(Window* window) { +void tp::Window::destroyWindow(Window* window) { delete window; glfwTerminate(); } -bool Window::shouldClose() const { return glfwWindowShouldClose(mContext->window); } +bool tp::Window::shouldClose() const { return glfwWindowShouldClose(mContext->window); } -void Window::processEvents() { +void tp::Window::processEvents() { mContext->inputManager.isEvent = false; #ifdef ENV_OS_WINDOWS - HWND w32window = glfwGetWin32Window(mContext->window); - MSG msg; - if (PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE)) { - if (EasyTab_HandleEvent(msg.hwnd, msg.message, msg.lParam, msg.wParam) == EASYTAB_OK) - mEvents.pressure = EasyTab->Pressure; - } + // HWND w32window = glfwGetWin32Window(mContext->window); + // MSG msg; + // if (PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE)) { + // if (EasyTab_HandleEvent(msg.hwnd, msg.message, msg.lParam, msg.wParam) == EASYTAB_OK) + // mEvents.pressure = EasyTab->Pressure; + // } #endif glfwPollEvents(); @@ -192,24 +192,24 @@ void Window::processEvents() { get_time(); } -void Window::draw() { +void tp::Window::draw() { mGraphics.draw(); glfwSwapBuffers(mContext->window); mContext->inputManager.resetScroll(); } -auto Window::getContext() -> Context* { return mContext; } -Graphics::Canvas& Window::getCanvas() { return mGraphics.mCanvas; } -const Window::Events& Window::getEvents() { return mEvents; } +auto tp::Window::getContext() -> Context* { return mContext; } +Graphics::Canvas& tp::Window::getCanvas() { return mGraphics.mCanvas; } +const tp::Window::Events& tp::Window::getEvents() { return mEvents; } -const Vec2F& Window::Events::getPos() const { return mContext->inputManager.getPos(); } +const Vec2F& tp::Window::Events::getPos() const { return mContext->inputManager.getPos(); } -bool Window::Events::isPressed() const { return mContext->inputManager.isPressed(); } +bool tp::Window::Events::isPressed() const { return mContext->inputManager.isPressed(); } -bool Window::Events::isReleased() const { return mContext->inputManager.isReleased(); } +bool tp::Window::Events::isReleased() const { return mContext->inputManager.isReleased(); } -bool Window::Events::isDown() const { return mContext->inputManager.isDown(); } +bool tp::Window::Events::isDown() const { return mContext->inputManager.isDown(); } -halnf Window::Events::getScrollY() const { return mContext->inputManager.getScrollY(); } +halnf tp::Window::Events::getScrollY() const { return mContext->inputManager.getScrollY(); } -bool Window::Events::isEvent() const { return mContext->inputManager.isEvents(); } +bool tp::Window::Events::isEvent() const { return mContext->inputManager.isEvents(); } diff --git a/Graphics/private/bindings/WindowContext.hpp b/Graphics/private/bindings/WindowContext.hpp index 0f4e591..fd35566 100644 --- a/Graphics/private/bindings/WindowContext.hpp +++ b/Graphics/private/bindings/WindowContext.hpp @@ -1,9 +1,18 @@ #pragma once +#include "Environment.hpp" + // -------- Window Context -------- // #include +#ifdef ENV_OS_WINDOWS #define GLFW_EXPOSE_NATIVE_WIN32 +#endif + +#ifdef ENV_OS_LINUX +#define GLFW_EXPOSE_NATIVE_WAYLAND +#endif + #include #include diff --git a/Modules/public/Common.hpp b/Modules/public/Common.hpp index 6697780..d98b82e 100644 --- a/Modules/public/Common.hpp +++ b/Modules/public/Common.hpp @@ -51,7 +51,7 @@ namespace tp { ualni hash(alnf bytes); template - [[nodiscard]] T clamp(T v, T l, T u) { + T clamp(T v, T l, T u) { if (v < l) { v = l; } else if (v > u) { diff --git a/Sketch3D/private/FrameBuffer.cpp b/Sketch3D/private/FrameBuffer.cpp index 1f3a23b..0804fae 100644 --- a/Sketch3D/private/FrameBuffer.cpp +++ b/Sketch3D/private/FrameBuffer.cpp @@ -2,6 +2,8 @@ #include "FrameBuffer.hpp" #include "GraphicsApi.hpp" +#include + void glerr(GLenum type) { printf("GL ERROR\n"); } #define AssertGL(x) { x; GLenum __gle = glGetError(); if (__gle != GL_NO_ERROR) glerr(__gle); } diff --git a/Sketch3D/private/Sketch3D.cpp b/Sketch3D/private/Sketch3D.cpp index 16f75e1..060829a 100644 --- a/Sketch3D/private/Sketch3D.cpp +++ b/Sketch3D/private/Sketch3D.cpp @@ -14,7 +14,7 @@ void StrokeGPUHandles::sendDataToGPU(Buffer* mPoints) { glBindVertexArray(VertexArrayID); vbo_len = mPoints->size(); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); - glBufferData(GL_ARRAY_BUFFER, sizeof(mPoints[0]) * vbo_len, mPoints->getBuff(), GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(StrokePoint) * vbo_len, mPoints->getBuff(), GL_STATIC_COPY); } StrokeGPUHandles::~StrokeGPUHandles() { @@ -340,7 +340,7 @@ Project::~Project() { Renderer::Renderer(Vec2F size) : mBuffer(size, 4), mBufferDowncast(size), - mShader(".\\rsc\\shaders\\stroke.vert", ".\\rsc\\shaders\\stroke.geom", ".\\rsc\\shaders\\stroke.frag") + mShader("rsc/shaders/stroke.vert", "rsc/shaders/stroke.geom", "rsc/shaders/stroke.frag") { mMaxSize = size; diff --git a/Sketch3D/public/Sketch3DWidget.hpp b/Sketch3D/public/Sketch3DWidget.hpp index 1cf5e3c..36e1054 100644 --- a/Sketch3D/public/Sketch3DWidget.hpp +++ b/Sketch3D/public/Sketch3DWidget.hpp @@ -45,8 +45,8 @@ namespace tp { } private: - Project mProject; Renderer mRenderer; + Project mProject; Canvas::ImageHandle mImage; Canvas* mCanvas = nullptr; }; diff --git a/Strings/public/Strings.hpp b/Strings/public/Strings.hpp index 3675d92..c731ae1 100644 --- a/Strings/public/Strings.hpp +++ b/Strings/public/Strings.hpp @@ -62,6 +62,8 @@ namespace tp { DEBUG_ASSERT(mReferenceCount == 1 && !mIsConst) delete[] mBuff; mBuff = new tChar[size + 1]; + // set non-zero value so that size() function wont return size that may be less that actual + memSetVal(mBuff, size, 1); mBuff[size] = Logic::getEndChar(); } };