#include <BloomEffect.h>
Inheritance diagram for pge::BloomEffect:
Public Member Functions | |
BloomEffect (void) | |
Constructor. | |
virtual | ~BloomEffect (void) |
Destructor. | |
bool | init (void) |
void | render (void) |
Called when the object should render itself. | |
int | getTextureSize (void) |
void | renderEffect (void) |
void | renderBlur (int textureIndex) |
void | renderBrightPass (void) |
void | prepareRendering (void) |
void | timer (unsigned int delay) |
Called when the timer event comes. | |
Private Member Functions | |
void | renderToTexture (unsigned int textureTarget, unsigned int internalFormat, int width, int height) |
unsigned int | createTexture2D (int width, int height) |
Private Attributes | |
unsigned int | m_textureTarget [10] |
GPUProgram * | m_brightShader |
GPUProgram * | m_blurShader |
|
Constructor.
Definition at line 30 of file BloomEffect.h. References createTexture2D(), m_blurShader, m_brightShader, m_textureTarget, and RENDER_TEXTURE_SIZE.
00030 { 00031 // Texture 0 contains the scene and later the brightpass image. 00032 m_textureTarget[0] = createTexture2D(RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); 00033 m_textureTarget[1] = createTexture2D(RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); 00034 m_textureTarget[2] = createTexture2D(RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); 00035 00036 m_brightShader = new GPUProgram("../data/shader/brightpass_vs.txt", "../data/shader/brightpass_fs.txt"); 00037 m_blurShader = new GPUProgram("../data/shader/blur_vs.txt", "../data/shader/blur_fs.txt"); 00038 } |
Here is the call graph for this function:
|
Destructor.
Definition at line 47 of file BloomEffect.h. References m_blurShader, m_brightShader, and m_textureTarget.
00047 { 00048 glDeleteTextures(3, m_textureTarget); 00049 00050 if(m_brightShader != NULL) { 00051 delete m_brightShader; 00052 m_brightShader = NULL; 00053 } 00054 if(m_blurShader != NULL) { 00055 delete m_blurShader; 00056 m_blurShader = NULL; 00057 } 00058 } |
|
Definition at line 272 of file BloomEffect.h. Referenced by BloomEffect().
00272 { 00273 unsigned int *data; 00274 unsigned int tex; 00275 00276 00277 // Create texture for rendering to texture. 00278 data = new unsigned int[width * height * 3 * sizeof(int)]; 00279 memset(data, 0, width * height * 3 * sizeof(int)); 00280 glGenTextures(1, &tex); 00281 glBindTexture(GL_TEXTURE_2D, tex); 00282 glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 00283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00284 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 00286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 00287 delete [] data; 00288 00289 return tex; 00290 } |
|
Definition at line 82 of file BloomEffect.h. References RENDER_TEXTURE_SIZE. Referenced by pge::World::render().
00082 { 00083 return RENDER_TEXTURE_SIZE; 00084 } |
|
Implements pge::IRenderableObject. Definition at line 66 of file BloomEffect.h.
00066 { 00067 return true; 00068 } |
|
Definition at line 221 of file BloomEffect.h. References m_textureTarget, RENDER_TEXTURE_SIZE, renderBlur(), renderBrightPass(), and renderToTexture(). Referenced by pge::World::render().
00221 { 00222 00223 // First render the scene to a texture. 00224 renderToTexture(m_textureTarget[0], GL_RGB, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); 00225 00226 // Clear the screen. 00227 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00228 00229 // Go to 2D view. 00230 renderer::enter2DMode(0.0f, (float)CoreEngine::getInstance()->getResolutionWidth(), 0.0f, (float)CoreEngine::getInstance()->getResolutionHeight(), -1.0f, 1.0f); 00231 00232 // Then do the bright pass. 00233 renderBrightPass(); 00234 00235 // Overwrite the old scene texture with the brightpass information. 00236 renderToTexture(m_textureTarget[0], GL_RGB, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); 00237 renderBlur(0); 00238 renderToTexture(m_textureTarget[1], GL_RGB, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); 00239 renderBlur(1); 00240 renderToTexture(m_textureTarget[2], GL_RGB, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); 00241 00242 // Return to 3D mode. 00243 renderer::enter3DMode(); 00244 } |
Here is the call graph for this function:
|
Called when the object should render itself.
Implements pge::IRenderableObject. Definition at line 74 of file BloomEffect.h. References renderEffect(). Referenced by pge::World::render().
00074 { 00075 renderEffect(); 00076 } |
Here is the call graph for this function:
|
Definition at line 165 of file BloomEffect.h. References pge::GPUProgram::bind(), m_blurShader, m_textureTarget, pge::GPUProgram::passUniform1f(), pge::GPUProgram::release(), and RENDER_TEXTURE_SIZE. Referenced by prepareRendering().
00165 { 00166 glEnable(GL_TEXTURE_2D); 00167 glBindTexture(GL_TEXTURE_2D, m_textureTarget[textureIndex]); 00168 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 00169 00170 m_blurShader->bind(); 00171 m_blurShader->passUniform1f("width", (float)RENDER_TEXTURE_SIZE); 00172 m_blurShader->passUniform1f("height", (float)RENDER_TEXTURE_SIZE); 00173 00174 glBegin(GL_QUADS); 00175 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f); 00176 glVertex2i(0, 0); 00177 00178 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f); 00179 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), 0); 00180 00181 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f); 00182 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), CoreEngine::getInstance()->getResolutionHeight()); 00183 00184 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f); 00185 glVertex2i(0, CoreEngine::getInstance()->getResolutionHeight()); 00186 glEnd(); 00187 00188 m_blurShader->release(); 00189 } |
Here is the call graph for this function:
|
Definition at line 195 of file BloomEffect.h. References pge::GPUProgram::bind(), m_brightShader, m_textureTarget, and pge::GPUProgram::release(). Referenced by prepareRendering().
00195 { 00196 00197 glEnable(GL_TEXTURE_2D); 00198 glBindTexture(GL_TEXTURE_2D, m_textureTarget[0]); 00199 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 00200 m_brightShader->bind(); 00201 glBegin(GL_QUADS); 00202 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f); 00203 glVertex2i(0, 0); 00204 00205 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f); 00206 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), 0); 00207 00208 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f); 00209 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), CoreEngine::getInstance()->getResolutionHeight()); 00210 00211 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f); 00212 glVertex2i(0, CoreEngine::getInstance()->getResolutionHeight()); 00213 glEnd(); 00214 m_brightShader->release(); 00215 } |
Here is the call graph for this function:
|
Definition at line 90 of file BloomEffect.h. References m_textureTarget. Referenced by render().
00090 { 00091 float alpha; 00092 00093 00094 //alpha = mathutils::mapValueToInterval(0.0f, 1.0f, 0.0f, 0.2f, DayNightCycle::getInstance()->getDayNightCycle()); 00095 alpha = 0.2f; 00096 00097 if(alpha > 0.0f) { 00098 00099 glDisable(GL_DEPTH_TEST); 00100 00101 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00102 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 00103 glEnable(GL_BLEND); 00104 00105 glColor4f(1.0f, 1.0f, 1.0f, alpha); 00106 00107 glEnable(GL_TEXTURE_2D); 00108 glBindTexture(GL_TEXTURE_2D, m_textureTarget[0]); 00109 glBegin(GL_QUADS); 00110 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f); 00111 glVertex2i(0, 0); 00112 00113 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f); 00114 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), 0); 00115 00116 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f); 00117 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), CoreEngine::getInstance()->getResolutionHeight()); 00118 00119 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f); 00120 glVertex2i(0, CoreEngine::getInstance()->getResolutionHeight()); 00121 glEnd(); 00122 00123 glBindTexture(GL_TEXTURE_2D, m_textureTarget[1]); 00124 glBegin(GL_QUADS); 00125 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f); 00126 glVertex2i(0, 0); 00127 00128 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f); 00129 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), 0); 00130 00131 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f); 00132 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), CoreEngine::getInstance()->getResolutionHeight()); 00133 00134 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f); 00135 glVertex2i(0, CoreEngine::getInstance()->getResolutionHeight()); 00136 glEnd(); 00137 00138 glBindTexture(GL_TEXTURE_2D, m_textureTarget[2]); 00139 glBegin(GL_QUADS); 00140 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f); 00141 glVertex2i(0, 0); 00142 00143 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f); 00144 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), 0); 00145 00146 glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f); 00147 glVertex2i(CoreEngine::getInstance()->getResolutionWidth(), CoreEngine::getInstance()->getResolutionHeight()); 00148 00149 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f); 00150 glVertex2i(0, CoreEngine::getInstance()->getResolutionHeight()); 00151 glEnd(); 00152 00153 glDisable(GL_BLEND); 00154 glEnable(GL_DEPTH_TEST); 00155 00156 // Reset alpha color. 00157 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 00158 } 00159 } |
|
Definition at line 263 of file BloomEffect.h. Referenced by prepareRendering().
00263 { 00264 glBindTexture(GL_TEXTURE_2D, textureTarget); 00265 glCopyTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 0, 0, width, height, 0); 00266 } |
|
Called when the timer event comes.
Implements pge::IRenderableObject. Definition at line 250 of file BloomEffect.h.
00250 { 00251 } |
|
Definition at line 300 of file BloomEffect.h. Referenced by BloomEffect(), renderBlur(), and ~BloomEffect(). |
|
Definition at line 299 of file BloomEffect.h. Referenced by BloomEffect(), renderBrightPass(), and ~BloomEffect(). |
|
Definition at line 298 of file BloomEffect.h. Referenced by BloomEffect(), prepareRendering(), renderBlur(), renderBrightPass(), renderEffect(), and ~BloomEffect(). |