]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_gl_object.h
Initial vogl checkin
[vogl] / src / voglcommon / vogl_gl_object.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_gl_object.h
27 #ifndef VOGL_GL_OBJECT_H
28 #define VOGL_GL_OBJECT_H
29
30 #include "vogl_common.h"
31
32 class vogl_blob_manager;
33
34 struct vogl_handle_remapper
35 {
36     virtual ~vogl_handle_remapper()
37     {
38     }
39
40     virtual bool is_default_remapper() const
41     {
42         return true;
43     }
44
45     virtual uint64_t remap_handle(vogl_namespace_t handle_namespace, uint64_t from_handle)
46     {
47         VOGL_FUNC_TRACER
48
49         VOGL_NOTE_UNUSED(handle_namespace);
50         return from_handle;
51     }
52
53     // Note: This may not be fully implemented during tracing!
54     virtual bool is_valid_handle(vogl_namespace_t handle_namespace, uint64_t from_handle)
55     {
56         VOGL_FUNC_TRACER
57
58         VOGL_NOTE_UNUSED(handle_namespace);
59         VOGL_NOTE_UNUSED(from_handle);
60         VOGL_VERIFY(0);
61         return false;
62     }
63
64     virtual int32 remap_location(uint32 program, int32 from_location)
65     {
66         VOGL_FUNC_TRACER
67
68         VOGL_NOTE_UNUSED(program);
69         return from_location;
70     }
71
72     virtual vogl_trace_ptr_value remap_vertex_attrib_ptr(uint index, vogl_trace_ptr_value ptr_val)
73     {
74         VOGL_FUNC_TRACER
75
76         VOGL_NOTE_UNUSED(index);
77         return ptr_val;
78     }
79
80     virtual vogl_trace_ptr_value remap_vertex_array_ptr(vogl_client_side_array_desc_id_t id, uint index, vogl_trace_ptr_value ptr_val)
81     {
82         VOGL_FUNC_TRACER
83
84         VOGL_NOTE_UNUSED(id);
85         VOGL_NOTE_UNUSED(index);
86         return ptr_val;
87     }
88
89     virtual void declare_handle(vogl_namespace_t handle_namespace, uint64_t from_handle, uint64_t to_handle, GLenum target)
90     {
91         VOGL_FUNC_TRACER
92
93         VOGL_NOTE_UNUSED(handle_namespace);
94         VOGL_NOTE_UNUSED(from_handle);
95         VOGL_NOTE_UNUSED(to_handle);
96         VOGL_NOTE_UNUSED(target);
97     }
98
99     virtual void delete_handle_and_object(vogl_namespace_t handle_namespace, uint64_t from_handle, uint64_t to_handle);
100
101     virtual void declare_location(uint32 from_program_handle, uint32 to_program_handle, int32 from_location, int32 to_location)
102     {
103         VOGL_FUNC_TRACER
104
105         VOGL_NOTE_UNUSED(from_program_handle);
106         VOGL_NOTE_UNUSED(to_program_handle);
107         VOGL_NOTE_UNUSED(from_location);
108         VOGL_NOTE_UNUSED(to_location);
109     }
110
111     // Note: This may not be fully implemented during tracing!
112     virtual bool determine_from_object_target(vogl_namespace_t handle_namespace, uint64_t from_handle, GLenum &target)
113     {
114         VOGL_FUNC_TRACER
115
116         VOGL_NOTE_UNUSED(handle_namespace);
117         VOGL_NOTE_UNUSED(from_handle);
118
119         VOGL_VERIFY(0);
120         target = GL_NONE;
121         return false;
122     }
123
124     // Note: This may not be fully implemented during tracing!
125     virtual bool determine_to_object_target(vogl_namespace_t handle_namespace, uint64_t to_handle, GLenum &target)
126     {
127         VOGL_FUNC_TRACER
128
129         VOGL_NOTE_UNUSED(handle_namespace);
130         VOGL_NOTE_UNUSED(to_handle);
131
132         VOGL_VERIFY(0);
133         target = GL_NONE;
134         return false;
135     }
136 };
137
138 // Update this macro if you add more GL state object types!
139 #define VOGL_GL_OBJECT_STATE_TYPES \
140     DEF(Invalid)                  \
141     DEF(Texture)                  \
142     DEF(Renderbuffer)             \
143     DEF(Buffer)                   \
144     DEF(Framebuffer)              \
145     DEF(Query)                    \
146     DEF(Shader)                   \
147     DEF(Program)                  \
148     DEF(Sampler)                  \
149     DEF(VertexArray)              \
150     DEF(Sync)                     \
151     DEF(ARBProgram)
152
153 enum vogl_gl_object_state_type
154 {
155 #define DEF(x) cGLST##x,
156     VOGL_GL_OBJECT_STATE_TYPES
157 #undef DEF
158         cGLSTTotalTypes
159 };
160
161 const char *get_gl_object_state_type_str(vogl_gl_object_state_type type);
162
163 vogl_gl_object_state_type determine_gl_object_state_type_from_str(const char *pStr);
164
165 void vogl_destroy_gl_object(vogl_namespace_t handle_namespace, GLuint64 handle);
166 void vogl_destroy_gl_object(vogl_gl_object_state_type type, GLuint64 handle);
167
168 class vogl_gl_object_state
169 {
170 public:
171     vogl_gl_object_state()
172     {
173     }
174
175     virtual ~vogl_gl_object_state()
176     {
177     }
178
179     virtual vogl_gl_object_state_type get_type() const = 0;
180
181     virtual vogl_namespace_t get_handle_namespace() const = 0;
182
183     virtual bool snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 handle, GLenum target) = 0;
184
185     virtual bool restore(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 &handle) const = 0;
186
187     virtual bool remap_handles(vogl_handle_remapper &remapper) = 0;
188
189     virtual GLuint64 get_snapshot_handle() const = 0;
190
191     virtual void clear() = 0;
192
193     virtual bool is_valid() const = 0;
194
195     virtual bool serialize(json_node &node, vogl_blob_manager &blob_manager) const = 0;
196     virtual bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager) = 0;
197
198     virtual bool compare_restorable_state(const vogl_gl_object_state &rhs) const = 0;
199
200     virtual bool get_marked_for_deletion() const
201     {
202         return false;
203     }
204 };
205
206 typedef vogl::vector<vogl_gl_object_state *> vogl_gl_object_state_ptr_vec;
207 typedef vogl::vector<const vogl_gl_object_state *> vogl_const_gl_object_state_ptr_vec;
208
209 vogl_gl_object_state *vogl_gl_object_state_factory(vogl_gl_object_state_type type);
210
211 #endif // VOGL_GL_OBJECT_H