Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1.   private static void setupShadowFrameBuffer()
  2.   {
  3.     if (usedShadowDepthBuffers == 0)
  4.     {
  5.       return;
  6.     }
  7.  
  8.     if (sfb != 0)
  9.     {
  10.       glDeleteFramebuffersEXT(sfb);
  11.       GlStateManager.deleteTextures(sfbDepthTextures);
  12.       GlStateManager.deleteTextures(sfbColorTextures);
  13.     }
  14.  
  15.     sfb = glGenFramebuffersEXT();
  16.     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, sfb);
  17.     glDrawBuffer(GL_NONE);
  18.     glReadBuffer(GL_NONE);
  19.  
  20.     glGenTextures((IntBuffer) sfbDepthTextures.clear().limit(usedShadowDepthBuffers));
  21.     glGenTextures((IntBuffer) sfbColorTextures.clear().limit(usedShadowColorBuffers));
  22.     //printIntBuffer(sfbDepthTextures);
  23.     //printIntBuffer(sfbColorTextures);
  24.     sfbDepthTextures.position(0);
  25.     sfbColorTextures.position(0);
  26.  
  27.     // depth
  28.     for (int i = 0; i < usedShadowDepthBuffers; ++i)
  29.     {
  30.       GlStateManager.bindTexture(sfbDepthTextures.get(i));
  31.       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  32.       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  33.       int filter = shadowFilterNearest[i] ? GL_NEAREST : GL_LINEAR;
  34.       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
  35.       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
  36.       if (shadowHardwareFilteringEnabled[i])
  37.         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
  38.       glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (FloatBuffer) null);
  39.     }
  40.     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, sfbDepthTextures.get(0), 0);
  41.     checkGLError("FT sd");
  42.  
  43.     // color shadow
  44.     for (int i = 0; i < usedShadowColorBuffers; ++i)
  45.     {
  46.       GlStateManager.bindTexture(sfbColorTextures.get(i));
  47.       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  48.       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  49.       int filter = shadowColorFilterNearest[i] ? GL_NEAREST : GL_LINEAR;
  50.       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
  51.       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
  52.       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shadowMapWidth, shadowMapHeight, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (ByteBuffer) null);
  53.       glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + i, GL_TEXTURE_2D, sfbColorTextures.get(i), 0);
  54.       checkGLError("FT sc");
  55.     }
  56.  
  57.     GlStateManager.bindTexture(0);
  58.  
  59.     if (usedShadowColorBuffers > 0)
  60.     {
  61.       //glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
  62.       glDrawBuffers(Shaders.sfbDrawBuffers);
  63.     }
  64.  
  65.     int status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  66.     if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
  67.     {
  68.       printChatAndLogError("[Shaders] Error: Failed creating shadow framebuffer! (Status " + status + ")");
  69.     }
  70.     else
  71.     {
  72.       SMCLog.info("Shadow framebuffer created.");
  73.     }
  74.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement