Repository navigation
Expand file tree
/
Copy pathtexture.cpp
More file actions
89 lines (70 loc) · 1.98 KB
/
Copy pathtexture.cpp
File metadata and controls
89 lines (70 loc) · 1.98 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "texture.h"
#include "DirectXTex.h"
using namespace DirectX;
//#include "directx.h"
#include <string>
//#include "renderer.h"
#define TEXTURE_MAX (256)
struct TextureData
{
std::wstring filename;
ID3D11ShaderResourceView* shader_resource_view;
int width;
int height;
};
static TextureData g_Textures[TEXTURE_MAX] = {};
static int g_TextureCount = 0;
// ※外部からもらうデバイスのポインタなのでReleaseはしちゃダメ
static ID3D11Device* g_Device = NULL;
void TextureInitialize(ID3D11Device* device)
{
for (int i = 0; i < TEXTURE_MAX; i++) {
g_Textures[i].shader_resource_view = NULL;
}
g_TextureCount = 0;
g_Device = device;
}
int TextureLoad(const std::wstring& texture_filename)
{
// すでに同名のテクスチャが読み込まれていないか確認する
for (int i = 0; i < g_TextureCount; i++) {
if (g_Textures[i].filename == texture_filename) {
return i; // すでに読み込まれていたのでidをわたす
}
}
// テクスチャ読み込み
TexMetadata metadata;
ScratchImage image;
LoadFromWICFile(texture_filename.c_str(), WIC_FLAGS_NONE, &metadata, image);
CreateShaderResourceView(g_Device, image.GetImages(), image.GetImageCount(), metadata, &g_Textures[g_TextureCount].shader_resource_view);
g_Textures[g_TextureCount].width = (int)metadata.width;
g_Textures[g_TextureCount].height = (int)metadata.height;
if (!g_Textures[g_TextureCount].shader_resource_view) {
MessageBoxW(NULL, L"ファイルが読み込めなかった", texture_filename.c_str(), MB_ICONEXCLAMATION | MB_OK);
return -1;
}
return g_TextureCount++;
}
ID3D11ShaderResourceView* GetTexture(int id)
{
if (id < 0 || id >= g_TextureCount) {
return NULL;
}
return g_Textures[id].shader_resource_view;
}
int TextureGetWidth(int id)
{
return g_Textures[id].width;
}
int TextureGetHeight(int id)
{
return g_Textures[id].height;
}
void TextureFinalize(void)
{
for (int i = 0; i < g_TextureCount; i++) {
// g_Textures[i].shader_resource_view->Release();
// g_Textures[i] = NULL;
SAFE_RELEASE(g_Textures[i].shader_resource_view);
}
}