55
66namespace our {
77
8+ void ForwardRenderer::resizePostprocess (glm::ivec2 size) {
9+ if (!postprocessMaterial) return ;
10+
11+ glBindFramebuffer (GL_FRAMEBUFFER , postprocessFrameBuffer);
12+
13+ colorTarget->bind ();
14+ glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA8 , size.x , size.y , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr );
15+ glFramebufferTexture2D (GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , colorTarget->getOpenGLName (), 0 );
16+
17+ depthTarget->bind ();
18+ glTexImage2D (GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT24 , size.x , size.y , 0 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT ,
19+ nullptr );
20+ glFramebufferTexture2D (GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , depthTarget->getOpenGLName (), 0 );
21+
22+ Texture2D::unbind ();
23+ glBindFramebuffer (GL_FRAMEBUFFER , 0 );
24+ }
25+
826 void ForwardRenderer::initialize (glm::ivec2 windowSize, const nlohmann::json& config) {
927 // First, we store the window size for later use
1028 this ->windowSize = windowSize;
@@ -54,21 +72,8 @@ namespace our {
5472 // Then we check if there is a postprocessing shader in the configuration
5573 if (config.contains (" postprocess" )) {
5674 glGenFramebuffers (1 , &postprocessFrameBuffer);
57- glBindFramebuffer (GL_FRAMEBUFFER , postprocessFrameBuffer);
5875 colorTarget = new Texture2D ();
59- colorTarget->bind ();
60- glTexImage2D (GL_TEXTURE_2D , 0 , GL_RGBA8 , windowSize.x , windowSize.y , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr );
61- glFramebufferTexture2D (GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , colorTarget->getOpenGLName (),
62- 0 );
63- colorTarget->unbind ();
64-
6576 depthTarget = new Texture2D ();
66- depthTarget->bind ();
67- glTexImage2D (GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT24 , windowSize.x , windowSize.y , 0 , GL_DEPTH_COMPONENT ,
68- GL_UNSIGNED_INT , nullptr );
69- glFramebufferTexture2D (GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , depthTarget->getOpenGLName (), 0 );
70- depthTarget->unbind ();
71- glBindFramebuffer (GL_FRAMEBUFFER , 0 );
7277
7378 // Create a vertex array to use for drawing the texture
7479 glGenVertexArrays (1 , &postProcessVertexArray);
@@ -94,6 +99,8 @@ namespace our {
9499 // The default options are fine but we don't need to interact with the depth buffer
95100 // so it is more performant to disable the depth mask
96101 postprocessMaterial->pipelineState .depthMask = false ;
102+
103+ resizePostprocess (windowSize);
97104 }
98105 }
99106
@@ -125,7 +132,13 @@ namespace our {
125132 }
126133 }
127134
128- void ForwardRenderer::render (World* world) {
135+ void ForwardRenderer::render (World* world, glm::ivec2 windowSize) {
136+ if (windowSize.x <= 0 || windowSize.y <= 0 ) return ;
137+ if (this ->windowSize != windowSize) {
138+ this ->windowSize = windowSize;
139+ resizePostprocess (windowSize);
140+ }
141+
129142 // First of all, we search for a camera and for all the mesh renderers
130143 CameraComponent* camera = nullptr ;
131144 opaqueCommands.clear ();
0 commit comments