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 size_t 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 size_t 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 size_t 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) override; 164 165 angle::Result setImageExternal(const gl::Context *context, 166 const gl::ImageIndex &index, 167 GLenum internalFormat, 168 const gl::Extents &size, 169 GLenum format, 170 GLenum type) override; 171 172 angle::Result setImageExternal(const gl::Context *context, 173 gl::TextureType type, 174 egl::Stream *stream, 175 const egl::Stream::GLTextureDescription &desc) override; 176 177 angle::Result generateMipmap(const gl::Context *context) override; 178 179 angle::Result bindTexImage(const gl::Context *context, egl::Surface *surface) override; 180 angle::Result releaseTexImage(const gl::Context *context) override; 181 182 angle::Result setEGLImageTarget(const gl::Context *context, 183 gl::TextureType type, 184 egl::Image *image) override; 185 186 GLint getNativeID() const override; 187 getTextureID()188 GLuint getTextureID() const { return mTextureID; } 189 190 gl::TextureType getType() const; 191 192 angle::Result syncState(const gl::Context *context, 193 const gl::Texture::DirtyBits &dirtyBits) override; 194 bool hasAnyDirtyBit() const; 195 196 angle::Result setBaseLevel(const gl::Context *context, GLuint baseLevel) override; 197 angle::Result setMaxLevel(const gl::Context *context, GLuint maxLevel); 198 199 angle::Result initializeContents(const gl::Context *context, 200 const gl::ImageIndex &imageIndex) override; 201 202 angle::Result setMinFilter(const gl::Context *context, GLenum filter); 203 angle::Result setMagFilter(const gl::Context *context, GLenum filter); 204 205 angle::Result setSwizzle(const gl::Context *context, GLint swizzle[4]); 206 207 GLenum getNativeInternalFormat(const gl::ImageIndex &index) const; 208 bool hasEmulatedAlphaChannel(const gl::ImageIndex &index) const; 209 210 private: 211 angle::Result setImageHelper(const gl::Context *context, 212 gl::TextureTarget target, 213 size_t level, 214 GLenum internalFormat, 215 const gl::Extents &size, 216 GLenum format, 217 GLenum type, 218 const uint8_t *pixels); 219 // This changes the current pixel unpack state that will have to be reapplied. 220 angle::Result reserveTexImageToBeFilled(const gl::Context *context, 221 gl::TextureTarget target, 222 size_t level, 223 GLenum internalFormat, 224 const gl::Extents &size, 225 GLenum format, 226 GLenum type); 227 angle::Result setSubImageRowByRowWorkaround(const gl::Context *context, 228 gl::TextureTarget target, 229 size_t level, 230 const gl::Box &area, 231 GLenum format, 232 GLenum type, 233 const gl::PixelUnpackState &unpack, 234 const gl::Buffer *unpackBuffer, 235 const uint8_t *pixels); 236 237 angle::Result setSubImagePaddingWorkaround(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 const uint8_t *pixels); 246 247 angle::Result syncTextureStateSwizzle(const gl::Context *context, 248 const FunctionsGL *functions, 249 GLenum name, 250 GLenum value, 251 GLenum *outValue); 252 253 void setLevelInfo(const gl::Context *context, 254 gl::TextureTarget target, 255 size_t level, 256 size_t levelCount, 257 const LevelInfoGL &levelInfo); 258 void setLevelInfo(const gl::Context *context, 259 gl::TextureType type, 260 size_t level, 261 size_t levelCount, 262 const LevelInfoGL &levelInfo); 263 const LevelInfoGL &getLevelInfo(gl::TextureTarget target, size_t level) const; 264 const LevelInfoGL &getBaseLevelInfo() const; 265 266 std::vector<LevelInfoGL> mLevelInfo; 267 gl::Texture::DirtyBits mLocalDirtyBits; 268 269 gl::SwizzleState mAppliedSwizzle; 270 gl::SamplerState mAppliedSampler; 271 GLuint mAppliedBaseLevel; 272 GLuint mAppliedMaxLevel; 273 274 GLuint mTextureID; 275 }; 276 } // namespace rx 277 278 #endif // LIBANGLE_RENDERER_GL_TEXTUREGL_H_ 279