Skip to content

Instantly share code, notes, and snippets.

@giraphics
giraphics / gist:f0573cfd41d90ba7ff8f55da4286df70
Created December 1, 2019 04:04
How to merge two “ar” static libraries into one?
######################################################################################################
# You can extract the object from both the .a files and create your .a file using the extracted .os: #
######################################################################################################
# Make a .tmp directory where we will extract our .o file later we delete this dir
mkdir .tmp
cd .tmp
ar -x ../libBMDGfx.a
ar -x ../Graphics/3rdParty/FontSupport/harfbuzz-master/build/libharfbuzz.a
ar -rc ../libGfx.a *.o
@giraphics
giraphics / uniquePtrCustomDeleter.cpp
Created October 19, 2019 05:32
Unique Pointer CustomDeleter
template <class T>
struct GfxCircularQueueDefaultDeleter
{
void operator()(T* p_Buffer) const
{
LOG_INFO("Circlular queue array deleted, queue is empty now....");
delete p_Buffer;
}
};
@giraphics
giraphics / uniquePtrCustomDeleter.cpp
Created October 19, 2019 05:31
Unique Pointer CustomDeleter
template <class T>
struct GfxCircularQueueDefaultDeleter
{
void operator()(T* p_Buffer) const
{
LOG_INFO("Circlular queue array deleted, queue is empty now....");
delete p_Buffer;
}
};
@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
@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 / 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
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <QuartzCore/CAMetalLayer.h>
@interface MyAppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *window;
}
@end
#import <Cocoa/Cocoa.h>
// Ideally the interface should in .h
@interface Photo : NSObject {
NSString* caption;
NSString* photographer;
NSString* instrument;
NSString* musician;
}
@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
#include <QtCore>
#include <QtGui>
#include <QtWidgets>
QImage createImageWithFBO()
{
QSurfaceFormat format;
format.setMajorVersion(3);
format.setMinorVersion(3);