summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/image.cpp
blob: 2b274c248267acbbc98fc4fe1182a077089d94bb (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
#include "../core_config.h"

#include "image.h"
#include "gl.h"

using namespace AEIO;

namespace AsuraEngine
{
	namespace Graphics
	{

		Image::Image()
		{
		}

		Image::~Image()
		{
		}

		bool Image::Refresh(DecodedData* data)
		{
			ASSERT(data);

			ImageData* imgData = static_cast<ImageData*>(data);
			ASSERT(imgData);

			glBindTexture(GL_TEXTURE_2D, mTex);
			imgData->Lock();
			int width = imgData->width;
			int height = imgData->height;
			TextureFormat tf = ConvertColorFormat(imgData->format);
			glTexImage2D(
				GL_TEXTURE_2D
				, 0
				, tf.internalformat
				, width, height
				, 0
				, tf.externalformat
				, tf.type
				, imgData->pixels
			);
			mImageData = imgData;
			imgData->Unlock();
			glBindTexture(GL_TEXTURE_2D, 0);

			return true;
		}

	}
}