X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_tex.h;h=7b2142c371bc62d654c1db9e6b2b6020d822c738;hb=3b841cc427adddeeb5b624d254587a45622d506d;hp=ef7f0e99bfb55db0350a3dbf0589d1bb3150bb32;hpb=6d772a1e69860f4ae3e838e8c5c164754e6533ae;p=vg.git diff --git a/vg_tex.h b/vg_tex.h index ef7f0e9..7b2142c 100644 --- a/vg_tex.h +++ b/vg_tex.h @@ -1,4 +1,35 @@ -/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */ +/* Copyright (C) 2021-2023 Harry Godden (hgn) - All Rights Reserved + * + * A portion of this file is copied and altered from the QOI projects' source, + * Originally written by Dominic Szablewski. It is slightly modified. + * For the original unaltered QOI header, you can find it here: + * https://github.com/phoboslab/qoi/blob/master/qoi.h + * + * Copyright (C) 2021, Dominic Szablewski + * SPDX-License-Identifier: MIT + * + * MIT License + Copyright (c) 2022 Dominic Szablewski - https://phoboslab.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + #ifndef VG_TEX_H #define VG_TEX_H @@ -6,6 +37,21 @@ #include "vg/vg.h" #include "vg/vg_log.h" +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "vg/submodules/stb/stb_image_write.h" + +/* its a sad day. */ +#if 0 +#define STBI_MALLOC(X) +#define STBI_REALLOC(X,Y) +#define STBI_FREE(X) +#endif + +#define STBI_ONLY_JPEG +#define STBI_NO_THREAD_LOCALS +#define STB_IMAGE_IMPLEMENTATION +#include "vg/submodules/stb/stb_image.h" + struct vg_sprite { v4f uv_xywh; @@ -80,8 +126,12 @@ struct texture_load_info{ u8 *rgba; }; -VG_STATIC void async_vg_tex2d_upload( void *payload, u32 size ) +static void async_vg_tex2d_upload( void *payload, u32 size ) { + if( vg_thread_purpose() != k_thread_purpose_main ){ + vg_fatal_error( "Catastrophic programming error.\n" ); + } + struct texture_load_info *info = payload; glGenTextures( 1, info->dest ); @@ -120,7 +170,7 @@ VG_STATIC void async_vg_tex2d_upload( void *payload, u32 size ) } } -VG_STATIC void vg_tex2d_replace_with_error( GLuint *dest ) +static void vg_tex2d_replace_with_error( GLuint *dest ) { u32 hdr_size = vg_align8(sizeof(struct texture_load_info)); @@ -136,7 +186,7 @@ VG_STATIC void vg_tex2d_replace_with_error( GLuint *dest ) vg_async_dispatch( call, async_vg_tex2d_upload ); } -VG_STATIC +static void vg_tex2d_load_qoi_async( const u8 *bytes, u32 size, u32 flags, GLuint *dest ) { @@ -270,7 +320,7 @@ void vg_tex2d_load_qoi_async( const u8 *bytes, u32 size, vg_async_dispatch( call, async_vg_tex2d_upload ); } -VG_STATIC +static void vg_tex2d_load_qoi_async_file( const char *path, u32 flags, GLuint *dest ) { vg_linear_clear( vg_mem.scratch );