<commit_before>package net.machinemuse.utils.render

import org.lwjgl.opengl.GL11._
import net.minecraft.client.gui.ScaledResolution
import net.machinemuse.general.geometry.Colour
import org.lwjgl.opengl.GL13._
import net.minecraft.client.Minecraft
import net.machinemuse.utils.render.Render._
import net.machinemuse.powersuits.common.Config

/**
 * Author: MachineMuse (<NAME>)
 * Created: 6:02 PM, 5/15/13
 */
object GlowBuffer {
  // Texture dimension. Maybe make this configurable later
  val texDimension = 1024

  val glowBuffer = new TextureBuffer(texDimension)
  val secondBuffer = new TextureBuffer(texDimension)
  val depthBuffer = new TextureBuffer(texDimension)

  def draw[A](f: Render[A]): Render[A] = Render pure {
    glowBuffer.bindWrite()
    val a = f.run()
    glowBuffer.unbindWrite()
    a
  }

  def drawFullScreen(screen: ScaledResolution) {
    import Render._
    pushDualIdentityMatrix()
    MuseRenderer.glowOn()
    MuseRenderer.blendingOn()
    glDisable(GL_CULL_FACE)
    Colour.WHITE.doGL()
    glActiveTexture(GL_TEXTURE0)

    glBindTexture(GL_TEXTURE_2D, depthBuffer.depthRenderBufferID)
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texDimension, texDimension)
    glBindTexture(GL_TEXTURE_2D, 0)

    fromBuffer(depthBuffer) {
      toBuffer(secondBuffer) {
        withShaderProgram(MuseShaders.depthApplicatorProgram) {
          Render pure {
            glActiveTexture(GL_TEXTURE1)
            glBindTexture(GL_TEXTURE_2D, depthBuffer.depthRenderBufferID)
            MuseShaders.depthProgram.setTexUnit("depth", 1)
            glBegin(GL_QUADS)
            val t = texDimension
            val w = Minecraft.getMinecraft.displayWidth.toDouble
            val h = Minecraft.getMinecraft.displayHeight.toDouble
            val u = w / texDimension.toDouble
            val v = h / texDimension.toDouble
            vertUV(0, 0, 0, v)
            vertUV(0, t, 0, 0)
            vertUV(t, t, u, 0)
            vertUV(t, 0, u, v)
            glEnd()
          }
        }
      }
    }.run()


    fromBuffer(glowBuffer) {
      toBuffer(secondBuffer) {
        withShaderProgram(MuseShaders.depthProgram) {
          Render pure {
            glActiveTexture(GL_TEXTURE1)
            glBindTexture(GL_TEXTURE_2D, secondBuffer.depthRenderBufferID)
            glActiveTexture(GL_TEXTURE2)
            glBindTexture(GL_TEXTURE_2D, glowBuffer.depthRenderBufferID)
            glActiveTexture(GL_TEXTURE0)
            glBindTexture(GL_TEXTURE_2D, glowBuffer.colorTextureID)
            MuseShaders.depthProgram.setTexUnit("depth", 2)
            MuseShaders.depthProgram.setTexUnit("occlusion", 1)
            MuseShaders.depthProgram.setTexUnit("texture", 0)
            drawTexSquare(texDimension)
          }
        }
      }
    }.run()

    glActiveTexture(GL_TEXTURE1)
    glBindTexture(GL_TEXTURE_2D, 0)
    glActiveTexture(GL_TEXTURE2)
    glBindTexture(GL_TEXTURE_2D, 0)
    glActiveTexture(GL_TEXTURE0)
    glDisable(GL_DEPTH_TEST)

    for (i <- 1 until Config.glowMultiplier) {
      doBlurPasses()
    }

    //    To Main display
    fromBuffer(secondBuffer) {
      Render.pure {
        drawTexSquare(texDimension)
      }
    }.run()


