• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 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 // FramebufferObjectTest.cpp: Tests basic usage of OES_framebuffer_object extension.
8 
9 #include "test_utils/ANGLETest.h"
10 #include "test_utils/gl_raii.h"
11 
12 using namespace angle;
13 
14 class FramebufferObjectTest : public ANGLETest
15 {
16   protected:
FramebufferObjectTest()17     FramebufferObjectTest()
18     {
19         setWindowWidth(32);
20         setWindowHeight(32);
21         setConfigRedBits(8);
22         setConfigGreenBits(8);
23         setConfigBlueBits(8);
24         setConfigAlphaBits(8);
25         setConfigDepthBits(24);
26     }
27 
testSetUp()28     void testSetUp() override
29     {
30         mTexture.reset(new GLTexture());
31         glEnable(GL_TEXTURE_2D);
32         glBindTexture(GL_TEXTURE_2D, mTexture->get());
33     }
34 
testTearDown()35     void testTearDown() override { mTexture.reset(); }
36 
37     std::unique_ptr<GLTexture> mTexture;
38 };
39 
40 // Checks that framebuffer object can be used without GL errors.
TEST_P(FramebufferObjectTest,FramebufferObject)41 TEST_P(FramebufferObjectTest, FramebufferObject)
42 {
43     GLuint fboId;
44     GLint params;
45 
46     glGenFramebuffersOES(1, &fboId);
47     EXPECT_GL_NO_ERROR();
48     glIsFramebufferOES(fboId);
49     EXPECT_GL_NO_ERROR();
50     glBindFramebufferOES(GL_FRAMEBUFFER, fboId);
51     EXPECT_GL_NO_ERROR();
52 
53     glCheckFramebufferStatusOES(GL_FRAMEBUFFER);
54     EXPECT_GL_NO_ERROR();
55     glGetFramebufferAttachmentParameterivOES(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
56                                              GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &params);
57     EXPECT_GL_NO_ERROR();
58 
59     glBindFramebuffer(GL_FRAMEBUFFER, 0);
60     glDeleteFramebuffersOES(1, &fboId);
61     EXPECT_GL_NO_ERROR();
62 }
63 
64 // Checks that texture object can be bound for framebuffer object.
TEST_P(FramebufferObjectTest,TextureObject)65 TEST_P(FramebufferObjectTest, TextureObject)
66 {
67     GLuint fboId;
68 
69     glGenFramebuffers(1, &fboId);
70     glBindFramebuffer(GL_FRAMEBUFFER, fboId);
71     glFramebufferTexture2DOES(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture->get(),
72                               0);
73     EXPECT_GL_NO_ERROR();
74 
75     glBindFramebuffer(GL_FRAMEBUFFER, 0);
76     glDeleteFramebuffers(1, &fboId);
77 }
78 
79 // Checks different formats for a texture object bound to a framebuffer object.
TEST_P(FramebufferObjectTest,TextureObjectDifferentFormats)80 TEST_P(FramebufferObjectTest, TextureObjectDifferentFormats)
81 {
82     // http://anglebug.com/5642
83     ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
84 
85     GLuint fboId;
86 
87     glGenFramebuffersOES(1, &fboId);
88     glBindFramebufferOES(GL_FRAMEBUFFER_OES, fboId);
89 
90     using FormatInfo                                  = std::array<GLenum, 3>;
91     constexpr std::array<FormatInfo, 5> kFormatArrays = {
92         {{GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
93          {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE},
94          {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4},
95          {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1},
96          {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}}};
97 
98     for (const FormatInfo &formatInfo : kFormatArrays)
99     {
100         glTexImage2D(GL_TEXTURE_2D, 0, formatInfo[0], 1, 1, 0, formatInfo[1], formatInfo[2],
101                      &GLColor::green);
102         glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D,
103                                   mTexture->get(), 0);
104         ASSERT_EQ(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES),
105                   (GLenum)GL_FRAMEBUFFER_COMPLETE_OES);
106     }
107 
108     EXPECT_GL_NO_ERROR();
109 
110     glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
111     glDeleteFramebuffersOES(1, &fboId);
112 }
113 
114 // Checks that renderbuffer object can be used and can be bound for framebuffer object.
TEST_P(FramebufferObjectTest,RenderbufferObject)115 TEST_P(FramebufferObjectTest, RenderbufferObject)
116 {
117     GLuint fboId;
118     GLuint rboId;
119     GLint params;
120 
121     glGenFramebuffers(1, &fboId);
122     glBindFramebuffer(GL_FRAMEBUFFER, fboId);
123 
124     glGenRenderbuffersOES(1, &rboId);
125     EXPECT_GL_NO_ERROR();
126     glIsRenderbufferOES(rboId);
127     EXPECT_GL_NO_ERROR();
128     glBindRenderbufferOES(GL_RENDERBUFFER, rboId);
129     EXPECT_GL_NO_ERROR();
130     glRenderbufferStorageOES(GL_RENDERBUFFER, GL_RGBA8, 32, 32);
131     EXPECT_GL_NO_ERROR();
132 
133     glFramebufferRenderbufferOES(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rboId);
134     EXPECT_GL_NO_ERROR();
135     glGetRenderbufferParameterivOES(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &params);
136     EXPECT_GL_NO_ERROR();
137 
138     glBindFramebuffer(GL_FRAMEBUFFER, 0);
139     glDeleteFramebuffers(1, &fboId);
140     glDeleteRenderbuffersOES(1, &rboId);
141     EXPECT_GL_NO_ERROR();
142 }
143 
144 // Checks that generateMipmap can be called without GL errors.
TEST_P(FramebufferObjectTest,GenerateMipmap)145 TEST_P(FramebufferObjectTest, GenerateMipmap)
146 {
147     constexpr uint32_t kSize = 32;
148     std::vector<unsigned char> pixelData(kSize * kSize * 4, 0);
149 
150     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
151 
152     glGenerateMipmapOES(GL_TEXTURE_2D);
153     EXPECT_GL_NO_ERROR();
154 }
155 
156 ANGLE_INSTANTIATE_TEST_ES1(FramebufferObjectTest);