1 /*
2  * Copyright (c) 2021-2023 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 WEBGL_PROGRAM_H
17 #define WEBGL_PROGRAM_H
18 
19 #include "napi/n_exporter.h"
20 #include "webgl_object.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 
25 class WebGLProgram final : public NExporter, public WebGLObject {
26 public:
27     inline static const std::string className = "WebGLProgram";
28     inline static const int objectType = WEBGL_OBJECT_PROGRAM;
29     inline static const int DEFAULT_PROGRAM_ID = 0;
30 
31     bool Export(napi_env env, napi_value exports) override;
32     std::string GetClassName() override;
33     static napi_value Constructor(napi_env env, napi_callback_info info);
CreateObjectInstance(napi_env env,WebGLProgram ** instance)34     static NVal CreateObjectInstance(napi_env env, WebGLProgram** instance)
35     {
36         return WebGLObject::CreateObjectInstance<WebGLProgram>(env, instance);
37     }
38 
GetObjectInstance(napi_env env,napi_value obj)39     static WebGLProgram* GetObjectInstance(napi_env env, napi_value obj)
40     {
41         return WebGLObject::GetObjectInstance<WebGLProgram>(env, obj);
42     }
43 
SetProgramId(uint32_t programId)44     void SetProgramId(uint32_t programId)
45     {
46         programId_ = programId;
47     }
48 
GetProgramId()49     uint32_t GetProgramId() const
50     {
51         return programId_;
52     }
53 
WebGLProgram()54     explicit WebGLProgram() : programId_(0) {};
55     WebGLProgram(napi_env env, napi_value exports);
56     ~WebGLProgram();
57     bool AttachShader(uint32_t index, uint32_t shaderId);
58     bool DetachShader(uint32_t index, uint32_t shaderId);
59 private:
60     GLuint attachedShader_[2] = { 0 }; // 2 is default attachShader type : Vertex shader and Fragment shader.
61     uint32_t programId_;
62 };
63 } // namespace Rosen
64 } // namespace OHOS
65 #endif // WEBGL_PROGRAM_H
66