]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_default_framebuffer_state.h
Initial vogl checkin
[vogl] / src / voglcommon / vogl_default_framebuffer_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_default_framebuffer_state.h
27 #ifndef VOGL_DEFAULT_FRAMEBUFFER_STATE_H
28 #define VOGL_DEFAULT_FRAMEBUFFER_STATE_H
29
30 #include "vogl_dynamic_string.h"
31 #include "vogl_json.h"
32 #include "vogl_map.h"
33
34 #include "vogl_common.h"
35 #include "vogl_general_context_state.h"
36 #include "vogl_texture_state.h"
37
38 struct vogl_default_framebuffer_attribs
39 {
40     uint m_width;
41     uint m_height;
42     uint m_r_size;
43     uint m_g_size;
44     uint m_b_size;
45     uint m_a_size;
46     uint m_depth_size;
47     uint m_stencil_size;
48     uint m_samples;
49     bool m_double_buffered;
50
51     vogl_default_framebuffer_attribs()
52     {
53         clear();
54     }
55
56     void clear()
57     {
58         utils::zero_object(*this);
59     }
60
61     bool serialize(json_node &node) const
62     {
63         node.add_key_value("width", m_width);
64         node.add_key_value("height", m_height);
65         node.add_key_value("r_size", m_r_size);
66         node.add_key_value("g_size", m_g_size);
67         node.add_key_value("b_size", m_b_size);
68         node.add_key_value("a_size", m_a_size);
69         node.add_key_value("depth_size", m_depth_size);
70         node.add_key_value("stencil_size", m_stencil_size);
71         node.add_key_value("samples", m_samples);
72         node.add_key_value("double_buffered", m_double_buffered);
73         return true;
74     }
75
76     bool deserialize(const json_node &node)
77     {
78         m_width = node.value_as_uint32("width");
79         m_height = node.value_as_uint32("height");
80         m_r_size = node.value_as_uint32("r_size");
81         m_g_size = node.value_as_uint32("g_size");
82         m_b_size = node.value_as_uint32("b_size");
83         m_a_size = node.value_as_uint32("a_size");
84         m_depth_size = node.value_as_uint32("depth_size");
85         m_stencil_size = node.value_as_uint32("stencil_size");
86         m_samples = node.value_as_uint32("samples");
87         m_double_buffered = node.value_as_bool("double_buffered");
88         return true;
89     }
90 };
91
92 bool vogl_get_default_framebuffer_attribs(vogl_default_framebuffer_attribs &attribs, uint screen);
93
94 enum vogl_default_framebuffer_t
95 {
96     cDefFramebufferFrontLeft,
97     cDefFramebufferBackLeft,
98     cDefFramebufferFrontRight,
99     cDefFramebufferBackRight,
100     cDefFramebufferDepthStencil,
101
102     cDefFramebufferTotal
103 };
104
105 class vogl_default_framebuffer_state
106 {
107 public:
108     vogl_default_framebuffer_state();
109     ~vogl_default_framebuffer_state();
110
111     bool snapshot(const vogl_context_info &context_info, const vogl_default_framebuffer_attribs &fb_attribs);
112     bool restore(const vogl_context_info &context_info) const;
113
114     void clear();
115
116     bool serialize(json_node &node, vogl_blob_manager &blob_manager) const;
117     bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager);
118
119     bool is_valid() const
120     {
121         return m_valid;
122     }
123
124     const vogl_texture_state &get_texture(vogl_default_framebuffer_t index) const
125     {
126         VOGL_ASSERT(index < cDefFramebufferTotal);
127         return m_textures[index];
128     }
129
130     vogl_texture_state &get_texture(vogl_default_framebuffer_t index)
131     {
132         VOGL_ASSERT(index < cDefFramebufferTotal);
133         return m_textures[index];
134     }
135
136
137 private:
138     vogl_default_framebuffer_attribs m_fb_attribs;
139
140     vogl_texture_state m_textures[cDefFramebufferTotal];
141
142     bool m_valid;
143 };
144
145 #endif // VOGL_DEFAULT_FRAMEBUFFER_STATE_H