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:
DiscardFramebufferEXTTest()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
TEST_P(DiscardFramebufferEXTTest,DefaultFramebuffer)27 TEST_P(DiscardFramebufferEXTTest, DefaultFramebuffer)
28 {
29 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_discard_framebuffer"));
30
31 // TODO: fix crash issue. http://anglebug.com/4141
32 ANGLE_SKIP_TEST_IF(IsD3D11());
33
34 // These should succeed on the default framebuffer
35 const GLenum discards1[] = {GL_COLOR_EXT};
36 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards1);
37 EXPECT_GL_NO_ERROR();
38
39 const GLenum discards2[] = {GL_DEPTH_EXT};
40 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards2);
41 EXPECT_GL_NO_ERROR();
42
43 const GLenum discards3[] = {GL_STENCIL_EXT};
44 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards3);
45 EXPECT_GL_NO_ERROR();
46
47 const GLenum discards4[] = {GL_STENCIL_EXT, GL_COLOR_EXT, GL_DEPTH_EXT};
48 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 3, discards4);
49 EXPECT_GL_NO_ERROR();
50
51 // These should fail on the default framebuffer
52 const GLenum discards5[] = {GL_COLOR_ATTACHMENT0};
53 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards5);
54 EXPECT_GL_ERROR(GL_INVALID_ENUM);
55
56 const GLenum discards6[] = {GL_DEPTH_ATTACHMENT};
57 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards6);
58 EXPECT_GL_ERROR(GL_INVALID_ENUM);
59
60 const GLenum discards7[] = {GL_STENCIL_ATTACHMENT};
61 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards7);
62 EXPECT_GL_ERROR(GL_INVALID_ENUM);
63 }
64
TEST_P(DiscardFramebufferEXTTest,NonDefaultFramebuffer)65 TEST_P(DiscardFramebufferEXTTest, NonDefaultFramebuffer)
66 {
67 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_discard_framebuffer"));
68
69 GLuint tex2D;
70 GLuint framebuffer;
71
72 // Create a basic off-screen framebuffer
73 // Don't create a depth/stencil texture, to ensure that also works correctly
74 glGenTextures(1, &tex2D);
75 glGenFramebuffers(1, &framebuffer);
76 glBindTexture(GL_TEXTURE_2D, tex2D);
77 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
78 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
79 GL_UNSIGNED_BYTE, nullptr);
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
82 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex2D, 0);
83 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
84
85 // These should fail on the non-default framebuffer
86 const GLenum discards1[] = {GL_COLOR_EXT};
87 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards1);
88 EXPECT_GL_ERROR(GL_INVALID_ENUM);
89
90 const GLenum discards2[] = {GL_DEPTH_EXT};
91 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards2);
92 EXPECT_GL_ERROR(GL_INVALID_ENUM);
93
94 const GLenum discards3[] = {GL_STENCIL_EXT};
95 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards3);
96 EXPECT_GL_ERROR(GL_INVALID_ENUM);
97
98 const GLenum discards4[] = {GL_STENCIL_EXT, GL_COLOR_EXT, GL_DEPTH_EXT};
99 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 3, discards4);
100 EXPECT_GL_ERROR(GL_INVALID_ENUM);
101
102 // These should succeed on the non-default framebuffer
103 const GLenum discards5[] = {GL_COLOR_ATTACHMENT0};
104 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards5);
105 EXPECT_GL_NO_ERROR();
106
107 const GLenum discards6[] = {GL_DEPTH_ATTACHMENT};
108 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards6);
109 EXPECT_GL_NO_ERROR();
110
111 const GLenum discards7[] = {GL_STENCIL_ATTACHMENT};
112 glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards7);
113 EXPECT_GL_NO_ERROR();
114 }
115
116 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
117 // tests should be run against.
118 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(DiscardFramebufferEXTTest);
119