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 ALGORITHM_PROGRAM_H 17 #define ALGORITHM_PROGRAM_H 18 19 #include "base/render_base.h" 20 #include "core/render_resource_cache.h" 21 #include "graphic/render_context.h" 22 #include "graphic/render_general_program.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace Effect { 27 class AlgorithmProgram { 28 public: 29 AlgorithmProgram(RenderContext *context, const std::string vertex, const std::string fragment); 30 ~AlgorithmProgram(); 31 void UpdateShader(const std::string vertex, const std::string fragment); 32 void Bind(); 33 void Unbind(); 34 int GetAttributeLocation(const std::string attributeName); 35 int GetUniformLocation(const std::string uniformName); 36 void SetInt(const std::string name, int value); 37 void SetFloat(const std::string name, float value); 38 void SetMat4(const std::string name, const void* value); 39 void BindTexture(const std::string name, int unitId, int textureId, GLenum target = GL_TEXTURE_2D); 40 void UnBindTexture(int unitId, GLenum target = GL_TEXTURE_2D); 41 RenderGeneralProgram *GetShader(); 42 private: 43 RenderGeneralProgram *shader_ = nullptr; 44 RenderContext *context_ = nullptr; 45 std::string vertexShaderCode_; 46 std::string fragmentShaderCode_; 47 }; 48 } // namespace Effect 49 } // namespace Media 50 } // namespace OHOS 51 #endif