1 // 2 // Copyright 2015 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // TextureGL.h: Defines the class interface for TextureGL. 8 9 #ifndef LIBANGLE_RENDERER_GL_TEXTUREGL_H_ 10 #define LIBANGLE_RENDERER_GL_TEXTUREGL_H_ 11 12 #include "libANGLE/Texture.h" 13 #include "libANGLE/angletypes.h" 14 #include "libANGLE/renderer/TextureImpl.h" 15 16 namespace rx 17 { 18 19 class BlitGL; 20 class FunctionsGL; 21 class StateManagerGL; 22 23 struct LUMAWorkaroundGL 24 { 25 bool enabled; 26 GLenum workaroundFormat; 27 28 LUMAWorkaroundGL(); 29 LUMAWorkaroundGL(bool enabled, GLenum workaroundFormat); 30 }; 31 32 // Structure containing information about format and workarounds for each mip level of the 33 // TextureGL. 34 struct LevelInfoGL 35 { 36 // Format of the data used in this mip level. 37 GLenum sourceFormat; 38 39 // Internal format used for the native call to define this texture 40 GLenum nativeInternalFormat; 41 42 // If this mip level requires sampler-state re-writing so that only a red channel is exposed. 43 // In GLES 2.0, depth textures are treated as luminance, so we check the 44 // context's major version when applying the depth swizzle. 45 bool depthStencilWorkaround; 46 47 // Information about luminance alpha texture workarounds in the core profile. 48 LUMAWorkaroundGL lumaWorkaround; 49 50 // If this texture level hides the fact that it has an alpha channel by setting the sampler 51 // parameters to always sample 1.0. 52 bool emulatedAlphaChannel; 53 54 LevelInfoGL(); 55 LevelInfoGL(GLenum sourceFormat, 56 GLenum nativeInternalFormat, 57 bool depthStencilWorkaround, 58 const LUMAWorkaroundGL &lumaWorkaround, 59 bool emulatedAlphaChannel); 60 }; 61 62 class TextureGL : public TextureImpl 63 { 64 public: 65 TextureGL(const gl::TextureState &state, GLuint id); 66 ~TextureGL() override; 67 68 void onDestroy(const gl::Context *context) override; 69 70 angle::Result setImage(const gl::Context *context, 71 const gl::ImageIndex &index, 72 GLenum internalFormat, 73 const gl::Extents &size, 74 GLenum format, 75 GLenum type, 76 const gl::PixelUnpackState &unpack, 77 gl::Buffer *unpackBuffer, 78 const uint8_t *pixels) override; 79 angle::Result setSubImage(const gl::Context *context, 80 const gl::ImageIndex &index, 81 const gl::Box &area, 82 GLenum format, 83 GLenum type, 84 const gl::PixelUnpackState &unpack, 85 gl::Buffer *unpackBuffer, 86 const uint8_t *pixels) override; 87 88 angle::Result setCompressedImage(const gl::Context *context, 89 const gl::ImageIndex &index, 90 GLenum internalFormat, 91 const gl::Extents &size, 92 const gl::PixelUnpackState &unpack, 93 size_t imageSize, 94 const uint8_t *pixels) override; 95 angle::Result setCompressedSubImage(const gl::Context *context, 96 const gl::ImageIndex &index, 97 const gl::Box &area, 98 GLenum format, 99 const gl::PixelUnpackState &unpack, 100 size_t imageSize, 101 const uint8_t *pixels) override; 102 103 angle::Result copyImage(const gl::Context *context, 104 const gl::ImageIndex &index, 105 const gl::Rectangle &sourceArea, 106 GLenum internalFormat, 107 gl::Framebuffer *source) override; 108 angle::Result copySubImage(const gl::Context *context, 109 const gl::ImageIndex &index, 110 const gl::Offset &destOffset, 111 const gl::Rectangle &sourceArea, 112 gl::Framebuffer *source) override; 113 114 angle::Result copyTexture(const gl::Context *context, 115 const gl::ImageIndex &index, 116 GLenum internalFormat, 117 GLenum type, 118 GLint sourceLevel, 119 bool unpackFlipY, 120 bool unpackPremultiplyAlpha, 121 bool unpackUnmultiplyAlpha, 122 const gl::Texture *source) override; 123 angle::Result copySubTexture(const gl::Context *context, 124 const gl::ImageIndex &index, 125 const gl::Offset &destOffset, 126 GLint sourceLevel, 127 const gl::Box &sourceBox, 128 bool unpackFlipY, 129 bool unpackPremultiplyAlpha, 130 bool unpackUnmultiplyAlpha, 131 const gl::Texture *source) override; 132 angle::Result copySubTextureHelper(const gl::Context *context, 133 gl::TextureTarget target, 134 size_t level, 135 const gl::Offset &destOffset, 136 GLint sourceLevel, 137 const gl::Rectangle &sourceArea, 138 const gl::InternalFormat &destFormat, 139 bool unpackFlipY, 140 bool unpackPremultiplyAlpha, 141 bool unpackUnmultiplyAlpha, 142 const gl::Texture *source); 143 144 angle::Result setStorage(const gl::Context *context, 145 gl::TextureType type, 146 size_t levels, 147 GLenum internalFormat, 148 const gl::Extents &size) override; 149 150 angle::Result setStorageMultisample(const gl::Context *context, 151 gl::TextureType type, 152 GLsizei samples, 153 GLint internalformat, 154 const gl::Extents &size, 155 bool fixedSampleLocations) override; 156 157 angle::Result setStorageExternalMemory(const gl::Context *context, 158 gl::TextureType type, 159 size_t levels, 160 GLenum internalFormat, 161 const gl::Extents &size, 162 gl::MemoryObject *memoryObject, 163 GLuint64 offset, 164 GLbitfield createFlags, 165 GLbitfield usageFlags, 166 const void *imageCreateInfoPNext) override; 167 168 angle::Result setImageExternal(const gl::Context *context, 169 const gl::ImageIndex &index, 170 GLenum internalFormat, 171 const gl::Extents &size, 172 GLenum format, 173 GLenum type) override; 174 175 angle::Result setImageExternal(const gl::Context *context, 176 gl::TextureType type, 177 egl::Stream *stream, 178 const egl::Stream::GLTextureDescription &desc) override; 179 180 angle::Result generateMipmap(const gl::Context *context) override; 181 182 angle::Result bindTexImage(const gl::Context *context, egl::Surface *surface) override; 183 angle::Result releaseTexImage(const gl::Context *context) override; 184 185 angle::Result setEGLImageTarget(const gl::Context *context, 186 gl::TextureType type, 187 egl::Image *image) override; 188 189 GLint getNativeID() const override; 190 getTextureID()191 GLuint getTextureID() const { return mTextureID; } 192 193 gl::TextureType getType() const; 194 195 angle::Result syncState(const gl::Context *context, 196 const gl::Texture::DirtyBits &dirtyBits, 197 gl::Command source) override; 198 bool hasAnyDirtyBit() const; 199 200 angle::Result setBaseLevel(const gl::Context *context, GLuint baseLevel) override; 201 angle::Result setMaxLevel(const gl::Context *context, GLuint maxLevel); 202 203 angle::Result initializeContents(const gl::Context *context, 204 const gl::ImageIndex &imageIndex) override; 205 206 GLint getRequiredExternalTextureImageUnits(const gl::Context *context) override; 207 208 angle::Result setMinFilter(const gl::Context *context, GLenum filter); 209 angle::Result setMagFilter(const gl::Context *context, GLenum filter); 210 211 angle::Result setSwizzle(const gl::Context *context, GLint swizzle[4]); 212 213 angle::Result setBuffer(const gl::Context *context, GLenum internalFormat) override; 214 215 GLenum getNativeInternalFormat(const gl::ImageIndex &index) const; 216 bool hasEmulatedAlphaChannel(const gl::ImageIndex &index) const; 217 218 private: 219 angle::Result recreateTexture(const gl::Context *context); 220 221 angle::Result setImageHelper(const gl::Context *context, 222 gl::TextureTarget target, 223 size_t level, 224 GLenum internalFormat, 225 const gl::Extents &size, 226 GLenum format, 227 GLenum type, 228 const uint8_t *pixels); 229 // This changes the current pixel unpack state that will have to be reapplied. 230 angle::Result reserveTexImageToBeFilled(const gl::Context *context, 231 gl::TextureTarget target, 232 size_t level, 233 GLenum internalFormat, 234 const gl::Extents &size, 235 GLenum format, 236 GLenum type); 237 angle::Result setSubImageRowByRowWorkaround(const gl::Context *context, 238 gl::TextureTarget target, 239 size_t level, 240 const gl::Box &area, 241 GLenum format, 242 GLenum type, 243 const gl::PixelUnpackState &unpack, 244 const gl::Buffer *unpackBuffer, 245 size_t maxBytesUploadedPerChunk, 246 const uint8_t *pixels); 247 248 angle::Result setSubImagePaddingWorkaround(const gl::Context *context, 249 gl::TextureTarget target, 250 size_t level, 251 const gl::Box &area, 252 GLenum format, 253 GLenum type, 254 const gl::PixelUnpackState &unpack, 255 const gl::Buffer *unpackBuffer, 256 const uint8_t *pixels); 257 258 angle::Result syncTextureStateSwizzle(const gl::Context *context, 259 const FunctionsGL *functions, 260 GLenum name, 261 GLenum value, 262 GLenum *outValue); 263 264 void setLevelInfo(const gl::Context *context, 265 gl::TextureTarget target, 266 size_t level, 267 size_t levelCount, 268 const LevelInfoGL &levelInfo); 269 void setLevelInfo(const gl::Context *context, 270 gl::TextureType type, 271 size_t level, 272 size_t levelCount, 273 const LevelInfoGL &levelInfo); 274 const LevelInfoGL &getLevelInfo(gl::TextureTarget target, size_t level) const; 275 const LevelInfoGL &getBaseLevelInfo() const; 276 277 std::vector<LevelInfoGL> mLevelInfo; 278 gl::Texture::DirtyBits mLocalDirtyBits; 279 280 // All dirty bits ever sychronized by this texture OR'd together. Used to know what state needs 281 // to be resynced if the texture is ever recreated without needing extension checks or state 282 // comparisons. 283 gl::Texture::DirtyBits mAllModifiedDirtyBits; 284 285 gl::SwizzleState mAppliedSwizzle; 286 gl::SamplerState mAppliedSampler; 287 GLuint mAppliedBaseLevel; 288 GLuint mAppliedMaxLevel; 289 290 GLuint mTextureID; 291 }; 292 } // namespace rx 293 294 #endif // LIBANGLE_RENDERER_GL_TEXTUREGL_H_ 295