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 #include "deArrayBuffer.hpp"
     33 
     34 #include <vector>
     35 #include <string>
     36 
     37 namespace glu
     38 {
     39 
     40 /*--------------------------------------------------------------------*//*!
     41  * \brief 1D Texture only supported on OpenGL
     42  *//*--------------------------------------------------------------------*/
     43 class Texture1D
     44 {
     45 public:
     46 							Texture1D				(const RenderContext& context, deUint32 format, deUint32 dataType, int width);
     47 							Texture1D				(const RenderContext& context, deUint32 internalFormat, int width);
     48 							~Texture1D				(void);
     49 
     50 	tcu::Texture1D&			getRefTexture			(void)			{ return m_refTexture;	}
     51 	const tcu::Texture1D&	getRefTexture			(void) const	{ return m_refTexture;	}
     52 	deUint32				getGLTexture			(void) const	{ return m_glTexture;	}
     53 
     54 	void					upload					(void);
     55 
     56 private:
     57 							Texture1D				(const Texture1D& other); // Not allowed!
     58 	Texture1D&				operator=				(const Texture1D& other); // Not allowed!
     59 
     60 	const RenderContext&	m_context;
     61 	deUint32				m_format;				//!< Internal format.
     62 	tcu::Texture1D			m_refTexture;
     63 	deUint32				m_glTexture;
     64 } DE_WARN_UNUSED_TYPE;
     65 
     66 /*--------------------------------------------------------------------*//*!
     67  * \brief 2D Texture
     68  *//*--------------------------------------------------------------------*/
     69 class Texture2D
     70 {
     71 public:
     72 							Texture2D				(const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams());
     73 							Texture2D				(const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height);
     74 							Texture2D				(const RenderContext& context, deUint32 internalFormat, int width, int height);
     75 	virtual					~Texture2D				(void);
     76 
     77 	virtual void			upload					(void); // Not supported on compressed textures.
     78 
     79 	tcu::Texture2D&			getRefTexture			(void)			{ return m_refTexture;	}
     80 	const tcu::Texture2D&	getRefTexture			(void) const	{ return m_refTexture;	}
     81 	deUint32				getGLTexture			(void) const	{ return m_glTexture;	}
     82 
     83 	static Texture2D*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const std::vector<std::string>& filenames);
     84 	static Texture2D*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const char* const* filenames);
     85 	static Texture2D*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, const char* filename) { return create(context, contextInfo, archive, 1, &filename); }
     86 
     87 protected:
     88 	const RenderContext&	m_context;
     89 
     90 	bool					m_isCompressed;
     91 	deUint32				m_format;               //!< Internal format.
     92 	tcu::Texture2D			m_refTexture;
     93 
     94 	deUint32				m_glTexture;
     95 
     96 private:
     97 							Texture2D				(const Texture2D& other); // Not allowed!
     98 	Texture2D&				operator=				(const Texture2D& other); // Not allowed!
     99 
    100 	void					loadCompressed			(int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams);
    101 } DE_WARN_UNUSED_TYPE;
    102 
    103 class ImmutableTexture2D : public Texture2D
    104 {
    105 public:
    106 							ImmutableTexture2D		(const RenderContext& context, deUint32 internalFormat, int width, int height);
    107 
    108 	void					upload					(void); // Not supported on compressed textures.
    109 
    110 private:
    111 							ImmutableTexture2D		(const ImmutableTexture2D& other); // Not allowed!
    112 	ImmutableTexture2D&		operator=				(const ImmutableTexture2D& other); // Not allowed!
    113 };
    114 
    115 /*--------------------------------------------------------------------*//*!
    116  * \brief Cube Map Texture
    117  *//*--------------------------------------------------------------------*/
    118 class TextureCube
    119 {
    120 public:
    121 	// For compressed cubemap constructor and create() function input level pointers / filenames are expected
    122 	// to laid out to array in following order:
    123 	//   { l0_neg_x, l0_pos_x, l0_neg_y, l0_pos_y, l0_neg_z, l0_pos_z, l1_neg_x, l1_pos_x, ... }
    124 
    125 							TextureCube				(const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams());
    126 							TextureCube				(const RenderContext& context, deUint32 format, deUint32 dataType, int size);
    127 							TextureCube				(const RenderContext& context, deUint32 internalFormat, int size);
    128 							~TextureCube			(void);
    129 
    130 	void					upload					(void); // Not supported on compressed textures.
    131 
    132 	tcu::TextureCube&		getRefTexture			(void)			{ return m_refTexture;	}
    133 	const tcu::TextureCube&	getRefTexture			(void) const	{ return m_refTexture;	}
    134 	deUint32				getGLTexture			(void) const	{ return m_glTexture;	}
    135 
    136 	static TextureCube*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const std::vector<std::string>& filenames);
    137 	static TextureCube*		create					(const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const char* const* filenames);
    138 
    139 private:
    140 							TextureCube				(const TextureCube& other); // Not allowed!
    141 	TextureCube&			operator=				(const TextureCube& other); // Not allowed!
    142 
    143 	void					loadCompressed			(int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams);
    144 
    145 	const RenderContext&	m_context;
    146 
    147 	bool					m_isCompressed;
    148 	deUint32				m_format;				//!< Internal format.
    149 
    150 	tcu::TextureCube		m_refTexture;
    151 	deUint32				m_glTexture;
    152 } DE_WARN_UNUSED_TYPE;
    153 
    154 /*--------------------------------------------------------------------*//*!
    155  * \brief 2D Array Texture
    156  * \note Not supported on OpenGL ES 2
    157  *//*--------------------------------------------------------------------*/
    158 class Texture2DArray
    159 {
    160 public:
    161 								Texture2DArray			(const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int numLayers);
    162 								Texture2DArray			(const RenderContext& context, deUint32 internalFormat, int width, int height, int numLayers);
    163 								Texture2DArray			(const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams());
    164 								~Texture2DArray			(void);
    165 
    166 	void						upload					(void);
    167 
    168 	tcu::Texture2DArray&		getRefTexture			(void)			{ return m_refTexture;	}
    169 	const tcu::Texture2DArray&	getRefTexture			(void) const	{ return m_refTexture;	}
    170 	deUint32					getGLTexture			(void) const	{ return m_glTexture;	}
    171 
    172 private:
    173 								Texture2DArray			(const Texture2DArray& other); // Not allowed!
    174 	Texture2DArray&				operator=				(const Texture2DArray& other); // Not allowed!
    175 
    176 	void						loadCompressed			(int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams);
    177 
    178 
    179 	const RenderContext&		m_context;
    180 
    181 	bool						m_isCompressed;
    182 	deUint32					m_format;				//!< Internal format.
    183 
    184 	tcu::Texture2DArray			m_refTexture;
    185 	deUint32					m_glTexture;
    186 } DE_WARN_UNUSED_TYPE;
    187 
    188 /*--------------------------------------------------------------------*//*!
    189  * \brief 1D Array Texture
    190  * \note Only supported on OpenGL
    191  *//*--------------------------------------------------------------------*/
    192 class Texture1DArray
    193 {
    194 public:
    195 								Texture1DArray			(const RenderContext& context, deUint32 format, deUint32 dataType, int width, int numLayers);
    196 								Texture1DArray			(const RenderContext& context, deUint32 internalFormat, int width, int numLayers);
    197 								~Texture1DArray			(void);
    198 
    199 	void						upload					(void);
    200 
    201 	tcu::Texture1DArray&		getRefTexture			(void)			{ return m_refTexture;	}
    202 	const tcu::Texture1DArray&	getRefTexture			(void) const	{ return m_refTexture;	}
    203 	deUint32					getGLTexture			(void) const	{ return m_glTexture;	}
    204 
    205 private:
    206 								Texture1DArray			(const Texture1DArray& other); // Not allowed!
    207 	Texture1DArray&				operator=				(const Texture1DArray& other); // Not allowed!
    208 
    209 	const RenderContext&		m_context;
    210 
    211 	deUint32					m_format;				//!< Internal format.
    212 
    213 	tcu::Texture1DArray			m_refTexture;
    214 	deUint32					m_glTexture;
    215 } DE_WARN_UNUSED_TYPE;
    216 
    217 /*--------------------------------------------------------------------*//*!
    218  * \brief 3D Texture
    219  * \note Not supported on OpenGL ES 2
    220  *//*--------------------------------------------------------------------*/
    221 class Texture3D
    222 {
    223 public:
    224 								Texture3D			(const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int depth);
    225 								Texture3D			(const RenderContext& context, deUint32 internalFormat, int width, int height, int depth);
    226 								Texture3D			(const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams());
    227 								~Texture3D			(void);
    228 
    229 	void						upload				(void);
    230 
    231 	tcu::Texture3D&				getRefTexture		(void)			{ return m_refTexture;	}
    232 	const tcu::Texture3D&		getRefTexture		(void) const	{ return m_refTexture;	}
    233 	deUint32					getGLTexture		(void) const	{ return m_glTexture;	}
    234 
    235 private:
    236 								Texture3D			(const Texture3D& other); // Not allowed!
    237 	Texture3D&					operator=			(const Texture3D& other); // Not allowed!
    238 
    239 	void						loadCompressed		(int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams);
    240 
    241 	const RenderContext&		m_context;
    242 
    243 	bool						m_isCompressed;
    244 	deUint32					m_format;			//!< Internal format.
    245 
    246 	tcu::Texture3D				m_refTexture;
    247 	deUint32					m_glTexture;
    248 } DE_WARN_UNUSED_TYPE;
    249 
    250 /*--------------------------------------------------------------------*//*!
    251  * \brief Cube Map Array Texture
    252  * \note Not supported on OpenGL ES 3.0 or lower
    253  *//*--------------------------------------------------------------------*/
    254 class TextureCubeArray
    255 {
    256 public:
    257 									TextureCubeArray	(const RenderContext& context, deUint32 format, deUint32 dataType, int size, int numLayers);
    258 									TextureCubeArray	(const RenderContext& context, deUint32 internalFormat, int size, int numLayers);
    259 
    260 									~TextureCubeArray	(void);
    261 
    262 	void							upload				(void);
    263 
    264 	tcu::TextureCubeArray&			getRefTexture		(void)			{ return m_refTexture;	}
    265 	const tcu::TextureCubeArray&	getRefTexture		(void) const	{ return m_refTexture;	}
    266 	deUint32						getGLTexture		(void) const	{ return m_glTexture;	}
    267 
    268 private:
    269 									TextureCubeArray	(const TextureCubeArray& other); // Not allowed!
    270 	TextureCubeArray&				operator=			(const TextureCubeArray& other); // Not allowed!
    271 
    272 	const RenderContext&			m_context;
    273 
    274 	bool							m_isCompressed;
    275 	deUint32						m_format;			//!< Internal format.
    276 
    277 	tcu::TextureCubeArray			m_refTexture;
    278 	deUint32						m_glTexture;
    279 } DE_WARN_UNUSED_TYPE;
    280 
    281 /*--------------------------------------------------------------------*//*!
    282  * \brief 1D Texture Buffer only supported on OpenGL
    283  *//*--------------------------------------------------------------------*/
    284 class TextureBuffer
    285 {
    286 public:
    287 										TextureBuffer		(const RenderContext& context, deUint32 internalFormat, size_t bufferSize);
    288 										TextureBuffer		(const RenderContext& context, deUint32 internalFormat, size_t bufferSize, size_t offset, size_t size, const void* data = DE_NULL);
    289 
    290 										~TextureBuffer		(void);
    291 
    292 	// \note Effective pixel buffer access must be limited to w <= GL_MAX_TEXTURE_BUFFER_SIZE
    293 	const tcu::PixelBufferAccess		getFullRefTexture	(void);
    294 	const tcu::ConstPixelBufferAccess	getFullRefTexture	(void) const;
    295 
    296 	// \note mutating buffer storage will invalidate existing pixel buffer accesses
    297 	de::ArrayBuffer<deUint8>&			getRefBuffer		(void)			{ return m_refBuffer;			}
    298 	const de::ArrayBuffer<deUint8>&		getRefBuffer		(void) const	{ return m_refBuffer;			}
    299 
    300 	size_t								getSize				(void) const	{ return m_size;				}
    301 	size_t								getOffset			(void) const	{ return m_offset;				}
    302 	size_t								getBufferSize		(void) const	{ return m_refBuffer.size();	}
    303 
    304 	deUint32							getGLTexture		(void) const	{ return m_glTexture;			}
    305 	deUint32							getGLBuffer			(void) const	{ return m_glBuffer;			}
    306 
    307 	void								upload				(void);
    308 
    309 private:
    310 	void								init				(deUint32 internalFormat, size_t bufferSize, size_t offset, size_t size, const void* data);
    311 										TextureBuffer		(const TextureBuffer& other); // Not allowed!
    312 	TextureBuffer&						operator=			(const TextureBuffer& other); // Not allowed!
    313 
    314 	const RenderContext&				m_context;
    315 	deUint32							m_format;		//!< Internal format.
    316 	de::ArrayBuffer<deUint8>			m_refBuffer;
    317 	size_t								m_offset;
    318 	size_t								m_size;
    319 
    320 	deUint32							m_glTexture;
    321 	deUint32							m_glBuffer;
    322 } DE_WARN_UNUSED_TYPE;
    323 
    324 } // glu
    325 
    326 #endif // _GLUTEXTURE_HPP
    327