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 clearImage(const gl::Context *context, 183 GLint level, 184 GLenum format, 185 GLenum type, 186 const uint8_t *data) override; 187 angle::Result clearSubImage(const gl::Context *context, 188 GLint level, 189 const gl::Box &area, 190 GLenum format, 191 GLenum type, 192 const uint8_t *data) override; 193 194 angle::Result bindTexImage(const gl::Context *context, egl::Surface *surface) override; 195 angle::Result releaseTexImage(const gl::Context *context) override; 196 197 angle::Result setEGLImageTarget(const gl::Context *context, 198 gl::TextureType type, 199 egl::Image *image) override; 200 201 GLint getNativeID() const override; 202 getTextureID()203 GLuint getTextureID() const { return mTextureID; } 204 205 gl::TextureType getType() const; 206 207 angle::Result syncState(const gl::Context *context, 208 const gl::Texture::DirtyBits &dirtyBits, 209 gl::Command source) override; 210 bool hasAnyDirtyBit() const; 211 212 angle::Result setBaseLevel(const gl::Context *context, GLuint baseLevel) override; 213 angle::Result setMaxLevel(const gl::Context *context, GLuint maxLevel); 214 215 angle::Result initializeContents(const gl::Context *context, 216 GLenum binding, 217 const gl::ImageIndex &imageIndex) override; 218 219 GLint getRequiredExternalTextureImageUnits(const gl::Context *context) override; 220 221 angle::Result setMinFilter(const gl::Context *context, GLenum filter); 222 angle::Result setMagFilter(const gl::Context *context, GLenum filter); 223 224 angle::Result setSwizzle(const gl::Context *context, GLint swizzle[4]); 225 226 angle::Result setBuffer(const gl::Context *context, GLenum internalFormat) override; 227 228 GLenum getNativeInternalFormat(const gl::ImageIndex &index) const; 229 bool hasEmulatedAlphaChannel(const gl::ImageIndex &index) const; 230 231 private: 232 angle::Result recreateTexture(const gl::Context *context); 233 234 angle::Result setImageHelper(const gl::Context *context, 235 gl::TextureTarget target, 236 size_t level, 237 GLenum internalFormat, 238 const gl::Extents &size, 239 GLenum format, 240 GLenum type, 241 const uint8_t *pixels); 242 // This changes the current pixel unpack state that will have to be reapplied. 243 angle::Result reserveTexImageToBeFilled(const gl::Context *context, 244 gl::TextureTarget target, 245 size_t level, 246 GLenum internalFormat, 247 const gl::Extents &size, 248 GLenum format, 249 GLenum type); 250 angle::Result setSubImageRowByRowWorkaround(const gl::Context *context, 251 gl::TextureTarget target, 252 size_t level, 253 const gl::Box &area, 254 GLenum format, 255 GLenum type, 256 const gl::PixelUnpackState &unpack, 257 const gl::Buffer *unpackBuffer, 258 size_t maxBytesUploadedPerChunk, 259 const uint8_t *pixels); 260 261 angle::Result setSubImagePaddingWorkaround(const gl::Context *context, 262 gl::TextureTarget target, 263 size_t level, 264 const gl::Box &area, 265 GLenum format, 266 GLenum type, 267 const gl::PixelUnpackState &unpack, 268 const gl::Buffer *unpackBuffer, 269 const uint8_t *pixels); 270 271 angle::Result syncTextureStateSwizzle(const gl::Context *context, 272 const FunctionsGL *functions, 273 GLenum name, 274 GLenum value, 275 GLenum *currentlyAppliedValue); 276 277 void setLevelInfo(const gl::Context *context, 278 gl::TextureTarget target, 279 size_t level, 280 size_t levelCount, 281 const LevelInfoGL &levelInfo); 282 void setLevelInfo(const gl::Context *context, 283 gl::TextureType type, 284 size_t level, 285 size_t levelCount, 286 const LevelInfoGL &levelInfo); 287 const LevelInfoGL &getLevelInfo(gl::TextureTarget target, size_t level) const; 288 const LevelInfoGL &getBaseLevelInfo() const; 289 290 std::vector<LevelInfoGL> mLevelInfo; 291 gl::Texture::DirtyBits mLocalDirtyBits; 292 293 // All dirty bits ever sychronized by this texture OR'd together. Used to know what state needs 294 // to be resynced if the texture is ever recreated without needing extension checks or state 295 // comparisons. 296 gl::Texture::DirtyBits mAllModifiedDirtyBits; 297 298 gl::SwizzleState mAppliedSwizzle; 299 gl::SamplerState mAppliedSampler; 300 GLuint mAppliedBaseLevel; 301 GLuint mAppliedMaxLevel; 302 GLenum mAppliedDepthStencilTextureMode; 303 304 GLuint mTextureID; 305 }; 306 } // namespace rx 307 308 #endif // LIBANGLE_RENDERER_GL_TEXTUREGL_H_ 309