| 8 | #include "rendertarget.h" |
| 9 | |
| 10 | void RenderTarget::Create(int w, int h, bool hasdepth) |
| 11 | { |
| 12 | hasdepthbuffer = hasdepth; |
| 13 | width = w; |
| 14 | height = h; |
| 15 | |
| 16 | glActiveTexture(GL_TEXTURE0); |
| 17 | glGenTextures(1, &fbo_texture); |
| 18 | glBindTexture(GL_TEXTURE_2D, fbo_texture); |
| 19 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 20 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 21 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 22 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 23 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 24 | glBindTexture(GL_TEXTURE_2D, 0); |
| 25 | |
| 26 | if (hasdepthbuffer) |
| 27 | { |
| 28 | glGenRenderbuffers(1, &rbo_depth); |
| 29 | glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth); |
| 30 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); |
| 31 | glBindRenderbuffer(GL_RENDERBUFFER, 0); |
| 32 | } |
| 33 | |
| 34 | glGenFramebuffers(1, &fbo); |
| 35 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 36 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo_texture, 0); |
| 37 | if (hasdepthbuffer) |
| 38 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_depth); |
| 39 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 40 | } |
| 41 | |
| 42 | void RenderTarget::Resize(int w, int h) |
| 43 | { |
no outgoing calls
no test coverage detected