MCPcopy Create free account
hub / github.com/axmolengine/axmol / parseSampler

Method parseSampler

core/renderer/Material.cpp:260–356  ·  view source on GitHub ↗

axmol doesn't support Samplers yet.

Source from the content-addressed store, hash-verified

258
259// axmol doesn't support Samplers yet.
260bool Material::parseSampler(backend::ProgramState* programState, Properties* samplerProperties)
261{
262 AXASSERT(!samplerProperties->getId().empty(), "Sampler must have an id. The id is the uniform name");
263
264 // required
265 auto filename = samplerProperties->getString("path");
266
267 auto texture = Director::getInstance()->getTextureCache()->addImage(filename);
268 if (!texture)
269 {
270 AXLOGW("Invalid filepath");
271 return false;
272 }
273
274 // optionals
275 {
276 Texture2D::TexParams texParams;
277
278 // mipmap
279 bool usemipmap = false;
280 const char* mipmap = getOptionalString(samplerProperties, "mipmap", "false");
281 if (mipmap && strcasecmp(mipmap, "true") == 0)
282 {
283 texture->generateMipmap();
284 usemipmap = true;
285 }
286
287 // valid options: REPEAT, CLAMP
288 const char* wrapS = getOptionalString(samplerProperties, "wrapS", "CLAMP_TO_EDGE");
289 if (strcasecmp(wrapS, "REPEAT") == 0)
290 texParams.sAddressMode = backend::SamplerAddressMode::REPEAT;
291 else if (strcasecmp(wrapS, "CLAMP_TO_EDGE") == 0)
292 texParams.sAddressMode = backend::SamplerAddressMode::CLAMP_TO_EDGE;
293 else
294 AXLOGW("Invalid wrapS: {}", wrapS);
295
296 // valid options: REPEAT, CLAMP
297 const char* wrapT = getOptionalString(samplerProperties, "wrapT", "CLAMP_TO_EDGE");
298 if (strcasecmp(wrapT, "REPEAT") == 0)
299 texParams.tAddressMode = backend::SamplerAddressMode::REPEAT;
300 else if (strcasecmp(wrapT, "CLAMP_TO_EDGE") == 0)
301 texParams.tAddressMode = backend::SamplerAddressMode::CLAMP_TO_EDGE;
302 else
303 AXLOGW("Invalid wrapT: {}", wrapT);
304
305 // valid options: NEAREST, LINEAR, NEAREST_MIPMAP_NEAREST, LINEAR_MIPMAP_NEAREST, NEAREST_MIPMAP_LINEAR,
306 // LINEAR_MIPMAP_LINEAR
307 const char* minFilter =
308 getOptionalString(samplerProperties, "minFilter", usemipmap ? "LINEAR_MIPMAP_NEAREST" : "LINEAR");
309 if (strcasecmp(minFilter, "NEAREST") == 0)
310 texParams.minFilter = backend::SamplerFilter::NEAREST;
311 else if (strcasecmp(minFilter, "LINEAR") == 0)
312 texParams.minFilter = backend::SamplerFilter::LINEAR;
313 else if (strcasecmp(minFilter, "NEAREST_MIPMAP_NEAREST") == 0)
314 texParams.minFilter = backend::SamplerFilter::NEAREST;
315 else if (strcasecmp(minFilter, "LINEAR_MIPMAP_NEAREST") == 0)
316 texParams.minFilter = backend::SamplerFilter::LINEAR;
317 else if (strcasecmp(minFilter, "NEAREST_MIPMAP_LINEAR") == 0)

Callers

nothing calls this directly

Calls 15

getInstanceFunction · 0.85
getOptionalStringFunction · 0.85
strcasecmpFunction · 0.85
getTextureCacheMethod · 0.80
generateMipmapMethod · 0.80
getBackendTextureMethod · 0.80
emptyMethod · 0.45
getIdMethod · 0.45
getStringMethod · 0.45
addImageMethod · 0.45
setTexParametersMethod · 0.45
getUniformLocationMethod · 0.45

Tested by

no test coverage detected