1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES Utilities
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 OpenGL ES Pixel Transfer Utilities.
22 *//*--------------------------------------------------------------------*/
24 #include "gluPixelTransfer.hpp"
25 #include "gluTextureUtil.hpp"
26 #include "gluRenderContext.hpp"
27 #include "glwEnums.hpp"
28 #include "glwFunctions.hpp"
29 #include "tcuTexture.hpp"
30 #include "tcuSurface.hpp"
36 static inline int getTransferAlignment (tcu::TextureFormat format)
38 int pixelSize = format.getPixelSize();
39 if (deIsPowerOfTwo32(pixelSize))
40 return de::min(pixelSize, 8);
45 /*--------------------------------------------------------------------*//*!
46 * \brief Read pixels to pixel buffer access.
47 * \note Stride must be default stride for format.
48 *//*--------------------------------------------------------------------*/
49 void readPixels (const RenderContext& context, int x, int y, const tcu::PixelBufferAccess& dst)
51 const glw::Functions& gl = context.getFunctions();
53 TCU_CHECK_INTERNAL(dst.getDepth() == 1);
54 TCU_CHECK_INTERNAL(dst.getRowPitch() == dst.getFormat().getPixelSize()*dst.getWidth());
56 int width = dst.getWidth();
57 int height = dst.getHeight();
58 TransferFormat format = getTransferFormat(dst.getFormat());
60 gl.pixelStorei(GL_PACK_ALIGNMENT, getTransferAlignment(dst.getFormat()));
61 gl.readPixels(x, y, width, height, format.format, format.dataType, dst.getDataPtr());
64 /*--------------------------------------------------------------------*//*!
65 * \brief Upload pixels from pixel buffer access.
66 * \note Stride must be default stride for format.
67 *//*--------------------------------------------------------------------*/
68 void texImage2D (const RenderContext& context, deUint32 target, int level, deUint32 internalFormat, const tcu::ConstPixelBufferAccess& src)
70 const glw::Functions& gl = context.getFunctions();
72 TCU_CHECK_INTERNAL(src.getDepth() == 1);
73 TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth());
75 int width = src.getWidth();
76 int height = src.getHeight();
77 TransferFormat format = getTransferFormat(src.getFormat());
79 gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
80 gl.texImage2D(target, level, internalFormat, width, height, 0, format.format, format.dataType, src.getDataPtr());
83 /*--------------------------------------------------------------------*//*!
84 * \brief Upload pixels from pixel buffer access.
85 * \note Stride must be default stride for format.
86 *//*--------------------------------------------------------------------*/
87 void texImage3D (const RenderContext& context, deUint32 target, int level, deUint32 internalFormat, const tcu::ConstPixelBufferAccess& src)
89 const glw::Functions& gl = context.getFunctions();
91 TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth());
92 TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch()*src.getHeight());
94 int width = src.getWidth();
95 int height = src.getHeight();
96 int depth = src.getDepth();
97 TransferFormat format = getTransferFormat(src.getFormat());
99 gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
100 gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format.format, format.dataType, src.getDataPtr());
103 /*--------------------------------------------------------------------*//*!
104 * \brief Upload pixels from pixel buffer access.
105 * \note Stride must be default stride for format.
106 *//*--------------------------------------------------------------------*/
107 void texSubImage2D (const RenderContext& context, deUint32 target, int level, int x, int y, const tcu::ConstPixelBufferAccess& src)
109 const glw::Functions& gl = context.getFunctions();
111 TCU_CHECK_INTERNAL(src.getDepth() == 1);
112 TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth());
114 int width = src.getWidth();
115 int height = src.getHeight();
116 TransferFormat format = getTransferFormat(src.getFormat());
118 gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
119 gl.texSubImage2D(target, level, x, y, width, height, format.format, format.dataType, src.getDataPtr());
122 /*--------------------------------------------------------------------*//*!
123 * \brief Upload pixels from pixel buffer access.
124 * \note Stride must be default stride for format.
125 *//*--------------------------------------------------------------------*/
126 void texSubImage3D (const RenderContext& context, deUint32 target, int level, int x, int y, int z, const tcu::ConstPixelBufferAccess& src)
128 const glw::Functions& gl = context.getFunctions();
130 TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth());
131 TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch()*src.getHeight());
133 int width = src.getWidth();
134 int height = src.getHeight();
135 int depth = src.getDepth();
136 TransferFormat format = getTransferFormat(src.getFormat());
138 gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
139 gl.texSubImage3D(target, level, x, y, z, width, height, depth, format.format, format.dataType, src.getDataPtr());