#ifndef _GL_H #define _GL_H extern "C" { #include } #include #include #define GLM_ENABLE_EXPERIMENTAL #include #include #include #include using namespace glm; namespace Mauri { enum ObjectType { DEFAULT, DEFAULT_FLIPPED, FULLSCREEN, MODEL, COMBINE }; enum UniformType { TYPE_INVALID, TYPE_UINT, TYPE_FLOAT, TYPE_VEC4, TYPE_VEC3, TYPE_VEC2, TYPE_MAT4, TYPE_MAT3, TYPE_SAMPLER2D }; extern auto uniform_type_to_string(UniformType type) -> std::string; extern auto uniform_type_from_string(const std::string_view &s) -> UniformType; class Object; class Texture; class RenderObject { public: RenderObject(ObjectType type, Object *object = nullptr, Texture *texture = nullptr); ~RenderObject(); auto set_data(f32 *vertices, s32 vertex_count) -> void; auto bind() -> void; auto draw() -> void; private: u32 vao; u32 vbo; u32 vertex_count; }; class RenderShader { public: RenderShader(const std::string &vs_source, const std::string &fs_source); ~RenderShader(); auto compile(u32 shader, const char *source, char *error) -> bool; auto bind() -> void; auto get_uniform_location(const std::string &name) -> s32; auto set_uniform(const std::string &name, UniformType type, void *value) -> void; private: u32 program = 0; std::unordered_map uniform_locations; }; class RenderTexture { public: RenderTexture(bool no_interp, bool clamp, bool filtering, s32 mm_count); ~RenderTexture(); u32 id = 0; s32 width; s32 height; s32 format; std::vector pixels; auto upload(const void *ptr, s32 width, s32 height, s32 level, s32 iformat = GL_UNSIGNED_BYTE) -> void; auto bind(s32 index) -> void; private: auto save_pixels(const void *ptr, s32 width, s32 height, bool dxt) -> void; }; class RenderFramebuffer { public: RenderFramebuffer(s32 width, s32 height, f32 scale); ~RenderFramebuffer(); u32 id = 0; f32 width; f32 height; RenderTexture *texture = nullptr; auto bind() -> void; auto blit(u32 dest, s32 width, s32 height) -> void; auto clear(vec4 color) -> void; }; class Render { public: static auto blend_func(s32 sfactor, s32 dfactor) -> void; static auto color_mask(f32 r, f32 g, f32 b, f32 a) -> void; static auto depth_test(bool enabled) -> void; static auto bind_framebuffer(s32 id) -> void; static auto set_viewport(s32 x, s32 y, s32 width, s32 height) -> void; }; } // namespace Mauri #endif // _GL_H