1 /*------------------------------------------------------------------------- 2 * OpenGL Conformance Test Suite 3 * ----------------------------- 4 * 5 * Copyright (c) 2014-2016 The Khronos Group Inc. 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 22 */ /*-------------------------------------------------------------------*/ 23 24 /*! 25 * \file esextcTextureBufferErrors.hpp 26 * \brief TexBufferEXT and TexBufferRangeEXT errors (Test 7) 27 */ /*-------------------------------------------------------------------*/ 28 29 #include "esextcTextureBufferErrors.hpp" 30 #include "gluContextInfo.hpp" 31 #include "gluDefs.hpp" 32 #include "glwEnums.hpp" 33 #include "glwFunctions.hpp" 34 #include "tcuTestLog.hpp" 35 #include <cstddef> 36 37 namespace glcts 38 { 39 40 /* Size of buffer object's data store */ 41 const glw::GLint TextureBufferErrors::m_bo_size = 42 256 /* number of texels */ * 4 /* number of components */ * sizeof(glw::GLint); 43 44 /** Constructor 45 * 46 * @param context Test context 47 * @param name Test case's name 48 * @param description Test case's description 49 **/ 50 TextureBufferErrors::TextureBufferErrors(Context& context, const ExtParameters& extParams, const char* name, 51 const char* description) 52 : TestCaseBase(context, extParams, name, description), m_bo_id(0), m_tex_id(0) 53 { 54 } 55 56 /** Deinitializes all GLES objects created for the test. */ 57 void TextureBufferErrors::deinit(void) 58 { 59 /* Retrieve GLES entry points. */ 60 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 61 62 /* Reset GLES state */ 63 gl.bindTexture(m_glExtTokens.TEXTURE_BUFFER, 0); 64 gl.bindBuffer(m_glExtTokens.TEXTURE_BUFFER, 0); 65 66 /* Delete GLES objects */ 67 if (m_tex_id != 0) 68 { 69 gl.deleteTextures(1, &m_tex_id); 70 m_tex_id = 0; 71 } 72 73 if (m_bo_id != 0) 74 { 75 gl.deleteBuffers(1, &m_bo_id); 76 m_bo_id = 0; 77 } 78 79 /* Deinitialize base class */ 80 TestCaseBase::deinit(); 81 } 82 83 /** Initializes all GLES objects and reference values for the test. */ 84 void TextureBufferErrors::initTest(void) 85 { 86 /* Skip if required extensions are not supported. */ 87 if (!m_is_texture_buffer_supported) 88 { 89 throw tcu::NotSupportedError(TEXTURE_BUFFER_EXTENSION_NOT_SUPPORTED, "", __FILE__, __LINE__); 90 } 91 92 /* Retrieve GLES entry points. */ 93 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 94 95 gl.genTextures(1, &m_tex_id); 96 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not generate texture object!"); 97 98 gl.bindTexture(m_glExtTokens.TEXTURE_BUFFER, m_tex_id); 99 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not bind texture object!"); 100 101 gl.genBuffers(1, &m_bo_id); 102 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not generate buffer object!"); 103 104 gl.bindBuffer(m_glExtTokens.TEXTURE_BUFFER, m_bo_id); 105 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not bind buffer object!"); 106 107 gl.bufferData(m_glExtTokens.TEXTURE_BUFFER, m_bo_size, DE_NULL, GL_STATIC_READ); 108 GLU_EXPECT_NO_ERROR(gl.getError(), "Could not allocate buffer object's data store"); 109 110 m_texture_targets.push_back(GL_TEXTURE_2D); 111 m_texture_targets.push_back(GL_TEXTURE_2D_ARRAY); 112 m_texture_targets.push_back(GL_TEXTURE_3D); 113 m_texture_targets.push_back(GL_TEXTURE_CUBE_MAP); 114 115 if (m_is_texture_cube_map_array_supported) 116 { 117 m_texture_targets.push_back(GL_TEXTURE_CUBE_MAP_ARRAY); 118 } 119 120 if (m_is_texture_storage_multisample_supported) 121 { 122 m_texture_targets.push_back(GL_TEXTURE_2D_MULTISAMPLE); 123 } 124 125 if (m_is_texture_storage_multisample_2d_array_supported) 126 { 127 m_texture_targets.push_back(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES); 128 } 129 } 130 /** Test if the error code returned by glGetError is the same as expected. 131 * If the error is different from expected description is logged. 132 * 133 * @param expected_error GLenum error which is expected 134 * @param description Log message in the case of failure. 135 * 136 * @return true if error is equal to expected, false otherwise. 137 */ 138 glw::GLboolean TextureBufferErrors::verifyError(const glw::GLenum expected_error, const char* description) 139 { 140 /* Retrieve GLES entry points. */ 141 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 142 143 glw::GLboolean test_passed = true; 144 glw::GLenum error_code = gl.getError(); 145 146 if (error_code != expected_error) 147 { 148 test_passed = false; 149 150 m_testCtx.getLog() << tcu::TestLog::Message << description << tcu::TestLog::EndMessage; 151 } 152 153 return test_passed; 154 } 155 156 /** Executes the test. 157 * 158 * Sets the test result to QP_TEST_RESULT_FAIL if the test failed, QP_TEST_RESULT_PASS otherwise. 159 * 160 * Note the function throws exception should an error occur! 161 * 162 * @return STOP if the test has finished, CONTINUE to indicate iterate should be called once again. 163 **/ 164 tcu::TestNode::IterateResult TextureBufferErrors::iterate(void) 165 { 166 /* Initialization */ 167 initTest(); 168 169 /* Retrieve ES entry/state points. */ 170 const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 171 172 glw::GLboolean test_passed = true; 173 174 /*An INVALID_ENUM error should be generated if target parameter is not TEXTURE_BUFFER_EXT.*/ 175 for (TargetsVector::iterator iter = m_texture_targets.begin(); iter != m_texture_targets.end(); ++iter) 176 { 177 gl.texBuffer(*iter, GL_RGBA32I, m_bo_id); 178 test_passed = verifyError(GL_INVALID_ENUM, "Expected GL_INVALID_ENUM was not returned " 179 "when wrong texture target was used in glTexBufferEXT.") && 180 test_passed; 181 182 gl.texBufferRange(*iter, GL_RGBA32I, m_bo_id, 0, m_bo_size); 183 test_passed = verifyError(GL_INVALID_ENUM, "Expected GL_INVALID_ENUM was not returned " 184 "when wrong texture target was used in glTexBufferRangeEXT.") && 185 test_passed; 186 } 187 188 /* An INVALID_ENUM error should be generated if internal format parameter 189 * is not one of the sized internal formats specified in the extension 190 * specification. One of the formats that should generate INVALID_ENUM 191 * error is GL_DEPTH_COMPONENT32F. */ 192 gl.texBuffer(m_glExtTokens.TEXTURE_BUFFER, GL_DEPTH_COMPONENT32F, m_bo_id); 193 test_passed = verifyError(GL_INVALID_ENUM, "Expected GL_INVALID_ENUM was not returned " 194 "when wrong sized internal format was used " 195 "in glTexBufferEXT.") && 196 test_passed; 197 198 gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_DEPTH_COMPONENT32F, m_bo_id, 0, m_bo_size); 199 test_passed = verifyError(GL_INVALID_ENUM, "Expected GL_INVALID_ENUM was not returned " 200 "when wrong sized internal format was used " 201 "in glTexBufferRangeEXT.") && 202 test_passed; 203 204 /* An INVALID_OPERATION error should be generated if buffer parameter 205 * is non-zero, but is not the name of an existing buffer object. */ 206 gl.texBuffer(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id + 1); 207 test_passed = verifyError(GL_INVALID_OPERATION, "Expected GL_INVALID_OPERATION was not returned " 208 "when non-existing buffer object was used in glTexBufferEXT.") && 209 test_passed; 210 211 gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id + 1, 0, m_bo_size); 212 test_passed = 213 verifyError(GL_INVALID_OPERATION, "Expected GL_INVALID_OPERATION was not returned " 214 "when non-existing buffer object was used in glTexBufferRangeEXT.") && 215 test_passed; 216 217 /* INVALID_VALUE error should be generated if offset parameter is negative */ 218 gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, -16, m_bo_size); 219 test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned " 220 "when negative offset was used in glTexBufferRangeEXT.") && 221 test_passed; 222 223 /* INVALID_VALUE error should be generated if size parameter is less than or equal to zero */ 224 gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, 0, 0); 225 test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned " 226 "when 0 size was used in glTexBufferRangeEXT.") && 227 test_passed; 228 229 gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, 0, -1); 230 test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned " 231 "when negative size was used in glTexBufferRangeEXT.") && 232 test_passed; 233 234 /* INVALID_VALUE error should be generated if offset + size is greater than the value of BUFFER_SIZE */ 235 gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, m_bo_size / 2, m_bo_size); 236 test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned " 237 "when offset + size is greater than BUFFER_SIZE") && 238 test_passed; 239 240 /* INVALID_VALUE error should be generated if offset parameter is not an integer multiple of 241 * value(TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT). */ 242 glw::GLint texture_buffer_offset_alignment = 0; 243 gl.getIntegerv(m_glExtTokens.TEXTURE_BUFFER_OFFSET_ALIGNMENT, &texture_buffer_offset_alignment); 244 245 if (texture_buffer_offset_alignment > 1) 246 { 247 gl.texBufferRange(m_glExtTokens.TEXTURE_BUFFER, GL_RGBA32I, m_bo_id, texture_buffer_offset_alignment / 2, 248 m_bo_size - texture_buffer_offset_alignment / 2); 249 test_passed = verifyError(GL_INVALID_VALUE, "Expected INVALID_VALUE was not returned " 250 "when improperly aligned offset was used " 251 "in glTexBufferRangeEXT.") && 252 test_passed; 253 } 254 255 /* All done */ 256 if (test_passed) 257 { 258 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 259 } 260 else 261 { 262 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 263 } 264 265 return STOP; 266 } 267 268 } /* namespace glcts */ 269