Skip to content

Instantly share code, notes, and snippets.

View sortofsleepy's full-sized avatar

Joe sortofsleepy

View GitHub Profile
@sortofsleepy
sortofsleepy / utils.h
Created February 24, 2020 22:10
useful c++ stuff
//! borrowed from https://github.com/wdlindmeier/Cinder-Metal/blob/master/include/MetalHelpers.hpp
template <typename T, typename U >
const U static inline convert( const T & t )
{
U tmp;
memcpy(&tmp, &t, sizeof(U));
U ret = tmp;
return ret;
}

Building Dawn on Windows

Writing this here cause it was one heck of an adventure to finally get Dawn built on Windows. It's unclear if things are truly built and whether or not there might be more issues to resolve, but for now, by following these instructions, you should be able to at the very least, get Dawn built, set things up properly without any compiler complaints, and with a slight tweak, get the samples up and running.

Note that Google has suggested that the current build system setup is not recommended for producing libraries to be included into your own projects, but there is the desire to include CMake build support for this purpose in the future.

As you might imagine, Dawn is stil being developed so things are bound to be broken. Hopefully things will smooth out as the project reaches it's first major milestone. I am just a casual hobyist so I have no idea as to the current progress but there is a mailing list you can keep up with [here](https://groups.google.com/forum/#!forum/dawn-g

@sortofsleepy
sortofsleepy / constants.ts
Created January 30, 2020 21:11
WebGPU constants aliased to shorter or more sensible names. Will apply on top of the window variable
export default function setConstants(){
if(navigator.gpu !== undefined){
let constants = {
// ============= SHADER STAGES ============ //
VERTEX_STAGE:GPUShaderStage.VERTEX,
FRAGMENT_STAGE:GPUShaderStage.FRAGMENT,
COMPUTE_STAGE:GPUShaderStage.COMPUTE,
@sortofsleepy
sortofsleepy / gist:e95f74ecd30522b83ba884d2ce62c23c
Created January 24, 2020 13:57
add MSVC checks + how to add options in CMake
if(MSVC_VERSION GREATER_EQUAL "1900")
include(CheckCXXCompilerFlag)
add_compile_options("/std:c++latest")
endif()
@sortofsleepy
sortofsleepy / utils.hpp
Created January 17, 2020 00:12
Helpful utilities
//
// utils.h
// Test
//
// Created by josephchow on 1/16/20.
//
#ifndef utils_h
#define utils_h
@sortofsleepy
sortofsleepy / main.cpp
Created January 11, 2020 16:57
How to initialize Cinder from main function instead of macro
int __stdcall WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/)\
{
HMODULE livepp = lpp::lppLoadAndRegister(L"../../../LivePP","project");
lpp::lppEnableAllCallingModulesSync(livepp);
lpp::lppInstallExceptionHandler(livepp);
cinder::app::RendererRef renderer(new ci::app::RendererGl);
@sortofsleepy
sortofsleepy / VIewController.h
Last active December 12, 2022 13:07
Basic setup of getting a Metal context up and running.
//
// ViewController.h
// metal.test
//
// Created by josephchow on 12/10/19.
// Copyright © 2019 josephchow. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Metal/Metal.h>
@sortofsleepy
sortofsleepy / array-setup.glsl
Last active September 30, 2019 22:47
Basic template for utilizing a texture as an array and setting it up with data at specific columns/rows
precision highp float;
// note - assuming OpenGL ES 2.0 - adjust as needed
// the number of items total you want to write out on each row
#define NUM 100
// the row of pixels to store, in this example positions
#define POSITION_ROW 2
vec2 uv = gl_FragCoord.xy;
//uv = fragCoord.xy / iResolution.xy;
uv.y -= u_RenderSize.y / 2.0;
uv.x -= u_RenderSize.x / 2.0;
vec2 coords = uv;
vec4 color = vec4(1.0,1.0,0.0,1.0);
float radius = 20.0;
@sortofsleepy
sortofsleepy / snippits.glsl
Last active December 19, 2019 01:50
Useful glsl snippits
// Helps to scale image uvs to fit variable surfaces.
// Note - still need to test but sounds promising and basic idea appeared to work based on case study.
// adapted from description by @lhbzr
// https://tympanus.net/codrops/2019/12/18/case-study-portfolio-of-bruno-arizio/
vec2 scaleToFit(vec2 resolution,vec2 imageResolution){
vec2 ratio = vec2(
min((resolution.x / resolution.y) / (imageResolution.x / imageResolution.y), 1.0),
min((resolution.y / resolution.x) / (imageResolution.y / imageResolution.x), 1.0)
);