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