From 0cff550c234d3f30986dbbfe2e23cc663e271af0 Mon Sep 17 00:00:00 2001 From: mtgmonkey Date: Sun, 30 Nov 2025 19:13:44 +0100 Subject: [PATCH] add hs-glsl library, remove shader files --- frag.glsl | 10 ---------- lib/hs-glsl | 2 +- package.nix | 2 +- src/IO.hs | 7 +++++-- src/Shaders.hs | 35 +++++++++++++++++++++++++++++++++++ vert.glsl | 13 ------------- 6 files changed, 42 insertions(+), 27 deletions(-) delete mode 100644 frag.glsl create mode 100644 src/Shaders.hs delete mode 100644 vert.glsl diff --git a/frag.glsl b/frag.glsl deleted file mode 100644 index e7dd9a7..0000000 --- a/frag.glsl +++ /dev/null @@ -1,10 +0,0 @@ -#version 450 core - -in vec4 fragColor_in; - -out vec4 fragColor_out; - -void main() -{ - fragColor_out = fragColor_in; -} diff --git a/lib/hs-glsl b/lib/hs-glsl index 2bc1cab..fa90055 160000 --- a/lib/hs-glsl +++ b/lib/hs-glsl @@ -1 +1 @@ -Subproject commit 2bc1cab2af274c3360988d5556718c7ad1edca6a +Subproject commit fa90055518540314430139748e7febee3f03f24e diff --git a/package.nix b/package.nix index 9d0a66a..28f24f8 100644 --- a/package.nix +++ b/package.nix @@ -20,7 +20,7 @@ "-rtsopts" "-with-rtsopts=-N" # hs-glsl - "-i./lib/hs-glsl/src/Language/GLSL.hs" + "-i./lib/hs-glsl/src" # src "-i./src" ]; diff --git a/src/IO.hs b/src/IO.hs index a237774..39b7798 100644 --- a/src/IO.hs +++ b/src/IO.hs @@ -8,15 +8,18 @@ module IO (openWindow, shutdownWindow, view) where import qualified Graphics.Rendering.OpenGL as GL import Graphics.Rendering.OpenGL (($=)) import qualified Graphics.UI.GLFW as GLFW +import qualified Language.GLSL as GLSL import Control.Exception import Control.Monad +import Data.Text (unpack) import Foreign.Ptr import Foreign.Marshal.Array import Foreign.Storable import LoadShaders import Relude +import Shaders import Types -- VIEW -- @@ -100,8 +103,8 @@ initResources = do -- load shaders program <- loadShaders - [ ShaderInfo GL.VertexShader (FileSource "vert.glsl") - , ShaderInfo GL.FragmentShader (FileSource "frag.glsl") + [ ShaderInfo GL.VertexShader (StringSource $ unpack $ GLSL.generateGLSL vertShader) + , ShaderInfo GL.FragmentShader (StringSource $ unpack $ GLSL.generateGLSL fragShader) ] GL.currentProgram $= Just program diff --git a/src/Shaders.hs b/src/Shaders.hs new file mode 100644 index 0000000..5f49b42 --- /dev/null +++ b/src/Shaders.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} + +module Shaders (fragShader, vertShader) where + +-- IMPORTS -- + +import Relude + +import Language.GLSL + +fragShader :: Program +fragShader = + [ VersionDeclaration 450 Core + , VariableDeclaration Nothing In fragColorOut + , VariableDeclaration Nothing Out fragColor + , MainStart + , VariableAssignment fragColor fragColorOut + ] + +vertShader :: Program +vertShader = + [ VersionDeclaration 450 Core + , VariableDeclaration (Just $ Location 0) In vertexPosition + , VariableDeclaration (Just $ Location 1) In vertexColor + , VariableDeclaration Nothing Out fragColorOut + , MainStart + , VariableAssignment GL_POSITION vertexPosition + , VariableAssignment fragColorOut vertexColor + ] + +fragColor = Variable "fragColor" $ GLSLVec4 GLSLFloat +fragColorOut = Variable "fragColorOut" $ GLSLVec4 GLSLFloat +vertexPosition = Variable "vertexPosition" $ GLSLVec4 GLSLFloat +vertexColor = Variable "vertexColor" $ GLSLVec4 GLSLFloat diff --git a/vert.glsl b/vert.glsl deleted file mode 100644 index f206195..0000000 --- a/vert.glsl +++ /dev/null @@ -1,13 +0,0 @@ -#version 450 core - -layout (location = 0) in vec4 vertexPosition; -layout (location = 1) in vec4 vertexColor; - -out vec4 fragColor_in; - -void main() -{ - gl_Position = vertexPosition; - - fragColor_in = vertexColor; -}