1 #ifndef _GLUTEXTURE_HPP
2 #define _GLUTEXTURE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES Utilities
5 * ------------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Texture classes.
24 *//*--------------------------------------------------------------------*/
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"
40 /*--------------------------------------------------------------------*//*!
41 * \brief 1D Texture only supported on OpenGL
42 *//*--------------------------------------------------------------------*/
46 Texture1D (const RenderContext& context, deUint32 format, deUint32 dataType, int width);
47 Texture1D (const RenderContext& context, deUint32 internalFormat, int width);
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; }
57 Texture1D (const Texture1D& other); // Not allowed!
58 Texture1D& operator= (const Texture1D& other); // Not allowed!
60 const RenderContext& m_context;
61 deUint32 m_format; //!< Internal format.
62 tcu::Texture1D m_refTexture;
64 } DE_WARN_UNUSED_TYPE;
66 /*--------------------------------------------------------------------*//*!
68 *//*--------------------------------------------------------------------*/
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);
77 virtual void upload (void); // Not supported on compressed textures.
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; }
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); }
88 const RenderContext& m_context;
91 deUint32 m_format; //!< Internal format.
92 tcu::Texture2D m_refTexture;
97 Texture2D (const Texture2D& other); // Not allowed!
98 Texture2D& operator= (const Texture2D& other); // Not allowed!
100 void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams);
101 } DE_WARN_UNUSED_TYPE;
103 class ImmutableTexture2D : public Texture2D
106 ImmutableTexture2D (const RenderContext& context, deUint32 internalFormat, int width, int height);
108 void upload (void); // Not supported on compressed textures.
111 ImmutableTexture2D (const ImmutableTexture2D& other); // Not allowed!
112 ImmutableTexture2D& operator= (const ImmutableTexture2D& other); // Not allowed!
115 /*--------------------------------------------------------------------*//*!
116 * \brief Cube Map Texture
117 *//*--------------------------------------------------------------------*/
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, ... }
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);
130 void upload (void); // Not supported on compressed textures.
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; }
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);
140 TextureCube (const TextureCube& other); // Not allowed!
141 TextureCube& operator= (const TextureCube& other); // Not allowed!
143 void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams);
145 const RenderContext& m_context;
148 deUint32 m_format; //!< Internal format.
150 tcu::TextureCube m_refTexture;
151 deUint32 m_glTexture;
152 } DE_WARN_UNUSED_TYPE;
154 /*--------------------------------------------------------------------*//*!
155 * \brief 2D Array Texture
156 * \note Not supported on OpenGL ES 2
157 *//*--------------------------------------------------------------------*/
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);
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; }
173 Texture2DArray (const Texture2DArray& other); // Not allowed!
174 Texture2DArray& operator= (const Texture2DArray& other); // Not allowed!
176 void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams);
179 const RenderContext& m_context;
182 deUint32 m_format; //!< Internal format.
184 tcu::Texture2DArray m_refTexture;
185 deUint32 m_glTexture;
186 } DE_WARN_UNUSED_TYPE;
188 /*--------------------------------------------------------------------*//*!
189 * \brief 1D Array Texture
190 * \note Only supported on OpenGL
191 *//*--------------------------------------------------------------------*/
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);
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; }
206 Texture1DArray (const Texture1DArray& other); // Not allowed!
207 Texture1DArray& operator= (const Texture1DArray& other); // Not allowed!
209 const RenderContext& m_context;
211 deUint32 m_format; //!< Internal format.
213 tcu::Texture1DArray m_refTexture;
214 deUint32 m_glTexture;
215 } DE_WARN_UNUSED_TYPE;
217 /*--------------------------------------------------------------------*//*!
219 * \note Not supported on OpenGL ES 2
220 *//*--------------------------------------------------------------------*/
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());
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; }
236 Texture3D (const Texture3D& other); // Not allowed!
237 Texture3D& operator= (const Texture3D& other); // Not allowed!
239 void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams);
241 const RenderContext& m_context;
244 deUint32 m_format; //!< Internal format.
246 tcu::Texture3D m_refTexture;
247 deUint32 m_glTexture;
248 } DE_WARN_UNUSED_TYPE;
250 /*--------------------------------------------------------------------*//*!
251 * \brief Cube Map Array Texture
252 * \note Not supported on OpenGL ES 3.0 or lower
253 *//*--------------------------------------------------------------------*/
254 class TextureCubeArray
257 TextureCubeArray (const RenderContext& context, deUint32 format, deUint32 dataType, int size, int numLayers);
258 TextureCubeArray (const RenderContext& context, deUint32 internalFormat, int size, int numLayers);
260 ~TextureCubeArray (void);
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; }
269 TextureCubeArray (const TextureCubeArray& other); // Not allowed!
270 TextureCubeArray& operator= (const TextureCubeArray& other); // Not allowed!
272 const RenderContext& m_context;
275 deUint32 m_format; //!< Internal format.
277 tcu::TextureCubeArray m_refTexture;
278 deUint32 m_glTexture;
279 } DE_WARN_UNUSED_TYPE;
281 /*--------------------------------------------------------------------*//*!
282 * \brief 1D Texture Buffer only supported on OpenGL
283 *//*--------------------------------------------------------------------*/
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);
290 ~TextureBuffer (void);
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;
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; }
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(); }
304 deUint32 getGLTexture (void) const { return m_glTexture; }
305 deUint32 getGLBuffer (void) const { return m_glBuffer; }
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!
314 const RenderContext& m_context;
315 deUint32 m_format; //!< Internal format.
316 de::ArrayBuffer<deUint8> m_refBuffer;
320 deUint32 m_glTexture;
322 } DE_WARN_UNUSED_TYPE;
326 #endif // _GLUTEXTURE_HPP