    MuseRenderer.blendingOff()
    MuseRenderer.glowOff()
    popDualIdentityMatrix()
  }

  def doBlurPasses() {
    // Vertical Pass
    fromBuffer(secondBuffer) {
      toBuffer(glowBuffer) {
        withShaderProgram(MuseShaders.vBlurProgram) {
          Render pure {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            MuseShaders.vBlurProgram.setUniform2f("u_Scale", 0, 1.0f / texDimension)
            MuseShaders.vBlurProgram.setTexUnit("u_Texture0", 0)
            drawTexSquare(texDimension)
          }
        }
      }
    }.run()

<commit_msg>put a popattrib back in after disabling culling<commit_after>package net.machinemuse.utils.render

import org.lwjgl.opengl.GL11._
import net.minecraft.client.gui.ScaledResolution
import net.machinemuse.general.geometry.Colour
import org.lwjgl.opengl.GL13._
import net.minecraft.client.Minecraft
import net.machinemuse.utils.render.Render._
import net.machinemuse.powersuits.common.Config

/**
 * Author: MachineMuse (<NAME>)
 * Created: 6:02 PM, 5/15/13
 */
object GlowBuffer {
  // Texture dimension. Maybe make this configurable later
  val texDimension = 1024

  val glowBuffer = new TextureBuffer(texDimension)
  val secondBuffer = new TextureBuffer(texDimension)
  val depthBuffer = new TextureBuffer(texDimension)

  def draw[A](f: Render[A]): Render[A] = Render pure {
    glowBuffer.bindWrite()
    val a = f.run()
    glowBuffer.unbindWrite()
    a
  }

  def drawFullScreen(screen: ScaledResolution) {
    import Render._
    pushDualIdentityMatrix()
    MuseRenderer.glowOn()
    MuseRenderer.blendingOn()
    glPushAttrib(GL_ENABLE_BIT)

    glDisable(GL_CULL_FACE)
    Colour.WHITE.doGL()
    glActiveTexture(GL_TEXTURE0)

    glBindTexture(GL_TEXTURE_2D, depthBuffer.depthRenderBufferID)
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texDimension, texDimension)
    glBindTexture(GL_TEXTURE_2D, 0)

    fromBuffer(depthBuffer) {
      toBuffer(secondBuffer) {
        withShaderProgram(MuseShaders.depthApplicatorProgram) {
          Render pure {
            glActiveTexture(GL_TEXTURE1)
            glBindTexture(GL_TEXTURE_2D, depthBuffer.depthRenderBufferID)
            MuseShaders.depthProgram.setTexUnit("depth", 1)
            glBegin(GL_QUADS)
            val t = texDimension
            val w = Minecraft.getMinecraft.displayWidth.toDouble
            val h = Minecraft.getMinecraft.displayHeight.toDouble
            val u = w / texDimension.toDouble
            val v = h / texDimension.toDouble
            vertUV(0, 0, 0, v)
            vertUV(0, t, 0, 0)
            vertUV(t, t, u, 0)
            vertUV(t, 0, u, v)
            glEnd()
          }
        }
      }
    }.run()


    fromBuffer(glowBuffer) {
      toBuffer(secondBuffer) {
        withShaderProgram(MuseShaders.depthProgram) {
          Render pure {
            glActiveTexture(GL_TEXTURE1)
            glBindTexture(GL_TEXTURE_2D, secondBuffer.depthRenderBufferID)
            glActiveTexture(GL_TEXTURE2)
            glBindTexture(GL_TEXTURE_2D, glowBuffer.depthRenderBufferID)
            glActiveTexture(GL_TEXTURE0)
            glBindTexture(GL_TEXTURE_2D, glowBuffer.colorTextureID)
            MuseShaders.depthProgram.setTexUnit("depth", 2)
            MuseShaders.depthProgram.setTexUnit("occlusion", 1)
            MuseShaders.depthProgram.setTexUnit("texture", 0)
            drawTexSquare(texDimension)
          }
        }
      }
    }.run()

    glActiveTexture(GL_TEXTURE1)
    glBindTexture(GL_TEXTURE_2D, 0)
    glActiveTexture(GL_TEXTURE2)
    glBindTexture(GL_TEXTURE_2D, 0)
    glActiveTexture(GL_TEXTURE0)
    glDisable(GL_DEPTH_TEST)

    for (i <- 1 until Config.glowMultiplier) {
      doBlurPasses()
    }

    //    To Main display
    fromBuffer(secondBuffer) {
      Render.pure {
        drawTexSquare(texDimension)
      }
    }.run()


    glPopAttrib()
    MuseRenderer.blendingOff()
    MuseRenderer.glowOff()
    popDualIdentityMatrix()
  }

  def doBlurPasses() {
    // Vertical Pass
    fromBuffer(secondBuffer) {
      toBuffer(glowBuffer) {
        withShaderProgram(MuseShaders.vBlurProgram) {
          Render pure {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            MuseShaders.vBlurProgram.setUniform2f("u_Scale", 0, 1.0f / texDimension)
            MuseShaders.vBlurProgram.setTexUnit("u_Texture0", 0)
            drawTexSquare(texDimension)
          }
        }
      }
    }.run()


{'fraction_non_alphanumeric': 0.09082580814029577, 'fraction_numerical': 0.015966496531867557, 'mean_word_length': 2.686444766039556, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3313321', 'n_tokens_mistral': 2584, 'n_tokens_neox': 2494, 'n_words': 395}