CrushedPixel

Shaders Mod Framebuffer

Nov 24th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.41 KB | None | 0 0
  1. private static void setupFrameBuffer() {
  2.         if (dfb != 0) {
  3.             glDeleteFramebuffersEXT(dfb);
  4.             glDeleteTextures(dfbDepthTextures);
  5.             glDeleteTextures(dfbColorTextures);
  6.         }
  7.        
  8.         dfb = glGenFramebuffersEXT();
  9.         glGenTextures((IntBuffer)dfbDepthTextures.clear().limit(usedDepthBuffers));
  10.         glGenTextures((IntBuffer)dfbColorTextures.clear().limit(MaxColorBuffers*2));
  11.         //glGenTextures((IntBuffer)dfbColorTexturesAlt.clear().limit(usedColorBuffers));
  12.         dfbDepthTextures.position(0);
  13.         dfbColorTextures.position(0); dfbColorTextures.get(dfbColorTexturesA).position(0);
  14.        
  15.         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dfb);
  16.         glDrawBuffers(GL_NONE);
  17.         glReadBuffer(GL_NONE);
  18.  
  19.         for (int i=0; i < usedDepthBuffers; ++i)
  20.         {
  21.             glBindTexture(GL_TEXTURE_2D, dfbDepthTextures.get(i));
  22.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  23.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  24.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  25.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  26.             glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
  27.             glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, renderWidth, renderHeight, 0, GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer)null);
  28.         }
  29.  
  30.         glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, dfbDepthTextures.get(0), 0);
  31.         glDrawBuffers(dfbDrawBuffers);
  32.         glReadBuffer(GL_NONE);
  33.         checkGLError("FT d");
  34.        
  35.         for (int i = 0; i < usedColorBuffers; ++i) {
  36.             glBindTexture(GL_TEXTURE_2D, dfbColorTexturesA[i]);
  37. //          glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0);
  38.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  39.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  40.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  41.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  42.             glTexImage2D(GL_TEXTURE_2D, 0, gbuffersFormat[i], renderWidth, renderHeight, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (ByteBuffer)null);
  43.             glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, dfbColorTexturesA[i], 0);
  44.             checkGLError("FT c");
  45.         }
  46.         for (int i = 0; i < usedColorBuffers; ++i) {
  47.             glBindTexture(GL_TEXTURE_2D, dfbColorTexturesA[MaxColorBuffers+i]);
  48. //          glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0);
  49.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  50.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  51.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  52.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  53.             glTexImage2D(GL_TEXTURE_2D, 0, gbuffersFormat[i], renderWidth, renderHeight, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (ByteBuffer)null);
  54.             checkGLError("FT ca");
  55.         }
  56.  
  57.         int status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  58.        
  59.         if (status==GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT)
  60.         {
  61.             printChatAndLogError("Failed framebuffer incomplete formats");
  62.             for (int i = 0; i < usedColorBuffers; ++i) {
  63.                 glBindTexture(GL_TEXTURE_2D, dfbColorTextures.get(i));
  64.                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, renderWidth, renderHeight, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (ByteBuffer)null);
  65.                 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, dfbColorTextures.get(i), 0);
  66.                 checkGLError("FT c");
  67.             }
  68.             status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  69.             if (status == GL_FRAMEBUFFER_COMPLETE_EXT) {
  70.                 SMCLog.info("complete");
  71.             }
  72.         }
  73.        
  74.         glBindTexture(GL_TEXTURE_2D, 0);
  75.        
  76.         if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
  77.             printChatAndLogError("Failed creating framebuffer! (Status " + status + ")");
  78.         } else {
  79.             SMCLog.info("Framebuffer created.");
  80.         }
  81.     }
  82.    
  83.     private static void setupShadowFrameBuffer() {
  84.         if (usedShadowDepthBuffers == 0) {
  85.             return;
  86.         }
  87.  
  88.         if (sfb != 0) {
  89.             glDeleteFramebuffersEXT(sfb);
  90.             glDeleteTextures(sfbDepthTextures);
  91.             glDeleteTextures(sfbColorTextures);
  92.         }
  93.  
  94.         sfb = glGenFramebuffersEXT();
  95.         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, sfb);
  96.         glDrawBuffers(drawBuffersNone);
  97.         glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
  98.  
  99.         glGenTextures((IntBuffer)sfbDepthTextures.clear().limit(usedShadowDepthBuffers));
  100.         glGenTextures((IntBuffer)sfbColorTextures.clear().limit(usedShadowColorBuffers));
  101.         //printIntBuffer(sfbDepthTextures);
  102.         //printIntBuffer(sfbColorTextures);
  103.         sfbDepthTextures.position(0); sfbColorTextures.position(0);
  104.        
  105.         // depth
  106.         for (int i=0; i < usedShadowDepthBuffers; ++i)
  107.         {
  108.             glBindTexture(GL_TEXTURE_2D, sfbDepthTextures.get(i));
  109.             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  110.             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  111.             int filter = shadowFilterNearest[i]? GL_NEAREST : GL_LINEAR;
  112.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
  113.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
  114.             if (shadowHardwareFilteringEnabled[i])
  115.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
  116.             glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (FloatBuffer)null);
  117.         }
  118.         glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, sfbDepthTextures.get(0), 0);
  119.         checkGLError("FT sd");
  120.  
  121.         // color shadow
  122.         for (int i=0; i < usedShadowColorBuffers; ++i) {
  123.             glBindTexture(GL_TEXTURE_2D, sfbColorTextures.get(i));
  124.             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  125.             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  126.             int filter = shadowColorFilterNearest[i]? GL_NEAREST : GL_LINEAR;
  127.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
  128.             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
  129.             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shadowMapWidth, shadowMapHeight, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (ByteBuffer)null);
  130.             glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, sfbColorTextures.get(i), 0);
  131.             checkGLError("FT sc");
  132.         }
  133.        
  134.         glBindTexture(GL_TEXTURE_2D, 0);
  135.  
  136.         int status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  137.         if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
  138.             printChatAndLogError("Failed creating shadow framebuffer! (Status " + status + ")");
  139.         } else {
  140.             SMCLog.info("Shadow framebuffer created.");
  141.         }
  142.     }
Advertisement
Add Comment
Please, Sign In to add comment