added posteffectmodule

This commit is contained in:
Anselme 2015-12-07 07:18:57 +01:00
parent 87a2c2c906
commit fbc9a5d037
6 changed files with 63 additions and 5 deletions

View File

@ -25,6 +25,9 @@ const char* const ForwardModule::lightStr[] =
void ForwardModule::renderGL(Camera* myCamera, Scene* scene)
{
// bind target
renderTarget->bindFBO();
// render ambient lighting
glAssert(glClearColor(0, 0.1f, 0.05f, 1.)); // add attribute, and setter for clear color
glAssert(glClearDepth(1.0));
@ -163,3 +166,9 @@ void ForwardModule::compileShaders(Scene* scene)
}
}
}
void ForwardModule::setRenderTarget(FrameBuffer* target)
{
if(target != NULL)
renderTarget = target;
}

View File

@ -7,6 +7,7 @@
#include <glew/glew.h>
#include "shadersource.h"
#include "material.h"
#include "framebuffer.h"
class Light;
class Scene;
@ -15,7 +16,10 @@ class PhongEntity;
class ForwardModule : public Module
{
public:
ForwardModule() : shaderSources(NULL) {}
ForwardModule() :
shaderSources(NULL),
renderTarget(FrameBuffer::getScreen())
{}
virtual void renderGL(Camera* myCamera, Scene* scene);
virtual bool requiresModernOpenGL() {return true;} // write some compatibility code to change that to false
@ -25,6 +29,8 @@ public:
void setShaderSource(ShaderSource* source);
void compileShaders(Scene* scene);
void setRenderTarget(FrameBuffer* target);
private:
enum {
// light flags
@ -41,6 +47,7 @@ private:
ShaderSource* shaderSources;
std::vector<Shader*> shaders;
std::vector<unsigned int> flags;
FrameBuffer* renderTarget;
void lightPass(Camera* myCamera, Scene* scene, Light* light, unsigned int type);
};

View File

@ -2,14 +2,18 @@
#include "texture.h"
#include "glassert.h"
FrameBuffer::FrameBuffer()
FrameBuffer::FrameBuffer(bool isNULL)
{
glAssert(glGenFramebuffers(1, &fbo));
if(isNULL)
fbo = 0;
else
glAssert(glGenFramebuffers(1, &fbo));
}
FrameBuffer::~FrameBuffer()
{
glAssert(glDeleteFramebuffers(1, &fbo));
if(fbo != 0)
glAssert(glDeleteFramebuffers(1, &fbo));
}
void FrameBuffer::addTexture(Texture* tex, GLenum attachment)
@ -35,3 +39,11 @@ Texture* FrameBuffer::getTexture(int texId)
{
return textures[texId];
}
FrameBuffer* FrameBuffer::getScreen()
{
static FrameBuffer* screen = NULL;
if(screen != NULL)
screen = new FrameBuffer(true);
return screen;
}

View File

@ -13,13 +13,14 @@ protected:
std::vector<Texture*> textures;
std::vector<GLuint> attachments;
public:
FrameBuffer();
FrameBuffer(bool isNULL = false);
~FrameBuffer();
void addTexture(Texture* tex, GLenum attachment);
void initGL();
void bindFBO();
Texture* getTexture(int texId);
static FrameBuffer* getScreen();
};
#endif // FRAMEBUFFER_H

12
posteffectmodule.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "posteffectmodule.h"
PostEffectModule::PostEffectModule()
{
}
PostEffectModule::~PostEffectModule()
{
}

17
posteffectmodule.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef POSTEFFECTMODULE_H
#define POSTEFFECTMODULE_H
#include "module.h"
class FrameBuffer;
class PostEffectModule : public Module
{
FrameBuffer* inputFBO;
FrameBuffer* outputFBO;
public:
PostEffectModule();
~PostEffectModule();
};
#endif // POSTEFFECTMODULE_H