summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/texture.cpp
blob: 240a5f8abccbd9f7c26bd75e999c9b20cfff6c32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <asura-utils/exceptions/exception.h>

#include "Texture.h"

namespace AsuraEngine
{
	namespace Graphics
	{

		Texture::Texture()
			: mTexID(0)
		{
		}

		Texture::~Texture()
		{
			// ͷԴ
			if(mTexID != 0)
				glDeleteTextures(1, &mTexID);
		}

		GLuint Texture::GetGLTexture() const
		{
			return mTexID;
		}

		TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat)
		{
			TextureFormat t;
			switch (colorformat)
			{
			case COLOR_FORMAT_RGBA8:
				t.internalformat = GL_RGBA8; // 4*sizeof(byte) ~= 4 bytes
				t.externalformat = GL_RGBA;
				t.type = GL_UNSIGNED_BYTE;
				break;
			case COLOR_FORMAT_RGBA32F:
				t.internalformat = GL_RGBA32F; // 4*sizeof(float) = 16 bytes
				t.externalformat = GL_RGBA;
				t.type = GL_FLOAT;
				break;
			default: 
				ASSERT(false);
			}
			return t;
		}

	}
}