Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gltf/structures/gltf_buffer_view.h
21101 views
1
/**************************************************************************/
2
/* gltf_buffer_view.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "../gltf_defines.h"
34
35
#include "core/io/resource.h"
36
37
class GLTFBufferView : public Resource {
38
GDCLASS(GLTFBufferView, Resource);
39
friend class GLTFDocument;
40
41
public:
42
// When a buffer view is used by vertex indices or attribute accessors it SHOULD specify
43
// "target" with a value of ELEMENT_ARRAY_BUFFER (34963) or ARRAY_BUFFER (34962) respectively.
44
// This is only used for mesh data. For non-mesh buffer views, the target should be left blank.
45
// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#buffers-and-buffer-views-overview
46
enum ArrayBufferTarget {
47
TARGET_NONE = 0,
48
TARGET_ARRAY_BUFFER = 34962,
49
TARGET_ELEMENT_ARRAY_BUFFER = 34963,
50
};
51
52
private:
53
GLTFBufferIndex buffer = -1;
54
int64_t byte_offset = 0;
55
int64_t byte_length = 0;
56
int64_t byte_stride = -1;
57
bool indices = false; // True for TARGET_ELEMENT_ARRAY_BUFFER.
58
bool vertex_attributes = false; // True for TARGET_ARRAY_BUFFER.
59
60
protected:
61
static void _bind_methods();
62
63
#ifndef DISABLE_DEPRECATED
64
// Non-const versions for compatibility.
65
GLTFBufferIndex _get_buffer_bind_compat_86907();
66
int _get_byte_offset_bind_compat_86907();
67
int _get_byte_length_bind_compat_86907();
68
int _get_byte_stride_bind_compat_86907();
69
bool _get_indices_bind_compat_86907();
70
static void _bind_compatibility_methods();
71
#endif // DISABLE_DEPRECATED
72
73
public:
74
GLTFBufferIndex get_buffer() const;
75
void set_buffer(GLTFBufferIndex p_buffer);
76
77
int64_t get_byte_offset() const;
78
void set_byte_offset(int64_t p_byte_offset);
79
80
int64_t get_byte_length() const;
81
void set_byte_length(int64_t p_byte_length);
82
83
int64_t get_byte_stride() const;
84
void set_byte_stride(int64_t p_byte_stride);
85
86
bool get_indices() const;
87
void set_indices(bool p_indices);
88
89
bool get_vertex_attributes() const;
90
void set_vertex_attributes(bool p_attributes);
91
92
Vector<uint8_t> load_buffer_view_data(const Ref<GLTFState> p_gltf_state) const;
93
static GLTFBufferViewIndex write_new_buffer_view_into_state(const Ref<GLTFState> &p_gltf_state, const PackedByteArray &p_input_data, const int64_t p_alignment = 1, const ArrayBufferTarget p_target = TARGET_NONE, const int64_t p_byte_stride = -1, const GLTFBufferIndex p_buffer_index = 0, const bool p_deduplicate = true);
94
95
static Ref<GLTFBufferView> from_dictionary(const Dictionary &p_dict);
96
Dictionary to_dictionary() const;
97
};
98
99