-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathTexture.c
63 lines (47 loc) · 1.71 KB
/
Texture.c
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
54
55
56
57
58
59
60
61
62
/*
* Copyright (c) scott.cgi All Rights Reserved.
*
* This source code belongs to project Mojoc, which is a pure C Game Engine hosted on GitHub.
* The Mojoc Game Engine is licensed under the MIT License, and will continue to be iterated with coding passion.
*
* License : https://github.com/scottcgi/Mojoc/blob/master/LICENSE
* GitHub : https://github.com/scottcgi/Mojoc
* CodeStyle: https://github.com/scottcgi/Mojoc/blob/master/Docs/CodeStyle.md
*
* Since : 2013-1-2
* Update : 2019-1-19
* Author : scott.cgi
*/
#include <stdlib.h>
#include "Engine/Graphics/OpenGL/Texture.h"
#include "Engine/Graphics/OpenGL/GLTool.h"
#include "Engine/Toolkit/Utils/ArrayStrMap.h"
#include "Engine/Toolkit/Platform/Log.h"
static ArrayStrMap(filePath, Texture*) textureCacheMap[1] = AArrayStrMap_Init(Texture*, 25);
static Texture* Get(const char* resourceFilePath)
{
Texture* texture = AArrayStrMap_Get(textureCacheMap, resourceFilePath, Texture*);
if (texture == NULL)
{
texture = malloc(sizeof(Texture));
AGLTool->LoadTexture(resourceFilePath, texture);
texture->filePath = AArrayStrMap_GetKey
(
AArrayStrMap_TryPut(textureCacheMap, resourceFilePath, texture),
textureCacheMap->valueTypeSize
);
}
return texture;
}
static void Destroy(Texture* texture)
{
glDeleteTextures(1, (GLuint[1]) {texture->id});
bool isRemoved = AArrayStrMap->TryRemove(textureCacheMap, texture->filePath);
ALog_A(isRemoved, "ATexture Destroy not found %s in textureCacheMap", texture->filePath);
free(texture);
}
struct ATexture ATexture[1] =
{{
Get,
Destroy,
}};