Skip to content

Instantly share code, notes, and snippets.

// based on xxhash32
unsigned int hash(char *data, size_t len)
{
unsigned int hash;
if (len < 4) {
// load 3 bytes, overlapping if len < 3
static unsigned char offset1[4] = { 0,0,1,1 };
static unsigned char offset2[4] = { 0,0,0,2 };
unsigned int h = data[0] + (data[offset1[len]]<<8) + (data[offset2[len]]<<16);
h = xxprime1 + h*xxprime2;
// Old code which could only have one value for all threads:
static int stbi__vertically_flip_on_load = 0;
STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip)
{
stbi__vertically_flip_on_load = flag_true_if_should_flip;
}
// New code which allows per-thread values without breaking old behavior:
@nothings
nothings / gist:ef38135f4aa4799e8f09069a44ded5a2
Created October 21, 2019 00:26
current stb_platform API structure
typedef struct {
float seconds_delta;
double seconds;
stbp_uint64 ns;
stbp_uint64 ns_delta;
stbp_uint64 ms;
stbp_uint64 ms_delta;
} stbp_time_info;
typedef struct {
#define STB_DEFINE
#include "stb.h"
char *header;
typedef struct
{
char *id;
char *html;
char *commentary;
instruction = cccccccc t xx r bb i aaa
8-bit registers A,B,C,T
8-bit program counter X
input I
output O
1-bit register F
; constant
C <- -128..127
uniform vec3 base;
uniform usamplerBuffer heightfield;
uniform float edge_lod[5];
out vec4 vcolor;
out vec2 norm_tc;
out vec3 world_pos;
const ivec2 v[4] = ivec2[4](ivec2(0,0),ivec2(-1,0),ivec2(0,-1),ivec2(-1, -1));
: find-)
key
')' =
not if
tail find-)
then
;
: ( immediate
find-)
#ifndef STBP_NUM_INPUT_HISTORY
#define STBP_NUM_INPUT_HISTORY 20 // 100ms at 5ms/sample
#endif
#ifndef STBP_MAX_CHARS_PER_FRAME
#define STBP_MAX_CHARS_PER_FRAME 50
#endif
typedef struct {
float seconds_delta;
double seconds;
// "Virtual" key codes... these are not the same as windows; as many as possible are
// mapped to the ASCII codes so you can ASCII index them, and they're repacked to
// fit from 0..127. There are no keycodes for mouse buttons or IME events.
enum
{
// no mouse button aliases yet (ever?)
STBVK_PAUSE = 0x07, // new?
STBVK_BACK = 0x08,
STBVK_TAB = 0x09, // "\t"
STBVK_LWIN = 0x0a,
// What I'm trying to do: store a 1-byte alpha texture:
GLenum swizzle[4] = { GL_ONE, GL_ONE, GL_ONE, GL_RED };
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width,height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
// above draws (1,1,1,1)
// works as expected: storing to red channel of an RGBA texture and using swizzle into the alpha
GLenum swizzle[4] = { GL_ONE, GL_ONE, GL_ONE, GL_RED };
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width,height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
// ^^^^^^^^