fixing windows dll issues

This commit is contained in:
2023-12-08 23:33:26 +01:00
parent 038a6db77f
commit 555af79e9e
43 changed files with 121 additions and 110 deletions

6
.gitignore vendored
View File

@@ -5,10 +5,16 @@
*.so
*.out
*.dll
*.lib
*.exp
*.json
*.tmp
*.ilk
*.pdb
.vs/
.xmake/
.cache/
objs/
build/
test/.gdb_history
test/Test

View File

@@ -13,6 +13,7 @@
NAME = libmlx.so
SRCS = $(wildcard $(addsuffix /*.cpp, ./src/core))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/core/**))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/platform))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer/**))

View File

@@ -15,13 +15,9 @@
#ifndef __MACRO_LIB_X_H__
#define __MACRO_LIB_X_H__
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_WIN32) || defined(_WIN64)
#define MLX_EXPORT __declspec(dllexport)
#define MLX_IMPORT __declspec(dllexport)
#define MLX_IMPORT __declspec(dllimport)
#else
#define MLX_EXPORT
#define MLX_IMPORT
@@ -33,6 +29,10 @@ extern "C" {
#define MLX_API MLX_IMPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
MLX_KEYDOWN = 0,

View File

@@ -28,7 +28,7 @@
namespace mlx::core
{
class MLX_API Application
class Application
{
public:
Application();

View File

@@ -15,6 +15,7 @@
#include "application.h"
#include <renderer/core/render_core.h>
#include <filesystem>
#include <mlx.h>
extern "C"
{
@@ -31,29 +32,29 @@ extern "C"
if(app == nullptr)
mlx::core::error::report(e_kind::fatal_error, "Tout a pété");
init = true;
return app;
return static_cast<void*>(app);
}
void* mlx_new_window(mlx::core::Application* mlx, int w, int h, const char* title)
void* mlx_new_window(void* mlx, int w, int h, const char* title)
{
return mlx->newGraphicsSuport(w, h, title);
return static_cast<mlx::core::Application*>(mlx)->newGraphicsSuport(w, h, title);
}
int mlx_loop_hook(mlx::core::Application* mlx, int (*f)(void*), void* param)
int mlx_loop_hook(void* mlx, int (*f)(void*), void* param)
{
mlx->loopHook(f, param);
static_cast<mlx::core::Application*>(mlx)->loopHook(f, param);
return 0;
}
int mlx_loop(mlx::core::Application* mlx)
int mlx_loop(void* mlx)
{
mlx->run();
static_cast<mlx::core::Application*>(mlx)->run();
return 0;
}
int mlx_loop_end(mlx::core::Application* mlx)
int mlx_loop_end(void* mlx)
{
mlx->loopEnd();
static_cast<mlx::core::Application*>(mlx)->loopEnd();
return 0;
}
@@ -67,57 +68,57 @@ extern "C"
return SDL_ShowCursor(SDL_DISABLE);
}
int mlx_mouse_move(mlx::core::Application* mlx, void* win, int x, int y)
int mlx_mouse_move(void* mlx, void* win, int x, int y)
{
mlx->mouseMove(win, x, y);
static_cast<mlx::core::Application*>(mlx)->mouseMove(win, x, y);
return 0;
}
int mlx_mouse_get_pos(mlx::core::Application* mlx, int* x, int* y)
int mlx_mouse_get_pos(void* mlx, int* x, int* y)
{
mlx->getMousePos(x, y);
static_cast<mlx::core::Application*>(mlx)->getMousePos(x, y);
return 0;
}
int mlx_on_event(mlx::core::Application* mlx, void* win, int event, int (*funct_ptr)(int, void*), void* param)
int mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*funct_ptr)(int, void*), void* param)
{
mlx->onEvent(win, event, funct_ptr, param);
static_cast<mlx::core::Application*>(mlx)->onEvent(win, static_cast<int>(event), funct_ptr, param);
return 0;
}
void* mlx_new_image(mlx::core::Application* mlx, int width, int height)
void* mlx_new_image(void* mlx, int width, int height)
{
return mlx->newTexture(width, height);
return static_cast<mlx::core::Application*>(mlx)->newTexture(width, height);
}
int mlx_get_image_pixel(mlx::core::Application* mlx, void* img, int x, int y)
int mlx_get_image_pixel(void* mlx, void* img, int x, int y)
{
return mlx->getTexturePixel(img, x, y);
return static_cast<mlx::core::Application*>(mlx)->getTexturePixel(img, x, y);
}
void mlx_set_image_pixel(mlx::core::Application* mlx, void* img, int x, int y, int color)
void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color)
{
unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = (color & 0x000000FF);
color_bits[3] = (color & 0xFF000000) >> 24;
mlx->setTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
static_cast<mlx::core::Application*>(mlx)->setTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
}
int mlx_put_image_to_window(mlx::core::Application* mlx, void* win, void* img, int x, int y)
int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y)
{
mlx->texturePut(win, img, x, y);
static_cast<mlx::core::Application*>(mlx)->texturePut(win, img, x, y);
return 0;
}
int mlx_destroy_image(mlx::core::Application* mlx, void* img)
int mlx_destroy_image(void* mlx, void* img)
{
mlx->destroyTexture(img);
static_cast<mlx::core::Application*>(mlx)->destroyTexture(img);
return 0;
}
void* mlx_png_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".png")
@@ -125,10 +126,10 @@ extern "C"
mlx::core::error::report(e_kind::error, "PNG loader : not a png file '%s'", filename);
return nullptr;
}
return mlx->newStbTexture(filename, width, height);
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
}
void* mlx_jpg_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".jpg" && file.extension() != ".jpeg")
@@ -136,10 +137,10 @@ extern "C"
mlx::core::error::report(e_kind::error, "JPG loader : not a jpg file '%s'", filename);
return nullptr;
}
return mlx->newStbTexture(filename, width, height);
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
}
void* mlx_bmp_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".bmp" && file.extension() != ".dib")
@@ -147,32 +148,32 @@ extern "C"
mlx::core::error::report(e_kind::error, "BMP loader : not a bmp file '%s'", filename);
return nullptr;
}
return mlx->newStbTexture(filename, width, height);
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
}
int mlx_pixel_put(mlx::core::Application* mlx, void* win, int x, int y, int color)
int mlx_pixel_put(void* mlx, void* win, int x, int y, int color)
{
unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = color & 0x000000FF;
color_bits[3] = 0xFF;
mlx->pixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
static_cast<mlx::core::Application*>(mlx)->pixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
return 0;
}
int mlx_string_put(mlx::core::Application* mlx, void* win, int x, int y, int color, char* str)
int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str)
{
unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = color & 0x000000FF;
color_bits[3] = 0xFF;
mlx->stringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
static_cast<mlx::core::Application*>(mlx)->stringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
return 0;
}
void mlx_set_font(mlx::core::Application* mlx, void* win, char* filepath)
void mlx_set_font(void* mlx, void* win, char* filepath)
{
std::filesystem::path file(filepath);
if(file.extension() != ".ttf" && file.extension() != ".tte")
@@ -180,10 +181,10 @@ extern "C"
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
return;
}
mlx->loadFont(win, file, 16.f);
static_cast<mlx::core::Application*>(mlx)->loadFont(win, file, 16.f);
}
void mlx_set_font_scale(mlx::core::Application* mlx, void* win, char* filepath, float scale)
void mlx_set_font_scale(void* mlx, void* win, char* filepath, float scale)
{
std::filesystem::path file(filepath);
if(file.extension() != ".ttf" && file.extension() != ".tte")
@@ -191,31 +192,31 @@ extern "C"
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
return;
}
mlx->loadFont(win, file, scale);
static_cast<mlx::core::Application*>(mlx)->loadFont(win, file, scale);
}
int mlx_clear_window(mlx::core::Application* mlx, void* win)
int mlx_clear_window(void* mlx, void* win)
{
mlx->clearGraphicsSupport(win);
static_cast<mlx::core::Application*>(mlx)->clearGraphicsSupport(win);
return 0;
}
int mlx_destroy_window(mlx::core::Application* mlx, void* win)
int mlx_destroy_window(void* mlx, void* win)
{
mlx->destroyGraphicsSupport(win);
static_cast<mlx::core::Application*>(mlx)->destroyGraphicsSupport(win);
return 0;
}
int mlx_destroy_display(mlx::core::Application* mlx)
int mlx_destroy_display(void* mlx)
{
delete mlx;
delete static_cast<mlx::core::Application*>(mlx);
mlx::Render_Core::get().destroy();
return 0;
}
int mlx_get_screens_size(mlx::core::Application* mlx, int* w, int* h)
int mlx_get_screens_size(void* mlx, int* w, int* h)
{
mlx->getScreenSize(w, h);
static_cast<mlx::core::Application*>(mlx)->getScreenSize(w, h);
return 0;
}
}

View File

@@ -26,7 +26,7 @@ enum class e_kind
namespace mlx::core::error
{
void MLX_API report(e_kind kind, std::string msg, ...);
void report(e_kind kind, std::string msg, ...);
}
#endif // __MLX_ERRORS__

View File

@@ -30,7 +30,7 @@
namespace mlx
{
class MLX_API GraphicsSupport : public non_copyable
class GraphicsSupport : public non_copyable
{
public:
GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id);

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API MemManager : public Singleton<MemManager>
class MemManager : public Singleton<MemManager>
{
friend class Singleton<MemManager>;

View File

@@ -41,19 +41,18 @@
#warning "This compiler is not fully supported"
#endif
#if defined(_WIN32) || defined(_WIN64)
#define MLX_EXPORT __declspec(dllexport)
#define MLX_IMPORT __declspec(dllexport)
#if defined(_WIN32) || defined(__CYGWIN__)
#define MLX_PLAT_WINDOWS
#elif defined(__linux__)
#define MLX_PLAT_LINUX
#elif defined(__APPLE__) && defined(__MACH__)
#define MLX_PLAT_MACOS
#elif defined(unix) || defined(__unix__) || defined(__unix)
#define MLX_PLAT_UNIX
#else
#define MLX_EXPORT
#define MLX_IMPORT
#error "Unknown environment!"
#endif
#ifdef MLX_BUILD
#define MLX_API MLX_EXPORT
#else
#define MLX_API MLX_IMPORT
#endif
// Checking common assumptions
#include <climits>

View File

@@ -32,7 +32,7 @@ namespace mlx
void* param = nullptr;
};
class MLX_API Input
class Input
{
public:
Input();

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API MLX_Window
class MLX_Window
{
public:
MLX_Window(std::size_t w, std::size_t h, const std::string& title);

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API Buffer
class Buffer
{
public:
enum class kind { dynamic, uniform, constant };

View File

@@ -20,7 +20,7 @@
namespace mlx
{
class MLX_API C_IBO : public Buffer
class C_IBO : public Buffer
{
public:
inline void create(uint32_t size, const uint16_t* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); }

View File

@@ -20,7 +20,7 @@
namespace mlx
{
class MLX_API UBO
class UBO
{
public:
void create(class Renderer* renderer, uint32_t size, const char* name);

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API VBO : public Buffer
class VBO : public Buffer
{
public:
inline void create(uint32_t size, const char* name) { Buffer::create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name); }
@@ -27,7 +27,7 @@ namespace mlx
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
};
class MLX_API C_VBO : public Buffer
class C_VBO : public Buffer
{
public:
inline void create(uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }

View File

@@ -23,7 +23,7 @@
namespace mlx
{
class MLX_API CmdManager
class CmdManager
{
public:
CmdManager() = default;

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API CmdBuffer
class CmdBuffer
{
public:
void init(class CmdManager* manager);

View File

@@ -18,7 +18,7 @@
namespace mlx
{
class MLX_API CmdPool
class CmdPool
{
public:
void init();

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API GPUallocator
class GPUallocator
{
public:
GPUallocator() = default;

View File

@@ -24,7 +24,11 @@
#include <mutex>
#ifdef DEBUG
#ifndef MLX_COMPILER_MSVC
#warning "MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances"
#else
#pragma NOTE("MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances")
#endif
#endif
namespace mlx

View File

@@ -43,7 +43,7 @@ namespace mlx
constexpr const int MAX_FRAMES_IN_FLIGHT = 3;
class MLX_API Render_Core : public Singleton<Render_Core>
class Render_Core : public Singleton<Render_Core>
{
public:
Render_Core() = default;

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API Device
class Device
{
public:
void init();

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API Fence
class Fence
{
public:
Fence() = default;

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API Instance
class Instance
{
public:
void init();

View File

@@ -20,7 +20,7 @@
namespace mlx
{
class MLX_API Queues
class Queues
{
public:
struct QueueFamilyIndices

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API Semaphore
class Semaphore
{
public:
void init();

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API Surface
class Surface
{
public:
void create(class Renderer& renderer);

View File

@@ -18,7 +18,7 @@
namespace mlx
{
class MLX_API ValidationLayers
class ValidationLayers
{
public:
void init();

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API DescriptorPool
class DescriptorPool
{
public:
void init(std::size_t n, VkDescriptorPoolSize* size);

View File

@@ -20,7 +20,7 @@
namespace mlx
{
class MLX_API DescriptorSet
class DescriptorSet
{
public:
void init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);

View File

@@ -21,7 +21,7 @@
namespace mlx
{
class MLX_API DescriptorSetLayout
class DescriptorSetLayout
{
public:
void init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);

View File

@@ -25,7 +25,7 @@
namespace mlx
{
class MLX_API Texture : public Image
class Texture : public Image
{
public:
Texture() = default;
@@ -62,9 +62,9 @@ namespace mlx
bool _has_been_updated = false;
};
MLX_API Texture stbTextureLoad(std::filesystem::path file, int* w, int* h);
Texture stbTextureLoad(std::filesystem::path file, int* w, int* h);
struct MLX_API TextureRenderData
struct TextureRenderData
{
Texture* texture;
std::size_t hash = 0;
@@ -79,7 +79,7 @@ namespace mlx
namespace std
{
template <>
struct MLX_API hash<mlx::TextureRenderData>
struct hash<mlx::TextureRenderData>
{
size_t operator()(const mlx::TextureRenderData& td) const noexcept
{

View File

@@ -20,7 +20,7 @@
namespace mlx
{
class MLX_API TextureAtlas : public Image
class TextureAtlas : public Image
{
public:
TextureAtlas() = default;

View File

@@ -22,9 +22,9 @@
namespace mlx
{
MLX_API uint32_t formatSize(VkFormat format);
uint32_t formatSize(VkFormat format);
class MLX_API Image
class Image
{
friend class SwapChain;

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API GraphicPipeline
class GraphicPipeline
{
public:
void init(class Renderer& renderer);

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API PixelPutPipeline
class PixelPutPipeline
{
public:
PixelPutPipeline() = default;

View File

@@ -37,7 +37,7 @@
namespace mlx
{
struct MLX_API Vertex
struct Vertex
{
glm::vec2 pos;
glm::vec4 color;
@@ -78,7 +78,7 @@ namespace mlx
}
};
class MLX_API Renderer
class Renderer
{
public:
Renderer() = default;

View File

@@ -18,7 +18,7 @@
namespace mlx
{
class MLX_API FrameBuffer
class FrameBuffer
{
public:
void init(class RenderPass& renderpass, class Image& image);

View File

@@ -18,7 +18,7 @@
namespace mlx
{
class MLX_API RenderPass
class RenderPass
{
public:
void init(VkFormat attachement_format);

View File

@@ -20,14 +20,14 @@
namespace mlx
{
class MLX_API SwapChain
class SwapChain
{
friend class GraphicPipeline;
friend class RenderPass;
friend class Renderer;
public:
struct MLX_API SwapChainSupportDetails
struct SwapChainSupportDetails
{
VkSurfaceCapabilitiesKHR capabilities;
std::vector<VkSurfaceFormatKHR> formats;

View File

@@ -27,7 +27,7 @@ namespace mlx
using TextID = uint32_t;
constexpr TextID nulltext = 0;
class MLX_API TextData
class TextData
{
public:
TextData() = default;
@@ -46,7 +46,7 @@ namespace mlx
std::string _text;
};
class MLX_API TextLibrary
class TextLibrary
{
public:
TextLibrary() = default;

View File

@@ -24,7 +24,7 @@
namespace mlx
{
struct MLX_API TextDrawData
struct TextDrawData
{
TextID id;
int x;
@@ -41,7 +41,7 @@ namespace mlx
namespace std
{
template <>
struct MLX_API hash<mlx::TextDrawData>
struct hash<mlx::TextDrawData>
{
std::size_t operator()(const mlx::TextDrawData& d) const noexcept
{
@@ -52,7 +52,7 @@ namespace std
namespace mlx
{
class MLX_API TextPutPipeline
class TextPutPipeline
{
public:
TextPutPipeline() = default;

BIN
test/Test.exe git.filemode.normal_file

Binary file not shown.