MaterialLoader.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include "tests/framework/Framework.h"
  6. #include "anki/resource/MaterialLoader.h"
  7. #include "anki/misc/Xml.h"
  8. #include <unordered_map>
  9. namespace anki
  10. {
  11. static const char* MTL = R"(
  12. <material>
  13. <levelsOfDetail>3</levelsOfDetail>
  14. <shadow>1</shadow>
  15. <programs>
  16. <program>
  17. <type>vert</type>
  18. <inputs>
  19. <input>
  20. <name>anki_mvp</name>
  21. <type>mat4</type>
  22. </input>
  23. <input>
  24. <name>c</name>
  25. <type>float</type>
  26. <value>1.0</value>
  27. <const>1</const>
  28. </input>
  29. <input>
  30. <name>anki_msDepthRt</name>
  31. <type>sampler2D</type>
  32. </input>
  33. <input>
  34. <name>sampl</name>
  35. <type>sampler2D</type>
  36. <value>aasdfasdf/asdfasdf</value>
  37. </input>
  38. <input>
  39. <name>mouse</name>
  40. <type>float</type>
  41. <value>1.0</value>
  42. <inShadow>0</inShadow>
  43. </input>
  44. <input>
  45. <name>cat</name>
  46. <type>vec3</type>
  47. <value>1.0 1.0 1.0</value>
  48. <inShadow>1</inShadow>
  49. </input>
  50. </inputs>
  51. <includes><include>file.glsl</include></includes>
  52. <operations>
  53. <operation>
  54. <id>12</id>
  55. <returnType>vec3</returnType>
  56. <function>ha</function>
  57. </operation>
  58. <operation>
  59. <id>123</id>
  60. <returnType>vec3</returnType>
  61. <function>foo</function>
  62. <arguments>
  63. <argument>anki_mvp</argument>
  64. <argument>c</argument>
  65. <argument>cat</argument>
  66. <argument>out12</argument>
  67. <argument>anki_msDepthRt</argument>
  68. </arguments>
  69. </operation>
  70. <operation>
  71. <id>124</id>
  72. <returnType>void</returnType>
  73. <function>boo</function>
  74. <arguments>
  75. <argument>out123</argument>
  76. <argument>mouse</argument>
  77. <argument>sampl</argument>
  78. </arguments>
  79. </operation>
  80. </operations>
  81. </program>
  82. </programs>
  83. </material>
  84. )";
  85. //==============================================================================
  86. ANKI_TEST(Resource, MaterialLoader)
  87. {
  88. XmlDocument doc;
  89. HeapAllocator<U8> alloc(allocAligned, nullptr);
  90. MaterialLoader loader(alloc);
  91. ANKI_TEST_EXPECT_NO_ERR(doc.parse(MTL, alloc));
  92. ANKI_TEST_EXPECT_NO_ERR(loader.parseXmlDocument(doc));
  93. {
  94. RenderingKey key(Pass::SM, 1, false, 3);
  95. loader.mutate(key);
  96. printf("%s\n", &loader.getShaderSource(ShaderType::VERTEX)[0]);
  97. std::unordered_map<std::string, Bool> map;
  98. map["anki_mvp"] = true;
  99. map["c"] = false;
  100. map["anki_msDepthRt"] = false;
  101. map["sampl"] = true;
  102. map["mouse"] = true;
  103. map["cat"] = true;
  104. Error err = loader.iterateAllInputVariables(
  105. [&](const MaterialLoaderInputVariable& in) -> Error {
  106. ANKI_TEST_EXPECT_EQ(map[&in.m_name.toCString()[0]], true);
  107. if(in.m_flags.m_inBlock)
  108. {
  109. printf("var in block: %s %d %d %d %d\n",
  110. &in.m_name[0],
  111. in.m_blockInfo.m_offset,
  112. in.m_blockInfo.m_arraySize,
  113. in.m_blockInfo.m_arrayStride,
  114. in.m_blockInfo.m_matrixStride);
  115. }
  116. return ErrorCode::NONE;
  117. });
  118. (void)err;
  119. }
  120. // Check block size
  121. /*{
  122. RenderingKey key(Pass::MS_FS, 1, false, 4);
  123. loader.mutate(key);
  124. ANKI_TEST_EXPECT_EQ(loader.getUniformBlockSize(),
  125. 16 * 4 * sizeof(F32) + 4 * sizeof(F32) + 3 * sizeof(F32));
  126. }*/
  127. }
  128. } // end namespace anki