1e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 2e5c31af7Sopenharmony_ci * drawElements Quality Program OpenGL ES Utilities 3e5c31af7Sopenharmony_ci * ------------------------------------------------ 4e5c31af7Sopenharmony_ci * 5e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 10e5c31af7Sopenharmony_ci * 11e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 17e5c31af7Sopenharmony_ci * limitations under the License. 18e5c31af7Sopenharmony_ci * 19e5c31af7Sopenharmony_ci *//*! 20e5c31af7Sopenharmony_ci * \file 21e5c31af7Sopenharmony_ci * \brief SGLR Context utilities. 22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci#include "sglrContextUtil.hpp" 25e5c31af7Sopenharmony_ci#include "sglrContext.hpp" 26e5c31af7Sopenharmony_ci#include "glwEnums.hpp" 27e5c31af7Sopenharmony_ci 28e5c31af7Sopenharmony_cinamespace sglr 29e5c31af7Sopenharmony_ci{ 30e5c31af7Sopenharmony_ci 31e5c31af7Sopenharmony_civoid drawQuad (sglr::Context& ctx, deUint32 program, const tcu::Vec3& p0, const tcu::Vec3& p1) 32e5c31af7Sopenharmony_ci{ 33e5c31af7Sopenharmony_ci const glu::ContextType ctxType = ctx.getType(); 34e5c31af7Sopenharmony_ci 35e5c31af7Sopenharmony_ci if (glu::isContextTypeGLCore(ctxType) || (contextSupports(ctxType, glu::ApiType::es(3,1)))) 36e5c31af7Sopenharmony_ci drawQuadWithVaoBuffers(ctx, program, p0, p1); 37e5c31af7Sopenharmony_ci else 38e5c31af7Sopenharmony_ci { 39e5c31af7Sopenharmony_ci DE_ASSERT(isContextTypeES(ctxType)); 40e5c31af7Sopenharmony_ci drawQuadWithClientPointers(ctx, program, p0, p1); 41e5c31af7Sopenharmony_ci } 42e5c31af7Sopenharmony_ci} 43e5c31af7Sopenharmony_ci 44e5c31af7Sopenharmony_civoid drawQuadWithVaoBuffers (sglr::Context& ctx, deUint32 program, const tcu::Vec3& p0, const tcu::Vec3& p1) 45e5c31af7Sopenharmony_ci{ 46e5c31af7Sopenharmony_ci // Vertex data. 47e5c31af7Sopenharmony_ci float hz = (p0.z() + p1.z()) * 0.5f; 48e5c31af7Sopenharmony_ci float position[] = 49e5c31af7Sopenharmony_ci { 50e5c31af7Sopenharmony_ci p0.x(), p0.y(), p0.z(), 1.0f, 51e5c31af7Sopenharmony_ci p0.x(), p1.y(), hz, 1.0f, 52e5c31af7Sopenharmony_ci p1.x(), p0.y(), hz, 1.0f, 53e5c31af7Sopenharmony_ci p1.x(), p1.y(), p1.z(), 1.0f 54e5c31af7Sopenharmony_ci }; 55e5c31af7Sopenharmony_ci const float coord[] = 56e5c31af7Sopenharmony_ci { 57e5c31af7Sopenharmony_ci 0.0f, 0.0f, 58e5c31af7Sopenharmony_ci 0.0f, 1.0f, 59e5c31af7Sopenharmony_ci 1.0f, 0.0f, 60e5c31af7Sopenharmony_ci 1.0f, 1.0f 61e5c31af7Sopenharmony_ci }; 62e5c31af7Sopenharmony_ci const deUint16 indices[] = { 0, 1, 2, 2, 1, 3 }; 63e5c31af7Sopenharmony_ci 64e5c31af7Sopenharmony_ci deInt32 posLoc = ctx.getAttribLocation(program, "a_position"); 65e5c31af7Sopenharmony_ci deInt32 coordLoc = ctx.getAttribLocation(program, "a_coord"); 66e5c31af7Sopenharmony_ci deUint32 vaoID; 67e5c31af7Sopenharmony_ci deUint32 bufIDs[2]; 68e5c31af7Sopenharmony_ci 69e5c31af7Sopenharmony_ci ctx.genVertexArrays(1, &vaoID); 70e5c31af7Sopenharmony_ci ctx.bindVertexArray(vaoID); 71e5c31af7Sopenharmony_ci 72e5c31af7Sopenharmony_ci ctx.genBuffers(2, &bufIDs[0]); 73e5c31af7Sopenharmony_ci 74e5c31af7Sopenharmony_ci ctx.useProgram(program); 75e5c31af7Sopenharmony_ci TCU_CHECK(posLoc >= 0); 76e5c31af7Sopenharmony_ci { 77e5c31af7Sopenharmony_ci ctx.bindBuffer(GL_ARRAY_BUFFER, bufIDs[0]); 78e5c31af7Sopenharmony_ci ctx.bufferData(GL_ARRAY_BUFFER, DE_LENGTH_OF_ARRAY(position)*sizeof(float), &position[0], GL_STATIC_DRAW); 79e5c31af7Sopenharmony_ci 80e5c31af7Sopenharmony_ci ctx.enableVertexAttribArray(posLoc); 81e5c31af7Sopenharmony_ci ctx.vertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, 0); 82e5c31af7Sopenharmony_ci 83e5c31af7Sopenharmony_ci ctx.bindBuffer(GL_ARRAY_BUFFER, 0); 84e5c31af7Sopenharmony_ci } 85e5c31af7Sopenharmony_ci 86e5c31af7Sopenharmony_ci if (coordLoc >= 0) 87e5c31af7Sopenharmony_ci { 88e5c31af7Sopenharmony_ci ctx.bindBuffer(GL_ARRAY_BUFFER, bufIDs[1]); 89e5c31af7Sopenharmony_ci ctx.bufferData(GL_ARRAY_BUFFER, DE_LENGTH_OF_ARRAY(coord)*sizeof(float), &coord[0], GL_STATIC_DRAW); 90e5c31af7Sopenharmony_ci 91e5c31af7Sopenharmony_ci ctx.enableVertexAttribArray(coordLoc); 92e5c31af7Sopenharmony_ci ctx.vertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, 0); 93e5c31af7Sopenharmony_ci 94e5c31af7Sopenharmony_ci ctx.bindBuffer(GL_ARRAY_BUFFER, 0); 95e5c31af7Sopenharmony_ci } 96e5c31af7Sopenharmony_ci 97e5c31af7Sopenharmony_ci { 98e5c31af7Sopenharmony_ci deUint32 ndxID; 99e5c31af7Sopenharmony_ci ctx.genBuffers(1, &ndxID); 100e5c31af7Sopenharmony_ci 101e5c31af7Sopenharmony_ci ctx.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, ndxID); 102e5c31af7Sopenharmony_ci ctx.bufferData(GL_ELEMENT_ARRAY_BUFFER, DE_LENGTH_OF_ARRAY(indices)*sizeof(deUint16), &indices[0], GL_STATIC_DRAW); 103e5c31af7Sopenharmony_ci 104e5c31af7Sopenharmony_ci ctx.drawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_SHORT, 0); 105e5c31af7Sopenharmony_ci 106e5c31af7Sopenharmony_ci ctx.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 107e5c31af7Sopenharmony_ci ctx.deleteBuffers(1, &ndxID); 108e5c31af7Sopenharmony_ci } 109e5c31af7Sopenharmony_ci 110e5c31af7Sopenharmony_ci ctx.deleteBuffers(2, &bufIDs[0]); 111e5c31af7Sopenharmony_ci ctx.deleteVertexArrays(1, &vaoID); 112e5c31af7Sopenharmony_ci} 113e5c31af7Sopenharmony_ci 114e5c31af7Sopenharmony_civoid drawQuadWithClientPointers (sglr::Context& ctx, deUint32 program, const tcu::Vec3& p0, const tcu::Vec3& p1) 115e5c31af7Sopenharmony_ci{ 116e5c31af7Sopenharmony_ci // Vertex data. 117e5c31af7Sopenharmony_ci float hz = (p0.z() + p1.z()) * 0.5f; 118e5c31af7Sopenharmony_ci float position[] = 119e5c31af7Sopenharmony_ci { 120e5c31af7Sopenharmony_ci p0.x(), p0.y(), p0.z(), 1.0f, 121e5c31af7Sopenharmony_ci p0.x(), p1.y(), hz, 1.0f, 122e5c31af7Sopenharmony_ci p1.x(), p0.y(), hz, 1.0f, 123e5c31af7Sopenharmony_ci p1.x(), p1.y(), p1.z(), 1.0f 124e5c31af7Sopenharmony_ci }; 125e5c31af7Sopenharmony_ci const float coord[] = 126e5c31af7Sopenharmony_ci { 127e5c31af7Sopenharmony_ci 0.0f, 0.0f, 128e5c31af7Sopenharmony_ci 0.0f, 1.0f, 129e5c31af7Sopenharmony_ci 1.0f, 0.0f, 130e5c31af7Sopenharmony_ci 1.0f, 1.0f 131e5c31af7Sopenharmony_ci }; 132e5c31af7Sopenharmony_ci const deUint16 indices[] = { 0, 1, 2, 2, 1, 3 }; 133e5c31af7Sopenharmony_ci 134e5c31af7Sopenharmony_ci deInt32 posLoc = ctx.getAttribLocation(program, "a_position"); 135e5c31af7Sopenharmony_ci deInt32 coordLoc = ctx.getAttribLocation(program, "a_coord"); 136e5c31af7Sopenharmony_ci 137e5c31af7Sopenharmony_ci ctx.useProgram(program); 138e5c31af7Sopenharmony_ci TCU_CHECK(posLoc >= 0); 139e5c31af7Sopenharmony_ci { 140e5c31af7Sopenharmony_ci ctx.enableVertexAttribArray(posLoc); 141e5c31af7Sopenharmony_ci ctx.vertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &position[0]); 142e5c31af7Sopenharmony_ci } 143e5c31af7Sopenharmony_ci 144e5c31af7Sopenharmony_ci if (coordLoc >= 0) 145e5c31af7Sopenharmony_ci { 146e5c31af7Sopenharmony_ci ctx.enableVertexAttribArray(coordLoc); 147e5c31af7Sopenharmony_ci ctx.vertexAttribPointer(coordLoc, 2, GL_FLOAT, GL_FALSE, 0, &coord[0]); 148e5c31af7Sopenharmony_ci } 149e5c31af7Sopenharmony_ci 150e5c31af7Sopenharmony_ci ctx.drawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_SHORT, &indices[0]); 151e5c31af7Sopenharmony_ci 152e5c31af7Sopenharmony_ci if (posLoc >= 0) 153e5c31af7Sopenharmony_ci ctx.disableVertexAttribArray(posLoc); 154e5c31af7Sopenharmony_ci 155e5c31af7Sopenharmony_ci if (coordLoc >= 0) 156e5c31af7Sopenharmony_ci ctx.disableVertexAttribArray(coordLoc); 157e5c31af7Sopenharmony_ci} 158e5c31af7Sopenharmony_ci 159e5c31af7Sopenharmony_ci} //sglr 160