Skip to content

Instantly share code, notes, and snippets.

@giraphics
giraphics / run.sh
Last active September 16, 2022 18:06
Enabling Metal Validation Layer through command line application
# Enable Metal validation layer: 0FF-0, ON-1
export METAL_DEVICE_WRAPPER_TYPE=1
export METAL_ERROR_MODE=5
export METAL_DEBUG_ERROR_MODE=5
# Clean and make
make clean && make
# Execute
./YourExecutableName
@giraphics
giraphics / ImplicitDeallocateModel.cpp
Last active November 20, 2017 12:41
Implicit deallocation model
// This example shows a demo as per existing Pan3D Model.
// Here, each class is responsible to release it own resources.
#include <iostream>
using namespace std;
class Position // GPU allocator/deallocator for position buffers
{
public:
Position() { cout << "Position Ctor" << endl; Allocate(); }
@giraphics
giraphics / ExplicitDeallocateModel.cpp
Last active November 29, 2017 01:56
Explicit deallocation model
// This example shows a demo as per new deallocation model suggestion.
// Here, the derive class explicitly deallocates
// a. owned resources.
// b. based class resources
#include <iostream>
using namespace std;
class Position // GPU allocator/deallocator for position buffers
{
#include <QtCore>
#include <QtGui>
#include <QtWidgets>
QImage createImageWithFBO()
{
QSurfaceFormat format;
format.setMajorVersion(3);
format.setMinorVersion(3);
@giraphics
giraphics / CmdLineNSApp.mm
Created September 13, 2018 04:56
Command line Cocoa application
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
@interface MyAppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *window;
}
@end
@implementation MyAppDelegate
#import <Cocoa/Cocoa.h>
// Ideally the interface should in .h
@interface Photo : NSObject {
NSString* caption;
NSString* photographer;
NSString* instrument;
NSString* musician;
}
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <QuartzCore/CAMetalLayer.h>
@interface MyAppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *window;
}
@end
@giraphics
giraphics / demo.pro
Last active October 7, 2018 04:59
Cannot find TargetConditionals.h
# FIX: force the macosxsdk to 10.12
# macx {
# QMAKE_MAC_SDK = macosx10.12
# }
#
# With the above change ensure you first delete the existing makefile and .qmake.stash from the directory. Note .qmake.stash is a hidden file (view it ls -la)
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
DEFINES += QT_DEPRECATED_WARNINGS
@giraphics
giraphics / gist:734d077e9492ca374712e50ac39af4a3
Created December 23, 2018 17:16
Retrieving parent object from structure's member
// Example program
#include <iostream>
#include <string>
#include <cstddef>
#include <iostream>
using namespace std;
template <typename Owner, typename Tag>
@giraphics
giraphics / gist:6d7659094273b0276cdf71a1c319b985
Created September 2, 2019 10:43
MEMORY MANAGEMENT HELPER
#define TO_POINTER(value) ((void*)(value))
#define FORWARD_POINTER(pointer, offset) ((void*)((uintptr_t)TO_POINTER(pointer) + offset))
#define POINTER_TO_UINT(pointer) ((uintptr_t)(pointer))
#define ALIGN_POINTER(pointer, base) TO_POINTER(((POINTER_TO_UINT(pointer))+((base)-1L)) & ~((base)-1L))
or
#define ALIGN_POINTER(pointer, base) TO_POINTER((UT_POINTER_TO_UINT(pointer)) + ((UT_POINTER_TO_UINT(pointer)) % base))
#define IS_POINTER_ALIGNED(pointer, alignment) (((uintptr_t)pointer & (uintptr_t)(alignment - 1L)) == 0)
or