]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_general_context_state.h
Initial vogl checkin
[vogl] / src / voglcommon / vogl_general_context_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_general_context_state.h
27 #ifndef VOGL_BASIC_CONTEXT_STATE_H
28 #define VOGL_BASIC_CONTEXT_STATE_H
29
30 #include "vogl_context_info.h"
31 #include "vogl_state_vector.h"
32 #include "vogl_blob_manager.h"
33 #include "vogl_gl_object.h"
34
35 bool vogl_gl_enum_is_dependent_on_client_active_texture(GLenum enum_val);
36 bool vogl_gl_enum_is_dependent_on_active_texture(GLenum enum_val);
37
38 class vogl_general_context_state : public vogl_state_vector
39 {
40 public:
41     vogl_general_context_state();
42
43     // Snapshots current context
44     bool snapshot(const vogl_context_info &context_info);
45
46     // Restores state to current context
47     class vogl_persistent_restore_state
48     {
49     public:
50         vogl_persistent_restore_state()
51             : m_pSelect_buffer(NULL)
52         {
53             VOGL_FUNC_TRACER
54         }
55
56         void clear()
57         {
58             VOGL_FUNC_TRACER
59
60             m_pSelect_buffer = NULL;
61         }
62
63         // May be NULL, if so the selection buffer can't be restored
64         vogl::vector<GLuint> *m_pSelect_buffer;
65     };
66
67     bool restore(const vogl_context_info &context_info, vogl_handle_remapper &remapper, vogl_persistent_restore_state &persistent_state) const;
68
69     bool remap_handles(vogl_handle_remapper &remapper);
70
71 private:
72     bool can_snapshot_state(const vogl_context_info &context_info, vogl_snapshot_context_info &context, uint get_desc_index);
73     bool snapshot_state(const vogl_context_info &context_info, vogl_snapshot_context_info &context, uint get_desc_index, uint index, bool indexed_variant);
74     bool restore_buffer_binding(GLenum binding_enum, GLenum set_enum, vogl_handle_remapper &remapper) const;
75     bool restore_buffer_binding_range(GLenum binding_enum, GLenum start_enum, GLenum size_enum, GLenum set_enum, uint index, bool indexed_variant, vogl_handle_remapper &remapper) const;
76     bool snapshot_active_queries(const vogl_context_info &context_info);
77 };
78
79 class vogl_polygon_stipple_state
80 {
81 public:
82     vogl_polygon_stipple_state();
83     ~vogl_polygon_stipple_state();
84
85     bool snapshot(const vogl_context_info &context_info);
86     bool restore(const vogl_context_info &context_info) const;
87
88     void clear();
89
90     bool is_valid() const
91     {
92         return m_valid;
93     }
94
95     bool serialize(json_node &node, vogl_blob_manager &blob_manager) const;
96     bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager);
97
98     uint get_num_pattern_rows() const;
99     uint32 get_pattern_row(uint rowIndex) const;
100
101 private:
102     bool m_valid;
103     uint32 m_pattern[32];
104 };
105
106 #endif // VOGL_BASIC_CONTEXT_STATE_H