13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES Utilities 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------ 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief OpenGL ES Pixel Transfer Utilities. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace glu 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline int getTransferAlignment (tcu::TextureFormat format) 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int pixelSize = format.getPixelSize(); 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (deIsPowerOfTwo32(pixelSize)) 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return de::min(pixelSize, 8); 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 1; 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Read pixels to pixel buffer access. 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \note Stride must be default stride for format. 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid readPixels (const RenderContext& context, int x, int y, const tcu::PixelBufferAccess& dst) 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(dst.getDepth() == 1); 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(dst.getRowPitch() == dst.getFormat().getPixelSize()*dst.getWidth()); 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = dst.getWidth(); 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = dst.getHeight(); 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat format = getTransferFormat(dst.getFormat()); 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_PACK_ALIGNMENT, getTransferAlignment(dst.getFormat())); 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.readPixels(x, y, width, height, format.format, format.dataType, dst.getDataPtr()); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Upload pixels from pixel buffer access. 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \note Stride must be default stride for format. 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid texImage2D (const RenderContext& context, deUint32 target, int level, deUint32 internalFormat, const tcu::ConstPixelBufferAccess& src) 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(src.getDepth() == 1); 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth()); 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = src.getWidth(); 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = src.getHeight(); 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat format = getTransferFormat(src.getFormat()); 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat())); 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texImage2D(target, level, internalFormat, width, height, 0, format.format, format.dataType, src.getDataPtr()); 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Upload pixels from pixel buffer access. 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \note Stride must be default stride for format. 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid texImage3D (const RenderContext& context, deUint32 target, int level, deUint32 internalFormat, const tcu::ConstPixelBufferAccess& src) 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth()); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch()*src.getHeight()); 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = src.getWidth(); 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = src.getHeight(); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int depth = src.getDepth(); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat format = getTransferFormat(src.getFormat()); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat())); 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format.format, format.dataType, src.getDataPtr()); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Upload pixels from pixel buffer access. 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \note Stride must be default stride for format. 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid texSubImage2D (const RenderContext& context, deUint32 target, int level, int x, int y, const tcu::ConstPixelBufferAccess& src) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(src.getDepth() == 1); 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth()); 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = src.getWidth(); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = src.getHeight(); 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat format = getTransferFormat(src.getFormat()); 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat())); 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texSubImage2D(target, level, x, y, width, height, format.format, format.dataType, src.getDataPtr()); 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Upload pixels from pixel buffer access. 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \note Stride must be default stride for format. 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid texSubImage3D (const RenderContext& context, deUint32 target, int level, int x, int y, int z, const tcu::ConstPixelBufferAccess& src) 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = context.getFunctions(); 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth()); 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch()*src.getHeight()); 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = src.getWidth(); 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = src.getHeight(); 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int depth = src.getDepth(); 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransferFormat format = getTransferFormat(src.getFormat()); 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat())); 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texSubImage3D(target, level, x, y, z, width, height, depth, format.format, format.dataType, src.getDataPtr()); 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // glu 143