Skip to content

Instantly share code, notes, and snippets.

@bazhenovc
bazhenovc / the_sane_rendering_manifesto.md
Last active April 13, 2024 12:57
The Sane Rendering Manifesto

The Sane Rendering Manifesto

The goal of this manifesto is to provide an easy to follow and reasonable rules that realtime and video game renderers can follow.

These rules highly prioritize image clarity/stability and pleasant gameplay experience over photorealism and excess graphics fidelity.

Keep in mind that shipping a game has priority over everything else and it is allowed to break the rules of the manifesto when there are no other good options in order to ship the game.

Do not use dynamic resolution.

template <unsigned x> struct PopCount
{
enum {
a = x - ((x >> 1) & 0x55555555),
b = (((a >> 2) & 0x33333333) + (a & 0x33333333)),
c = (((b >> 4) + b) & 0x0f0f0f0f),
d = c + (c >> 8),
e = d + (d >> 16),
result = e & 0x0000003f
};
template <typename T>
constexpr unsigned BitsRequired(T min, T max)
{
template <unsigned x> struct PopCount
{
enum {
a = x - ((x >> 1) & 0x55555555),
b = (((a >> 2) & 0x33333333) + (a & 0x33333333)),
c = (((b >> 4) + b) & 0x0f0f0f0f),
d = c + (c >> 8),
@bazhenovc
bazhenovc / nvapi_force_discrete_card.cpp
Created September 7, 2016 15:03
nvapi force discrete card
void nvidiaForceUseDiscreteCard()
{
NvAPI_Status status = NvAPI_Initialize();
if(status != NVAPI_OK) return;
NvDRSSessionHandle hSession = 0;
status = NvAPI_DRS_CreateSession(&hSession);
if(status != NVAPI_OK) return;
status = NvAPI_DRS_LoadSettings(hSession);
/// Increase the reference count on the object.
template< class T, class DeletePolicy >
inline void ThreadSafeRefCount< T, DeletePolicy >::addRef()
{
dFetchAndAdd( mRefCount, 2 );
}
/// Decrease the object's reference count and delete the object, if the count
/// drops to zero and claiming the object by the current thread succeeds.
@bazhenovc
bazhenovc / v8_wrap_class.cpp
Created September 28, 2015 15:25 — forked from mythagel/v8_wrap_class.cpp
Complete example of binding a C++ class with Google V8.
/*
* v8_wrap_class.cpp
*
* Created on: 14/01/2013
* Author: nicholas
* License: public domain
*/
/* CMakeLists.txt
project(v8_wrap_class)
class Thread
{
private:
uint8_t storage[kThreadDataStorage];
public:
typedef void (*ThreadWorkerFunction)(void*);
void StartWorkerFunction(ThreadWorkerFunction func);
@bazhenovc
bazhenovc / thread.cpp
Last active September 23, 2015 01:04
class Thread
{
public:
typedef void (*ThreadWorkerFunction)(void*);
void StartWorkerFunction(ThreadWorkerFunction func);
template <typename F, typename ...Args>
inline void Start(F&& func, Args&&... args)
{
#include "shaders/common/torque.hlsl"
struct VS_OUTPUT
{
float4 hpos : SV_POSITION;
float2 uv : TEXCOORD0;
};
namespace internal
{
template <typename R, typename ...Args>
struct FunctionImplBase
{
virtual FORCE_INLINE ~FunctionImplBase() {}
virtual R Invoke(Args... args) const = 0;