Skip to content

Instantly share code, notes, and snippets.

View Kuranes's full-sized avatar

Tuan Kuranes Kuranes

View GitHub Profile
@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 );
@phaulos
phaulos / gist:9827541
Created March 28, 2014 07:58
Examples of subtly incorrect GLSL ES 3.1 snippets
// Implicit conversion in ndx = 0 assignment, should be ndx = 0u
for (uint ndx = 0; ndx < count; ndx+++)
...
// Implicit conversion in ndx+2, should be ndx+2u
uint ndx = ...;
myArray[ndx+2] = value;
// Implicit conversion, array.length() returns int
uint threadCount = ...;
console.highlight = function(text, sample) {
var escapedSample = sample.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
var reSample = new RegExp(escapedSample, 'g');
var args = [''];
var highlightedText = text.replace(reSample, function(match) {
args.push('background-color: #ffc', 'background-color: none');
return '%c' + match + '%c';
});
args[0] = highlightedText;
console.log.apply(console, args);
@dwilliamson
dwilliamson / GenerateSHConstants.c
Last active August 29, 2015 14:05
Generating SH constants from polynomial form in C-style comments
//
// Uses pycgen: https://github.com/Celtoys/pycgen
// Generates code for C, HLSL, CUDA and OpenCL
//
void SH_Y2(float3 n, cmp_out float y[9])
{
/*$pycgen
from math import pi
from math import sqrt
@jeromeetienne
jeromeetienne / consoleLogToScreen.js
Created September 25, 2014 13:55
console.log to screen - nice to debug mobile
//////////////////////////////////////////////////////////////////////////////////
// console.log to screen
//////////////////////////////////////////////////////////////////////////////////
;(function(){
var container = document.createElement('div')
container.dataset.name = 'consoleLogOnScreen'
container.style.width = '100%';
container.style.height = '100%';
container.style.position = 'absolute';
container.style.fontSize = '100%';
@pervognsen
pervognsen / dbg.el
Last active May 12, 2025 14:29
dbg.el
(require 'cl)
(require 'peg)
(defcustom dbg-mi-process-name "dbg-mi" "")
(defcustom dbg-mi-buffer-name "*dbg-mi*" "")
(defvar dbg-mi-process nil)
(defvar dbg-mi-buffer nil)
@pervognsen
pervognsen / asdf.el
Last active August 29, 2015 14:10
watch expressions with dbg.el
(defun dbg-watch (expression)
(interactive "sExpression: ")
(dbg-mi-command (list 'dbg-watch-handler expression) "-var-create - @ %s" (prin1-to-string expression)))
(defun dbg-watch-handler (status result expression)
(case status
((done)
(push (cons (cons 'expression expression) result) dbg-watches)))
(dbg-render-watches))
@ocornut
ocornut / printf_tips.cpp
Last active March 24, 2023 11:23
C/C++ tips for using printf-style functions
// C/C++ tips for using printf-style functions
// Lots of manipulation can be expressed simply and fast with printf-style formatting
// Also helps reducing the number of temporaries, memory allocations or copies
// ( If you are looking for a simple C++ string class that is printf-friendly and not heap-abusive,
// I've been using this one: https://github.com/ocornut/Str )
// If you are interested in a FASTER implementation of sprintf functions, see stb_sprintf.h
// https://github.com/nothings/stb/blob/master/stb_sprintf.h
// How to concatenate non-zero terminated strings
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Listing 2-2, Load Shaders From DOM</title>
<meta charset="utf-8">
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
void main() {
gl_Position = vec4(aVertexPosition, 1.0);
@gafferongames
gafferongames / delta_compression.cpp
Last active October 19, 2025 16:17
Delta Compression
/*
Delta Compression by Glenn Fiedler.
This source code is placed in the public domain.
http://gafferongames.com/2015/03/14/the-networked-physics-data-compression-challenge/
*/
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>