gl_bgra_mipmap_unittest.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 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 <stdint.h>
  7. #include "gpu/command_buffer/tests/gl_manager.h"
  8. #include "gpu/command_buffer/tests/gl_test_utils.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace gpu {
  11. // A collection of tests that exercise the GL_EXT_srgb extension.
  12. class GLBGRAMipMapTest : public testing::Test {
  13. protected:
  14. void SetUp() override { gl_.Initialize(GLManager::Options()); }
  15. void TearDown() override { gl_.Destroy(); }
  16. GLManager gl_;
  17. };
  18. // Test to ensure that using GL_BGRA as a texture internal format does
  19. // not hinder the use of mipmaps. Support for GL_BGRA as an internal format
  20. // is required by ES 2.0 (internal format must be equal to external format),
  21. // but some desktop GL implementations may not fully support the use of
  22. // GL_BGRA. For example, Mesa+Intel does not support mipmapping on textures
  23. // that use the GL_BGRA internal format. This test verifies a workaround.
  24. TEST_F(GLBGRAMipMapTest, GenerateMipmapsSucceeds) {
  25. static const int kWidth = 100;
  26. static const int kHeight = 50;
  27. uint8_t pixels[kWidth * kHeight * 4];
  28. GLuint tex = 0;
  29. glGenTextures(1, &tex);
  30. glBindTexture(GL_TEXTURE_2D, tex);
  31. memset(pixels, 128, sizeof(pixels));
  32. glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, kWidth, kHeight, 0,
  33. GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
  34. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  35. // Without the workaround, the following call generates a
  36. // GL_INVALID_OPERATION error on some desktop GL implementations
  37. glGenerateMipmap(GL_TEXTURE_2D);
  38. EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
  39. }
  40. } // namespace gpu