1 /*
2 * Copyright (c) 2022 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 "algo_filter.h"
17
18 namespace OHOS {
19 namespace Rosen {
AlgoFilter()20 AlgoFilter::AlgoFilter()
21 {
22 mesh_ = std::make_shared<Mesh>();
23 mesh_->Use();
24 }
25
Prepare(ProcessData & data)26 void AlgoFilter::Prepare(ProcessData& data)
27 {
28 glBindTexture(GL_TEXTURE_2D, data.dstTextureID);
29 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data.textureWidth, data.textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
30 glBindFramebuffer(GL_FRAMEBUFFER, data.frameBufferID);
31 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, data.dstTextureID, 0);
32 glViewport(0, 0, data.textureWidth, data.textureHeight);
33 glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
34 glClear(GL_COLOR_BUFFER_BIT);
35 }
36
Draw(ProcessData & data)37 void AlgoFilter::Draw(ProcessData& data)
38 {
39 Use();
40 glBindVertexArray(mesh_->VAO_);
41 glBindTexture(GL_TEXTURE_2D, data.srcTextureID);
42 glDrawElements(GL_TRIANGLES, DRAW_ELEMENTS_NUMBER, GL_UNSIGNED_INT, 0);
43 glBindFramebuffer(GL_FRAMEBUFFER, 0);
44 }
45
CreateProgram(const std::string & vertexString,const std::string & fragmentString)46 void AlgoFilter::CreateProgram(const std::string& vertexString, const std::string& fragmentString)
47 {
48 program_ = std::make_shared<Program>();
49 program_->Compile(vertexString, fragmentString);
50 }
51
Use()52 void AlgoFilter::Use()
53 {
54 if (program_ == nullptr) {
55 LOGD("The AlgoFilter Use Program Faild!");
56 return;
57 }
58 program_->UseProgram();
59 }
60
GetFilterType()61 FILTER_TYPE AlgoFilter::GetFilterType()
62 {
63 return FILTER_TYPE::ALGOFILTER;
64 }
65
DoProcess(ProcessData & data)66 void AlgoFilter::DoProcess(ProcessData& data)
67 {
68 Prepare(data);
69 LoadFilterParams();
70 Draw(data);
71 }
72 } // namespcae Rosen
73 } // namespace OHOS