/******************************************************************************
*	File		-	Image.h
*	Author		-	Joey Pollack
*	Date		-	2019/07/17 (y/m/d)
*	Mod Date	-	2019/07/18 (y/m/d)
*	Description	-	Manage image data that can be rendered with OpenGL.
*					Use the Graphics class to create instances of Image.
******************************************************************************/

#include "image.h"
#include <cstring>

namespace lunarium
{
	
	Image::Image()
		: mRawData(nullptr), mRawDataSize(0), mWidth(0), mHeight(0)
	{
	}

	Image::~Image()
	{
		delete[] mRawData;
		mRawData = nullptr;
	}

	
	Image::Image(const Image& rhs)
		: mRawData(nullptr), mRawDataSize(0), mWidth(0), mHeight(0)
	{
		*this = rhs;
	}

	const Image& Image::operator=(const Image& rhs)
	{
		if (this == &rhs)
		{
			return *this;
		}

		FreeRawData();
		mGLTextureID = rhs.mGLTextureID;
		mFormat = rhs.mFormat;
		mWidth = rhs.mWidth;
		mHeight = rhs.mHeight;
		mRawDataSize = rhs.mRawDataSize;

		mRawData = new unsigned char[mRawDataSize];
		memcpy(mRawData, rhs.mRawData, mRawDataSize);

		return *this;
	}

	unsigned int  Image::GetGLTextureID() const
	{
		return mGLTextureID;
	}
	
	int Image::GetWidth() const
	{
		return mWidth;
	}

	int Image::GetHeight() const
	{
		return mHeight;
	}

	ImageFormat Image::GetFormat() const
	{
		return mFormat;
	}

	void Image::FreeRawData()
	{
		delete[] mRawData;
		mRawData = nullptr;

		mRawDataSize = 0;
	}
}
