From 8dddac6f3376b92496c86b1bfa4bed8fa2c7327f Mon Sep 17 00:00:00 2001 From: Matheus Date: Wed, 12 Oct 2022 18:14:36 -0300 Subject: [PATCH] jinx: tinygl port --- patches/tinygl/tinygl.patch | 188 ++++++++++++++++++++++++++++++++++++ recipes/tinygl | 25 +++++ source-recipes/tinygl | 8 ++ 3 files changed, 221 insertions(+) create mode 100644 patches/tinygl/tinygl.patch create mode 100644 recipes/tinygl create mode 100644 source-recipes/tinygl diff --git a/patches/tinygl/tinygl.patch b/patches/tinygl/tinygl.patch new file mode 100644 index 00000000..dbe7571c --- /dev/null +++ b/patches/tinygl/tinygl.patch @@ -0,0 +1,188 @@ +diff -ruN tinygl-clean/config.mk tinygl/config.mk +--- tinygl-clean/config.mk 2022-10-12 16:23:10.526644185 -0300 ++++ tinygl/config.mk 2022-10-12 16:26:32.323309224 -0300 +@@ -3,7 +3,7 @@ + + #CC= clang + #CC=cc +-CC=gcc ++CC=x86_64-astral-gcc + #CC=tcc + #uncomment the following line for compiling the lib using tinyc. + #note that the demos will fail to build with tinyc, but you can +@@ -15,16 +15,11 @@ + #extract the maximum possible performance from gcc. + + +-#CFLAGS= -Wall -O3 -std=c99 -DNDEBUG -march=native -Wno-unused-function +-CFLAGS= -Wall -O3 -std=c99 -DNDEBUG -march=native -fopenmp -Wno-unused-function +-#CFLAGS_LIB= -Wall -O3 -std=c99 -pedantic -DNDEBUG -march=native -Wno-unused-function +-CFLAGS_LIB= -Wall -O3 -std=c99 -pedantic -DNDEBUG -fopenmp -march=native -Wno-unused-function +- + + #CFLAGS= -Wall -Ofast -std=gnu99 -DNDEBUG -mtune=native + #uncomment the following line for compiling the lib with tinyc + #keep these flags for compiling with gcc if you are linking with tinygl compiled with tcc. +-#CFLAGS= -Wall -O3 -std=gnu99 -DNDEBUG -g ++CFLAGS= -Wall -O3 -std=gnu99 -DNDEBUG -g + #CFLAGS= -Wall -O1 -g -std=c99 -Wno-undef -DNDEBUG + LFLAGS= + +diff -ruN tinygl-clean/Makefile tinygl/Makefile +--- tinygl-clean/Makefile 2022-10-12 16:23:10.526644185 -0300 ++++ tinygl/Makefile 2022-10-12 16:37:01.029970821 -0300 +@@ -1,9 +1,10 @@ + + LIBNAME=libTinyGL.a ++PREFIX=/usr/local/ + LIB=lib/$(LIBNAME) +-LIBDIR=/usr/local/lib +-INCDIR=/usr/local/include +-BINDIR=/usr/local/bin ++LIBDIR=$(DESTDIR)/$(PREFIX)/lib ++INCDIR=$(DESTDIR)/$(PREFIX)/include ++BINDIR=$(DESTDIR)/$(PREFIX)/bin + + all: $(LIB) RDMOS + @echo Done! +@@ -13,8 +14,10 @@ + cp src/*.a ./lib/ + + install: $(LIB) ++ [ -d $(INCDIR)/tinygl ] || mkdir -p $(INCDIR)/tinygl ++ [ -d $(LIBDIR)/ ] || mkdir -p $(LIBDIR) ++ [ -d $(BINDIR)/ ] || mkdir -p $(BINDIR) + cp $(LIB) $(LIBDIR) +- mkdir $(INCDIR)/tinygl || echo "You installed before?" + cp -r include/* $(INCDIR)/tinygl + + uninstall: +diff -ruN tinygl-clean/Raw_Demos/gears.c tinygl/Raw_Demos/gears.c +--- tinygl-clean/Raw_Demos/gears.c 2022-10-12 16:23:10.576644185 -0300 ++++ tinygl/Raw_Demos/gears.c 2022-10-12 17:07:07.653289522 -0300 +@@ -15,6 +15,9 @@ + #include + #include + ++#include ++#include ++#include + + //Doesn't drag in anything. + #include "../include/GL/gl.h" +@@ -293,10 +296,79 @@ + // glEnable( GL_NORMALIZE ); + } + ++static int seekordie(int fd, off_t offset, int whence){ ++ int ret = lseek(fd, offset, whence); ++ if(ret == -1){ ++ printf("gears: lseek failed on fd %d: %s", fd, strerror(errno)); ++ exit(errno); ++ } ++ return ret; ++} ++ ++static int ioctlordie(int fd, unsigned long request, void* arg){ ++ int ret = ioctl(fd, request, arg); ++ if(ret == -1){ ++ printf("gears: ioctl failed on fd %d: %s\n", fd, strerror(errno)); ++ exit(errno); ++ } ++ return ret; ++} ++ ++static int openordie(char* name, int flags, int mode){ ++ int fd = open(name, flags, mode); ++ if(fd == -1){ ++ printf("gears: failed to open %s: %s\n", name, strerror(errno)); ++ exit(errno); ++ } ++ return fd; ++} ++ ++static int writeordie(int fd, void* buff, size_t count){ ++ int writec = write(fd, buff, count); ++ if(writec == -1){ ++ printf("gears: write failed on fd %d: %s\n", fd, strerror(errno)); ++ exit(errno); ++ } ++ ++ return writec; ++} ++ ++static int readordie(int fd, void* buff, size_t count){ ++ int readc = read(fd, buff, count); ++ if(readc == -1){ ++ printf("gears: read failed on fd %d: %s\n", fd, strerror(errno)); ++ exit(errno); ++ } ++ return readc; ++} ++ ++void usage(){ ++ printf("Usage: gears [options]\n"); ++ printf("--help Display this information.\n"); ++ printf("-w Set width of the window\n"); ++ printf("-h Set height of the window\n"); ++ printf("-flat\n"); ++ printf("-smooth\n"); ++ printf("-blend\n"); ++ printf("-nospecular\n"); ++ printf("-lines\n"); ++ printf("-points\n"); ++ printf("-notext\n"); ++} ++ + int main(int argc, char** argv) { + // initialize SDL video: +- int winSizeX = 640; +- int winSizeY = 480; ++ ++ int fbfd = openordie("/dev/fb0", O_RDONLY, 0); ++ ++ struct fb_var_screeninfo fbvs; ++ struct fb_fix_screeninfo fbfs; ++ ++ ioctlordie(fbfd, FBIOGET_VSCREENINFO, &fbvs); ++ ioctlordie(fbfd, FBIOGET_FSCREENINFO, &fbfs); ++ ++ int winSizeX = fbvs.xres; ++ int winSizeY = fbvs.yres; + PIXEL* imbuf = NULL; + uchar* pbuf = NULL; + unsigned int flat = 0; +@@ -324,6 +396,10 @@ + override_drawmodes = 2; + if (!strcmp(argv[i],"-notext")) + dotext = 0; ++ if (!strcmp(argv[i],"--help")){ ++ usage(); ++ exit(0); ++ } + larg = argv[i]; + } + } +@@ -413,15 +489,18 @@ + if(frames > 0) break; + } + if(TGL_FEATURE_RENDER_BITS == 32){ //very little conversion. +- pbuf = malloc(3 * winSizeX * winSizeY); ++ pbuf = malloc(4 * winSizeX * winSizeY); + for(int i = 0; i < winSizeX * winSizeY; i++){ + //pbuf[3*i+0] = (imbuf[i]&0xff0000)>>16; + //pbuf[3*i+1] = (imbuf[i]&0x00ff00)>>8; + //pbuf[3*i+2] = (imbuf[i]&0x0000ff); +- pbuf[3*i+0] = GET_RED(imbuf[i]); +- pbuf[3*i+1] = GET_GREEN(imbuf[i]); +- pbuf[3*i+2] = GET_BLUE(imbuf[i]); ++ pbuf[4*i+0] = GET_RED(imbuf[i]); ++ pbuf[4*i+1] = GET_GREEN(imbuf[i]); ++ pbuf[4*i+2] = GET_BLUE(imbuf[i]); + } ++ ++ writeordie(fbfd, pbuf, 4 * winSizeX * winSizeY); ++ + stbi_write_png("render.png", winSizeX, winSizeY, 3, pbuf, 0); + free(imbuf); + free(pbuf); diff --git a/recipes/tinygl b/recipes/tinygl new file mode 100644 index 00000000..a378aba4 --- /dev/null +++ b/recipes/tinygl @@ -0,0 +1,25 @@ +name=tinygl +revision=1 +from_source=tinygl +imagedeps="base-devel" +hostdeps="gcc-cross binutils-cross" +deps="mlibc" + + +configure() { + + true + +} + +build() { + + make -C ${source_dir} CC=x86_64-astral-gcc + +} + +install() { + + make -C ${source_dir} install PREFIX=${prefix} DESTDIR=${dest_dir} + cp ${source_dir}/Raw_Demos/{bigfont,asciifractal.sh,gears,t2i} ${dest_dir}/usr/bin/ +} diff --git a/source-recipes/tinygl b/source-recipes/tinygl new file mode 100644 index 00000000..bc29b97b --- /dev/null +++ b/source-recipes/tinygl @@ -0,0 +1,8 @@ +name=tinygl +version=0.0.0 +source_method=git +clone_url="https://github.com/C-Chads/tinygl.git" +tag=main +regenerate() { + true +}