Okay, just got back after a vacation and ready to continue. I have fixed some conceptual issues I had before, and now with newly added Blend Map I carry on. However, with my new implementation a similar issue I had before remains. I only see a single top level texture rendering, the rest draws blank, and I wonder if there’s something I am not following.
I implemented the following code (going top to bottom):
[NOTE]void graphicsWindow::drawScene(void)
{
// DRAWING LAYERS
if (sceneDebugFlag) { std::cout << “GENERATING FINAL IMAGE…” << std::endl; }
bufferWindow->scene->drawLayers();
// DRAWING FINAL IMAGE
if (sceneDebugFlag) { std::cout << “DISPLAYING FINAL IMAGE…” << std::endl; }
glBindFramebuffer(GL_FRAMEBUFFER, 0); // bind main window buffer
glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // set clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // wipe the drawing surface clear
glUseProgram(bufferWindow->windowSceneRenderShader);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, bufferWindow->scene->sceneRenderedImageTextureID);
glUniform1i(glGetUniformLocation(this->windowSceneRenderShader, “finalImageTexture”), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, bufferWindow->scene->sceneRenderedControlTextureID);
glUniform1i(glGetUniformLocation(this->windowSceneRenderShader, “finalControlTexture”), 0);
glBindVertexArray(this->windowVAO);
glBindBuffer(GL_ARRAY_BUFFER, this->windowVBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, (3 + 2) * sizeof(GLfloat), NULL);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, (3 + 2) * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glDrawArrays(GL_TRIANGLES, 0, 30);
}[/NOTE]
[NOTE]void graphicsScene::drawLayers(void)
{
// DRAWING LAYERS
//-------------------------------------------------------------------------------------------------------------------------
if (sceneDebugFlag) { std::cout << " GENERATING LAYERS…" << std::endl; }
int i = 0;
for (i = 0; i < this->listOfSubScenes.size(); i++) {
[INDENT]this->listOfSubScenes.front()->drawObjects();
this->listOfSubScenes.push(this->listOfSubScenes.front());
this->listOfSubScenes.pop();
}[/INDENT]
// RENDER LAYERS
//-------------------------------------------------------------------------------------------------------------------------
if (sceneDebugFlag) { std::cout << " DISPLAYING LAYERS..." << std::endl; }
glBindFramebuffer(GL_FRAMEBUFFER, sceneRenderFBO); // bind main window buffer
glDrawBuffers(2, this->sceneDrawBuffers);
glViewport(0, 0, this->ownerWindow->width, this->ownerWindow->height); // redundant?
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(this->sceneLayerRenderShader);
GLuint uniformIDBuff;
uniformIDBuff = glGetUniformLocation(this->sceneLayerRenderShader, "layerAspectRatio");
glUniform1i(uniformIDBuff, this->ownerWindow->aspectRatio);
for (i = 0; i < this->listOfSubScenes.size(); i++) {
[INDENT]uniformIDBuff = glGetUniformLocation(this->sceneLayerRenderShader, "layerOffset");
glUniform1i(uniformIDBuff, this->listOfSubScenes.front()->layerOffset);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, this->listOfSubScenes.front()->layerRenderedImageTextureID);
glUniform1i(glGetUniformLocation(this->sceneLayerRenderShader, "layerImageTexture"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, this->listOfSubScenes.front()->layerRenderedControlTextureID);
glUniform1i(glGetUniformLocation(this->sceneLayerRenderShader, "layerControlTexture"), 1);
glBindVertexArray(this->sceneVAO);
glBindBuffer(GL_ARRAY_BUFFER, this->sceneVBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, (3 + 2) * sizeof(GLfloat), NULL);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, (3 + 2) * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glDrawArrays(GL_TRIANGLES, 0, 30);
this->listOfSubScenes.push(this->listOfSubScenes.front());
this->listOfSubScenes.pop();
}[/INDENT]
}[/NOTE]
[NOTE]void graphicsSubScene::drawObjects(void)
{
// PERFORM RENDERING OF OBJECTS
//------------------------------------------------------------------------------------------------------------------------------
if (subSceneDebugFlag) { std::cout << " GENERATING OBJECTS..." << std::endl; }
glBindFramebuffer(GL_FRAMEBUFFER, objectRenderFBO); // bind main window buffer
glViewport(0, 0, this->ownerScene->ownerWindow->width, this->ownerScene->ownerWindow->height); // redundant?
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(this->subSceneObjectRenderShader);
int i = 0;
for (i = 0; i < this->listOfObjects.size(); i++) {
[INDENT]//this->listOfObjects.front()->drawObject();
this->listOfObjects.push(this->listOfObjects.front());
this->listOfObjects.pop();
}
[/INDENT]
// PERFORM SHADING OF LAYERS
//------------------------------------------------------------------------------------------------------------------------------
if (subSceneDebugFlag) { std::cout << " SHADING LAYERS…" << std::endl; }
glBindFramebuffer(GL_FRAMEBUFFER, layerShadingFBO); // bind main window buffer
glViewport(0, 0, this->ownerScene->ownerWindow->width, this->ownerScene->ownerWindow->height); // redundant?
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(this->subSceneLayerShadingShader);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, this->objectRenderBlendMapID);
glUniform1i(glGetUniformLocation(this->subSceneLayerShadingShader, "blendMap"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, this->objectRenderControlMapID);
glUniform1i(glGetUniformLocation(this->subSceneLayerShadingShader, "controlMap"), 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, this->objectRenderColorMapID);
glUniform1i(glGetUniformLocation(this->subSceneLayerShadingShader, "colorMap"), 2);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, this->objectRenderNormalMapID);
glUniform1i(glGetUniformLocation(this->subSceneLayerShadingShader, "normalMap"), 3);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, this->objectRenderSpecularMapID);
glUniform1i(glGetUniformLocation(this->subSceneLayerShadingShader, "specularMap"), 4);
glBindVertexArray(this->layerShadingVAO);
glBindBuffer(GL_ARRAY_BUFFER, this->layerShadingVBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, (3 + 2) * sizeof(GLfloat), NULL);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, (3 + 2) * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glDrawArrays(GL_TRIANGLES, 0, 30);
}[/NOTE]
It’s relatively straight forward. My window draws the scene, then extracts 1 output texture from it and draws onto a square. The background is set to be red for testing, and it works.
The scene draws the layers, then renders each layer onto a square. The output is saved into a texture that is used by the window. The background is set as green, for testing, again it works.
However right now, I have a red space with a green square in it. The single layer that is attached to the scene, doesn’t draw any objects, but at the deferred shading stage it cleans the background into a blue color. But it’s not being drawn on the screen. This is a bit of a pickle since I am not sure which portion doesn’t work. Whether I don’t see any blue squares because it’s the scene that doesn’t draw the layer, or the layer that isn’t initiated properly and is transparent. The textures and geometries are initiated the same way on all levels. So I wonder if I’m missing a step required to do render to texture again before buffer swap.
Update: I initiated the layer output textures using a test texture I had around, and commented out any renderings to it. In theory I would see a texture inside a green square inside a red square, but I still get just the green square, meaning the layer’s output texture is not being rendered into scene’s quad.
My texture initialization are of the format:
[NOTE]void graphicsSubScene::setUpObjects(void)
{
// OBJECT RENDER VARIABLES
glGenFramebuffers(1, &objectRenderFBO);
glBindFramebuffer(GL_FRAMEBUFFER, objectRenderFBO);
glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, this->ownerScene->ownerWindow->width);
glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, this->ownerScene->ownerWindow->height);
glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 4);
glDrawBuffers(5, this->objectRenderDrawBuffers);
// BLEND MAP SET UP
glGenTextures(1, &(this->objectRenderBlendMapID));
glBindTexture(GL_TEXTURE_2D, this->objectRenderBlendMapID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, this->ownerScene->ownerWindow->width, this->ownerScene->ownerWindow->height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // not needed?
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, objectRenderBlendMapID, 0); // move to loop?
glBindTexture(GL_TEXTURE_2D, 0);
… more textures here
// DEPTHBUFFER SETUP
glGenTextures(1, &(this->objectRenderDepthBufferID));
glBindTexture(GL_TEXTURE_2D, this->objectRenderDepthBufferID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, this->ownerScene->ownerWindow->width, this->ownerScene->ownerWindow->height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // not needed?
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, objectRenderDepthBufferID, 0); // move to loop?
glBindTexture(GL_TEXTURE_2D, 0);
}[/NOTE]