
//**************************************************************************/
// Copyright (c) 2008 Autodesk, Inc.
// All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk license
// agreement provided at the time of installation or download, or which
// otherwise accompanies this software in either electronic or hard copy form.
//
//**************************************************************************/
// DESCRIPTION:
// CREATED: October 2008
//**************************************************************************/

#ifndef __MUDBOXSDK_MUDBOX_H__
#define __MUDBOXSDK_MUDBOX_H__

#pragma once 
 
#ifdef _WIN32
#pragma warning( disable : 4251 )
#endif
/*****
 * System headers
 *
 * Usage:
 *   - Ensure size_t is defined properly.
 */
#include <stdlib.h>
#include <stdio.h>
#ifdef _WIN32
#include <intrin.h>
#endif

#if defined(JAMBUILD)
#include <Mudbox/dllinterface.h>
#else
#include "dllinterface.h"
#endif

// defines
#ifdef _DEBUG 
#ifndef MB_DEBUG
#define MB_DEBUG
#endif
#endif

// version info, short & simple for, similar to Qt version info
#define MB_SDK_VERSION_STRING "1.0.0"

// MB_SDK_VERSION is (major << 16) + (minor << 8) + patch.
//
// Each pair of #s after the x represent a version # (major, minor, patch).
// Hexadecimal is the base and each digit represents 4 bits, so 16 different
// combinations.  So since the version takes up 2 digits = 8 bits = 256 possible
// versions for each group.
#define MB_SDK_VERSION 0x010000
// can be used like #if (MB_SDK_VERSION >= MB_SDK_VERSION_CHECK(1, 1, 0))
#define MB_SDK_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))

#ifndef MB_ASSERT
	#if defined(MB_DEBUG)
		#if defined(_WIN32)
			#define MB_ASSERT( condition ) { if (!(condition)&&mudbox::AssertFailed( __FILE__, __LINE__, #condition, "" )) __debugbreak(); }
		#else
			#define MB_ASSERT( condition ) { if (!(condition)) mudbox::AssertFailed( __FILE__, __LINE__, #condition, "" ); }
		#endif
	#else
		#define MB_ASSERT( condition ) {}
	#endif
#endif
#ifndef MB_VERIFY
	#ifdef MB_DEBUG
		#define MB_VERIFY( condition ) MB_ASSERT( condition )
	#else
		#define MB_VERIFY( condition ) { bool b___ = condition; b___; }
	#endif
#endif


#ifndef MB_VERIFY_EQ
	#ifdef MB_DEBUG
		#define MB_VERIFY_EQ( condition_, value_ ) MB_ASSERT( (condition_) == (value_) )
	#else
		#define MB_VERIFY_EQ( condition_, value_ ) (condition_)
	#endif
#endif

#ifndef MB_VERIFY_TRUE
	#ifdef MB_DEBUG
		#define MB_VERIFY_TRUE( condition_ ) MB_ASSERT( (condition_) )
	#else
		#define MB_VERIFY_TRUE( condition_ ) (condition_)
	#endif
#endif

#define MB_ONBUG( condition ) MB_ASSERT( !(condition) ); if ( condition )
#define MB_SAFELY( condition ) MB_ASSERT( condition ); if ( condition )


#if defined( MB_TEST ) || defined( MB_DEBUG )

#if defined(_MSC_VER)
#define MB_TIMER( name ) static int ____iTimerIndex = -1; mudbox::Timer ____cTimer( __FUNCTION__" - "##name, ____iTimerIndex );
#else
#define MB_TIMER( name ) static int ____iTimerIndex = -1; mudbox::Timer ____cTimer( __FILE__ " - " name, ____iTimerIndex );
#endif

#else
#define MB_TIMER( name ) ;
#endif
#if defined(__GNUC__)
#define MB_ERROR throw (new mudbox::Error( "", Error::codeUnspecified, __PRETTY_FUNCTION__, __FILE__, __LINE__ ))->Format
#else
#define MB_ERROR throw (new mudbox::Error( "", Error::codeUnspecified, __FUNCTION__, __FILE__, __LINE__ ))->Format
#endif

#define MB_PLUGIN( name, description, author, url, initializer ) mudbox::Plugin __myplugin( name, description, author, url, __DATE__" "__TIME__, initializer );

#if defined(QT_VERSION) || defined(MB_USE_QT)
    // Avoid X11's define clash.
    #include "MudBoxX11Clean.h"

	//#if QT_VERSION < 0x040200
	//  #error "Mudbox SDK needs Qt version 4.2 or later. Update your Qt or if you dont want custom widgets include mudbox.h before the Qt headers."
	//#endif
	#include <QtCore/QString>
	#include <QtGui/QLabel>
