Skip to content

Instantly share code, notes, and snippets.

#define IGNORE_ERRORS
static S32 check_prog_ok( GLuint * prog )
{
#ifndef IGNORE_ERRORS
GLint ok = 0;
glGetProgramiv( *prog, GL_LINK_STATUS, &ok );
if ( !ok )
{
char errors[ 512 ];
@rygorous
rygorous / gist:8908164
Created February 10, 2014 00:16
Game changer.
static __m128i const shuffles[16] = {
#define _ -1 // for readability
{ _,_,_,_, _,_,_,_, _,_,_,_, _,_,_,_ }, // 0000
{ 0,1,_,_, _,_,_,_, _,_,_,_, _,_,_,_ }, // 0001
{ _,_,_,_, 0,1,_,_, _,_,_,_, _,_,_,_ }, // 0010
{ 0,1,_,_, 2,3,_,_, _,_,_,_, _,_,_,_ }, // 0011
{ _,_,_,_, _,_,_,_, 0,1,_,_, _,_,_,_ }, // 0100
{ 0,1,_,_, _,_,_,_, 2,3,_,_, _,_,_,_ }, // 0101
{ _,_,_,_, 0,1,_,_, 2,3,_,_, _,_,_,_ }, // 0110
{ 0,1,_,_, 2,3,_,_, 4,5,_,_, _,_,_,_ }, // 0111
@rygorous
rygorous / gist:9540422
Created March 14, 2014 01:10
Diagnostic class: ZALGO.
In file included from /usr/include/c++/4.6/algorithm:63:0,
from error_code.cpp:2:
/usr/include/c++/4.6/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator*, std::vector > >, _Tp = int]’:
/usr/include/c++/4.6/bits/stl_algo.h:4403:45: instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator*, std::vector > >, _Tp = int]’
error_code.cpp:8:89: instantiated from here
͢/҉ùs͟r̶/̸incl͞u̴de/c++͏/4.6/͠bi͘t͢s/stl_al̵g̛o.h:1͏62:͞4:͏ e̷rr͝o͢r: no m͜a̷t̀ch̵ ͢for͡ ̶‘͏op̸e̕r̴a҉to͡r͟==̕’̀ in ‘̵_̀_̡fi͟rşt.__̴g͘n͘u_c͠x̡x̴:҉:͢_̡_͜n͘orma̸l_҉it͠erat̡o̵r̨::op͠e̷r͜at̸o͡r* ̢[҉wi̶t̢h͝ ̶_Iter̴ato̴r͡ ͝=̨ ͜s̷t̨d::̸v͏eçtor*, _҉C͡on͘t̛aine͟r ͝= ͘s̷td::̕v̨ect̸or >,̧ ͞_̢_g҉nu_c̀x͢x̵:̵:_͞_n͘o͟r̴m̷a̸l_ite̢r҉a͢tor͘::́rȩf̡ȩr͠e͟n̛ce =͡ śtd:̡:ve͜ćtor̸&]̸()͜ ͢==͝ __̸v̀al’
͢/̕u̸sr͘/̨in͠ćl͏u̷de̸/c++/͢4̡.̨6/́b̶it̢
@rygorous
rygorous / gl_leak_check.c
Last active August 29, 2015 13:57
DYI GL object leak checker.
static void check_for_leaks()
{
GLuint max_id = 10000; // better idea would be to keep track of assigned names.
GLuint id;
// if brute force doesn't work, you're not applying it hard enough
for ( id = 1 ; id <= max_id ; id++ )
{
#define CHECK( type ) if ( glIs##type( id ) ) fprintf( stderr, "GLX: leaked " #type " handle 0x%x\n", (unsigned int) id )
CHECK( Texture );
@rygorous
rygorous / gist:9623065
Created March 18, 2014 16:01
Quadrics / distance from planes
Okay, to make this simpler I'll write:
p = (x, y, z)^T
q_i = (x_i, y_i, z_i)^T
g_i = (grad f)(q_i)
And I'll also assume that f(x,y,z) = c not w (since I'll be using w for homogeneous coords!)
then
@rygorous
rygorous / simplex_shuffle.glsl
Created May 1, 2014 20:20
Shuffle for simple noise.
// ---- original code
// when declaring this as const, FPS drops from 30fps to 4fps on NV. wat?
int T[8] = int[8](0x15,0x38,0x32,0x2c,0x0d,0x13,0x07,0x2a);
int b0(int N, int B) { return (N>>B) & 1; }
int b(ivec3 p, int B) {
return T[b0(p.x,B)<<2 | b0(p.y,B)<<1 | b0(p.z,B)];
}
#if defined(__RADXENON__) || defined(BINKTEXTURES_GL) || defined(__RADNT__) || \
defined(__RADPS3__) || defined(__RAD3DS__) || defined(__RADPSP2__) || \
defined(__RADWIIU__) || defined(__RADXBOXONE__) || defined(__RADPS4__) || \
defined(__RADWINRTAPI__)
//
// we only have to compile the shaders on Xenon, PS3 and PC, they
// are statically defined on Xbox1, Wii, and NGC
//
@rygorous
rygorous / content_log.txt
Created May 4, 2014 08:29
Steam trashing my disk like crazy while downloading - content_log says this (multiple servers)
[2014-05-04 01:24:45] Scheduler update appID 49520: Priority Last, legacy=no, restore=""
[2014-05-04 01:24:45] AppID 49520 state changed : 0x00000502 = Update Required,Update Running,Update Started,
[2014-05-04 01:24:45] AppID 49520 state changed : 0x00010502 = Update Required,Update Running,Update Started,Reconfiguring,
[2014-05-04 01:24:45] AppID 49520 state changed : 0x00000502 = Update Required,Update Running,Update Started,
[2014-05-04 01:24:45] AppID 49520 state changed : 0x00300502 = Update Required,Update Running,Update Started,Downloading,Staging,
[2014-05-04 01:24:45] Starting update AppID 49520: download 4229636432/9612740848, store 0/0, reuse 0/0, stage 4734440959/10850295279
[2014-05-04 01:24:45] Update job for app 49520 canceled: Failed updating depot 49521 while unpacking bad chunk "e983a5ce80f17f6d5a6775a4628ee0ebf9769a01" from "content6.steampowered.com" (Unpack failed (c:1168,u:0,b:2048)) (Suspended)
[2014-05-04 01:24:45] AppID 49520 state changed : 0x00b00502 = Update Required,Update Runnin
// We temporarily disable this warning for the shared interface portions
#pragma warning (push)
#pragma warning (disable: 4201) // nonstandard extension used : nameless struct/union
#include <windows.h>
#include <d3d11.h>
#include "gdraw.h"
#include "iggy.h"
#include <string.h>
#include <math.h>
@rygorous
rygorous / gist:8da6651b597f3d825862
Created May 14, 2014 00:49
Rotate vector by quaternion
// Rotate vector v by q (=compute qvq*)
vec3 t = 2 * cross(q.xyz, v);
vec3 rv = v + q.w * t + cross(q.xyz, t);