• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES Utilities
3  * ------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  *//*!
20  * \file
21  * \brief OpenGL ES Pixel Transfer Utilities.
22  *//*--------------------------------------------------------------------*/
23 
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"
31 #include "deMemory.h"
32 
33 namespace glu
34 {
35 
getTransferAlignment(tcu::TextureFormat format)36 static inline int getTransferAlignment (tcu::TextureFormat format)
37 {
38 	int pixelSize = format.getPixelSize();
39 	if (deIsPowerOfTwo32(pixelSize))
40 		return de::min(pixelSize, 8);
41 	else
42 		return 1;
43 }
44 
45 /*--------------------------------------------------------------------*//*!
46  * \brief Read pixels to pixel buffer access.
47  * \note Stride must be default stride for format.
48  *//*--------------------------------------------------------------------*/
readPixels(const RenderContext & context,int x,int y,const tcu::PixelBufferAccess & dst)49 void readPixels (const RenderContext& context, int x, int y, const tcu::PixelBufferAccess& dst)
50 {
51 	const glw::Functions& gl = context.getFunctions();
52 
53 	TCU_CHECK_INTERNAL(dst.getDepth() == 1);
54 	TCU_CHECK_INTERNAL(dst.getRowPitch() == dst.getFormat().getPixelSize()*dst.getWidth());
55 
56 	int				width		= dst.getWidth();
57 	int				height		= dst.getHeight();
58 	TransferFormat	format		= getTransferFormat(dst.getFormat());
59 
60 	gl.pixelStorei(GL_PACK_ALIGNMENT, getTransferAlignment(dst.getFormat()));
61 	gl.readPixels(x, y, width, height, format.format, format.dataType, dst.getDataPtr());
62 }
63 
64 /*--------------------------------------------------------------------*//*!
65  * \brief Upload pixels from pixel buffer access.
66  * \note Stride must be default stride for format.
67  *//*--------------------------------------------------------------------*/
texImage2D(const RenderContext & context,deUint32 target,int level,deUint32 internalFormat,const tcu::ConstPixelBufferAccess & src)68 void texImage2D (const RenderContext& context, deUint32 target, int level, deUint32 internalFormat, const tcu::ConstPixelBufferAccess& src)
69 {
70 	const glw::Functions& gl = context.getFunctions();
71 
72 	TCU_CHECK_INTERNAL(src.getDepth() == 1);
73 	TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth());
74 
75 	int				width		= src.getWidth();
76 	int				height		= src.getHeight();
77 	TransferFormat	format		= getTransferFormat(src.getFormat());
78 
79 	gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
80 	gl.texImage2D(target, level, internalFormat, width, height, 0, format.format, format.dataType, src.getDataPtr());
81 }
82 
83 /*--------------------------------------------------------------------*//*!
84  * \brief Upload pixels from pixel buffer access.
85  * \note Stride must be default stride for format.
86  *//*--------------------------------------------------------------------*/
texImage3D(const RenderContext & context,deUint32 target,int level,deUint32 internalFormat,const tcu::ConstPixelBufferAccess & src)87 void texImage3D (const RenderContext& context, deUint32 target, int level, deUint32 internalFormat, const tcu::ConstPixelBufferAccess& src)
88 {
89 	const glw::Functions& gl = context.getFunctions();
90 
91 	TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth());
92 	TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch()*src.getHeight());
93 
94 	int				width		= src.getWidth();
95 	int				height		= src.getHeight();
96 	int				depth		= src.getDepth();
97 	TransferFormat	format		= getTransferFormat(src.getFormat());
98 
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());
101 }
102 
103 /*--------------------------------------------------------------------*//*!
104  * \brief Upload pixels from pixel buffer access.
105  * \note Stride must be default stride for format.
106  *//*--------------------------------------------------------------------*/
texSubImage2D(const RenderContext & context,deUint32 target,int level,int x,int y,const tcu::ConstPixelBufferAccess & src)107 void texSubImage2D (const RenderContext& context, deUint32 target, int level, int x, int y, const tcu::ConstPixelBufferAccess& src)
108 {
109 	const glw::Functions& gl = context.getFunctions();
110 
111 	TCU_CHECK_INTERNAL(src.getDepth() == 1);
112 	TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth());
113 
114 	int				width		= src.getWidth();
115 	int				height		= src.getHeight();
116 	TransferFormat	format		= getTransferFormat(src.getFormat());
117 
118 	gl.pixelStorei(GL_UNPACK_ALIGNMENT, getTransferAlignment(src.getFormat()));
119 	gl.texSubImage2D(target, level, x, y, width, height, format.format, format.dataType, src.getDataPtr());
120 }
121 
122 /*--------------------------------------------------------------------*//*!
123  * \brief Upload pixels from pixel buffer access.
124  * \note Stride must be default stride for format.
125  *//*--------------------------------------------------------------------*/
texSubImage3D(const RenderContext & context,deUint32 target,int level,int x,int y,int z,const tcu::ConstPixelBufferAccess & src)126 void texSubImage3D (const RenderContext& context, deUint32 target, int level, int x, int y, int z, const tcu::ConstPixelBufferAccess& src)
127 {
128 	const glw::Functions& gl = context.getFunctions();
129 
130 	TCU_CHECK_INTERNAL(src.getRowPitch() == src.getFormat().getPixelSize()*src.getWidth());
131 	TCU_CHECK_INTERNAL(src.getSlicePitch() == src.getRowPitch()*src.getHeight());
132 
133 	int				width		= src.getWidth();
134 	int				height		= src.getHeight();
135 	int				depth		= src.getDepth();
136 	TransferFormat	format		= getTransferFormat(src.getFormat());
137 
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());
140 }
141 
142 } // glu
143