diff --git a/shader/dualTwoD/arc.vert b/shader/dualTwoD/arc.vert index 86af29ae8..e53f915ee 100644 --- a/shader/dualTwoD/arc.vert +++ b/shader/dualTwoD/arc.vert @@ -3,6 +3,7 @@ layout (location = 0) in vec4 pos; layout (location = 1) in vec4 col; layout (location = 2) in vec3 boxXboxYwidth; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; +layout (location = 0) uniform int layoff; out vec4 vCol; out vec3 vPos; out vec3 vparams; diff --git a/shader/dualTwoD/basic.vert b/shader/dualTwoD/basic.vert index e2c2a4556..73e38b53c 100644 --- a/shader/dualTwoD/basic.vert +++ b/shader/dualTwoD/basic.vert @@ -1,6 +1,7 @@ #version 450 core layout (location = 0) in vec4 pos; layout (location = 1) in vec4 col; +layout (location = 0) uniform int layoff; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; out vec4 vCol; out vec3 vPos; diff --git a/shader/dualTwoD/ellipse.vert b/shader/dualTwoD/ellipse.vert index 388606600..67e6c0c68 100644 --- a/shader/dualTwoD/ellipse.vert +++ b/shader/dualTwoD/ellipse.vert @@ -1,15 +1,33 @@ #version 450 core -layout (location = 0) in vec4 pos; -layout (location = 1) in vec4 col; +struct PosCol { vec4 posx; vec4 colx; }; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; -out vec4 vCol; -//const int ks[6] = // -// {0,1,2 // 2--3 -// ,2,1,3 // | | -// }; // 0--1 -// // +layout (std430, binding = 13) readonly buffer Data { PosCol data[]; }; +layout (location = 0) uniform int n; +out vec4 gColC; // center color +out vec4 gColE; // edge color +out vec2 gBoundingBox; +out vec3 gPos; +const int ks[6] = // + {1,0,2 // 2--3 + ,2,0,3 // | | + }; // 1--0 + // +const vec2 bs[4] = + { vec2( 1, 1) + , vec2(-1, 1) + , vec2(-1,-1) + , vec2( 1,-1) + } ; void main() { - gl_Position = pos; - vCol = col; + int i0 = n + (3 * (gl_VertexID/6) ); + gColC = data[i0].colx; + gColE = data[i0+1].colx; + int k = ks[gl_VertexID % 6]; + gBoundingBox = bs[k]; + gPos = (k > 2.5 + ? data[i0].posx + data[i0+2].posx - data[i0+1].posx + : data[i0+k].posx + ).xyz; + gl_Position = theMat * vec4(gPos,1); } diff --git a/shader/picture/charArray.vert b/shader/picture/charArray.vert index a7956a219..297843891 100644 --- a/shader/picture/charArray.vert +++ b/shader/picture/charArray.vert @@ -1,8 +1,8 @@ #version 450 core layout (location = 0) in vec4 pos; layout (location = 1) in vec4 inColor; -//layout (location = 2) in vec4 inTexCoord; layout (location = 2) in vec3 inTexCoord; +layout (location = 0) uniform int layoff; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; out vec4 vColor; out vec3 vTexCoord; diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index e09fe0a76..f9910f564 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -3,7 +3,7 @@ module Preload.Render (preloadRender) where import Control.Concurrent ---import Control.Lens +import Control.Lens import Control.Monad import Data.Preload.Render import qualified Data.Vector.Mutable as MV @@ -105,9 +105,9 @@ preloadRender = do putStrLn "Setup 2D shaders" bslist <- makeShaderVBO "dualTwoD/basic" [vert, frag] (toFloatVAs [4, 4]) - aslist <- makeShaderVBO "dualTwoD/arc" [vert, frag] (toFloatVAs [4, 4, 4]) - eslist <- makeShaderVBO "dualTwoD/ellipse" [vert, geom, frag] (toFloatVAs [4, 4]) cslist <- makeShaderVBO "picture/charArray" [vert, frag] (toFloatVAs [4, 4, 4]) + aslist <- makeShaderVBO "dualTwoD/arc" [vert, frag] (toFloatVAs [4, 4, 4]) + eslist <- makeShaderVBO "dualTwoD/ellipse" [vert, frag] (toFloatVAs [4, 4]) shadV <- MV.new 4 zipWithM_ (MV.write shadV) @@ -117,6 +117,14 @@ preloadRender = do , aslist , eslist ] + zipWithM_ + (\i vbo -> glBindBufferBase GL_SHADER_STORAGE_BUFFER i (vbo ^. _2 . vboName)) + [10 .. 13] + [ bslist -- note the ordering is very important + , cslist + , aslist + , eslist + ] -- GL_NEAREST_MIPMAP_LINEAR GL_LINEAR ? initTexture2DArray 50 "data/charMaps/cMap16x32.Custom.png" 2 16 32 256 GL_NEAREST GL_NEAREST putStrLn "Setup full screen shaders" diff --git a/src/Shader.hs b/src/Shader.hs index 9e2dbaf0d..4c5a15200 100644 --- a/src/Shader.hs +++ b/src/Shader.hs @@ -13,13 +13,16 @@ drawShaderLay l countsVector shadIn fs = do i <- UMV.read countsVector shadIn glUseProgram (_shaderUINT $ fst fs) glBindVertexArray $ fs ^. _1 . shaderVAO . unVAO + glUniform1i 0 . fromIntegral $ (l * numSubElements) glDrawArrays GL_TRIANGLES (fromIntegral $ l * numSubElements) + --(drawCountMod shadIn i) (drawCountMod shadIn i) --(fromIntegral i) drawCountMod :: Int -> Int -> GLsizei drawCountMod i n - | i == 3 = fromIntegral n -- modifies ellipse draw count +-- | i == 3 = fromIntegral $ 2 * n -- modifies ellipse draw count + | i == 3 = fromIntegral $ 2 * n -- modifies ellipse draw count | otherwise = fromIntegral n diff --git a/tags b/tags index e7fa0399e..78ebcb817 100644 --- a/tags +++ b/tags @@ -2599,7 +2599,7 @@ attachOnward src/Dodge/Tree/Compose.hs 95;" f attachOnward' src/Dodge/Tree/Compose.hs 98;" f attachTree src/Dodge/Tree/Compose.hs 38;" f attentionViewPoint src/Dodge/Creature/ReaderUpdate.hs 75;" f -attribSize src/Shader/Compile.hs 195;" f +attribSize src/Shader/Compile.hs 193;" f autoAmr src/Dodge/Item/Held/Rod.hs 39;" f autoBS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 488;" f autoCrit src/Dodge/Creature/AutoCrit.hs 10;" f @@ -2766,7 +2766,7 @@ checkConnection src/Dodge/Inventory/Swap.hs 66;" f checkDeath src/Dodge/Creature/Update.hs 70;" f checkDeath' src/Dodge/Creature/Update.hs 73;" f checkEndGame src/Dodge/Update.hs 766;" f -checkErrorGL src/Shader/Compile.hs 142;" f +checkErrorGL src/Shader/Compile.hs 140;" f checkFBO src/Framebuffer/Check.hs 6;" f checkGLError src/GLHelp.hs 14;" f checkInvSlotsYou src/Dodge/Inventory/CheckSlots.hs 18;" f @@ -2867,7 +2867,7 @@ compP2A src/Dodge/ShiftPoint.hs 11;" f compactDraw src/Dodge/LevelGen.hs 94;" f compactDraw' src/Dodge/LevelGen.hs 105;" f compactDrawTree src/Dodge/LevelGen.hs 88;" f -compileAndCheckShader src/Shader/Compile.hs 164;" f +compileAndCheckShader src/Shader/Compile.hs 162;" f composeNode src/Dodge/Tree/Compose.hs 76;" f composeTree src/Dodge/Tree/Compose.hs 47;" f computerBeepingS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 640;" f @@ -2888,7 +2888,7 @@ copier src/Dodge/Item/Scope.hs 88;" f copierItemUpdate src/Dodge/Creature/State.hs 131;" f copyItemToFloor src/Dodge/FloorItem.hs 14;" f corDoor src/Dodge/Room/Room.hs 385;" f -cornerList src/Preload/Render.hs 219;" f +cornerList src/Preload/Render.hs 225;" f corpseOrGib src/Dodge/Creature/Update.hs 111;" f corridor src/Dodge/Room/Corridor.hs 17;" f corridorBoss src/Dodge/LockAndKey.hs 133;" f @@ -3252,7 +3252,7 @@ drawCombFilter src/Dodge/Render/Picture.hs 269;" f drawCombineInventory src/Dodge/Render/HUD.hs 183;" f drawConcurrentMessage src/Dodge/Render/Picture.hs 74;" f drawCoord src/Dodge/Debug/Picture.hs 386;" f -drawCountMod src/Shader.hs 22;" f +drawCountMod src/Shader.hs 24;" f drawCrInfo src/Dodge/Debug.hs 169;" f drawCrInfo' src/Dodge/Debug.hs 164;" f drawCreature src/Dodge/Render/ShapePicture.hs 71;" f @@ -3715,7 +3715,7 @@ initWallZoning src/Dodge/Wall/Zone.hs 12;" f initialRoomTree src/Dodge/Floor.hs 24;" f initialWorld src/Dodge/Initialisation.hs 15;" f initialisePlaying src/Sound.hs 77;" f -initializeGLState src/Preload/Render.hs 240;" f +initializeGLState src/Preload/Render.hs 246;" f initializeOptionMenu src/Dodge/Menu/Option.hs 17;" f initializeOptionMenuBO src/Dodge/Menu/Option.hs 30;" f initializeTexture2D src/Framebuffer/Update.hs 214;" f @@ -4804,7 +4804,7 @@ setRBCreatureTargeting src/Dodge/Creature/State.hs 290;" f setRoomInt src/Dodge/Room/Tutorial.hs 91;" f setSelWhileDragging src/Dodge/Update/Input/InGame.hs 337;" f setSelectionListRestriction src/Dodge/Update/Input/ScreenLayer.hs 87;" f -setShaderSource src/Shader/Compile.hs 177;" f +setShaderSource src/Shader/Compile.hs 175;" f setShadowLimits src/Dodge/Shadows.hs 11;" f setSoundVolume src/Sound.hs 157;" f setTargetMv src/Dodge/Creature/ReaderUpdate.hs 83;" f @@ -5441,7 +5441,7 @@ vShape src/Dodge/Placement/Instance/LightSource.hs 93;" f vToL src/MatrixHelper.hs 56;" f vToQuat src/Quaternion.hs 42;" f validTerminalCommands src/Dodge/Debug/Terminal.hs 137;" f -vasTightStride src/Shader/Compile.hs 184;" f +vasTightStride src/Shader/Compile.hs 182;" f vecBetweenSpeed src/Dodge/Base.hs 146;" f vecTurnTo src/Dodge/Movement/Turn.hs 19;" f vert src/Shader/Data.hs 110;" f @@ -5509,7 +5509,7 @@ windowLine src/Dodge/Placement/Instance/Wall.hs 59;" f windowXFloat src/Dodge/Data/Config.hs 72;" f windowYFloat src/Dodge/Data/Config.hs 74;" f withAlpha src/Color.hs 10;" f -withByteString src/Shader/Compile.hs 213;" f +withByteString src/Shader/Compile.hs 211;" f wlIXsNearCirc src/Dodge/Zoning/Wall.hs 32;" f wlIXsNearPoint src/Dodge/Zoning/Wall.hs 22;" f wlIXsNearRect src/Dodge/Zoning/Wall.hs 29;" f