diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 69a3d4c05..1fe5aa0db 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 69a3d4c05eb6bb1efe7fd926fc99f2982e22a59a +Subproject commit 1fe5aa0db6277b852e60d3b622886550d901eab8 diff --git a/lib/libimhex/include/hex/helpers/opengl.hpp b/lib/libimhex/include/hex/helpers/opengl.hpp index b214ddf3c..6a7a80eaf 100644 --- a/lib/libimhex/include/hex/helpers/opengl.hpp +++ b/lib/libimhex/include/hex/helpers/opengl.hpp @@ -154,6 +154,7 @@ namespace hex::gl { glEnableVertexAttribArray(index); buffer.bind(); glVertexAttribPointer(index, 3, getType(), GL_FALSE, 3 * sizeof(T), nullptr); + buffer.unbind(); } void bind() const; diff --git a/lib/libimhex/source/helpers/opengl.cpp b/lib/libimhex/source/helpers/opengl.cpp index 5546f0389..d10c37cef 100644 --- a/lib/libimhex/source/helpers/opengl.cpp +++ b/lib/libimhex/source/helpers/opengl.cpp @@ -98,6 +98,7 @@ namespace hex::gl { glGenBuffers(1, &this->m_buffer); glBindBuffer(this->m_type, this->m_buffer); glBufferData(this->m_type, data.size_bytes(), data.data(), GL_STATIC_DRAW); + glBindBuffer(this->m_type, 0); } template @@ -110,7 +111,7 @@ namespace hex::gl { this->m_buffer = other.m_buffer; this->m_size = other.m_size; this->m_type = other.m_type; - other.m_buffer = 0; + other.m_buffer = -1; } template @@ -118,7 +119,7 @@ namespace hex::gl { this->m_buffer = other.m_buffer; this->m_size = other.m_size; this->m_type = other.m_type; - other.m_buffer = 0; + other.m_buffer = -1; return *this; } @@ -163,12 +164,12 @@ namespace hex::gl { VertexArray::VertexArray(VertexArray &&other) noexcept { this->m_array = other.m_array; - other.m_array = 0; + other.m_array = -1; } VertexArray& VertexArray::operator=(VertexArray &&other) noexcept { this->m_array = other.m_array; - other.m_array = 0; + other.m_array = -1; return *this; } @@ -200,12 +201,12 @@ namespace hex::gl { Texture::Texture(Texture &&other) noexcept { this->m_texture = other.m_texture; - other.m_texture = 0; + other.m_texture = -1; } Texture& Texture::operator=(Texture &&other) noexcept { this->m_texture = other.m_texture; - other.m_texture = 0; + other.m_texture = -1; return *this; } @@ -231,7 +232,7 @@ namespace hex::gl { GLuint Texture::release() { auto copy = this->m_texture; - this->m_texture = 0; + this->m_texture = -1; return copy; } @@ -257,16 +258,16 @@ namespace hex::gl { FrameBuffer::FrameBuffer(FrameBuffer &&other) noexcept { this->m_frameBuffer = other.m_frameBuffer; - other.m_frameBuffer = 0; + other.m_frameBuffer = -1; this->m_renderBuffer = other.m_renderBuffer; - other.m_renderBuffer = 0; + other.m_renderBuffer = -1; } FrameBuffer& FrameBuffer::operator=(FrameBuffer &&other) noexcept { this->m_frameBuffer = other.m_frameBuffer; - other.m_frameBuffer = 0; + other.m_frameBuffer = -1; this->m_renderBuffer = other.m_renderBuffer; - other.m_renderBuffer = 0; + other.m_renderBuffer = -1; return *this; } diff --git a/plugins/builtin/romfs/shaders/default/vertex.glsl b/plugins/builtin/romfs/shaders/default/vertex.glsl index 38185f0cb..37776b04f 100644 --- a/plugins/builtin/romfs/shaders/default/vertex.glsl +++ b/plugins/builtin/romfs/shaders/default/vertex.glsl @@ -5,7 +5,7 @@ layout (location = 1) in vec3 in_Normal; /*uniform float time;*/ uniform float scale; uniform vec3 rotation; - +uniform vec3 translation; out vec3 normal; @@ -32,5 +32,5 @@ mat4 viewMatrix(vec3 rotation) { void main() { mat4 view = viewMatrix(rotation); normal = (vec4(in_Normal, 1.0) * view).xyz; - gl_Position = vec4(in_Position * scale, 1.0) * view; + gl_Position = vec4((in_Position + translation) * scale, 1.0) * view; } \ No newline at end of file diff --git a/plugins/builtin/source/content/pl_visualizers.cpp b/plugins/builtin/source/content/pl_visualizers.cpp index 5a0917e67..09dea4412 100644 --- a/plugins/builtin/source/content/pl_visualizers.cpp +++ b/plugins/builtin/source/content/pl_visualizers.cpp @@ -9,8 +9,10 @@ #include #include #include +#include #include +#include #include @@ -125,14 +127,17 @@ namespace hex::plugin::builtin { static auto readValues(pl::ptrn::Pattern *pattern){ std::vector result; - if (pattern->getSize() == 0) + if (dynamic_cast(pattern) && pattern->getSize() == 0) return result; if (auto iteratable = dynamic_cast(pattern); iteratable != nullptr) { result.reserve(iteratable->getEntryCount()); iteratable->forEachEntry(0, iteratable->getEntryCount(), [&](u64, pl::ptrn::Pattern *entry) { for (auto [offset, child] : entry->getChildren()) { + auto startOffset = child->getOffset(); + child->setOffset(offset); + ON_SCOPE_EXIT { child->setOffset(startOffset); }; T value; if (std::floating_point) @@ -144,7 +149,7 @@ namespace hex::plugin::builtin { } }); } else { - result.reserve(pattern->getSize() / sizeof(float)); + result.resize(pattern->getSize() / sizeof(float)); pattern->getEvaluator()->readData(pattern->getOffset(), result.data(), result.size() * sizeof(float), pattern->getSection()); } @@ -158,6 +163,7 @@ namespace hex::plugin::builtin { static ImGui::Texture texture; static float scaling = 0.5F; static gl::Vector rotation = { { 1.0F, -1.0F, 0.0F } }; + static gl::Vector translation; static std::vector vertices, normals; static std::vector indices; static gl::Shader shader; @@ -171,6 +177,11 @@ namespace hex::plugin::builtin { rotation[1] += -dragDelta.x * 0.0075F; ImGui::ResetMouseDragDelta(ImGuiMouseButton_Middle); + dragDelta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right); + translation[0] += -dragDelta.x * 0.1F; + translation[1] += -dragDelta.y * 0.1F; + ImGui::ResetMouseDragDelta(ImGuiMouseButton_Right); + auto scrollDelta = ImGui::GetIO().MouseWheel; scaling += scrollDelta * 0.01F; @@ -184,31 +195,36 @@ namespace hex::plugin::builtin { normals.clear(); normals.resize(vertices.size()); - for (u32 i = 0; i < normals.size() && normals.size() >= 9; i += 9) { - auto v1 = gl::Vector({ vertices[i + 0], vertices[i + 1], vertices[i + 2] }); - auto v2 = gl::Vector({ vertices[i + 3], vertices[i + 4], vertices[i + 5] }); - auto v3 = gl::Vector({ vertices[i + 6], vertices[i + 7], vertices[i + 8] }); + for (u32 i = 9; i < normals.size(); i += 9) { + auto v1 = gl::Vector({ vertices[i - 9], vertices[i - 8], vertices[i - 7] }); + auto v2 = gl::Vector({ vertices[i - 6], vertices[i - 5], vertices[i - 4] }); + auto v3 = gl::Vector({ vertices[i - 3], vertices[i - 2], vertices[i - 1] }); auto normal = ((v2 - v1).cross(v3 - v1)).normalize(); - normals[i + 0] = normal[0]; - normals[i + 1] = normal[1]; - normals[i + 2] = normal[2]; - normals[i + 3] = normal[0]; - normals[i + 4] = normal[1]; - normals[i + 5] = normal[2]; - normals[i + 6] = normal[0]; - normals[i + 7] = normal[1]; - normals[i + 8] = normal[2]; + normals[i - 9] = normal[0]; + normals[i - 8] = normal[1]; + normals[i - 7] = normal[2]; + normals[i - 6] = normal[0]; + normals[i - 5] = normal[1]; + normals[i - 4] = normal[2]; + normals[i - 3] = normal[0]; + normals[i - 2] = normal[1]; + normals[i - 1] = normal[2]; } shader = gl::Shader(romfs::get("shaders/default/vertex.glsl").string(), romfs::get("shaders/default/fragment.glsl").string()); vertexArray = gl::VertexArray(); + + vertexBuffer = {}; + normalBuffer = {}; + indexBuffer = {}; + vertexArray.bind(); - vertexBuffer = gl::Buffer (gl::BufferType::Vertex, vertices); + vertexBuffer = gl::Buffer(gl::BufferType::Vertex, vertices); normalBuffer = gl::Buffer(gl::BufferType::Vertex, normals); - indexBuffer = gl::Buffer(gl::BufferType::Index, indices); + indexBuffer = gl::Buffer(gl::BufferType::Index, indices); vertexArray.addBuffer(0, vertexBuffer); vertexArray.addBuffer(1, normalBuffer); @@ -217,6 +233,8 @@ namespace hex::plugin::builtin { vertexArray.addBuffer(2, indexBuffer); vertexBuffer.unbind(); + normalBuffer.unbind(); + indexBuffer.unbind(); vertexArray.unbind(); } @@ -229,16 +247,21 @@ namespace hex::plugin::builtin { frameBuffer.bind(); glEnable(GL_DEPTH_TEST); + glEnable(GL_DEPTH_CLAMP); shader.bind(); shader.setUniform("scale", scaling); shader.setUniform("rotation", rotation); + shader.setUniform("translation", translation); vertexArray.bind(); glViewport(0, 0, renderTexture.getWidth(), renderTexture.getHeight()); glClearColor(0.00F, 0.00F, 0.00F, 0.00f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0F, 1.0F, -1.0F, 1.0F, 0.0000001F, 10000000.0F); if (indices.empty()) vertexBuffer.draw();