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 OpenGL ES Pixel Transfer Utilities. 22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci#include "gluPixelTransfer.hpp" 25e5c31af7Sopenharmony_ci#include "gluTextureUtil.hpp" 26e5c31af7Sopenharmony_ci#include "gluRenderContext.hpp" 27e5c31af7Sopenharmony_ci#include "glwEnums.hpp" 28e5c31af7Sopenharmony_ci#include "glwFunctions.hpp" 29e5c31af7Sopenharmony_ci#include "tcuTexture.hpp" 30e5c31af7Sopenharmony_ci#include "tcuSurface.hpp" 31e5c31af7Sopenharmony_ci#include "deMemory.h" 32e5c31af7Sopenharmony_ci 33e5c31af7Sopenharmony_cinamespace glu 34e5c31af7Sopenharmony_ci{ 35e5c31af7Sopenharmony_ci 36e5c31af7Sopenharmony_cistatic inline int getTransferAlignment (tcu::TextureFormat format) 37e5c31af7Sopenharmony_ci{ 38e5c31af7Sopenharmony_ci int pixelSize = format.getPixelSize(); 39e5c31af7Sopenharmony_ci if (deIsPowerOfTwo32(pixelSize)) 40e5c31af7Sopenharmony_ci return de::min(pixelSize, 8); 41e5c31af7Sopenharmony_ci else 42e5c31af7Sopenharmony_ci return 1; 43e5c31af7Sopenharmony_ci} 44e5c31af7Sopenharmony_ci 45e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 46e5c31af7Sopenharmony_ci * \brief Read pixels to pixel buffer access. 47e5c31af7Sopenharmony_ci * \note Stride must be default stride for format. 48e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 49e5c31af7Sopenharmony_civoid readPixels (const RenderContext& context, int x, int y, const tcu::PixelBufferAccess& dst) 50e5c31af7Sopenharmony_ci{ 51e5c31af7Sopenharmony_ci const glw::Functions& gl = context.getFunctions(); 52e5c31af7Sopenharmony_ci 53e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(dst.getDepth() == 1); 54e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(dst.getRowPitch() == dst.getFormat().getPixelSize()*dst.getWidth()); 55e5c31af7Sopenharmony_ci 56e5c31af7Sopenharmony_ci int width = dst.getWidth(); 57e5c31af7Sopenharmony_ci int height = dst.getHeight(); 58e5c31af7Sopenharmony_ci TransferFormat format = getTransferFormat(dst.getFormat()); 59e5c31af7Sopenharmony_ci 60e5c31af7Sopenharmony_ci gl.pixelStorei(GL_PACK_ALIGNMENT, getTransferAlignment(dst.getFormat())); 61e5c31af7Sopenharmony_ci gl.readPixels(x, y, width, height, format.format, format.dataType, dst.getDataPtr()); 62e5c31af7Sopenharmony_ci} 63e5c31af7Sopenharmony_ci 64e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 65e5c31af7Sopenharmony_ci * \brief Upload pixels from pixel buffer access. 66e5c31af7Sopenharmony_ci * \note Stride must be default stride for format. 67e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 68e5c31af7Sopenharmony_civoid texImage2D (const RenderContext& context, deUint32 target, int level, deUint32 internalFormat, const tcu::ConstPixelBufferAccess& src) 69e5c31af7Sopenharmony_ci{ 70e5c31af7Sopenharmony_ci const glw::Functions& gl = context.getFunctions(); 71e5c31af7Sopenharmony_ci 72e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(src.getDepth() == 1); 73e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth()); 74e5c31af7Sopenharmony_ci 75e5c31af7Sopenharmony_ci int width = src.getWidth(); 76e5c31af7Sopenharmony_ci int height = src.getHeight(); 77e5c31af7Sopenharmony_ci TransferFormat format = getTransferFormat(src.getFormat()); 78e5c31af7Sopenharmony_ci 79e5c31af7Sopenharmony_ci gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat())); 80e5c31af7Sopenharmony_ci gl.texImage2D(target, level, internalFormat, width, height, 0, format.format, format.dataType, src.getDataPtr()); 81e5c31af7Sopenharmony_ci} 82e5c31af7Sopenharmony_ci 83e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 84e5c31af7Sopenharmony_ci * \brief Upload pixels from pixel buffer access. 85e5c31af7Sopenharmony_ci * \note Stride must be default stride for format. 86e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 87e5c31af7Sopenharmony_civoid texImage3D (const RenderContext& context, deUint32 target, int level, deUint32 internalFormat, const tcu::ConstPixelBufferAccess& src) 88e5c31af7Sopenharmony_ci{ 89e5c31af7Sopenharmony_ci const glw::Functions& gl = context.getFunctions(); 90e5c31af7Sopenharmony_ci 91e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth()); 92e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch()*src.getHeight()); 93e5c31af7Sopenharmony_ci 94e5c31af7Sopenharmony_ci int width = src.getWidth(); 95e5c31af7Sopenharmony_ci int height = src.getHeight(); 96e5c31af7Sopenharmony_ci int depth = src.getDepth(); 97e5c31af7Sopenharmony_ci TransferFormat format = getTransferFormat(src.getFormat()); 98e5c31af7Sopenharmony_ci 99e5c31af7Sopenharmony_ci gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat())); 100e5c31af7Sopenharmony_ci gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format.format, format.dataType, src.getDataPtr()); 101e5c31af7Sopenharmony_ci} 102e5c31af7Sopenharmony_ci 103e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 104e5c31af7Sopenharmony_ci * \brief Upload pixels from pixel buffer access. 105e5c31af7Sopenharmony_ci * \note Stride must be default stride for format. 106e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 107e5c31af7Sopenharmony_civoid texSubImage2D (const RenderContext& context, deUint32 target, int level, int x, int y, const tcu::ConstPixelBufferAccess& src) 108e5c31af7Sopenharmony_ci{ 109e5c31af7Sopenharmony_ci const glw::Functions& gl = context.getFunctions(); 110e5c31af7Sopenharmony_ci 111e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(src.getDepth() == 1); 112e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth()); 113e5c31af7Sopenharmony_ci 114e5c31af7Sopenharmony_ci int width = src.getWidth(); 115e5c31af7Sopenharmony_ci int height = src.getHeight(); 116e5c31af7Sopenharmony_ci TransferFormat format = getTransferFormat(src.getFormat()); 117e5c31af7Sopenharmony_ci 118e5c31af7Sopenharmony_ci gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat())); 119e5c31af7Sopenharmony_ci gl.texSubImage2D(target, level, x, y, width, height, format.format, format.dataType, src.getDataPtr()); 120e5c31af7Sopenharmony_ci} 121e5c31af7Sopenharmony_ci 122e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 123e5c31af7Sopenharmony_ci * \brief Upload pixels from pixel buffer access. 124e5c31af7Sopenharmony_ci * \note Stride must be default stride for format. 125e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 126e5c31af7Sopenharmony_civoid texSubImage3D (const RenderContext& context, deUint32 target, int level, int x, int y, int z, const tcu::ConstPixelBufferAccess& src) 127e5c31af7Sopenharmony_ci{ 128e5c31af7Sopenharmony_ci const glw::Functions& gl = context.getFunctions(); 129e5c31af7Sopenharmony_ci 130e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth()); 131e5c31af7Sopenharmony_ci TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch()*src.getHeight()); 132e5c31af7Sopenharmony_ci 133e5c31af7Sopenharmony_ci int width = src.getWidth(); 134e5c31af7Sopenharmony_ci int height = src.getHeight(); 135e5c31af7Sopenharmony_ci int depth = src.getDepth(); 136e5c31af7Sopenharmony_ci TransferFormat format = getTransferFormat(src.getFormat()); 137e5c31af7Sopenharmony_ci 138e5c31af7Sopenharmony_ci gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat())); 139e5c31af7Sopenharmony_ci gl.texSubImage3D(target, level, x, y, z, width, height, depth, format.format, format.dataType, src.getDataPtr()); 140e5c31af7Sopenharmony_ci} 141e5c31af7Sopenharmony_ci 142e5c31af7Sopenharmony_ci} // glu 143