GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
data_buffer.h
Go to the documentation of this file.
1// Copyright 2016 The Draco Authors.
2//
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#ifndef DRACO_CORE_DATA_BUFFER_H_
16#define DRACO_CORE_DATA_BUFFER_H_
17
18#include <cstring>
19#include <ostream>
20#include <vector>
21
23
24namespace draco {
25
26// Buffer descriptor servers as a unique identifier of a buffer.
29 // Id of the data buffer.
30 int64_t buffer_id;
31 // The number of times the buffer content was updated.
33};
34
35// Class used for storing raw buffer data.
37 public:
38 DataBuffer();
39 bool Update(const void *data, int64_t size);
40 bool Update(const void *data, int64_t size, int64_t offset);
41
42 // Reallocate the buffer storage to a new size keeping the data unchanged.
43 void Resize(int64_t new_size);
44 void WriteDataToStream(std::ostream &stream);
45 // Reads data from the buffer. Potentially unsafe, called needs to ensure
46 // the accessed memory is valid.
47 void Read(int64_t byte_pos, void *out_data, size_t data_size) const {
48 memcpy(out_data, data() + byte_pos, data_size);
49 }
50
51 // Writes data to the buffer. Unsafe, caller must ensure the accessed memory
52 // is valid.
53 void Write(int64_t byte_pos, const void *in_data, size_t data_size) {
54 memcpy(const_cast<uint8_t *>(data()) + byte_pos, in_data, data_size);
55 }
56
57 // Copies data from another buffer to this buffer.
58 void Copy(int64_t dst_offset, const DataBuffer *src_buf, int64_t src_offset,
59 int64_t size) {
60 memcpy(const_cast<uint8_t *>(data()) + dst_offset,
61 src_buf->data() + src_offset, size);
62 }
63
64 void set_update_count(int64_t buffer_update_count) {
65 descriptor_.buffer_update_count = buffer_update_count;
66 }
67 int64_t update_count() const { return descriptor_.buffer_update_count; }
68 size_t data_size() const { return data_.size(); }
69 const uint8_t *data() const { return data_.data(); }
70 uint8_t *data() { return data_.data(); }
71 int64_t buffer_id() const { return descriptor_.buffer_id; }
72 void set_buffer_id(int64_t buffer_id) { descriptor_.buffer_id = buffer_id; }
73
74 private:
75 std::vector<uint8_t> data_;
76 // Counter incremented by Update() calls.
77 DataBufferDescriptor descriptor_;
78};
79
80} // namespace draco
81
82#endif // DRACO_CORE_DATA_BUFFER_H_
int64_t buffer_id() const
Definition data_buffer.h:71
bool Update(const void *data, int64_t size)
Definition data_buffer.cc:23
void Resize(int64_t new_size)
Definition data_buffer.cc:49
int64_t update_count() const
Definition data_buffer.h:67
const uint8_t * data() const
Definition data_buffer.h:69
size_t data_size() const
Definition data_buffer.h:68
uint8_t * data()
Definition data_buffer.h:70
void set_update_count(int64_t buffer_update_count)
Definition data_buffer.h:64
void set_buffer_id(int64_t buffer_id)
Definition data_buffer.h:72
DataBuffer()
Definition data_buffer.cc:21
void Write(int64_t byte_pos, const void *in_data, size_t data_size)
Definition data_buffer.h:53
void WriteDataToStream(std::ostream &stream)
Definition data_buffer.cc:54
void Read(int64_t byte_pos, void *out_data, size_t data_size) const
Definition data_buffer.h:47
void Copy(int64_t dst_offset, const DataBuffer *src_buf, int64_t src_offset, int64_t size)
Definition data_buffer.h:58
n< br > font size
Definition meshpage.php:3536
Definition attribute_octahedron_transform.cc:21
Definition data_buffer.h:27
int64_t buffer_id
Definition data_buffer.h:30
DataBufferDescriptor()
Definition data_buffer.h:28
int64_t buffer_update_count
Definition data_buffer.h:32