xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
framebufferobject.cc
浏览该文件的文档.
3
5 _gl glBindFramebuffer(_gl GL_FRAMEBUFFER, 0);
6}
8 gl::GLuint width, gl::GLuint height, color_format_t color_format,
9 pixel_type_t pixel_type)
10 : texture_(_gl GL_TEXTURE_2D),
11 width_(width),
12 height_(height),
13 color_format_(color_format),
14 pixel_type_(pixel_type) {
15 _gl glGenFramebuffers(1, &fbo_);
16 _gl glBindFramebuffer(_gl GL_FRAMEBUFFER, fbo_);
17 texture_.bind();
18 texture_.image_2d(0, color_format_, width_, height_, 0, color_format_,
19 pixel_type_, nullptr);
20 texture_.parameteri(_gl GL_TEXTURE_MIN_FILTER, _gl GL_LINEAR);
21 texture_.parameteri(_gl GL_TEXTURE_MAG_FILTER, _gl GL_LINEAR);
22 texture_.unbind();
23 _gl glFramebufferTexture2D(_gl GL_FRAMEBUFFER, _gl GL_COLOR_ATTACHMENT0,
24 _gl GL_TEXTURE_2D, texture_.texture_, 0);
25 if (_gl glCheckFramebufferStatus(_gl GL_FRAMEBUFFER) !=
26 _gl GL_FRAMEBUFFER_COMPLETE) {
27 throw std::runtime_error("Framebuffer not complete");
28 }
29};
31 _gl glDeleteFramebuffers(1, &fbo_);
32}
34 _gl glBindFramebuffer(_gl GL_FRAMEBUFFER, fbo_);
35}
36std::vector<char>
38 assert(pixel_type_ == pixel_type_t::UNSIGNED_BYTE);
39 std::vector<char> pixels(width_ * height_ * 4);
40 _gl glReadBuffer(_gl GL_COLOR_ATTACHMENT0);
41 _gl glReadPixels(0, 0, width_, height_, _gl GL_RGBA, _gl GL_UNSIGNED_BYTE,
42 pixels.data());
43 return pixels;
44}
45std::vector<float>
47 assert(pixel_type_ == pixel_type_t::FLOAT);
48 std::vector<float> pixels(width_ * height_ * 4);
49 _gl glReadBuffer(_gl GL_COLOR_ATTACHMENT0);
50 _gl glReadPixels(0, 0, width_, height_, _gl GL_RGBA, _gl GL_FLOAT,
51 pixels.data());
52 return pixels;
53};
std::vector< float > read_pixels_float() const
FramebufferObject(gl::GLuint width, gl::GLuint height, color_format_t color_format=color_format_t::RGBA, pixel_type_t pixel_type=pixel_type_t::UNSIGNED_BYTE)
void bind(gl::GLenum target) const
Definition texture.cc:5
void image_2d(gl::GLint level, color_format_t internalformat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, color_format_t format, pixel_type_t type, const void *data) const
Definition texture.cc:44
void parameteri(gl::GLenum pname, gl::GLenum param) const
Definition texture.cc:12
unsigned int GLuint
Definition typedef.hpp:21