From 23937046e4771c32fda6c46e80c593009ce9b769 Mon Sep 17 00:00:00 2001 From: Kosyrev Serge <_deepfire@feelingofgreen.ru> Date: Tue, 18 Sep 2018 01:15:09 +0300 Subject: compileRenderTarget/allocRenderer: fill the glOutputs of a GLRenderer --- src/LambdaCube/GL/Backend.hs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/LambdaCube') diff --git a/src/LambdaCube/GL/Backend.hs b/src/LambdaCube/GL/Backend.hs index 324b3e6..90cb014 100644 --- a/src/LambdaCube/GL/Backend.hs +++ b/src/LambdaCube/GL/Backend.hs @@ -283,6 +283,15 @@ compileProgram p = do , inputStreams = Map.fromList [(n,(idx, attrName)) | (n,idx) <- Map.toList $ attributes, let attrName = fromMaybe (error $ "missing attribute: " ++ n) $ Map.lookup n lcStreamName] } +renderTargetOutputs :: Vector GLTexture -> RenderTarget -> GLRenderTarget -> [GLOutput] +renderTargetOutputs glTexs (RenderTarget targetItems) (GLRenderTarget fbo bufs) = + let isFB (Framebuffer _) = True + isFB _ = False + images = [img | TargetItem _ (Just img) <- V.toList targetItems] + in case all isFB images of + True -> fromMaybe [] $ (GLOutputDrawBuffer fbo <$>) <$> bufs + False -> (\(TextureImage texIdx _ _)-> GLOutputRenderTexture fbo $ glTexs ! texIdx) <$> images + compileRenderTarget :: Vector TextureDescriptor -> Vector GLTexture -> RenderTarget -> IO GLRenderTarget compileRenderTarget texs glTexs (RenderTarget targets) = do let isFB (Framebuffer _) = True @@ -488,16 +497,25 @@ createStreamCommands texUnitMap topUnis attrs primitive prg = streamUniCmds ++ s -- constant generic attribute constAttr -> GLSetVertexAttrib i constAttr +outputIsRenderTexture :: GLOutput -> Bool +outputIsRenderTexture GLOutputRenderTexture{..} = True +outputIsRenderTexture _ = False + allocRenderer :: Pipeline -> IO GLRenderer allocRenderer p = do smps <- V.mapM compileSampler $ samplers p texs <- V.mapM compileTexture $ textures p - trgs <- V.mapM (compileRenderTarget (textures p) texs) $ targets p + let cmds = V.toList $ commands p + finalRenderTargetIdx = head [i | SetRenderTarget i <- reverse $ cmds] + trgs <- traverse (compileRenderTarget (textures p) texs) $ targets p + let finalRenderTarget = targets p ! finalRenderTargetIdx + finalGLRenderTarget = trgs ! finalRenderTargetIdx + outs = renderTargetOutputs texs finalRenderTarget finalGLRenderTarget prgs <- V.mapM compileProgram $ programs p -- texture unit mapping ioref trie -- texUnitMapRefs :: Map UniformName (IORef TextureUnit) texUnitMapRefs <- Map.fromList <$> mapM (\k -> (k,) <$> newIORef 0) (Set.toList $ Set.fromList $ concat $ V.toList $ V.map (Map.keys . programInTextures) $ programs p) - let st = execState (mapM_ (compileCommand texUnitMapRefs smps texs trgs prgs) (V.toList $ commands p)) initCGState + let st = execState (mapM_ (compileCommand texUnitMapRefs smps texs trgs prgs) cmds) initCGState input <- newIORef Nothing -- default Vertex Array Object vao <- alloca $! \pvao -> glGenVertexArrays 1 pvao >> peek pvao @@ -515,6 +533,7 @@ allocRenderer p = do , glCommands = reverse $ drawCommands st , glSlotPrograms = V.map (V.toList . slotPrograms) $ IR.slots p , glInput = input + , glOutputs = outs , glSlotNames = V.map slotName $ IR.slots p , glVAO = vao , glTexUnitMapping = texUnitMapRefs @@ -895,4 +914,4 @@ compileCommand texUnitMap samplers textures targets programs cmd = case cmd of case IM.lookup tu tb of Nothing -> fail "internal error (GenerateMipMap)!" Just tex -> return $ GLGenerateMipMap (GL_TEXTURE0 + fromIntegral tu) (glTextureTarget tex) --} \ No newline at end of file +-} -- cgit v1.2.3