1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef GL_UTILS_H 17 #define GL_UTILS_H 18 19 #include "render_context.h" 20 #include "base/render_base.h" 21 #include "surface_buffer.h" 22 #include "image_effect_marco_define.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace Effect { 27 class GLUtils { 28 public: 29 IMAGE_EFFECT_EXPORT 30 static GLuint CreateTexture2D(GLsizei width, GLsizei height, GLsizei levels, GLenum internalFormat, 31 GLint minFilter, GLint magFilter, GLint wrapS, GLint wrapT); 32 33 IMAGE_EFFECT_EXPORT 34 static void CreateDefaultTexture(GLsizei width, GLsizei height, GLenum internalFormat, GLuint textureId); 35 36 IMAGE_EFFECT_EXPORT static unsigned int CreateFramebuffer(unsigned int textureId = 0); 37 38 static unsigned int CreateFramebufferWithTarget(unsigned int textureId, GLenum target); 39 40 IMAGE_EFFECT_EXPORT static void DeleteTexture(unsigned int textureId); 41 42 IMAGE_EFFECT_EXPORT static void DeleteFboOnly(unsigned int fbo); 43 44 static unsigned int LoadShader(const std::string &src, unsigned int shaderType); 45 46 static unsigned int CreateProgram(const std::string &vss, const std::string &fss); 47 48 IMAGE_EFFECT_EXPORT 49 static GLuint CreateTexWithStorage(GLenum target, int levels, GLenum internalFormat, int width, int height); 50 51 IMAGE_EFFECT_EXPORT static size_t GetInternalFormatPixelByteSize(GLenum internalFormat); 52 53 IMAGE_EFFECT_EXPORT static void CheckError(const char *file, int line); 54 55 static EGLImageKHR CreateEGLImage(EGLDisplay display, SurfaceBuffer *buffer); 56 57 static GLuint CreateTextureFromImage(EGLImageKHR img); 58 59 static GLuint CreateTextureFromSurfaceBuffer(SurfaceBuffer *buffer); 60 61 IMAGE_EFFECT_EXPORT static unsigned int GetTexWidth(GLuint texture); 62 63 IMAGE_EFFECT_EXPORT static unsigned int GetTexHeight(GLuint texture); 64 65 IMAGE_EFFECT_EXPORT static unsigned int GetTexFormat(GLuint texture); 66 67 static void DestroyImage(EGLImageKHR img); 68 69 static void DestroySyncKHR(EGLSyncKHR sync); 70 71 static void CreateSyncKHR(EGLSyncKHR &sync); 72 73 static int32_t GetEGLFenceFd(EGLSyncKHR sync); 74 }; 75 } // namespace Effect 76 } // namespace Media 77 } // namespace OHOS 78 #endif // GL_UTILS_H 79