Graphics and memory stuff for stb_image

This commit is contained in:
Ben Visness 2023-06-24 10:05:04 -05:00 committed by Martin Fouilleul
parent bc03887148
commit bcf84e0b80
4 changed files with 5598 additions and 45 deletions

View File

@ -1,5 +1,7 @@
#!/bin/bash
set -euo pipefail
DEBUG_FLAGS="-g -DDEBUG -DLOG_COMPILE_DEBUG"
#DEBUG_FLAGS="-O3"
@ -26,6 +28,8 @@ if [ $OS = "Darwin" ] ; then
SYS_LIBS=''
FLAGS="-mmacos-version-min=10.15.4 -maes"
CFLAGS="-std=c11"
SDKDIR=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
LDFLAGS="-L$SDKDIR/usr/lib -F$SDKDIR/System/Library/Frameworks/"
elif [ $OS = "Linux" ] ; then
echo "Error: Linux is not supported yet"
@ -69,7 +73,7 @@ if [ $target = 'lib' ] ; then
$CC $DEBUG_FLAGS -c -o $BINDIR/milepost_objc.o $FLAGS $INCLUDES $SRCDIR/milepost.m
# build dynamic library
ld -dylib -o $BINDIR/libmilepost.dylib $BINDIR/milepost_c.o $BINDIR/milepost_objc.o -lc -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore -L$BINDIR -weak-lEGL -weak-lGLESv2
ld $LDFLAGS -dylib -o $BINDIR/libmilepost.dylib $BINDIR/milepost_c.o $BINDIR/milepost_objc.o -L$BINDIR -lc -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore -weak-lEGL -weak-lGLESv2
# change dependent libs path to @rpath.
install_name_tool -change "./libEGL.dylib" '@rpath/libEGL.dylib' $BINDIR/libmilepost.dylib

View File

@ -10,10 +10,14 @@
#include"platform/platform.h"
#include"platform/platform_math.h"
#if !PLATFORM_ORCA
#define STB_IMAGE_IMPLEMENTATION
#include"stb_image.h"
#define STB_IMAGE_IMPLEMENTATION
#if PLATFORM_ORCA
#define STBI_NO_STDIO
#define STBI_NO_HDR
#endif
#include"stb_image.h"
#if !PLATFORM_ORCA
#define STB_TRUETYPE_IMPLEMENTATION
#include"stb_truetype.h"
#endif
@ -1596,8 +1600,6 @@ mg_image mg_image_create_from_rgba8(mg_surface surface, u32 width, u32 height, u
return(image);
}
#if !PLATFORM_ORCA
mg_image mg_image_create_from_data(mg_surface surface, str8 data, bool flip)
{
mg_image image = mg_image_nil();
@ -1614,6 +1616,8 @@ mg_image mg_image_create_from_data(mg_surface surface, str8 data, bool flip)
return(image);
}
#if !PLATFORM_ORCA
mg_image mg_image_create_from_file(mg_surface surface, str8 path, bool flip)
{
mg_image image = mg_image_nil();

5578
src/platform/orca_malloc.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@
*****************************************************************/
#include"platform_memory.h"
#include <stdlib.h>
void* ORCA_IMPORT(orca_mem_grow)(u64 size);
@ -30,58 +31,24 @@ mem_base_allocator* mem_base_allocator_default()
return(&base);
}
//TODO: implement malloc/realloc/free/memset/etc here...
// malloc, free, realloc, etc. are defined in orca_malloc.c
void* memset(void* b, int c, size_t n)
{
for(size_t i = 0; i<n; i++)
{
((char*)b)[i] = (u8)c;
}
return(b);
return __builtin_memset(b, c, n);
}
void* memcpy(void *restrict dst, const void *restrict src, size_t n)
{
for(size_t i = 0; i<n; i++)
{
((char*)dst)[i] = ((char*)src)[i];
}
return(dst);
return __builtin_memcpy(dst, src, n);
}
void* memmove(void *dst, const void *src, size_t n)
{
if(src < dst)
{
for(size_t i = n-1; i>=0; i--)
{
((char*)dst)[i] = ((char*)src)[i];
}
}
else if(src > dst)
{
for(size_t i = 0; i<n; i++)
{
((char*)dst)[i] = ((char*)src)[i];
}
}
return(dst);
return __builtin_memmove(dst, src, n);
}
int memcmp(const void *s1, const void *s2, size_t n)
{
const unsigned char* c1 = (const unsigned char*)s1;
const unsigned char* c2 = (const unsigned char*)s2;
for(size_t i = 0; i<n; i++)
{
if(c1[i] != c2[i])
{
return(c1 - c2);
}
}
return(0);
return __builtin_memcmp(s1, s2, n);
}