SHARE
TWEET

Untitled

a guest Aug 25th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void Renderer::InitiateFirstPass()
  2. {
  3.     glGenFramebuffers(1, &s_GBufferData->GeometryBuffer);
  4.     glBindFramebuffer(GL_FRAMEBUFFER, s_GBufferData->GeometryBuffer);
  5.  
  6.     // - position color buffer
  7.     glGenTextures(1, &s_GBufferData->Position);
  8.     glBindTexture(GL_TEXTURE_2D, s_GBufferData->Position);
  9.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, s_Width, s_Height, 0, GL_RGB, GL_FLOAT, NULL);
  10.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  11.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  12.     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s_GBufferData->Position, 0);
  13.  
  14.     // - normal color buffer
  15.     glGenTextures(1, &s_GBufferData->Normal);
  16.     glBindTexture(GL_TEXTURE_2D, s_GBufferData->Normal);
  17.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, s_Width, s_Height, 0, GL_RGB, GL_FLOAT, NULL);
  18.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  19.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  20.     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, s_GBufferData->Normal, 0);
  21.  
  22.     // - color(albedo) buffer
  23.     glGenTextures(1, &s_GBufferData->Albedo);
  24.     glBindTexture(GL_TEXTURE_2D, s_GBufferData->Albedo);
  25.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, s_Width, s_Height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
  26.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  27.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  28.     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, s_GBufferData->Albedo, 0);
  29.  
  30.     // - specular color buffer
  31.     glGenTextures(1, &s_GBufferData->Specular);
  32.     glBindTexture(GL_TEXTURE_2D, s_GBufferData->Specular);
  33.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s_Width, s_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  34.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  35.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  36.     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, s_GBufferData->Specular, 0);
  37.  
  38.     unsigned int attachments[4] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
  39.     glDrawBuffers(4, attachments);
  40.  
  41.     // create and attach depth buffer (renderbuffer)
  42.     //unsigned int rboDepth;
  43.     glGenRenderbuffers(1, &s_GBufferData->rboDepth);
  44.     //glBindRenderbuffer(GL_RENDERBUFFER, s_GBufferData->rboDepth);
  45.     //glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, s_Width, s_Height);
  46.     //glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, s_GBufferData->rboDepth);
  47.     glBindTexture(GL_TEXTURE_2D, s_GBufferData->rboDepth);
  48.     glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, s_Width, s_Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
  49.     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, s_GBufferData->rboDepth, 0);
  50.  
  51.     // finally check if framebuffer is complete
  52.     if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
  53.         std::cout << "Framebuffer not complete!" << std::endl;
  54.     glBindFramebuffer(GL_FRAMEBUFFER, 0);
  55.  
  56.     // shader configuration
  57.     s_GBufferData->GeometryShader->Bind();
  58.     s_GBufferData->GeometryShader->UploadUniformInt("u_DiffuseTexture", 0);
  59.     s_GBufferData->GeometryShader->UploadUniformInt("u_NormalTexture", 1);
  60.     s_GBufferData->GeometryShader->UploadUniformInt("u_SpecularTexture", 2);
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top