Skip to content

Instantly share code, notes, and snippets.

View graphitemaster's full-sized avatar
🎩
Building my dream game

Dale Weiler graphitemaster

🎩
Building my dream game
View GitHub Profile
@graphitemaster
graphitemaster / WORKING_AROUND_OFFSETOF_LIMITATIONS.MD
Last active January 10, 2026 00:20
Working around offsetof limitations in C++

Working around offsetof limitations in C++:

There is sometimes a situation in which one needs to get the relative offset of a structure field, common examples of this include serialization frameworks which aid to serialize objects, vertex attributes for rendering (D3D, GL.), etc.

The most common technique for getting this information is through the offsetof macro defined in stddef.h. Unfortunately using the macro in C++ comes with a new set of restrictions that prevent some (subjectively valid) uses of it.

@graphitemaster
graphitemaster / openglbb.md
Created July 6, 2017 19:13
OpenGL Black Bible

OpenGL Black Bible

Author: Dale Weiler

Preface

The following is a writeup of the following things I've independently discovered or been told over the years on how to utilize OpenGL effectively. Not everything in here I gurantee to be factually correct - though several others share similar ideas as present here. Take these are your own peril, like everything else - nothing is absolute; so profile to be sure and check the standards if something here is incorrect. These things presented here I've come to accept as being a safe

@graphitemaster
graphitemaster / T0.md
Last active July 26, 2025 12:53
Vulkan Tutorial

Tutorial 0

What is Vulkan

Vulkan is a low-overhead, cross-platform 3D graphics and compute API.

Vulkan targets

Vulkan targets high-performance realtime 3D graphics applications such as games and interactive media across multiple platforms providing higher performance and lower CPU usage.

@graphitemaster
graphitemaster / gist:f8e6666c48fbedf6e554
Last active October 7, 2024 07:07
Engine achievements
Achievement Engine/Game Why it's bad
storing world space positions in gbuffer STALKER, F.E.A.R. Depth buffer can be used to derive position saving a lot of memory bandwidth
uploaded texture upside down Various engines, mostly Quake derived. Difficult to debug with tools like apitrace, nsight, pix, renderdoc, etc
@graphitemaster
graphitemaster / gist:7a1b970798cf2b1f65c38fbf97f8edf1
Created April 25, 2017 08:12
awful compiler explosion gcc 7
This file has been truncated, but you can view the full file.
t.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000007 <foo>:
7: 55 push %rbp
8: 48 89 e5 mov %rsp,%rbp
b: b8 00 00 00 00 mov $0x0,%eax
10: e8 00 00 00 00 callq 15 <foo+0xe>
/*
* Bit twiddling hacks: By Dale Weiler (a.k.a graphitemaster)
* all code is public domain.
*/
#include <limits.h>
#include <stdio.h>
/*
* Simple utility to convert integer to binary string: it's a pity
* C doesn't support a format specifier for printf. Or binary constants
// church numerals and lambda calculus in C++ using meta-template
// programming, everything evaluated at compile-time. This code should
// never be used in the real world. If I catch people using this for
// real-world code just because it's awesome I will track said people
// down and have a length discussion on why their existance is the
// reason I need to question the ethics of writing this code in the
// first place.
// all code is licensed under MIT under one condition, never actually
// use this code in real world programs, you can share it, and modify it
Here's an example. I have this data structure which represents a rectangle
struct Rectangle {
uint32_t x, y, w, h;
};
I have myself an unspecified size of these in a vector.
Vector<Rectangle> rectangles;
There is this other data structure which represents a rounded rectangle, looks something like this.
struct RoundedRectangle {
@graphitemaster
graphitemaster / zlib_compress.c
Created August 27, 2011 06:27
ZLIB compression in 200 LOC
// ~zlib compression in 200 LOC quality allowed (5-8), where 5 is lowest, and 8 is heighest, the lower
// the quality the smaller the file. By graphitemaster, licensed unded public domain.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* fast lookup tables for length and distance */
static const unsigned short zlib_lengthc[] = {
0x003, 0x004, 0x005, 0x006, 0x007, 0x008, 0x009, 0x00A, 0x00B, 0x00D,
0x00F, 0x011, 0x013, 0x017, 0x01B, 0x01F, 0x023, 0x02B, 0x033, 0x03B,
@graphitemaster
graphitemaster / Makefile
Created October 14, 2012 00:17
gmbootloader
CFLAGS = -nostdinc -nostdlib -ffreestanding -m32 -fno-pic
CC ?= gcc
DD ?= dd
OBJDUMP = objdump
OBJCOPY = objcopy
HEXDUMP = hexdump
boot: main.S boot.c
$(CC) $(CFLAGS) -c boot.c
$(CC) $(CFLAGS) -c main.S