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 static unsigned int CreateFramebuffer(unsigned int textureId = 0);
34 
35     static unsigned int CreateFramebufferWithTarget(unsigned int textureId, GLenum target);
36 
37     IMAGE_EFFECT_EXPORT static void DeleteTexture(unsigned int textureId);
38 
39     IMAGE_EFFECT_EXPORT static void DeleteFboOnly(unsigned int fbo);
40 
41     static unsigned int LoadShader(const std::string &src, unsigned int shaderType);
42 
43     static unsigned int CreateProgram(const std::string &vss, const std::string &fss);
44 
45     IMAGE_EFFECT_EXPORT
46     static GLuint CreateTexWithStorage(GLenum target, int levels, GLenum internalFormat, int width, int height);
47 
48     IMAGE_EFFECT_EXPORT static size_t GetInternalFormatPixelByteSize(GLenum internalFormat);
49 
50     IMAGE_EFFECT_EXPORT static void CheckError(const char *file, int line);
51 
52     static EGLImageKHR CreateEGLImage(EGLDisplay display, SurfaceBuffer *buffer);
53 
54     static GLuint CreateTextureFromImage(EGLImageKHR img);
55 
56     static GLuint CreateTextureFromSurfaceBuffer(SurfaceBuffer *buffer);
57 };
58 } // namespace Effect
59 } // namespace Media
60 } // namespace OHOS
61 #endif // GL_UTILS_H
62