xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fFboStateQueryTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 2.0 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Fbo state query tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es2fFboStateQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "es2fApiCase.hpp"
27 #include "gluRenderContext.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
30 #include "tcuRenderTarget.hpp"
31 #include "deMath.h"
32 
33 using namespace glw; // GLint and other GL types
34 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
35 
36 namespace deqp
37 {
38 namespace gles2
39 {
40 namespace Functional
41 {
42 namespace
43 {
44 
checkIntEquals(tcu::TestContext & testCtx,GLint got,GLint expected)45 void checkIntEquals(tcu::TestContext &testCtx, GLint got, GLint expected)
46 {
47     using tcu::TestLog;
48 
49     if (got != expected)
50     {
51         testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got
52                          << TestLog::EndMessage;
53         if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
54             testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
55     }
56 }
57 
checkAttachmentParam(tcu::TestContext & testCtx,glu::CallLogWrapper & gl,GLenum target,GLenum attachment,GLenum pname,GLenum reference)58 void checkAttachmentParam(tcu::TestContext &testCtx, glu::CallLogWrapper &gl, GLenum target, GLenum attachment,
59                           GLenum pname, GLenum reference)
60 {
61     StateQueryMemoryWriteGuard<GLint> state;
62     gl.glGetFramebufferAttachmentParameteriv(target, attachment, pname, &state);
63 
64     if (state.verifyValidity(testCtx))
65         checkIntEquals(testCtx, state, reference);
66 }
67 
checkColorAttachmentParam(tcu::TestContext & testCtx,glu::CallLogWrapper & gl,GLenum target,GLenum pname,GLenum reference)68 void checkColorAttachmentParam(tcu::TestContext &testCtx, glu::CallLogWrapper &gl, GLenum target, GLenum pname,
69                                GLenum reference)
70 {
71     checkAttachmentParam(testCtx, gl, target, GL_COLOR_ATTACHMENT0, pname, reference);
72 }
73 
74 class AttachmentObjectCase : public ApiCase
75 {
76 public:
AttachmentObjectCase(Context & context,const char * name,const char * description)77     AttachmentObjectCase(Context &context, const char *name, const char *description)
78         : ApiCase(context, name, description)
79     {
80     }
81 
test(void)82     void test(void)
83     {
84         GLuint framebufferID = 0;
85         glGenFramebuffers(1, &framebufferID);
86         glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
87         expectError(GL_NO_ERROR);
88 
89         // texture
90         {
91             GLuint textureID = 0;
92             glGenTextures(1, &textureID);
93             glBindTexture(GL_TEXTURE_2D, textureID);
94             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
95             expectError(GL_NO_ERROR);
96 
97             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);
98             expectError(GL_NO_ERROR);
99 
100             checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
101                                       GL_TEXTURE);
102             checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
103                                       textureID);
104 
105             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
106             glDeleteTextures(1, &textureID);
107         }
108 
109         // rb
110         {
111             GLuint renderbufferID = 0;
112             glGenRenderbuffers(1, &renderbufferID);
113             glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
114             glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 128, 128);
115             expectError(GL_NO_ERROR);
116 
117             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbufferID);
118             expectError(GL_NO_ERROR);
119 
120             checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
121                                       GL_RENDERBUFFER);
122             checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
123                                       renderbufferID);
124 
125             glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
126             glDeleteRenderbuffers(1, &renderbufferID);
127         }
128 
129         glDeleteFramebuffers(1, &framebufferID);
130         expectError(GL_NO_ERROR);
131     }
132 };
133 
134 class AttachmentTextureLevelCase : public ApiCase
135 {
136 public:
AttachmentTextureLevelCase(Context & context,const char * name,const char * description)137     AttachmentTextureLevelCase(Context &context, const char *name, const char *description)
138         : ApiCase(context, name, description)
139     {
140     }
141 
test(void)142     void test(void)
143     {
144         GLuint framebufferID = 0;
145         glGenFramebuffers(1, &framebufferID);
146         glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
147         expectError(GL_NO_ERROR);
148 
149         // GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL can only be 0
150         {
151             GLuint textureID = 0;
152 
153             glGenTextures(1, &textureID);
154             glBindTexture(GL_TEXTURE_2D, textureID);
155             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, DE_NULL);
156             expectError(GL_NO_ERROR);
157 
158             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);
159             expectError(GL_NO_ERROR);
160 
161             checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, 0);
162 
163             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
164             glDeleteTextures(1, &textureID);
165         }
166 
167         glDeleteFramebuffers(1, &framebufferID);
168         expectError(GL_NO_ERROR);
169     }
170 };
171 
172 class AttachmentTextureCubeMapFaceCase : public ApiCase
173 {
174 public:
AttachmentTextureCubeMapFaceCase(Context & context,const char * name,const char * description)175     AttachmentTextureCubeMapFaceCase(Context &context, const char *name, const char *description)
176         : ApiCase(context, name, description)
177     {
178     }
179 
test(void)180     void test(void)
181     {
182         GLuint framebufferID = 0;
183         glGenFramebuffers(1, &framebufferID);
184         glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
185         expectError(GL_NO_ERROR);
186 
187         {
188             GLuint textureID = 0;
189             glGenTextures(1, &textureID);
190             glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
191             expectError(GL_NO_ERROR);
192 
193             const GLenum faces[] = {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
194                                     GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
195                                     GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z};
196 
197             for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(faces); ++ndx)
198                 glTexImage2D(faces[ndx], 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, DE_NULL);
199             expectError(GL_NO_ERROR);
200 
201             for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(faces); ++ndx)
202             {
203                 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, faces[ndx], textureID, 0);
204                 checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER,
205                                           GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, faces[ndx]);
206             }
207 
208             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
209             glDeleteTextures(1, &textureID);
210         }
211 
212         glDeleteFramebuffers(1, &framebufferID);
213         expectError(GL_NO_ERROR);
214     }
215 };
216 
217 } // namespace
218 
FboStateQueryTests(Context & context)219 FboStateQueryTests::FboStateQueryTests(Context &context) : TestCaseGroup(context, "fbo", "Fbo State Query tests")
220 {
221 }
222 
init(void)223 void FboStateQueryTests::init(void)
224 {
225     addChild(new AttachmentObjectCase(m_context, "framebuffer_attachment_object",
226                                       "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE and FRAMEBUFFER_ATTACHMENT_OBJECT_NAME"));
227     addChild(new AttachmentTextureLevelCase(m_context, "framebuffer_attachment_texture_level",
228                                             "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL"));
229     addChild(new AttachmentTextureCubeMapFaceCase(m_context, "framebuffer_attachment_texture_cube_map_face",
230                                                   "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE"));
231 }
232 
233 } // namespace Functional
234 } // namespace gles2
235 } // namespace deqp
236