• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <GLES3/gl3.h>
17 #include "render/graphics/base/math/math_utils.h"
18 #include "render_program.h"
19 
20 namespace OHOS {
21 namespace Media {
RenderProgram(RenderContext * context)22 RenderProgram::RenderProgram(RenderContext* context) : program_(0), context_(context) {}
23 
SetUniform(const std::string & name,float value)24 void RenderProgram::SetUniform(const std::string& name, float value)
25 {
26     glUniform1f(glGetUniformLocation(program_, name.c_str()), value);
27 }
28 
SetUniform(const std::string & name,int32_t value)29 void RenderProgram::SetUniform(const std::string& name, int32_t value)
30 {
31     glUniform1i(glGetUniformLocation(program_, name.c_str()), value);
32 }
33 
SetUniform(const std::string & name,uint32_t value)34 void RenderProgram::SetUniform(const std::string& name, uint32_t value)
35 {
36     glUniform1ui(glGetUniformLocation(program_, name.c_str()), value);
37 }
38 
SetUniform(const std::string & name,const Vec2 & value)39 void RenderProgram::SetUniform(const std::string& name, const Vec2& value)
40 {
41     glUniform2f(glGetUniformLocation(program_, name.c_str()), value.x, value.y);
42 }
43 
SetUniform(const std::string & name,const Vec3 & value)44 void RenderProgram::SetUniform(const std::string& name, const Vec3& value)
45 {
46     glUniform3f(glGetUniformLocation(program_, name.c_str()), value.x, value.y, value.z);
47 }
48 
SetUniform(const std::string & name,const Vec4 & value)49 void RenderProgram::SetUniform(const std::string& name, const Vec4& value)
50 {
51     glUniform4f(glGetUniformLocation(program_, name.c_str()), value.x, value.y, value.z, value.w);
52 }
53 
SetUniform(const std::string & name,const Mat2x2 & value)54 void RenderProgram::SetUniform(const std::string& name, const Mat2x2& value)
55 {
56     glUniformMatrix2fv(glGetUniformLocation(program_, name.c_str()), 1, GL_FALSE,
57         reinterpret_cast<const GLfloat*>(MathUtils::NativePtr(value)));
58 }
59 
SetUniform(const std::string & name,const Mat3x3 & value)60 void RenderProgram::SetUniform(const std::string& name, const Mat3x3& value)
61 {
62     glUniformMatrix3fv(glGetUniformLocation(program_, name.c_str()), 1, GL_FALSE,
63         reinterpret_cast<const GLfloat*>(MathUtils::NativePtr(value)));
64 }
65 
SetUniform(const std::string & name,const Mat4x4 & value)66 void RenderProgram::SetUniform(const std::string& name, const Mat4x4& value)
67 {
68     glUniformMatrix4fv(glGetUniformLocation(program_, name.c_str()), 1, GL_FALSE,
69         reinterpret_cast<const GLfloat*>(MathUtils::NativePtr(value)));
70 }
71 
Bind()72 void RenderProgram::Bind()
73 {
74     glUseProgram(program_);
75 }
76 
Unbind()77 void RenderProgram::Unbind()
78 {
79     glUseProgram(INVALID_PROGRAM_NAME);
80 }
81 
GetName()82 uint32_t RenderProgram::GetName()
83 {
84     return program_;
85 }
86 
GetAttributeLocation(const std::string & name)87 int32_t RenderProgram::GetAttributeLocation(const std::string& name)
88 {
89     return glGetAttribLocation(program_, name.c_str());
90 }
91 
GetUniformLocation(const std::string & name)92 int32_t RenderProgram::GetUniformLocation(const std::string& name)
93 {
94     return glGetUniformLocation(program_, name.c_str());
95 }
96 }
97 }