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 40 class BlitGL : angle::NonCopyable 41 { 42 public: 43 BlitGL(const FunctionsGL *functions, 44 const angle::FeaturesGL &features, 45 StateManagerGL *stateManager); 46 ~BlitGL(); 47 48 angle::Result copyImageToLUMAWorkaroundTexture(const gl::Context *context, 49 GLuint texture, 50 gl::TextureType textureType, 51 gl::TextureTarget target, 52 GLenum lumaFormat, 53 size_t level, 54 const gl::Rectangle &sourceArea, 55 GLenum internalFormat, 56 gl::Framebuffer *source); 57 58 angle::Result copySubImageToLUMAWorkaroundTexture(const gl::Context *context, 59 GLuint texture, 60 gl::TextureType textureType, 61 gl::TextureTarget target, 62 GLenum lumaFormat, 63 size_t level, 64 const gl::Offset &destOffset, 65 const gl::Rectangle &sourceArea, 66 gl::Framebuffer *source); 67 68 angle::Result blitColorBufferWithShader(const gl::Context *context, 69 const gl::Framebuffer *source, 70 const gl::Framebuffer *dest, 71 const gl::Rectangle &sourceArea, 72 const gl::Rectangle &destArea, 73 GLenum filter, 74 bool writeAlpha); 75 76 angle::Result blitColorBufferWithShader(const gl::Context *context, 77 const gl::Framebuffer *source, 78 const GLuint destFramebuffer, 79 const gl::Rectangle &sourceArea, 80 const gl::Rectangle &destArea, 81 GLenum filter, 82 bool writeAlpha); 83 84 angle::Result blitColorBufferWithShader(const gl::Context *context, 85 const gl::Framebuffer *source, 86 const GLuint destTexture, 87 const gl::TextureTarget destTarget, 88 const size_t destLevel, 89 const gl::Rectangle &sourceArea, 90 const gl::Rectangle &destArea, 91 GLenum filter, 92 bool writeAlpha); 93 94 angle::Result copySubTexture(const gl::Context *context, 95 TextureGL *source, 96 size_t sourceLevel, 97 GLenum sourceComponentType, 98 GLuint destID, 99 gl::TextureTarget destTarget, 100 size_t destLevel, 101 GLenum destComponentType, 102 const gl::Extents &sourceSize, 103 const gl::Rectangle &sourceArea, 104 const gl::Offset &destOffset, 105 bool needsLumaWorkaround, 106 GLenum lumaFormat, 107 bool unpackFlipY, 108 bool unpackPremultiplyAlpha, 109 bool unpackUnmultiplyAlpha, 110 bool *copySucceededOut); 111 112 angle::Result copySubTextureCPUReadback(const gl::Context *context, 113 TextureGL *source, 114 size_t sourceLevel, 115 GLenum sourceSizedInternalFormat, 116 TextureGL *dest, 117 gl::TextureTarget destTarget, 118 size_t destLevel, 119 GLenum destFormat, 120 GLenum destType, 121 const gl::Extents &sourceSize, 122 const gl::Rectangle &sourceArea, 123 const gl::Offset &destOffset, 124 bool needsLumaWorkaround, 125 GLenum lumaFormat, 126 bool unpackFlipY, 127 bool unpackPremultiplyAlpha, 128 bool unpackUnmultiplyAlpha); 129 130 angle::Result copyTexSubImage(const gl::Context *context, 131 TextureGL *source, 132 size_t sourceLevel, 133 TextureGL *dest, 134 gl::TextureTarget destTarget, 135 size_t destLevel, 136 const gl::Rectangle &sourceArea, 137 const gl::Offset &destOffset, 138 bool *copySucceededOut); 139 140 angle::Result clearRenderableTexture(const gl::Context *context, 141 TextureGL *source, 142 GLenum sizedInternalFormat, 143 int numTextureLayers, 144 const gl::ImageIndex &imageIndex, 145 bool *clearSucceededOut); 146 147 angle::Result clearRenderbuffer(const gl::Context *context, 148 RenderbufferGL *source, 149 GLenum sizedInternalFormat); 150 151 angle::Result clearFramebuffer(const gl::Context *context, FramebufferGL *source); 152 153 angle::Result clearRenderableTextureAlphaToOne(const gl::Context *context, 154 GLuint texture, 155 gl::TextureTarget target, 156 size_t level); 157 158 angle::Result generateSRGBMipmap(const gl::Context *context, 159 TextureGL *source, 160 GLuint baseLevel, 161 GLuint levelCount, 162 const gl::Extents &sourceBaseLevelSize); 163 164 angle::Result initializeResources(const gl::Context *context); 165 166 private: 167 angle::Result orphanScratchTextures(const gl::Context *context); 168 angle::Result setScratchTextureParameter(const gl::Context *context, 169 GLenum param, 170 GLenum value); 171 172 const FunctionsGL *mFunctions; 173 const angle::FeaturesGL &mFeatures; 174 StateManagerGL *mStateManager; 175 176 struct BlitProgram 177 { 178 GLuint program = 0; 179 GLint sourceTextureLocation = -1; 180 GLint scaleLocation = -1; 181 GLint offsetLocation = -1; 182 GLint multiplyAlphaLocation = -1; 183 GLint unMultiplyAlphaLocation = -1; 184 }; 185 186 angle::Result getBlitProgram(const gl::Context *context, 187 gl::TextureType sourceTextureType, 188 GLenum sourceComponentType, 189 GLenum destComponentType, 190 BlitProgram **program); 191 192 // SourceType, SourceComponentType, DestComponentType 193 using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>; 194 std::map<BlitProgramType, BlitProgram> mBlitPrograms; 195 196 GLuint mScratchTextures[2]; 197 GLuint mScratchFBO; 198 199 GLuint mVAO; 200 GLuint mVertexBuffer; 201 202 nativegl::TexImageFormat mSRGBMipmapGenerationFormat; 203 }; 204 } // namespace rx 205 206 #endif // LIBANGLE_RENDERER_GL_BLITGL_H_ 207