ShaderProgramCompiler.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2009-2019, Panagiotis Christopoulos Charitos and contributors.
  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/shader_compiler/ShaderProgramCompiler.h>
  7. ANKI_TEST(ShaderCompiler, ShaderProgramCompiler)
  8. {
  9. const CString sourceCode = R"(
  10. #pragma anki start vert
  11. out gl_PerVertex
  12. {
  13. Vec4 gl_Position;
  14. };
  15. void main()
  16. {
  17. gl_Position = Vec4(gl_Position);
  18. }
  19. #pragma anki end
  20. #pragma anki start frag
  21. layout(location = 0) out Vec3 out_color;
  22. void main()
  23. {
  24. out_color = Vec3(0.0);
  25. }
  26. #pragma anki end
  27. )";
  28. // Write the file
  29. {
  30. File file;
  31. ANKI_TEST_EXPECT_NO_ERR(file.open("test.glslp", FileOpenFlag::WRITE));
  32. ANKI_TEST_EXPECT_NO_ERR(file.writeText(sourceCode));
  33. }
  34. class Fsystem : public ShaderProgramFilesystemInterface
  35. {
  36. public:
  37. Error readAllText(CString filename, StringAuto& txt) final
  38. {
  39. File file;
  40. ANKI_CHECK(file.open(filename, FileOpenFlag::READ));
  41. ANKI_CHECK(file.readAllText(txt));
  42. return Error::NONE;
  43. }
  44. } fsystem;
  45. HeapAllocator<U8> alloc(allocAligned, nullptr);
  46. ShaderProgramBinaryWrapper binary(alloc);
  47. ANKI_TEST_EXPECT_NO_ERR(compileShaderProgram("test.glslp", fsystem, alloc, 128, 1, 1, GpuVendor::AMD, binary));
  48. }