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_SHADER_PASS_PROGRAM_H 17 #define OH_VEF_GRAPHICS_SHADER_PASS_PROGRAM_H 18 19 #include <GLES3/gl3.h> 20 #include "render/graphics/base/math/render_matrix.h" 21 #include "render/graphics/base/math/render_vector.h" 22 #include "render/graphics/base/render_context.h" 23 #include "render_general_program.h" 24 25 namespace OHOS { 26 namespace Media { 27 class ShaderPassProgram { 28 public: 29 ShaderPassProgram(RenderContext* context, const std::string& vertex, const std::string& fragment); 30 ~ShaderPassProgram(); 31 32 void Bind(); 33 void Unbind(); 34 35 int GetAttributeLocation(std::string attributeName); 36 37 int GetUniformLocation(std::string uniformName); 38 39 void SetInt(std::string name, int value); 40 41 void SetFloat(std::string name, float value); 42 43 void SetVec2(std::string name, Vec2 value); 44 45 void SetVec3(std::string name, Vec3 value); 46 47 void SetVec4(std::string name, Vec4 value); 48 49 void SetMat2(std::string name, Mat2x2 value); 50 51 void SetMat3(std::string name, Mat3x3 value); 52 53 void SetMat4(std::string name, Mat4x4 value); 54 55 void BindTexture(std::string name, int unitId, int textureId, GLenum target = GL_TEXTURE_2D); 56 57 void UnBindTexture(int unitId); 58 59 std::shared_ptr<RenderGeneralProgram> GetShader(); 60 61 private: 62 std::shared_ptr<RenderGeneralProgram> shader_ = nullptr; 63 RenderContext* context_ = nullptr; 64 std::string vertexShaderCode_; 65 std::string fragmentShaderCode_; 66 }; 67 } 68 } 69 70 #endif