1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Fbo state query tests.
22 *//*--------------------------------------------------------------------*/
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"
33 using namespace glw; // GLint and other GL types
34 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
46 void checkIntEquals (tcu::TestContext& testCtx, GLint got, GLint expected)
52 testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got << TestLog::EndMessage;
53 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
54 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
58 void checkAttachmentParam(tcu::TestContext& testCtx, glu::CallLogWrapper& gl, GLenum target, GLenum attachment, GLenum pname, GLenum reference)
60 StateQueryMemoryWriteGuard<GLint> state;
61 gl.glGetFramebufferAttachmentParameteriv(target, attachment, pname, &state);
63 if (state.verifyValidity(testCtx))
64 checkIntEquals(testCtx, state, reference);
67 void checkColorAttachmentParam(tcu::TestContext& testCtx, glu::CallLogWrapper& gl, GLenum target, GLenum pname, GLenum reference)
69 checkAttachmentParam(testCtx, gl, target, GL_COLOR_ATTACHMENT0, pname, reference);
72 class AttachmentObjectCase : public ApiCase
75 AttachmentObjectCase (Context& context, const char* name, const char* description)
76 : ApiCase(context, name, description)
82 GLuint framebufferID = 0;
83 glGenFramebuffers(1, &framebufferID);
84 glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
85 expectError(GL_NO_ERROR);
90 glGenTextures(1, &textureID);
91 glBindTexture(GL_TEXTURE_2D, textureID);
92 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
93 expectError(GL_NO_ERROR);
95 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);
96 expectError(GL_NO_ERROR);
98 checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, GL_TEXTURE);
99 checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, textureID);
101 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
102 glDeleteTextures(1, &textureID);
107 GLuint renderbufferID = 0;
108 glGenRenderbuffers(1, &renderbufferID);
109 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
110 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 128, 128);
111 expectError(GL_NO_ERROR);
113 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbufferID);
114 expectError(GL_NO_ERROR);
116 checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, GL_RENDERBUFFER);
117 checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, renderbufferID);
119 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
120 glDeleteRenderbuffers(1, &renderbufferID);
123 glDeleteFramebuffers(1, &framebufferID);
124 expectError(GL_NO_ERROR);
128 class AttachmentTextureLevelCase : public ApiCase
131 AttachmentTextureLevelCase (Context& context, const char* name, const char* description)
132 : ApiCase(context, name, description)
138 GLuint framebufferID = 0;
139 glGenFramebuffers(1, &framebufferID);
140 glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
141 expectError(GL_NO_ERROR);
143 // GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL can only be 0
145 GLuint textureID = 0;
147 glGenTextures(1, &textureID);
148 glBindTexture(GL_TEXTURE_2D, textureID);
149 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, DE_NULL);
150 expectError(GL_NO_ERROR);
152 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);
153 expectError(GL_NO_ERROR);
155 checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, 0);
157 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
158 glDeleteTextures(1, &textureID);
161 glDeleteFramebuffers(1, &framebufferID);
162 expectError(GL_NO_ERROR);
166 class AttachmentTextureCubeMapFaceCase : public ApiCase
169 AttachmentTextureCubeMapFaceCase (Context& context, const char* name, const char* description)
170 : ApiCase(context, name, description)
176 GLuint framebufferID = 0;
177 glGenFramebuffers(1, &framebufferID);
178 glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
179 expectError(GL_NO_ERROR);
182 GLuint textureID = 0;
183 glGenTextures(1, &textureID);
184 glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
185 expectError(GL_NO_ERROR);
187 const GLenum faces[] =
189 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
190 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
191 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
194 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(faces); ++ndx)
195 glTexImage2D(faces[ndx], 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, DE_NULL);
196 expectError(GL_NO_ERROR);
198 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(faces); ++ndx)
200 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, faces[ndx], textureID, 0);
201 checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, faces[ndx]);
204 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
205 glDeleteTextures(1, &textureID);
208 glDeleteFramebuffers(1, &framebufferID);
209 expectError(GL_NO_ERROR);
216 FboStateQueryTests::FboStateQueryTests (Context& context)
217 : TestCaseGroup(context, "fbo", "Fbo State Query tests")
221 void FboStateQueryTests::init (void)
223 addChild(new AttachmentObjectCase (m_context, "framebuffer_attachment_object", "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE and FRAMEBUFFER_ATTACHMENT_OBJECT_NAME"));
224 addChild(new AttachmentTextureLevelCase (m_context, "framebuffer_attachment_texture_level", "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL"));
225 addChild(new AttachmentTextureCubeMapFaceCase (m_context, "framebuffer_attachment_texture_cube_map_face", "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE"));