1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL (ES) 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 Vertex array and buffer tests
22 *//*--------------------------------------------------------------------*/
24 #include "glsVertexArrayTests.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuPixelFormat.hpp"
30 #include "tcuRGBA.hpp"
31 #include "tcuSurface.hpp"
32 #include "tcuVector.hpp"
33 #include "tcuTestLog.hpp"
34 #include "tcuRenderTarget.hpp"
35 #include "tcuStringTemplate.hpp"
36 #include "tcuImageCompare.hpp"
38 #include "gluPixelTransfer.hpp"
39 #include "gluCallLogWrapper.hpp"
41 #include "sglrContext.hpp"
42 #include "sglrReferenceContext.hpp"
43 #include "sglrGLContext.hpp"
46 #include "deStringUtil.hpp"
47 #include "deArrayUtil.hpp"
56 #include "glwDefs.hpp"
57 #include "glwEnums.hpp"
65 using namespace glw; // GL types
67 std::string Array::targetToString(Target target)
69 static const char* targets[] =
71 "element_array", // TARGET_ELEMENT_ARRAY = 0,
72 "array" // TARGET_ARRAY,
75 return de::getSizedArrayElement<Array::TARGET_LAST>(targets, (int)target);
78 std::string Array::inputTypeToString(InputType type)
80 static const char* types[] =
82 "float", // INPUTTYPE_FLOAT = 0,
83 "fixed", // INPUTTYPE_FIXED,
84 "double", // INPUTTYPE_DOUBLE
86 "byte", // INPUTTYPE_BYTE,
87 "short", // INPUTTYPE_SHORT,
89 "unsigned_byte", // INPUTTYPE_UNSIGNED_BYTE,
90 "unsigned_short", // INPUTTYPE_UNSIGNED_SHORT,
92 "int", // INPUTTYPE_INT,
93 "unsigned_int", // INPUTTYPE_UNSIGNED_INT,
94 "half", // INPUTTYPE_HALF,
95 "usigned_int2_10_10_10", // INPUTTYPE_UNSIGNED_INT_2_10_10_10,
96 "int2_10_10_10" // INPUTTYPE_INT_2_10_10_10,
99 return de::getSizedArrayElement<Array::INPUTTYPE_LAST>(types, (int)type);
102 std::string Array::outputTypeToString(OutputType type)
104 static const char* types[] =
106 "float", // OUTPUTTYPE_FLOAT = 0,
107 "vec2", // OUTPUTTYPE_VEC2,
108 "vec3", // OUTPUTTYPE_VEC3,
109 "vec4", // OUTPUTTYPE_VEC4,
111 "int", // OUTPUTTYPE_INT,
112 "uint", // OUTPUTTYPE_UINT,
114 "ivec2", // OUTPUTTYPE_IVEC2,
115 "ivec3", // OUTPUTTYPE_IVEC3,
116 "ivec4", // OUTPUTTYPE_IVEC4,
118 "uvec2", // OUTPUTTYPE_UVEC2,
119 "uvec3", // OUTPUTTYPE_UVEC3,
120 "uvec4", // OUTPUTTYPE_UVEC4,
123 return de::getSizedArrayElement<Array::OUTPUTTYPE_LAST>(types, (int)type);
126 std::string Array::usageTypeToString(Usage usage)
128 static const char* usages[] =
130 "dynamic_draw", // USAGE_DYNAMIC_DRAW = 0,
131 "static_draw", // USAGE_STATIC_DRAW,
132 "stream_draw", // USAGE_STREAM_DRAW,
134 "stream_read", // USAGE_STREAM_READ,
135 "stream_copy", // USAGE_STREAM_COPY,
137 "static_read", // USAGE_STATIC_READ,
138 "static_copy", // USAGE_STATIC_COPY,
140 "dynamic_read", // USAGE_DYNAMIC_READ,
141 "dynamic_copy", // USAGE_DYNAMIC_COPY,
144 return de::getSizedArrayElement<Array::USAGE_LAST>(usages, (int)usage);
147 std::string Array::storageToString (Storage storage)
149 static const char* storages[] =
151 "user_ptr", // STORAGE_USER = 0,
152 "buffer" // STORAGE_BUFFER,
155 return de::getSizedArrayElement<Array::STORAGE_LAST>(storages, (int)storage);
158 std::string Array::primitiveToString (Primitive primitive)
160 static const char* primitives[] =
162 "points", // PRIMITIVE_POINTS ,
163 "triangles", // PRIMITIVE_TRIANGLES,
164 "triangle_fan", // PRIMITIVE_TRIANGLE_FAN,
165 "triangle_strip" // PRIMITIVE_TRIANGLE_STRIP,
168 return de::getSizedArrayElement<Array::PRIMITIVE_LAST>(primitives, (int)primitive);
171 int Array::inputTypeSize (InputType type)
173 static const int size[] =
175 (int)sizeof(float), // INPUTTYPE_FLOAT = 0,
176 (int)sizeof(deInt32), // INPUTTYPE_FIXED,
177 (int)sizeof(double), // INPUTTYPE_DOUBLE
179 (int)sizeof(deInt8), // INPUTTYPE_BYTE,
180 (int)sizeof(deInt16), // INPUTTYPE_SHORT,
182 (int)sizeof(deUint8), // INPUTTYPE_UNSIGNED_BYTE,
183 (int)sizeof(deUint16), // INPUTTYPE_UNSIGNED_SHORT,
185 (int)sizeof(deInt32), // INPUTTYPE_INT,
186 (int)sizeof(deUint32), // INPUTTYPE_UNSIGNED_INT,
187 (int)sizeof(deFloat16), // INPUTTYPE_HALF,
188 (int)sizeof(deUint32) / 4, // INPUTTYPE_UNSIGNED_INT_2_10_10_10,
189 (int)sizeof(deUint32) / 4 // INPUTTYPE_INT_2_10_10_10,
192 return de::getSizedArrayElement<Array::INPUTTYPE_LAST>(size, (int)type);
195 static bool inputTypeIsFloatType (Array::InputType type)
197 if (type == Array::INPUTTYPE_FLOAT)
199 if (type == Array::INPUTTYPE_FIXED)
201 if (type == Array::INPUTTYPE_DOUBLE)
203 if (type == Array::INPUTTYPE_HALF)
208 static bool outputTypeIsFloatType (Array::OutputType type)
210 if (type == Array::OUTPUTTYPE_FLOAT
211 || type == Array::OUTPUTTYPE_VEC2
212 || type == Array::OUTPUTTYPE_VEC3
213 || type == Array::OUTPUTTYPE_VEC4)
220 inline T getRandom (deRandom& rnd, T min, T max);
223 inline GLValue::Float getRandom (deRandom& rnd, GLValue::Float min, GLValue::Float max)
228 return GLValue::Float::create(min + deRandom_getFloat(&rnd) * (max.to<float>() - min.to<float>()));
232 inline GLValue::Short getRandom (deRandom& rnd, GLValue::Short min, GLValue::Short max)
237 return GLValue::Short::create((min == max ? min : (deInt16)(min + (deRandom_getUint32(&rnd) % (max.to<int>() - min.to<int>())))));
241 inline GLValue::Ushort getRandom (deRandom& rnd, GLValue::Ushort min, GLValue::Ushort max)
246 return GLValue::Ushort::create((min == max ? min : (deUint16)(min + (deRandom_getUint32(&rnd) % (max.to<int>() - min.to<int>())))));
250 inline GLValue::Byte getRandom (deRandom& rnd, GLValue::Byte min, GLValue::Byte max)
255 return GLValue::Byte::create((min == max ? min : (deInt8)(min + (deRandom_getUint32(&rnd) % (max.to<int>() - min.to<int>())))));
259 inline GLValue::Ubyte getRandom (deRandom& rnd, GLValue::Ubyte min, GLValue::Ubyte max)
264 return GLValue::Ubyte::create((min == max ? min : (deUint8)(min + (deRandom_getUint32(&rnd) % (max.to<int>() - min.to<int>())))));
268 inline GLValue::Fixed getRandom (deRandom& rnd, GLValue::Fixed min, GLValue::Fixed max)
273 return GLValue::Fixed::create((min == max ? min : min + (deRandom_getUint32(&rnd) % (max.to<deUint32>() - min.to<deUint32>()))));
277 inline GLValue::Half getRandom (deRandom& rnd, GLValue::Half min, GLValue::Half max)
282 float fMax = max.to<float>();
283 float fMin = min.to<float>();
284 GLValue::Half h = GLValue::Half::create(fMin + deRandom_getFloat(&rnd) * (fMax - fMin));
289 inline GLValue::Int getRandom (deRandom& rnd, GLValue::Int min, GLValue::Int max)
294 return GLValue::Int::create((min == max ? min : min + (deRandom_getUint32(&rnd) % (max.to<deUint32>() - min.to<deUint32>()))));
298 inline GLValue::Uint getRandom (deRandom& rnd, GLValue::Uint min, GLValue::Uint max)
303 return GLValue::Uint::create((min == max ? min : min + (deRandom_getUint32(&rnd) % (max.to<deUint32>() - min.to<deUint32>()))));
307 inline GLValue::Double getRandom (deRandom& rnd, GLValue::Double min, GLValue::Double max)
312 return GLValue::Double::create(min + deRandom_getFloat(&rnd) * (max.to<float>() - min.to<float>()));
315 // Minimum difference required between coordinates
317 inline T minValue (void);
320 inline GLValue::Float minValue (void)
322 return GLValue::Float::create(4 * 1.0f);
326 inline GLValue::Short minValue (void)
328 return GLValue::Short::create(4 * 256);
332 inline GLValue::Ushort minValue (void)
334 return GLValue::Ushort::create(4 * 256);
338 inline GLValue::Byte minValue (void)
340 return GLValue::Byte::create(4 * 1);
344 inline GLValue::Ubyte minValue (void)
346 return GLValue::Ubyte::create(4 * 2);
350 inline GLValue::Fixed minValue (void)
352 return GLValue::Fixed::create(4 * 512);
356 inline GLValue::Int minValue (void)
358 return GLValue::Int::create(4 * 16777216);
362 inline GLValue::Uint minValue (void)
364 return GLValue::Uint::create(4 * 16777216);
368 inline GLValue::Half minValue (void)
370 return GLValue::Half::create(4 * 1.0f);
374 inline GLValue::Double minValue (void)
376 return GLValue::Double::create(4 * 1.0f);
380 inline T abs (T val);
383 inline GLValue::Fixed abs (GLValue::Fixed val)
385 return GLValue::Fixed::create(0x7FFFu & val.getValue());
389 inline GLValue::Ubyte abs (GLValue::Ubyte val)
395 inline GLValue::Byte abs (GLValue::Byte val)
397 return GLValue::Byte::create(0x7Fu & val.getValue());
401 inline GLValue::Ushort abs (GLValue::Ushort val)
407 inline GLValue::Short abs (GLValue::Short val)
409 return GLValue::Short::create(0x7FFFu & val.getValue());
413 inline GLValue::Float abs (GLValue::Float val)
415 return GLValue::Float::create(std::fabs(val.to<float>()));
419 inline GLValue::Uint abs (GLValue::Uint val)
425 inline GLValue::Int abs (GLValue::Int val)
427 return GLValue::Int::create(0x7FFFFFFFu & val.getValue());
431 inline GLValue::Half abs (GLValue::Half val)
433 return GLValue::Half::create(std::fabs(val.to<float>()));
437 inline GLValue::Double abs (GLValue::Double val)
439 return GLValue::Double::create(std::fabs(val.to<float>()));
443 static inline void alignmentSafeAssignment (char* dst, T val)
445 std::memcpy(dst, &val, sizeof(T));
448 ContextArray::ContextArray (Storage storage, sglr::Context& context)
449 : m_storage (storage)
456 , m_componentCount (1)
457 , m_target (Array::TARGET_ARRAY)
458 , m_inputType (Array::INPUTTYPE_FLOAT)
459 , m_outputType (Array::OUTPUTTYPE_VEC4)
460 , m_normalize (false)
464 if (m_storage == STORAGE_BUFFER)
466 m_ctx.genBuffers(1, &m_glBuffer);
467 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glGenBuffers()");
471 ContextArray::~ContextArray (void)
473 if (m_storage == STORAGE_BUFFER)
475 m_ctx.deleteBuffers(1, &m_glBuffer);
476 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glDeleteBuffers()");
478 else if (m_storage == STORAGE_USER)
484 Array* ContextArrayPack::getArray (int i)
486 return m_arrays.at(i);
489 void ContextArray::data (Target target, int size, const char* ptr, Usage usage)
494 if (m_storage == STORAGE_BUFFER)
496 m_ctx.bindBuffer(targetToGL(target), m_glBuffer);
497 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBindBuffer()");
499 m_ctx.bufferData(targetToGL(target), size, ptr, usageToGL(usage));
500 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBufferData()");
502 else if (m_storage == STORAGE_USER)
507 m_data = new char[size];
508 std::memcpy(m_data, ptr, size);
514 void ContextArray::subdata (Target target, int offset, int size, const char* ptr)
518 if (m_storage == STORAGE_BUFFER)
520 m_ctx.bindBuffer(targetToGL(target), m_glBuffer);
521 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBindBuffer()");
523 m_ctx.bufferSubData(targetToGL(target), offset, size, ptr);
524 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBufferSubData()");
526 else if (m_storage == STORAGE_USER)
527 std::memcpy(m_data + offset, ptr, size);
532 void ContextArray::bind (int attribNdx, int offset, int size, InputType inputType, OutputType outType, bool normalized, int stride)
534 m_attribNdx = attribNdx;
536 m_componentCount = size;
537 m_inputType = inputType;
538 m_outputType = outType;
539 m_normalize = normalized;
544 void ContextArray::bindIndexArray (Array::Target target)
546 if (m_storage == STORAGE_USER)
549 else if (m_storage == STORAGE_BUFFER)
551 m_ctx.bindBuffer(targetToGL(target), m_glBuffer);
555 void ContextArray::glBind (deUint32 loc)
557 if (m_storage == STORAGE_BUFFER)
559 m_ctx.bindBuffer(targetToGL(m_target), m_glBuffer);
560 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBindBuffer()");
562 if (!inputTypeIsFloatType(m_inputType))
564 // Input is not float type
566 if (outputTypeIsFloatType(m_outputType))
568 // Output type is float type
569 m_ctx.vertexAttribPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_normalize, m_stride, (GLvoid*)((GLintptr)m_offset));
570 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribPointer()");
574 // Output type is int type
575 m_ctx.vertexAttribIPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_stride, (GLvoid*)((GLintptr)m_offset));
576 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribIPointer()");
581 // Input type is float type
583 // Output type must be float type
584 DE_ASSERT(m_outputType == OUTPUTTYPE_FLOAT || m_outputType == OUTPUTTYPE_VEC2 || m_outputType == OUTPUTTYPE_VEC3 || m_outputType == OUTPUTTYPE_VEC4);
586 m_ctx.vertexAttribPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_normalize, m_stride, (GLvoid*)((GLintptr)m_offset));
587 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribPointer()");
590 m_ctx.bindBuffer(targetToGL(m_target), 0);
592 else if (m_storage == STORAGE_USER)
594 m_ctx.bindBuffer(targetToGL(m_target), 0);
595 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glBindBuffer()");
597 if (!inputTypeIsFloatType(m_inputType))
599 // Input is not float type
601 if (outputTypeIsFloatType(m_outputType))
603 // Output type is float type
604 m_ctx.vertexAttribPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_normalize, m_stride, m_data + m_offset);
605 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribPointer()");
609 // Output type is int type
610 m_ctx.vertexAttribIPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_stride, m_data + m_offset);
611 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribIPointer()");
616 // Input type is float type
618 // Output type must be float type
619 DE_ASSERT(m_outputType == OUTPUTTYPE_FLOAT || m_outputType == OUTPUTTYPE_VEC2 || m_outputType == OUTPUTTYPE_VEC3 || m_outputType == OUTPUTTYPE_VEC4);
621 m_ctx.vertexAttribPointer(loc, m_componentCount, inputTypeToGL(m_inputType), m_normalize, m_stride, m_data + m_offset);
622 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glVertexAttribPointer()");
629 GLenum ContextArray::targetToGL (Array::Target target)
631 static const GLenum targets[] =
633 GL_ELEMENT_ARRAY_BUFFER, // TARGET_ELEMENT_ARRAY = 0,
634 GL_ARRAY_BUFFER // TARGET_ARRAY,
637 return de::getSizedArrayElement<Array::TARGET_LAST>(targets, (int)target);
640 GLenum ContextArray::usageToGL (Array::Usage usage)
642 static const GLenum usages[] =
644 GL_DYNAMIC_DRAW, // USAGE_DYNAMIC_DRAW = 0,
645 GL_STATIC_DRAW, // USAGE_STATIC_DRAW,
646 GL_STREAM_DRAW, // USAGE_STREAM_DRAW,
648 GL_STREAM_READ, // USAGE_STREAM_READ,
649 GL_STREAM_COPY, // USAGE_STREAM_COPY,
651 GL_STATIC_READ, // USAGE_STATIC_READ,
652 GL_STATIC_COPY, // USAGE_STATIC_COPY,
654 GL_DYNAMIC_READ, // USAGE_DYNAMIC_READ,
655 GL_DYNAMIC_COPY // USAGE_DYNAMIC_COPY,
658 return de::getSizedArrayElement<Array::USAGE_LAST>(usages, (int)usage);
661 GLenum ContextArray::inputTypeToGL (Array::InputType type)
663 static const GLenum types[] =
665 GL_FLOAT, // INPUTTYPE_FLOAT = 0,
666 GL_FIXED, // INPUTTYPE_FIXED,
667 GL_DOUBLE, // INPUTTYPE_DOUBLE
668 GL_BYTE, // INPUTTYPE_BYTE,
669 GL_SHORT, // INPUTTYPE_SHORT,
670 GL_UNSIGNED_BYTE, // INPUTTYPE_UNSIGNED_BYTE,
671 GL_UNSIGNED_SHORT, // INPUTTYPE_UNSIGNED_SHORT,
673 GL_INT, // INPUTTYPE_INT,
674 GL_UNSIGNED_INT, // INPUTTYPE_UNSIGNED_INT,
675 GL_HALF_FLOAT, // INPUTTYPE_HALF,
676 GL_UNSIGNED_INT_2_10_10_10_REV, // INPUTTYPE_UNSIGNED_INT_2_10_10_10,
677 GL_INT_2_10_10_10_REV // INPUTTYPE_INT_2_10_10_10,
680 return de::getSizedArrayElement<Array::INPUTTYPE_LAST>(types, (int)type);
683 std::string ContextArray::outputTypeToGLType (Array::OutputType type)
685 static const char* types[] =
687 "float", // OUTPUTTYPE_FLOAT = 0,
688 "vec2", // OUTPUTTYPE_VEC2,
689 "vec3", // OUTPUTTYPE_VEC3,
690 "vec4", // OUTPUTTYPE_VEC4,
692 "int", // OUTPUTTYPE_INT,
693 "uint", // OUTPUTTYPE_UINT,
695 "ivec2", // OUTPUTTYPE_IVEC2,
696 "ivec3", // OUTPUTTYPE_IVEC3,
697 "ivec4", // OUTPUTTYPE_IVEC4,
699 "uvec2", // OUTPUTTYPE_UVEC2,
700 "uvec3", // OUTPUTTYPE_UVEC3,
701 "uvec4", // OUTPUTTYPE_UVEC4,
704 return de::getSizedArrayElement<Array::OUTPUTTYPE_LAST>(types, (int)type);
707 GLenum ContextArray::primitiveToGL (Array::Primitive primitive)
709 static const GLenum primitives[] =
711 GL_POINTS, // PRIMITIVE_POINTS = 0,
712 GL_TRIANGLES, // PRIMITIVE_TRIANGLES,
713 GL_TRIANGLE_FAN, // PRIMITIVE_TRIANGLE_FAN,
714 GL_TRIANGLE_STRIP // PRIMITIVE_TRIANGLE_STRIP,
717 return de::getSizedArrayElement<Array::PRIMITIVE_LAST>(primitives, (int)primitive);
720 ContextArrayPack::ContextArrayPack (glu::RenderContext& renderCtx, sglr::Context& drawContext)
721 : m_renderCtx (renderCtx)
722 , m_ctx (drawContext)
723 , m_program (DE_NULL)
724 , m_screen (std::min(512, renderCtx.getRenderTarget().getWidth()), std::min(512, renderCtx.getRenderTarget().getHeight()))
728 ContextArrayPack::~ContextArrayPack (void)
730 for (std::vector<ContextArray*>::iterator itr = m_arrays.begin(); itr != m_arrays.end(); itr++)
736 int ContextArrayPack::getArrayCount (void)
738 return (int)m_arrays.size();
741 void ContextArrayPack::newArray (Array::Storage storage)
743 m_arrays.push_back(new ContextArray(storage, m_ctx));
746 class ContextShaderProgram : public sglr::ShaderProgram
749 ContextShaderProgram (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays);
751 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
752 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
755 static std::string genVertexSource (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays);
756 static std::string genFragmentSource (const glu::RenderContext& ctx);
757 static rr::GenericVecType mapOutputType (const Array::OutputType& type);
758 static int getComponentCount (const Array::OutputType& type);
760 static sglr::pdec::ShaderProgramDeclaration createProgramDeclaration (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays);
762 std::vector<int> m_componentCount;
763 std::vector<rr::GenericVecType> m_attrType;
766 ContextShaderProgram::ContextShaderProgram (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays)
767 : sglr::ShaderProgram (createProgramDeclaration(ctx, arrays))
768 , m_componentCount (arrays.size())
769 , m_attrType (arrays.size())
771 for (int arrayNdx = 0; arrayNdx < (int)arrays.size(); arrayNdx++)
773 m_componentCount[arrayNdx] = getComponentCount(arrays[arrayNdx]->getOutputType());
774 m_attrType[arrayNdx] = mapOutputType(arrays[arrayNdx]->getOutputType());
778 template <typename T>
779 void calcShaderColorCoord (tcu::Vec2& coord, tcu::Vec3& color, const tcu::Vector<T, 4>& attribValue, bool isCoordinate, int numComponents)
782 switch (numComponents)
784 case 1: coord = tcu::Vec2((float)attribValue.x(), (float)attribValue.x()); break;
785 case 2: coord = tcu::Vec2((float)attribValue.x(), (float)attribValue.y()); break;
786 case 3: coord = tcu::Vec2((float)attribValue.x() + (float)attribValue.z(), (float)attribValue.y()); break;
787 case 4: coord = tcu::Vec2((float)attribValue.x() + (float)attribValue.z(), (float)attribValue.y() + (float)attribValue.w()); break;
794 switch (numComponents)
797 color = color * (float)attribValue.x();
801 color.x() = color.x() * (float)attribValue.x();
802 color.y() = color.y() * (float)attribValue.y();
806 color.x() = color.x() * (float)attribValue.x();
807 color.y() = color.y() * (float)attribValue.y();
808 color.z() = color.z() * (float)attribValue.z();
812 color.x() = color.x() * (float)attribValue.x() * (float)attribValue.w();
813 color.y() = color.y() * (float)attribValue.y() * (float)attribValue.w();
814 color.z() = color.z() * (float)attribValue.z() * (float)attribValue.w();
823 void ContextShaderProgram::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
825 const float u_coordScale = getUniformByName("u_coordScale").value.f;
826 const float u_colorScale = getUniformByName("u_colorScale").value.f;
828 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
830 const size_t varyingLocColor = 0;
832 rr::VertexPacket& packet = *packets[packetNdx];
835 tcu::Vec2 coord = tcu::Vec2(1.0, 1.0);
836 tcu::Vec3 color = tcu::Vec3(1.0, 1.0, 1.0);
838 for (int attribNdx = 0; attribNdx < (int)m_attrType.size(); attribNdx++)
840 const int numComponents = m_componentCount[attribNdx];
842 switch (m_attrType[attribNdx])
844 case rr::GENERICVECTYPE_FLOAT: calcShaderColorCoord(coord, color, rr::readVertexAttribFloat(inputs[attribNdx], packet.instanceNdx, packet.vertexNdx), attribNdx == 0, numComponents); break;
845 case rr::GENERICVECTYPE_INT32: calcShaderColorCoord(coord, color, rr::readVertexAttribInt (inputs[attribNdx], packet.instanceNdx, packet.vertexNdx), attribNdx == 0, numComponents); break;
846 case rr::GENERICVECTYPE_UINT32: calcShaderColorCoord(coord, color, rr::readVertexAttribUint (inputs[attribNdx], packet.instanceNdx, packet.vertexNdx), attribNdx == 0, numComponents); break;
852 // Transform position
854 packet.position = tcu::Vec4(u_coordScale * coord.x(), u_coordScale * coord.y(), 1.0f, 1.0f);
859 packet.outputs[varyingLocColor] = tcu::Vec4(u_colorScale * color.x(), u_colorScale * color.y(), u_colorScale * color.z(), 1.0f);
864 void ContextShaderProgram::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
866 const size_t varyingLocColor = 0;
868 // Triangles are flashaded
869 tcu::Vec4 color = rr::readTriangleVarying<float>(packets[0], context, varyingLocColor, 0);
871 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
872 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
873 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
876 std::string ContextShaderProgram::genVertexSource (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays)
878 std::stringstream vertexShaderTmpl;
879 std::map<std::string, std::string> params;
881 if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_300_ES))
883 params["VTX_IN"] = "in";
884 params["VTX_OUT"] = "out";
885 params["FRAG_IN"] = "in";
886 params["FRAG_COLOR"] = "dEQP_FragColor";
887 params["VTX_HDR"] = "#version 300 es\n";
888 params["FRAG_HDR"] = "#version 300 es\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n";
890 else if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_100_ES))
892 params["VTX_IN"] = "attribute";
893 params["VTX_OUT"] = "varying";
894 params["FRAG_IN"] = "varying";
895 params["FRAG_COLOR"] = "gl_FragColor";
896 params["VTX_HDR"] = "";
897 params["FRAG_HDR"] = "";
899 else if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_330))
901 params["VTX_IN"] = "in";
902 params["VTX_OUT"] = "out";
903 params["FRAG_IN"] = "in";
904 params["FRAG_COLOR"] = "dEQP_FragColor";
905 params["VTX_HDR"] = "#version 330\n";
906 params["FRAG_HDR"] = "#version 330\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n";
911 vertexShaderTmpl << "${VTX_HDR}";
913 for (int arrayNdx = 0; arrayNdx < (int)arrays.size(); arrayNdx++)
916 << "${VTX_IN} highp " << ContextArray::outputTypeToGLType(arrays[arrayNdx]->getOutputType()) << " a_" << arrays[arrayNdx]->getAttribNdx() << ";\n";
920 "uniform highp float u_coordScale;\n"
921 "uniform highp float u_colorScale;\n"
922 "${VTX_OUT} mediump vec4 v_color;\n"
925 "\tgl_PointSize = 1.0;\n"
926 "\thighp vec2 coord = vec2(1.0, 1.0);\n"
927 "\thighp vec3 color = vec3(1.0, 1.0, 1.0);\n";
929 for (int arrayNdx = 0; arrayNdx < (int)arrays.size(); arrayNdx++)
931 if (arrays[arrayNdx]->getAttribNdx() == 0)
933 switch (arrays[arrayNdx]->getOutputType())
935 case (Array::OUTPUTTYPE_FLOAT):
937 "\tcoord = vec2(a_0);\n";
940 case (Array::OUTPUTTYPE_VEC2):
942 "\tcoord = a_0.xy;\n";
945 case (Array::OUTPUTTYPE_VEC3):
947 "\tcoord = a_0.xy;\n"
948 "\tcoord.x = coord.x + a_0.z;\n";
951 case (Array::OUTPUTTYPE_VEC4):
953 "\tcoord = a_0.xy;\n"
954 "\tcoord += a_0.zw;\n";
957 case (Array::OUTPUTTYPE_IVEC2):
958 case (Array::OUTPUTTYPE_UVEC2):
960 "\tcoord = vec2(a_0.xy);\n";
963 case (Array::OUTPUTTYPE_IVEC3):
964 case (Array::OUTPUTTYPE_UVEC3):
966 "\tcoord = vec2(a_0.xy);\n"
967 "\tcoord.x = coord.x + float(a_0.z);\n";
970 case (Array::OUTPUTTYPE_IVEC4):
971 case (Array::OUTPUTTYPE_UVEC4):
973 "\tcoord = vec2(a_0.xy);\n"
974 "\tcoord += vec2(a_0.zw);\n";
984 switch (arrays[arrayNdx]->getOutputType())
986 case (Array::OUTPUTTYPE_FLOAT):
988 "\tcolor = color * a_" << arrays[arrayNdx]->getAttribNdx() << ";\n";
991 case (Array::OUTPUTTYPE_VEC2):
993 "\tcolor.rg = color.rg * a_" << arrays[arrayNdx]->getAttribNdx() << ".xy;\n";
996 case (Array::OUTPUTTYPE_VEC3):
998 "\tcolor = color.rgb * a_" << arrays[arrayNdx]->getAttribNdx() << ".xyz;\n";
1001 case (Array::OUTPUTTYPE_VEC4):
1003 "\tcolor = color.rgb * a_" << arrays[arrayNdx]->getAttribNdx() << ".xyz * a_" << arrays[arrayNdx]->getAttribNdx() << ".w;\n";
1013 "\tv_color = vec4(u_colorScale * color, 1.0);\n"
1014 "\tgl_Position = vec4(u_coordScale * coord, 1.0, 1.0);\n"
1017 return tcu::StringTemplate(vertexShaderTmpl.str().c_str()).specialize(params);
1020 std::string ContextShaderProgram::genFragmentSource (const glu::RenderContext& ctx)
1022 std::map<std::string, std::string> params;
1024 if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_300_ES))
1026 params["VTX_IN"] = "in";
1027 params["VTX_OUT"] = "out";
1028 params["FRAG_IN"] = "in";
1029 params["FRAG_COLOR"] = "dEQP_FragColor";
1030 params["VTX_HDR"] = "#version 300 es\n";
1031 params["FRAG_HDR"] = "#version 300 es\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n";
1033 else if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_100_ES))
1035 params["VTX_IN"] = "attribute";
1036 params["VTX_OUT"] = "varying";
1037 params["FRAG_IN"] = "varying";
1038 params["FRAG_COLOR"] = "gl_FragColor";
1039 params["VTX_HDR"] = "";
1040 params["FRAG_HDR"] = "";
1042 else if (glu::isGLSLVersionSupported(ctx.getType(), glu::GLSL_VERSION_330))
1044 params["VTX_IN"] = "in";
1045 params["VTX_OUT"] = "out";
1046 params["FRAG_IN"] = "in";
1047 params["FRAG_COLOR"] = "dEQP_FragColor";
1048 params["VTX_HDR"] = "#version 330\n";
1049 params["FRAG_HDR"] = "#version 330\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n";
1052 DE_ASSERT(DE_FALSE);
1054 static const char* fragmentShaderTmpl =
1056 "${FRAG_IN} mediump vec4 v_color;\n"
1059 "\t${FRAG_COLOR} = v_color;\n"
1062 return tcu::StringTemplate(fragmentShaderTmpl).specialize(params);
1065 rr::GenericVecType ContextShaderProgram::mapOutputType (const Array::OutputType& type)
1069 case (Array::OUTPUTTYPE_FLOAT):
1070 case (Array::OUTPUTTYPE_VEC2):
1071 case (Array::OUTPUTTYPE_VEC3):
1072 case (Array::OUTPUTTYPE_VEC4):
1073 return rr::GENERICVECTYPE_FLOAT;
1075 case (Array::OUTPUTTYPE_INT):
1076 case (Array::OUTPUTTYPE_IVEC2):
1077 case (Array::OUTPUTTYPE_IVEC3):
1078 case (Array::OUTPUTTYPE_IVEC4):
1079 return rr::GENERICVECTYPE_INT32;
1081 case (Array::OUTPUTTYPE_UINT):
1082 case (Array::OUTPUTTYPE_UVEC2):
1083 case (Array::OUTPUTTYPE_UVEC3):
1084 case (Array::OUTPUTTYPE_UVEC4):
1085 return rr::GENERICVECTYPE_UINT32;
1089 return rr::GENERICVECTYPE_LAST;
1093 int ContextShaderProgram::getComponentCount (const Array::OutputType& type)
1097 case (Array::OUTPUTTYPE_FLOAT):
1098 case (Array::OUTPUTTYPE_INT):
1099 case (Array::OUTPUTTYPE_UINT):
1102 case (Array::OUTPUTTYPE_VEC2):
1103 case (Array::OUTPUTTYPE_IVEC2):
1104 case (Array::OUTPUTTYPE_UVEC2):
1107 case (Array::OUTPUTTYPE_VEC3):
1108 case (Array::OUTPUTTYPE_IVEC3):
1109 case (Array::OUTPUTTYPE_UVEC3):
1112 case (Array::OUTPUTTYPE_VEC4):
1113 case (Array::OUTPUTTYPE_IVEC4):
1114 case (Array::OUTPUTTYPE_UVEC4):
1123 sglr::pdec::ShaderProgramDeclaration ContextShaderProgram::createProgramDeclaration (const glu::RenderContext& ctx, const std::vector<ContextArray*>& arrays)
1125 sglr::pdec::ShaderProgramDeclaration decl;
1127 for (int arrayNdx = 0; arrayNdx < (int)arrays.size(); arrayNdx++)
1128 decl << sglr::pdec::VertexAttribute(std::string("a_") + de::toString(arrayNdx), mapOutputType(arrays[arrayNdx]->getOutputType()));
1130 decl << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT);
1131 decl << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT);
1133 decl << sglr::pdec::VertexSource(genVertexSource(ctx, arrays));
1134 decl << sglr::pdec::FragmentSource(genFragmentSource(ctx));
1136 decl << sglr::pdec::Uniform("u_coordScale", glu::TYPE_FLOAT);
1137 decl << sglr::pdec::Uniform("u_colorScale", glu::TYPE_FLOAT);
1142 void ContextArrayPack::updateProgram (void)
1145 m_program = new ContextShaderProgram(m_renderCtx, m_arrays);
1148 void ContextArrayPack::render (Array::Primitive primitive, int firstVertex, int vertexCount, bool useVao, float coordScale, float colorScale)
1150 deUint32 program = 0;
1155 m_ctx.viewport(0, 0, m_screen.getWidth(), m_screen.getHeight());
1156 m_ctx.clearColor(0.0, 0.0, 0.0, 1.0);
1157 m_ctx.clear(GL_COLOR_BUFFER_BIT);
1159 program = m_ctx.createProgram(m_program);
1161 m_ctx.useProgram(program);
1162 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glUseProgram()");
1164 m_ctx.uniform1f(m_ctx.getUniformLocation(program, "u_coordScale"), coordScale);
1165 m_ctx.uniform1f(m_ctx.getUniformLocation(program, "u_colorScale"), colorScale);
1169 m_ctx.genVertexArrays(1, &vaoId);
1170 m_ctx.bindVertexArray(vaoId);
1173 for (int arrayNdx = 0; arrayNdx < (int)m_arrays.size(); arrayNdx++)
1175 if (m_arrays[arrayNdx]->isBound())
1177 std::stringstream attribName;
1178 attribName << "a_" << m_arrays[arrayNdx]->getAttribNdx();
1180 deUint32 loc = m_ctx.getAttribLocation(program, attribName.str().c_str());
1181 m_ctx.enableVertexAttribArray(loc);
1182 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glEnableVertexAttribArray()");
1184 m_arrays[arrayNdx]->glBind(loc);
1188 DE_ASSERT((firstVertex % 6) == 0);
1189 m_ctx.drawArrays(ContextArray::primitiveToGL(primitive), firstVertex, vertexCount - firstVertex);
1190 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glDrawArrays()");
1192 for (int arrayNdx = 0; arrayNdx < (int)m_arrays.size(); arrayNdx++)
1194 if (m_arrays[arrayNdx]->isBound())
1196 std::stringstream attribName;
1197 attribName << "a_" << m_arrays[arrayNdx]->getAttribNdx();
1199 deUint32 loc = m_ctx.getAttribLocation(program, attribName.str().c_str());
1201 m_ctx.disableVertexAttribArray(loc);
1202 GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glDisableVertexAttribArray()");
1207 m_ctx.deleteVertexArrays(1, &vaoId);
1209 m_ctx.deleteProgram(program);
1210 m_ctx.useProgram(0);
1211 m_ctx.readPixels(m_screen, 0, 0, m_screen.getWidth(), m_screen.getHeight());
1216 GLValue GLValue::getMaxValue (Array::InputType type)
1218 GLValue rangesHi[(int)Array::INPUTTYPE_LAST];
1220 rangesHi[(int)Array::INPUTTYPE_FLOAT] = GLValue(Float::create(127.0f));
1221 rangesHi[(int)Array::INPUTTYPE_DOUBLE] = GLValue(Double::create(127.0f));
1222 rangesHi[(int)Array::INPUTTYPE_BYTE] = GLValue(Byte::create(127));
1223 rangesHi[(int)Array::INPUTTYPE_UNSIGNED_BYTE] = GLValue(Ubyte::create(255));
1224 rangesHi[(int)Array::INPUTTYPE_UNSIGNED_SHORT] = GLValue(Ushort::create(65530));
1225 rangesHi[(int)Array::INPUTTYPE_SHORT] = GLValue(Short::create(32760));
1226 rangesHi[(int)Array::INPUTTYPE_FIXED] = GLValue(Fixed::create(32760));
1227 rangesHi[(int)Array::INPUTTYPE_INT] = GLValue(Int::create(2147483647));
1228 rangesHi[(int)Array::INPUTTYPE_UNSIGNED_INT] = GLValue(Uint::create(4294967295u));
1229 rangesHi[(int)Array::INPUTTYPE_HALF] = GLValue(Half::create(256.0f));
1231 return rangesHi[(int)type];
1234 GLValue GLValue::getMinValue (Array::InputType type)
1236 GLValue rangesLo[(int)Array::INPUTTYPE_LAST];
1238 rangesLo[(int)Array::INPUTTYPE_FLOAT] = GLValue(Float::create(-127.0f));
1239 rangesLo[(int)Array::INPUTTYPE_DOUBLE] = GLValue(Double::create(-127.0f));
1240 rangesLo[(int)Array::INPUTTYPE_BYTE] = GLValue(Byte::create(-127));
1241 rangesLo[(int)Array::INPUTTYPE_UNSIGNED_BYTE] = GLValue(Ubyte::create(0));
1242 rangesLo[(int)Array::INPUTTYPE_UNSIGNED_SHORT] = GLValue(Ushort::create(0));
1243 rangesLo[(int)Array::INPUTTYPE_SHORT] = GLValue(Short::create(-32760));
1244 rangesLo[(int)Array::INPUTTYPE_FIXED] = GLValue(Fixed::create(-32760));
1245 rangesLo[(int)Array::INPUTTYPE_INT] = GLValue(Int::create(-2147483647));
1246 rangesLo[(int)Array::INPUTTYPE_UNSIGNED_INT] = GLValue(Uint::create(0));
1247 rangesLo[(int)Array::INPUTTYPE_HALF] = GLValue(Half::create(-256.0f));
1249 return rangesLo[(int)type];
1252 float GLValue::toFloat (void) const
1256 case Array::INPUTTYPE_FLOAT:
1257 return fl.getValue();
1260 case Array::INPUTTYPE_BYTE:
1261 return b.getValue();
1264 case Array::INPUTTYPE_UNSIGNED_BYTE:
1265 return ub.getValue();
1268 case Array::INPUTTYPE_SHORT:
1269 return s.getValue();
1272 case Array::INPUTTYPE_UNSIGNED_SHORT:
1273 return us.getValue();
1276 case Array::INPUTTYPE_FIXED:
1278 int maxValue = 65536;
1279 return (float)(double(2 * fi.getValue() + 1) / (maxValue - 1));
1284 case Array::INPUTTYPE_UNSIGNED_INT:
1285 return (float)ui.getValue();
1288 case Array::INPUTTYPE_INT:
1289 return (float)i.getValue();
1292 case Array::INPUTTYPE_HALF:
1293 return h.to<float>();
1296 case Array::INPUTTYPE_DOUBLE:
1297 return (float)d.getValue();
1307 class RandomArrayGenerator
1310 static char* generateArray (int seed, GLValue min, GLValue max, int count, int componentCount, int stride, Array::InputType type);
1311 static char* generateQuads (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, Array::InputType type, GLValue min, GLValue max, float gridSize);
1312 static char* generatePerQuad (int seed, int count, int componentCount, int stride, Array::Primitive primitive, Array::InputType type, GLValue min, GLValue max);
1315 template<typename T>
1316 static char* createQuads (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, T min, T max, float gridSize);
1317 template<typename T>
1318 static char* createPerQuads (int seed, int count, int componentCount, int stride, Array::Primitive primitive, T min, T max);
1319 static char* createQuadsPacked (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive);
1320 static void setData (char* data, Array::InputType type, deRandom& rnd, GLValue min, GLValue max);
1323 void RandomArrayGenerator::setData (char* data, Array::InputType type, deRandom& rnd, GLValue min, GLValue max)
1327 case Array::INPUTTYPE_FLOAT:
1329 alignmentSafeAssignment<float>(data, getRandom<GLValue::Float>(rnd, min.fl, max.fl));
1333 case Array::INPUTTYPE_DOUBLE:
1335 alignmentSafeAssignment<double>(data, getRandom<GLValue::Float>(rnd, min.fl, max.fl));
1339 case Array::INPUTTYPE_SHORT:
1341 alignmentSafeAssignment<deInt16>(data, getRandom<GLValue::Short>(rnd, min.s, max.s));
1345 case Array::INPUTTYPE_UNSIGNED_SHORT:
1347 alignmentSafeAssignment<deUint16>(data, getRandom<GLValue::Ushort>(rnd, min.us, max.us));
1351 case Array::INPUTTYPE_BYTE:
1353 alignmentSafeAssignment<deInt8>(data, getRandom<GLValue::Byte>(rnd, min.b, max.b));
1357 case Array::INPUTTYPE_UNSIGNED_BYTE:
1359 alignmentSafeAssignment<deUint8>(data, getRandom<GLValue::Ubyte>(rnd, min.ub, max.ub));
1363 case Array::INPUTTYPE_FIXED:
1365 alignmentSafeAssignment<deInt32>(data, getRandom<GLValue::Fixed>(rnd, min.fi, max.fi));
1369 case Array::INPUTTYPE_INT:
1371 alignmentSafeAssignment<deInt32>(data, getRandom<GLValue::Int>(rnd, min.i, max.i));
1375 case Array::INPUTTYPE_UNSIGNED_INT:
1377 alignmentSafeAssignment<deUint32>(data, getRandom<GLValue::Uint>(rnd, min.ui, max.ui));
1381 case Array::INPUTTYPE_HALF:
1383 alignmentSafeAssignment<deFloat16>(data, getRandom<GLValue::Half>(rnd, min.h, max.h).getValue());
1393 char* RandomArrayGenerator::generateArray (int seed, GLValue min, GLValue max, int count, int componentCount, int stride, Array::InputType type)
1398 deRandom_init(&rnd, seed);
1401 stride = componentCount * Array::inputTypeSize(type);
1403 data = new char[stride * count];
1405 for (int vertexNdx = 0; vertexNdx < count; vertexNdx++)
1407 for (int componentNdx = 0; componentNdx < componentCount; componentNdx++)
1409 setData(&(data[vertexNdx * stride + Array::inputTypeSize(type) * componentNdx]), type, rnd, min, max);
1416 char* RandomArrayGenerator::generateQuads (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, Array::InputType type, GLValue min, GLValue max, float gridSize)
1418 char* data = DE_NULL;
1422 case Array::INPUTTYPE_FLOAT:
1423 data = createQuads<GLValue::Float>(seed, count, componentCount, offset, stride, primitive, min.fl, max.fl, gridSize);
1426 case Array::INPUTTYPE_FIXED:
1427 data = createQuads<GLValue::Fixed>(seed, count, componentCount, offset, stride, primitive, min.fi, max.fi, gridSize);
1430 case Array::INPUTTYPE_DOUBLE:
1431 data = createQuads<GLValue::Double>(seed, count, componentCount, offset, stride, primitive, min.d, max.d, gridSize);
1434 case Array::INPUTTYPE_BYTE:
1435 data = createQuads<GLValue::Byte>(seed, count, componentCount, offset, stride, primitive, min.b, max.b, gridSize);
1438 case Array::INPUTTYPE_SHORT:
1439 data = createQuads<GLValue::Short>(seed, count, componentCount, offset, stride, primitive, min.s, max.s, gridSize);
1442 case Array::INPUTTYPE_UNSIGNED_BYTE:
1443 data = createQuads<GLValue::Ubyte>(seed, count, componentCount, offset, stride, primitive, min.ub, max.ub, gridSize);
1446 case Array::INPUTTYPE_UNSIGNED_SHORT:
1447 data = createQuads<GLValue::Ushort>(seed, count, componentCount, offset, stride, primitive, min.us, max.us, gridSize);
1450 case Array::INPUTTYPE_UNSIGNED_INT:
1451 data = createQuads<GLValue::Uint>(seed, count, componentCount, offset, stride, primitive, min.ui, max.ui, gridSize);
1454 case Array::INPUTTYPE_INT:
1455 data = createQuads<GLValue::Int>(seed, count, componentCount, offset, stride, primitive, min.i, max.i, gridSize);
1458 case Array::INPUTTYPE_HALF:
1459 data = createQuads<GLValue::Half>(seed, count, componentCount, offset, stride, primitive, min.h, max.h, gridSize);
1462 case Array::INPUTTYPE_INT_2_10_10_10:
1463 case Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10:
1464 data = createQuadsPacked(seed, count, componentCount, offset, stride, primitive);
1475 char* RandomArrayGenerator::createQuadsPacked (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive)
1477 DE_ASSERT(componentCount == 4);
1478 DE_UNREF(componentCount);
1482 stride = sizeof(deUint32);
1486 case Array::PRIMITIVE_TRIANGLES:
1487 quadStride = stride * 6;
1495 char* const _data = new char[offset + quadStride * (count - 1) + stride * 5 + componentCount * Array::inputTypeSize(Array::INPUTTYPE_INT_2_10_10_10)]; // last element must be fully in the array
1496 char* const resultData = _data + offset;
1498 const deUint32 max = 1024;
1499 const deUint32 min = 10;
1500 const deUint32 max2 = 4;
1503 deRandom_init(&rnd, seed);
1507 case Array::PRIMITIVE_TRIANGLES:
1509 for (int quadNdx = 0; quadNdx < count; quadNdx++)
1511 deUint32 x1 = min + deRandom_getUint32(&rnd) % (max - min);
1512 deUint32 x2 = min + deRandom_getUint32(&rnd) % (max - x1);
1514 deUint32 y1 = min + deRandom_getUint32(&rnd) % (max - min);
1515 deUint32 y2 = min + deRandom_getUint32(&rnd) % (max - y1);
1517 deUint32 z = min + deRandom_getUint32(&rnd) % (max - min);
1518 deUint32 w = deRandom_getUint32(&rnd) % max2;
1520 deUint32 val1 = (w << 30) | (z << 20) | (y1 << 10) | x1;
1521 deUint32 val2 = (w << 30) | (z << 20) | (y1 << 10) | x2;
1522 deUint32 val3 = (w << 30) | (z << 20) | (y2 << 10) | x1;
1524 deUint32 val4 = (w << 30) | (z << 20) | (y2 << 10) | x1;
1525 deUint32 val5 = (w << 30) | (z << 20) | (y1 << 10) | x2;
1526 deUint32 val6 = (w << 30) | (z << 20) | (y2 << 10) | x2;
1528 alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 0]), val1);
1529 alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 1]), val2);
1530 alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 2]), val3);
1531 alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 3]), val4);
1532 alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 4]), val5);
1533 alignmentSafeAssignment<deUint32>(&(resultData[quadNdx * quadStride + stride * 5]), val6);
1547 template<typename T>
1548 T roundTo (const T& step, const T& value)
1550 return value - (value % step);
1553 template<typename T>
1554 char* RandomArrayGenerator::createQuads (int seed, int count, int componentCount, int offset, int stride, Array::Primitive primitive, T min, T max, float gridSize)
1556 int componentStride = sizeof(T);
1560 stride = componentCount * componentStride;
1562 DE_ASSERT(stride >= componentCount * componentStride);
1566 case Array::PRIMITIVE_TRIANGLES:
1567 quadStride = stride * 6;
1575 char* resultData = new char[offset + quadStride * count];
1576 char* _data = resultData;
1577 resultData = resultData + offset;
1580 deRandom_init(&rnd, seed);
1584 case Array::PRIMITIVE_TRIANGLES:
1586 const T minQuadSize = T::fromFloat(deFloatAbs(max.template to<float>() - min.template to<float>()) * gridSize);
1587 const T minDiff = minValue<T>() > minQuadSize
1591 for (int quadNdx = 0; quadNdx < count; ++quadNdx)
1597 // attempt to find a good (i.e not extremely small) quad
1598 for (int attemptNdx = 0; attemptNdx < 4; ++attemptNdx)
1600 x1 = roundTo(minDiff, getRandom<T>(rnd, min, max));
1601 x2 = roundTo(minDiff, getRandom<T>(rnd, minDiff, abs<T>(max - x1)));
1603 y1 = roundTo(minDiff, getRandom<T>(rnd, min, max));
1604 y2 = roundTo(minDiff, getRandom<T>(rnd, minDiff, abs<T>(max - y1)));
1606 z = (componentCount > 2) ? roundTo(minDiff, (getRandom<T>(rnd, min, max))) : (T::create(0));
1607 w = (componentCount > 3) ? roundTo(minDiff, (getRandom<T>(rnd, min, max))) : (T::create(1));
1609 // no additional components, all is good
1610 if (componentCount <= 2)
1613 // The result quad is too thin?
1614 if ((deFloatAbs(x2.template to<float>() + z.template to<float>()) < minDiff.template to<float>()) ||
1615 (deFloatAbs(y2.template to<float>() + w.template to<float>()) < minDiff.template to<float>()))
1622 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride]), x1);
1623 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + componentStride]), y1);
1625 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride]), x1 + x2);
1626 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride + componentStride]), y1);
1628 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 2]), x1);
1629 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 2 + componentStride]), y1 + y2);
1631 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 3]), x1);
1632 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 3 + componentStride]), y1 + y2);
1634 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 4]), x1 + x2);
1635 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 4 + componentStride]), y1);
1637 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 5]), x1 + x2);
1638 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * 5 + componentStride]), y1 + y2);
1640 if (componentCount > 2)
1642 for (int i = 0; i < 6; i++)
1643 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * i + componentStride * 2]), z);
1646 if (componentCount > 3)
1648 for (int i = 0; i < 6; i++)
1649 alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + stride * i + componentStride * 3]), w);
1664 char* RandomArrayGenerator::generatePerQuad (int seed, int count, int componentCount, int stride, Array::Primitive primitive, Array::InputType type, GLValue min, GLValue max)
1666 char* data = DE_NULL;
1670 case Array::INPUTTYPE_FLOAT:
1671 data = createPerQuads<GLValue::Float>(seed, count, componentCount, stride, primitive, min.fl, max.fl);
1674 case Array::INPUTTYPE_FIXED:
1675 data = createPerQuads<GLValue::Fixed>(seed, count, componentCount, stride, primitive, min.fi, max.fi);
1678 case Array::INPUTTYPE_DOUBLE:
1679 data = createPerQuads<GLValue::Double>(seed, count, componentCount, stride, primitive, min.d, max.d);
1682 case Array::INPUTTYPE_BYTE:
1683 data = createPerQuads<GLValue::Byte>(seed, count, componentCount, stride, primitive, min.b, max.b);
1686 case Array::INPUTTYPE_SHORT:
1687 data = createPerQuads<GLValue::Short>(seed, count, componentCount, stride, primitive, min.s, max.s);
1690 case Array::INPUTTYPE_UNSIGNED_BYTE:
1691 data = createPerQuads<GLValue::Ubyte>(seed, count, componentCount, stride, primitive, min.ub, max.ub);
1694 case Array::INPUTTYPE_UNSIGNED_SHORT:
1695 data = createPerQuads<GLValue::Ushort>(seed, count, componentCount, stride, primitive, min.us, max.us);
1698 case Array::INPUTTYPE_UNSIGNED_INT:
1699 data = createPerQuads<GLValue::Uint>(seed, count, componentCount, stride, primitive, min.ui, max.ui);
1702 case Array::INPUTTYPE_INT:
1703 data = createPerQuads<GLValue::Int>(seed, count, componentCount, stride, primitive, min.i, max.i);
1706 case Array::INPUTTYPE_HALF:
1707 data = createPerQuads<GLValue::Half>(seed, count, componentCount, stride, primitive, min.h, max.h);
1718 template<typename T>
1719 char* RandomArrayGenerator::createPerQuads (int seed, int count, int componentCount, int stride, Array::Primitive primitive, T min, T max)
1722 deRandom_init(&rnd, seed);
1724 int componentStride = sizeof(T);
1727 stride = componentStride * componentCount;
1733 case Array::PRIMITIVE_TRIANGLES:
1734 quadStride = stride * 6;
1742 char* data = new char[count * quadStride];
1744 for (int quadNdx = 0; quadNdx < count; quadNdx++)
1746 for (int componentNdx = 0; componentNdx < componentCount; componentNdx++)
1748 T val = getRandom<T>(rnd, min, max);
1750 alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 0 + componentStride * componentNdx, val);
1751 alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 1 + componentStride * componentNdx, val);
1752 alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 2 + componentStride * componentNdx, val);
1753 alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 3 + componentStride * componentNdx, val);
1754 alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 4 + componentStride * componentNdx, val);
1755 alignmentSafeAssignment<T>(data + quadNdx * quadStride + stride * 5 + componentStride * componentNdx, val);
1764 VertexArrayTest::VertexArrayTest (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name ,const char* desc)
1765 : TestCase (testCtx, name, desc)
1766 , m_renderCtx (renderCtx)
1767 , m_refBuffers (DE_NULL)
1768 , m_refContext (DE_NULL)
1769 , m_glesContext (DE_NULL)
1770 , m_glArrayPack (DE_NULL)
1771 , m_rrArrayPack (DE_NULL)
1773 , m_maxDiffRed (deCeilFloatToInt32(256.0f * (2.0f / (float)(1 << m_renderCtx.getRenderTarget().getPixelFormat().redBits))))
1774 , m_maxDiffGreen (deCeilFloatToInt32(256.0f * (2.0f / (float)(1 << m_renderCtx.getRenderTarget().getPixelFormat().greenBits))))
1775 , m_maxDiffBlue (deCeilFloatToInt32(256.0f * (2.0f / (float)(1 << m_renderCtx.getRenderTarget().getPixelFormat().blueBits))))
1779 VertexArrayTest::~VertexArrayTest (void)
1784 void VertexArrayTest::init (void)
1786 const int renderTargetWidth = de::min(512, m_renderCtx.getRenderTarget().getWidth());
1787 const int renderTargetHeight = de::min(512, m_renderCtx.getRenderTarget().getHeight());
1788 sglr::ReferenceContextLimits limits (m_renderCtx);
1790 m_glesContext = new sglr::GLContext(m_renderCtx, m_testCtx.getLog(), sglr::GLCONTEXT_LOG_CALLS | sglr::GLCONTEXT_LOG_PROGRAMS, tcu::IVec4(0, 0, renderTargetWidth, renderTargetHeight));
1792 m_refBuffers = new sglr::ReferenceContextBuffers(m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, renderTargetWidth, renderTargetHeight);
1793 m_refContext = new sglr::ReferenceContext(limits, m_refBuffers->getColorbuffer(), m_refBuffers->getDepthbuffer(), m_refBuffers->getStencilbuffer());
1795 m_glArrayPack = new ContextArrayPack(m_renderCtx, *m_glesContext);
1796 m_rrArrayPack = new ContextArrayPack(m_renderCtx, *m_refContext);
1799 void VertexArrayTest::deinit (void)
1801 delete m_glArrayPack;
1802 delete m_rrArrayPack;
1803 delete m_refBuffers;
1804 delete m_refContext;
1805 delete m_glesContext;
1807 m_glArrayPack = DE_NULL;
1808 m_rrArrayPack = DE_NULL;
1809 m_refBuffers = DE_NULL;
1810 m_refContext = DE_NULL;
1811 m_glesContext = DE_NULL;
1814 void VertexArrayTest::compare (void)
1816 const tcu::Surface& ref = m_rrArrayPack->getSurface();
1817 const tcu::Surface& screen = m_glArrayPack->getSurface();
1819 if (m_renderCtx.getRenderTarget().getNumSamples() > 1)
1821 // \todo [mika] Improve compare when using multisampling
1822 m_testCtx.getLog() << tcu::TestLog::Message << "Warning: Comparision of result from multisample render targets are not as stricts as without multisampling. Might produce false positives!" << tcu::TestLog::EndMessage;
1823 m_isOk = tcu::fuzzyCompare(m_testCtx.getLog(), "Compare Results", "Compare Results", ref.getAccess(), screen.getAccess(), 1.5f, tcu::COMPARE_LOG_RESULT);
1827 tcu::RGBA threshold (m_maxDiffRed, m_maxDiffGreen, m_maxDiffBlue, 255);
1828 tcu::Surface error (ref.getWidth(), ref.getHeight());
1832 for (int y = 0; y < ref.getHeight(); y++)
1834 for (int x = 0; x < ref.getWidth(); x++)
1836 tcu::RGBA refPixel = ref.getPixel(x, y);
1837 tcu::RGBA screenPixel = screen.getPixel(x, y);
1838 bool isOkPixel = false;
1840 if (y == 0 || y + 1 == ref.getHeight() || x == 0 || x + 1 == ref.getWidth())
1842 // Don't check borders since the pixel neighborhood is undefined
1843 error.setPixel(x, y, tcu::RGBA(screenPixel.getRed(), (screenPixel.getGreen() + 255) / 2, screenPixel.getBlue(), 255));
1847 // Don't do comparisons for this pixel if it belongs to a one-pixel-thin part (i.e. it doesn't have similar-color neighbors in both x and y directions) in both result and reference.
1848 // This fixes some false negatives.
1849 bool refThin = (!tcu::compareThreshold(refPixel, ref.getPixel(x-1, y ), threshold) && !tcu::compareThreshold(refPixel, ref.getPixel(x+1, y ), threshold)) ||
1850 (!tcu::compareThreshold(refPixel, ref.getPixel(x , y-1), threshold) && !tcu::compareThreshold(refPixel, ref.getPixel(x , y+1), threshold));
1851 bool screenThin = (!tcu::compareThreshold(screenPixel, screen.getPixel(x-1, y ), threshold) && !tcu::compareThreshold(screenPixel, screen.getPixel(x+1, y ), threshold)) ||
1852 (!tcu::compareThreshold(screenPixel, screen.getPixel(x , y-1), threshold) && !tcu::compareThreshold(screenPixel, screen.getPixel(x , y+1), threshold));
1854 if (refThin && screenThin)
1858 for (int dy = -1; dy < 2 && !isOkPixel; dy++)
1860 for (int dx = -1; dx < 2 && !isOkPixel; dx++)
1862 // Check reference pixel against screen pixel
1864 tcu::RGBA screenCmpPixel = screen.getPixel(x+dx, y+dy);
1865 deUint8 r = (deUint8)deAbs32(refPixel.getRed() - screenCmpPixel.getRed());
1866 deUint8 g = (deUint8)deAbs32(refPixel.getGreen() - screenCmpPixel.getGreen());
1867 deUint8 b = (deUint8)deAbs32(refPixel.getBlue() - screenCmpPixel.getBlue());
1869 if (r <= m_maxDiffRed && g <= m_maxDiffGreen && b <= m_maxDiffBlue)
1873 // Check screen pixels against reference pixel
1875 tcu::RGBA refCmpPixel = ref.getPixel(x+dx, y+dy);
1876 deUint8 r = (deUint8)deAbs32(refCmpPixel.getRed() - screenPixel.getRed());
1877 deUint8 g = (deUint8)deAbs32(refCmpPixel.getGreen() - screenPixel.getGreen());
1878 deUint8 b = (deUint8)deAbs32(refCmpPixel.getBlue() - screenPixel.getBlue());
1880 if (r <= m_maxDiffRed && g <= m_maxDiffGreen && b <= m_maxDiffBlue)
1888 error.setPixel(x, y, tcu::RGBA(screen.getPixel(x, y).getRed(), (screen.getPixel(x, y).getGreen() + 255) / 2, screen.getPixel(x, y).getBlue(), 255));
1891 error.setPixel(x, y, tcu::RGBA(255, 0, 0, 255));
1897 tcu::TestLog& log = m_testCtx.getLog();
1900 log << TestLog::Message << "Image comparison failed, threshold = (" << m_maxDiffRed << ", " << m_maxDiffGreen << ", " << m_maxDiffBlue << ")" << TestLog::EndMessage;
1901 log << TestLog::ImageSet("Compare result", "Result of rendering")
1902 << TestLog::Image("Result", "Result", screen)
1903 << TestLog::Image("Reference", "Reference", ref)
1904 << TestLog::Image("ErrorMask", "Error mask", error)
1905 << TestLog::EndImageSet;
1909 log << TestLog::ImageSet("Compare result", "Result of rendering")
1910 << TestLog::Image("Result", "Result", screen)
1911 << TestLog::EndImageSet;
1916 // MultiVertexArrayTest
1918 MultiVertexArrayTest::Spec::ArraySpec::ArraySpec(Array::InputType inputType_, Array::OutputType outputType_, Array::Storage storage_, Array::Usage usage_, int componentCount_, int offset_, int stride_, bool normalize_, GLValue min_, GLValue max_)
1919 : inputType (inputType_)
1920 , outputType (outputType_)
1921 , storage (storage_)
1923 , componentCount(componentCount_)
1926 , normalize (normalize_)
1932 std::string MultiVertexArrayTest::Spec::getName (void) const
1934 std::stringstream name;
1936 for (size_t ndx = 0; ndx < arrays.size(); ++ndx)
1938 const ArraySpec& array = arrays[ndx];
1940 if (arrays.size() > 1)
1941 name << "array" << ndx << "_";
1944 << Array::storageToString(array.storage) << "_"
1945 << array.offset << "_"
1946 << array.stride << "_"
1947 << Array::inputTypeToString((Array::InputType)array.inputType);
1948 if (array.inputType != Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10 && array.inputType != Array::INPUTTYPE_INT_2_10_10_10)
1949 name << array.componentCount;
1952 << (array.normalize ? "normalized_" : "")
1953 << Array::outputTypeToString(array.outputType) << "_"
1954 << Array::usageTypeToString(array.usage) << "_";
1958 name << "first" << first << "_";
1962 case Array::PRIMITIVE_TRIANGLES:
1965 case Array::PRIMITIVE_POINTS:
1979 std::string MultiVertexArrayTest::Spec::getDesc (void) const
1981 std::stringstream desc;
1983 for (size_t ndx = 0; ndx < arrays.size(); ++ndx)
1985 const ArraySpec& array = arrays[ndx];
1988 << "Array " << ndx << ": "
1989 << "Storage in " << Array::storageToString(array.storage) << ", "
1990 << "stride " << array.stride << ", "
1991 << "input datatype " << Array::inputTypeToString((Array::InputType)array.inputType) << ", "
1992 << "input component count " << array.componentCount << ", "
1993 << (array.normalize ? "normalized, " : "")
1994 << "used as " << Array::outputTypeToString(array.outputType) << ", ";
1999 << "first " << first << ", "
2004 case Array::PRIMITIVE_TRIANGLES:
2007 case Array::PRIMITIVE_POINTS:
2020 MultiVertexArrayTest::MultiVertexArrayTest (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const Spec& spec, const char* name, const char* desc)
2021 : VertexArrayTest (testCtx, renderCtx, name, desc)
2027 MultiVertexArrayTest::~MultiVertexArrayTest (void)
2031 MultiVertexArrayTest::IterateResult MultiVertexArrayTest::iterate (void)
2033 if (m_iteration == 0)
2035 const size_t primitiveSize = (m_spec.primitive == Array::PRIMITIVE_TRIANGLES) ? (6) : (1); // in non-indexed draw Triangles means rectangles
2036 float coordScale = 1.0f;
2037 float colorScale = 1.0f;
2038 const bool useVao = m_renderCtx.getType().getProfile() == glu::PROFILE_CORE;
2041 m_testCtx.getLog() << TestLog::Message << m_spec.getDesc() << TestLog::EndMessage;
2043 // Color and Coord scale
2045 // First array is always position
2047 Spec::ArraySpec arraySpec = m_spec.arrays[0];
2048 if (arraySpec.inputType == Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10)
2050 if (arraySpec.normalize)
2053 coordScale = 1.0 / 1024.0;
2055 else if (arraySpec.inputType == Array::INPUTTYPE_INT_2_10_10_10)
2057 if (arraySpec.normalize)
2060 coordScale = 1.0 / 512.0;
2063 coordScale = (arraySpec.normalize && !inputTypeIsFloatType(arraySpec.inputType) ? 1.0f : float(0.9 / double(arraySpec.max.toFloat())));
2065 if (arraySpec.outputType == Array::OUTPUTTYPE_VEC3 || arraySpec.outputType == Array::OUTPUTTYPE_VEC4
2066 || arraySpec.outputType == Array::OUTPUTTYPE_IVEC3 || arraySpec.outputType == Array::OUTPUTTYPE_IVEC4
2067 || arraySpec.outputType == Array::OUTPUTTYPE_UVEC3 || arraySpec.outputType == Array::OUTPUTTYPE_UVEC4)
2068 coordScale = coordScale * 0.5f;
2071 // And other arrays are color-like
2072 for (int arrayNdx = 1; arrayNdx < (int)m_spec.arrays.size(); arrayNdx++)
2074 Spec::ArraySpec arraySpec = m_spec.arrays[arrayNdx];
2076 colorScale *= (arraySpec.normalize && !inputTypeIsFloatType(arraySpec.inputType) ? 1.0f : float(1.0 / double(arraySpec.max.toFloat())));
2077 if (arraySpec.outputType == Array::OUTPUTTYPE_VEC4)
2078 colorScale *= (arraySpec.normalize && !inputTypeIsFloatType(arraySpec.inputType) ? 1.0f : float(1.0 / double(arraySpec.max.toFloat())));
2083 for (int arrayNdx = 0; arrayNdx < (int)m_spec.arrays.size(); arrayNdx++)
2085 Spec::ArraySpec arraySpec = m_spec.arrays[arrayNdx];
2086 const int seed = int(arraySpec.inputType) + 10 * int(arraySpec.outputType) + 100 * int(arraySpec.storage) + 1000 * int(m_spec.primitive) + 10000 * int(arraySpec.usage) + int(m_spec.drawCount) + 12 * int(arraySpec.componentCount) + int(arraySpec.stride) + int(arraySpec.normalize);
2087 const char* data = DE_NULL;
2088 const size_t stride = (arraySpec.stride == 0) ? (arraySpec.componentCount * Array::inputTypeSize(arraySpec.inputType)) : (arraySpec.stride);
2089 const size_t bufferSize = arraySpec.offset + stride * (m_spec.drawCount * primitiveSize - 1) + arraySpec.componentCount * Array::inputTypeSize(arraySpec.inputType);
2090 // Snap values to at least 3x3 grid
2091 const float gridSize = 3.0f / (float)(de::min(m_renderCtx.getRenderTarget().getWidth(), m_renderCtx.getRenderTarget().getHeight()) - 1);
2093 switch (m_spec.primitive)
2095 // case Array::PRIMITIVE_POINTS:
2096 // data = RandomArrayGenerator::generateArray(seed, arraySpec.min, arraySpec.max, arraySpec.count, arraySpec.componentCount, arraySpec.stride, arraySpec.inputType);
2098 case Array::PRIMITIVE_TRIANGLES:
2101 data = RandomArrayGenerator::generateQuads(seed, m_spec.drawCount, arraySpec.componentCount, arraySpec.offset, arraySpec.stride, m_spec.primitive, arraySpec.inputType, arraySpec.min, arraySpec.max, gridSize);
2105 DE_ASSERT(arraySpec.offset == 0); // \note [jarkko] it just hasn't been implemented
2106 data = RandomArrayGenerator::generatePerQuad(seed, m_spec.drawCount, arraySpec.componentCount, arraySpec.stride, m_spec.primitive, arraySpec.inputType, arraySpec.min, arraySpec.max);
2115 m_glArrayPack->newArray(arraySpec.storage);
2116 m_rrArrayPack->newArray(arraySpec.storage);
2118 m_glArrayPack->getArray(arrayNdx)->data(Array::TARGET_ARRAY, (int)bufferSize, data, arraySpec.usage);
2119 m_rrArrayPack->getArray(arrayNdx)->data(Array::TARGET_ARRAY, (int)bufferSize, data, arraySpec.usage);
2121 m_glArrayPack->getArray(arrayNdx)->bind(arrayNdx, arraySpec.offset, arraySpec.componentCount, arraySpec.inputType, arraySpec.outputType, arraySpec.normalize, arraySpec.stride);
2122 m_rrArrayPack->getArray(arrayNdx)->bind(arrayNdx, arraySpec.offset, arraySpec.componentCount, arraySpec.inputType, arraySpec.outputType, arraySpec.normalize, arraySpec.stride);
2129 m_glArrayPack->render(m_spec.primitive, m_spec.first, m_spec.drawCount * (int)primitiveSize, useVao, coordScale, colorScale);
2130 m_rrArrayPack->render(m_spec.primitive, m_spec.first, m_spec.drawCount * (int)primitiveSize, useVao, coordScale, colorScale);
2132 catch (glu::Error& err)
2134 // GL Errors are ok if the mode is not properly aligned
2136 m_testCtx.getLog() << TestLog::Message << "Got error: " << err.what() << TestLog::EndMessage;
2138 if (isUnalignedBufferOffsetTest())
2139 m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Failed to draw with unaligned buffers.");
2140 else if (isUnalignedBufferStrideTest())
2141 m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Failed to draw with unaligned stride.");
2151 else if (m_iteration == 1)
2157 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2161 if (isUnalignedBufferOffsetTest())
2162 m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Failed to draw with unaligned buffers.");
2163 else if (isUnalignedBufferStrideTest())
2164 m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Failed to draw with unaligned stride.");
2166 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed.");
2179 bool MultiVertexArrayTest::isUnalignedBufferOffsetTest (void) const
2181 // Buffer offsets should be data type size aligned
2182 for (size_t i = 0; i < m_spec.arrays.size(); ++i)
2184 if (m_spec.arrays[i].storage == Array::STORAGE_BUFFER)
2186 const bool inputTypePacked = m_spec.arrays[i].inputType == Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10 || m_spec.arrays[i].inputType == Array::INPUTTYPE_INT_2_10_10_10;
2188 int dataTypeSize = Array::inputTypeSize(m_spec.arrays[i].inputType);
2189 if (inputTypePacked)
2192 if (m_spec.arrays[i].offset % dataTypeSize != 0)
2200 bool MultiVertexArrayTest::isUnalignedBufferStrideTest (void) const
2202 // Buffer strides should be data type size aligned
2203 for (size_t i = 0; i < m_spec.arrays.size(); ++i)
2205 if (m_spec.arrays[i].storage == Array::STORAGE_BUFFER)
2207 const bool inputTypePacked = m_spec.arrays[i].inputType == Array::INPUTTYPE_UNSIGNED_INT_2_10_10_10 || m_spec.arrays[i].inputType == Array::INPUTTYPE_INT_2_10_10_10;
2209 int dataTypeSize = Array::inputTypeSize(m_spec.arrays[i].inputType);
2210 if (inputTypePacked)
2213 if (m_spec.arrays[i].stride % dataTypeSize != 0)