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