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 // ObjectAllocationTest
7 // Tests for object allocations and lifetimes.
8 //
9
10 #include "test_utils/ANGLETest.h"
11
12 using namespace angle;
13
14 namespace
15 {
16
17 class ObjectAllocationTest : public ANGLETest<>
18 {
19 protected:
ObjectAllocationTest()20 ObjectAllocationTest() {}
21 };
22
23 class ObjectAllocationTestES3 : public ObjectAllocationTest
24 {};
25
26 // Test that we don't re-allocate a bound framebuffer ID.
TEST_P(ObjectAllocationTestES3,BindFramebufferBeforeGen)27 TEST_P(ObjectAllocationTestES3, BindFramebufferBeforeGen)
28 {
29 glBindFramebuffer(GL_FRAMEBUFFER, 1);
30 GLuint fbo = 0;
31 glGenFramebuffers(1, &fbo);
32 EXPECT_NE(1u, fbo);
33 glDeleteFramebuffers(1, &fbo);
34 EXPECT_GL_NO_ERROR();
35 }
36
37 // Test that we don't re-allocate a bound framebuffer ID, other pattern.
TEST_P(ObjectAllocationTestES3,BindFramebufferAfterGen)38 TEST_P(ObjectAllocationTestES3, BindFramebufferAfterGen)
39 {
40 GLuint reservedFBO1 = 1;
41 GLuint reservedFBO2 = 2;
42
43 GLuint firstFBO = 0;
44 glGenFramebuffers(1, &firstFBO);
45 glBindFramebuffer(GL_FRAMEBUFFER, reservedFBO1);
46 glDeleteFramebuffers(1, &firstFBO);
47
48 glBindFramebuffer(GL_FRAMEBUFFER, reservedFBO2);
49 GLuint secondFBOs[2] = {0};
50 glGenFramebuffers(2, secondFBOs);
51 EXPECT_NE(reservedFBO2, secondFBOs[0]);
52 EXPECT_NE(reservedFBO2, secondFBOs[1]);
53 glDeleteFramebuffers(2, secondFBOs);
54
55 // Clean up
56 glDeleteFramebuffers(1, &reservedFBO1);
57 glDeleteFramebuffers(1, &reservedFBO2);
58
59 EXPECT_GL_NO_ERROR();
60 }
61
62 // Test that we don't re-allocate a bound framebuffer ID.
TEST_P(ObjectAllocationTest,BindRenderbuffer)63 TEST_P(ObjectAllocationTest, BindRenderbuffer)
64 {
65 GLuint rbId;
66 glGenRenderbuffers(1, &rbId);
67 glBindRenderbuffer(GL_RENDERBUFFER, rbId);
68 EXPECT_GL_NO_ERROR();
69
70 // Swap now to trigger the serialization of the renderbuffer that
71 // was initialized with the default values
72 swapBuffers();
73
74 glDeleteRenderbuffers(1, &rbId);
75 EXPECT_GL_NO_ERROR();
76 }
77
78 // Renderbuffers can be created on the fly by calling glBindRenderbuffer,
79 // so// check that the call doesn't fail that the renderbuffer is also deleted
TEST_P(ObjectAllocationTest,BindRenderbufferBeforeGenAndDelete)80 TEST_P(ObjectAllocationTest, BindRenderbufferBeforeGenAndDelete)
81 {
82 GLuint rbId = 1;
83 glBindRenderbuffer(GL_RENDERBUFFER, rbId);
84 EXPECT_GL_NO_ERROR();
85
86 // Swap now to trigger the serialization of the renderbuffer that
87 // was initialized with the default values
88 swapBuffers();
89
90 glDeleteRenderbuffers(1, &rbId);
91 EXPECT_GL_NO_ERROR();
92 }
93
94 // Buffers can be created on the fly by calling glBindBuffer, so
95 // check that the call doesn't fail that the buffer is also deleted
TEST_P(ObjectAllocationTest,BindBufferBeforeGenAndDelete)96 TEST_P(ObjectAllocationTest, BindBufferBeforeGenAndDelete)
97 {
98 GLuint id = 1;
99 glBindBuffer(GL_ARRAY_BUFFER, id);
100 EXPECT_GL_NO_ERROR();
101 // trigger serialization to capture the created buffer ID
102 swapBuffers();
103 glDeleteBuffers(1, &id);
104 EXPECT_GL_NO_ERROR();
105 }
106
107 // Textures can be created on the fly by calling glBindTexture, so
108 // check that the call doesn't fail that the texture is also deleted
TEST_P(ObjectAllocationTest,BindTextureBeforeGenAndDelete)109 TEST_P(ObjectAllocationTest, BindTextureBeforeGenAndDelete)
110 {
111 GLuint id = 1;
112 glBindTexture(GL_TEXTURE_2D, id);
113 EXPECT_GL_NO_ERROR();
114 // trigger serialization to capture the created texture ID
115 swapBuffers();
116 glDeleteTextures(1, &id);
117 EXPECT_GL_NO_ERROR();
118 }
119
120 } // anonymous namespace
121
122 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ObjectAllocationTest);
123 ANGLE_INSTANTIATE_TEST_ES2(ObjectAllocationTest);
124 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ObjectAllocationTestES3);
125 ANGLE_INSTANTIATE_TEST_ES3(ObjectAllocationTestES3);
126