MCPcopy Create free account
hub / github.com/Voine/ChatWaifu_Mobile / CreateTextureFromPngFile

Method CreateTextureFromPngFile

Live2D/src/main/cpp/LAppTextureManager.cpp:25–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromPngFile(std::string fileName)
26{
27 //search loaded texture already.
28 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
29 {
30 if (_textures[i]->fileName == fileName)
31 {
32 return _textures[i];
33 }
34 }
35
36 GLuint textureId;
37 int width, height, channels;
38 unsigned int size;
39 unsigned char* png;
40 unsigned char* address;
41
42 address = LAppPal::LoadFileAsBytes(fileName, &size);
43
44 // png情報を取得する
45 png = stbi_load_from_memory(
46 address,
47 static_cast<int>(size),
48 &width,
49 &height,
50 &channels,
51 STBI_rgb_alpha);
52 {
53#ifdef PREMULTIPLIED_ALPHA_ENABLE
54 unsigned int* fourBytes = reinterpret_cast<unsigned int*>(png);
55 for (int i = 0; i < width * height; i++)
56 {
57 unsigned char* p = png + i * 4;
58 fourBytes[i] = Premultiply(p[0], p[1], p[2], p[3]);
59 }
60#endif
61 }
62
63 // OpenGL用のテクスチャを生成する
64 glGenTextures(1, &textureId);
65 glBindTexture(GL_TEXTURE_2D, textureId);
66 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, png);
67 glGenerateMipmap(GL_TEXTURE_2D);
68 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
69 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
70 glBindTexture(GL_TEXTURE_2D, 0);
71
72 // 解放処理
73 stbi_image_free(png);
74 LAppPal::ReleaseBytes(address);
75
76 LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
77 if (textureInfo != NULL)
78 {
79 textureInfo->fileName = fileName;
80 textureInfo->width = width;
81 textureInfo->height = height;
82 textureInfo->id = textureId;

Callers 2

InitializeSpriteMethod · 0.80
SetupTexturesMethod · 0.80

Calls 4

stbi_load_from_memoryFunction · 0.85
stbi_image_freeFunction · 0.85
GetSizeMethod · 0.45
PushBackMethod · 0.45

Tested by

no test coverage detected