Skip to content

Commit

Permalink
merge indev into master (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 authored Sep 13, 2024
2 parents 33d2b98 + ffe5704 commit 3dd68f9
Show file tree
Hide file tree
Showing 27 changed files with 40,518 additions and 35,092 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# Build the lib
- name: Build MacroLibX
run: make -j && make fclean && make -j DEBUG=true
run: make -j && make fclean && make debug

# Build the example
- name: Build Example
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux_gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# Build the lib
- name: Build MacroLibX
run: make TOOLCHAIN=gcc -j && make fclean && make TOOLCHAIN=gcc DEBUG=true -j
run: make TOOLCHAIN=gcc -j && make fclean && make TOOLCHAIN=gcc debug

# Build the example
- name: Build Example
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# Build the lib
- name: Build MacroLibX
run: make -j && make fclean && make DEBUG=true -j
run: make -j && make fclean && make debug

# Build the example
- name: Build Example
Expand Down
128 changes: 79 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,129 @@
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: maldavid <[email protected]> +#+ +:+ +#+ #
# By: kiroussa <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
# Updated: 2024/01/10 14:20:30 by maldavid ### ########.fr #
# Updated: 2024/04/24 14:59:23 by kiroussa ### ########.fr #
# #
# **************************************************************************** #

NAME = libmlx.so
NAME = libmlx.so
MAKE = make --no-print-directory

SRCS = $(wildcard $(addsuffix /*.cpp, ./src/core))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/platform))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer/**))
OS ?= $(shell uname -s)
DEBUG ?= false
TOOLCHAIN ?= clang
IMAGES_OPTIMIZED ?= true
FORCE_INTEGRATED_GPU ?= false
GRAPHICS_MEMORY_DUMP ?= false
PROFILER ?= false
_ENABLEDFLAGS =

OBJ_DIR = objs/makefile
OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
SRCS = $(wildcard $(addsuffix /*.cpp, src/core))
SRCS += $(wildcard $(addsuffix /*.cpp, src/platform))
SRCS += $(wildcard $(addsuffix /*.cpp, src/renderer))
SRCS += $(wildcard $(addsuffix /*.cpp, src/renderer/**))

OS = $(shell uname -s)
DEBUG ?= false
TOOLCHAIN ?= clang
IMAGES_OPTIMIZED ?= true
FORCE_INTEGRATED_GPU ?= false
GRAPHICS_MEMORY_DUMP ?= false
PROFILER ?= false
OBJ_DIR = objs/make/$(shell echo $(OS) | tr '[:upper:]' '[:lower:]')
OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))

MODE = "release"

CXX = clang++

CXXFLAGS = -std=c++17 -O3 -fPIC -Wall -Wextra -Werror -DSDL_MAIN_HANDLED
INCLUDES = -I./includes -I./src -I./third_party

LDLIBS =
CXX = clang++
CXXFLAGS = -std=c++17 -O3 -fPIC -Wall -Wextra -Werror -DSDL_MAIN_HANDLED
INCLUDES = -I./includes -I./src -I./third_party

ifeq ($(TOOLCHAIN), gcc)
CXX = g++
CXXFLAGS += -Wno-error=cpp
CXX = g++
CXXFLAGS += -Wno-error=cpp
else
CXXFLAGS += -Wno-error=#warning
CXXFLAGS += -Wno-error=#warning
endif

ifeq ($(OS), Darwin)
LDLIBS += -L /opt/homebrew/lib -lSDL2
CXXFLAGS += -I /opt/homebrew/include
NAME = libmlx.dylib
LDFLAGS += -L /opt/homebrew/lib -lSDL2
CXXFLAGS += -I /opt/homebrew/include
NAME = libmlx.dylib
endif

ifeq ($(DEBUG), true)
CXXFLAGS += -g -D DEBUG
MODE = "debug"
CXXFLAGS += -g3 -D DEBUG
LDFLAGS += -rdynamic
endif

ifeq ($(FORCE_INTEGRATED_GPU), true)
CXXFLAGS += -D FORCE_INTEGRATED_GPU
_ENABLEDFLAGS += FORCE_INTEGRATED_GPU
endif

ifeq ($(IMAGES_OPTIMIZED), true)
CXXFLAGS += -D IMAGE_OPTIMIZED
_ENABLEDFLAGS += IMAGE_OPTIMIZED
endif

ifeq ($(GRAPHICS_MEMORY_DUMP), true)
CXXFLAGS += -D GRAPHICS_MEMORY_DUMP
_ENABLEDFLAGS += GRAPHICS_MEMORY_DUMP
endif

ifeq ($(PROFILER), true)
CXXFLAGS += -D PROFILER
_ENABLEDFLAGS += PROFILER
endif

CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS))

RM = rm -rf

TPUT = tput -T xterm-256color
_RESET := $(shell $(TPUT) sgr0)
_BOLD := $(shell $(TPUT) bold)
_ITALIC := $(shell $(TPUT) sitm)
_UNDER := $(shell $(TPUT) smul)
_GREEN := $(shell $(TPUT) setaf 2)
_YELLOW := $(shell $(TPUT) setaf 3)
_RED := $(shell $(TPUT) setaf 1)
_GRAY := $(shell $(TPUT) setaf 8)
_PURPLE := $(shell $(TPUT) setaf 5)

ifeq ($(DEBUG), true)
MODE := $(_RESET)$(_PURPLE)$(_BOLD)Debug$(_RESET)$(_PURPLE)
COLOR := $(_PURPLE)
else
MODE := $(_RESET)$(_GREEN)$(_BOLD)Release$(_RESET)$(_GREEN)
COLOR := $(_GREEN)
endif

OBJS_TOTAL = $(words $(OBJS))
N_OBJS := $(shell find $(OBJ_DIR) -type f -name '*.o' 2>/dev/null | wc -l)
OBJS_TOTAL := $(shell echo $$(( $(OBJS_TOTAL) - $(N_OBJS) )))
CURR_OBJ = 0

$(OBJ_DIR)/%.o: %.cpp
@printf "\033[1;32m[compiling... "$(MODE)" "$(CXX)"]\033[1;00m "$<"\n"
@mkdir -p $(dir $@)
@$(eval CURR_OBJ=$(shell echo $$(( $(CURR_OBJ) + 1 ))))
@$(eval PERCENT=$(shell echo $$(( $(CURR_OBJ) * 100 / $(OBJS_TOTAL) ))))
@printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)$<$(_RESET)\n" "$(PERCENT)"
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

all: $(NAME)
all: _printbuildinfos
@$(MAKE) $(NAME)

$(NAME): $(OBJS)
@printf "Linking $(_BOLD)$(NAME)$(_RESET)\n"
@$(CXX) -shared -o $(NAME) $(OBJS) $(LDFLAGS)
@printf "$(_BOLD)$(NAME)$(_RESET) compiled $(COLOR)$(_BOLD)successfully$(_RESET)\n"

$(NAME): $(OBJ_DIR) $(OBJS)
@printf "\033[1;32m[linking ... "$(MODE)"]\033[1;00m "$@"\n"
@$(CXX) -shared -o $(NAME) $(OBJS) $(LDLIBS)
@printf "\033[1;32m[build finished]\033[1;00m\n"
_printbuildinfos:
@printf "$(_PURPLE)$(_BOLD)MacroLibX $(_RESET)Compiling in $(_BOLD)$(MODE)$(_RESET) mode on $(_BOLD)$(OS)$(_RESET) | Using $(_BOLD)$(CXX)$(_RESET), flags: $(_BOLD)$(_ENABLEDFLAGS)$(_RESET)\n"

$(OBJ_DIR):
@mkdir -p $(sort $(addprefix $(OBJ_DIR)/, $(dir $(SRCS))))
@printf "\033[1;32m[created objs directory]\033[1;00m\n"
debug:
@$(MAKE) all DEBUG=true -j$(shell nproc)

clean:
@$(RM) $(OBJ_DIR)
@printf "\033[1;32m[object files removed]\033[1;00m\n"
@printf "Cleaned $(_BOLD)$(OBJ_DIR)$(_RESET)\n"

fclean: clean
@$(RM) $(NAME)
@printf "\033[1;32m["$(NAME)" removed]\033[1;00m\n"
@printf "Cleaned $(_BOLD)$(NAME)$(_RESET)\n"

re: fclean all
re: fclean _printbuildinfos
@$(MAKE) $(NAME)

.PHONY: all clean fclean re
.PHONY: all clean debug fclean re
8 changes: 6 additions & 2 deletions src/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2024/04/21 18:13:29 by maldavid ### ########.fr */
/* Updated: 2024/04/24 13:52:18 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -40,6 +40,7 @@ namespace mlx::core

void Application::run() noexcept
{
_in->run();
while(_in->isRunning())
{
if(!_fps.update())
Expand Down Expand Up @@ -107,7 +108,10 @@ namespace mlx::core
else
texture->destroy();
for(auto& gs : _graphics)
gs->tryEraseTextureFromManager(texture);
{
if(gs)
gs->tryEraseTextureFromManager(texture);
}
_textures.erase(it);
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
/* Updated: 2024/01/11 04:38:53 by maldavid ### ########.fr */
/* Updated: 2024/04/22 17:34:27 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -52,7 +52,7 @@ namespace mlx
_proj = glm::ortho<float>(0, _width, 0, _height);
_renderer->getUniformBuffer()->setData(sizeof(_proj), &_proj);

static std::array<VkDescriptorSet, 2> sets = {
std::array<VkDescriptorSet, 2> sets = {
_renderer->getVertDescriptorSet().get(),
VK_NULL_HANDLE
};
Expand Down
3 changes: 2 additions & 1 deletion src/platform/inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */
/* Updated: 2024/02/25 07:51:55 by maldavid ### ########.fr */
/* Updated: 2024/04/22 17:35:23 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -45,6 +45,7 @@ namespace mlx
inline int getYRel() const noexcept { return _yRel; }

inline bool isRunning() const noexcept { return !_end; }
inline constexpr void run() noexcept { _end = false; }
inline constexpr void finish() noexcept { _end = true; }

inline void addWindow(std::shared_ptr<MLX_Window> window)
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: kbz_8 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
/* Updated: 2024/03/14 16:34:53 by maldavid ### ########.fr */
/* Updated: 2024/09/14 00:04:16 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,6 +31,8 @@
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wparentheses"
#include <renderer/core/memory.h>
#pragma GCC diagnostic pop
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/core/render_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */
/* Updated: 2024/01/20 08:20:07 by maldavid ### ########.fr */
/* Updated: 2024/04/23 20:32:54 by kiroussa ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
11 changes: 9 additions & 2 deletions src/renderer/images/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
/* Updated: 2024/03/14 19:07:01 by maldavid ### ########.fr */
/* Updated: 2024/09/14 00:04:29 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -18,7 +18,14 @@
#include <cstring>

#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
#ifdef MLX_COMPILER_GCC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#include <stb_image.h>
#pragma GCC diagnostic pop
#else
#include <stb_image.h>
#endif

#ifdef IMAGE_OPTIMIZED
#define TILING VK_IMAGE_TILING_OPTIMAL
Expand Down
Loading

0 comments on commit 3dd68f9

Please sign in to comment.