<commit_before>-----------------------------------------------------------------------------
-- |
-- Copyright   : (C) 2014 <NAME>
-- License     : BSD3
--
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : portable
--
----------------------------------------------------------------------------

module Photon.Render.PostFX where

import Control.Monad.Error.Class ( MonadError )
import Control.Monad.Trans ( MonadIO(..) )
import Graphics.Rendering.OpenGL.Raw
import Photon.Core.PostFX
import Photon.Render.GL.Shader ( ShaderType(..), genShader, genProgram
                               , useProgram )
import Photon.Render.GL.VertexArray ( bindVertexArray, genVertexArray
                                    , unbindVertexArray )
import Photon.Render.Texture ( GPUTexture(..) )
import Photon.Utils.Log ( Log, MonadLogger )

newtype GPUPostFXScreen = GPUPostFXScreen { runPostFXScreen :: IO () }

gpuPostFXScreen :: (MonadIO m) => m GPUPostFXScreen
gpuPostFXScreen = liftIO $ do
  va <- genVertexArray
  bindVertexArray va
  unbindVertexArray
  return . GPUPostFXScreen $ do
    bindVertexArray va
    glDrawArrays gl_TRIANGLE_STRIP 0 4

newtype GPUPostFX = GPUPostFX { runPostFX :: GPUPostFXScreen -> GPUTexture -> IO () }

gpuPostFX :: (MonadIO m,MonadLogger m,MonadError Log m) => PostFX -> m GPUPostFX
gpuPostFX (PostFX src) = do
    program <- sequence [genShader VertexShader vsSrc,genShader FragmentShader src] >>= genProgram
    return . GPUPostFX $ \screen texture -> do
      useProgram program
      bindTextureAt texture 0
      runPostFXScreen screen

vsSrc :: String
vsSrc = unlines
    [
    "#version 330 core"
  , "out vec2 uv;"
  , "vec2[4] v = vec2[]("
  , "    vec2(-1,  1)"
  , "  , vec2( 1,  1)"
  , "  , vec2(-1, -1)"
  , "  , vec2( 1, -1)"
  , "  );"
  , "void main() {"
  , "  uv = (v[gl_VertexID] + 1) * 0.5;"
  , "  gl_Position = vec4(v[gl_VertexID], 0., 1.);"
  , "}"
  ]
<commit_msg>More verbose.<commit_after>-----------------------------------------------------------------------------
-- |
-- Copyright   : (C) 2014 <NAME>
-- License     : BSD3
--
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : portable
--
----------------------------------------------------------------------------

module Photon.Render.PostFX where

import Control.Monad.Error.Class ( MonadError )
import Control.Monad.Trans ( MonadIO(..) )
import Graphics.Rendering.OpenGL.Raw
import Photon.Core.PostFX
import Photon.Render.GL.Shader ( ShaderType(..), genShader, genProgram
                               , useProgram )
import Photon.Render.GL.VertexArray ( bindVertexArray, genVertexArray
                                    , unbindVertexArray )
import Photon.Render.Texture ( GPUTexture(..) )
import Photon.Utils.Log ( Log, MonadLogger, sinkLogs )

newtype GPUPostFXScreen = GPUPostFXScreen { runPostFXScreen :: IO () }

gpuPostFXScreen :: (MonadIO m) => m GPUPostFXScreen
gpuPostFXScreen = liftIO $ do
  va <- genVertexArray
  bindVertexArray va
  unbindVertexArray
  return . GPUPostFXScreen $ do
    bindVertexArray va
    glDrawArrays gl_TRIANGLE_STRIP 0 4

newtype GPUPostFX = GPUPostFX { runPostFX :: GPUPostFXScreen -> GPUTexture -> IO () }

gpuPostFX :: (MonadIO m,MonadLogger m,MonadError Log m) => PostFX -> m GPUPostFX
gpuPostFX (PostFX src) = do
    program <- sequence [genShader VertexShader vsSrc,genShader FragmentShader src] >>= genProgram
    sinkLogs
    return . GPUPostFX $ \screen texture -> do
      useProgram program
      bindTextureAt texture 0
      runPostFXScreen screen

vsSrc :: String
vsSrc = unlines
    [
    "#version 330 core"
  , "out vec2 uv;"
  , "vec2[4] v = vec2[]("
  , "    vec2(-1,  1)"
  , "  , vec2( 1,  1)"
  , "  , vec2(-1, -1)"
  , "  , vec2( 1, -1)"
  , "  );"
  , "void main() {"
  , "  uv = (v[gl_VertexID] + 1) * 0.5;"
  , "  gl_Position = vec4(v[gl_VertexID], 0., 1.);"
  , "}"
  ]

{'fraction_non_alphanumeric': 0.19912976708471974, 'fraction_numerical': 0.016892756590734578, 'mean_word_length': 2.1490733279613217, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4982519', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1249, 'n_words': 293}