Skip to content

Instantly share code, notes, and snippets.

@sakrist
sakrist / homeNAS
Created November 26, 2023 16:05
Building home NAS
Here I will list my components, software setup and some steps that I did.
@sakrist
sakrist / TextureResource+extension.swift
Last active March 26, 2023 21:53
Extension to TextureResource of RealityKit. This is the way how to control multiple materials in RealityKit
//
// TextureResource+extension.swift
//
// Created by Volodymyr Boichentsov on 24/03/2023.
//
import Foundation
import Metal
import MetalKit
import RealityKit
@sakrist
sakrist / build_gmp.sh
Last active November 9, 2022 06:27
GMP and MPFR compile for iOS
#!/bin/bash
#===============================================================================
# Filename: build_gmp.sh
# Created by Volodymyr Boichentsov on 18/09/2015.
# Copyright © 2015 3D4Medical. All rights reserved.
# Property of 3D4Medical.
#===============================================================================
#-emit-obj -fembed-bitcode -disable-llvm-optzns -O3
# Builds a Libpng framework for the iPhone and the iPhone Simulator.
# Creates a set of universal libraries that can be used on an iPhone and in the
# iPhone simulator. Then creates a pseudo-framework to make using libpng in Xcode
# less painful.
#
# To configure the script, define:
# IPHONE_SDKVERSION: iPhone SDK version (e.g. 8.1)
#
# Then go get the source tar.bz of the libpng you want to build, shove it in the
# same directory as this script, and run "./libpng.sh".
typedef struct FontHeader {
int32_t fVersion;
uint16_t fNumTables;
uint16_t fSearchRange;
uint16_t fEntrySelector;
uint16_t fRangeShift;
}FontHeader;
typedef struct TableEntry {
uint32_t fTag;
@sakrist
sakrist / screenshot.mm
Last active August 28, 2020 06:21
Getting screenshot on iOS OpenGL ES
- (UIImage*) takePicture {
int s = 1;
UIScreen* screen = [UIScreen mainScreen];
if ([screen respondsToSelector:@selector(scale)]) {
s = (int) [screen scale];
}
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
// warping hexagons, WIP. @psonice_cw
// I'm sure there's a less fugly way of making a hexagonal grid, but hey :)
// Maybe - Try this...
// Simplify!
#ifdef GL_ES
precision mediump float;
#endif
@sakrist
sakrist / gist:f97499de2dd6687d6403
Last active April 22, 2020 06:40
Objective-C Language Enhancements

Objective-C APIs can now express the “nullability” of parameters, return types, properties, variables, etc. For example, here is the expression of nullability for several UITableView APIs:

-(void)registerNib:(nonnull UINib *)nib forCellReuseIdentifier:(nonnull NSString *)identifier;
-(nullable UITableViewCell *)cellForRowAtIndexPath:(nonnull NSIndexPath)indexPath;
@property (nonatomic, readwrite, retain, nullable) UIView *backgroundView;

The nullability qualifiers affect the optionality of the Objective-C APIs when in Swift. Instead of being imported as implicitly-unwrapped optionals (e.g., UINib!), nonnull-qualified types are imported as non-optional (e.g., UINib) and nullable-qualified types are imported as optional (e.g., UITableViewCell?), so the above APIs will be seen in Swift as:

func registerNib(nib: UINib, forCellReuseIdentifier identifier: String)
@sakrist
sakrist / gist:7912905
Created December 11, 2013 15:55
FXAA algorithm
float FXAA_SPAN_MAX = 8.0;
float FXAA_REDUCE_MUL = 1.0/8.0;
float FXAA_REDUCE_MIN = 1.0/128.0;
vec3 rgbNW=texture2D(buf0,texCoords+(vec2(-1.0,-1.0)/frameBufSize)).xyz;
vec3 rgbNE=texture2D(buf0,texCoords+(vec2(1.0,-1.0)/frameBufSize)).xyz;
vec3 rgbSW=texture2D(buf0,texCoords+(vec2(-1.0,1.0)/frameBufSize)).xyz;
vec3 rgbSE=texture2D(buf0,texCoords+(vec2(1.0,1.0)/frameBufSize)).xyz;
vec3 rgbM=texture2D(buf0,texCoords).xyz;
@sakrist
sakrist / pbr.glsl
Created July 24, 2017 08:14 — forked from galek/pbr.glsl
PBR GLSL SHADER
in vec2 v_texcoord; // texture coords
in vec3 v_normal; // normal
in vec3 v_binormal; // binormal (for TBN basis calc)
in vec3 v_pos; // pixel view space position
out vec4 color;
layout(std140) uniform Transforms
{
mat4x4 world_matrix; // object's world position