xref: /aosp_15_r20/external/deqp/framework/opengl/gluTexture.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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, uint32_t format, uint32_t dataType, int width);
47     Texture1D(const RenderContext &context, uint32_t internalFormat, int width);
48     ~Texture1D(void);
49 
getRefTexture(void)50     tcu::Texture1D &getRefTexture(void)
51     {
52         return m_refTexture;
53     }
getRefTexture(void) const54     const tcu::Texture1D &getRefTexture(void) const
55     {
56         return m_refTexture;
57     }
getGLTexture(void) const58     uint32_t getGLTexture(void) const
59     {
60         return m_glTexture;
61     }
62 
63     void upload(void);
64 
65 private:
66     Texture1D(const Texture1D &other);            // Not allowed!
67     Texture1D &operator=(const Texture1D &other); // Not allowed!
68 
69     const RenderContext &m_context;
70     uint32_t m_format; //!< Internal format.
71     tcu::Texture1D m_refTexture;
72     uint32_t m_glTexture;
73 } DE_WARN_UNUSED_TYPE;
74 
75 /*--------------------------------------------------------------------*//*!
76  * \brief 2D Texture
77  *//*--------------------------------------------------------------------*/
78 class Texture2D
79 {
80 public:
81     Texture2D(const RenderContext &context, const ContextInfo &contextInfo, int numLevels,
82               const tcu::CompressedTexture *levels,
83               const tcu::TexDecompressionParams &decompressionParams = tcu::TexDecompressionParams());
84     Texture2D(const RenderContext &context, uint32_t format, uint32_t dataType, int width, int height);
85     Texture2D(const RenderContext &context, uint32_t internalFormat, int width, int height);
86     virtual ~Texture2D(void);
87 
88     virtual void upload(void); // Not supported on compressed textures.
89 
getRefTexture(void)90     tcu::Texture2D &getRefTexture(void)
91     {
92         return m_refTexture;
93     }
getRefTexture(void) const94     const tcu::Texture2D &getRefTexture(void) const
95     {
96         return m_refTexture;
97     }
getGLTexture(void) const98     uint32_t getGLTexture(void) const
99     {
100         return m_glTexture;
101     }
102 
103     static Texture2D *create(const RenderContext &context, const ContextInfo &contextInfo, const tcu::Archive &archive,
104                              int numLevels, const std::vector<std::string> &filenames);
105     static Texture2D *create(const RenderContext &context, const ContextInfo &contextInfo, const tcu::Archive &archive,
106                              int numLevels, const char *const *filenames);
create(const RenderContext & context,const ContextInfo & contextInfo,const tcu::Archive & archive,const char * filename)107     static Texture2D *create(const RenderContext &context, const ContextInfo &contextInfo, const tcu::Archive &archive,
108                              const char *filename)
109     {
110         return create(context, contextInfo, archive, 1, &filename);
111     }
112 
113 protected:
114     const RenderContext &m_context;
115 
116     bool m_isCompressed;
117     uint32_t m_format; //!< Internal format.
118     tcu::Texture2D m_refTexture;
119 
120     uint32_t m_glTexture;
121 
122 private:
123     Texture2D(const Texture2D &other);            // Not allowed!
124     Texture2D &operator=(const Texture2D &other); // Not allowed!
125 
126     void loadCompressed(int numLevels, const tcu::CompressedTexture *levels,
127                         const tcu::TexDecompressionParams &decompressionParams);
128 } DE_WARN_UNUSED_TYPE;
129 
130 class ImmutableTexture2D : public Texture2D
131 {
132 public:
133     ImmutableTexture2D(const RenderContext &context, uint32_t internalFormat, int width, int height);
134 
135     void upload(void); // Not supported on compressed textures.
136 
137 private:
138     ImmutableTexture2D(const ImmutableTexture2D &other);            // Not allowed!
139     ImmutableTexture2D &operator=(const ImmutableTexture2D &other); // Not allowed!
140 };
141 
142 /*--------------------------------------------------------------------*//*!
143  * \brief Cube Map Texture
144  *//*--------------------------------------------------------------------*/
145 class TextureCube
146 {
147 public:
148     // For compressed cubemap constructor and create() function input level pointers / filenames are expected
149     // to laid out to array in following order:
150     //   { l0_neg_x, l0_pos_x, l0_neg_y, l0_pos_y, l0_neg_z, l0_pos_z, l1_neg_x, l1_pos_x, ... }
151 
152     TextureCube(const RenderContext &context, const ContextInfo &contextInfo, int numLevels,
153                 const tcu::CompressedTexture *levels,
154                 const tcu::TexDecompressionParams &decompressionParams = tcu::TexDecompressionParams());
155     TextureCube(const RenderContext &context, uint32_t format, uint32_t dataType, int size);
156     TextureCube(const RenderContext &context, uint32_t internalFormat, int size);
157     ~TextureCube(void);
158 
159     void upload(void); // Not supported on compressed textures.
160 
getRefTexture(void)161     tcu::TextureCube &getRefTexture(void)
162     {
163         return m_refTexture;
164     }
getRefTexture(void) const165     const tcu::TextureCube &getRefTexture(void) const
166     {
167         return m_refTexture;
168     }
getGLTexture(void) const169     uint32_t getGLTexture(void) const
170     {
171         return m_glTexture;
172     }
173 
174     static TextureCube *create(const RenderContext &context, const ContextInfo &contextInfo,
175                                const tcu::Archive &archive, int numLevels, const std::vector<std::string> &filenames);
176     static TextureCube *create(const RenderContext &context, const ContextInfo &contextInfo,
177                                const tcu::Archive &archive, int numLevels, const char *const *filenames);
178 
179 private:
180     TextureCube(const TextureCube &other);            // Not allowed!
181     TextureCube &operator=(const TextureCube &other); // Not allowed!
182 
183     void loadCompressed(int numLevels, const tcu::CompressedTexture *levels,
184                         const tcu::TexDecompressionParams &decompressionParams);
185 
186     const RenderContext &m_context;
187 
188     bool m_isCompressed;
189     uint32_t m_format; //!< Internal format.
190 
191     tcu::TextureCube m_refTexture;
192     uint32_t m_glTexture;
193 } DE_WARN_UNUSED_TYPE;
194 
195 /*--------------------------------------------------------------------*//*!
196  * \brief 2D Array Texture
197  * \note Not supported on OpenGL ES 2
198  *//*--------------------------------------------------------------------*/
199 class Texture2DArray
200 {
201 public:
202     Texture2DArray(const RenderContext &context, uint32_t format, uint32_t dataType, int width, int height,
203                    int numLayers);
204     Texture2DArray(const RenderContext &context, uint32_t internalFormat, int width, int height, int numLayers);
205     Texture2DArray(const RenderContext &context, const ContextInfo &contextInfo, int numLevels,
206                    const tcu::CompressedTexture *levels,
207                    const tcu::TexDecompressionParams &decompressionParams = tcu::TexDecompressionParams());
208     ~Texture2DArray(void);
209 
210     void upload(void);
211 
getRefTexture(void)212     tcu::Texture2DArray &getRefTexture(void)
213     {
214         return m_refTexture;
215     }
getRefTexture(void) const216     const tcu::Texture2DArray &getRefTexture(void) const
217     {
218         return m_refTexture;
219     }
getGLTexture(void) const220     uint32_t getGLTexture(void) const
221     {
222         return m_glTexture;
223     }
224 
225 private:
226     Texture2DArray(const Texture2DArray &other);            // Not allowed!
227     Texture2DArray &operator=(const Texture2DArray &other); // Not allowed!
228 
229     void loadCompressed(int numLevels, const tcu::CompressedTexture *levels,
230                         const tcu::TexDecompressionParams &decompressionParams);
231 
232     const RenderContext &m_context;
233 
234     bool m_isCompressed;
235     uint32_t m_format; //!< Internal format.
236 
237     tcu::Texture2DArray m_refTexture;
238     uint32_t m_glTexture;
239 } DE_WARN_UNUSED_TYPE;
240 
241 /*--------------------------------------------------------------------*//*!
242  * \brief 1D Array Texture
243  * \note Only supported on OpenGL
244  *//*--------------------------------------------------------------------*/
245 class Texture1DArray
246 {
247 public:
248     Texture1DArray(const RenderContext &context, uint32_t format, uint32_t dataType, int width, int numLayers);
249     Texture1DArray(const RenderContext &context, uint32_t internalFormat, int width, int numLayers);
250     ~Texture1DArray(void);
251 
252     void upload(void);
253 
getRefTexture(void)254     tcu::Texture1DArray &getRefTexture(void)
255     {
256         return m_refTexture;
257     }
getRefTexture(void) const258     const tcu::Texture1DArray &getRefTexture(void) const
259     {
260         return m_refTexture;
261     }
getGLTexture(void) const262     uint32_t getGLTexture(void) const
263     {
264         return m_glTexture;
265     }
266 
267 private:
268     Texture1DArray(const Texture1DArray &other);            // Not allowed!
269     Texture1DArray &operator=(const Texture1DArray &other); // Not allowed!
270 
271     const RenderContext &m_context;
272 
273     uint32_t m_format; //!< Internal format.
274 
275     tcu::Texture1DArray m_refTexture;
276     uint32_t m_glTexture;
277 } DE_WARN_UNUSED_TYPE;
278 
279 /*--------------------------------------------------------------------*//*!
280  * \brief 3D Texture
281  * \note Not supported on OpenGL ES 2
282  *//*--------------------------------------------------------------------*/
283 class Texture3D
284 {
285 public:
286     Texture3D(const RenderContext &context, uint32_t format, uint32_t dataType, int width, int height, int depth);
287     Texture3D(const RenderContext &context, uint32_t internalFormat, int width, int height, int depth);
288     Texture3D(const RenderContext &context, const ContextInfo &contextInfo, int numLevels,
289               const tcu::CompressedTexture *levels,
290               const tcu::TexDecompressionParams &decompressionParams = tcu::TexDecompressionParams());
291     ~Texture3D(void);
292 
293     void upload(void);
294 
getRefTexture(void)295     tcu::Texture3D &getRefTexture(void)
296     {
297         return m_refTexture;
298     }
getRefTexture(void) const299     const tcu::Texture3D &getRefTexture(void) const
300     {
301         return m_refTexture;
302     }
getGLTexture(void) const303     uint32_t getGLTexture(void) const
304     {
305         return m_glTexture;
306     }
307 
308 private:
309     Texture3D(const Texture3D &other);            // Not allowed!
310     Texture3D &operator=(const Texture3D &other); // Not allowed!
311 
312     void loadCompressed(int numLevels, const tcu::CompressedTexture *levels,
313                         const tcu::TexDecompressionParams &decompressionParams);
314 
315     const RenderContext &m_context;
316 
317     bool m_isCompressed;
318     uint32_t m_format; //!< Internal format.
319 
320     tcu::Texture3D m_refTexture;
321     uint32_t m_glTexture;
322 } DE_WARN_UNUSED_TYPE;
323 
324 /*--------------------------------------------------------------------*//*!
325  * \brief Cube Map Array Texture
326  * \note Not supported on OpenGL ES 3.0 or lower
327  *//*--------------------------------------------------------------------*/
328 class TextureCubeArray
329 {
330 public:
331     TextureCubeArray(const RenderContext &context, uint32_t format, uint32_t dataType, int size, int numLayers);
332     TextureCubeArray(const RenderContext &context, uint32_t internalFormat, int size, int numLayers);
333 
334     ~TextureCubeArray(void);
335 
336     void upload(void);
337 
getRefTexture(void)338     tcu::TextureCubeArray &getRefTexture(void)
339     {
340         return m_refTexture;
341     }
getRefTexture(void) const342     const tcu::TextureCubeArray &getRefTexture(void) const
343     {
344         return m_refTexture;
345     }
getGLTexture(void) const346     uint32_t getGLTexture(void) const
347     {
348         return m_glTexture;
349     }
350 
351 private:
352     TextureCubeArray(const TextureCubeArray &other);            // Not allowed!
353     TextureCubeArray &operator=(const TextureCubeArray &other); // Not allowed!
354 
355     const RenderContext &m_context;
356 
357     bool m_isCompressed;
358     uint32_t m_format; //!< Internal format.
359 
360     tcu::TextureCubeArray m_refTexture;
361     uint32_t m_glTexture;
362 } DE_WARN_UNUSED_TYPE;
363 
364 /*--------------------------------------------------------------------*//*!
365  * \brief 1D Texture Buffer only supported on OpenGL
366  *//*--------------------------------------------------------------------*/
367 class TextureBuffer
368 {
369 public:
370     TextureBuffer(const RenderContext &context, uint32_t internalFormat, size_t bufferSize);
371     TextureBuffer(const RenderContext &context, uint32_t internalFormat, size_t bufferSize, size_t offset, size_t size,
372                   const void *data = DE_NULL);
373 
374     ~TextureBuffer(void);
375 
376     // \note Effective pixel buffer access must be limited to w <= GL_MAX_TEXTURE_BUFFER_SIZE
377     const tcu::PixelBufferAccess getFullRefTexture(void);
378     const tcu::ConstPixelBufferAccess getFullRefTexture(void) const;
379 
380     // \note mutating buffer storage will invalidate existing pixel buffer accesses
getRefBuffer(void)381     de::ArrayBuffer<uint8_t> &getRefBuffer(void)
382     {
383         return m_refBuffer;
384     }
getRefBuffer(void) const385     const de::ArrayBuffer<uint8_t> &getRefBuffer(void) const
386     {
387         return m_refBuffer;
388     }
389 
getSize(void) const390     size_t getSize(void) const
391     {
392         return m_size;
393     }
getOffset(void) const394     size_t getOffset(void) const
395     {
396         return m_offset;
397     }
getBufferSize(void) const398     size_t getBufferSize(void) const
399     {
400         return m_refBuffer.size();
401     }
402 
getGLTexture(void) const403     uint32_t getGLTexture(void) const
404     {
405         return m_glTexture;
406     }
getGLBuffer(void) const407     uint32_t getGLBuffer(void) const
408     {
409         return m_glBuffer;
410     }
411 
412     void upload(void);
413 
414 private:
415     void init(uint32_t internalFormat, size_t bufferSize, size_t offset, size_t size, const void *data);
416     TextureBuffer(const TextureBuffer &other);            // Not allowed!
417     TextureBuffer &operator=(const TextureBuffer &other); // Not allowed!
418 
419     const RenderContext &m_context;
420     uint32_t m_format; //!< Internal format.
421     de::ArrayBuffer<uint8_t> m_refBuffer;
422     size_t m_offset;
423     size_t m_size;
424 
425     uint32_t m_glTexture;
426     uint32_t m_glBuffer;
427 } DE_WARN_UNUSED_TYPE;
428 
429 } // namespace glu
430 
431 #endif // _GLUTEXTURE_HPP
432