• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ = new Mesh();
23     mesh_->Use();
24 }
25 
~AlgoFilter()26 AlgoFilter::~AlgoFilter()
27 {
28     delete program_;
29     delete mesh_;
30 }
31 
Prepare(ProcessData & data)32 void AlgoFilter::Prepare(ProcessData& data)
33 {
34     glBindTexture(GL_TEXTURE_2D, data.dstTextureID);
35     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data.textureWidth, data.textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
36     glBindFramebuffer(GL_FRAMEBUFFER, data.frameBufferID);
37     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, data.dstTextureID, 0);
38     glViewport(0, 0, data.textureWidth, data.textureHeight);
39     glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
40     glClear(GL_COLOR_BUFFER_BIT);
41 }
42 
Draw(ProcessData & data)43 void AlgoFilter::Draw(ProcessData& data)
44 {
45     Use();
46     glBindVertexArray(mesh_->VAO_);
47     glBindTexture(GL_TEXTURE_2D, data.srcTextureID);
48     glDrawElements(GL_TRIANGLES, DRAW_ELEMENTS_NUMBER, GL_UNSIGNED_INT, 0);
49     glBindFramebuffer(GL_FRAMEBUFFER, 0);
50 }
51 
CreateProgram(const std::string & vertexString,const std::string & fragmentString)52 void AlgoFilter::CreateProgram(const std::string& vertexString, const std::string& fragmentString)
53 {
54     program_ = new Program();
55     program_->Compile(vertexString, fragmentString);
56 }
57 
Use()58 void AlgoFilter::Use()
59 {
60     if (program_ != nullptr) {
61         program_->UseProgram();
62     }
63 }
64 
GetFilterType()65 FILTER_TYPE AlgoFilter::GetFilterType()
66 {
67     return FILTER_TYPE::ALGOFILTER;
68 }
69 
DoProcess(ProcessData & data)70 void AlgoFilter::DoProcess(ProcessData& data)
71 {
72     Prepare(data);
73     LoadFilterParams();
74     Draw(data);
75 }
76 } // namespcae Rosen
77 } // namespace OHOS