1 /* 2 * Copyright (C) 2025 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 RENDER_TEXTURE_H 17 #define RENDER_TEXTURE_H 18 19 #include "gl_utils.h" 20 21 class RenderTexture { 22 public: 23 RenderTexture(GLsizei w, GLsizei h, GLenum interFmt = GL_RGBA8) 24 { 25 internalFormat_ = interFmt; 26 width_ = w; 27 height_ = h; 28 } 29 ~RenderTexture()30 ~RenderTexture() 31 { 32 Release(); 33 } 34 IsReady()35 bool IsReady() const 36 { 37 return isReady_; 38 } 39 SetReady(bool flag)40 void SetReady(bool flag) 41 { 42 isReady_ = flag; 43 } 44 Width()45 unsigned int Width() 46 { 47 return width_; 48 } 49 Height()50 unsigned int Height() 51 { 52 return height_; 53 } 54 Format()55 GLenum Format() 56 { 57 return internalFormat_; 58 } 59 SetName(unsigned int name)60 void SetName(unsigned int name) 61 { 62 name_ = name; 63 } 64 GetName()65 unsigned int GetName() 66 { 67 return name_; 68 } 69 Init()70 bool Init() 71 { 72 if (!IsReady()) { 73 name_ = GLUtils::CreateTexture2D(width_, height_, 1, internalFormat_); 74 SetReady(true); 75 } 76 return true; 77 } 78 Release()79 bool Release() 80 { 81 GLUtils::DeleteTexture(name_); 82 name_ = GL_ZERO; 83 width_ = 0; 84 height_ = 0; 85 SetReady(false); 86 return true; 87 } 88 89 private: 90 GLuint name_{ GL_ZERO }; 91 GLsizei width_{ 0 }; 92 GLsizei height_{ 0 }; 93 GLenum internalFormat_; 94 bool isReady_ = false; 95 }; 96 #endif