1 #ifndef _ES2FBUFFERTESTUTIL_HPP 2 #define _ES2FBUFFERTESTUTIL_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program OpenGL ES 2.0 Module 5 * ------------------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Buffer test utilities. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "tcuTestLog.hpp" 28 #include "gluCallLogWrapper.hpp" 29 #include "tes2TestCase.hpp" 30 31 #include <vector> 32 #include <set> 33 34 namespace glu 35 { 36 class ShaderProgram; 37 } 38 39 namespace deqp 40 { 41 namespace gles2 42 { 43 namespace Functional 44 { 45 namespace BufferTestUtil 46 { 47 48 // Helper functions. 49 50 void fillWithRandomBytes (deUint8* ptr, int numBytes, deUint32 seed); 51 bool compareByteArrays (tcu::TestLog& log, const deUint8* resPtr, const deUint8* refPtr, int numBytes); 52 const char* getBufferTargetName (deUint32 target); 53 const char* getUsageHintName (deUint32 hint); 54 55 // Base class for buffer cases. 56 57 class BufferCase : public TestCase, public glu::CallLogWrapper 58 { 59 public: 60 BufferCase (Context& context, const char* name, const char* description); 61 virtual ~BufferCase (void); 62 63 void init (void); 64 void deinit (void); 65 66 deUint32 genBuffer (void); 67 void deleteBuffer (deUint32 buffer); 68 void checkError (void); 69 70 private: 71 // Resource handles for cleanup in case of unexpected iterate() termination. 72 std::set<deUint32> m_allocatedBuffers; 73 }; 74 75 // Reference buffer. 76 77 class ReferenceBuffer 78 { 79 public: ReferenceBuffer(void)80 ReferenceBuffer (void) {} ~ReferenceBuffer(void)81 ~ReferenceBuffer (void) {} 82 83 void setSize (int numBytes); 84 void setData (int numBytes, const deUint8* bytes); 85 void setSubData (int offset, int numBytes, const deUint8* bytes); 86 getPtr(int offset=0)87 deUint8* getPtr (int offset = 0) { return &m_data[offset]; } getPtr(int offset=0) const88 const deUint8* getPtr (int offset = 0) const { return &m_data[offset]; } 89 90 private: 91 std::vector<deUint8> m_data; 92 }; 93 94 // Buffer verifier system. 95 96 enum VerifyType 97 { 98 VERIFY_AS_VERTEX_ARRAY = 0, 99 VERIFY_AS_INDEX_ARRAY, 100 101 VERIFY_LAST 102 }; 103 104 class BufferVerifierBase : public glu::CallLogWrapper 105 { 106 public: 107 BufferVerifierBase (Context& context); ~BufferVerifierBase(void)108 virtual ~BufferVerifierBase (void) {} 109 110 virtual int getMinSize (void) const = DE_NULL; 111 virtual int getAlignment (void) const = DE_NULL; 112 virtual bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes) = DE_NULL; 113 114 protected: 115 Context& m_context; 116 117 private: 118 BufferVerifierBase (const BufferVerifierBase& other); 119 BufferVerifierBase& operator= (const BufferVerifierBase& other); 120 }; 121 122 class BufferVerifier 123 { 124 public: 125 BufferVerifier (Context& context, VerifyType verifyType); 126 ~BufferVerifier (void); 127 getMinSize(void) const128 int getMinSize (void) const { return m_verifier->getMinSize(); } getAlignment(void) const129 int getAlignment (void) const { return m_verifier->getAlignment(); } 130 131 // \note Offset is applied to reference pointer as well. 132 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes); 133 134 private: 135 BufferVerifier (const BufferVerifier& other); 136 BufferVerifier& operator= (const BufferVerifier& other); 137 138 BufferVerifierBase* m_verifier; 139 }; 140 141 class VertexArrayVerifier : public BufferVerifierBase 142 { 143 public: 144 VertexArrayVerifier (Context& context); 145 ~VertexArrayVerifier (void); 146 getMinSize(void) const147 int getMinSize (void) const { return 3*4; } getAlignment(void) const148 int getAlignment (void) const { return 1; } 149 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes); 150 151 private: 152 glu::ShaderProgram* m_program; 153 deUint32 m_posLoc; 154 deUint32 m_byteVecLoc; 155 }; 156 157 class IndexArrayVerifier : public BufferVerifierBase 158 { 159 public: 160 IndexArrayVerifier (Context& context); 161 ~IndexArrayVerifier (void); 162 getMinSize(void) const163 int getMinSize (void) const { return 2; } getAlignment(void) const164 int getAlignment (void) const { return 1; } 165 bool verify (deUint32 buffer, const deUint8* reference, int offset, int numBytes); 166 167 private: 168 glu::ShaderProgram* m_program; 169 deUint32 m_posLoc; 170 deUint32 m_colorLoc; 171 }; 172 173 } // BufferTestUtil 174 } // Functional 175 } // gles2 176 } // deqp 177 178 #endif // _ES2FBUFFERTESTUTIL_HPP 179