summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/texture.cpp
blob: 522ba953a926c079d06cff573186bad8b88b82dc (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
50
51
52
53
#include <asura-utils/exceptions/exception.h>

#include "Texture.h"

namespace AsuraEngine
{
	namespace Graphics
	{

		Texture::Texture()
			: mTex(0)
		{
			// Fix: ҪʱԴ
			//glGenTextures(1, &mTex);
			//if(mTex == 0)
			//	throw Exception("Cannot create texture.");
		}

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

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

		TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat)
		{
			TextureFormat t;
			switch (colorformat)
			{
			case COLOR_FORMAT_RGBA8:
				t.internalformat = GL_RGBA8;
				t.externalformat = GL_RGBA;
				t.type = GL_UNSIGNED_BYTE;
				break;
			case COLOR_FORMAT_RGBA32F:
				t.internalformat = GL_RGBA32F;
				t.externalformat = GL_RGBA;
				t.type = GL_FLOAT;
				break;
			default: 
				ASSERT(false); // cant reach here
			}
			return t;
		}

	}
}