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 OH_VEF_GRAPHICS_RENDER_TEXTURE_H 17 #define OH_VEF_GRAPHICS_RENDER_TEXTURE_H 18 19 #include <GLES3/gl3.h> 20 #include "gl_utils.h" 21 #include "render_context.h" 22 #include "render_object.h" 23 24 namespace OHOS { 25 namespace Media { 26 class RenderTexture : public RenderObject { 27 public: 28 RenderTexture(RenderContext* ctx, GLsizei w, GLsizei h, GLenum interFmt = GL_RGBA8) 29 { 30 context_ = ctx; 31 internalFormat_ = interFmt; 32 width_ = w; 33 height_ = h; 34 } 35 ~RenderTexture() override; 36 Width()37 GLsizei Width() 38 { 39 return width_; 40 } Height()41 GLsizei Height() 42 { 43 return height_; 44 } Format()45 GLenum Format() 46 { 47 return internalFormat_; 48 } 49 GetTextureId()50 GLuint GetTextureId() 51 { 52 return textureId_; 53 } 54 Init()55 bool Init() override 56 { 57 if (!IsReady()) { 58 textureId_ = GLUtils::CreateTexture2D(width_, height_, internalFormat_, GL_LINEAR, GL_LINEAR); 59 SetReady(true); 60 } 61 return true; 62 } 63 Release()64 bool Release() override 65 { 66 GLUtils::DeleteTexture(textureId_); 67 textureId_ = GL_ZERO; 68 width_ = 0; 69 height_ = 0; 70 SetReady(false); 71 return true; 72 } 73 74 private: 75 GLuint textureId_{ GL_ZERO }; 76 GLsizei width_{ 0 }; 77 GLsizei height_{ 0 }; 78 GLenum internalFormat_; 79 RenderContext* context_{ nullptr }; 80 }; 81 82 using RenderTexturePtr = std::shared_ptr<RenderTexture>; 83 84 RenderTexturePtr CreateRenderTexture(RenderContext* ctx, GLsizei w, GLsizei h, GLenum interFmt); 85 } 86 } 87 88 #endif