axmol doesn't support Samplers yet.
| 258 | |
| 259 | // axmol doesn't support Samplers yet. |
| 260 | bool 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) |
nothing calls this directly
no test coverage detected