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_fbo_state.h
27 #ifndef VOGL_FBO_STATE_H
28 #define VOGL_FBO_STATE_H
30 #include "vogl_dynamic_string.h"
31 #include "vogl_json.h"
34 #include "vogl_common.h"
35 #include "vogl_general_context_state.h"
37 class vogl_framebuffer_attachment
40 vogl_framebuffer_attachment();
41 ~vogl_framebuffer_attachment();
43 bool snapshot(const vogl_context_info &context_info, vogl_handle_remapper &remapper, GLenum attachment, GLenum type);
45 bool remap_handles(vogl_handle_remapper &remapper);
49 bool serialize(json_node &node) const;
50 bool deserialize(const json_node &node);
52 inline GLenum get_attachment() const
57 inline GLenum get_type() const
62 inline const GLenum_to_int_map &get_params() const
67 inline int get_param(GLenum pname, GLenum def = GL_NONE) const
69 return m_params.value(pname, def);
72 inline GLuint get_handle() const
74 return get_param(GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, 0);
77 bool operator==(const vogl_framebuffer_attachment &rhs) const;
80 // For default framebuffers, m_attachment is GL_FRONT_LEFT, etc.
81 // Otherwise, it's GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, etc.
84 // GL_NONE, GL_FRAMEBUFFER_DEFAULT, GL_RENDERBUFFER, or GL_TEXTURE
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;
93 class vogl_framebuffer_state : public vogl_gl_object_state
96 vogl_framebuffer_state();
97 virtual ~vogl_framebuffer_state();
99 virtual vogl_gl_object_state_type get_type() const
101 return cGLSTFramebuffer;
103 virtual vogl_namespace_t get_handle_namespace() const
105 return VOGL_NAMESPACE_FRAMEBUFFERS;
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);
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;
114 virtual bool remap_handles(vogl_handle_remapper &remapper);
116 virtual void clear();
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);
121 virtual GLuint64 get_snapshot_handle() const
123 return m_snapshot_handle;
126 virtual bool is_valid() const
131 virtual bool compare_restorable_state(const vogl_gl_object_state &rhs_obj) const;
133 typedef vogl::map<GLenum, vogl_framebuffer_attachment> GLenum_to_attachment_map;
134 const GLenum_to_attachment_map &get_attachments() const
136 return m_attachments;
139 // GL_FRAMEBUFFER_COMPLETE, etc.
140 GLenum get_status() const
145 uint get_read_buffer() const
147 return m_read_buffer;
150 const uint_vec &get_draw_buffers() const
152 return m_draw_buffers;
156 GLuint m_snapshot_handle;
157 bool m_has_been_bound;
159 GLenum_to_attachment_map m_attachments;
161 uint_vec m_draw_buffers;
171 VOGL_DEFINE_BITWISE_MOVABLE(vogl_framebuffer_attachment);
172 VOGL_DEFINE_BITWISE_MOVABLE(vogl_framebuffer_state);
175 #endif // #ifndef VOGL_FBO_STATE_H