Lagrange
FrameBuffer.h
1/*
2 * Copyright 2019 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <memory>
15#include <vector>
16
17#include <lagrange/ui/types/GLContext.h>
18#include <lagrange/ui/types/Texture.h>
19#include <lagrange/ui/api.h>
20
21namespace lagrange {
22namespace ui {
23
24/*
25 FrameBuffer class
26 Allows setting textures as color and depth attachements
27 Shares ownership of the attached textures
28*/
29class LA_UI_API FrameBuffer
30{
31public:
32 /*
33 Default constructor, the OpenGL FBO is owned by this object
34 */
36
37 /*
38 Uses FBO with custom_id. Acts a wrapper (does not delete the OpenGL FBO)
39 Use for default FBO or FBO allocated somewhere else.
40 */
41 FrameBuffer(GLuint custom_id);
43
44 /*
45 Resizes textures currently bound to this FBO
46 */
47 void resize_attachments(int w, int h);
48
49 void bind();
50
51 /*
52 Unbinds FBO (binds to id=0)
53 */
54 static void unbind();
55
56 void set_depth_attachement(
57 std::shared_ptr<Texture> t,
58 GLenum target = GL_TEXTURE_2D,
59 int mipmap_level = 0);
60
61 void set_color_attachement(
62 unsigned int index,
63 std::shared_ptr<Texture> t,
64 GLenum target = GL_TEXTURE_2D,
65 int mipmap_level = 0);
66
67 GLuint get_id() const;
68
69 bool check_status() const;
70 bool is_srgb() const;
71
72 std::shared_ptr<Texture> get_color_attachement(int index) const;
73 std::shared_ptr<Texture> get_depth_attachment() const;
74
75 static int get_max_color_attachments();
76
77 bool has_color_attachment() const
78 {
79 return m_color_attachments.size() > 0 && (m_color_attachments.front() != nullptr);
80 }
81
82 bool has_depth_attachement() const { return m_depth_attachment != nullptr; }
83
84private:
85 GLuint m_id;
86 std::vector<std::shared_ptr<Texture>> m_color_attachments;
87 std::shared_ptr<Texture> m_depth_attachment;
88 bool m_managed;
89};
90
91} // namespace ui
92} // namespace lagrange
Definition: FrameBuffer.h:30
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30