#ifndef _MRenderTargetManager
#define _MRenderTargetManager
//-
// ==========================================================================
// Copyright (C) 2010 Autodesk, Inc., and/or its licensors.  All
// rights reserved.
//
// The coded instructions, statements, computer programs, and/or related
// material (collectively the "Data") in these files contain unpublished
// information proprietary to Autodesk, Inc. ("Autodesk") and/or its
// licensors,  which is protected by U.S. and Canadian federal copyright law
// and by international treaties.
//
// The Data may not be disclosed or distributed to third parties or be
// copied or duplicated, in whole or in part, without the prior written
// consent of Autodesk.
//
// The copyright notices in the Software and this entire statement,
// including the above license grant, this restriction and the following
// disclaimer, must be included in all copies of the Software, in whole
// or in part, and all derivative works of the Software, unless such copies
// or derivative works are solely in the form of machine-executable object
// code generated by a source language processor.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
// AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
// WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
// NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
// OR ARISING FROM A COURSE OF DEALING, USAGE, OR TRADE PRACTICE. IN NO
// EVENT WILL AUTODESK AND/OR ITS LICENSORS BE LIABLE FOR ANY LOST
// REVENUES, DATA, OR PROFITS, OR SPECIAL, DIRECT, INDIRECT, OR
// CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK AND/OR ITS LICENSORS HAS
// BEEN ADVISED OF THE POSSIBILITY OR PROBABILITY OF SUCH DAMAGES.
// ==========================================================================
//+
//
// ****************************************************************************

#if defined __cplusplus

// ****************************************************************************
// INCLUDED HEADER FILES

#include <maya/MStatus.h>
#include <maya/MStringArray.h>
#include <maya/MColor.h>
#include <maya/MString.h>
#include <maya/MViewport2Renderer.h>

// ****************************************************************************
// NAMESPACE

namespace MHWRender
{

// ****************************************************************************
// DECLARATIONS

// ****************************************************************************
// CLASS DECLARATION (MRenderTargetDescription)
//! \ingroup OpenMayaRender
//!\brief Class which provides a description of a hardware render target
//! The name is the unique identifier for a render target.
//
class OPENMAYARENDER_EXPORT MRenderTargetDescription
{
public:
	MRenderTargetDescription();
	MRenderTargetDescription(const MString &name,
							unsigned int width, unsigned int height,
							unsigned int multiSampleCount,
							MHWRender::MRasterFormat rasterFormat,
							unsigned int arraySliceCount,
							bool isCubeMap);
	virtual ~MRenderTargetDescription();

	const MString & name() const;
	unsigned int width() const;
	unsigned int height() const;
	unsigned int multiSampleCount() const;
	MHWRender::MRasterFormat rasterFormat() const;
	unsigned int arraySliceCount() const;
	bool isCubeMap() const;
	bool allowsUnorderedAccess() const; 

	void setName(const MString & name);
	void setWidth(unsigned int val);
	void setHeight(unsigned int val);
	void setMultiSampleCount(unsigned int val);
	void setRasterFormat(MHWRender::MRasterFormat val);
	void setArraySliceCount(unsigned int val);
	void setIsCubeMap(bool val);
    void setAllowsUnorderedAccess(bool val);
 
	bool compatibleWithDescription( const MRenderTargetDescription & desc );

private:
	MString			mName;
	unsigned int	mWidth;
	unsigned int	mHeight;
	unsigned int	mMultiSampleCount;
	MHWRender::MRasterFormat mFormat;
	unsigned int	mArraySliceCount;
	bool			mIsCubeMap;
	bool			mAllowsUnorderedAccess;
};

// ****************************************************************************
// CLASS DECLARATION (MRenderTarget)
//! \ingroup OpenMayaRender
//! \brief An instance of a render target that may be used with Viewport 2.0
/*!
This class represents a render target that may be used with the MRenderOperation class
for rendering in Viewport 2.0.
*/
class OPENMAYARENDER_EXPORT MRenderTarget
{
public:
	MStatus updateDescription( const MRenderTargetDescription & targetDescription);
	void targetDescription(MRenderTargetDescription& desc) const;

	static const char* className();

	void * resourceHandle() const;

	void * rawData(int &rowPitch, int &slicePitch);

private:
	MRenderTarget(void* data, unsigned int *rasterMap, bool );
	~MRenderTarget();

	void* fData;
	unsigned int* fRasterMap;
	bool fIsInternalTarget;

	friend class MRenderer;
	friend class MRenderTargetManager;
	friend class MRenderUtilities;
	friend class MRenderItem;
	friend class MShaderInstance;
};


// ****************************************************************************
// CLASS DECLARATION (MShaderManager)
//! \ingroup OpenMayaRender
//! \brief Provides access to MRenderTarget objects for use in Viewport 2.0.
/*!
This class generates MRenderTarget objects for use with
MRenderOperation objects. Any MRenderTarget objects created by this class are
owned by the caller.
*/
class OPENMAYARENDER_EXPORT MRenderTargetManager
{
public:
	MRenderTarget* acquireRenderTarget(const MRenderTargetDescription& targetDescription) const;

	MRenderTarget* acquireRenderTargetFromScreen(const MString &targetName) const;

	bool formatSupportsSRGBWrite( MHWRender::MRasterFormat format ) const;

	void releaseRenderTarget(MRenderTarget* target) const;

	static const char* className();

private:
	MRenderTargetManager(unsigned int *rasterMap);
	~MRenderTargetManager();

	MRenderTarget* target( void*, bool ) const ;

	unsigned int* fRasterMap;

	friend class MFrameContext;
	friend class MDrawContext;
	friend class MRenderer;
};

} // namespace MHWRender

#endif /* __cplusplus */
#endif /* _MRenderTargetManager */
