Home | History | Annotate | Download | only in opengl
      1 #ifndef _GLUTEXTURE_HPP
      2 #define _GLUTEXTURE_HPP
      3 /*-------------------------------------------------------------------------
      4  * drawElements Quality Program OpenGL ES Utilities
      5  * ------------------------------------------------
      6  *
      7  * Copyright 2014 The Android Open Source Project
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*!
     22  * \file
     23  * \brief Texture classes.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "gluDefs.hpp"
     27 #include "tcuTexture.hpp"
     28 #include "tcuCompressedTexture.hpp"
     29 #include "tcuResource.hpp"
     30 #include "gluRenderContext.hpp"
     31 #include "gluContextInfo.hpp"
     32 
     33 #include <vector>
     34 #include <string>
     35 
     36 namespace glu
     37 {
     38 
     39 /*--------------------------------------------------------------------*//*!
     40  * \brief 1D Texture only supported on OpenGL
     41  *//*--------------------------------------------------------------------*/
     42 class Texture1D
     43 {
     44 public:
     45 							Texture1D				(const RenderContext& context, deUint32 format, deUint32 dataType, int width);
     46 							Texture1D				(const RenderContext& context, deUint32 internalFormat, int width);
     47 							~Texture1D				(void);
     48 
     49 	tcu::Texture1D&			getRefTexture			(void)			{ return m_refTexture;	}
     50 	const tcu::Texture1D&	getRefTexture			(void) const	{ return m_refTexture;	}
     51 	deUint32				getGLTexture			(void) const	{ return m_glTexture;	}
     52 
     53 	void					upload					(void);
     54 
     55 private:
     56 							Texture1D				(const Texture1D& other); // Not allowed!
     57 	Texture1D&				operator=				(const Texture1D& other); // Not allowed!
     58 
     59 	const RenderContext&	m_context;
     60 	deUint32				m_format;				//!< Internal format.
     61 	tcu::Texture1D			m_refTexture;
     62 	deUint32				m_glTexture;
     63 };
     64 
     65 /*--------------------------------------------------------------------*//*!
     66  * \brief 2D Texture
     67  *//*--------------------------------------------------------------------*/
     68 class Texture2D
     69 {
     70 public:
     71 							Texture2D				(const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams& = tcu::CompressedTexture::DecompressionParams(false));
     72 							Texture2D				(const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height);
     73 							Texture2D				(const RenderContext& context, deUint32 internalFormat, int width, int height);
     74 							~Texture2D				(void);
     75 
     76 	void					upload					(void); // Not supported on compressed textures.
     77 
     78 	tcu::Texture2D&			getRefTexture			(void)			{ return m_refTexture;	}
     79 	const tcu::Texture2D&	getRefTexture			(void) const	{ return m_refTexture;	}
     80 	deUint32				getGLTexture			(void) const	{ return m_glTexture;	}
     81 
     82 	static Texture2D*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const std::vector<std::string>& filenames);
     83 	static Texture2D*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const char* const* filenames);
     84 	static Texture2D*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, const char* filename) { return create(context, contextInfo, archive, 1, &filename); }
     85 
     86 private:
     87 							Texture2D				(const Texture2D& other); // Not allowed!
     88 	Texture2D&				operator=				(const Texture2D& other); // Not allowed!
     89 
     90 	void					loadCompressed			(int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams&);
     91 
     92 	const RenderContext&	m_context;
     93 
     94 	bool					m_isCompressed;
     95 	deUint32				m_format;				//!< Internal format.
     96 
     97 	tcu::Texture2D			m_refTexture;
     98 	deUint32				m_glTexture;
     99 };
    100 
    101 /*--------------------------------------------------------------------*//*!
    102  * \brief Cube Map Texture
    103  *//*--------------------------------------------------------------------*/
    104 class TextureCube
    105 {
    106 public:
    107 	// For compressed cubemap constructor and create() function input level pointers / filenames are expected
    108 	// to laid out to array in following order:
    109 	//   { l0_neg_x, l0_pos_x, l0_neg_y, l0_pos_y, l0_neg_z, l0_pos_z, l1_neg_x, l1_pos_x, ... }
    110 
    111 							TextureCube				(const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams& = tcu::CompressedTexture::DecompressionParams(false));
    112 							TextureCube				(const RenderContext& context, deUint32 format, deUint32 dataType, int size);
    113 							TextureCube				(const RenderContext& context, deUint32 internalFormat, int size);
    114 							~TextureCube			(void);
    115 
    116 	void					upload					(void); // Not supported on compressed textures.
    117 
    118 	tcu::TextureCube&		getRefTexture			(void)			{ return m_refTexture;	}
    119 	const tcu::TextureCube&	getRefTexture			(void) const	{ return m_refTexture;	}
    120 	deUint32				getGLTexture			(void) const	{ return m_glTexture;	}
    121 
    122 	static TextureCube*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const std::vector<std::string>& filenames);
    123 	static TextureCube*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const char* const* filenames);
    124 
    125 private:
    126 							TextureCube				(const TextureCube& other); // Not allowed!
    127 	TextureCube&			operator=				(const TextureCube& other); // Not allowed!
    128 
    129 	void					loadCompressed			(int numLevels, const tcu::CompressedTexture* levels, const tcu::CompressedTexture::DecompressionParams&);
    130 
    131 	const RenderContext&	m_context;
    132 
    133 	bool					m_isCompressed;
    134 	deUint32				m_format;				//!< Internal format.
    135 
    136 	tcu::TextureCube		m_refTexture;
    137 	deUint32				m_glTexture;
    138 };
    139 
    140 /*--------------------------------------------------------------------*//*!
    141  * \brief 2D Array Texture
    142  * \note Not supported on OpenGL ES 2
    143  *//*--------------------------------------------------------------------*/
    144 class Texture2DArray
    145 {
    146 public:
    147 								Texture2DArray			(const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int numLayers);
    148 								Texture2DArray			(const RenderContext& context, deUint32 internalFormat, int width, int height, int numLayers);
    149 								~Texture2DArray			(void);
    150 
    151 	void						upload					(void);
    152 
    153 	tcu::Texture2DArray&		getRefTexture			(void)			{ return m_refTexture;	}
    154 	const tcu::Texture2DArray&	getRefTexture			(void) const	{ return m_refTexture;	}
    155 	deUint32					getGLTexture			(void) const	{ return m_glTexture;	}
    156 
    157 private:
    158 								Texture2DArray			(const Texture2DArray& other); // Not allowed!
    159 	Texture2DArray&				operator=				(const Texture2DArray& other); // Not allowed!
    160 
    161 	const RenderContext&		m_context;
    162 
    163 	deUint32					m_format;				//!< Internal format.
    164 
    165 	tcu::Texture2DArray			m_refTexture;
    166 	deUint32					m_glTexture;
    167 };
    168 
    169 /*--------------------------------------------------------------------*//*!
    170  * \brief 1D Array Texture
    171  * \note Only supported on OpenGL
    172  *//*--------------------------------------------------------------------*/
    173 class Texture1DArray
    174 {
    175 public:
    176 								Texture1DArray			(const RenderContext& context, deUint32 format, deUint32 dataType, int width, int numLayers);
    177 								Texture1DArray			(const RenderContext& context, deUint32 internalFormat, int width, int numLayers);
    178 								~Texture1DArray			(void);
    179 
    180 	void						upload					(void);
    181 
    182 	tcu::Texture1DArray&		getRefTexture			(void)			{ return m_refTexture;	}
    183 	const tcu::Texture1DArray&	getRefTexture			(void) const	{ return m_refTexture;	}
    184 	deUint32					getGLTexture			(void) const	{ return m_glTexture;	}
    185 
    186 private:
    187 								Texture1DArray			(const Texture1DArray& other); // Not allowed!
    188 	Texture1DArray&				operator=				(const Texture1DArray& other); // Not allowed!
    189 
    190 	const RenderContext&		m_context;
    191 
    192 	deUint32					m_format;				//!< Internal format.
    193 
    194 	tcu::Texture1DArray			m_refTexture;
    195 	deUint32					m_glTexture;
    196 };
    197 
    198 /*--------------------------------------------------------------------*//*!
    199  * \brief 3D Texture
    200  * \note Not supported on OpenGL ES 2
    201  *//*--------------------------------------------------------------------*/
    202 class Texture3D
    203 {
    204 public:
    205 								Texture3D			(const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int depth);
    206 								Texture3D			(const RenderContext& context, deUint32 internalFormat, int width, int height, int depth);
    207 								~Texture3D			(void);
    208 
    209 	void						upload				(void);
    210 
    211 	tcu::Texture3D&				getRefTexture		(void)			{ return m_refTexture;	}
    212 	const tcu::Texture3D&		getRefTexture		(void) const	{ return m_refTexture;	}
    213 	deUint32					getGLTexture		(void) const	{ return m_glTexture;	}
    214 
    215 private:
    216 								Texture3D			(const Texture3D& other); // Not allowed!
    217 	Texture3D&					operator=			(const Texture3D& other); // Not allowed!
    218 
    219 	const RenderContext&		m_context;
    220 
    221 	deUint32					m_format;			//!< Internal format.
    222 
    223 	tcu::Texture3D				m_refTexture;
    224 	deUint32					m_glTexture;
    225 };
    226 
    227 /*--------------------------------------------------------------------*//*!
    228  * \brief Cube Map Array Texture
    229  * \note Not supported on OpenGL ES 3.0 or lower
    230  *//*--------------------------------------------------------------------*/
    231 class TextureCubeArray
    232 {
    233 public:
    234 									TextureCubeArray	(const RenderContext& context, deUint32 format, deUint32 dataType, int size, int numLayers);
    235 									TextureCubeArray	(const RenderContext& context, deUint32 internalFormat, int size, int numLayers);
    236 									~TextureCubeArray	(void);
    237 
    238 	void							upload				(void);
    239 
    240 	tcu::TextureCubeArray&			getRefTexture		(void)			{ return m_refTexture;	}
    241 	const tcu::TextureCubeArray&	getRefTexture		(void) const	{ return m_refTexture;	}
    242 	deUint32						getGLTexture		(void) const	{ return m_glTexture;	}
    243 
    244 private:
    245 									TextureCubeArray	(const TextureCubeArray& other); // Not allowed!
    246 	TextureCubeArray&				operator=			(const TextureCubeArray& other); // Not allowed!
    247 
    248 	const RenderContext&			m_context;
    249 
    250 	deUint32						m_format;			//!< Internal format.
    251 
    252 	tcu::TextureCubeArray			m_refTexture;
    253 	deUint32						m_glTexture;
    254 };
    255 
    256 /*--------------------------------------------------------------------*//*!
    257  * \brief 1D Texture Buffer only supported on OpenGL
    258  *//*--------------------------------------------------------------------*/
    259 class TextureBuffer
    260 {
    261 public:
    262 										TextureBuffer		(const RenderContext& context, deUint32 internalFormat, size_t bufferSize);
    263 										TextureBuffer		(const RenderContext& context, deUint32 internalFormat, size_t bufferSize, size_t offset, size_t size, const void* data = DE_NULL);
    264 
    265 										~TextureBuffer		(void);
    266 
    267 	const tcu::PixelBufferAccess&		getRefTexture		(void)			{ return m_refTexture;			}
    268 	const tcu::ConstPixelBufferAccess&	getRefTexture		(void) const	{ return m_refTexture;			}
    269 
    270 	deUint8*							getRefBuffer		(void)			{ return &(m_refBuffer[0]);		}
    271 	const deUint8*						getRefBuffer		(void) const	{ return &(m_refBuffer[0]);		}
    272 
    273 	size_t								getSize				(void) const	{ return m_size;				}
    274 	size_t								getOffset			(void) const	{ return m_offset;				}
    275 	size_t								getBufferSize		(void) const	{ return m_refBuffer.size();	}
    276 
    277 	deUint32							getGLTexture		(void) const	{ return m_glTexture;			}
    278 	deUint32							getGLBuffer			(void) const	{ return m_glBuffer;			}
    279 
    280 	// \note Resizes reference buffer. Invalidates old pixel buffer acceses.
    281 	// \note Doesn't upload data.
    282 	void								bufferData			(const deUint8* data, size_t size);
    283 	void								upload				(void);
    284 
    285 private:
    286 	void					init					(deUint32 internalFormat, size_t bufferSize, size_t offset, size_t size, const void* data);
    287 							TextureBuffer			(const TextureBuffer& other); // Not allowed!
    288 	TextureBuffer&			operator=				(const TextureBuffer& other); // Not allowed!
    289 
    290 	const RenderContext&	m_context;
    291 	deUint32				m_format;		//!< Internal format.
    292 	std::vector<deUint8>	m_refBuffer;
    293 	size_t					m_offset;
    294 	size_t					m_size;
    295 
    296 	tcu::PixelBufferAccess	m_refTexture;
    297 	deUint32				m_glTexture;
    298 	deUint32				m_glBuffer;
    299 };
    300 
    301 } // glu
    302 
    303 #endif // _GLUTEXTURE_HPP
    304