ECS/Project/Project/Renderers/RendererModules/GBufferModule/GBufferModule.cpp
//	Create the G Buffer Textures and Framebuffers.
Create the G Buffer Textures and Framebuffers.
Create the G Buffer Textures and Framebuffers .
void GBufferModule::createGBufferTexturesAndFramebuffers(const unsigned int & screenWidth, const unsigned int & screenHeight)
{
	glGenTextures(1, &worldSpaceVertexPositionTexture);
	glBindTexture(GL_TEXTURE_2D, worldSpaceVertexPositionTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, screenWidth, screenHeight, 0, GL_RGBA, GL_FLOAT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, 0);
	glGenTextures(1, &worldSpaceVertexNormalAndDepthTexture);
	glBindTexture(GL_TEXTURE_2D, worldSpaceVertexNormalAndDepthTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, screenWidth, screenHeight, 0, GL_RGBA, GL_FLOAT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, 0);
	glGenTextures(1, &ambientColorTexture);
	glBindTexture(GL_TEXTURE_2D, ambientColorTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, screenWidth, screenHeight, 0, GL_RGBA, GL_FLOAT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, 0);
	glGenTextures(1, &diffuseAlbedoAndLitTypeTexture);
	glBindTexture(GL_TEXTURE_2D, diffuseAlbedoAndLitTypeTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, screenWidth, screenHeight, 0, GL_RGBA, GL_FLOAT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, 0);
	glGenTextures(1, &specularAlbedoAndLightingTypeTexture);
	glBindTexture(GL_TEXTURE_2D, specularAlbedoAndLightingTypeTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, screenWidth, screenHeight, 0, GL_RGBA, GL_FLOAT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, 0);
	glGenTextures(1, &mrfoTexture);
	glBindTexture(GL_TEXTURE_2D, mrfoTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, screenWidth, screenHeight, 0, GL_RGBA, GL_FLOAT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, 0);
	glGenTextures(1, &emissiveColorAndIntensityTexture);
	glBindTexture(GL_TEXTURE_2D, emissiveColorAndIntensityTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, screenWidth, screenHeight, 0, GL_RGBA, GL_FLOAT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, 0);
	glGenTextures(1, &depthTexture);
	glBindTexture(GL_TEXTURE_2D, depthTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, screenWidth, screenHeight, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glBindTexture(GL_TEXTURE_2D, 0);
	glGenFramebuffers(1, &framebufferID);
	glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 0, GL_TEXTURE_2D, worldSpaceVertexPositionTexture, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 1, GL_TEXTURE_2D, worldSpaceVertexNormalAndDepthTexture, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 2, GL_TEXTURE_2D, ambientColorTexture, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 3, GL_TEXTURE_2D, diffuseAlbedoAndLitTypeTexture, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 4, GL_TEXTURE_2D, specularAlbedoAndLightingTypeTexture, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 5, GL_TEXTURE_2D, mrfoTexture, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 6, GL_TEXTURE_2D, emissiveColorAndIntensityTexture, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
	GLenum framebufferDrawBuffers[] = { GL_COLOR_ATTACHMENT0 + 0, GL_COLOR_ATTACHMENT0 + 1, GL_COLOR_ATTACHMENT0 + 2, GL_COLOR_ATTACHMENT0 + 3, GL_COLOR_ATTACHMENT0 + 4, GL_COLOR_ATTACHMENT0 + 5, GL_COLOR_ATTACHMENT0 + 6};
	glDrawBuffers(7, framebufferDrawBuffers);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void GBufferModule :: createGBufferTexturesAndFramebuffers ( const unsigned int & screenWidth , const unsigned int & screenHeight ) { glGenTextures ( 1 , & worldSpaceVertexPositionTexture ) ; glBindTexture ( GL_TEXTURE_2D , worldSpaceVertexPositionTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA32F , screenWidth , screenHeight , 0 , GL_RGBA , GL_FLOAT , NULL ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenTextures ( 1 , & worldSpaceVertexNormalAndDepthTexture ) ; glBindTexture ( GL_TEXTURE_2D , worldSpaceVertexNormalAndDepthTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA32F , screenWidth , screenHeight , 0 , GL_RGBA , GL_FLOAT , NULL ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenTextures ( 1 , & ambientColorTexture ) ; glBindTexture ( GL_TEXTURE_2D , ambientColorTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA32F , screenWidth , screenHeight , 0 , GL_RGBA , GL_FLOAT , NULL ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenTextures ( 1 , & diffuseAlbedoAndLitTypeTexture ) ; glBindTexture ( GL_TEXTURE_2D , diffuseAlbedoAndLitTypeTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA32F , screenWidth , screenHeight , 0 , GL_RGBA , GL_FLOAT , NULL ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenTextures ( 1 , & specularAlbedoAndLightingTypeTexture ) ; glBindTexture ( GL_TEXTURE_2D , specularAlbedoAndLightingTypeTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA32F , screenWidth , screenHeight , 0 , GL_RGBA , GL_FLOAT , NULL ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenTextures ( 1 , & mrfoTexture ) ; glBindTexture ( GL_TEXTURE_2D , mrfoTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA32F , screenWidth , screenHeight , 0 , GL_RGBA , GL_FLOAT , NULL ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenTextures ( 1 , & emissiveColorAndIntensityTexture ) ; glBindTexture ( GL_TEXTURE_2D , emissiveColorAndIntensityTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA32F , screenWidth , screenHeight , 0 , GL_RGBA , GL_FLOAT , NULL ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenTextures ( 1 , & depthTexture ) ; glBindTexture ( GL_TEXTURE_2D , depthTexture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_DEPTH24_STENCIL8 , screenWidth , screenHeight , 0 , GL_DEPTH_STENCIL , GL_UNSIGNED_INT_24_8 , NULL ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenFramebuffers ( 1 , & framebufferID ) ; glBindFramebuffer ( GL_FRAMEBUFFER , framebufferID ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + 0 , GL_TEXTURE_2D , worldSpaceVertexPositionTexture , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + 1 , GL_TEXTURE_2D , worldSpaceVertexNormalAndDepthTexture , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + 2 , GL_TEXTURE_2D , ambientColorTexture , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + 3 , GL_TEXTURE_2D , diffuseAlbedoAndLitTypeTexture , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + 4 , GL_TEXTURE_2D , specularAlbedoAndLightingTypeTexture , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + 5 , GL_TEXTURE_2D , mrfoTexture , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + 6 , GL_TEXTURE_2D , emissiveColorAndIntensityTexture , 0 ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_TEXTURE_2D , depthTexture , 0 ) ; GLenum framebufferDrawBuffers [ ] = { GL_COLOR_ATTACHMENT0 + 0 , GL_COLOR_ATTACHMENT0 + 1 , GL_COLOR_ATTACHMENT0 + 2 , GL_COLOR_ATTACHMENT0 + 3 , GL_COLOR_ATTACHMENT0 + 4 , GL_COLOR_ATTACHMENT0 + 5 , GL_COLOR_ATTACHMENT0 + 6 } ; glDrawBuffers ( 7 , framebufferDrawBuffers ) ; glBindFramebuffer ( GL_FRAMEBUFFER , 0 ) ; }
Create the G Buffer Textures and Framebuffers.
Create the G Buffer Textures and Framebuffers .
//	Generate the World Space Vertex Position Textures. //	Generate the World space Vertex Normal and Depth Texture. //	Generate the Ambient Color Texture. //	Generate the Diffuse Albedo and Lit Type Texture. //	Generate the Specular Albedo and Lighting Type Texture. //	Generate the Specular Albedo and Lighting Type Texture. //	Generate the Emssive Color and Intensity Texture. //	Generate the Depth Texture. //	Create the Framebuffer to Render to the G Buffer. //	Associate the Textures of the G Buffer with the G Buffer Framebuffer. //	Associate the Depth Stencil Texture with the G Buffer Framebuffer. //	Set up the G Buffer Draw Textures. //	Bind the Default Framebuffer.