#!/bin/bash

function runCompiz() {
    if ( [ -e /usr/lib/compizconfig/backends/libini.so ] || [ -e /usr/lib64/compizconfig/backends/libini.so ] )
        then
            exec compiz --replace --sm-disable --ignore-desktop-hints ccp &&
            emerald --replace $@
        else
        	exec compiz --replace --sm-disable --ignore-desktop-hints glib ini matecompat $@
        fi
}

ISSW=`glxinfo | grep "Software Rasterizer" -c`

# Try with direct rendering
HAVETFP=`glxinfo | grep texture_from_pixmap -c`

if ( [ $ISSW == 0 ] && [ $HAVETFP -gt 2 ] ); then 
	runCompiz $@
fi

# Try again with indirect rendering
export LIBGL_ALWAYS_INDIRECT=1

HAVETFP=`glxinfo | grep texture_from_pixmap -c`

if ( [ $ISSW == 0 ] && [ $HAVETFP -gt 2 ] ); then 
	runCompiz $@
fi

# Fall back to marco
exec marco $@
