test_visual_shader.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**************************************************************************/
  2. /* test_visual_shader.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_VISUAL_SHADER_H
  31. #define TEST_VISUAL_SHADER_H
  32. #include "scene/resources/visual_shader.h"
  33. #include "tests/test_macros.h"
  34. namespace TestVisualArray {
  35. TEST_CASE("[SceneTree][VisualShader] Object creation and parameter") {
  36. Ref<VisualShader> vs = memnew(VisualShader);
  37. CHECK(vs.is_valid());
  38. CHECK(vs->get_mode() == Shader::MODE_SPATIAL);
  39. for (int i = 1; i < Shader::MODE_MAX; i++) {
  40. vs->set_mode((Shader::Mode)i);
  41. CHECK(vs->get_mode() == i);
  42. }
  43. }
  44. TEST_CASE("[SceneTree][VisualShader] Testing VisualShaderNodes") {
  45. SUBCASE("Testing Node Creation") {
  46. Ref<VisualShader> vs = memnew(VisualShader);
  47. CHECK(vs.is_valid());
  48. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  49. Ref<VisualShaderNode> vsn = memnew(VisualShaderNodeInput);
  50. CHECK(vsn.is_valid());
  51. vs->add_node(VisualShader::Type(i), vsn, Vector2(1, 10), i + 2);
  52. CHECK(vs->get_node(VisualShader::Type(i), i + 2) == vsn);
  53. }
  54. ERR_PRINT_OFF;
  55. // Testing for Invalid entries.
  56. Ref<VisualShaderNode> vsn5 = memnew(VisualShaderNodeInput);
  57. Ref<VisualShaderNode> vsn6 = memnew(VisualShaderNodeInput);
  58. CHECK(vsn6.is_valid());
  59. CHECK(vsn5.is_valid());
  60. vs->add_node(VisualShader::TYPE_SKY, vsn5, Vector2(1, 10), 0);
  61. CHECK_FALSE(vs->get_node(VisualShader::TYPE_SKY, 0) == vsn6);
  62. vs->add_node(VisualShader::TYPE_MAX, vsn6, Vector2(1, 10), 7);
  63. CHECK_FALSE(vs->get_node(VisualShader::TYPE_SKY, 7) == vsn6);
  64. ERR_PRINT_ON;
  65. }
  66. SUBCASE("Testing VisualShaderNode position getter and setter") {
  67. Ref<VisualShader> vs = memnew(VisualShader);
  68. CHECK(vs.is_valid());
  69. Ref<VisualShaderNode> vsn1 = memnew(VisualShaderNodeInput);
  70. CHECK(vsn1.is_valid());
  71. vs->add_node(VisualShader::TYPE_COLLIDE, vsn1, Vector2(0, 0), 3);
  72. CHECK(vs->get_node_position(VisualShader::TYPE_COLLIDE, 3) == Vector2(0, 0));
  73. vs->set_node_position(VisualShader::TYPE_COLLIDE, 3, Vector2(1, 1));
  74. CHECK(vs->get_node_position(VisualShader::TYPE_COLLIDE, 3) == Vector2(1, 1));
  75. Ref<VisualShaderNode> vsn2 = memnew(VisualShaderNodeInput);
  76. CHECK(vsn2.is_valid());
  77. vs->add_node(VisualShader::TYPE_FOG, vsn2, Vector2(1, 2), 4);
  78. CHECK(vs->get_node_position(VisualShader::TYPE_FOG, 4) == Vector2(1, 2));
  79. vs->set_node_position(VisualShader::TYPE_FOG, 4, Vector2(2, 2));
  80. CHECK(vs->get_node_position(VisualShader::TYPE_FOG, 4) == Vector2(2, 2));
  81. }
  82. SUBCASE("Testing VisualShaderNode ID") {
  83. Ref<VisualShader> vs = memnew(VisualShader);
  84. CHECK(vs.is_valid());
  85. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  86. Ref<VisualShaderNode> vsn = memnew(VisualShaderNodeInput);
  87. CHECK(vsn.is_valid());
  88. vs->add_node(VisualShader::Type(i), vsn, Vector2(1, 10), i + 2);
  89. CHECK(vs->get_valid_node_id(VisualShader::Type(i)) - 1 == i + 2);
  90. }
  91. }
  92. SUBCASE("Testing remove and replace VisualShaderNode") {
  93. Ref<VisualShader> vs = memnew(VisualShader);
  94. CHECK(vs.is_valid());
  95. ERR_PRINT_OFF;
  96. for (int i = 0; i < VisualShader::TYPE_MAX; i++) {
  97. Ref<VisualShaderNode> vsn = memnew(VisualShaderNodeInput);
  98. CHECK(vsn.is_valid());
  99. vs->add_node(VisualShader::Type(i), vsn, Vector2(1, 10), i + 2);
  100. CHECK(vs->get_node(VisualShader::Type(i), i + 2) == vsn);
  101. vs->remove_node(VisualShader::Type(i), i + 2);
  102. CHECK_FALSE(vs->get_node(VisualShader::Type(i), i + 2) == vsn);
  103. }
  104. ERR_PRINT_ON;
  105. }
  106. }
  107. TEST_CASE("[SceneTree][VisualShader] Testing Varyings") {
  108. Ref<VisualShader> vs = memnew(VisualShader);
  109. vs->add_varying("Test1", VisualShader::VARYING_MODE_FRAG_TO_LIGHT, VisualShader::VARYING_TYPE_TRANSFORM);
  110. CHECK(vs->has_varying("Test1") == true);
  111. vs->add_varying("Test2", VisualShader::VARYING_MODE_VERTEX_TO_FRAG_LIGHT, VisualShader::VARYING_TYPE_VECTOR_2D);
  112. CHECK(vs->has_varying("Test2"));
  113. CHECK_FALSE(vs->has_varying("Does_not_exits"));
  114. ERR_PRINT_OFF;
  115. vs->add_varying("Test3", VisualShader::VARYING_MODE_MAX, VisualShader::VARYING_TYPE_INT);
  116. CHECK_FALSE(vs->has_varying("Test3"));
  117. vs->add_varying("Test4", VisualShader::VARYING_MODE_FRAG_TO_LIGHT, VisualShader::VARYING_TYPE_MAX);
  118. CHECK_FALSE(vs->has_varying("Test4"));
  119. ERR_PRINT_ON;
  120. }
  121. } //namespace TestVisualArray
  122. #endif // TEST_VISUAL_SHADER_H