MCPcopy Create free account
hub / github.com/beefytech/Beef / LoadTexture

Method LoadTexture

BeefySysLib/gfx/RenderDevice.cpp:108–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108Texture* RenderDevice::LoadTexture(const StringImpl& fileName, int flags)
109{
110 int dotPos = (int)fileName.LastIndexOf('.');
111 String ext;
112 if (dotPos != -1)
113 ext = fileName.Substring(dotPos);
114
115 ImageData* imageData = NULL;
116 bool handled = false;
117 bool failed = false;
118
119 if (fileName == "!white")
120 {
121 imageData = new ImageData();
122 imageData->CreateNew(1, 1, true);
123 imageData->mBits[0] = 0xFFFFFFFF;
124 handled = true;
125 }
126 else if (fileName.StartsWith("!square"))
127 {
128 int squareSize = atoi(fileName.c_str() + 7);
129 imageData = new ImageData();
130 imageData->CreateNew(squareSize + 2, squareSize + 2, true);
131 for (int y = 0; y < squareSize; y++)
132 {
133 for (int x = 0; x < squareSize; x++)
134 {
135 imageData->mBits[(y + 1) * (squareSize + 2) + x + 1] = 0xFFFFFFFF;
136 }
137 }
138 handled = true;
139 }
140 else if (ext == ".tga")
141 imageData = new TGAData();
142 else if (ext == ".png")
143 imageData = new PNGData();
144 else if (ext == ".jpg")
145 imageData = new JPEGData();
146 else if (ext == ".pvr")
147 imageData = new PVRData();
148 else if (ext == ".bmp")
149 {
150 BMPData* bmpData = new BMPData();
151 bmpData->mHasTransFollowing = (flags & TextureFlag_HasTransFollowing) == 0;;
152 imageData = bmpData;
153 }
154 else
155 {
156 return NULL; // Unknown format
157 }
158
159 if (!handled)
160 {
161 imageData->mWantsAlphaPremultiplied = (flags & TextureFlag_NoPremult) == 0;
162
163 void* memPtr = NULL;
164 int memLen = 0;
165 if (ParseMemorySpan(fileName, memPtr, memLen))

Callers 4

Gfx_LoadTextureFunction · 0.45
LoadLayerTextureMethod · 0.45
AllocGlyphMethod · 0.45

Calls 8

SubstringMethod · 0.80
CreateNewMethod · 0.80
LoadFromMemoryMethod · 0.80
LoadFromFileMethod · 0.80
LastIndexOfMethod · 0.45
StartsWithMethod · 0.45
c_strMethod · 0.45
DerefMethod · 0.45

Tested by

no test coverage detected