#endif

// get rid of win32 api hacks
#undef MessageBox

#ifndef _MSC_VER
#ifndef __forceinline
#define __forceinline inline
#endif
#endif

#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
// "Microosft C Compiler" and "Intel C Compiler" supports OpenMP
#define __MUDBOX_HAS_OPENMP_LIB__ 1
#endif

#if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 2)
// GCC 4.2 supports OpenMP.
#define __MUDBOX_HAS_OPENMP_LIB__ 1
#endif

class QColor;
class QImage;
class QString;
class QWidget;
class XMesh;
class XSubdivisionLevel;
class Manipulator;

namespace mudbox
{
	class AttributeWidget;
	class BrushOperation;

	// types
	typedef long long int64;
	typedef unsigned long long uint64;

	template <typename type> class Array;
	template <typename type> class Store;

	// functions
	template < typename type >
	inline type Min( type a, type b ) { return a < b ? a : b; };
	template < typename type >
	inline type Max( type a, type b ) { return a > b ? a : b; };
	bool MBDLL_DECL AssertFailed( const char *sSourceFile, int iSourceLine, const char *sCondition, const char *sMessage );
    
	float MBDLL_DECL Modf( float value );
};

	// classes
#if defined(JAMBUILD)
	#include <Mudbox/error.h>
	#include <Mudbox/array.h>
	#include <Mudbox/node.h>
	#include <Mudbox/stream.h>
	#include <Mudbox/plugin.h>
	#include <Mudbox/treenode.h>
	#include <Mudbox/math.h>
	#include <Mudbox/topology.h>
	#include <Mudbox/layer.h>
	#include <Mudbox/mesh.h>
	#include <Mudbox/preferences.h>
	#include <Mudbox/tray.h>
	#include <Mudbox/transformation.h>
	#include <Mudbox/image.h>
	#include <Mudbox/imagePlane.h>
	#include <Mudbox/material.h>
	#include <Mudbox/renderer.h>
	#include <Mudbox/subdivision.h>
	#include <Mudbox/geometry.h>
	#include <Mudbox/light.h>
	#include <Mudbox/camera.h>
	#include <Mudbox/scene.h>
	#include <Mudbox/interface.h>
	#include <Mudbox/kernel.h>
	#include <Mudbox/importexport.h>
	#include <Mudbox/operation.h>
	#include <Mudbox/viewport.h>
	#include <Mudbox/selectionset.h>
	#include <Mudbox/nurbs.h>
	#include <Mudbox/brush.h>
	#include <Mudbox/brushmask.h>
    #include <Mudbox/ConvolutionKernel.h>
    #include <Mudbox/ImageFilter.h>
#else
	#include "error.h"
	#include "array.h"
	#include "node.h"
	#include "stream.h"
	#include "plugin.h"
	#include "treenode.h"
	#include "math.h"
	#include "topology.h"
	#include "layer.h"
	#include "mesh.h"
	#include "preferences.h"
	#include "tray.h"
	#include "transformation.h"
	#include "image.h"
	#include "imagePlane.h"
	#include "material.h"
	#include "renderer.h"
	#include "subdivision.h"
	#include "geometry.h"
	#include "light.h"
	#include "camera.h"
	#include "scene.h"
	#include "interface.h"
	#include "kernel.h"
	#include "importexport.h"
	#include "operation.h"
	#include "viewport.h"
	#include "selectionset.h"
	#include "nurbs.h"
	#include "brush.h"
	#include "brushmask.h"
    #include "ConvolutionKernel.h"
    #include "ImageFilter.h"
#endif

#ifdef QT_VERSION
#if defined(JAMBUILD)
#include <Mudbox/widgets.h>
#else
#include "widgets.h"
#endif
#endif

#ifdef MB_DEBUG
#define MB_CHECK_GL_ERROR Kernel()->GLCheckError( __FILE__, __FUNCTION__, __LINE__ );
#define MB_CHECK_GL_STATES Kernel()->GLCheckStates( __FILE__, __FUNCTION__, __LINE__ );
#define MB_CHECK_CG_ERROR {CGerror error;\
	const char* const lastErrorString = cgGetLastErrorString(&error); \
	if( error != CG_NO_ERROR ) Kernel()->Log("Cg error: '%s'", lastErrorString);}
#else
#define MB_CHECK_GL_ERROR
#define MB_CHECK_GL_STATES
#define MB_CHECK_CG_ERROR
#endif

#ifdef PLUGIN
	#undef DLL
	#undef PLUGIN
#endif

#endif
