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 ~Texture2D (void); 76 77 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 private: 88 Texture2D (const Texture2D& other); // Not allowed! 89 Texture2D& operator= (const Texture2D& other); // Not allowed! 90 91 void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams); 92 93 const RenderContext& m_context; 94 95 bool m_isCompressed; 96 deUint32 m_format; //!< Internal format. 97 98 tcu::Texture2D m_refTexture; 99 deUint32 m_glTexture; 100 } DE_WARN_UNUSED_TYPE; 101 102 /*--------------------------------------------------------------------*//*! 103 * \brief Cube Map Texture 104 *//*--------------------------------------------------------------------*/ 105 class TextureCube 106 { 107 public: 108 // For compressed cubemap constructor and create() function input level pointers / filenames are expected 109 // to laid out to array in following order: 110 // { l0_neg_x, l0_pos_x, l0_neg_y, l0_pos_y, l0_neg_z, l0_pos_z, l1_neg_x, l1_pos_x, ... } 111 112 TextureCube (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams()); 113 TextureCube (const RenderContext& context, deUint32 format, deUint32 dataType, int size); 114 TextureCube (const RenderContext& context, deUint32 internalFormat, int size); 115 ~TextureCube (void); 116 117 void upload (void); // Not supported on compressed textures. 118 119 tcu::TextureCube& getRefTexture (void) { return m_refTexture; } 120 const tcu::TextureCube& getRefTexture (void) const { return m_refTexture; } 121 deUint32 getGLTexture (void) const { return m_glTexture; } 122 123 static TextureCube* create (const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const std::vector<std::string>& filenames); 124 static TextureCube* create (const RenderContext& context, const ContextInfo& contextInfo, const tcu::Archive& archive, int numLevels, const char* const* filenames); 125 126 private: 127 TextureCube (const TextureCube& other); // Not allowed! 128 TextureCube& operator= (const TextureCube& other); // Not allowed! 129 130 void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams); 131 132 const RenderContext& m_context; 133 134 bool m_isCompressed; 135 deUint32 m_format; //!< Internal format. 136 137 tcu::TextureCube m_refTexture; 138 deUint32 m_glTexture; 139 } DE_WARN_UNUSED_TYPE; 140 141 /*--------------------------------------------------------------------*//*! 142 * \brief 2D Array Texture 143 * \note Not supported on OpenGL ES 2 144 *//*--------------------------------------------------------------------*/ 145 class Texture2DArray 146 { 147 public: 148 Texture2DArray (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int numLayers); 149 Texture2DArray (const RenderContext& context, deUint32 internalFormat, int width, int height, int numLayers); 150 Texture2DArray (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams()); 151 ~Texture2DArray (void); 152 153 void upload (void); 154 155 tcu::Texture2DArray& getRefTexture (void) { return m_refTexture; } 156 const tcu::Texture2DArray& getRefTexture (void) const { return m_refTexture; } 157 deUint32 getGLTexture (void) const { return m_glTexture; } 158 159 private: 160 Texture2DArray (const Texture2DArray& other); // Not allowed! 161 Texture2DArray& operator= (const Texture2DArray& other); // Not allowed! 162 163 void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams); 164 165 166 const RenderContext& m_context; 167 168 bool m_isCompressed; 169 deUint32 m_format; //!< Internal format. 170 171 tcu::Texture2DArray m_refTexture; 172 deUint32 m_glTexture; 173 } DE_WARN_UNUSED_TYPE; 174 175 /*--------------------------------------------------------------------*//*! 176 * \brief 1D Array Texture 177 * \note Only supported on OpenGL 178 *//*--------------------------------------------------------------------*/ 179 class Texture1DArray 180 { 181 public: 182 Texture1DArray (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int numLayers); 183 Texture1DArray (const RenderContext& context, deUint32 internalFormat, int width, int numLayers); 184 ~Texture1DArray (void); 185 186 void upload (void); 187 188 tcu::Texture1DArray& getRefTexture (void) { return m_refTexture; } 189 const tcu::Texture1DArray& getRefTexture (void) const { return m_refTexture; } 190 deUint32 getGLTexture (void) const { return m_glTexture; } 191 192 private: 193 Texture1DArray (const Texture1DArray& other); // Not allowed! 194 Texture1DArray& operator= (const Texture1DArray& other); // Not allowed! 195 196 const RenderContext& m_context; 197 198 deUint32 m_format; //!< Internal format. 199 200 tcu::Texture1DArray m_refTexture; 201 deUint32 m_glTexture; 202 } DE_WARN_UNUSED_TYPE; 203 204 /*--------------------------------------------------------------------*//*! 205 * \brief 3D Texture 206 * \note Not supported on OpenGL ES 2 207 *//*--------------------------------------------------------------------*/ 208 class Texture3D 209 { 210 public: 211 Texture3D (const RenderContext& context, deUint32 format, deUint32 dataType, int width, int height, int depth); 212 Texture3D (const RenderContext& context, deUint32 internalFormat, int width, int height, int depth); 213 Texture3D (const RenderContext& context, const ContextInfo& contextInfo, int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams = tcu::TexDecompressionParams()); 214 ~Texture3D (void); 215 216 void upload (void); 217 218 tcu::Texture3D& getRefTexture (void) { return m_refTexture; } 219 const tcu::Texture3D& getRefTexture (void) const { return m_refTexture; } 220 deUint32 getGLTexture (void) const { return m_glTexture; } 221 222 private: 223 Texture3D (const Texture3D& other); // Not allowed! 224 Texture3D& operator= (const Texture3D& other); // Not allowed! 225 226 void loadCompressed (int numLevels, const tcu::CompressedTexture* levels, const tcu::TexDecompressionParams& decompressionParams); 227 228 const RenderContext& m_context; 229 230 bool m_isCompressed; 231 deUint32 m_format; //!< Internal format. 232 233 tcu::Texture3D m_refTexture; 234 deUint32 m_glTexture; 235 } DE_WARN_UNUSED_TYPE; 236 237 /*--------------------------------------------------------------------*//*! 238 * \brief Cube Map Array Texture 239 * \note Not supported on OpenGL ES 3.0 or lower 240 *//*--------------------------------------------------------------------*/ 241 class TextureCubeArray 242 { 243 public: 244 TextureCubeArray (const RenderContext& context, deUint32 format, deUint32 dataType, int size, int numLayers); 245 TextureCubeArray (const RenderContext& context, deUint32 internalFormat, int size, int numLayers); 246 247 ~TextureCubeArray (void); 248 249 void upload (void); 250 251 tcu::TextureCubeArray& getRefTexture (void) { return m_refTexture; } 252 const tcu::TextureCubeArray& getRefTexture (void) const { return m_refTexture; } 253 deUint32 getGLTexture (void) const { return m_glTexture; } 254 255 private: 256 TextureCubeArray (const TextureCubeArray& other); // Not allowed! 257 TextureCubeArray& operator= (const TextureCubeArray& other); // Not allowed! 258 259 const RenderContext& m_context; 260 261 bool m_isCompressed; 262 deUint32 m_format; //!< Internal format. 263 264 tcu::TextureCubeArray m_refTexture; 265 deUint32 m_glTexture; 266 } DE_WARN_UNUSED_TYPE; 267 268 /*--------------------------------------------------------------------*//*! 269 * \brief 1D Texture Buffer only supported on OpenGL 270 *//*--------------------------------------------------------------------*/ 271 class TextureBuffer 272 { 273 public: 274 TextureBuffer (const RenderContext& context, deUint32 internalFormat, size_t bufferSize); 275 TextureBuffer (const RenderContext& context, deUint32 internalFormat, size_t bufferSize, size_t offset, size_t size, const void* data = DE_NULL); 276 277 ~TextureBuffer (void); 278 279 const tcu::PixelBufferAccess& getRefTexture (void) { return m_refTexture; } 280 const tcu::ConstPixelBufferAccess& getRefTexture (void) const { return m_refTexture; } 281 282 deUint8* getRefBuffer (void) { return &(m_refBuffer[0]); } 283 const deUint8* getRefBuffer (void) const { return &(m_refBuffer[0]); } 284 285 size_t getSize (void) const { return m_size; } 286 size_t getOffset (void) const { return m_offset; } 287 size_t getBufferSize (void) const { return m_refBuffer.size(); } 288 289 deUint32 getGLTexture (void) const { return m_glTexture; } 290 deUint32 getGLBuffer (void) const { return m_glBuffer; } 291 292 // \note Resizes reference buffer. Invalidates old pixel buffer acceses. 293 // \note Doesn't upload data. 294 void bufferData (const deUint8* data, size_t size); 295 void upload (void); 296 297 private: 298 void init (deUint32 internalFormat, size_t bufferSize, size_t offset, size_t size, const void* data); 299 TextureBuffer (const TextureBuffer& other); // Not allowed! 300 TextureBuffer& operator= (const TextureBuffer& other); // Not allowed! 301 302 const RenderContext& m_context; 303 deUint32 m_format; //!< Internal format. 304 std::vector<deUint8> m_refBuffer; 305 size_t m_offset; 306 size_t m_size; 307 308 tcu::PixelBufferAccess m_refTexture; 309 deUint32 m_glTexture; 310 deUint32 m_glBuffer; 311 } DE_WARN_UNUSED_TYPE; 312 313 } // glu 314 315 #endif // _GLUTEXTURE_HPP 316