parent
cea71238f1
commit
9c33af543c
@ -1,11 +1,11 @@
|
|||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
in vec3 Position;
|
layout(location=0) in vec3 Position;
|
||||||
in vec3 Normal;
|
layout(location=1) in vec3 Normal;
|
||||||
uniform mat4 ProjectionMatrix;
|
uniform mat4 ProjectionMatrix;
|
||||||
uniform mat4 ViewMatrix;
|
uniform mat4 ViewMatrix;
|
||||||
uniform mat3 NormalMatrix;
|
uniform mat3 NormalMatrix;
|
||||||
uniform vec3 PositionOffset;
|
uniform vec3 PositionOffset = vec3(25,5,25);
|
||||||
uniform float TessLevelInner = 1.0; // controlled by keyboard buttons
|
uniform float TessLevelInner = 1.0; // controlled by keyboard buttons
|
||||||
uniform float TessLevelOuter = 1.0; // controlled by keyboard buttons
|
uniform float TessLevelOuter = 1.0; // controlled by keyboard buttons
|
||||||
|
|
||||||
@ -14,6 +14,6 @@ out vec3 vNormal;
|
|||||||
|
|
||||||
void main () {
|
void main () {
|
||||||
vPosition = Position;
|
vPosition = Position;
|
||||||
gl_Position = ProjectionMatrix * ViewMatrix * vec4(Position, 1);
|
gl_Position = ProjectionMatrix * ViewMatrix * vec4(PositionOffset + 10*Position, 1);
|
||||||
vNormal = Normal;
|
vNormal = Normal;
|
||||||
}
|
}
|
||||||
|
@ -268,16 +268,17 @@ toBufferTargetfromVAType _ = ArrayBuffer
|
|||||||
-- is needed in term of computation.
|
-- is needed in term of computation.
|
||||||
readInVAO :: ByteString -> IQMVertexArray -> IO IQMVertexArray
|
readInVAO :: ByteString -> IQMVertexArray -> IO IQMVertexArray
|
||||||
readInVAO d (IQMVertexArray type' a format num offset ptr) =
|
readInVAO d (IQMVertexArray type' a format num offset ptr) =
|
||||||
do
|
do
|
||||||
let
|
let
|
||||||
byteLen = fromIntegral num * vaSize format
|
byteLen = fromIntegral num * vaSize format
|
||||||
data' = skipDrop (fromIntegral offset) byteLen d
|
data' = skipDrop (fromIntegral offset) byteLen d
|
||||||
|
|
||||||
unless (ptr == nullPtr) $ error $ "Error reading Vertex-Array: Double Read of " ++ show type'
|
unless (ptr == nullPtr) $ error $ "Error reading Vertex-Array: Double Read of " ++ show type'
|
||||||
p <- mallocBytes byteLen
|
p <- mallocBytes byteLen
|
||||||
putStrLn $ concat ["Allocating ", show byteLen, " Bytes at ", show p]
|
putStrLn $ concat ["Allocating ", show num,"x",show (vaSize format)," = ", show byteLen, " Bytes at ", show p, " for ", show type']
|
||||||
unsafeUseAsCString data' (\s -> copyBytes p s byteLen)
|
putStrLn $ concat ["Filling with: ", show data', " starting at ", show offset]
|
||||||
return $ IQMVertexArray type' a format num offset $ castPtr p
|
unsafeUseAsCString data' (\s -> copyBytes p s byteLen)
|
||||||
|
return $ IQMVertexArray type' a format num offset $ castPtr p
|
||||||
|
|
||||||
-- | Real internal Parser.
|
-- | Real internal Parser.
|
||||||
--
|
--
|
||||||
@ -308,5 +309,8 @@ doIQMparse vao =
|
|||||||
-- by the Offsets provided.
|
-- by the Offsets provided.
|
||||||
--
|
--
|
||||||
-- O(1).
|
-- O(1).
|
||||||
skipDrop :: Int -> Int -> ByteString -> ByteString
|
skipDrop :: Int -- ^ Bytes to drop
|
||||||
skipDrop a b= B.drop b . B.take a
|
-> Int -- ^ Bytes to take
|
||||||
|
-> ByteString
|
||||||
|
-> ByteString
|
||||||
|
skipDrop a b= B.take b . B.drop a
|
||||||
|
@ -194,7 +194,7 @@ data IQMVertexArray = IQMVertexArray
|
|||||||
IQMVertexArrayFormat
|
IQMVertexArrayFormat
|
||||||
NumComponents
|
NumComponents
|
||||||
Offset
|
Offset
|
||||||
IQMData
|
IQMData
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
instance Show IQMVertexArray where
|
instance Show IQMVertexArray where
|
||||||
show (IQMVertexArray t fl fo nc off dat) = "IQMVertexArray (Type: " ++ show t ++
|
show (IQMVertexArray t fl fo nc off dat) = "IQMVertexArray (Type: " ++ show t ++
|
||||||
|
@ -180,8 +180,9 @@ initMapShader tessFac (buf, vertDes) = do
|
|||||||
checkError "PositionOffset"
|
checkError "PositionOffset"
|
||||||
|
|
||||||
att' <- get (activeAttribs objProgram)
|
att' <- get (activeAttribs objProgram)
|
||||||
|
|
||||||
putStrLn $ unlines $ "Model-Attributes: ":map show att'
|
putStrLn $ unlines $ "Model-Attributes: ":map show att'
|
||||||
|
uni' <- get (activeUniforms objProgram)
|
||||||
|
putStrLn $ unlines $ "Model-Uniforms: ":map show uni'
|
||||||
putStrLn $ unlines $ ["Model-Indices: ", show (texIndex', normalIndex', vertexIndex')]
|
putStrLn $ unlines $ ["Model-Indices: ", show (texIndex', normalIndex', vertexIndex')]
|
||||||
checkError "initShader"
|
checkError "initShader"
|
||||||
let sdata = MapShaderData
|
let sdata = MapShaderData
|
||||||
@ -285,9 +286,10 @@ initRendering = do
|
|||||||
-- | renders an IQM-Model at Position with scaling
|
-- | renders an IQM-Model at Position with scaling
|
||||||
renderIQM :: IQM -> L.V3 CFloat -> L.V3 CFloat -> IO ()
|
renderIQM :: IQM -> L.V3 CFloat -> L.V3 CFloat -> IO ()
|
||||||
renderIQM m p@(L.V3 x y z) s@(L.V3 sx sy sz) = do
|
renderIQM m p@(L.V3 x y z) s@(L.V3 sx sy sz) = do
|
||||||
bindVertexArrayObject $= Just (vertexArrayObject m)
|
bindVertexArrayObject $= Just (vertexArrayObject m)
|
||||||
glDrawArrays gl_TRIANGLES 0 3
|
let n = num_vertexes $ header m
|
||||||
return ()
|
glDrawArrays gl_TRIANGLES 0 (fromIntegral n)
|
||||||
|
return ()
|
||||||
|
|
||||||
renderObject :: MapObject -> IO ()
|
renderObject :: MapObject -> IO ()
|
||||||
renderObject (MapObject model pos@(L.V3 x y z) _{-state-}) =
|
renderObject (MapObject model pos@(L.V3 x y z) _{-state-}) =
|
||||||
@ -485,21 +487,15 @@ render = do
|
|||||||
checkError "setting up shadowmap-program"
|
checkError "setting up shadowmap-program"
|
||||||
|
|
||||||
--set up projection (= copy from state)
|
--set up projection (= copy from state)
|
||||||
--TODO: Fix width/depth
|
|
||||||
mat44ToGPU frust projmo "mapObjects-projection"
|
mat44ToGPU frust projmo "mapObjects-projection"
|
||||||
|
|
||||||
--set up camera
|
--set up camera
|
||||||
--TODO: Fix magic constants... and camPos
|
|
||||||
let ! cam = getCam camPos zDist' xa ya
|
let ! cam = getCam camPos zDist' xa ya
|
||||||
mat44ToGPU cam vmatmo "mapObjects-cam"
|
mat44ToGPU cam vmatmo "mapObjects-cam"
|
||||||
|
--set up normal
|
||||||
--set up normal--Mat transpose((model*camera)^-1)
|
|
||||||
--needed?
|
|
||||||
let normal' = (case L.inv33 (fmap (^. L._xyz) cam ^. L._xyz) of
|
let normal' = (case L.inv33 (fmap (^. L._xyz) cam ^. L._xyz) of
|
||||||
(Just a) -> a
|
(Just a) -> a
|
||||||
Nothing -> L.eye3) :: L.M33 CFloat
|
Nothing -> L.eye3) :: L.M33 CFloat
|
||||||
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
nmap = collect id normal' :: L.M33 CFloat --transpose...
|
||||||
|
|
||||||
mat33ToGPU nmap nmatmo "mapObjects-nmat"
|
mat33ToGPU nmap nmatmo "mapObjects-nmat"
|
||||||
|
|
||||||
mapM_ renderObject (state ^. gl.glMap.mapObjects)
|
mapM_ renderObject (state ^. gl.glMap.mapObjects)
|
||||||
|
Loading…
Reference in New Issue
Block a user