macrolibx update to 1.2.1
This commit is contained in:
42
MacroLibX/.github/workflows/linux_clang.yml
vendored
Normal file
42
MacroLibX/.github/workflows/linux_clang.yml
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
name: Linux (clang)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
arch: [x86_64]
|
||||
mode: [release]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- name: Get current date as package key
|
||||
id: cache_key
|
||||
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install mesa-common-dev clang libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev
|
||||
|
||||
# Build the lib
|
||||
- name: Build MacroLibX
|
||||
run: make -j
|
||||
|
||||
# Build the test
|
||||
- name: Build Test
|
||||
run: cd test && clang main.c ../libmlx.so -lSDL2
|
43
MacroLibX/.github/workflows/linux_gcc.yml
vendored
Normal file
43
MacroLibX/.github/workflows/linux_gcc.yml
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
name: Linux (gcc)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
arch: [x86_64]
|
||||
mode: [release]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- name: Get current date as package key
|
||||
id: cache_key
|
||||
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install mesa-common-dev libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev
|
||||
|
||||
# Build the lib
|
||||
- name: Build MacroLibX
|
||||
run: make TOOLCHAIN=gcc -j
|
||||
|
||||
# Build the test
|
||||
- name: Build Test
|
||||
run: cd test && gcc main.c ../libmlx.so -lSDL2
|
||||
|
49
MacroLibX/.github/workflows/macos_x86.yml
vendored
Normal file
49
MacroLibX/.github/workflows/macos_x86.yml
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
name: macOS
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [macOS-latest]
|
||||
arch: [x86_64]
|
||||
mode: [release]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- name: Get current date as package key
|
||||
id: cache_key
|
||||
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Install system dependencies
|
||||
- name: Install Vulkan SDK
|
||||
uses: humbletim/install-vulkan-sdk@v1.1.1
|
||||
with:
|
||||
version: 1.3.204.1
|
||||
cache: true
|
||||
|
||||
- name: Install Dependancies
|
||||
run: |
|
||||
brew install SDL2
|
||||
|
||||
# Build the lib
|
||||
- name: Build MacroLibX
|
||||
run: make -j
|
||||
|
||||
# Build the test
|
||||
- name: Build Test
|
||||
run: cd test && clang main.c ../libmlx.so -lSDL2
|
||||
|
75
MacroLibX/.github/workflows/windows.yml
vendored
Normal file
75
MacroLibX/.github/workflows/windows.yml
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
name: Windows (xmake)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest]
|
||||
arch: [x64]
|
||||
mode: [release]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- name: Get current date as package key
|
||||
id: cache_key
|
||||
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Install system dependencies
|
||||
- name: Install Vulkan SDK
|
||||
uses: humbletim/install-vulkan-sdk@v1.1.1
|
||||
with:
|
||||
version: 1.3.204.1
|
||||
cache: true
|
||||
|
||||
# Force xmake to a specific folder (for cache)
|
||||
- name: Set xmake env
|
||||
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV
|
||||
|
||||
# Install xmake
|
||||
- name: Setup xmake
|
||||
uses: xmake-io/github-action-setup-xmake@v1
|
||||
with:
|
||||
xmake-version: branch@master
|
||||
actions-cache-folder: .xmake-cache-W${{ steps.cache_key.outputs.key }}
|
||||
|
||||
# Update xmake repository (in order to have the file that will be cached)
|
||||
- name: Update xmake repository
|
||||
run: xmake repo --update
|
||||
|
||||
# Fetch xmake dephash
|
||||
- name: Retrieve dependencies hash
|
||||
id: dep_hash
|
||||
run: echo "hash=$(xmake l utils.ci.packageskey)" >> $GITHUB_OUTPUT
|
||||
|
||||
# Cache xmake dependencies
|
||||
- name: Retrieve cached xmake dependencies
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
|
||||
key: Windows-${{ matrix.arch }}-${{ matrix.mode }}-${{ steps.dep_hash.outputs.hash }}-W${{ steps.cache_key.outputs.key }}
|
||||
|
||||
# Setup compilation mode and install project dependencies
|
||||
- name: Configure xmake and install dependencies
|
||||
run: xmake config --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --yes
|
||||
|
||||
# Build the mlx
|
||||
- name: Build MacroLibX
|
||||
run: xmake --yes
|
||||
|
||||
# Build the test
|
||||
- name: Build Test
|
||||
run: xmake build --yes Test
|
21
MacroLibX/.gitignore
vendored
Normal file
21
MacroLibX/.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
*.swp
|
||||
*.swx
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
*.out
|
||||
*.dll
|
||||
*.lib
|
||||
*.exp
|
||||
*.json
|
||||
*.tmp
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.exe
|
||||
.vs/
|
||||
.xmake/
|
||||
.cache/
|
||||
objs/
|
||||
build/
|
||||
test/.gdb_history
|
||||
test/Test
|
@ -1,17 +0,0 @@
|
||||
# How to contribute to the MacroLibX
|
||||
|
||||
For any questions, suggestions or help [contact me](mailto:contact@kbz8.me)
|
||||
|
||||
## **Found a bug?**
|
||||
|
||||
* Avoid opening any new issues without having checked if your problem has already been reported. If there are no currently open issues that fit your problem's description, feel free to [add it](https://github.com/seekrs/MacroLibX/issues/new).
|
||||
|
||||
* When writing an issue make sure to include a clear title and description as well as having filled out all the necessary information: System info, OS, OS-Version, ...
|
||||
|
||||
* If possible add pictures of the issue.
|
||||
|
||||
## Contributing
|
||||
|
||||
Before thinking of adding a contribution, think. Is it necessary? Will this actually be a useful/required feature? Is your implementation good?
|
||||
Provide clear and documented explanation as to what was changed.
|
||||
|
@ -1,5 +1,5 @@
|
||||
MIT License
|
||||
Copyright (c) 2022-2024 kbz_8
|
||||
Copyright (c) 2022-2023 kbz_8
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -6,13 +6,14 @@
|
||||
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
|
||||
# Updated: 2023/12/31 01:09:30 by maldavid ### ########.fr #
|
||||
# Updated: 2023/12/07 15:25:52 by kbz_8 ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
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/**))
|
||||
@ -31,22 +32,17 @@ MODE = "release"
|
||||
|
||||
CXX = clang++
|
||||
|
||||
CXXFLAGS = -std=c++17 -O3 -fPIC -Wall -Wextra -Werror -DSDL_MAIN_HANDLED
|
||||
ifeq ($(TOOLCHAIN), gcc)
|
||||
CXX = g++
|
||||
endif
|
||||
|
||||
CXXFLAGS = -std=c++17 -O3 -fPIC
|
||||
INCLUDES = -I./includes -I./src -I./third_party
|
||||
|
||||
LDLIBS =
|
||||
|
||||
ifeq ($(TOOLCHAIN), gcc)
|
||||
CXX = g++
|
||||
CXXFLAGS += -Wno-error=cpp
|
||||
else
|
||||
CXXFLAGS += -Wno-error=#warning
|
||||
endif
|
||||
|
||||
ifeq ($(OS), Darwin)
|
||||
LDLIBS += -L /opt/homebrew/lib -lSDL2
|
||||
CXXFLAGS += -I /opt/homebrew/include
|
||||
NAME = libmlx.dylib
|
||||
LDLIBS += -lSDL2
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG), true)
|
||||
|
@ -1,38 +1,18 @@
|
||||
<div align="center">
|
||||
<img src="./res/logo.png" alt="drawing" width="200"/>
|
||||
<div align="center">
|
||||
<a href="https://github.com/seekrs/MacroLibX/actions/workflows/linux_clang.yml"><img src="https://github.com/seekrs/MacroLibX/actions/workflows/linux_clang.yml/badge.svg"></a>
|
||||
<a href="https://github.com/seekrs/MacroLibX/actions/workflows/linux_gcc.yml"><img src="https://github.com/seekrs/MacroLibX/actions/workflows/linux_gcc.yml/badge.svg"></a>
|
||||
<a href="https://github.com/seekrs/MacroLibX/actions/workflows/macos_x86.yml"><img src="https://github.com/seekrs/MacroLibX/actions/workflows/macos_x86.yml/badge.svg"></a>
|
||||
<a href="https://github.com/420verfl0w/MacroLibX/actions/workflows/linux_clang.yml"><img src="https://github.com/420verfl0w/MacroLibX/actions/workflows/linux_clang.yml/badge.svg"></a>
|
||||
<a href="https://github.com/420verfl0w/MacroLibX/actions/workflows/linux_gcc.yml"><img src="https://github.com/420verfl0w/MacroLibX/actions/workflows/linux_gcc.yml/badge.svg"></a>
|
||||
<a href="https://github.com/420verfl0w/MacroLibX/actions/workflows/macos_x86.yml"><img src="https://github.com/420verfl0w/MacroLibX/actions/workflows/macos_x86.yml/badge.svg"></a>
|
||||
</div>
|
||||
<div align="center">
|
||||
<a href="https://github.com/seekrs/MacroLibX/actions/workflows/windows.yml"><img src="https://github.com/seekrs/MacroLibX/actions/workflows/windows.yml/badge.svg"></a>
|
||||
<a href="https://github.com/420verfl0w/MacroLibX/actions/workflows/windows.yml"><img src="https://github.com/420verfl0w/MacroLibX/actions/workflows/windows.yml/badge.svg"></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
###### MacroLibX, a rewrite of 42 School's MiniLibX using SDL2 and Vulkan.
|
||||
The goal of this version is to provide a light, fast, and modern graphical tool while keeping the same API.
|
||||
|
||||
## 🌟 Features
|
||||
|
||||
### 🚀 Performances
|
||||
Built on top of Vulkan, the MacroLibX takes advantage of its very low-level nature to achieve high performance with great control over available resources.
|
||||
|
||||
### 💻 Cross-Platform
|
||||
Designed to be totally cross-platform, it can run on any SDL2-supported platform that supports Vulkan (even the Nintendo Switch ! theoretically... ).
|
||||
|
||||
### 🗿 Close to the old minilibx
|
||||
One of the guidelines of this lib was to get as close as possible to the old minilibx API, and therefore to the educational choices of the old minilibx.
|
||||
|
||||
### 📖 It's all FOSS
|
||||
Everything in this repo is entirely free and open source, all available under the MIT license (even the third-party libraries used).
|
||||
|
||||
### 🔍 Valgrind suppressions file
|
||||
Experimental for now, a [suppressions file for valgrind](./valgrind.supp) is given to remove potential leaks comming from Xorg, Nvidia drivers, SDL2, or any other tool which the user has no control. It is far from perfect at the moment and may allow some leaks but it will block the majority.
|
||||
|
||||
### ⛔ Error system
|
||||
Strong error handling informing the user of problems with their code and even capable of informing them of graphics memory leaks that tools like Valgrind cannot detect.
|
||||
|
||||
## 🖥️ Installation
|
||||
|
||||
### Dependencies
|
||||
@ -58,9 +38,6 @@ sudo apt install libsdl2-2.0-0 libsdl2-dev build-essential
|
||||
<pre><code>sudo pacman -S sdl2</code></pre>
|
||||
</details>
|
||||
|
||||
<br>
|
||||
Note that you need to have up do date video drivers with <code>libvulkan.so</code> installed.
|
||||
|
||||
#### 🍎 macOS
|
||||
[MacroLibX](#) on macOS requires [SDL2](#) and [MoltenVK](https://github.com/KhronosGroup/MoltenVK). You can install both using the [Homebrew](https://brew.sh) package manager:
|
||||
```sh
|
||||
@ -74,7 +51,7 @@ To build on Windows you may need to use the [xmake](https://xmake.io) build. [He
|
||||
### Clone and Build
|
||||
Finally, you can clone the Git repository. When inside it, run the GNU `make` command to compile MacroLibX.
|
||||
```bash
|
||||
git clone https://github.com/seekrs/MacroLibX.git
|
||||
git clone https://github.com/420verfl0w/MacroLibX.git
|
||||
cd MacroLibX
|
||||
make
|
||||
```
|
||||
@ -110,4 +87,5 @@ You can force the mlx to use your integrated GPU by using `make FORCE_INTEGRATED
|
||||
The mlx can dump it's graphics memory use to json files every two seconds by enabling this option `make GRAPHICS_MEMORY_DUMP=true`.
|
||||
|
||||
## License
|
||||
This project and all its files, even the [`third_party`](./third_party) directory or unless otherwise mentionned, are licenced under the [MIT license](./LICENSE).
|
||||
|
||||
This project and all its files, except the [`third_party`](./third_party) directory or unless otherwise mentionned, are licenced under the [MIT license](./LICENSE).
|
||||
|
Binary file not shown.
@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $(uname -s) = 'Darwin' ]; then
|
||||
clang main.c ../libmlx.dylib -L /opt/homebrew/lib -lSDL2 -g;
|
||||
else
|
||||
clang main.c ../libmlx.so -lSDL2 -g;
|
||||
fi
|
||||
|
@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
bash ./build.sh
|
||||
./a.out
|
@ -6,16 +6,28 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/27 17:19:50 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 18:07:40 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// MacroLibX official repo https://github.com/seekrs/MacroLibX
|
||||
// MacroLibX official repo https://github.com/420verfl0w/MacroLibX
|
||||
|
||||
#ifndef __MACRO_LIB_X_H__
|
||||
#define __MACRO_LIB_X_H__
|
||||
|
||||
#include "mlx_profile.h"
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define MLX_EXPORT __declspec(dllexport)
|
||||
#define MLX_IMPORT __declspec(dllimport)
|
||||
#else
|
||||
#define MLX_EXPORT
|
||||
#define MLX_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef MLX_BUILD
|
||||
#define MLX_API MLX_EXPORT
|
||||
#else
|
||||
#define MLX_API MLX_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -31,7 +43,6 @@ typedef enum
|
||||
MLX_WINDOW_EVENT = 5
|
||||
} mlx_event_type;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializes the MLX internal application
|
||||
*
|
||||
@ -39,7 +50,6 @@ typedef enum
|
||||
*/
|
||||
MLX_API void* mlx_init();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a new window
|
||||
*
|
||||
@ -52,7 +62,6 @@ MLX_API void* mlx_init();
|
||||
*/
|
||||
MLX_API void* mlx_new_window(void* mlx, int w, int h, const char* title);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gives a function to be executed at each loop turn
|
||||
*
|
||||
@ -62,8 +71,8 @@ MLX_API void* mlx_new_window(void* mlx, int w, int h, const char* title);
|
||||
*
|
||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
||||
*/
|
||||
MLX_API int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
|
||||
|
||||
MLX_API int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
|
||||
|
||||
/**
|
||||
* @brief Starts the internal main loop
|
||||
@ -74,7 +83,6 @@ MLX_API int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
|
||||
*/
|
||||
MLX_API int mlx_loop(void* mlx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Ends the internal main loop
|
||||
*
|
||||
@ -84,7 +92,6 @@ MLX_API int mlx_loop(void* mlx);
|
||||
*/
|
||||
MLX_API int mlx_loop_end(void* mlx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Shows mouse cursor
|
||||
*
|
||||
@ -92,7 +99,6 @@ MLX_API int mlx_loop_end(void* mlx);
|
||||
*/
|
||||
MLX_API int mlx_mouse_show();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Hides mouse cursor
|
||||
*
|
||||
@ -100,7 +106,6 @@ MLX_API int mlx_mouse_show();
|
||||
*/
|
||||
MLX_API int mlx_mouse_hide();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Moves cursor to givent position
|
||||
*
|
||||
@ -113,7 +118,6 @@ MLX_API int mlx_mouse_hide();
|
||||
*/
|
||||
MLX_API int mlx_mouse_move(void* mlx, void* win, int x, int y);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get cursor's position
|
||||
*
|
||||
@ -168,7 +172,6 @@ MLX_API int mlx_pixel_put(void* mlx, void* win, int x, int y, int color);
|
||||
*/
|
||||
MLX_API void* mlx_new_image(void* mlx, int width, int height);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get image pixel data
|
||||
*
|
||||
@ -182,14 +185,13 @@ MLX_API void* mlx_new_image(void* mlx, int width, int height);
|
||||
* /!\ If you run into glitches when writing or reading pixels from images /!\
|
||||
* You need to add IMAGES_OPTIMIZED=false to your make mlx command
|
||||
* ```
|
||||
* ~ git clone https://github.com/seekrs/MacroLibX.git
|
||||
* ~ git clone https://github.com/420verfl0w/MacroLibX.git
|
||||
* ~ cd MacroLibX
|
||||
* ~ make IMAGES_OPTIMIZED=false
|
||||
* ```
|
||||
*/
|
||||
MLX_API int mlx_get_image_pixel(void* mlx, void* img, int x, int y);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set image pixel data
|
||||
*
|
||||
@ -204,14 +206,13 @@ MLX_API int mlx_get_image_pixel(void* mlx, void* img, int x, int y);
|
||||
* /!\ If you run into glitches when writing or reading pixels from images /!\
|
||||
* You need to add IMAGES_OPTIMIZED=false to your make mlx command
|
||||
* ```
|
||||
* ~ git clone https://github.com/seekrs/MacroLibX.git
|
||||
* ~ git clone https://github.com/420verfl0w/MacroLibX.git
|
||||
* ~ cd MacroLibX
|
||||
* ~ make IMAGES_OPTIMIZED=false
|
||||
* ```
|
||||
*/
|
||||
MLX_API void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Put image to the given window
|
||||
*
|
||||
@ -225,7 +226,6 @@ MLX_API void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);
|
||||
*/
|
||||
MLX_API int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Destroys internal image
|
||||
*
|
||||
@ -249,7 +249,6 @@ MLX_API int mlx_destroy_image(void* mlx, void* img);
|
||||
*/
|
||||
MLX_API void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create a new image from a jpg file
|
||||
*
|
||||
@ -262,7 +261,6 @@ MLX_API void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int*
|
||||
*/
|
||||
MLX_API void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create a new image from a bmp file
|
||||
*
|
||||
@ -296,19 +294,18 @@ MLX_API int mlx_string_put(void* mlx, void* win, int x, int y, int color, char*
|
||||
*
|
||||
* @param mlx Internal MLX application
|
||||
* @param win Internal window
|
||||
* @param filepath Filepath to the font or "default" to reset to the embedded font
|
||||
* @param filepath Filepath to the font
|
||||
*
|
||||
* @return (void)
|
||||
*/
|
||||
MLX_API void mlx_set_font(void* mlx, void* win, char* filepath);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Loads a font to be used by `mlx_string_put` and scales it
|
||||
*
|
||||
* @param mlx Internal MLX application
|
||||
* @param win Internal window
|
||||
* @param filepath Filepath to the font or "default" to reset to the embedded font
|
||||
* @param filepath Filepath to the font
|
||||
* @param scale Scale to apply to the font
|
||||
*
|
||||
* @return (void)
|
||||
|
@ -1,215 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mlx_profile.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/10 08:49:17 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:33:35 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_PROFILE__
|
||||
#define __MLX_PROFILE__
|
||||
|
||||
// Try to identify the compiler
|
||||
#if defined(__BORLANDC__)
|
||||
#define MLX_COMPILER_BORDLAND
|
||||
#elif defined(__clang__)
|
||||
#define MLX_COMPILER_CLANG
|
||||
#ifdef __MINGW32__
|
||||
#define MLX_COMPILER_MINGW
|
||||
#ifdef __MINGW64_VERSION_MAJOR
|
||||
#define MLX_COMPILER_MINGW_W64
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__GNUC__) || defined(__MINGW32__)
|
||||
#define MLX_COMPILER_GCC
|
||||
#ifdef __MINGW32__
|
||||
#define MLX_COMPILER_MINGW
|
||||
#ifdef __MINGW64_VERSION_MAJOR
|
||||
#define MLX_COMPILER_MINGW_W64
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__INTEL_COMPILER) || defined(__ICL)
|
||||
#define MLX_COMPILER_INTEL
|
||||
#elif defined(_MSC_VER)
|
||||
#define MLX_COMPILER_MSVC
|
||||
#else
|
||||
#define MLX_COMPILER_UNKNOWN
|
||||
#warning "This compiler is not fully supported"
|
||||
#endif
|
||||
|
||||
#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
|
||||
#error "Unknown environment (not Windows, not Linux, not MacOS, not Unix)"
|
||||
#endif
|
||||
|
||||
#ifdef MLX_PLAT_WINDOWS
|
||||
#ifdef MLX_COMPILER_MSVC
|
||||
#ifdef MLX_BUILD
|
||||
#define MLX_API __declspec(dllexport)
|
||||
#else
|
||||
#define MLX_API __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined(MLX_COMPILER_GCC)
|
||||
#ifdef MLX_BUILD
|
||||
#define MLX_API __attribute__((dllexport))
|
||||
#else
|
||||
#define MLX_API __attribute__((dllimport))
|
||||
#endif
|
||||
#else
|
||||
#define MLX_API
|
||||
#endif
|
||||
#elif defined(MLX_COMPILER_GCC)
|
||||
#define MLX_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define MLX_API
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
|
||||
#define MLX_FUNC_SIG __PRETTY_FUNCTION__
|
||||
#elif defined(__DMC__) && (__DMC__ >= 0x810)
|
||||
#define MLX_FUNC_SIG __PRETTY_FUNCTION__
|
||||
#elif (defined(__FUNCSIG__) || (_MSC_VER))
|
||||
#define MLX_FUNC_SIG __FUNCSIG__
|
||||
#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
|
||||
#define MLX_FUNC_SIG __FUNCTION__
|
||||
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
|
||||
#define MLX_FUNC_SIG __FUNC__
|
||||
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
|
||||
#define MLX_FUNC_SIG __func__
|
||||
#elif defined(__cplusplus) && (__cplusplus >= 201103)
|
||||
#define MLX_FUNC_SIG __func__
|
||||
#else
|
||||
#define MLX_FUNC_SIG "Unknown function"
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus // if we compile in C
|
||||
#ifdef __STDC__
|
||||
#ifdef __STDC_VERSION__
|
||||
#if __STDC_VERSION__ == 199409L
|
||||
#define MLX_C_VERSION 1994
|
||||
#elif __STDC_VERSION__ == 199901L
|
||||
#define MLX_C_VERSION 1999
|
||||
#elif __STDC_VERSION__ == 201112L
|
||||
#define MLX_C_VERSION 2011
|
||||
#elif __STDC_VERSION__ == 201710L
|
||||
#define MLX_C_VERSION 2017
|
||||
#elif __STDC_VERSION__ == 202311L
|
||||
#define MLX_C_VERSION 2023
|
||||
#else
|
||||
#define MLX_C_VERSION 0
|
||||
#endif
|
||||
#else
|
||||
#define MLX_C_VERSION 0
|
||||
#endif
|
||||
#else
|
||||
#define MLX_C_VERSION 0
|
||||
#endif
|
||||
#else
|
||||
#define MLX_C_VERSION 0
|
||||
#endif
|
||||
|
||||
#if defined(MLX_PLAT_WINDOWS)
|
||||
#define VK_USE_PLATFORM_WIN32_KHR
|
||||
#ifdef __cplusplus
|
||||
constexpr const char* VULKAN_LIB_NAME = "vulkan-1.dll";
|
||||
#endif
|
||||
#elif defined(MLX_PLAT_MACOS)
|
||||
#define VK_USE_PLATFORM_MACOS_MVK
|
||||
#define VK_USE_PLATFORM_METAL_EXT
|
||||
#ifdef __cplusplus
|
||||
constexpr const char* VULKAN_LIB_NAME = "libvulkan.dylib / libvulkan.1.dylib / libMoltenVK.dylib";
|
||||
#endif
|
||||
#else
|
||||
#define VK_USE_PLATFORM_XLIB_KHR
|
||||
#define VK_USE_PLATFORM_WAYLAND_KHR
|
||||
#ifdef __cplusplus
|
||||
constexpr const char* VULKAN_LIB_NAME = "libvulkan.so / libvulkan.so.1";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Checking common assumptions
|
||||
#ifdef __cplusplus
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
|
||||
static_assert(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
|
||||
|
||||
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
|
||||
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
|
||||
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
|
||||
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
|
||||
|
||||
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
|
||||
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
|
||||
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
|
||||
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
|
||||
#elif MLX_C_VERSION >= 2011
|
||||
#if MLX_C_VERSION < 2023
|
||||
#include <assert.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static_assert(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
|
||||
|
||||
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
|
||||
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
|
||||
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
|
||||
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
|
||||
|
||||
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
|
||||
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
|
||||
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
|
||||
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
|
||||
#elif defined(MLX_COMPILER_GCC)
|
||||
#define STATIC_ASSERT(cnd, descr) \
|
||||
({ \
|
||||
extern int __attribute__((error("static assert failed: (" #cnd ") (" #descr ")"))) compile_time_check(void); \
|
||||
((cnd) ? 0 : compile_time_check()), 0; \
|
||||
})
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
STATIC_ASSERT(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
|
||||
|
||||
STATIC_ASSERT(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
|
||||
STATIC_ASSERT(sizeof(int16_t) == 2, "int16_t is not of the correct size");
|
||||
STATIC_ASSERT(sizeof(int32_t) == 4, "int32_t is not of the correct size");
|
||||
STATIC_ASSERT(sizeof(int64_t) == 8, "int64_t is not of the correct size");
|
||||
|
||||
STATIC_ASSERT(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
|
||||
STATIC_ASSERT(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
|
||||
STATIC_ASSERT(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
|
||||
STATIC_ASSERT(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
|
||||
#else
|
||||
#define STATIC_ASSERT(COND, MSG) typedef char static_assertion___##MSG[(COND)?1:-1]
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
STATIC_ASSERT(CHAR_BIT == 8, CHAR_BIT_is_expected_to_be_8);
|
||||
|
||||
STATIC_ASSERT(sizeof(int8_t) == 1, int8_t_is_not_of_the_correct_size);
|
||||
STATIC_ASSERT(sizeof(int16_t) == 2, int16_t_is_not_of_the_correct_size);
|
||||
STATIC_ASSERT(sizeof(int32_t) == 4, int32_t_is_not_of_the_correct_size);
|
||||
STATIC_ASSERT(sizeof(int64_t) == 8, int64_t_is_not_of_the_correct_size);
|
||||
|
||||
STATIC_ASSERT(sizeof(uint8_t) == 1, uint8_t_is_not_of_the_correct_size);
|
||||
STATIC_ASSERT(sizeof(uint16_t) == 2, uint16_t_is_not_of_the_correct_size);
|
||||
STATIC_ASSERT(sizeof(uint32_t) == 4, uint32_t_is_not_of_the_correct_size);
|
||||
STATIC_ASSERT(sizeof(uint64_t) == 8, uint64_t_is_not_of_the_correct_size);
|
||||
#endif
|
||||
|
||||
#endif
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Update volk
|
||||
rm -f ../third_party/volk.c
|
||||
rm -f ../third_party/volk.h
|
||||
tag_name=$(curl -sL https://api.github.com/repos/zeux/Volk/releases/latest | jq -r '.tag_name')
|
||||
wget https://api.github.com/repos/zeux/volk/zipball/$tag_name -O volk.zip
|
||||
unzip -o volk.zip -d ../third_party/
|
||||
mv ../third_party/zeux-volk*/volk.h ../third_party
|
||||
mv ../third_party/zeux-volk*/volk.c ../third_party
|
||||
rm -rf ../third_party/zeux-volk*
|
||||
rm volk.zip
|
||||
|
||||
# Update VMA
|
||||
rm -f ../third_party/vma.h
|
||||
tag_name=$(curl -sL https://api.github.com/repos/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/releases/latest | jq -r '.tag_name')
|
||||
wget https://api.github.com/repos/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/zipball/$tag_name -O vma.zip
|
||||
unzip -o vma.zip -d ../third_party/
|
||||
mv ../third_party/GPUOpen-LibrariesAndSDKs-VulkanMemoryAllocator*/include/vk_mem_alloc.h ../third_party/vma.h
|
||||
rm -rf ../third_party/GPUOpen-LibrariesAndSDKs-VulkanMemoryAllocator*
|
||||
rm vma.zip
|
||||
|
||||
# Update Vulkan headers
|
||||
rm -rf ../third_party/vulkan
|
||||
rm -rf ../third_party/vk_video
|
||||
wget https://github.com/KhronosGroup/Vulkan-Headers/archive/main.zip -O vulkan-headers.zip
|
||||
unzip -o vulkan-headers.zip -d ../third_party/
|
||||
mv ../third_party/Vulkan-Headers-main/include/vulkan ../third_party/
|
||||
mv ../third_party/Vulkan-Headers-main/include/vk_video ../third_party/
|
||||
rm -rf ../third_party/Vulkan-Headers-main
|
||||
rm vulkan-headers.zip
|
@ -6,28 +6,21 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/27 21:30:10 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/09 17:44:13 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "application.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <renderer/images/texture.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <array>
|
||||
#include <core/errors.h>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/memory.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx::core
|
||||
{
|
||||
static bool __drop_sdl_responsability = false;
|
||||
Application::Application() : _in(std::make_unique<Input>())
|
||||
{
|
||||
__drop_sdl_responsability = SDL_WasInit(SDL_INIT_VIDEO);
|
||||
if(__drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init
|
||||
return;
|
||||
SDL_SetMemoryFunctions(MemManager::malloc, MemManager::calloc, MemManager::realloc, MemManager::free);
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
|
||||
error::report(e_kind::fatal_error, "SDL error : unable to init all subsystems : %s", SDL_GetError());
|
||||
}
|
||||
@ -37,12 +30,14 @@ namespace mlx::core
|
||||
while(_in->is_running())
|
||||
{
|
||||
_in->update();
|
||||
for(auto& gs : _graphics)
|
||||
gs->beginRender();
|
||||
|
||||
if(_loop_hook)
|
||||
_loop_hook(_param);
|
||||
|
||||
for(auto& gs : _graphics)
|
||||
gs->render();
|
||||
gs->endRender();
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,15 +59,13 @@ namespace mlx::core
|
||||
|
||||
void Application::destroyTexture(void* ptr)
|
||||
{
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get()); // TODO : synchronize with another method than stopping all the GPU process
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
Texture* texture = static_cast<Texture*>(ptr);
|
||||
texture->destroy();
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
if(__drop_sdl_responsability)
|
||||
return;
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/22 21:04:48 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/08 18:52:47 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
#include <core/graphics.h>
|
||||
#include <platform/inputs.h>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx::core
|
||||
{
|
||||
@ -40,7 +40,7 @@ namespace mlx::core
|
||||
|
||||
inline void getScreenSize(int* w, int* h) noexcept;
|
||||
|
||||
inline void* newGraphicsSuport(std::size_t w, std::size_t h, const char* title);
|
||||
inline void* newGraphicsSuport(std::size_t w, std::size_t h, std::string title);
|
||||
inline void clearGraphicsSupport(void* win);
|
||||
inline void destroyGraphicsSupport(void* win);
|
||||
|
||||
@ -69,6 +69,7 @@ namespace mlx::core
|
||||
std::function<int(void*)> _loop_hook;
|
||||
std::unique_ptr<Input> _in;
|
||||
void* _param = nullptr;
|
||||
bool _is_loop_running = false;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -12,18 +12,6 @@
|
||||
|
||||
#include <core/application.h>
|
||||
|
||||
#define CHECK_WINDOW_PTR(win) \
|
||||
if(win == nullptr) \
|
||||
{ \
|
||||
core::error::report(e_kind::error, "invalid window ptr (NULL)"); \
|
||||
return; \
|
||||
} \
|
||||
else if(*static_cast<int*>(win) < 0 || *static_cast<int*>(win) > static_cast<int>(_graphics.size()))\
|
||||
{ \
|
||||
core::error::report(e_kind::error, "invalid window ptr"); \
|
||||
return; \
|
||||
} else {}\
|
||||
|
||||
namespace mlx::core
|
||||
{
|
||||
void Application::getMousePos(int* x, int* y) noexcept
|
||||
@ -34,7 +22,6 @@ namespace mlx::core
|
||||
|
||||
void Application::mouseMove(void* win, int x, int y) noexcept
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
SDL_WarpMouseInWindow(_graphics[*static_cast<int*>(win)]->getWindow()->getNativeWindow(), x, y);
|
||||
SDL_PumpEvents();
|
||||
SDL_FlushEvent(SDL_MOUSEMOTION);
|
||||
@ -42,7 +29,6 @@ namespace mlx::core
|
||||
|
||||
void Application::onEvent(void* win, int event, int (*funct_ptr)(int, void*), void* param) noexcept
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
_in->onEvent(_graphics[*static_cast<int*>(win)]->getWindow()->getID(), event, funct_ptr, param);
|
||||
}
|
||||
|
||||
@ -54,94 +40,53 @@ namespace mlx::core
|
||||
*h = DM.h;
|
||||
}
|
||||
|
||||
void* Application::newGraphicsSuport(std::size_t w, std::size_t h, const char* title)
|
||||
{
|
||||
auto it = std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture)
|
||||
{
|
||||
return &texture == reinterpret_cast<Texture*>(const_cast<char*>(title));
|
||||
});
|
||||
if(it != _textures.end())
|
||||
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, reinterpret_cast<Texture*>(const_cast<char*>(title)), _graphics.size()));
|
||||
else
|
||||
void* Application::newGraphicsSuport(std::size_t w, std::size_t h, std::string title)
|
||||
{
|
||||
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, _graphics.size()));
|
||||
_in->addWindow(_graphics.back()->getWindow());
|
||||
}
|
||||
return static_cast<void*>(&_graphics.back()->getID());
|
||||
}
|
||||
|
||||
void Application::clearGraphicsSupport(void* win)
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
_graphics[*static_cast<int*>(win)]->clearRenderData();
|
||||
}
|
||||
|
||||
void Application::destroyGraphicsSupport(void* win)
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
_graphics[*static_cast<int*>(win)].reset();
|
||||
}
|
||||
|
||||
void Application::pixelPut(void* win, int x, int y, uint32_t color) const noexcept
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
_graphics[*static_cast<int*>(win)]->pixelPut(x, y, color);
|
||||
}
|
||||
|
||||
void Application::stringPut(void* win, int x, int y, int color, char* str)
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
_graphics[*static_cast<int*>(win)]->stringPut(x, y, color, str);
|
||||
}
|
||||
|
||||
void Application::loadFont(void* win, const std::filesystem::path& filepath, float scale)
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
_graphics[*static_cast<int*>(win)]->loadFont(filepath, scale);
|
||||
}
|
||||
|
||||
void Application::texturePut(void* win, void* img, int x, int y)
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
if(img == nullptr)
|
||||
{
|
||||
core::error::report(e_kind::error, "wrong texture (NULL)");
|
||||
return;
|
||||
}
|
||||
Texture* texture = static_cast<Texture*>(img);
|
||||
if(!texture->isInit())
|
||||
core::error::report(e_kind::error, "trying to put a texture that has been destroyed");
|
||||
else
|
||||
_graphics[*static_cast<int*>(win)]->texturePut(texture, x, y);
|
||||
}
|
||||
|
||||
int Application::getTexturePixel(void* img, int x, int y)
|
||||
{
|
||||
if(img == nullptr)
|
||||
{
|
||||
core::error::report(e_kind::error, "wrong texture (NULL)");
|
||||
return 0;
|
||||
}
|
||||
Texture* texture = static_cast<Texture*>(img);
|
||||
if(!texture->isInit())
|
||||
{
|
||||
core::error::report(e_kind::error, "trying to get a pixel from texture that has been destroyed");
|
||||
return 0;
|
||||
}
|
||||
return texture->getPixel(x, y);
|
||||
}
|
||||
|
||||
void Application::setTexturePixel(void* img, int x, int y, uint32_t color)
|
||||
{
|
||||
if(img == nullptr)
|
||||
{
|
||||
core::error::report(e_kind::error, "wrong texture (NULL)");
|
||||
return;
|
||||
}
|
||||
Texture* texture = static_cast<Texture*>(img);
|
||||
if(!texture->isInit())
|
||||
core::error::report(e_kind::error, "trying to set a pixel on texture that has been destroyed");
|
||||
else
|
||||
texture->setPixel(x, y, color);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/31 00:22:58 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/07 23:05:05 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,57 +16,44 @@
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <filesystem>
|
||||
#include <mlx.h>
|
||||
#include <core/memory.h>
|
||||
#include <mlx_profile.h>
|
||||
|
||||
static void* __mlx_ptr = nullptr;
|
||||
|
||||
#define MLX_CHECK_APPLICATION_POINTER(ptr) \
|
||||
if(ptr != __mlx_ptr || ptr == NULL) \
|
||||
mlx::core::error::report(e_kind::fatal_error, "invalid mlx pointer passed to '%s'", MLX_FUNC_SIG); \
|
||||
else {} // just to avoid issues with possible if-else statements outside this macro
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void* mlx_init()
|
||||
{
|
||||
if(__mlx_ptr != nullptr)
|
||||
static bool init = false;
|
||||
if(init)
|
||||
{
|
||||
mlx::core::error::report(e_kind::error, "MLX cannot be initialized multiple times");
|
||||
return NULL; // not nullptr for the C compatibility
|
||||
return NULL;
|
||||
}
|
||||
mlx::MemManager::get(); // just to initialize the C garbage collector
|
||||
mlx::core::Application* app = new mlx::core::Application;
|
||||
mlx::Render_Core::get().init();
|
||||
if(app == nullptr)
|
||||
mlx::core::error::report(e_kind::fatal_error, "Tout a pété");
|
||||
__mlx_ptr = static_cast<void*>(app);
|
||||
return __mlx_ptr;
|
||||
init = true;
|
||||
return static_cast<void*>(app);
|
||||
}
|
||||
|
||||
void* mlx_new_window(void* mlx, int w, int h, const char* title)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
return static_cast<mlx::core::Application*>(mlx)->newGraphicsSuport(w, h, title);
|
||||
}
|
||||
|
||||
int mlx_loop_hook(void* mlx, int (*f)(void*), void* param)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->loopHook(f, param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_loop(void* mlx)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_loop_end(void* mlx)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->loopEnd();
|
||||
return 0;
|
||||
}
|
||||
@ -83,40 +70,34 @@ extern "C"
|
||||
|
||||
int mlx_mouse_move(void* mlx, void* win, int x, int y)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->mouseMove(win, x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_mouse_get_pos(void* mlx, int* x, int* y)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->getMousePos(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*funct_ptr)(int, void*), void* param)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->onEvent(win, static_cast<int>(event), funct_ptr, param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* mlx_new_image(void* mlx, int width, int height)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
return static_cast<mlx::core::Application*>(mlx)->newTexture(width, height);
|
||||
}
|
||||
|
||||
int mlx_get_image_pixel(void* mlx, void* img, int x, int y)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
return static_cast<mlx::core::Application*>(mlx)->getTexturePixel(img, x, y);
|
||||
}
|
||||
|
||||
void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
unsigned char color_bits[4];
|
||||
color_bits[0] = (color & 0x00FF0000) >> 16;
|
||||
color_bits[1] = (color & 0x0000FF00) >> 8;
|
||||
@ -127,21 +108,18 @@ extern "C"
|
||||
|
||||
int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->texturePut(win, img, x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_destroy_image(void* mlx, void* img)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->destroyTexture(img);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
std::filesystem::path file(filename);
|
||||
if(file.extension() != ".png")
|
||||
{
|
||||
@ -153,7 +131,6 @@ extern "C"
|
||||
|
||||
void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
std::filesystem::path file(filename);
|
||||
if(file.extension() != ".jpg" && file.extension() != ".jpeg")
|
||||
{
|
||||
@ -165,7 +142,6 @@ extern "C"
|
||||
|
||||
void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
std::filesystem::path file(filename);
|
||||
if(file.extension() != ".bmp" && file.extension() != ".dib")
|
||||
{
|
||||
@ -177,19 +153,17 @@ extern "C"
|
||||
|
||||
int mlx_pixel_put(void* mlx, void* win, int x, int y, int color)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
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;
|
||||
color_bits[2] = color & 0x000000FF;
|
||||
color_bits[3] = 0xFF;
|
||||
static_cast<mlx::core::Application*>(mlx)->pixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
unsigned char color_bits[4];
|
||||
color_bits[0] = (color & 0x00FF0000) >> 16;
|
||||
color_bits[1] = (color & 0x0000FF00) >> 8;
|
||||
@ -201,9 +175,8 @@ extern "C"
|
||||
|
||||
void mlx_set_font(void* mlx, void* win, char* filepath)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
std::filesystem::path file(filepath);
|
||||
if(std::strcmp(filepath, "default") != 0 && file.extension() != ".ttf" && file.extension() != ".tte")
|
||||
if(file.extension() != ".ttf" && file.extension() != ".tte")
|
||||
{
|
||||
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
|
||||
return;
|
||||
@ -213,9 +186,8 @@ extern "C"
|
||||
|
||||
void mlx_set_font_scale(void* mlx, void* win, char* filepath, float scale)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
std::filesystem::path file(filepath);
|
||||
if(std::strcmp(filepath, "default") != 0 && file.extension() != ".ttf" && file.extension() != ".tte")
|
||||
if(file.extension() != ".ttf" && file.extension() != ".tte")
|
||||
{
|
||||
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
|
||||
return;
|
||||
@ -225,30 +197,25 @@ extern "C"
|
||||
|
||||
int mlx_clear_window(void* mlx, void* win)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->clearGraphicsSupport(win);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_destroy_window(void* mlx, void* win)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->destroyGraphicsSupport(win);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_destroy_display(void* mlx)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
delete static_cast<mlx::core::Application*>(mlx);
|
||||
mlx::Render_Core::get().destroy();
|
||||
__mlx_ptr = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_get_screens_size(void* mlx, int* w, int* h)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::core::Application*>(mlx)->getScreenSize(w, h);
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:42:32 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/27 17:21:07 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 18:53:11 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
#define __MLX_ERRORS__
|
||||
|
||||
#include <string>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
enum class e_kind
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/27 21:27:48 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/09 16:52:08 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,40 +14,19 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, Texture* render_target, int id) :
|
||||
_window(nullptr),
|
||||
_text_put_pipeline(std::make_unique<TextPutPipeline>()),
|
||||
_renderer(std::make_unique<Renderer>()),
|
||||
_width(w),
|
||||
_height(h),
|
||||
_id(id)
|
||||
{
|
||||
_renderer->setWindow(nullptr);
|
||||
_renderer->init(render_target);
|
||||
_pixel_put_pipeline.init(w, h, *_renderer);
|
||||
_text_put_pipeline->init(_renderer.get());
|
||||
}
|
||||
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id) :
|
||||
_window(std::make_shared<MLX_Window>(w, h, title)),
|
||||
_text_put_pipeline(std::make_unique<TextPutPipeline>()),
|
||||
_renderer(std::make_unique<Renderer>()),
|
||||
_width(w),
|
||||
_height(h),
|
||||
_renderer(std::make_unique<Renderer>()), _text_put_pipeline(std::make_unique<TextPutPipeline>()),
|
||||
_id(id)
|
||||
{
|
||||
_renderer->setWindow(_window.get());
|
||||
_renderer->init(nullptr);
|
||||
_renderer->init();
|
||||
_pixel_put_pipeline.init(w, h, *_renderer);
|
||||
_text_put_pipeline->init(_renderer.get());
|
||||
}
|
||||
|
||||
void GraphicsSupport::render() noexcept
|
||||
void GraphicsSupport::endRender() noexcept
|
||||
{
|
||||
if(!_renderer->beginFrame())
|
||||
return;
|
||||
_proj = glm::ortho<float>(0, _width, 0, _height);
|
||||
_renderer->getUniformBuffer()->setData(sizeof(_proj), &_proj);
|
||||
auto cmd_buff = _renderer->getActiveCmdBuffer().get();
|
||||
|
||||
static std::array<VkDescriptorSet, 2> sets = {
|
||||
@ -57,12 +36,8 @@ namespace mlx
|
||||
|
||||
for(auto& data : _textures_to_render)
|
||||
{
|
||||
if(!data.texture->isInit())
|
||||
continue;
|
||||
if(data.texture->getSet() == VK_NULL_HANDLE)
|
||||
data.texture->setDescriptor(_renderer->getFragDescriptorSet().duplicate());
|
||||
if(data.texture->getLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
|
||||
data.texture->transitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
if(!data.texture->hasBeenUpdated())
|
||||
data.texture->updateSet(0);
|
||||
sets[1] = data.texture->getSet();
|
||||
@ -75,7 +50,11 @@ namespace mlx
|
||||
sets[1] = _pixel_put_pipeline.getDescriptorSet();
|
||||
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
_pixel_put_pipeline.render(*_renderer);
|
||||
_text_put_pipeline->render(sets);
|
||||
|
||||
sets[1] = _text_put_pipeline->getDescriptorSet();
|
||||
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
_text_put_pipeline->render();
|
||||
|
||||
_renderer->endFrame();
|
||||
|
||||
for(auto& data : _textures_to_render)
|
||||
@ -98,7 +77,6 @@ namespace mlx
|
||||
_text_put_pipeline->destroy();
|
||||
_pixel_put_pipeline.destroy();
|
||||
_renderer->destroy();
|
||||
if(_window)
|
||||
_window->destroy();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/24 08:56:14 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:04:59 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,20 +26,20 @@
|
||||
#include <renderer/text_pipeline.h>
|
||||
#include <utils/non_copyable.h>
|
||||
#include <renderer/images/texture.h>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class GraphicsSupport : public non_copyable
|
||||
{
|
||||
public:
|
||||
GraphicsSupport(std::size_t w, std::size_t h, Texture* render_target, int id);
|
||||
GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id);
|
||||
GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id);
|
||||
|
||||
inline int& getID() noexcept;
|
||||
inline std::shared_ptr<MLX_Window> getWindow();
|
||||
|
||||
void render() noexcept;
|
||||
inline void beginRender() noexcept;
|
||||
void endRender() noexcept;
|
||||
|
||||
inline void clearRenderData() noexcept;
|
||||
inline void pixelPut(int x, int y, uint32_t color) noexcept;
|
||||
@ -56,8 +56,6 @@ namespace mlx
|
||||
std::shared_ptr<MLX_Window> _window;
|
||||
std::unique_ptr<TextPutPipeline> _text_put_pipeline; // unique_ptr because of the size of the class
|
||||
std::unique_ptr<Renderer> _renderer;
|
||||
std::size_t _width = 0;
|
||||
std::size_t _height = 0;
|
||||
int _id;
|
||||
};
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "renderer/images/texture.h"
|
||||
#include <core/graphics.h>
|
||||
#include <type_traits>
|
||||
|
||||
@ -18,6 +19,14 @@ namespace mlx
|
||||
int& GraphicsSupport::getID() noexcept { return _id; }
|
||||
std::shared_ptr<MLX_Window> GraphicsSupport::getWindow() { return _window; }
|
||||
|
||||
void GraphicsSupport::beginRender() noexcept
|
||||
{
|
||||
if(!_renderer->beginFrame())
|
||||
return;
|
||||
_proj = glm::ortho<float>(0, _window->getWidth(), 0, _window->getHeight());
|
||||
_renderer->getUniformBuffer()->setData(sizeof(_proj), &_proj);
|
||||
}
|
||||
|
||||
void GraphicsSupport::clearRenderData() noexcept
|
||||
{
|
||||
_textures_to_render.clear();
|
||||
@ -38,7 +47,14 @@ namespace mlx
|
||||
void GraphicsSupport::texturePut(Texture* texture, int x, int y)
|
||||
{
|
||||
_textures_to_render.emplace_back(texture, x, y);
|
||||
auto it = std::find(_textures_to_render.begin(), _textures_to_render.end() - 1, _textures_to_render.back());
|
||||
std::size_t hash = std::hash<TextureRenderData>{}(_textures_to_render.back());
|
||||
_textures_to_render.back().hash = hash;
|
||||
|
||||
auto it = std::find_if(_textures_to_render.begin(), _textures_to_render.end() - 1, [=](const TextureRenderData& rhs)
|
||||
{
|
||||
return rhs.hash == hash;
|
||||
});
|
||||
|
||||
if(it != _textures_to_render.end() - 1)
|
||||
_textures_to_render.erase(it);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/07 16:32:01 by kbz_8 #+# #+# */
|
||||
/* Updated: 2023/12/11 15:25:02 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/08 12:56:14 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void* MemManager::malloc(std::size_t size)
|
||||
void* MemManager::alloc(std::size_t size)
|
||||
{
|
||||
void* ptr = std::malloc(size);
|
||||
if(ptr != nullptr)
|
||||
@ -25,25 +25,6 @@ namespace mlx
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* MemManager::calloc(std::size_t n, std::size_t size)
|
||||
{
|
||||
void* ptr = std::calloc(n, size);
|
||||
if(ptr != nullptr)
|
||||
_blocks.push_back(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* MemManager::realloc(void* ptr, std::size_t size)
|
||||
{
|
||||
void* ptr2 = std::realloc(ptr, size);
|
||||
if(ptr2 != nullptr)
|
||||
_blocks.push_back(ptr2);
|
||||
auto it = std::find(_blocks.begin(), _blocks.end(), ptr);
|
||||
if(it != _blocks.end())
|
||||
_blocks.erase(it);
|
||||
return ptr2;
|
||||
}
|
||||
|
||||
void MemManager::free(void* ptr)
|
||||
{
|
||||
auto it = std::find(_blocks.begin(), _blocks.end(), ptr);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/07 16:31:51 by kbz_8 #+# #+# */
|
||||
/* Updated: 2023/12/11 19:47:13 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:05:15 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
#define __MLX_MEMORY__
|
||||
|
||||
#include <utils/singleton.h>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
#include <list>
|
||||
|
||||
namespace mlx
|
||||
@ -24,17 +24,15 @@ namespace mlx
|
||||
friend class Singleton<MemManager>;
|
||||
|
||||
public:
|
||||
static void* malloc(std::size_t size);
|
||||
static void* calloc(std::size_t n, std::size_t size);
|
||||
static void* realloc(void* ptr, std::size_t size);
|
||||
static void free(void* ptr);
|
||||
void* alloc(std::size_t size);
|
||||
void free(void* ptr);
|
||||
|
||||
private:
|
||||
MemManager() = default;
|
||||
~MemManager();
|
||||
|
||||
private:
|
||||
inline static std::list<void*> _blocks;
|
||||
std::list<void*> _blocks;
|
||||
};
|
||||
}
|
||||
|
||||
|
73
MacroLibX/src/core/profile.h
Normal file
73
MacroLibX/src/core/profile.h
Normal file
@ -0,0 +1,73 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* profile.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/10 08:49:17 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/08 18:49:38 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_PROFILE__
|
||||
#define __MLX_PROFILE__
|
||||
|
||||
// Try to identify the compiler
|
||||
#if defined(__BORLANDC__)
|
||||
#define MLX_COMPILER_BORDLAND
|
||||
#elif defined(__clang__)
|
||||
#define MLX_COMPILER_CLANG
|
||||
#ifdef __MINGW32__
|
||||
#define MLX_COMPILER_MINGW
|
||||
#ifdef __MINGW64_VERSION_MAJOR
|
||||
#define MLX_COMPILER_MINGW_W64
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__GNUC__) || defined(__MINGW32__)
|
||||
#define MLX_COMPILER_GCC
|
||||
#ifdef __MINGW32__
|
||||
#define MLX_COMPILER_MINGW
|
||||
#ifdef __MINGW64_VERSION_MAJOR
|
||||
#define MLX_COMPILER_MINGW_W64
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__INTEL_COMPILER) || defined(__ICL)
|
||||
#define MLX_COMPILER_INTEL
|
||||
#elif defined(_MSC_VER)
|
||||
#define MLX_COMPILER_MSVC
|
||||
#else
|
||||
#define MLX_COMPILER_UNKNOWN
|
||||
#warning "This compiler is not fully supported"
|
||||
#endif
|
||||
|
||||
#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
|
||||
#error "Unknown environment!"
|
||||
#endif
|
||||
|
||||
|
||||
// Checking common assumptions
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
|
||||
static_assert(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
|
||||
|
||||
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
|
||||
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
|
||||
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
|
||||
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
|
||||
|
||||
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
|
||||
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
|
||||
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
|
||||
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
|
||||
|
||||
#endif
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/11 19:01:14 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/08 12:17:40 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,6 +16,12 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
Input::Input()
|
||||
{
|
||||
std::memset(_keys.data(), 0, SDL_NUM_SCANCODES);
|
||||
std::memset(_mouse.data(), 0, 8);
|
||||
}
|
||||
|
||||
void Input::update()
|
||||
{
|
||||
_xRel = 0;
|
||||
@ -41,6 +47,7 @@ namespace mlx
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
_keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::down);
|
||||
if(hooks[MLX_KEYDOWN].hook)
|
||||
hooks[MLX_KEYDOWN].hook(_event.key.keysym.scancode, hooks[MLX_KEYDOWN].param);
|
||||
break;
|
||||
@ -48,6 +55,7 @@ namespace mlx
|
||||
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
_keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::up);
|
||||
if(hooks[MLX_KEYUP].hook)
|
||||
hooks[MLX_KEYUP].hook(_event.key.keysym.scancode, hooks[MLX_KEYUP].param);
|
||||
break;
|
||||
@ -55,6 +63,7 @@ namespace mlx
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
{
|
||||
_mouse[_event.button.button] = static_cast<uint8_t>(action::down);
|
||||
if(hooks[MLX_MOUSEDOWN].hook)
|
||||
hooks[MLX_MOUSEDOWN].hook(_event.button.button, hooks[MLX_MOUSEDOWN].param);
|
||||
break;
|
||||
@ -62,6 +71,7 @@ namespace mlx
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
_mouse[_event.button.button] = static_cast<uint8_t>(action::up);
|
||||
if(hooks[MLX_MOUSEUP].hook)
|
||||
hooks[MLX_MOUSEUP].hook(_event.button.button, hooks[MLX_MOUSEUP].param);
|
||||
break;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/11 19:47:20 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/08 18:54:03 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,12 +18,14 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
enum class action : uint8_t { up = (1 << 1), down = (1 << 2) };
|
||||
|
||||
struct Hook
|
||||
{
|
||||
std::function<int(int, void*)> hook;
|
||||
@ -33,10 +35,13 @@ namespace mlx
|
||||
class Input
|
||||
{
|
||||
public:
|
||||
Input() = default;
|
||||
Input();
|
||||
|
||||
void update();
|
||||
|
||||
inline bool getInKey(const SDL_Scancode key, action type = action::down) const noexcept { return _keys[key] & static_cast<uint8_t>(type); }
|
||||
|
||||
inline bool getInMouse(const uint8_t button, action type = action::down) const noexcept { return _mouse[button] & static_cast<uint8_t>(type); }
|
||||
inline bool isMouseMoving() const noexcept { return _xRel || _yRel; }
|
||||
|
||||
inline int getX() const noexcept { return _x; }
|
||||
@ -63,9 +68,11 @@ namespace mlx
|
||||
~Input() = default;
|
||||
|
||||
private:
|
||||
std::array<uint8_t, SDL_NUM_SCANCODES> _keys;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<MLX_Window>> _windows;
|
||||
std::unordered_map<uint32_t, std::array<Hook, 6>> _events_hooks;
|
||||
SDL_Event _event;
|
||||
std::array<uint8_t, 8> _mouse;
|
||||
|
||||
int _x = 0;
|
||||
int _y = 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/27 16:57:28 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/09 16:52:29 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -31,8 +31,6 @@ namespace mlx
|
||||
|
||||
MLX_Window::MLX_Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h)
|
||||
{
|
||||
if(title.find("vvaas") != std::string::npos)
|
||||
core::error::report(e_kind::message, "vvaas est mauvais");
|
||||
_win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN);
|
||||
if(!_win)
|
||||
core::error::report(e_kind::fatal_error, std::string("unable to open a new window, ") + SDL_GetError());
|
||||
@ -43,6 +41,7 @@ namespace mlx
|
||||
|
||||
void MLX_Window::destroy() noexcept
|
||||
{
|
||||
std::cout << "prout" << std::endl;
|
||||
if(_win != nullptr)
|
||||
{
|
||||
SDL_DestroyWindow(_win);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/21 00:24:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/09 16:35:57 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 18:55:57 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 17:10:17 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 13:54:25 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -23,9 +23,9 @@ namespace mlx
|
||||
void Buffer::create(Buffer::kind type, VkDeviceSize size, VkBufferUsageFlags usage, const char* name, const void* data)
|
||||
{
|
||||
_usage = usage;
|
||||
if(type == Buffer::kind::constant || type == Buffer::kind::dynamic_device_local)
|
||||
if(type == Buffer::kind::constant)
|
||||
{
|
||||
if(data == nullptr && type == Buffer::kind::constant)
|
||||
if(data == nullptr)
|
||||
{
|
||||
core::error::report(e_kind::warning, "Vulkan : trying to create constant buffer without data (constant buffers cannot be modified after creation)");
|
||||
return;
|
||||
@ -45,7 +45,7 @@ namespace mlx
|
||||
mapMem(&mapped);
|
||||
std::memcpy(mapped, data, size);
|
||||
unmapMem();
|
||||
if(type == Buffer::kind::constant || type == Buffer::kind::dynamic_device_local)
|
||||
if(type == Buffer::kind::constant)
|
||||
pushToGPU();
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ namespace mlx
|
||||
_buffer = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
void Buffer::createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info, VkDeviceSize size, [[maybe_unused]] const char* name)
|
||||
void Buffer::createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info, VkDeviceSize size, const char* name)
|
||||
{
|
||||
VkBufferCreateInfo bufferInfo{};
|
||||
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
@ -74,7 +74,7 @@ namespace mlx
|
||||
alloc_name.append("_index_buffer");
|
||||
else if(usage & VK_BUFFER_USAGE_VERTEX_BUFFER_BIT)
|
||||
alloc_name.append("_vertex_buffer");
|
||||
else if(!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT))
|
||||
else if((usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 1)
|
||||
alloc_name.append("_buffer");
|
||||
_allocation = Render_Core::get().getAllocator().createBuffer(&bufferInfo, &info, _buffer, alloc_name.c_str());
|
||||
#else
|
||||
@ -83,33 +83,6 @@ namespace mlx
|
||||
_size = size;
|
||||
}
|
||||
|
||||
bool Buffer::copyFromBuffer(const Buffer& buffer) noexcept
|
||||
{
|
||||
if(!(_usage & VK_BUFFER_USAGE_TRANSFER_DST_BIT))
|
||||
{
|
||||
core::error::report(e_kind::error, "Vulkan : buffer cannot be the destination of a copy because it does not have the correct usage flag");
|
||||
return false;
|
||||
}
|
||||
if(!(buffer._usage & VK_BUFFER_USAGE_TRANSFER_SRC_BIT))
|
||||
{
|
||||
core::error::report(e_kind::error, "Vulkan : buffer cannot be the source of a copy because it does not have the correct usage flag");
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO, use global cmd buffer pool to manage resources
|
||||
CmdBuffer& cmd = Render_Core::get().getSingleTimeCmdBuffer();
|
||||
cmd.beginRecord();
|
||||
|
||||
VkBufferCopy copyRegion{};
|
||||
copyRegion.size = _size;
|
||||
vkCmdCopyBuffer(cmd.get(), buffer._buffer, _buffer, 1, ©Region);
|
||||
|
||||
cmd.endRecord();
|
||||
cmd.submitIdle();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Buffer::pushToGPU() noexcept
|
||||
{
|
||||
VmaAllocationCreateInfo alloc_info{};
|
||||
@ -124,8 +97,25 @@ namespace mlx
|
||||
newBuffer.createBuffer(newBuffer._usage, alloc_info, _size, nullptr);
|
||||
#endif
|
||||
|
||||
if(newBuffer.copyFromBuffer(*this)) // if the copy succeded we swap the buffers, else the new one is deleted
|
||||
CmdPool cmdpool;
|
||||
cmdpool.init();
|
||||
CmdBuffer cmdBuffer;
|
||||
cmdBuffer.init(&cmdpool);
|
||||
|
||||
cmdBuffer.beginRecord(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
||||
|
||||
VkBufferCopy copyRegion{};
|
||||
copyRegion.size = _size;
|
||||
vkCmdCopyBuffer(cmdBuffer.get(), _buffer, newBuffer._buffer, 1, ©Region);
|
||||
|
||||
cmdBuffer.endRecord();
|
||||
cmdBuffer.submitIdle();
|
||||
|
||||
cmdBuffer.destroy();
|
||||
cmdpool.destroy();
|
||||
|
||||
this->swap(newBuffer);
|
||||
|
||||
newBuffer.destroy();
|
||||
}
|
||||
|
||||
|
@ -6,23 +6,23 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 23:18:52 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:56 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:05:50 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_BUFFER__
|
||||
#define __MLX_VK_BUFFER__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
enum class kind { dynamic, dynamic_device_local, uniform, constant };
|
||||
enum class kind { dynamic, uniform, constant };
|
||||
|
||||
void create(kind type, VkDeviceSize size, VkBufferUsageFlags usage, const char* name, const void* data = nullptr);
|
||||
void destroy() noexcept;
|
||||
@ -32,7 +32,6 @@ namespace mlx
|
||||
inline void unmapMem() noexcept { Render_Core::get().getAllocator().unmapMemory(_allocation); _is_mapped = false; }
|
||||
|
||||
void flush(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0);
|
||||
bool copyFromBuffer(const Buffer& buffer) noexcept;
|
||||
|
||||
inline VkBuffer& operator()() noexcept { return _buffer; }
|
||||
inline VkBuffer& get() noexcept { return _buffer; }
|
||||
|
@ -6,17 +6,17 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/25 15:05:05 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:27:02 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:06:07 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __VK_IBO__
|
||||
#define __VK_IBO__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include "vk_buffer.h"
|
||||
#include <renderer/renderer.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:45:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/10 22:22:28 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/11/16 13:57:42 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void UBO::create(Renderer* renderer, uint32_t size, [[maybe_unused]] const char* name)
|
||||
void UBO::create(Renderer* renderer, uint32_t size, const char* name)
|
||||
{
|
||||
_renderer = renderer;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "vk_buffer.h"
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:28:08 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/12 22:17:14 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/11/10 08:33:52 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,10 +18,7 @@ namespace mlx
|
||||
void VBO::setData(uint32_t size, const void* data)
|
||||
{
|
||||
if(size > getSize())
|
||||
{
|
||||
core::error::report(e_kind::error, "Vulkan : trying to store to much data in a vertex buffer (%d bytes in %d bytes)", size, getSize());
|
||||
return;
|
||||
}
|
||||
|
||||
if(data == nullptr)
|
||||
core::error::report(e_kind::warning, "Vulkan : mapping null data in a vertex buffer");
|
||||
@ -31,25 +28,4 @@ namespace mlx
|
||||
std::memcpy(temp, data, static_cast<size_t>(size));
|
||||
unmapMem();
|
||||
}
|
||||
|
||||
void D_VBO::setData(uint32_t size, const void* data)
|
||||
{
|
||||
if(size > getSize())
|
||||
{
|
||||
core::error::report(e_kind::error, "Vulkan : trying to store to much data in a vertex buffer (%d bytes in %d bytes)", size, getSize());
|
||||
return;
|
||||
}
|
||||
|
||||
if(data == nullptr)
|
||||
core::error::report(e_kind::warning, "Vulkan : mapping null data in a vertex buffer");
|
||||
|
||||
Buffer tmp_buf;
|
||||
#ifdef DEBUG
|
||||
tmp_buf.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, "tmp_buffer", data);
|
||||
#else
|
||||
tmp_buf.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, nullptr, data);
|
||||
#endif
|
||||
copyFromBuffer(tmp_buf);
|
||||
tmp_buf.destroy();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:27:38 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/12 22:46:21 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:06:45 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,22 +15,14 @@
|
||||
|
||||
#include "vk_buffer.h"
|
||||
#include <renderer/renderer.h>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class VBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
void setData(uint32_t size, const void* data);
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
|
||||
};
|
||||
|
||||
class D_VBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::dynamic_device_local, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
inline void create(uint32_t size, const char* name) { Buffer::create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name); }
|
||||
void setData(uint32_t size, const void* data);
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 17:48:52 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:27:35 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:07:00 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,8 +15,8 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <core/profile.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <renderer/command/vk_cmd_pool.h>
|
||||
#include <renderer/command/vk_cmd_buffer.h>
|
||||
|
@ -1,53 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* single_time_cmd_manager.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/15 19:57:49 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 18:46:26 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <algorithm>
|
||||
#include <renderer/command/single_time_cmd_manager.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
SingleTimeCmdManager::SingleTimeCmdManager() : _buffers(MIN_POOL_SIZE) {}
|
||||
|
||||
void SingleTimeCmdManager::init() noexcept
|
||||
{
|
||||
_pool.init();
|
||||
for(int i = 0; i < MIN_POOL_SIZE; i++)
|
||||
{
|
||||
_buffers.emplace_back();
|
||||
_buffers.back().init(&_pool);
|
||||
}
|
||||
}
|
||||
|
||||
CmdBuffer& SingleTimeCmdManager::getCmdBuffer() noexcept
|
||||
{
|
||||
for(CmdBuffer& buf : _buffers)
|
||||
{
|
||||
if(buf.isReadyToBeUsed())
|
||||
{
|
||||
buf.reset();
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
_buffers.emplace_back().init(&_pool);
|
||||
return _buffers.back();
|
||||
}
|
||||
|
||||
void SingleTimeCmdManager::destroy() noexcept
|
||||
{
|
||||
std::for_each(_buffers.begin(), _buffers.end(), [](CmdBuffer& buf)
|
||||
{
|
||||
buf.destroy();
|
||||
});
|
||||
_pool.destroy();
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* single_time_cmd_manager.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/15 18:25:57 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 18:09:56 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_SINGLE_TIME_CMD_MANAGER__
|
||||
#define __MLX_SINGLE_TIME_CMD_MANAGER__
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <renderer/command/vk_cmd_pool.h>
|
||||
#include <renderer/command/vk_cmd_buffer.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class SingleTimeCmdManager
|
||||
{
|
||||
public:
|
||||
SingleTimeCmdManager();
|
||||
|
||||
void init() noexcept;
|
||||
void destroy() noexcept;
|
||||
|
||||
inline CmdPool& getCmdPool() noexcept { return _pool; }
|
||||
CmdBuffer& getCmdBuffer() noexcept;
|
||||
|
||||
~SingleTimeCmdManager() = default;
|
||||
|
||||
inline static constexpr const uint8_t MIN_POOL_SIZE = 8;
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
std::vector<CmdBuffer> _buffers;
|
||||
CmdPool _pool;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 13:12:58 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/08 20:17:49 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -32,22 +32,18 @@ namespace mlx
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandBufferCount = 1;
|
||||
|
||||
VkResult res = vkAllocateCommandBuffers(Render_Core::get().getDevice().get(), &allocInfo, &_cmd_buffer);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate command buffer, %s", RCore::verbaliseResultVk(res));
|
||||
if(vkAllocateCommandBuffers(Render_Core::get().getDevice().get(), &allocInfo, &_cmd_buffer) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate command buffer");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new command buffer");
|
||||
#endif
|
||||
|
||||
_fence.init();
|
||||
_state = state::idle;
|
||||
}
|
||||
|
||||
void CmdBuffer::beginRecord(VkCommandBufferUsageFlags usage)
|
||||
{
|
||||
if(!isInit())
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : begenning record on un uninit command buffer");
|
||||
if(_state == state::recording)
|
||||
if(_is_recording)
|
||||
return;
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo{};
|
||||
@ -56,19 +52,17 @@ namespace mlx
|
||||
if(vkBeginCommandBuffer(_cmd_buffer, &beginInfo) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to begin recording command buffer");
|
||||
|
||||
_state = state::recording;
|
||||
_is_recording = true;
|
||||
}
|
||||
|
||||
void CmdBuffer::endRecord()
|
||||
{
|
||||
if(!isInit())
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : ending record on un uninit command buffer");
|
||||
if(_state != state::recording)
|
||||
if(!_is_recording)
|
||||
return;
|
||||
if(vkEndCommandBuffer(_cmd_buffer) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to end recording command buffer");
|
||||
|
||||
_state = state::idle;
|
||||
_is_recording = false;
|
||||
}
|
||||
|
||||
void CmdBuffer::submitIdle() noexcept
|
||||
@ -86,52 +80,34 @@ namespace mlx
|
||||
VkFence fence;
|
||||
vkCreateFence(device, &fenceCreateInfo, nullptr, &fence);
|
||||
vkResetFences(device, 1, &fence);
|
||||
VkResult res = vkQueueSubmit(Render_Core::get().getQueue().getGraphic(), 1, &submitInfo, fence);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to submit a single time command buffer, %s", RCore::verbaliseResultVk(res));
|
||||
_state = state::submitted;
|
||||
vkQueueSubmit(Render_Core::get().getQueue().getGraphic(), 1, &submitInfo, fence);
|
||||
vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX);
|
||||
vkDestroyFence(device, fence, nullptr);
|
||||
_state = state::ready;
|
||||
}
|
||||
|
||||
void CmdBuffer::submit(Semaphore* semaphores) noexcept
|
||||
void CmdBuffer::submit(Semaphore& semaphores) noexcept
|
||||
{
|
||||
std::array<VkSemaphore, 1> signalSemaphores;
|
||||
std::array<VkSemaphore, 1> waitSemaphores;
|
||||
|
||||
if(semaphores != nullptr)
|
||||
{
|
||||
signalSemaphores[0] = semaphores->getRenderImageSemaphore();
|
||||
waitSemaphores[0] = semaphores->getImageSemaphore();
|
||||
}
|
||||
else
|
||||
{
|
||||
signalSemaphores[0] = nullptr;
|
||||
waitSemaphores[0] = nullptr;
|
||||
}
|
||||
VkSemaphore signalSemaphores[] = { semaphores.getRenderImageSemaphore() };
|
||||
VkSemaphore waitSemaphores[] = { semaphores.getImageSemaphore() };
|
||||
VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
|
||||
|
||||
VkSubmitInfo submitInfo{};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.waitSemaphoreCount = (semaphores == nullptr ? 0 : waitSemaphores.size());
|
||||
submitInfo.pWaitSemaphores = waitSemaphores.data();
|
||||
submitInfo.waitSemaphoreCount = 1;
|
||||
submitInfo.pWaitSemaphores = waitSemaphores;
|
||||
submitInfo.pWaitDstStageMask = waitStages;
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &_cmd_buffer;
|
||||
submitInfo.signalSemaphoreCount = (semaphores == nullptr ? 0 : signalSemaphores.size());
|
||||
submitInfo.pSignalSemaphores = signalSemaphores.data();
|
||||
submitInfo.signalSemaphoreCount = 1;
|
||||
submitInfo.pSignalSemaphores = signalSemaphores;
|
||||
|
||||
VkResult res = vkQueueSubmit(Render_Core::get().getQueue().getGraphic(), 1, &submitInfo, _fence.get());
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to submit draw command buffer, %s", RCore::verbaliseResultVk(res));
|
||||
_state = state::submitted;
|
||||
if(vkQueueSubmit(Render_Core::get().getQueue().getGraphic(), 1, &submitInfo, _fence.get()) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to submit draw command buffer");
|
||||
}
|
||||
|
||||
void CmdBuffer::destroy() noexcept
|
||||
{
|
||||
_fence.destroy();
|
||||
_cmd_buffer = VK_NULL_HANDLE;
|
||||
_state = state::uninit;
|
||||
}
|
||||
}
|
||||
|
@ -6,48 +6,35 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:27:20 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:07:11 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_CMD_BUFFER__
|
||||
#define __MLX_VK_CMD_BUFFER__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <renderer/core/vk_fence.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class CmdBuffer
|
||||
{
|
||||
public:
|
||||
enum class state
|
||||
{
|
||||
uninit = 0, // buffer not initialized or destroyed
|
||||
ready, // buffer ready to be used after having been submitted
|
||||
idle, // buffer has recorded informations but has not been submitted
|
||||
recording, // buffer is currently recording
|
||||
submitted, // buffer has been submitted
|
||||
};
|
||||
|
||||
public:
|
||||
void init(class CmdManager* manager);
|
||||
void init(class CmdPool* pool);
|
||||
void destroy() noexcept;
|
||||
|
||||
void beginRecord(VkCommandBufferUsageFlags usage = 0);
|
||||
void submit(class Semaphore* semaphores) noexcept;
|
||||
void submit(class Semaphore& semaphores) noexcept;
|
||||
void submitIdle() noexcept;
|
||||
inline void waitForExecution() noexcept { _fence.waitAndReset(); _state = state::ready; }
|
||||
inline void waitForExecution() noexcept { _fence.waitAndReset(); }
|
||||
inline void reset() noexcept { vkResetCommandBuffer(_cmd_buffer, 0); }
|
||||
void endRecord();
|
||||
|
||||
inline bool isInit() const noexcept { return _state != state::uninit; }
|
||||
inline bool isReadyToBeUsed() const noexcept { return _state == state::ready; }
|
||||
inline bool isRecording() const noexcept { return _state == state::recording; }
|
||||
inline bool hasBeenSubmitted() const noexcept { return _state == state::submitted; }
|
||||
inline state getCurrentState() const noexcept { return _state; }
|
||||
inline bool isRecording() const noexcept { return _is_recording; }
|
||||
inline bool isInit() const noexcept { return _cmd_buffer != VK_NULL_HANDLE; }
|
||||
|
||||
inline VkCommandBuffer& operator()() noexcept { return _cmd_buffer; }
|
||||
inline VkCommandBuffer& get() noexcept { return _cmd_buffer; }
|
||||
@ -57,7 +44,7 @@ namespace mlx
|
||||
Fence _fence;
|
||||
VkCommandBuffer _cmd_buffer = VK_NULL_HANDLE;
|
||||
class CmdPool* _pool = nullptr;
|
||||
state _state = state::uninit;
|
||||
bool _is_recording = false;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:24:33 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 13:13:25 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:23:38 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,9 +22,8 @@ namespace mlx
|
||||
poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
||||
poolInfo.queueFamilyIndex = Render_Core::get().getQueue().getFamilies().graphicsFamily.value();
|
||||
|
||||
VkResult res = vkCreateCommandPool(Render_Core::get().getDevice().get(), &poolInfo, nullptr, &_cmd_pool);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create command pool, %s", RCore::verbaliseResultVk(res));
|
||||
if(vkCreateCommandPool(Render_Core::get().getDevice().get(), &poolInfo, nullptr, &_cmd_pool) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create command pool");
|
||||
}
|
||||
|
||||
void CmdPool::destroy() noexcept
|
||||
|
@ -6,15 +6,15 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:24:12 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:27:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:07:22 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_CMD_POOL__
|
||||
#define __MLX_VK_CMD_POOL__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -6,34 +6,25 @@
|
||||
/* By: kbz_8 <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
|
||||
/* Updated: 2024/01/03 13:09:40 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 12:45:29 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <core/profile.h>
|
||||
#include <core/errors.h>
|
||||
#include <cstdio>
|
||||
|
||||
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_VULKAN_VERSION 1002000
|
||||
#define VMA_ASSERT(expr) ((void)0)
|
||||
#define VMA_ASSERT(expr) (static_cast<bool>(expr) ? void(0) : mlx::core::error::report(e_kind::fatal_error, "Graphics allocator : an assertion has been catched : '%s'", #expr))
|
||||
#define VMA_IMPLEMENTATION
|
||||
|
||||
#ifdef MLX_COMPILER_CLANG
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Weverything"
|
||||
#pragma clang diagnostic ignored "-Wnullability-completeness"
|
||||
#include <renderer/core/memory.h>
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined(MLX_COMPILER_GCC)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wparentheses"
|
||||
#include <renderer/core/memory.h>
|
||||
#pragma GCC diagnostic pop
|
||||
#else
|
||||
#include <renderer/core/memory.h>
|
||||
#endif
|
||||
@ -76,26 +67,23 @@ namespace mlx
|
||||
allocatorCreateInfo.instance = Render_Core::get().getInstance().get();
|
||||
allocatorCreateInfo.pVulkanFunctions = &vma_vulkan_func;
|
||||
|
||||
VkResult res = vmaCreateAllocator(&allocatorCreateInfo, &_allocator);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : failed to create graphics memory allocator, %s", RCore::verbaliseResultVk(res));
|
||||
if(vmaCreateAllocator(&allocatorCreateInfo, &_allocator) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create graphics memory allocator");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics allocator : created new allocator");
|
||||
core::error::report(e_kind::message, "Vulkan : created new allocator");
|
||||
#endif
|
||||
}
|
||||
|
||||
VmaAllocation GPUallocator::createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name) noexcept
|
||||
{
|
||||
VmaAllocation allocation;
|
||||
VkResult res = vmaCreateBuffer(_allocator, binfo, vinfo, &buffer, &allocation, nullptr);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : failed to allocate a buffer, %s", RCore::verbaliseResultVk(res));
|
||||
if(vmaCreateBuffer(_allocator, binfo, vinfo, &buffer, &allocation, nullptr) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate a buffer");
|
||||
if(name != nullptr)
|
||||
vmaSetAllocationName(_allocator, allocation, name);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : created new buffer");
|
||||
#endif
|
||||
_active_buffers_allocations++;
|
||||
return allocation;
|
||||
}
|
||||
|
||||
@ -106,21 +94,18 @@ namespace mlx
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : destroyed buffer");
|
||||
#endif
|
||||
_active_buffers_allocations--;
|
||||
}
|
||||
|
||||
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name) noexcept
|
||||
{
|
||||
VmaAllocation allocation;
|
||||
VkResult res = vmaCreateImage(_allocator, iminfo, vinfo, &image, &allocation, nullptr);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : failed to allocate an image, %s", RCore::verbaliseResultVk(res));
|
||||
if(vmaCreateImage(_allocator, iminfo, vinfo, &image, &allocation, nullptr) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate an image");
|
||||
if(name != nullptr)
|
||||
vmaSetAllocationName(_allocator, allocation, name);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : created new image");
|
||||
#endif
|
||||
_active_images_allocations++;
|
||||
return allocation;
|
||||
}
|
||||
|
||||
@ -131,14 +116,12 @@ namespace mlx
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : destroyed image");
|
||||
#endif
|
||||
_active_images_allocations--;
|
||||
}
|
||||
|
||||
void GPUallocator::mapMemory(VmaAllocation allocation, void** data) noexcept
|
||||
{
|
||||
VkResult res = vmaMapMemory(_allocator, allocation, data);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : unable to map GPU memory to CPU memory, %s", RCore::verbaliseResultVk(res));
|
||||
if(vmaMapMemory(_allocator, allocation, data) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : unable to map GPU memory to CPU memory");
|
||||
}
|
||||
|
||||
void GPUallocator::unmapMemory(VmaAllocation allocation) noexcept
|
||||
@ -172,12 +155,6 @@ namespace mlx
|
||||
|
||||
void GPUallocator::destroy() noexcept
|
||||
{
|
||||
if(_active_images_allocations != 0)
|
||||
core::error::report(e_kind::error, "Graphics allocator : some user-dependant allocations were not freed before destroying the display (%d active allocations)", _active_images_allocations);
|
||||
else if(_active_buffers_allocations != 0)
|
||||
core::error::report(e_kind::error, "Graphics allocator : some MLX-dependant allocations were not freed before destroying the display (%d active allocations), please report, this should not happen", _active_buffers_allocations);
|
||||
vmaDestroyAllocator(_allocator);
|
||||
_active_buffers_allocations = 0;
|
||||
_active_images_allocations = 0;
|
||||
}
|
||||
}
|
||||
|
@ -6,16 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/20 02:13:03 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:25:56 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:07:34 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_MEMORY__
|
||||
#define __MLX_VK_MEMORY__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <vma.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@ -44,8 +44,6 @@ namespace mlx
|
||||
|
||||
private:
|
||||
VmaAllocator _allocator;
|
||||
uint32_t _active_buffers_allocations = 0;
|
||||
uint32_t _active_images_allocations = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,21 +6,28 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:22:38 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/20 12:04:51 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#define VOLK_IMPLEMENTATION
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define VK_USE_PLATFORM_WIN32_KHR
|
||||
#elif defined(__APPLE__) || defined(__MACH__)
|
||||
#define VK_USE_PLATFORM_MACOS_MVK
|
||||
#else
|
||||
#define VK_USE_PLATFORM_XLIB_KHR
|
||||
#endif
|
||||
|
||||
#include "render_core.h"
|
||||
#include <mutex>
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef MLX_COMPILER_MSVC
|
||||
#pragma NOTE("MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances")
|
||||
#else
|
||||
#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
|
||||
|
||||
@ -42,45 +49,11 @@ namespace mlx
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to find suitable memory type");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const char* verbaliseResultVk(VkResult result)
|
||||
{
|
||||
switch(result)
|
||||
{
|
||||
case VK_SUCCESS: return "Success";
|
||||
case VK_NOT_READY: return "A fence or query has not yet completed";
|
||||
case VK_TIMEOUT: return "A wait operation has not completed in the specified time";
|
||||
case VK_EVENT_SET: return "An event is signaled";
|
||||
case VK_EVENT_RESET: return "An event is unsignaled";
|
||||
case VK_INCOMPLETE: return "A return array was too small for the result";
|
||||
case VK_ERROR_OUT_OF_HOST_MEMORY: return "A host memory allocation has failed";
|
||||
case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "A device memory allocation has failed";
|
||||
case VK_ERROR_INITIALIZATION_FAILED: return "Initialization of an object could not be completed for implementation-specific reasons";
|
||||
case VK_ERROR_DEVICE_LOST: return "The logical or physical device has been lost";
|
||||
case VK_ERROR_MEMORY_MAP_FAILED: return "Mapping of a memory object has failed";
|
||||
case VK_ERROR_LAYER_NOT_PRESENT: return "A requested layer is not present or could not be loaded";
|
||||
case VK_ERROR_EXTENSION_NOT_PRESENT: return "A requested extension is not supported";
|
||||
case VK_ERROR_FEATURE_NOT_PRESENT: return "A requested feature is not supported";
|
||||
case VK_ERROR_INCOMPATIBLE_DRIVER: return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible";
|
||||
case VK_ERROR_TOO_MANY_OBJECTS: return "Too many objects of the type have already been created";
|
||||
case VK_ERROR_FORMAT_NOT_SUPPORTED: return "A requested format is not supported on this device";
|
||||
case VK_ERROR_SURFACE_LOST_KHR: return "A surface is no longer available";
|
||||
case VK_SUBOPTIMAL_KHR: return "A swapchain no longer matches the surface properties exactly, but can still be used";
|
||||
case VK_ERROR_OUT_OF_DATE_KHR: return "A surface has changed in such a way that it is no longer compatible with the swapchain";
|
||||
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: return "The display used by a swapchain does not use the same presentable image layout";
|
||||
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API";
|
||||
case VK_ERROR_VALIDATION_FAILED_EXT: return "A validation layer found an error";
|
||||
|
||||
default: return "Unknown Vulkan error";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Render_Core::init()
|
||||
{
|
||||
if(volkInitialize() != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan loader : cannot load %s, are you sure Vulkan is installed on your system ?", VULKAN_LIB_NAME);
|
||||
volkInitialize();
|
||||
|
||||
_instance.init();
|
||||
volkLoadInstance(_instance.get());
|
||||
@ -89,7 +62,6 @@ namespace mlx
|
||||
volkLoadDevice(_device.get());
|
||||
_queues.init();
|
||||
_allocator.init();
|
||||
_cmd_manager.init();
|
||||
_is_init = true;
|
||||
}
|
||||
|
||||
@ -100,7 +72,6 @@ namespace mlx
|
||||
|
||||
vkDeviceWaitIdle(_device());
|
||||
|
||||
_cmd_manager.destroy();
|
||||
_allocator.destroy();
|
||||
_device.destroy();
|
||||
_layers.destroy();
|
||||
|
@ -6,18 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:08 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 18:53:36 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_RENDER_CORE__
|
||||
#define __MLX_RENDER_CORE__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <optional>
|
||||
|
||||
#include <renderer/command/single_time_cmd_manager.h>
|
||||
#include "vk_queues.h"
|
||||
#include "vk_device.h"
|
||||
#include "vk_instance.h"
|
||||
@ -26,13 +24,13 @@
|
||||
|
||||
#include <utils/singleton.h>
|
||||
#include <core/errors.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
namespace RCore
|
||||
{
|
||||
std::optional<uint32_t> findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties, bool error = true);
|
||||
const char* verbaliseResultVk(VkResult result);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -58,13 +56,11 @@ namespace mlx
|
||||
inline Queues& getQueue() noexcept { return _queues; }
|
||||
inline GPUallocator& getAllocator() noexcept { return _allocator; }
|
||||
inline ValidationLayers& getLayers() noexcept { return _layers; }
|
||||
inline CmdBuffer& getSingleTimeCmdBuffer() noexcept { return _cmd_manager.getCmdBuffer(); }
|
||||
|
||||
~Render_Core() = default;
|
||||
|
||||
private:
|
||||
ValidationLayers _layers;
|
||||
SingleTimeCmdManager _cmd_manager;
|
||||
Queues _queues;
|
||||
Device _device;
|
||||
Instance _instance;
|
||||
|
@ -6,12 +6,11 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/30 23:29:41 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:22:02 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "render_core.h"
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <SDL2/SDL.h>
|
||||
@ -57,9 +56,8 @@ namespace mlx
|
||||
createInfo.ppEnabledExtensionNames = deviceExtensions.data();
|
||||
createInfo.enabledLayerCount = 0;
|
||||
|
||||
VkResult res;
|
||||
if((res = vkCreateDevice(_physicalDevice, &createInfo, nullptr, &_device)) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create logcal device, %s", RCore::verbaliseResultVk(res));
|
||||
if(vkCreateDevice(_physicalDevice, &createInfo, nullptr, &_device) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create logcal device");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new logical device");
|
||||
#endif
|
||||
@ -86,10 +84,8 @@ namespace mlx
|
||||
|
||||
std::vector<std::pair<int, VkPhysicalDevice>> devices_score;
|
||||
|
||||
std::transform(devices.cbegin(), devices.cend(), std::back_inserter(devices_score), [&](VkPhysicalDevice device)
|
||||
{
|
||||
return std::make_pair(deviceScore(device, surface), device);
|
||||
});
|
||||
for(const auto& device : devices)
|
||||
devices_score.emplace_back(deviceScore(device, surface), device);
|
||||
|
||||
vkDestroySurfaceKHR(Render_Core::get().getInstance().get(), surface, nullptr);
|
||||
SDL_DestroyWindow(window);
|
||||
|
@ -6,16 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:13:42 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:14 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:07:49 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_DEVICE__
|
||||
#define __MLX_VK_DEVICE__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include "vk_queues.h"
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -6,24 +6,25 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 17:53:06 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 18:47:36 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:07:21 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <renderer/core/vk_fence.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Fence::init()
|
||||
{
|
||||
VkSemaphoreCreateInfo semaphoreInfo{};
|
||||
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||
|
||||
VkFenceCreateInfo fenceInfo{};
|
||||
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
|
||||
|
||||
VkResult res;
|
||||
if((res = vkCreateFence(Render_Core::get().getDevice().get(), &fenceInfo, nullptr, &_fence)) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a synchronization object (fence), %s", RCore::verbaliseResultVk(res));
|
||||
if(vkCreateFence(Render_Core::get().getDevice().get(), &fenceInfo, nullptr, &_fence) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create CPU synchronization object");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new fence");
|
||||
#endif
|
||||
@ -39,11 +40,6 @@ namespace mlx
|
||||
vkResetFences(Render_Core::get().getDevice().get(), 1, &_fence);
|
||||
}
|
||||
|
||||
bool Fence::isReady() const noexcept
|
||||
{
|
||||
return vkGetFenceStatus(Render_Core::get().getDevice().get(), _fence) == VK_SUCCESS;
|
||||
}
|
||||
|
||||
void Fence::destroy() noexcept
|
||||
{
|
||||
if(_fence != VK_NULL_HANDLE)
|
||||
|
@ -6,15 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 17:52:09 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:21 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:08:01 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_FENCE__
|
||||
#define __MLX_VK_FENCE__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <core/profile.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@ -28,7 +29,6 @@ namespace mlx
|
||||
inline VkFence& get() noexcept { return _fence; }
|
||||
void wait() noexcept;
|
||||
void reset() noexcept;
|
||||
bool isReady() const noexcept;
|
||||
inline void waitAndReset() noexcept { wait(); reset(); }
|
||||
|
||||
void destroy() noexcept;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:04:21 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/31 00:40:10 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:21:42 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -21,19 +21,19 @@ namespace mlx
|
||||
{
|
||||
VkApplicationInfo appInfo{};
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pApplicationName = "MacroLibX";
|
||||
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.pEngineName = "MacroLibX";
|
||||
appInfo.engineVersion = VK_MAKE_VERSION(1, 2, 1);
|
||||
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.apiVersion = VK_API_VERSION_1_2;
|
||||
|
||||
auto extensions = getRequiredExtensions();
|
||||
|
||||
VkInstanceCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
createInfo.pApplicationInfo = &appInfo;
|
||||
|
||||
auto extensions = getRequiredExtensions();
|
||||
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
|
||||
createInfo.ppEnabledExtensionNames = extensions.data();
|
||||
createInfo.enabledLayerCount = 0; // will be replaced if validation layers are enabled
|
||||
createInfo.pNext = nullptr;
|
||||
|
||||
VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo;
|
||||
if constexpr(enableValidationLayers)
|
||||
@ -43,13 +43,18 @@ namespace mlx
|
||||
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
|
||||
createInfo.ppEnabledLayerNames = validationLayers.data();
|
||||
Render_Core::get().getLayers().populateDebugMessengerCreateInfo(debugCreateInfo);
|
||||
createInfo.pNext = static_cast<VkDebugUtilsMessengerCreateInfoEXT*>(&debugCreateInfo);
|
||||
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
createInfo.enabledLayerCount = 0;
|
||||
createInfo.pNext = nullptr;
|
||||
}
|
||||
|
||||
VkResult res;
|
||||
if((res = vkCreateInstance(&createInfo, nullptr, &_instance)) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create Vulkan instance, %s", RCore::verbaliseResultVk(res));
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create Vulkan instance");
|
||||
volkLoadInstance(_instance);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new instance");
|
||||
|
@ -6,16 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:03:04 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:08:14 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_INSTANCE__
|
||||
#define __MLX_VK_INSTANCE__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <vector>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -6,17 +6,17 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:01:49 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:31 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:08:25 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_QUEUES__
|
||||
#define __MLX_VK_QUEUES__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <optional>
|
||||
#include <cstdint>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:01:08 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/16 18:47:29 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:22:29 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -21,10 +21,9 @@ namespace mlx
|
||||
VkSemaphoreCreateInfo semaphoreInfo{};
|
||||
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||
|
||||
VkResult res;
|
||||
if( (res = vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_imageAvailableSemaphores)) != VK_SUCCESS ||
|
||||
(res = vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_renderFinishedSemaphores)) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a synchronization object (semaphore), %s", RCore::verbaliseResultVk(res));
|
||||
if( vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_imageAvailableSemaphores) != VK_SUCCESS ||
|
||||
vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_renderFinishedSemaphores) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create GPU synchronization object");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new semaphore");
|
||||
#endif
|
||||
|
@ -6,16 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 18:59:38 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:39 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:08:36 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_SEMAPHORE__
|
||||
#define __MLX_VK_SEMAPHORE__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <vector>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 18:58:49 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/30 23:14:54 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:22:38 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
#include <renderer/renderer.h>
|
||||
#include <SDL2/SDL_vulkan.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@ -30,12 +29,13 @@ namespace mlx
|
||||
|
||||
VkSurfaceFormatKHR Surface::chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats)
|
||||
{
|
||||
auto it = std::find_if(availableFormats.begin(), availableFormats.end(), [](VkSurfaceFormatKHR format)
|
||||
for(const auto& availableFormat : availableFormats)
|
||||
{
|
||||
return format.format == VK_FORMAT_R8G8B8A8_SRGB && format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||
});
|
||||
if(availableFormat.format == VK_FORMAT_R8G8B8A8_SRGB && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
||||
return availableFormat;
|
||||
}
|
||||
|
||||
return (it == availableFormats.end() ? availableFormats[0] : *it);
|
||||
return availableFormats[0];
|
||||
}
|
||||
|
||||
void Surface::destroy() noexcept
|
||||
|
@ -6,16 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 18:57:55 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:43 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:08:49 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_SURFACE__
|
||||
#define __MLX_VK_SURFACE__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <vector>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* vk_validation_layers.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/19 14:05:25 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 13:11:27 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/20 07:21:57 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
#include <core/errors.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@ -25,11 +24,10 @@ namespace mlx
|
||||
if constexpr(!enableValidationLayers)
|
||||
return;
|
||||
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo{};
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo;
|
||||
populateDebugMessengerCreateInfo(createInfo);
|
||||
VkResult res = createDebugUtilsMessengerEXT(&createInfo, nullptr);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::warning, "Vulkan : failed to set up debug messenger, %s", RCore::verbaliseResultVk(res));
|
||||
if(createDebugUtilsMessengerEXT(&createInfo, nullptr) != VK_SUCCESS)
|
||||
core::error::report(e_kind::error, "Vulkan : failed to set up debug messenger");
|
||||
#ifdef DEBUG
|
||||
else
|
||||
core::error::report(e_kind::message, "Vulkan : enabled validation layers");
|
||||
@ -44,15 +42,36 @@ namespace mlx
|
||||
std::vector<VkLayerProperties> availableLayers(layerCount);
|
||||
vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
|
||||
|
||||
return std::all_of(validationLayers.begin(), validationLayers.end(), [&](const char* layerName)
|
||||
for(const char* layerName : validationLayers)
|
||||
{
|
||||
if(!std::any_of(availableLayers.begin(), availableLayers.end(), [=](VkLayerProperties props) { return std::strcmp(layerName, props.layerName) == 0; }))
|
||||
bool layerFound = false;
|
||||
|
||||
for(const auto& layerProperties : availableLayers)
|
||||
{
|
||||
core::error::report(e_kind::error, "Vulkan : a validation layer was requested but was not found ('%s')", layerName);
|
||||
if(std::strcmp(layerName, layerProperties.layerName) == 0)
|
||||
{
|
||||
layerFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!layerFound)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void ValidationLayers::destroy()
|
||||
{
|
||||
if constexpr(!enableValidationLayers)
|
||||
return;
|
||||
destroyDebugUtilsMessengerEXT(nullptr);
|
||||
}
|
||||
|
||||
VkResult ValidationLayers::createDebugUtilsMessengerEXT(const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator)
|
||||
{
|
||||
auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(Render_Core::get().getInstance().get(), "vkCreateDebugUtilsMessengerEXT");
|
||||
return func != nullptr ? func(Render_Core::get().getInstance().get(), pCreateInfo, pAllocator, &_debugMessenger) : VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||
}
|
||||
|
||||
void ValidationLayers::populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo)
|
||||
@ -64,20 +83,7 @@ namespace mlx
|
||||
createInfo.pfnUserCallback = ValidationLayers::debugCallback;
|
||||
}
|
||||
|
||||
|
||||
void ValidationLayers::destroy()
|
||||
{
|
||||
if constexpr(enableValidationLayers)
|
||||
destroyDebugUtilsMessengerEXT(nullptr);
|
||||
}
|
||||
|
||||
VkResult ValidationLayers::createDebugUtilsMessengerEXT(const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator)
|
||||
{
|
||||
auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(Render_Core::get().getInstance().get(), "vkCreateDebugUtilsMessengerEXT");
|
||||
return func != nullptr ? func(Render_Core::get().getInstance().get(), pCreateInfo, pAllocator, &_debugMessenger) : VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL ValidationLayers::debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, [[maybe_unused]] VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, [[maybe_unused]] void* pUserData)
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL ValidationLayers::debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData)
|
||||
{
|
||||
if(messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
|
||||
{
|
||||
|
@ -6,34 +6,31 @@
|
||||
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/19 14:04:25 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:26:49 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:09:02 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __VK_VALIDATION_LAYERS__
|
||||
#define __VK_VALIDATION_LAYERS__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class ValidationLayers
|
||||
{
|
||||
public:
|
||||
ValidationLayers() = default;
|
||||
void init();
|
||||
void destroy();
|
||||
bool checkValidationLayerSupport();
|
||||
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
|
||||
void destroy();
|
||||
~ValidationLayers() = default;
|
||||
|
||||
private:
|
||||
VkResult createDebugUtilsMessengerEXT(const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator);
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData);
|
||||
void destroyDebugUtilsMessengerEXT(const VkAllocationCallbacks* pAllocator);
|
||||
|
||||
private:
|
||||
VkDebugUtilsMessengerEXT _debugMessenger;
|
||||
};
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/23 18:34:23 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 13:13:54 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:23:05 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -23,9 +23,8 @@ namespace mlx
|
||||
poolInfo.pPoolSizes = size;
|
||||
poolInfo.maxSets = 8192;
|
||||
|
||||
VkResult res = vkCreateDescriptorPool(Render_Core::get().getDevice().get(), &poolInfo, nullptr, &_pool);
|
||||
if(res != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create descriptor pool, %s", RCore::verbaliseResultVk(res));
|
||||
if(vkCreateDescriptorPool(Render_Core::get().getDevice().get(), &poolInfo, nullptr, &_pool) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create descriptor pool");
|
||||
}
|
||||
|
||||
void DescriptorPool::destroy() noexcept
|
||||
|
@ -6,16 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/23 18:32:43 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/03 15:27:45 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/08 19:09:20 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __VK_DESCRIPTOR_POOL__
|
||||
#define __VK_DESCRIPTOR_POOL__
|
||||
|
||||
#include <mlx_profile.h>
|
||||
#include <volk.h>
|
||||
#include <cstddef>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user