Minor fixes to gl_hud and gl_framebuffer

- leave framebuffer off by default (and remove SSAO UI from examples)
- fix some resources leakage when toggling SSAO on/off
This commit is contained in:
manuelk 2014-05-16 13:38:25 -07:00
parent b74f45f68d
commit 77b71a0446
4 changed files with 54 additions and 33 deletions

View File

@ -73,14 +73,18 @@ GLFrameBuffer::Init(int width, int height) {
if (not _program)
_program = compileProgram(g_framebufferShaderSource);
glGenVertexArrays(1, &_vao);
if (not _vao) {
glGenVertexArrays(1, &_vao);
}
glBindVertexArray(_vao);
glGenBuffers(1, &_vbo);
float pos[] = { -1, -1, 1, -1, -1, 1, 1, 1 };
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(pos), pos, GL_STATIC_DRAW);
if (not _vbo) {
glGenBuffers(1, &_vbo);
static float pos[] = { -1, -1, 1, -1, -1, 1, 1, 1 };
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(pos), pos, GL_STATIC_DRAW);
}
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glEnableVertexAttribArray(0);
@ -89,28 +93,37 @@ GLFrameBuffer::Init(int width, int height) {
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenFramebuffers(1, &_frameBuffer);
glGenTextures(1, &_frameBufferColor);
glGenTextures(1, &_frameBufferNormal);
glGenTextures(1, &_frameBufferDepthTexture);
if (not _frameBuffer) {
glGenFramebuffers(1, &_frameBuffer);
glBindTexture(GL_TEXTURE_2D, _frameBufferColor);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, _frameBufferNormal);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (not _frameBufferColor) {
glGenTextures(1, &_frameBufferColor);
glBindTexture(GL_TEXTURE_2D, _frameBufferColor);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
if (not _frameBufferNormal) {
glGenTextures(1, &_frameBufferNormal);
glBindTexture(GL_TEXTURE_2D, _frameBufferNormal);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
glBindTexture(GL_TEXTURE_2D, _frameBufferDepthTexture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (not _frameBufferDepthTexture) {
glGenTextures(1, &_frameBufferDepthTexture);
glBindTexture(GL_TEXTURE_2D, _frameBufferDepthTexture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
}
glBindTexture(GL_TEXTURE_2D, 0);
checkGLErrors("FrameBuffer::Init");

View File

@ -192,12 +192,6 @@ GLhud::Init(int width, int height)
glBindBuffer(GL_ARRAY_BUFFER, 0);
checkGLErrors("GLhud::Init");
_frameBuffer = new SSAOGLFrameBuffer;
_frameBuffer->Init(width, height);
_frameBuffer->BuildUI(this, 10, 600);
}
void
@ -214,7 +208,9 @@ GLhud::Rebuild(int width, int height)
&getStaticVboSource()[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GetFrameBuffer()->Reshape(width, height);
if (GetFrameBuffer()) {
GetFrameBuffer()->Reshape(width, height);
}
}
bool

View File

@ -42,6 +42,14 @@ public:
virtual void Rebuild(int width, int height);
virtual bool Flush();
void SetFrameBuffer(GLFrameBuffer * frameBuffer) {
if (not _frameBuffer) {
_frameBuffer = frameBuffer;
_frameBuffer->Init(GetWidth(), GetHeight());
_frameBuffer->BuildUI(this, 10, 600);
}
}
GLFrameBuffer * GetFrameBuffer() {
return _frameBuffer;

View File

@ -1726,7 +1726,11 @@ initHUD()
// window size might not match framebuffer size on a high DPI display
glfwGetWindowSize(g_window, &windowWidth, &windowHeight);
#endif
g_hud.Init(windowWidth, windowHeight);
g_hud.SetFrameBuffer(new SSAOGLFrameBuffer);
g_hud.AddCheckBox("Cage Edges (H)", g_drawCageEdges != 0,
10, 10, callbackCheckBox, kHUD_CB_DISPLAY_CAGE_EDGES, 'h');