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