// Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #include "tests/framework/Framework.h" #include "anki/resource/MaterialLoader.h" #include "anki/misc/Xml.h" #include namespace anki { static const char* MTL = R"( 3 1 vert anki_mvp mat4 c float 1.0 1 anki_msDepthRt sampler2D sampl sampler2D aasdfasdf/asdfasdf mouse float 1.0 0 cat vec3 1.0 1.0 1.0 1 file.glsl 12 vec3 ha 123 vec3 foo anki_mvp c cat out12 anki_msDepthRt 124 void boo out123 mouse sampl )"; ANKI_TEST(Resource, MaterialLoader) { XmlDocument doc; HeapAllocator alloc(allocAligned, nullptr); MaterialLoader loader(alloc); ANKI_TEST_EXPECT_NO_ERR(doc.parse(MTL, alloc)); ANKI_TEST_EXPECT_NO_ERR(loader.parseXmlDocument(doc)); { RenderingKey key(Pass::SM, 1, false, 3); loader.mutate(key); printf("%s\n", &loader.getShaderSource(ShaderType::VERTEX)[0]); std::unordered_map map; map["anki_mvp"] = true; map["c"] = false; map["anki_msDepthRt"] = false; map["sampl"] = true; map["mouse"] = true; map["cat"] = true; Error err = loader.iterateAllInputVariables([&](const MaterialLoaderInputVariable& in) -> Error { ANKI_TEST_EXPECT_EQ(map[&in.m_name.toCString()[0]], true); if(in.m_flags.m_inBlock) { printf("var in block: %s %d %d %d %d\n", &in.m_name[0], in.m_blockInfo.m_offset, in.m_blockInfo.m_arraySize, in.m_blockInfo.m_arrayStride, in.m_blockInfo.m_matrixStride); } return ErrorCode::NONE; }); (void)err; } // Check block size /*{ RenderingKey key(Pass::MS_FS, 1, false, 4); loader.mutate(key); ANKI_TEST_EXPECT_EQ(loader.getUniformBlockSize(), 16 * 4 * sizeof(F32) + 4 * sizeof(F32) + 3 * sizeof(F32)); }*/ } } // end namespace anki