<commit_before>module Gfx.Textures where

import qualified Data.Map.Strict as M

import qualified Data.ByteString as B
import qualified  Data.ByteString.Unsafe as BSU

import           Graphics.Rendering.OpenGL as GL
import           Foreign.Ptr
import Codec.BMP

data TextureLibrary = TextureLibrary
  { textures :: M.Map String TextureObject
  } deriving (Show)

loadTexture :: String -> FilePath -> IO (String, TextureObject)
loadTexture name path = do
  text <- genObjectName
  textureBinding Texture2D $= Just text
  GL.textureFilter GL.Texture2D $= ((GL.Linear', Nothing), GL.Linear')

  Right image <- readBMP path
  let
    rgba = unpackBMPToRGBA32 image
    dta = unpackBMPToRGBA32 image
    (width, height) = bmpDimensions image
  bPtr <- BSU.unsafeUseAsCString dta $ \cstr -> 
                return (castPtr cstr)
  let pd = PixelData RGBA UnsignedByte bPtr
  let tSize = TextureSize2D (fromIntegral width) (fromIntegral height)
  texImage2D Texture2D NoProxy 0 RGBA' tSize 0 pd
  textureBinding Texture2D $= Nothing
  return (name, text)

createTextureLib :: IO TextureLibrary
createTextureLib = do
  texture <- loadTexture "crystal" "textures/crystal.bmp"
  let textMap = M.fromList [texture]
  return $ TextureLibrary { textures = textMap }<commit_msg>Make TextureLibrary just a Map<commit_after>module Gfx.Textures where

import qualified Data.Map.Strict           as M

import qualified Data.ByteString           as B
import qualified Data.ByteString.Unsafe    as BSU

import           Codec.BMP
import           Foreign.Ptr
import           Graphics.Rendering.OpenGL as GL

type TextureLibrary = M.Map String TextureObject

loadTexture :: String -> FilePath -> IO (String, TextureObject)
loadTexture name path = do
  text <- genObjectName
  textureBinding Texture2D $= Just text
  GL.textureFilter GL.Texture2D $= ((GL.Linear', Nothing), GL.Linear')
  Right image <- readBMP path
  let rgba = unpackBMPToRGBA32 image
      dta = unpackBMPToRGBA32 image
      (width, height) = bmpDimensions image
  bPtr <- BSU.unsafeUseAsCString dta $ \cstr -> return (castPtr cstr)
  let pd = PixelData RGBA UnsignedByte bPtr
  let tSize = TextureSize2D (fromIntegral width) (fromIntegral height)
  texImage2D Texture2D NoProxy 0 RGBA' tSize 0 pd
  textureBinding Texture2D $= Nothing
  return (name, text)

createTextureLib :: IO TextureLibrary
createTextureLib = do
  texture <- loadTexture "crystal" "textures/crystal.bmp"
  return $ M.fromList [texture]
{'fraction_non_alphanumeric': 0.07479674796747968, 'fraction_numerical': 0.00975609756097561, 'mean_word_length': 3.652173913043478, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '5406290', 'n_tokens_mistral': 800, 'n_tokens_neox': 758, 'n_words': 239}