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_SHADER_H
17 #define WEBGL_SHADER_H
18 
19 #include "napi/n_exporter.h"
20 #include "webgl_object.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 class WebGLShader final : public NExporter, public WebGLObject {
25 public:
26     inline static const std::string className = "WebGLShader";
27     inline static const int objectType = WEBGL_OBJECT_SHADER;
28     inline static const int DEFAULT_SHADER_ID = 0;
29 
30     bool Export(napi_env env, napi_value exports) override;
31     std::string GetClassName() override;
32     static napi_value Constructor(napi_env env, napi_callback_info info);
CreateObjectInstance(napi_env env,WebGLShader ** instance)33     static NVal CreateObjectInstance(napi_env env, WebGLShader** instance)
34     {
35         return WebGLObject::CreateObjectInstance<WebGLShader>(env, instance);
36     }
37 
SetShaderId(uint32_t shaderId)38     void SetShaderId(uint32_t shaderId)
39     {
40         shaderId_ = shaderId;
41     }
42 
GetShaderId()43     uint32_t GetShaderId() const
44     {
45         return shaderId_;
46     }
47 
SetShaderRes(const std::string & res)48     void SetShaderRes(const std::string& res)
49     {
50         res_ = std::move(res);
51     }
52 
GetShaderRes()53     const std::string& GetShaderRes() const
54     {
55         return res_;
56     }
57 
WebGLShader()58     explicit WebGLShader() : shaderId_(0), type_(0) {};
59 
WebGLShader(napi_env env,napi_value exports)60     WebGLShader(napi_env env, napi_value exports) : NExporter(env, exports), shaderId_(0), type_(0) {};
61 
~WebGLShader()62     ~WebGLShader() {};
63 
GetObjectInstance(napi_env env,napi_value obj)64     static WebGLShader* GetObjectInstance(napi_env env, napi_value obj)
65     {
66         return WebGLObject::GetObjectInstance<WebGLShader>(env, obj);
67     }
68 
SetShaderType(GLenum type)69     void SetShaderType(GLenum type)
70     {
71         type_ = type;
72     }
73 
GetShaderType()74     GLenum GetShaderType() const
75     {
76         return type_;
77     }
78 private:
79     std::string res_ = {};
80     uint32_t shaderId_ { 0 };
81     GLenum type_ { 0 };
82 };
83 } // namespace Rosen
84 } // namespace OHOS
85 #endif // WEBGL_SHADER_H
86