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_BUFFER_H 17 #define WEBGL_BUFFER_H 18 19 #include "napi/n_exporter.h" 20 #include "webgl_object.h" 21 #include "webgl_arg.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 class WebGLBuffer final : public NExporter, public WebGLObject { 26 public: 27 inline static const std::string className = "WebGLBuffer"; 28 inline static const int objectType = WEBGL_OBJECT_BUFFER; 29 inline static const int DEFAULT_BUFFER = 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); WebGLBuffer()34 explicit WebGLBuffer() : bufferId_(0), target_(0) {}; WebGLBuffer(napi_env env,napi_value exports)35 WebGLBuffer(napi_env env, napi_value exports) : NExporter(env, exports), bufferId_(0), target_(0) {}; 36 ~WebGLBuffer(); SetBufferId(uint32_t bufferId)37 void SetBufferId(uint32_t bufferId) 38 { 39 bufferId_ = bufferId; 40 } 41 GetBufferId()42 uint32_t GetBufferId() const 43 { 44 return bufferId_; 45 } 46 GetTarget()47 GLenum GetTarget() const 48 { 49 return target_; 50 } 51 SetTarget(GLenum target)52 void SetTarget(GLenum target) 53 { 54 target_ = target; 55 } 56 CreateObjectInstance(napi_env env,WebGLBuffer ** instance)57 static NVal CreateObjectInstance(napi_env env, WebGLBuffer** instance) 58 { 59 return WebGLObject::CreateObjectInstance<WebGLBuffer>(env, instance); 60 } 61 SetBuffer(size_t bufferSize,const uint8_t * data)62 void SetBuffer(size_t bufferSize, const uint8_t* data) 63 { 64 bufferSize_ = bufferSize; 65 bufferData_ = data; 66 } 67 GetBufferSize()68 size_t GetBufferSize() const 69 { 70 return bufferSize_; 71 } 72 const uint8_t* bufferData_ { nullptr }; 73 private: 74 uint32_t bufferId_ { 0 }; 75 GLenum target_ { 0 }; 76 size_t bufferSize_ { 0 }; 77 }; 78 } // namespace Rosen 79 } // namespace OHOS 80 #endif // WEBGL_BUFFER_H 81