es3_misc_functions_unittest.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <GLES2/gl2.h>
  5. #include <GLES2/gl2ext.h>
  6. #include <GLES2/gl2extchromium.h>
  7. #include <GLES3/gl3.h>
  8. #include "base/strings/string_split.h"
  9. #include "base/strings/string_util.h"
  10. #include "build/build_config.h"
  11. #include "gpu/command_buffer/tests/gl_manager.h"
  12. #include "gpu/command_buffer/tests/gl_test_utils.h"
  13. #include "testing/gmock/include/gmock/gmock.h"
  14. #include "testing/gtest/include/gtest/gtest.h"
  15. #include "ui/gl/gl_switches.h"
  16. #define SHADER_VERSION_300(Src) "#version 300 es\n" #Src
  17. namespace gpu {
  18. class OpenGLES3FunctionTest : public testing::Test {
  19. protected:
  20. void SetUp() override {
  21. GLManager::Options options;
  22. options.context_type = CONTEXT_TYPE_OPENGLES3;
  23. gl_.Initialize(options);
  24. }
  25. void TearDown() override { gl_.Destroy(); }
  26. bool IsApplicable() const { return gl_.IsInitialized(); }
  27. GLManager gl_;
  28. };
  29. #if BUILDFLAG(IS_ANDROID)
  30. // Test is failing for Lollipop 64 bit Tester.
  31. // See crbug/550292.
  32. #define MAYBE_GetFragDataLocationInvalid DISABLED_GetFragDataLocationInvalid
  33. #else
  34. #define MAYBE_GetFragDataLocationInvalid GetFragDataLocationInvalid
  35. #endif
  36. TEST_F(OpenGLES3FunctionTest, MAYBE_GetFragDataLocationInvalid) {
  37. if (!IsApplicable()) {
  38. return;
  39. }
  40. // clang-format off
  41. static const char* kVertexShader =
  42. SHADER_VERSION_300(
  43. in vec4 position;
  44. void main() {
  45. gl_Position = position;
  46. });
  47. static const char* kFragColorShader =
  48. SHADER_VERSION_300(
  49. precision mediump float;
  50. uniform vec4 src;
  51. out vec4 FragColor;
  52. void main() {
  53. FragColor = src;
  54. });
  55. // clang-format on
  56. GLuint vsid = GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
  57. GLuint fsid = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, kFragColorShader);
  58. GLuint program = glCreateProgram();
  59. glAttachShader(program, vsid);
  60. glAttachShader(program, fsid);
  61. glDeleteShader(vsid);
  62. glDeleteShader(fsid);
  63. GLint location = glGetFragDataLocation(program, "FragColor");
  64. EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
  65. EXPECT_EQ(-1, location);
  66. location = glGetFragDataLocation(program, "Unknown");
  67. EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
  68. EXPECT_EQ(-1, location);
  69. glLinkProgram(program);
  70. location = glGetFragDataLocation(program, "FragColor");
  71. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  72. EXPECT_EQ(0, location);
  73. location = glGetFragDataLocation(program, "Unknown");
  74. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  75. EXPECT_EQ(-1, location);
  76. glDeleteProgram(program);
  77. }
  78. TEST_F(OpenGLES3FunctionTest, GetStringiTest) {
  79. if (!IsApplicable()) {
  80. return;
  81. }
  82. std::string extensionString =
  83. reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
  84. std::vector<std::string> extensions =
  85. base::SplitString(extensionString, base::kWhitespaceASCII,
  86. base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
  87. int num_extensions = 0;
  88. glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
  89. EXPECT_EQ(extensions.size(), static_cast<size_t>(num_extensions));
  90. std::set<std::string> extensions_from_string(extensions.begin(),
  91. extensions.end());
  92. std::set<std::string> extensions_from_stringi;
  93. for (int i = 0; i < num_extensions; ++i) {
  94. extensions_from_stringi.insert(
  95. reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i)));
  96. }
  97. EXPECT_EQ(extensions_from_string, extensions_from_stringi);
  98. }
  99. } // namespace gpu