Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | #include "test_utils/ANGLETest.h" |
| 8 | |
| 9 | using namespace angle; |
| 10 | |
| 11 | class DiscardFramebufferEXTTest : public ANGLETest |
| 12 | { |
| 13 | protected: |
| 14 | DiscardFramebufferEXTTest() |
| 15 | { |
| 16 | setWindowWidth(256); |
| 17 | setWindowHeight(256); |
| 18 | setConfigRedBits(8); |
| 19 | setConfigGreenBits(8); |
| 20 | setConfigBlueBits(8); |
| 21 | setConfigAlphaBits(8); |
| 22 | setConfigDepthBits(24); |
| 23 | setConfigStencilBits(8); |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | TEST_P(DiscardFramebufferEXTTest, ExtensionEnabled) |
| 28 | { |
Geoff Lang | dd323e9 | 2015-06-09 15:16:31 -0400 | [diff] [blame] | 29 | EGLPlatformParameters platform = GetParam().eglParameters; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 30 | |
| 31 | if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE) |
| 32 | { |
Kenneth Russell | e4bd041 | 2015-10-21 17:00:06 -0700 | [diff] [blame] | 33 | EXPECT_TRUE(extensionEnabled("EXT_discard_framebuffer")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 34 | } |
| 35 | else |
| 36 | { |
| 37 | // Other platforms don't currently implement this extension |
| 38 | EXPECT_FALSE(extensionEnabled("EXT_discard_framebuffer")); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | TEST_P(DiscardFramebufferEXTTest, DefaultFramebuffer) |
| 43 | { |
| 44 | if (!extensionEnabled("EXT_discard_framebuffer")) |
| 45 | { |
| 46 | std::cout << "Test skipped because EXT_discard_framebuffer is not available." << std::endl; |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | // These should succeed on the default framebuffer |
| 51 | const GLenum discards1[] = { GL_COLOR_EXT }; |
| 52 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards1); |
| 53 | EXPECT_GL_NO_ERROR(); |
| 54 | |
| 55 | const GLenum discards2[] = { GL_DEPTH_EXT }; |
| 56 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards2); |
| 57 | EXPECT_GL_NO_ERROR(); |
| 58 | |
| 59 | const GLenum discards3[] = { GL_STENCIL_EXT }; |
| 60 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards3); |
| 61 | EXPECT_GL_NO_ERROR(); |
| 62 | |
| 63 | const GLenum discards4[] = { GL_STENCIL_EXT, GL_COLOR_EXT, GL_DEPTH_EXT }; |
| 64 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 3, discards4); |
| 65 | EXPECT_GL_NO_ERROR(); |
| 66 | |
| 67 | // These should fail on the default framebuffer |
| 68 | const GLenum discards5[] = { GL_COLOR_ATTACHMENT0 }; |
| 69 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards5); |
| 70 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 71 | |
| 72 | const GLenum discards6[] = { GL_DEPTH_ATTACHMENT }; |
| 73 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards6); |
| 74 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 75 | |
| 76 | const GLenum discards7[] = { GL_STENCIL_ATTACHMENT }; |
| 77 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards7); |
| 78 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 79 | } |
| 80 | |
| 81 | TEST_P(DiscardFramebufferEXTTest, NonDefaultFramebuffer) |
| 82 | { |
| 83 | if (!extensionEnabled("EXT_discard_framebuffer")) |
| 84 | { |
| 85 | std::cout << "Test skipped because EXT_discard_framebuffer is not available." << std::endl; |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | GLuint tex2D; |
| 90 | GLuint framebuffer; |
| 91 | |
| 92 | // Create a basic off-screen framebuffer |
| 93 | // Don't create a depth/stencil texture, to ensure that also works correctly |
| 94 | glGenTextures(1, &tex2D); |
| 95 | glGenFramebuffers(1, &framebuffer); |
| 96 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 97 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 98 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 99 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 100 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 101 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex2D, 0); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 102 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 103 | |
| 104 | // These should fail on the non-default framebuffer |
| 105 | const GLenum discards1[] = { GL_COLOR_EXT }; |
| 106 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards1); |
| 107 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 108 | |
| 109 | const GLenum discards2[] = { GL_DEPTH_EXT }; |
| 110 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards2); |
| 111 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 112 | |
| 113 | const GLenum discards3[] = { GL_STENCIL_EXT }; |
| 114 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards3); |
| 115 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 116 | |
| 117 | const GLenum discards4[] = { GL_STENCIL_EXT, GL_COLOR_EXT, GL_DEPTH_EXT }; |
| 118 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 3, discards4); |
| 119 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 120 | |
| 121 | // These should succeed on the non-default framebuffer |
| 122 | const GLenum discards5[] = { GL_COLOR_ATTACHMENT0 }; |
| 123 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards5); |
| 124 | EXPECT_GL_NO_ERROR(); |
| 125 | |
| 126 | const GLenum discards6[] = { GL_DEPTH_ATTACHMENT }; |
| 127 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards6); |
| 128 | EXPECT_GL_NO_ERROR(); |
| 129 | |
| 130 | const GLenum discards7[] = { GL_STENCIL_ATTACHMENT }; |
| 131 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards7); |
| 132 | EXPECT_GL_NO_ERROR(); |
| 133 | } |
| 134 | |
| 135 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 136 | ANGLE_INSTANTIATE_TEST(DiscardFramebufferEXTTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3(), ES2_OPENGL(), ES3_OPENGL()); |