• 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 // BlitGL.h: Defines the BlitGL class, a helper for blitting textures
8 
9 #ifndef LIBANGLE_RENDERER_GL_BLITGL_H_
10 #define LIBANGLE_RENDERER_GL_BLITGL_H_
11 
12 #include "angle_gl.h"
13 #include "common/angleutils.h"
14 #include "libANGLE/Error.h"
15 #include "libANGLE/angletypes.h"
16 #include "libANGLE/renderer/gl/formatutilsgl.h"
17 
18 #include <map>
19 
20 namespace angle
21 {
22 struct FeaturesGL;
23 }  // namespace angle
24 
25 namespace gl
26 {
27 class Framebuffer;
28 class ImageIndex;
29 }  // namespace gl
30 
31 namespace rx
32 {
33 
34 class FramebufferGL;
35 class FunctionsGL;
36 class RenderbufferGL;
37 class StateManagerGL;
38 class TextureGL;
39 struct VertexArrayStateGL;
40 
41 class BlitGL : angle::NonCopyable
42 {
43   public:
44     BlitGL(const FunctionsGL *functions,
45            const angle::FeaturesGL &features,
46            StateManagerGL *stateManager);
47     ~BlitGL();
48 
49     angle::Result copyImageToLUMAWorkaroundTexture(const gl::Context *context,
50                                                    GLuint texture,
51                                                    gl::TextureType textureType,
52                                                    gl::TextureTarget target,
53                                                    GLenum lumaFormat,
54                                                    size_t level,
55                                                    const gl::Rectangle &sourceArea,
56                                                    GLenum internalFormat,
57                                                    gl::Framebuffer *source);
58 
59     angle::Result copySubImageToLUMAWorkaroundTexture(const gl::Context *context,
60                                                       GLuint texture,
61                                                       gl::TextureType textureType,
62                                                       gl::TextureTarget target,
63                                                       GLenum lumaFormat,
64                                                       size_t level,
65                                                       const gl::Offset &destOffset,
66                                                       const gl::Rectangle &sourceArea,
67                                                       gl::Framebuffer *source);
68 
69     angle::Result blitColorBufferWithShader(const gl::Context *context,
70                                             const gl::Framebuffer *source,
71                                             const gl::Framebuffer *dest,
72                                             const gl::Rectangle &sourceArea,
73                                             const gl::Rectangle &destArea,
74                                             GLenum filter,
75                                             bool writeAlpha);
76 
77     angle::Result blitColorBufferWithShader(const gl::Context *context,
78                                             const gl::Framebuffer *source,
79                                             const GLuint destFramebuffer,
80                                             const gl::Rectangle &sourceArea,
81                                             const gl::Rectangle &destArea,
82                                             GLenum filter,
83                                             bool writeAlpha);
84 
85     angle::Result blitColorBufferWithShader(const gl::Context *context,
86                                             const gl::Framebuffer *source,
87                                             const GLuint destTexture,
88                                             const gl::TextureTarget destTarget,
89                                             const size_t destLevel,
90                                             const gl::Rectangle &sourceArea,
91                                             const gl::Rectangle &destArea,
92                                             GLenum filter,
93                                             bool writeAlpha);
94 
95     angle::Result copySubTexture(const gl::Context *context,
96                                  TextureGL *source,
97                                  size_t sourceLevel,
98                                  GLenum sourceComponentType,
99                                  GLuint destID,
100                                  gl::TextureTarget destTarget,
101                                  size_t destLevel,
102                                  GLenum destComponentType,
103                                  const gl::Extents &sourceSize,
104                                  const gl::Rectangle &sourceArea,
105                                  const gl::Offset &destOffset,
106                                  bool needsLumaWorkaround,
107                                  GLenum lumaFormat,
108                                  bool unpackFlipY,
109                                  bool unpackPremultiplyAlpha,
110                                  bool unpackUnmultiplyAlpha,
111                                  bool *copySucceededOut);
112 
113     angle::Result copySubTextureCPUReadback(const gl::Context *context,
114                                             TextureGL *source,
115                                             size_t sourceLevel,
116                                             GLenum sourceSizedInternalFormat,
117                                             TextureGL *dest,
118                                             gl::TextureTarget destTarget,
119                                             size_t destLevel,
120                                             GLenum destFormat,
121                                             GLenum destType,
122                                             const gl::Extents &sourceSize,
123                                             const gl::Rectangle &sourceArea,
124                                             const gl::Offset &destOffset,
125                                             bool needsLumaWorkaround,
126                                             GLenum lumaFormat,
127                                             bool unpackFlipY,
128                                             bool unpackPremultiplyAlpha,
129                                             bool unpackUnmultiplyAlpha);
130 
131     angle::Result copyTexSubImage(const gl::Context *context,
132                                   TextureGL *source,
133                                   size_t sourceLevel,
134                                   TextureGL *dest,
135                                   gl::TextureTarget destTarget,
136                                   size_t destLevel,
137                                   const gl::Rectangle &sourceArea,
138                                   const gl::Offset &destOffset,
139                                   bool *copySucceededOut);
140 
141     angle::Result clearRenderableTexture(const gl::Context *context,
142                                          TextureGL *source,
143                                          GLenum sizedInternalFormat,
144                                          int numTextureLayers,
145                                          const gl::ImageIndex &imageIndex,
146                                          bool *clearSucceededOut);
147 
148     angle::Result clearRenderbuffer(const gl::Context *context,
149                                     RenderbufferGL *source,
150                                     GLenum sizedInternalFormat);
151 
152     angle::Result clearFramebuffer(const gl::Context *context,
153                                    bool colorClear,
154                                    bool depthClear,
155                                    bool stencilClear,
156                                    FramebufferGL *source);
157 
158     angle::Result clearRenderableTextureAlphaToOne(const gl::Context *context,
159                                                    GLuint texture,
160                                                    gl::TextureTarget target,
161                                                    size_t level);
162 
163     angle::Result generateSRGBMipmap(const gl::Context *context,
164                                      TextureGL *source,
165                                      GLuint baseLevel,
166                                      GLuint levelCount,
167                                      const gl::Extents &sourceBaseLevelSize);
168 
169     angle::Result initializeResources(const gl::Context *context);
170 
171   private:
172     angle::Result orphanScratchTextures(const gl::Context *context);
173     angle::Result setScratchTextureParameter(const gl::Context *context,
174                                              GLenum param,
175                                              GLenum value);
176     angle::Result setVAOState(const gl::Context *context);
177     angle::Result initializeVAOState(const gl::Context *context);
178 
179     const FunctionsGL *mFunctions;
180     const angle::FeaturesGL &mFeatures;
181     StateManagerGL *mStateManager;
182 
183     struct BlitProgram
184     {
185         GLuint program                = 0;
186         GLint sourceTextureLocation   = -1;
187         GLint scaleLocation           = -1;
188         GLint offsetLocation          = -1;
189         GLint multiplyAlphaLocation   = -1;
190         GLint unMultiplyAlphaLocation = -1;
191     };
192 
193     angle::Result getBlitProgram(const gl::Context *context,
194                                  gl::TextureType sourceTextureType,
195                                  GLenum sourceComponentType,
196                                  GLenum destComponentType,
197                                  BlitProgram **program);
198 
199     bool mResourcesInitialized = false;
200 
201     // SourceType, SourceComponentType, DestComponentType
202     using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>;
203     std::map<BlitProgramType, BlitProgram> mBlitPrograms;
204 
205     GLuint mScratchTextures[2] = {0};
206     GLuint mScratchFBO         = 0;
207 
208     GLuint mVAO                   = 0;
209     VertexArrayStateGL *mVAOState = nullptr;
210     bool mOwnsVAOState            = false;
211 
212     const GLuint mTexcoordAttribLocation = 0;
213     GLuint mVertexBuffer                 = 0;
214 
215     nativegl::TexImageFormat mSRGBMipmapGenerationFormat;
216 };
217 }  // namespace rx
218 
219 #endif  // LIBANGLE_RENDERER_GL_BLITGL_H_
220