Skip to content

Instantly share code, notes, and snippets.

View mosra's full-sized avatar

Vladimír Vondruš mosra

View GitHub Profile
@aras-p
aras-p / GraphicsCapsGLES.h
Created April 26, 2015 07:56
Part of runtime flags that kick in different things on our GL implementaton
int maxAASamplesConst; // gles2 img/apple/ext extensions all use different constants (facepalm)
int halfConst; // gles2 and gles3 have different constants for half float type
int texSRGBAConst; // gles2 (without 'internal format' ext) and gles3 have different constants for SRGB RGBA texture type
int texSRGBConst; // gles2 (without 'internal format' ext) and gles3 have different constants for SRGB RGB texture type
int etcFormatConst; // gles2/gles3 have different standard etc formats
bool isPvrGpu;
bool isMaliGpu;
bool isAdrenoGpu;
bool isTegraGpu;
@cdwfs
cdwfs / cube-strip
Last active April 3, 2025 20:48
Rendering a cube as a 14-index triangle strip
; How to render a cube using a single 14-index triangle strip
; (Reposted from http://www.asmcommunity.net/forums/topic/?id=6284#post-45209)
; Drawbacks: no support for per-vertex normals, UVs, etc.
;
; 1-------3-------4-------2 Cube = 8 vertices
; | E __/|\__ A | H __/| =================
; | __/ | \__ | __/ | Single Strip: 4 3 7 8 5 3 1 4 2 7 6 5 2 1
; |/ D | B \|/ I | 12 triangles: A B C D E F G H I J K L
; 5-------8-------7-------6
; | C __/|
@dwilliamson
dwilliamson / SphereIndexing.glsl
Last active December 8, 2017 17:48
Given a 3D point on the sphere, map to a unique, sub-divided triangle index in O(1) with no recursive searching or table lookups.
// Some shitty boolean logic code because WebGL...
bool and(int x, int y)
{
return mod(float(x), exp2(float(y))) != 0.0;
}
int GetTriangleIndex(vec3 position)
{
// TODO: Add integer arithmetic to simplify the boolean logic.
anonymous
anonymous / gist:de6b81c556b5dc7cdc8b
Created February 20, 2015 01:42
Kernel panic in latest OS X in 10 lines of C
#include <unistd.h>
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <mach-o/dyld.h>
int
main (int argc, char * argv[])
{
volatile char * library;
const mach_vm_size_t page_size = getpagesize ();
@nlguillemot
nlguillemot / gist:add8ef4679581c76e000
Last active August 29, 2015 14:14
updated glsl.xml that handles identifiers. previously, the 3 in the identifier or macro name "vertic3s" would become highlighted. Also fixed "0" not being highlighted in layouts along with hex/octal constants being used in layouts.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!-- the version of this file shows the largest supported OpenGL version, second digit is the minor patch level (Y.XP = supports GLSL X.Y0 with patchlevel P -->
<language name="GLSL" section="Sources" extensions="*.glsl;*.vsh;*.vert;*.tcsh;*.tcs;*.tesh;*.tes;*.gsh;*.geo;*.geom;*.fsh;*.frag;*.csh;*.cs" mimetype="text/x-glslsrc" version="4.40" kateversion="2.4" author="Robert Menzel ([email protected])" license="LGPL">
<highlighting>
<!-- ####################################################################################################### keywords -->
<list name="keywordsCompatibility">
<!-- compatibility mode, older GLSL versions -->
<item>attribute</item>
@bjornblissing
bjornblissing / CMakeManifest.txt
Last active July 30, 2024 22:12
CMake script to add manifest to exe-file
# Amend manifest to tell Windows that the application is DPI aware (needed for Windows 8.1 and up)
IF (MSVC)
IF (CMAKE_MAJOR_VERSION LESS 3)
MESSAGE(WARNING "CMake version 3.0 or newer is required use build variable TARGET_FILE")
ELSE()
ADD_CUSTOM_COMMAND(
TARGET ${TARGET_TARGETNAME}
POST_BUILD
COMMAND "mt.exe" -manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\dpiawarescaleing.manifest\" -inputresource:\"$<TARGET_FILE:${TARGET_TARGETNAME}>\"\;\#1 -outputresource:\"$<TARGET_FILE:${TARGET_TARGETNAME}>\"\;\#1
COMMENT "Adding display aware manifest..."
@rygorous
rygorous / winrt_basic.cpp
Created April 7, 2014 18:11
WinRT basic D3D example, one file; all cube rendering/framework-y stuff removed, this just clears the screen every frame.
#include <wrl/client.h>
#include <d3d11_1.h>
#include <agile.h>
#include <ppl.h>
#include <ppltasks.h>
using namespace Microsoft::WRL;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
@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 );
@vittorioromeo
vittorioromeo / FastFunc.hpp
Last active August 24, 2023 08:15
Don Clugston's fast delegate C++11 implementation
#ifndef SSVU_FASTFUNC
#define SSVU_FASTFUNC
#include <cstring>
#include <type_traits>
#include <cassert>
#include <cstddef>
#include <memory>
#include <new>
#include <utility>
@aras-p
aras-p / preprocessor_fun.h
Last active May 3, 2025 13:47
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,