1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
26 // File: vogl_program_state.h
27 #ifndef VOGL_PROGRAM_STATE_H
28 #define VOGL_PROGRAM_STATE_H
30 #include "vogl_common.h"
31 #include "vogl_dynamic_string.h"
32 #include "vogl_json.h"
34 #include "vogl_unique_ptr.h"
36 #include "vogl_general_context_state.h"
37 #include "vogl_blob_manager.h"
38 #include "vogl_shader_state.h"
40 struct vogl_program_attrib_state
44 dynamic_string m_name;
45 GLint m_bound_location;
55 inline bool operator==(const vogl_program_attrib_state &rhs) const
57 return (m_size == rhs.m_size) && (m_type == rhs.m_type) && (!m_name.compare(rhs.m_name, true)) && (m_bound_location == rhs.m_bound_location);
61 typedef vogl::vector<vogl_program_attrib_state> vogl_attrib_state_vec;
63 struct vogl_program_uniform_state
67 dynamic_string m_name;
68 GLint m_base_location;
69 growable_array<uint8, 16> m_data;
80 inline bool operator==(const vogl_program_uniform_state &rhs) const
82 return (m_size == rhs.m_size) && (m_type == rhs.m_type) && (!m_name.compare(rhs.m_name, true)) && (m_base_location == rhs.m_base_location) && (m_data == rhs.m_data);
86 typedef vogl::vector<vogl_program_uniform_state> vogl_uniform_state_vec;
88 struct vogl_program_uniform_block_state
90 GLuint m_uniform_block_index;
91 dynamic_string m_name;
92 GLint m_uniform_block_binding_point;
93 GLint m_uniform_block_data_size;
94 GLint m_uniform_block_active_uniforms;
98 m_uniform_block_index = 0;
100 m_uniform_block_binding_point = 0;
101 m_uniform_block_data_size = 0;
102 m_uniform_block_active_uniforms = 0;
105 inline bool operator==(const vogl_program_uniform_block_state &rhs) const
110 CMP(m_uniform_block_index)
112 CMP(m_uniform_block_binding_point)
113 CMP(m_uniform_block_data_size)
114 CMP(m_uniform_block_active_uniforms)
120 typedef vogl::vector<vogl_program_uniform_block_state> vogl_uniform_block_state_vec;
122 struct vogl_program_output_state
124 dynamic_string m_name;
126 GLint m_location_index;
130 //GLint m_location_component; // TODO
134 utils::zero_object(*this);
137 inline bool operator==(const vogl_program_output_state &rhs) const
144 CMP(m_location_index);
148 //CMP(m_location_component);
154 typedef vogl::vector<vogl_program_output_state> vogl_program_output_state_vec;
156 struct vogl_program_transform_feedback_varying
159 dynamic_string m_name;
171 inline bool operator==(const vogl_program_transform_feedback_varying &rhs) const
185 typedef vogl::vector<vogl_program_transform_feedback_varying> vogl_program_transform_feedback_varying_vec;
187 class vogl_program_state : public vogl_gl_object_state
190 vogl_program_state();
191 vogl_program_state(const vogl_program_state &other);
192 virtual ~vogl_program_state();
194 vogl_program_state &operator=(const vogl_program_state &rhs);
196 virtual vogl_gl_object_state_type get_type() const
200 virtual vogl_namespace_t get_handle_namespace() const
202 return VOGL_NAMESPACE_PROGRAMS;
205 virtual bool snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 handle, GLenum target);
207 virtual bool restore(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 &handle) const;
209 virtual bool remap_handles(vogl_handle_remapper &remapper);
211 virtual void clear();
213 virtual bool is_valid() const
218 virtual bool serialize(json_node &node, vogl_blob_manager &blob_manager) const;
219 virtual bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager);
221 virtual GLuint64 get_snapshot_handle() const
223 return m_snapshot_handle;
226 virtual bool compare_restorable_state(const vogl_gl_object_state &rhs_obj) const;
228 virtual bool get_marked_for_deletion() const
230 return m_marked_for_deletion;
233 const dynamic_string &get_info_log() const
238 bool link_snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint handle, const void *pBinary = NULL, uint binary_size = 0, GLenum binary_format = GL_NONE);
240 void set_link_time_snapshot(vogl_unique_ptr<vogl_program_state> &pSnapshot);
242 const vogl_unique_ptr<vogl_program_state> &get_link_time_snapshot() const
244 return m_pLink_time_snapshot;
246 vogl_unique_ptr<vogl_program_state> &get_link_time_snapshot()
248 return m_pLink_time_snapshot;
251 bool has_link_time_snapshot() const
253 return m_pLink_time_snapshot.get() != NULL;
256 bool is_link_snapshot() const
258 return m_link_snapshot;
261 bool get_link_status() const
263 return m_link_status;
265 bool get_verify_status() const
267 return m_verify_status;
270 uint get_num_active_attribs() const
272 return m_num_active_attribs;
274 uint get_num_active_uniforms() const
276 return m_num_active_uniforms;
278 uint get_num_active_uniform_blocks() const
280 return m_num_active_uniform_blocks;
283 typedef vogl::vector<GLuint> attached_shader_vec;
284 const attached_shader_vec &get_attached_shaders() const
286 return m_attached_shaders;
289 const vogl_attrib_state_vec &get_attrib_state_vec() const
294 const vogl_uniform_state_vec &get_uniform_state_vec() const
299 const vogl_uniform_block_state_vec &get_uniform_block_state_vec()
301 return m_uniform_blocks;
304 const uint8_vec &get_program_binary() const
306 return m_program_binary;
308 GLenum get_program_binary_format() const
310 return m_program_binary_format;
313 uint get_program_binary_size() const
315 return m_program_binary.size();
318 const vogl_shader_state_vec &get_shaders() const
323 vogl_shader_state_vec &get_shaders()
328 const vogl_program_output_state_vec &get_outputs() const
333 // The LATEST transform feedback mode.
334 GLenum get_transform_feedback_mode() const
336 return m_transform_feedback_mode;
339 // These are the varyings as of the last link, NOT the very latest varyings.
340 uint get_transform_feedback_num_varyings() const
342 return m_transform_feedback_num_varyings;
345 // These are the varyings as of the last link, NOT the very latest varyings.
346 const vogl_program_transform_feedback_varying_vec &get_varyings() const
351 bool compare_full_state(const vogl_program_state &rhs) const;
354 GLuint m_snapshot_handle;
356 uint8_vec m_program_binary;
357 GLenum m_program_binary_format;
359 attached_shader_vec m_attached_shaders;
361 dynamic_string m_info_log;
363 uint m_num_active_attribs;
364 uint m_num_active_uniforms;
365 uint m_num_active_uniform_blocks;
367 vogl_attrib_state_vec m_attribs;
368 vogl_uniform_state_vec m_uniforms;
369 vogl_uniform_block_state_vec m_uniform_blocks;
371 vogl_shader_state_vec m_shaders;
373 vogl_program_output_state_vec m_outputs;
375 vogl_unique_ptr<vogl_program_state> m_pLink_time_snapshot;
377 GLenum m_transform_feedback_mode;
378 uint m_transform_feedback_num_varyings;
379 vogl_program_transform_feedback_varying_vec m_varyings;
381 bool m_marked_for_deletion;
383 bool m_verify_status;
384 bool m_link_snapshot;
388 bool snapshot_uniforms(const vogl_context_info &context_info, vogl_handle_remapper &remapper);
389 bool snapshot_uniform_blocks(const vogl_context_info &context_info, vogl_handle_remapper &remapper);
390 bool snapshot_active_attribs(const vogl_context_info &context_info, vogl_handle_remapper &remapper);
391 bool snapshot_attached_shaders(const vogl_context_info &context_info, vogl_handle_remapper &remapper, bool linked_using_binary);
392 bool snapshot_shader_objects(const vogl_context_info &context_info, vogl_handle_remapper &remapper);
393 bool snapshot_info_log(const vogl_context_info &context_info, vogl_handle_remapper &remapper);
394 bool snapshot_program_binary(const vogl_context_info &context_info, vogl_handle_remapper &remapper);
395 bool snapshot_basic_info(const vogl_context_info &context_info, vogl_handle_remapper &remapper);
396 bool snapshot_outputs(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint program);
397 bool snapshot_transform_feedback(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint program);
398 bool restore_uniforms(uint32 handle32, const vogl_context_info &context_info, vogl_handle_remapper &remapper, bool &any_restore_warnings, bool &any_gl_errors) const;
399 bool restore_uniform_blocks(uint32 handle32, const vogl_context_info &context_info, vogl_handle_remapper &remapper, bool &any_restore_warnings, bool &any_gl_errors) const;
400 bool restore_active_attribs(uint32 handle32, const vogl_context_info &context_info, vogl_handle_remapper &remapper, bool &any_restore_warnings, bool &any_gl_errors) const;
401 bool restore_outputs(uint32 handle32, const vogl_context_info &context_info, vogl_handle_remapper &remapper, bool &any_restore_warnings, bool &any_gl_errors) const;
402 bool restore_transform_feedback(uint32 handle32, const vogl_context_info &context_info, vogl_handle_remapper &remapper, bool &any_restore_warnings, bool &any_gl_errors) const;
403 bool restore_link_snapshot(uint32 handle32, const vogl_context_info &context_info, vogl_handle_remapper &remapper, bool &any_restore_warnings, bool &any_gl_errors, bool &link_succeeded) const;
404 bool link_program(uint32 handle32, const vogl_context_info &context_info, vogl_handle_remapper &remapper, bool &any_restore_warnings, bool &any_gl_errors, bool &link_succeeded) const;
407 typedef vogl::map<GLuint, vogl_program_state> vogl_program_state_map;
409 class vogl_linked_program_state
412 vogl_linked_program_state();
413 vogl_linked_program_state(const vogl_linked_program_state &other);
414 ~vogl_linked_program_state();
416 vogl_linked_program_state &operator=(const vogl_linked_program_state &rhs);
420 bool add_snapshot(GLuint handle, const vogl_program_state &prog);
421 bool add_snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint handle, GLenum binary_format = GL_NONE, const void *pBinary = NULL, uint binary_size = 0);
422 bool remove_snapshot(GLuint handle);
424 const vogl_program_state *find_snapshot(GLuint handle) const;
425 vogl_program_state *find_snapshot(GLuint handle);
427 bool serialize(json_node &node, vogl_blob_manager &blob_manager) const;
428 bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager);
430 bool remap_handles(vogl_handle_remapper &remapper);
432 const vogl_program_state_map &get_linked_program_map() const
434 return m_linked_programs;
437 vogl_program_state_map &get_linked_program_map()
439 return m_linked_programs;
443 vogl_program_state_map m_linked_programs;
446 #endif // VOGL_PROGRAM_STATE_H