1 #ifndef _GLSVERTEXARRAYTESTS_HPP
2 #define _GLSVERTEXARRAYTESTS_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL (ES) Module
5 * -----------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Vertex array and buffer tests
24 *//*--------------------------------------------------------------------*/
26 #include "tcuTestCase.hpp"
27 #include "tcuVector.hpp"
28 #include "tcuSurface.hpp"
29 #include "gluRenderContext.hpp"
30 #include "gluCallLogWrapper.hpp"
31 #include "tcuTestLog.hpp"
32 #include "gluShaderProgram.hpp"
33 #include "deFloat16.h"
35 #include "tcuFloat.hpp"
36 #include "tcuPixelFormat.hpp"
37 #include "sglrContext.hpp"
42 class ReferenceContextBuffers;
43 class ReferenceContext;
58 // \note [mika] Are these actualy used somewhere?
59 TARGET_ELEMENT_ARRAY = 0,
74 INPUTTYPE_UNSIGNED_BYTE,
75 INPUTTYPE_UNSIGNED_SHORT,
78 INPUTTYPE_UNSIGNED_INT,
80 INPUTTYPE_UNSIGNED_INT_2_10_10_10,
81 INPUTTYPE_INT_2_10_10_10,
109 USAGE_DYNAMIC_DRAW = 0,
135 PRIMITIVE_POINTS = 0,
137 PRIMITIVE_TRIANGLE_FAN,
138 PRIMITIVE_TRIANGLE_STRIP,
143 static std::string targetToString (Target target);
144 static std::string inputTypeToString (InputType type);
145 static std::string outputTypeToString (OutputType type);
146 static std::string usageTypeToString (Usage usage);
147 static std::string storageToString (Storage storage);
148 static std::string primitiveToString (Primitive primitive);
149 static int inputTypeSize (InputType type);
151 virtual ~Array (void) {}
152 virtual void data (Target target, int size, const char* data, Usage usage) = 0;
153 virtual void subdata (Target target, int offset, int size, const char* data) = 0;
154 virtual void bind (int attribNdx, int offset, int size, InputType inType, OutputType outType, bool normalized, int stride) = 0;
155 virtual void unBind (void) = 0;
157 virtual bool isBound (void) const = 0;
158 virtual int getComponentCount (void) const = 0;
159 virtual Target getTarget (void) const = 0;
160 virtual InputType getInputType (void) const = 0;
161 virtual OutputType getOutputType (void) const = 0;
162 virtual Storage getStorageType (void) const = 0;
163 virtual bool getNormalized (void) const = 0;
164 virtual int getStride (void) const = 0;
165 virtual int getAttribNdx (void) const = 0;
166 virtual void setAttribNdx (int attribNdx) = 0;
169 class ContextArray : public Array
172 ContextArray (Storage storage, sglr::Context& context);
173 virtual ~ContextArray (void);
174 virtual void data (Target target, int size, const char* data, Usage usage);
175 virtual void subdata (Target target, int offset, int size, const char* data);
176 virtual void bind (int attribNdx, int offset, int size, InputType inType, OutputType outType, bool normalized, int stride);
177 virtual void bindIndexArray (Array::Target storage);
178 virtual void unBind (void) { m_bound = false; }
179 virtual bool isBound (void) const { return m_bound; }
181 virtual int getComponentCount (void) const { return m_componentCount; }
182 virtual Array::Target getTarget (void) const { return m_target; }
183 virtual Array::InputType getInputType (void) const { return m_inputType; }
184 virtual Array::OutputType getOutputType (void) const { return m_outputType; }
185 virtual Array::Storage getStorageType (void) const { return m_storage; }
186 virtual bool getNormalized (void) const { return m_normalize; }
187 virtual int getStride (void) const { return m_stride; }
188 virtual int getAttribNdx (void) const { return m_attribNdx; }
189 virtual void setAttribNdx (int attribNdx) { m_attribNdx = attribNdx; }
191 void glBind (deUint32 loc);
192 static deUint32 targetToGL (Array::Target target);
193 static deUint32 usageToGL (Array::Usage usage);
194 static deUint32 inputTypeToGL (Array::InputType type);
195 static std::string outputTypeToGLType (Array::OutputType type);
196 static deUint32 primitiveToGL (Array::Primitive primitive);
200 sglr::Context& m_ctx;
207 int m_componentCount;
208 Array::Target m_target;
209 Array::InputType m_inputType;
210 Array::OutputType m_outputType;
216 class ContextArrayPack
219 ContextArrayPack (glu::RenderContext& renderCtx, sglr::Context& drawContext);
220 virtual ~ContextArrayPack (void);
221 virtual Array* getArray (int i);
222 virtual int getArrayCount (void);
223 virtual void newArray (Array::Storage storage);
224 virtual void render (Array::Primitive primitive, int firstVertex, int vertexCount, bool useVao, float coordScale, float colorScale);
226 const tcu::Surface& getSurface (void) const { return m_screen; }
228 void updateProgram (void);
229 glu::RenderContext& m_renderCtx;
230 sglr::Context& m_ctx;
232 std::vector<ContextArray*> m_arrays;
233 sglr::ShaderProgram* m_program;
234 tcu::Surface m_screen;
244 static WrappedType<Type> create (Type value) { WrappedType<Type> v; v.m_value = value; return v; }
245 static WrappedType<Type> fromFloat (float value) { WrappedType<Type> v; v.m_value = (Type)value; return v; }
246 inline Type getValue (void) const { return m_value; }
248 inline WrappedType<Type> operator+ (const WrappedType<Type>& other) const { return WrappedType<Type>::create((Type)(m_value + other.getValue())); }
249 inline WrappedType<Type> operator* (const WrappedType<Type>& other) const { return WrappedType<Type>::create((Type)(m_value * other.getValue())); }
250 inline WrappedType<Type> operator/ (const WrappedType<Type>& other) const { return WrappedType<Type>::create((Type)(m_value / other.getValue())); }
251 inline WrappedType<Type> operator% (const WrappedType<Type>& other) const { return WrappedType<Type>::create((Type)(m_value % other.getValue())); }
252 inline WrappedType<Type> operator- (const WrappedType<Type>& other) const { return WrappedType<Type>::create((Type)(m_value - other.getValue())); }
254 inline WrappedType<Type>& operator+= (const WrappedType<Type>& other) { m_value += other.getValue(); return *this; }
255 inline WrappedType<Type>& operator*= (const WrappedType<Type>& other) { m_value *= other.getValue(); return *this; }
256 inline WrappedType<Type>& operator/= (const WrappedType<Type>& other) { m_value /= other.getValue(); return *this; }
257 inline WrappedType<Type>& operator-= (const WrappedType<Type>& other) { m_value -= other.getValue(); return *this; }
259 inline bool operator== (const WrappedType<Type>& other) const { return m_value == other.m_value; }
260 inline bool operator!= (const WrappedType<Type>& other) const { return m_value != other.m_value; }
261 inline bool operator< (const WrappedType<Type>& other) const { return m_value < other.m_value; }
262 inline bool operator> (const WrappedType<Type>& other) const { return m_value > other.m_value; }
263 inline bool operator<= (const WrappedType<Type>& other) const { return m_value <= other.m_value; }
264 inline bool operator>= (const WrappedType<Type>& other) const { return m_value >= other.m_value; }
266 inline operator Type (void) const { return m_value; }
268 inline T to (void) const { return (T)m_value; }
274 class WrappedFloatType
277 static WrappedFloatType<Type> create (Type value) { WrappedFloatType<Type> v; v.m_value = value; return v; }
278 static WrappedFloatType<Type> fromFloat (float value) { WrappedFloatType<Type> v; v.m_value = (Type)value; return v; }
279 inline Type getValue (void) const { return m_value; }
281 inline WrappedFloatType<Type> operator+ (const WrappedFloatType<Type>& other) const { return WrappedFloatType<Type>::create((Type)(m_value + other.getValue())); }
282 inline WrappedFloatType<Type> operator* (const WrappedFloatType<Type>& other) const { return WrappedFloatType<Type>::create((Type)(m_value * other.getValue())); }
283 inline WrappedFloatType<Type> operator/ (const WrappedFloatType<Type>& other) const { return WrappedFloatType<Type>::create((Type)(m_value / other.getValue())); }
284 inline WrappedFloatType<Type> operator% (const WrappedFloatType<Type>& other) const { return WrappedFloatType<Type>::create((Type)(deMod(m_value, other.getValue()))); }
285 inline WrappedFloatType<Type> operator- (const WrappedFloatType<Type>& other) const { return WrappedFloatType<Type>::create((Type)(m_value - other.getValue())); }
287 inline WrappedFloatType<Type>& operator+= (const WrappedFloatType<Type>& other) { m_value += other.getValue(); return *this; }
288 inline WrappedFloatType<Type>& operator*= (const WrappedFloatType<Type>& other) { m_value *= other.getValue(); return *this; }
289 inline WrappedFloatType<Type>& operator/= (const WrappedFloatType<Type>& other) { m_value /= other.getValue(); return *this; }
290 inline WrappedFloatType<Type>& operator-= (const WrappedFloatType<Type>& other) { m_value -= other.getValue(); return *this; }
292 inline bool operator== (const WrappedFloatType<Type>& other) const { return m_value == other.m_value; }
293 inline bool operator!= (const WrappedFloatType<Type>& other) const { return m_value != other.m_value; }
294 inline bool operator< (const WrappedFloatType<Type>& other) const { return m_value < other.m_value; }
295 inline bool operator> (const WrappedFloatType<Type>& other) const { return m_value > other.m_value; }
296 inline bool operator<= (const WrappedFloatType<Type>& other) const { return m_value <= other.m_value; }
297 inline bool operator>= (const WrappedFloatType<Type>& other) const { return m_value >= other.m_value; }
299 inline operator Type (void) const { return m_value; }
301 inline T to (void) const { return (T)m_value; }
306 typedef WrappedType<deInt16> Short;
307 typedef WrappedType<deUint16> Ushort;
309 typedef WrappedType<deInt8> Byte;
310 typedef WrappedType<deUint8> Ubyte;
312 typedef WrappedFloatType<float> Float;
313 typedef WrappedFloatType<double> Double;
315 typedef WrappedType<deInt32> Int;
316 typedef WrappedType<deUint32> Uint;
321 static Half create (float value) { Half h; h.m_value = floatToHalf(value); return h; }
322 static Half fromFloat (float value) { Half h; h.m_value = floatToHalf(value); return h; }
323 inline deFloat16 getValue (void) const { return m_value; }
325 inline Half operator+ (const Half& other) const { return create(halfToFloat(m_value) + halfToFloat(other.getValue())); }
326 inline Half operator* (const Half& other) const { return create(halfToFloat(m_value) * halfToFloat(other.getValue())); }
327 inline Half operator/ (const Half& other) const { return create(halfToFloat(m_value) / halfToFloat(other.getValue())); }
328 inline Half operator% (const Half& other) const { return create(deFloatMod(halfToFloat(m_value), halfToFloat(other.getValue()))); }
329 inline Half operator- (const Half& other) const { return create(halfToFloat(m_value) - halfToFloat(other.getValue())); }
331 inline Half& operator+= (const Half& other) { m_value = floatToHalf(halfToFloat(other.getValue()) + halfToFloat(m_value)); return *this; }
332 inline Half& operator*= (const Half& other) { m_value = floatToHalf(halfToFloat(other.getValue()) * halfToFloat(m_value)); return *this; }
333 inline Half& operator/= (const Half& other) { m_value = floatToHalf(halfToFloat(other.getValue()) / halfToFloat(m_value)); return *this; }
334 inline Half& operator-= (const Half& other) { m_value = floatToHalf(halfToFloat(other.getValue()) - halfToFloat(m_value)); return *this; }
336 inline bool operator== (const Half& other) const { return m_value == other.m_value; }
337 inline bool operator!= (const Half& other) const { return m_value != other.m_value; }
338 inline bool operator< (const Half& other) const { return halfToFloat(m_value) < halfToFloat(other.m_value); }
339 inline bool operator> (const Half& other) const { return halfToFloat(m_value) > halfToFloat(other.m_value); }
340 inline bool operator<= (const Half& other) const { return halfToFloat(m_value) <= halfToFloat(other.m_value); }
341 inline bool operator>= (const Half& other) const { return halfToFloat(m_value) >= halfToFloat(other.m_value); }
344 inline T to (void) const { return (T)halfToFloat(m_value); }
346 inline static deFloat16 floatToHalf (float f);
347 inline static float halfToFloat (deFloat16 h);
355 static Fixed create (deInt32 value) { Fixed v; v.m_value = value; return v; }
356 static Fixed fromFloat (float value) { Fixed v; v.m_value = (deInt32)(value * 32768.0f); return v; }
357 inline deInt32 getValue (void) const { return m_value; }
359 inline Fixed operator+ (const Fixed& other) const { return create(m_value + other.getValue()); }
360 inline Fixed operator* (const Fixed& other) const { return create(m_value * other.getValue()); }
361 inline Fixed operator/ (const Fixed& other) const { return create(m_value / other.getValue()); }
362 inline Fixed operator% (const Fixed& other) const { return create(m_value % other.getValue()); }
363 inline Fixed operator- (const Fixed& other) const { return create(m_value - other.getValue()); }
365 inline Fixed& operator+= (const Fixed& other) { m_value += other.getValue(); return *this; }
366 inline Fixed& operator*= (const Fixed& other) { m_value *= other.getValue(); return *this; }
367 inline Fixed& operator/= (const Fixed& other) { m_value /= other.getValue(); return *this; }
368 inline Fixed& operator-= (const Fixed& other) { m_value -= other.getValue(); return *this; }
370 inline bool operator== (const Fixed& other) const { return m_value == other.m_value; }
371 inline bool operator!= (const Fixed& other) const { return m_value != other.m_value; }
372 inline bool operator< (const Fixed& other) const { return m_value < other.m_value; }
373 inline bool operator> (const Fixed& other) const { return m_value > other.m_value; }
374 inline bool operator<= (const Fixed& other) const { return m_value <= other.m_value; }
375 inline bool operator>= (const Fixed& other) const { return m_value >= other.m_value; }
377 inline operator deInt32 (void) const { return m_value; }
379 inline T to (void) const { return (T)m_value; }
384 // \todo [mika] This is pretty messy
385 GLValue (void) : type(Array::INPUTTYPE_LAST) {}
386 explicit GLValue (Float value) : type(Array::INPUTTYPE_FLOAT), fl(value) {}
387 explicit GLValue (Fixed value) : type(Array::INPUTTYPE_FIXED), fi(value) {}
388 explicit GLValue (Byte value) : type(Array::INPUTTYPE_BYTE), b(value) {}
389 explicit GLValue (Ubyte value) : type(Array::INPUTTYPE_UNSIGNED_BYTE), ub(value) {}
390 explicit GLValue (Short value) : type(Array::INPUTTYPE_SHORT), s(value) {}
391 explicit GLValue (Ushort value) : type(Array::INPUTTYPE_UNSIGNED_SHORT), us(value) {}
392 explicit GLValue (Int value) : type(Array::INPUTTYPE_INT), i(value) {}
393 explicit GLValue (Uint value) : type(Array::INPUTTYPE_UNSIGNED_INT), ui(value) {}
394 explicit GLValue (Half value) : type(Array::INPUTTYPE_HALF), h(value) {}
395 explicit GLValue (Double value) : type(Array::INPUTTYPE_DOUBLE), d(value) {}
397 float toFloat (void) const;
399 static GLValue getMaxValue (Array::InputType type);
400 static GLValue getMinValue (Array::InputType type);
402 Array::InputType type;
419 class VertexArrayTest : public tcu::TestCase
422 VertexArrayTest (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name ,const char* desc);
423 virtual ~VertexArrayTest (void);
424 virtual void init (void);
425 virtual void deinit (void);
428 VertexArrayTest (const VertexArrayTest& other);
429 VertexArrayTest& operator= (const VertexArrayTest& other);
433 glu::RenderContext& m_renderCtx;
435 sglr::ReferenceContextBuffers* m_refBuffers;
436 sglr::ReferenceContext* m_refContext;
437 sglr::Context* m_glesContext;
439 ContextArrayPack* m_glArrayPack;
440 ContextArrayPack* m_rrArrayPack;
448 class MultiVertexArrayTest : public VertexArrayTest
457 ArraySpec (Array::InputType inputType, Array::OutputType outputType, Array::Storage storage, Array::Usage usage, int componetCount, int offset, int stride, bool normalize, GLValue min, GLValue max);
459 Array::InputType inputType;
460 Array::OutputType outputType;
461 Array::Storage storage;
471 std::string getName (void) const;
472 std::string getDesc (void) const;
474 Array::Primitive primitive;
475 int drawCount; //!<Number of primitives to draw
478 std::vector<ArraySpec> arrays;
481 MultiVertexArrayTest (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const Spec& spec, const char* name, const char* desc);
482 virtual ~MultiVertexArrayTest (void);
483 virtual IterateResult iterate (void);
486 bool isUnalignedBufferOffsetTest (void) const;
487 bool isUnalignedBufferStrideTest (void) const;
493 inline deFloat16 GLValue::Half::floatToHalf (float f)
495 // No denorm support.
496 tcu::Float<deUint16, 5, 10, 15, tcu::FLOAT_HAS_SIGN> v(f);
497 DE_ASSERT(!v.isNaN() && !v.isInf());
501 inline float GLValue::Half::halfToFloat (deFloat16 h)
503 return tcu::Float16((deUint16)h).asFloat();
509 #endif // _GLSVERTEXARRAYTESTS_HPP