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_arb_program_state.h
27 #ifndef VOGL_ARB_PROGRAM_STATE_H
28 #define VOGL_ARB_PROGRAM_STATE_H
30 #include "vogl_common.h"
31 #include "vogl_dynamic_string.h"
32 #include "vogl_json.h"
35 #include "vogl_general_context_state.h"
36 #include "vogl_blob_manager.h"
38 typedef vogl::vector<vec4F> vec4F_vec;
40 class vogl_arb_program_state : public vogl_gl_object_state
43 vogl_arb_program_state();
44 virtual ~vogl_arb_program_state();
46 virtual vogl_gl_object_state_type get_type() const
48 return cGLSTARBProgram;
50 virtual vogl_namespace_t get_handle_namespace() const
52 return VOGL_NAMESPACE_PROGRAM_ARB;
55 virtual bool snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 handle, GLenum target);
57 virtual bool restore(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 &handle) const;
59 virtual bool remap_handles(vogl_handle_remapper &remapper);
63 virtual bool is_valid() const
68 virtual bool serialize(json_node &node, vogl_blob_manager &blob_manager) const;
69 virtual bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager);
71 virtual GLuint64 get_snapshot_handle() const
73 return m_snapshot_handle;
76 virtual bool compare_restorable_state(const vogl_gl_object_state &rhs) const;
78 GLenum get_target() const
83 int get_error_position() const
85 return m_error_position;
87 const dynamic_string &get_error_string() const
89 return m_error_string;
91 bool is_native() const
96 GLenum get_program_format() const
98 return m_program_format;
100 const uint8_vec &get_program_string() const
102 return m_program_string;
105 uint get_program_string_size() const
107 return m_program_string.size();
110 const vec4F_vec &get_program_local_params() const
112 return m_local_params;
114 GLint get_num_instructions() const
116 return m_num_instructions;
120 GLuint m_snapshot_handle;
123 // only valid on restore, we can't query this on snapshotting unless we're willing to resubmit the string (which could have other consequences)
124 mutable GLint m_error_position; // -1 if program compiled successfuly
125 mutable dynamic_string m_error_string;
126 mutable bool m_is_native;
128 GLint m_num_instructions;
130 GLenum m_program_format;
131 uint8_vec m_program_string;
132 vec4F_vec m_local_params;
136 GLint get_program_int(GLenum pname) const;
139 class vogl_arb_program_environment_state
142 vogl_arb_program_environment_state();
143 ~vogl_arb_program_environment_state();
145 bool snapshot(const vogl_context_info &context_info);
147 bool restore(const vogl_context_info &context_info, vogl_handle_remapper &trace_to_replay_remapper) const;
149 bool remap_handles(vogl_handle_remapper &remapper);
153 bool is_valid() const
158 bool serialize(json_node &node, vogl_blob_manager &blob_manager) const;
159 bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager);
168 GLuint get_cur_program(uint index) const
170 return m_cur_programs[index];
173 const vec4F_vec &get_env_params(uint index) const
175 return m_env_params[index];
178 bool compare_restorable_state(const vogl_arb_program_environment_state &rhs) const;
180 static GLenum get_target_enum(uint index)
182 VOGL_ASSERT(index < cNumTargets);
183 return (index == cVertexTarget) ? GL_VERTEX_PROGRAM_ARB : GL_FRAGMENT_PROGRAM_ARB;
187 GLuint m_cur_programs[cNumTargets];
189 vec4F_vec m_env_params[cNumTargets];
192 static const char *get_target_index_name(uint index)
194 VOGL_ASSERT(index < cNumTargets);
195 return (index == cVertexTarget) ? "vertex" : "fragment";
199 #endif // VOGL_ARB_PROGRAM_STATE_H