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
37 namespace deqp
38 {
39 namespace gles2
40 {
41 namespace Functional
42 {
43 namespace
44 {
45
checkIntEquals(tcu::TestContext & testCtx,GLint got,GLint expected)46 void checkIntEquals (tcu::TestContext& testCtx, GLint got, GLint expected)
47 {
48 using tcu::TestLog;
49
50 if (got != expected)
51 {
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");
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, GLenum pname, GLenum reference)
59 {
60 StateQueryMemoryWriteGuard<GLint> state;
61 gl.glGetFramebufferAttachmentParameteriv(target, attachment, pname, &state);
62
63 if (state.verifyValidity(testCtx))
64 checkIntEquals(testCtx, state, reference);
65 }
66
checkColorAttachmentParam(tcu::TestContext & testCtx,glu::CallLogWrapper & gl,GLenum target,GLenum pname,GLenum reference)67 void checkColorAttachmentParam(tcu::TestContext& testCtx, glu::CallLogWrapper& gl, GLenum target, GLenum pname, GLenum reference)
68 {
69 checkAttachmentParam(testCtx, gl, target, GL_COLOR_ATTACHMENT0, pname, reference);
70 }
71
72 class AttachmentObjectCase : public ApiCase
73 {
74 public:
AttachmentObjectCase(Context & context,const char * name,const char * description)75 AttachmentObjectCase (Context& context, const char* name, const char* description)
76 : ApiCase(context, name, description)
77 {
78 }
79
test(void)80 void test (void)
81 {
82 GLuint framebufferID = 0;
83 glGenFramebuffers(1, &framebufferID);
84 glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
85 expectError(GL_NO_ERROR);
86
87 // texture
88 {
89 GLuint textureID = 0;
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);
94
95 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);
96 expectError(GL_NO_ERROR);
97
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);
100
101 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
102 glDeleteTextures(1, &textureID);
103 }
104
105 // rb
106 {
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);
112
113 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbufferID);
114 expectError(GL_NO_ERROR);
115
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);
118
119 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
120 glDeleteRenderbuffers(1, &renderbufferID);
121 }
122
123 glDeleteFramebuffers(1, &framebufferID);
124 expectError(GL_NO_ERROR);
125 }
126 };
127
128 class AttachmentTextureLevelCase : public ApiCase
129 {
130 public:
AttachmentTextureLevelCase(Context & context,const char * name,const char * description)131 AttachmentTextureLevelCase (Context& context, const char* name, const char* description)
132 : ApiCase(context, name, description)
133 {
134 }
135
test(void)136 void test (void)
137 {
138 GLuint framebufferID = 0;
139 glGenFramebuffers(1, &framebufferID);
140 glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
141 expectError(GL_NO_ERROR);
142
143 // GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL can only be 0
144 {
145 GLuint textureID = 0;
146
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);
151
152 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);
153 expectError(GL_NO_ERROR);
154
155 checkColorAttachmentParam(m_testCtx, *this, GL_FRAMEBUFFER, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, 0);
156
157 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
158 glDeleteTextures(1, &textureID);
159 }
160
161 glDeleteFramebuffers(1, &framebufferID);
162 expectError(GL_NO_ERROR);
163 }
164 };
165
166 class AttachmentTextureCubeMapFaceCase : public ApiCase
167 {
168 public:
AttachmentTextureCubeMapFaceCase(Context & context,const char * name,const char * description)169 AttachmentTextureCubeMapFaceCase (Context& context, const char* name, const char* description)
170 : ApiCase(context, name, description)
171 {
172 }
173
test(void)174 void test (void)
175 {
176 GLuint framebufferID = 0;
177 glGenFramebuffers(1, &framebufferID);
178 glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
179 expectError(GL_NO_ERROR);
180
181 {
182 GLuint textureID = 0;
183 glGenTextures(1, &textureID);
184 glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
185 expectError(GL_NO_ERROR);
186
187 const GLenum faces[] =
188 {
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
192 };
193
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);
197
198 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(faces); ++ndx)
199 {
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]);
202 }
203
204 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
205 glDeleteTextures(1, &textureID);
206 }
207
208 glDeleteFramebuffers(1, &framebufferID);
209 expectError(GL_NO_ERROR);
210 }
211 };
212
213 } // anonymous
214
215
FboStateQueryTests(Context & context)216 FboStateQueryTests::FboStateQueryTests (Context& context)
217 : TestCaseGroup(context, "fbo", "Fbo State Query tests")
218 {
219 }
220
init(void)221 void FboStateQueryTests::init (void)
222 {
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"));
226 }
227
228 } // Functional
229 } // gles2
230 } // deqp
231