]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_buffer_state.h
- Features for 10ft: PBO's, snapshotting/restoring mapped buffers during replaying
[vogl] / src / voglcommon / vogl_buffer_state.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 // File: vogl_buffer_state.h
27 #ifndef VOGL_BUFFER_STATE_H
28 #define VOGL_BUFFER_STATE_H
29
30 #include "vogl_core.h"
31 #include "vogl_ktx_texture.h"
32 #include "vogl_context_info.h"
33 #include "vogl_general_context_state.h"
34 #include "vogl_blob_manager.h"
35 #include "vogl_vec.h"
36
37 struct vogl_mapped_buffer_desc;
38
39 class vogl_buffer_state : public vogl_gl_object_state
40 {
41 public:
42     vogl_buffer_state();
43     virtual ~vogl_buffer_state();
44
45     virtual vogl_gl_object_state_type get_type() const
46     {
47         return cGLSTBuffer;
48     }
49     virtual vogl_namespace_t get_handle_namespace() const
50     {
51         return VOGL_NAMESPACE_BUFFERS;
52     }
53
54     virtual bool snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 handle, GLenum target);
55
56     void set_mapped_buffer_snapshot_state(const vogl_mapped_buffer_desc &map_desc);
57
58     virtual bool restore(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 &handle) const;
59
60     virtual bool remap_handles(vogl_handle_remapper &remapper);
61
62     virtual void clear();
63
64     virtual bool is_valid() const
65     {
66         return m_is_valid;
67     }
68
69     virtual bool serialize(json_node &node, vogl_blob_manager &blob_manager) const;
70     virtual bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager);
71
72     virtual GLuint64 get_snapshot_handle() const
73     {
74         return m_snapshot_handle;
75     }
76
77     virtual bool compare_restorable_state(const vogl_gl_object_state &rhs_obj) const;
78
79     GLenum get_target() const
80     {
81         return m_target;
82     }
83
84     const uint8_vec &get_buffer_data() const
85     {
86         return m_buffer_data;
87     }
88     const vogl_state_vector &get_params() const
89     {
90         return m_params;
91     }
92
93     // Whether or not the buffer was currently mapped when it was snapshotted. Note we don't actually support snapshotting the buffer
94     // while it's mapped (we unmap it first), this data comes from the replayer's shadow. We also don't restore it in a mapped state, that's up to the caller.
95     bool get_is_map_range() const { return m_map_range; }
96     bool get_is_mapped() const { return m_is_mapped; }
97     uint64_t get_map_ofs() const { return m_map_ofs; }
98     uint64_t get_map_size() const { return m_map_size; }
99     uint get_map_access() const { return m_map_access; }
100
101 private:
102     GLuint m_snapshot_handle;
103     GLenum m_target;
104
105     uint8_vec m_buffer_data;
106
107     vogl_state_vector m_params;
108
109     uint64_t m_map_ofs;
110     uint64_t m_map_size;
111     uint m_map_access;
112     bool m_map_range;
113     bool m_is_mapped;
114
115     bool m_is_valid;
116 };
117
118 namespace vogl
119 {
120     VOGL_DEFINE_BITWISE_MOVABLE(vogl_buffer_state);
121 }
122
123 #endif // VOGL_BUFFER_STATE_H