Skip to content

Instantly share code, notes, and snippets.

View stillwwater's full-sized avatar

Lucas stillwwater

  • Microsoft
  • Canada
View GitHub Profile
#include "array.h"
// arenasize:
// virtual address size of the backing arenai
void *
make_array(usize arenasize, usize elementsize, char *name)
{
struct arena *arena = make_arena(arenasize, name);
struct array_header *array = arena_alloc_align(arena, 16, sizeof *array);
@stillwwater
stillwwater / rasterizer.asm
Last active November 11, 2024 19:28
Simple rasterizer
bits 64
default rel
%define R_PITCH (160 * 4)
%define R_PITCH_SHIFT 10
section .data
float_1 dd 1.0
align 32
@stillwwater
stillwwater / vid_win32.c
Created October 24, 2024 04:33
OpenGL on DXGI swapchain
#define COBJMACROS
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_3.h>
cvar_t vid_dxgi = {"vid_dxgi", 0, CVAR_BOOL | CVAR_ALLOW | CVAR_INIT}; // DXGI layer for OpenGL
cvar_t vid_waitsync = {"vid_waitsync", 0, CVAR_BOOL | CVAR_ALLOW}; // lower latency, lower framerate
cvar_t vid_display = {"vid_display", -1, CVAR_INT | CVAR_ALLOW}; // -1 = primary
cvar_t vid_fullscreen = {"vid_fullscreen", 1, CVAR_BOOL | CVAR_ALLOW};
struct arena {
usize commitsize;
char *name;
char *start; // start of reserved address space
char *end; // end of reserved address space
char *heap; // start of user block
char *allocated; // end of allocated block
char *commited; // end of commited block
};
@stillwwater
stillwwater / gl_init.cpp
Created November 17, 2023 04:44
Create a modern OpenGL context on Windows
// Initializes an OpenGL device context for a given window.
void
gl_create_context(HWND hwnd)
{
HDC hdc;
HGLRC hglrc;
int pfd_index;
PIXELFORMATDESCRIPTOR pfd, device_pfd;
@stillwwater
stillwwater / gjk.c
Last active September 2, 2023 22:27
#include "core/vector.h"
#include "core/math.h"
#include "physics/clip.h"
struct phys_world {
unsigned static_clips_count;
struct aabb static_clips[PHYS_MAX_CLIP];
};
static struct phys_world phys;
spacing=1
id=1
nodes={}
rects={}
parent=nil
child=nil
function setpos(node)
local d=0
local p=node.p
@stillwwater
stillwwater / benchmark.h
Last active September 16, 2022 03:07
c++ benchmark library
// Copyright 2022 [email protected]
//
// Permission to use, copy, modify, and/or distribute this software for
// any purpose with or without fee is hereby granted, provided that the
// above copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
#define DEFER_CAT_(A, B) A ## B ## _
#define DEFER_CAT(A, B) DEFER_CAT_(A, B)
template <typename Func>
struct Defer {
Func fn;
Defer(Func fn_) : fn(fn_) {}
~Defer() { fn(); }
};
@stillwwater
stillwwater / test.h
Last active April 29, 2023 03:05
C/C++ test library
// Copyright (c) 2023 [email protected]
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//