PeriDyno 1.0.0
Loading...
Searching...
No Matches
Framebuffer.cpp
Go to the documentation of this file.
1#include "Framebuffer.h"
2#include <glad/glad.h>
3#include <iostream>
4#include "Texture.h"
5
6namespace dyno
7{
9 {
10 glGenFramebuffers(1, &id);
11 }
12
14 {
15 glDeleteFramebuffers(1, &id);
16
17 // reset object id
18 id = GL_INVALID_INDEX;
19 }
20
22 {
23 glBindFramebuffer(GL_FRAMEBUFFER, id);
24 int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
25 if (status != GL_FRAMEBUFFER_COMPLETE)
26 {
27 // TODO: error!
28 exit(0);
29 }
30 return status;
31 }
32
33 unsigned int Framebuffer::current()
34 {
35 GLint fbo;
36 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
37 return fbo;
38 }
39
40 void Framebuffer::clearColor(float r, float g, float b, float a)
41 {
42 glBindFramebuffer(GL_FRAMEBUFFER, id);
43 glClearColor(r, g, b, a);
44 glClear(GL_COLOR_BUFFER_BIT);
45 }
46
47 void Framebuffer::clearDepth(float depth)
48 {
49 glBindFramebuffer(GL_FRAMEBUFFER, id);
50 glClearDepth(depth);
51 glClear(GL_DEPTH_BUFFER_BIT);
52 }
53
54 void Framebuffer::bind(unsigned int target)
55 {
56 glBindFramebuffer(target, id);
57 }
58
60 {
61 glBindFramebuffer(GL_FRAMEBUFFER, 0);
62 }
63
64 void Framebuffer::setTexture(unsigned int attachment, const Texture* tex, int level)
65 {
66 glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, tex->target, tex->id, level);
68 }
69
70 void Framebuffer::drawBuffers(int count, const unsigned int* buffers)
71 {
72 glBindFramebuffer(GL_FRAMEBUFFER, id);
73 glDrawBuffers(count, buffers);
74 }
75}
#define glCheckError()
void setTexture(unsigned int attachment, const Texture *tex, int level=0)
void bind(unsigned int target=0x8CA9)
void drawBuffers(int count, const unsigned int *buffers)
static unsigned int current()
void clearColor(float r=0.f, float g=0.f, float b=0.f, float a=1.f)
void clearDepth(float depth=1.f)
void create() override
void release() override
unsigned int target
Definition Texture.h:38
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25