mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
feat: Added basic 3D visualizer, moved visualizers to separate file
This commit is contained in:
@@ -117,6 +117,8 @@ namespace hex {
|
||||
/* Pattern Language Function Registry. Allows adding of new functions that may be used inside the pattern language */
|
||||
namespace PatternLanguage {
|
||||
|
||||
using VisualizerFunctionCallback = std::function<void(pl::ptrn::Pattern&, pl::ptrn::Iteratable&, bool, const std::vector<pl::core::Token::Literal> &)>;
|
||||
|
||||
namespace impl {
|
||||
|
||||
struct FunctionDefinition {
|
||||
@@ -129,6 +131,13 @@ namespace hex {
|
||||
bool dangerous;
|
||||
};
|
||||
|
||||
struct Visualizer {
|
||||
u32 parameterCount;
|
||||
VisualizerFunctionCallback callback;
|
||||
};
|
||||
|
||||
std::map<std::string, Visualizer> &getVisualizers();
|
||||
|
||||
}
|
||||
|
||||
void configureRuntime(pl::PatternLanguage &runtime, prv::Provider *provider);
|
||||
@@ -138,6 +147,8 @@ namespace hex {
|
||||
void addFunction(const pl::api::Namespace &ns, const std::string &name, pl::api::FunctionParameterCount parameterCount, const pl::api::FunctionCallback &func);
|
||||
void addDangerousFunction(const pl::api::Namespace &ns, const std::string &name, pl::api::FunctionParameterCount parameterCount, const pl::api::FunctionCallback &func);
|
||||
|
||||
void addVisualizer(const std::string &name, const VisualizerFunctionCallback &func, u32 parameterCount);
|
||||
|
||||
std::map<std::string, pl::api::PragmaHandler> &getPragmas();
|
||||
std::vector<impl::FunctionDefinition> &getFunctions();
|
||||
|
||||
|
||||
120
lib/libimhex/include/hex/helpers/opengl.hpp
Normal file
120
lib/libimhex/include/hex/helpers/opengl.hpp
Normal file
@@ -0,0 +1,120 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <hex/helpers/concepts.hpp>
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
#include <imgui_impl_opengl3_loader.h>
|
||||
|
||||
namespace hex::gl {
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
GLuint getType() {
|
||||
if constexpr (std::is_same_v<T, float>)
|
||||
return GL_FLOAT;
|
||||
else if constexpr (std::is_same_v<T, u32>)
|
||||
return GL_UNSIGNED_INT;
|
||||
else
|
||||
static_assert(hex::always_false<T>::value, "Unsupported type");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
Shader(const std::string &vertexSource, const std::string &fragmentSource);
|
||||
~Shader();
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
private:
|
||||
void compile(GLuint shader, const std::string &source);
|
||||
|
||||
private:
|
||||
GLuint m_program;
|
||||
};
|
||||
|
||||
enum class BufferType {
|
||||
Vertex = GL_ARRAY_BUFFER,
|
||||
Index = GL_ELEMENT_ARRAY_BUFFER
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Buffer {
|
||||
public:
|
||||
Buffer(BufferType type, std::span<T> data);
|
||||
~Buffer();
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
void draw() const;
|
||||
|
||||
size_t getSize() const;
|
||||
private:
|
||||
GLuint m_buffer;
|
||||
size_t m_size;
|
||||
GLuint m_type;
|
||||
};
|
||||
|
||||
extern template class Buffer<float>;
|
||||
extern template class Buffer<u32>;
|
||||
|
||||
class VertexArray {
|
||||
public:
|
||||
VertexArray();
|
||||
~VertexArray();
|
||||
|
||||
template<typename T>
|
||||
void addBuffer(const Buffer<T> &buffer) const {
|
||||
glVertexAttribPointer(0, buffer.getSize() / sizeof(T), getType<T>(), GL_FALSE, 3 * sizeof(T), nullptr);
|
||||
glEnableVertexAttribArray(0);
|
||||
}
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
private:
|
||||
GLuint m_array;
|
||||
};
|
||||
|
||||
class Texture {
|
||||
public:
|
||||
Texture(u32 width, u32 height);
|
||||
~Texture();
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
GLuint getTexture() const;
|
||||
u32 getWidth() const;
|
||||
u32 getHeight() const;
|
||||
|
||||
void release();
|
||||
private:
|
||||
GLuint m_texture;
|
||||
u32 m_width, m_height;
|
||||
};
|
||||
|
||||
class FrameBuffer {
|
||||
public:
|
||||
FrameBuffer();
|
||||
~FrameBuffer();
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
void attachTexture(const Texture &texture) const;
|
||||
|
||||
private:
|
||||
GLuint m_frameBuffer, m_renderBuffer;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -36,6 +36,7 @@ namespace ImGui {
|
||||
Texture() = default;
|
||||
Texture(const ImU8 *buffer, int size, int width = 0, int height = 0);
|
||||
explicit Texture(const char *path);
|
||||
Texture(unsigned int texture, int width, int height);
|
||||
Texture(const Texture&) = delete;
|
||||
Texture(Texture&& other) noexcept;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user