1 /*
2  * Copyright (C) 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 OHOS_RENDER_3D_SHADER_INPUT_BUFFER_H
17 #define OHOS_RENDER_3D_SHADER_INPUT_BUFFER_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "data_type/constants.h"
23 
24 namespace OHOS::Render3D {
25 struct ShaderInputBuffer {
26 public:
27     ShaderInputBuffer() = default;
28     ~ShaderInputBuffer();
29     const float* Map(uint32_t floatSize) const; // floatSize are for sanity check if exceed the interal buffer size
30     bool Alloc(uint32_t floatSize); // do alloc if size are different, or do nothing
31     void Delete();
32     bool IsValid() const;
33     void Update(float *buffer, uint32_t floatSize);
34     void Update(float value, uint32_t index);
35     uint32_t FloatSize() const;
36     uint32_t ByteSize() const;
37 
38 private:
39     float *buffer_ = nullptr;
40     uint32_t floatSize_ = 0;
41     static constexpr int max_ = 0x100000;
42     static constexpr uint32_t floatToByte_ = sizeof(float) / sizeof(uint8_t);
43 };
44 } // namespace OHOS::Render3D
45 #endif // OHOS_RENDER_3D_SHADER_INPUT_BUFFER_H
46