]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_fbo_state.h
Initial vogl checkin
[vogl] / src / voglcommon / vogl_fbo_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_fbo_state.h
27 #ifndef VOGL_FBO_STATE_H
28 #define VOGL_FBO_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
37 class vogl_framebuffer_attachment
38 {
39 public:
40     vogl_framebuffer_attachment();
41     ~vogl_framebuffer_attachment();
42
43     bool snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLenum attachment, GLenum type);
44
45     bool remap_handles(vogl_handle_remapper &remapper);
46
47     void clear();
48
49     bool serialize(json_node &node) const;
50     bool deserialize(const json_node &node);
51
52     inline GLenum get_attachment() const
53     {
54         return m_attachment;
55     }
56
57     inline GLenum get_type() const
58     {
59         return m_type;
60     }
61
62     inline const GLenum_to_int_map &get_params() const
63     {
64         return m_params;
65     }
66
67     inline int get_param(GLenum pname, GLenum def = GL_NONE) const
68     {
69         return m_params.value(pname, def);
70     }
71
72     inline GLuint get_handle() const
73     {
74         return get_param(GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, 0);
75     }
76
77     bool operator==(const vogl_framebuffer_attachment &rhs) const;
78
79 private:
80     // For default framebuffers, m_attachment is GL_FRONT_LEFT, etc.
81     // Otherwise, it's GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, etc.
82     GLenum m_attachment;
83
84     // GL_NONE, GL_FRAMEBUFFER_DEFAULT, GL_RENDERBUFFER, or GL_TEXTURE
85     GLenum m_type;
86
87     // For all types: GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
88     // For default: GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE, etc.
89     // For textures: GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE, etc.
90     GLenum_to_int_map m_params;
91 };
92
93 class vogl_framebuffer_state : public vogl_gl_object_state
94 {
95 public:
96     vogl_framebuffer_state();
97     virtual ~vogl_framebuffer_state();
98
99     virtual vogl_gl_object_state_type get_type() const
100     {
101         return cGLSTFramebuffer;
102     }
103     virtual vogl_namespace_t get_handle_namespace() const
104     {
105         return VOGL_NAMESPACE_FRAMEBUFFERS;
106     }
107
108     // Creates snapshot of FBO handle, or 0 for the default framebuffer.
109     virtual bool snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 handle, GLenum target);
110
111     // Creates and restores an FBO, assumes textures/RBO's have been already restored.
112     virtual bool restore(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLuint64 &handle) const;
113
114     virtual bool remap_handles(vogl_handle_remapper &remapper);
115
116     virtual void clear();
117
118     virtual bool serialize(json_node &node, vogl_blob_manager &blob_manager) const;
119     virtual bool deserialize(const json_node &node, const vogl_blob_manager &blob_manager);
120
121     virtual GLuint64 get_snapshot_handle() const
122     {
123         return m_snapshot_handle;
124     }
125
126     virtual bool is_valid() const
127     {
128         return m_is_valid;
129     }
130
131     virtual bool compare_restorable_state(const vogl_gl_object_state &rhs_obj) const;
132
133     typedef vogl::map<GLenum, vogl_framebuffer_attachment> GLenum_to_attachment_map;
134     const GLenum_to_attachment_map &get_attachments() const
135     {
136         return m_attachments;
137     }
138
139     // GL_FRAMEBUFFER_COMPLETE, etc.
140     GLenum get_status() const
141     {
142         return m_status;
143     }
144
145     uint get_read_buffer() const
146     {
147         return m_read_buffer;
148     }
149
150     const uint_vec &get_draw_buffers() const
151     {
152         return m_draw_buffers;
153     }
154
155 private:
156     GLuint m_snapshot_handle;
157     bool m_has_been_bound;
158
159     GLenum_to_attachment_map m_attachments;
160
161     uint_vec m_draw_buffers;
162     uint m_read_buffer;
163
164     GLenum m_status;
165
166     bool m_is_valid;
167 };
168
169 namespace vogl
170 {
171     VOGL_DEFINE_BITWISE_MOVABLE(vogl_framebuffer_attachment);
172     VOGL_DEFINE_BITWISE_MOVABLE(vogl_framebuffer_state);
173 }
174
175 #endif // #ifndef VOGL_FBO_STATE_H