]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_arb_program_state.h
Initial vogl checkin
[vogl] / src / voglcommon / vogl_arb_program_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_arb_program_state.h
27 #ifndef VOGL_ARB_PROGRAM_STATE_H
28 #define VOGL_ARB_PROGRAM_STATE_H
29
30 #include "vogl_common.h"
31 #include "vogl_dynamic_string.h"
32 #include "vogl_json.h"
33 #include "vogl_map.h"
34
35 #include "vogl_general_context_state.h"
36 #include "vogl_blob_manager.h"
37
38 typedef vogl::vector<vec4F> vec4F_vec;
39
40 class vogl_arb_program_state : public vogl_gl_object_state
41 {
42 public:
43     vogl_arb_program_state();
44     virtual ~vogl_arb_program_state();
45
46     virtual vogl_gl_object_state_type get_type() const
47     {
48         return cGLSTARBProgram;
49     }
50     virtual vogl_namespace_t get_handle_namespace() const
51     {
52         return VOGL_NAMESPACE_PROGRAM_ARB;
53     }
54
55     virtual bool snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 handle, GLenum target);
56
57     virtual bool restore(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 &handle) const;
58
59     virtual bool remap_handles(vogl_handle_remapper &remapper);
60
61     virtual void clear();
62
63     virtual bool is_valid() const
64     {
65         return m_is_valid;
66     }
67
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);
70
71     virtual GLuint64 get_snapshot_handle() const
72     {
73         return m_snapshot_handle;
74     }
75
76     virtual bool compare_restorable_state(const vogl_gl_object_state &rhs) const;
77
78     GLenum get_target() const
79     {
80         return m_target;
81     }
82
83     int get_error_position() const
84     {
85         return m_error_position;
86     }
87     const dynamic_string &get_error_string() const
88     {
89         return m_error_string;
90     }
91     bool is_native() const
92     {
93         return m_is_native;
94     }
95
96     GLenum get_program_format() const
97     {
98         return m_program_format;
99     }
100     const uint8_vec &get_program_string() const
101     {
102         return m_program_string;
103     }
104
105     uint get_program_string_size() const
106     {
107         return m_program_string.size();
108     }
109
110     const vec4F_vec &get_program_local_params() const
111     {
112         return m_local_params;
113     }
114     GLint get_num_instructions() const
115     {
116         return m_num_instructions;
117     }
118
119 private:
120     GLuint m_snapshot_handle;
121     GLenum m_target;
122
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;
127
128     GLint m_num_instructions;
129
130     GLenum m_program_format;
131     uint8_vec m_program_string;
132     vec4F_vec m_local_params;
133
134     bool m_is_valid;
135
136     GLint get_program_int(GLenum pname) const;
137 };
138
139 class vogl_arb_program_environment_state
140 {
141 public:
142     vogl_arb_program_environment_state();
143     ~vogl_arb_program_environment_state();
144
145     bool snapshot(const vogl_context_info &context_info);
146
147     bool restore(const vogl_context_info &context_info, vogl_handle_remapper &trace_to_replay_remapper) const;
148
149     bool remap_handles(vogl_handle_remapper &remapper);
150
151     void clear();
152
153     bool is_valid() const
154     {
155         return m_is_valid;
156     }
157
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);
160
161     enum
162     {
163         cVertexTarget,
164         cFragmentTarget,
165         cNumTargets
166     };
167
168     GLuint get_cur_program(uint index) const
169     {
170         return m_cur_programs[index];
171     }
172
173     const vec4F_vec &get_env_params(uint index) const
174     {
175         return m_env_params[index];
176     }
177
178     bool compare_restorable_state(const vogl_arb_program_environment_state &rhs) const;
179
180     static GLenum get_target_enum(uint index)
181     {
182         VOGL_ASSERT(index < cNumTargets);
183         return (index == cVertexTarget) ? GL_VERTEX_PROGRAM_ARB : GL_FRAGMENT_PROGRAM_ARB;
184     }
185
186 private:
187     GLuint m_cur_programs[cNumTargets];
188
189     vec4F_vec m_env_params[cNumTargets];
190     bool m_is_valid;
191
192     static const char *get_target_index_name(uint index)
193     {
194         VOGL_ASSERT(index < cNumTargets);
195         return (index == cVertexTarget) ? "vertex" : "fragment";
196     }
197 };
198
199 #endif // VOGL_ARB_PROGRAM_STATE_H