xref: /aosp_15_r20/external/deqp/framework/opengl/gluPixelTransfer.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES Utilities
3*35238bceSAndroid Build Coastguard Worker  * ------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief OpenGL ES Pixel Transfer Utilities.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "deMemory.h"
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker namespace glu
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker 
getTransferAlignment(tcu::TextureFormat format)36*35238bceSAndroid Build Coastguard Worker static inline int getTransferAlignment(tcu::TextureFormat format)
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker     int pixelSize = format.getPixelSize();
39*35238bceSAndroid Build Coastguard Worker     if (deIsPowerOfTwo32(pixelSize))
40*35238bceSAndroid Build Coastguard Worker         return de::min(pixelSize, 8);
41*35238bceSAndroid Build Coastguard Worker     else
42*35238bceSAndroid Build Coastguard Worker         return 1;
43*35238bceSAndroid Build Coastguard Worker }
44*35238bceSAndroid Build Coastguard Worker 
45*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
46*35238bceSAndroid Build Coastguard Worker  * \brief Read pixels to pixel buffer access.
47*35238bceSAndroid Build Coastguard Worker  * \note Stride must be default stride for format.
48*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
readPixels(const RenderContext & context,int x,int y,const tcu::PixelBufferAccess & dst)49*35238bceSAndroid Build Coastguard Worker void readPixels(const RenderContext &context, int x, int y, const tcu::PixelBufferAccess &dst)
50*35238bceSAndroid Build Coastguard Worker {
51*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = context.getFunctions();
52*35238bceSAndroid Build Coastguard Worker 
53*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(dst.getDepth() == 1);
54*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(dst.getRowPitch() == dst.getFormat().getPixelSize() * dst.getWidth());
55*35238bceSAndroid Build Coastguard Worker 
56*35238bceSAndroid Build Coastguard Worker     int width             = dst.getWidth();
57*35238bceSAndroid Build Coastguard Worker     int height            = dst.getHeight();
58*35238bceSAndroid Build Coastguard Worker     TransferFormat format = getTransferFormat(dst.getFormat());
59*35238bceSAndroid Build Coastguard Worker 
60*35238bceSAndroid Build Coastguard Worker     gl.pixelStorei(GL_PACK_ALIGNMENT, getTransferAlignment(dst.getFormat()));
61*35238bceSAndroid Build Coastguard Worker     gl.readPixels(x, y, width, height, format.format, format.dataType, dst.getDataPtr());
62*35238bceSAndroid Build Coastguard Worker }
63*35238bceSAndroid Build Coastguard Worker 
64*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
65*35238bceSAndroid Build Coastguard Worker  * \brief Upload pixels from pixel buffer access.
66*35238bceSAndroid Build Coastguard Worker  * \note Stride must be default stride for format.
67*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
texImage2D(const RenderContext & context,uint32_t target,int level,uint32_t internalFormat,const tcu::ConstPixelBufferAccess & src)68*35238bceSAndroid Build Coastguard Worker void texImage2D(const RenderContext &context, uint32_t target, int level, uint32_t internalFormat,
69*35238bceSAndroid Build Coastguard Worker                 const tcu::ConstPixelBufferAccess &src)
70*35238bceSAndroid Build Coastguard Worker {
71*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = context.getFunctions();
72*35238bceSAndroid Build Coastguard Worker 
73*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(src.getDepth() == 1);
74*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize() * src.getWidth());
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker     int width             = src.getWidth();
77*35238bceSAndroid Build Coastguard Worker     int height            = src.getHeight();
78*35238bceSAndroid Build Coastguard Worker     TransferFormat format = getTransferFormat(src.getFormat());
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker     gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
81*35238bceSAndroid Build Coastguard Worker     gl.texImage2D(target, level, internalFormat, width, height, 0, format.format, format.dataType, src.getDataPtr());
82*35238bceSAndroid Build Coastguard Worker }
83*35238bceSAndroid Build Coastguard Worker 
84*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
85*35238bceSAndroid Build Coastguard Worker  * \brief Upload pixels from pixel buffer access.
86*35238bceSAndroid Build Coastguard Worker  * \note Stride must be default stride for format.
87*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
texImage3D(const RenderContext & context,uint32_t target,int level,uint32_t internalFormat,const tcu::ConstPixelBufferAccess & src)88*35238bceSAndroid Build Coastguard Worker void texImage3D(const RenderContext &context, uint32_t target, int level, uint32_t internalFormat,
89*35238bceSAndroid Build Coastguard Worker                 const tcu::ConstPixelBufferAccess &src)
90*35238bceSAndroid Build Coastguard Worker {
91*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = context.getFunctions();
92*35238bceSAndroid Build Coastguard Worker 
93*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize() * src.getWidth());
94*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch() * src.getHeight());
95*35238bceSAndroid Build Coastguard Worker 
96*35238bceSAndroid Build Coastguard Worker     int width             = src.getWidth();
97*35238bceSAndroid Build Coastguard Worker     int height            = src.getHeight();
98*35238bceSAndroid Build Coastguard Worker     int depth             = src.getDepth();
99*35238bceSAndroid Build Coastguard Worker     TransferFormat format = getTransferFormat(src.getFormat());
100*35238bceSAndroid Build Coastguard Worker 
101*35238bceSAndroid Build Coastguard Worker     gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
102*35238bceSAndroid Build Coastguard Worker     gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format.format, format.dataType,
103*35238bceSAndroid Build Coastguard Worker                   src.getDataPtr());
104*35238bceSAndroid Build Coastguard Worker }
105*35238bceSAndroid Build Coastguard Worker 
106*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
107*35238bceSAndroid Build Coastguard Worker  * \brief Upload pixels from pixel buffer access.
108*35238bceSAndroid Build Coastguard Worker  * \note Stride must be default stride for format.
109*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
texSubImage2D(const RenderContext & context,uint32_t target,int level,int x,int y,const tcu::ConstPixelBufferAccess & src)110*35238bceSAndroid Build Coastguard Worker void texSubImage2D(const RenderContext &context, uint32_t target, int level, int x, int y,
111*35238bceSAndroid Build Coastguard Worker                    const tcu::ConstPixelBufferAccess &src)
112*35238bceSAndroid Build Coastguard Worker {
113*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = context.getFunctions();
114*35238bceSAndroid Build Coastguard Worker 
115*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(src.getDepth() == 1);
116*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize() * src.getWidth());
117*35238bceSAndroid Build Coastguard Worker 
118*35238bceSAndroid Build Coastguard Worker     int width             = src.getWidth();
119*35238bceSAndroid Build Coastguard Worker     int height            = src.getHeight();
120*35238bceSAndroid Build Coastguard Worker     TransferFormat format = getTransferFormat(src.getFormat());
121*35238bceSAndroid Build Coastguard Worker 
122*35238bceSAndroid Build Coastguard Worker     gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
123*35238bceSAndroid Build Coastguard Worker     gl.texSubImage2D(target, level, x, y, width, height, format.format, format.dataType, src.getDataPtr());
124*35238bceSAndroid Build Coastguard Worker }
125*35238bceSAndroid Build Coastguard Worker 
126*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
127*35238bceSAndroid Build Coastguard Worker  * \brief Upload pixels from pixel buffer access.
128*35238bceSAndroid Build Coastguard Worker  * \note Stride must be default stride for format.
129*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
texSubImage3D(const RenderContext & context,uint32_t target,int level,int x,int y,int z,const tcu::ConstPixelBufferAccess & src)130*35238bceSAndroid Build Coastguard Worker void texSubImage3D(const RenderContext &context, uint32_t target, int level, int x, int y, int z,
131*35238bceSAndroid Build Coastguard Worker                    const tcu::ConstPixelBufferAccess &src)
132*35238bceSAndroid Build Coastguard Worker {
133*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = context.getFunctions();
134*35238bceSAndroid Build Coastguard Worker 
135*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize() * src.getWidth());
136*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch() * src.getHeight());
137*35238bceSAndroid Build Coastguard Worker 
138*35238bceSAndroid Build Coastguard Worker     int width             = src.getWidth();
139*35238bceSAndroid Build Coastguard Worker     int height            = src.getHeight();
140*35238bceSAndroid Build Coastguard Worker     int depth             = src.getDepth();
141*35238bceSAndroid Build Coastguard Worker     TransferFormat format = getTransferFormat(src.getFormat());
142*35238bceSAndroid Build Coastguard Worker 
143*35238bceSAndroid Build Coastguard Worker     gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
144*35238bceSAndroid Build Coastguard Worker     gl.texSubImage3D(target, level, x, y, z, width, height, depth, format.format, format.dataType, src.getDataPtr());
145*35238bceSAndroid Build Coastguard Worker }
146*35238bceSAndroid Build Coastguard Worker 
147*35238bceSAndroid Build Coastguard Worker } // namespace glu
148