summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore11
-rw-r--r--Makefile31
-rw-r--r--PKGBUILD7
-rw-r--r--example0.luma9
-rw-r--r--include/luma/main.hh65
-rw-r--r--include/luma/stdlibsock/gfx.hh2
-rw-r--r--initgfx.cc53
-rw-r--r--isvkphysdevvalid.cc5
-rw-r--r--main.cc8
-rw-r--r--stdlibsock/gfx/crtwin.cc37
-rw-r--r--termgfx.cc14
11 files changed, 163 insertions, 79 deletions
diff --git a/.gitignore b/.gitignore
index fcc8d94..d573c89 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,9 @@
-*.o
-luma.elf
+*
+!*.cc
+!*.gitignore
+!*.hh
+!*.luma
+!COPYING
+!Makefile
+!PKGBUILD
+!README
diff --git a/Makefile b/Makefile
index e36e63a..d0bdab8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,22 +1,29 @@
CXX=clang++
-CXXFLAGS+=-Iinclude -D_ATFILE_SOURCE -D_FORTIFY_SOURCE=2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_ISOC99_SOURCE -D_ISOC11_SOURCE -D_ISOC2X_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__=0x1
-CXXFLAGS+=-std=c++20 -Wall -Wextra -Wpedantic
-CXXFLAGS+=-march=native -O3
-LIBS=-lgmp -lmpfr -lpthread -lvulkan -lwayland-client -lxcb
-HDRS_CXX=\
+CXXFLAGS=-Iinclude -D_ATFILE_SOURCE -D_FORTIFY_SOURCE=2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_ISOC99_SOURCE -D_ISOC11_SOURCE -D_ISOC2X_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__=0x1
+ifneq ($(DEBUG),1)
+CXXFLAGS += -DNDEBUG
+endif
+ifeq ($(LUMA__X),1)
+CXXFLAGS += -DLUMA__X=true
+endif
+CXXFLAGS += -std=c++20 -Wall -Wextra -Wpedantic
+CXXFLAGS += -march=native -O3
+LDFLAGS = -lgmp -lmpfr -lpthread -lvulkan -lwayland-client -lxcb
+HDRS_CXX = \
include/luma/stdlibsock/gfx.hh \
include/luma/main.hh \
include/luma/stdlibsock.hh
-SRCS_CXX=\
+SRCS_CXX = \
stdlibsock/gfx/crtwin.cc \
stdlibsock/gfx/destwin.cc \
initgfx.cc \
- main.cc
+ main.cc \
+ termgfx.cc
SRCS=$(SRCS_CXX)
-OBJ=$(SRCS:.cc=.o)
-luma.elf: $(OBJ)
- $(CXX) $(LIBS) $(OBJ) -o $@
-$(OBJ): $(HDRS_CXX) $(SRCS_CXX)
+OBJS=$(SRCS:.cc=.o)
+luma.elf: $(OBJS)
+ $(CXX) $(LDFLAGS) -o $@ $(OBJS)
+$(OBJS): $(HDRS_CXX) $(SRCS_CXX)
.PHONY: clean
clean:
- rm $(OBJ)
+ rm $(OBJS)
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 0000000..e074174
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,7 @@
+pkgname="luma"
+pkgver=x
+pkgrel=10
+arch=("any")
+license=("AGPL3")
+depends=("glm" "gmp" "libxcb" "mpfr" "wayland")
+makedepends=("vulkan-headers")
diff --git a/example0.luma b/example0.luma
deleted file mode 100644
index 74245a0..0000000
--- a/example0.luma
+++ /dev/null
@@ -1,9 +0,0 @@
-frm /std/gfx imp clswin crtwin win_t
-void_t:main -fn []
- print “Creating window...\n”
- /std/gfx/win_t:win
- > Remember that Luma is little-endian, so numbers must be written reverse of what they normaly are (example: 123 becomes 321)
- catch (win = (/std/gfx/crtwin “luma test” #0 #0 #417 #045 no))
- print (“Error " + $errval + " when creating window")
- thrw #1
- /std/gfx/clswin
diff --git a/include/luma/main.hh b/include/luma/main.hh
index 12aaf1d..11df184 100644
--- a/include/luma/main.hh
+++ b/include/luma/main.hh
@@ -1,39 +1,58 @@
-# if defined(__cplusplus)
# if __cplusplus < 202002L
-# error The compiler seems to not have support for C++20 or newer½ (__cplusplus is less than 202002L), which is required to build Luma.
-# endif
-# else
-# error The compiler appears to not support C++ at all (__cplusplus is not defined).
+# error The compiler seems to not have support for C++20 or newer (__cplusplus is less than 202002L), which is required to build Luma.
# endif
# if !defined(LUMA__HEADER__MAIN)
# define LUMA__HEADER__MAIN
-//# if defined(__linux__)
-# define LUMA__USE_X
-//# endif
+# if !defined(LUMA__)
+# if (defined(__DragonFlyBSD__) || defined(__FreeBSD__) || defined(__linux__))
+# define LUMA__X false
+# else
+# define LUMA__X true
+# endif
+# endif
# include <cstdint>
+# include <iostream>
# include <luma/stdlibsock.hh>
# include <luma/stdlibsock/gfx.hh>
# include <string>
-# if defined(LUMA__USE_X)
+# include <vector>
+# include <vulkan/vulkan.h>
# include <wayland-client.h>
-# else
# include <xcb/xcb.h>
-# endif
using namespace std::literals::string_literals;
namespace luma {
- class dat_t {
- public:
- char * dispsrv;
-# if defined(LUMA__USE_X)
- wl_display * wldisp;
- wl_shell_surface * wlsurf;
+ bool constexpr debug =
+# if defined(NDEBUG)
+ false;
# else
- xcb_connection_t * xconn;
- xcb_screen_t * xscrn;
- xcb_window_t xwin;
+ true;
# endif
- };
- luma::dat_t extern dat;
- void initgfx(uint32_t * retval);
+ bool constexpr usex = LUMA__X;
+ void inline dbgmsg(char const * msg) {
+ if constexpr(debug) {
+ std::cerr << msg;
+ }
+ }
+ void initgfx();
+ void termgfx();
+ class dat_t {
+ private:
+ bool gfxisinit;
+ std::vector<VkExtensionProperties> vkexts;
+ std::vector<VkPhysicalDevice> vkphysdevs;
+ ::VkApplicationInfo vkappinf {};
+ ::VkInstance vkinst;
+ ::VkInstanceCreateInfo vkinstcrtinf {};
+ ::VkResult vkreslt;
+ ::wl_buffer * wlbuff = nullptr;
+ ::wl_display * wldisp = nullptr;
+ ::wl_shell_surface * wlsurf = nullptr;
+ ::xcb_connection_t * xconn = nullptr;
+ ::xcb_screen_t * xscrn = nullptr;
+ ::xcb_window_t xwin;
+ friend void luma::initgfx();
+ friend std::uint8_t luma::stdlibsock::gfx::crtwin(std::basic_string<char> nm,std::uint16_t pos_x,std::uint16_t pos_y,std::uint16_t res_x,std::uint16_t res_y,bool flscrn);
+ friend void luma::termgfx();
+ } extern dat;
}
# endif
diff --git a/include/luma/stdlibsock/gfx.hh b/include/luma/stdlibsock/gfx.hh
index a9d7805..f44ba34 100644
--- a/include/luma/stdlibsock/gfx.hh
+++ b/include/luma/stdlibsock/gfx.hh
@@ -5,7 +5,7 @@
namespace luma {
namespace stdlibsock {
namespace gfx {
- uint8_t crtwin(std::basic_string<char> nm, uint16_t pos_x, uint16_t pos_y, uint16_t res_x, uint16_t res_y, bool flscrn);
+ std::uint8_t crtwin(std::basic_string<char> nm, std::uint16_t pos_x, std::uint16_t pos_y, std::uint16_t res_x, std::uint16_t res_y, bool flscrn);
void destwin();
}
}
diff --git a/initgfx.cc b/initgfx.cc
index a6df6dd..01bd016 100644
--- a/initgfx.cc
+++ b/initgfx.cc
@@ -1,10 +1,51 @@
# include <luma/main.hh>
-# include <stdint.h>
-# include <stdio.h>
-# if defined(LUMA__USE_X)
+# include <cstdint>
+# include <string>
+# include <vulkan/vulkan.h>
# include <wayland-client.h>
-# else
# include <xcb/xcb.h>
-# endif
-void luma::initgfx(uint32_t * retval) {
+void luma::initgfx() {
+ luma::dat.gfxisinit = true;
+ if constexpr(luma::usex == 0x1) {
+ luma::dbgmsg("Creating X connection... ");
+ luma::dat.xconn = xcb_connect(nullptr,nullptr);
+ luma::dat.xscrn = xcb_setup_roots_iterator(xcb_get_setup(luma::dat.xconn)).data;
+ luma::dat.xwin = xcb_generate_id(luma::dat.xconn);
+ luma::dbgmsg("O.K.\n");
+ }
+ else {
+ luma::dbgmsg("Creating Wayland connection... ");
+ luma::dat.wldisp = wl_display_connect(nullptr);
+ if(luma::dat.wldisp == nullptr) {
+ luma::dbgmsg("Error\n");
+ }
+ else {
+ luma::dbgmsg("O.K.\n");
+ }
+ }
+ luma::dat.vkappinf.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
+ luma::dat.vkappinf.pApplicationName = "Luma Standard Library";
+ luma::dat.vkappinf.pEngineName = "Luma Standard Library";
+ luma::dat.vkinstcrtinf.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
+ luma::dat.vkinstcrtinf.pApplicationInfo = &luma::dat.vkappinf;
+ luma::dat.vkinstcrtinf.enabledLayerCount = 0x0;
+ luma::dbgmsg("Creating Vulkan instance... ");
+ luma::dat.vkreslt = vkCreateInstance(&luma::dat.vkinstcrtinf,nullptr,&luma::dat.vkinst);
+ if((luma::dat.vkreslt != VK_SUCCESS)) {
+ luma::dbgmsg("Error\n");
+ }
+ else {
+ luma::dbgmsg("O.K.\n");
+ }
+ std::uint32_t extcount = 0x0;
+ luma::dat.vkexts = std::vector<VkExtensionProperties>(extcount);
+ ::vkEnumerateInstanceExtensionProperties(nullptr,&extcount,luma::dat.vkexts.data());
+ luma::dbgmsg(std::basic_string<char> {std::to_string(extcount) + " Vulkan extensions supported.\n"s}.c_str());
+ luma::dbgmsg("The following Vulkan extensions are supported:\n");
+ for(auto const & ext : luma::dat.vkexts) {
+ luma::dbgmsg(ext.extensionName);
+ }
+ std::uint32_t devcount = 0x0;
+ ::vkEnumeratePhysicalDevices(luma::dat.vkinst,&devcount,luma::dat.vkphysdevs.data());
+ luma::dbgmsg(std::basic_string<char> {std::to_string(devcount) + " Vulkan-compatible device(s) found.\n"s}.c_str());
}
diff --git a/isvkphysdevvalid.cc b/isvkphysdevvalid.cc
new file mode 100644
index 0000000..9a8c065
--- /dev/null
+++ b/isvkphysdevvalid.cc
@@ -0,0 +1,5 @@
+# include <luma/main.hh>
+# include <vulkan/vulkan.h>
+//isVulkanPhysicalDeviceValid
+void luma::isvkphysdevvalid(VkPhysicalDevice & dev) {
+}
diff --git a/main.cc b/main.cc
index 773e0f4..b1d442e 100644
--- a/main.cc
+++ b/main.cc
@@ -7,14 +7,14 @@ luma::dat_t luma::dat;
int main(int argc, char * * argv) {
if(argc < 0x2) {
std::cout << "Missing argument \"file\".\n";
- exit(EXIT_FAILURE);
+ std::exit(EXIT_FAILURE);
}
- if((access(argv[0x1], F_OK) == 0)) {
+ if((::access(argv[0x1], F_OK) == 0x0)) {
luma::stdlibsock::gfx::crtwin("luma test"s,0x0,0x0,0x400,0x300,false);
}
else {
std::cout << "The file doesn't exist.\n";
- exit(EXIT_FAILURE);
+ std::exit(EXIT_FAILURE);
}
- exit(EXIT_SUCCESS);
+ std::exit(EXIT_SUCCESS);
}
diff --git a/stdlibsock/gfx/crtwin.cc b/stdlibsock/gfx/crtwin.cc
index d6ea03d..3e6f235 100644
--- a/stdlibsock/gfx/crtwin.cc
+++ b/stdlibsock/gfx/crtwin.cc
@@ -1,39 +1,32 @@
# include <cstdint>
+# include <cstring>
# include <iostream>
# include <luma/main.hh>
# include <string>
# include <unistd.h>
-# include <vulkan/vulkan.hpp>
-# if defined(LUMA__USE_X)
+# include <vulkan/vulkan.h>
# include <wayland-client.h>
-# else
# include <xcb/xcb.h>
# include <xcb/xcb_atom.h>
-# endif
-uint8_t luma::stdlibsock::gfx::crtwin(std::basic_string<char> nm,uint16_t pos_x,uint16_t pos_y,uint16_t res_x,uint16_t res_y,bool flscrn) {
+std::uint8_t luma::stdlibsock::gfx::crtwin(std::basic_string<char> nm,std::uint16_t pos_x,std::uint16_t pos_y,std::uint16_t res_x,std::uint16_t res_y,bool flscrn) {
+ if(!luma::dat.gfxisinit) {
+ luma::initgfx();
+ }
if(flscrn) {
std::cout << "Fullscreen is not supported yet!\n";
}
-# if defined(LUMA__USE_X)
- luma::dat.wldisp = wl_display_connect(NULL);
- if(luma::dat.wldisp == nullptr) {
- std::cout << "Unable to make a Wayland connection!\n";
+ if constexpr(luma::usex == 0x1) {
+ luma::dbgmsg("Creating X window... ");
+ ::xcb_create_window(luma::dat.xconn,XCB_COPY_FROM_PARENT,luma::dat.xwin,luma::dat.xscrn->root,pos_y,pos_x,res_x,res_y,0xa,XCB_WINDOW_CLASS_INPUT_OUTPUT,luma::dat.xscrn->root_visual,0x0,nullptr);
+ ::xcb_change_property(luma::dat.xconn,XCB_PROP_MODE_REPLACE,luma::dat.xwin,XCB_ATOM_WM_NAME,XCB_ATOM_STRING,0x8,nm.size(),nm.c_str());
+ ::xcb_map_window(luma::dat.xconn,luma::dat.xwin);
+ ::xcb_flush(luma::dat.xconn);
+ luma::dbgmsg("O.K.\n");
}
else {
- std::cout << "A Wayland connection has been made.\n";
}
+ std::cout <<
::sleep(0x6);
- ::wl_display_disconnect(luma::dat.wldisp);
-# else
- luma::dat.xconn = xcb_connect(NULL,NULL);
- luma::dat.xscrn = xcb_setup_roots_iterator(xcb_get_setup(luma::dat.xconn)).data;
- luma::dat.xwin = xcb_generate_id(luma::dat.xconn);
- xcb_create_window(luma::dat.xconn,XCB_COPY_FROM_PARENT,luma::dat.xwin,luma::dat.xscrn->root,pos_y,pos_x,res_x,res_y,0xa,XCB_WINDOW_CLASS_INPUT_OUTPUT,luma::dat.xscrn->root_visual,0x0,NULL);
- xcb_change_property(luma::dat.xconn,XCB_PROP_MODE_REPLACE,luma::dat.xwin,XCB_ATOM_WM_NAME,XCB_ATOM_STRING,0x8,nm.size(),nm.c_str());
- xcb_map_window(luma::dat.xconn,luma::dat.xwin);
- xcb_flush(luma::dat.xconn);
- sleep(0x6);
- xcb_disconnect(luma::dat.xconn);
-# endif
+ luma::termgfx();
return 0x0;
}
diff --git a/termgfx.cc b/termgfx.cc
new file mode 100644
index 0000000..1df3547
--- /dev/null
+++ b/termgfx.cc
@@ -0,0 +1,14 @@
+# include <cstdint>
+# include <luma/main.hh>
+# include <vulkan/vulkan.h>
+# include <wayland-client.h>
+# include <xcb/xcb.h>
+void luma::termgfx() {
+ ::vkDestroyInstance(luma::dat.vkinst,nullptr);
+ if constexpr(luma::usex == 0x1) {
+ ::xcb_disconnect(luma::dat.xconn);
+ }
+ else {
+ ::wl_display_disconnect(luma::dat.wldisp);
+ }
+}