• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 firstFBO = 0;
41     glGenFramebuffers(1, &firstFBO);
42     glBindFramebuffer(GL_FRAMEBUFFER, 1);
43     glDeleteFramebuffers(1, &firstFBO);
44 
45     glBindFramebuffer(GL_FRAMEBUFFER, 2);
46     GLuint secondFBOs[2] = {0};
47     glGenFramebuffers(2, secondFBOs);
48     EXPECT_NE(2u, secondFBOs[0]);
49     EXPECT_NE(2u, secondFBOs[1]);
50     glDeleteFramebuffers(2, secondFBOs);
51 
52     EXPECT_GL_NO_ERROR();
53 }
54 
55 // Test that we don't re-allocate a bound framebuffer ID.
TEST_P(ObjectAllocationTest,BindRenderbuffer)56 TEST_P(ObjectAllocationTest, BindRenderbuffer)
57 {
58     GLuint rbId;
59     glGenRenderbuffers(1, &rbId);
60     glBindRenderbuffer(GL_RENDERBUFFER, rbId);
61     EXPECT_GL_NO_ERROR();
62 
63     // Swap now to trigger the serialization of the renderbuffer that
64     // was initialized with the default values
65     swapBuffers();
66 
67     glDeleteRenderbuffers(1, &rbId);
68     EXPECT_GL_NO_ERROR();
69 }
70 
71 // Renderbuffers can be created on the fly by calling glBindRenderbuffer,
72 // so// check that the call doesn't fail that the renderbuffer is also deleted
TEST_P(ObjectAllocationTest,BindRenderbufferBeforeGenAndDelete)73 TEST_P(ObjectAllocationTest, BindRenderbufferBeforeGenAndDelete)
74 {
75     GLuint rbId = 1;
76     glBindRenderbuffer(GL_RENDERBUFFER, rbId);
77     EXPECT_GL_NO_ERROR();
78 
79     // Swap now to trigger the serialization of the renderbuffer that
80     // was initialized with the default values
81     swapBuffers();
82 
83     glDeleteRenderbuffers(1, &rbId);
84     EXPECT_GL_NO_ERROR();
85 }
86 
87 // Buffers can be created on the fly by calling glBindBuffer, so
88 // check that the call doesn't fail that the buffer is also deleted
TEST_P(ObjectAllocationTest,BindBufferBeforeGenAndDelete)89 TEST_P(ObjectAllocationTest, BindBufferBeforeGenAndDelete)
90 {
91     GLuint id = 1;
92     glBindBuffer(GL_ARRAY_BUFFER, id);
93     EXPECT_GL_NO_ERROR();
94     // trigger serialization to capture the created buffer ID
95     swapBuffers();
96     glDeleteBuffers(1, &id);
97     EXPECT_GL_NO_ERROR();
98 }
99 
100 // Textures can be created on the fly by calling glBindTexture, so
101 // check that the call doesn't fail that the texture is also deleted
TEST_P(ObjectAllocationTest,BindTextureBeforeGenAndDelete)102 TEST_P(ObjectAllocationTest, BindTextureBeforeGenAndDelete)
103 {
104     GLuint id = 1;
105     glBindTexture(GL_TEXTURE_2D, id);
106     EXPECT_GL_NO_ERROR();
107     // trigger serialization to capture the created texture ID
108     swapBuffers();
109     glDeleteTextures(1, &id);
110     EXPECT_GL_NO_ERROR();
111 }
112 
113 }  // anonymous namespace
114 
115 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ObjectAllocationTest);
116 ANGLE_INSTANTIATE_TEST_ES2(ObjectAllocationTest);
117 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ObjectAllocationTestES3);
118 ANGLE_INSTANTIATE_TEST_ES3(ObjectAllocationTestES3);
119