]> gitweb.factorcode.org Git - factor.git/commitdiff
Get fluids working on Mac
authorErik Charlebois <erikcharlebois@gmail.com>
Mon, 5 Apr 2010 08:38:39 +0000 (01:38 -0700)
committerErik Charlebois <erikcharlebois@gmail.com>
Mon, 5 Apr 2010 08:38:39 +0000 (01:38 -0700)
extra/fluids/fluids.factor
extra/gpu/effects/blur/blur.factor
extra/gpu/util/util.factor

index d241a82ede54e207368c383253a0053674048d67..1b4f1524de912c82d4e67437555049f61c855a41 100644 (file)
@@ -98,14 +98,14 @@ M: fluids-world begin-game-world
     dup fluid set
     init-gpu
     initial-particles clone >>particles
-    "C:/Users/erikc/Pictures/particle2.pgm" make-texture >>texture
-    "C:/Users/erikc/Pictures/colors.ppm" make-texture >>ramp
+    "resource:extra/fluids/particle2.pgm" make-texture >>texture
+    "resource:extra/fluids/colors.ppm" make-texture >>ramp
 
     RGB float-components T{ texture-parameters
-                           { wrap clamp-texcoord-to-edge }
-                           { min-filter filter-linear }
-                           { min-mipmap-filter f }
-    <texture-2d> >>color-texture
+                            { wrap clamp-texcoord-to-edge }
+                            { min-filter filter-linear }
+                            { min-mipmap-filter f } }
+    <texture-2d> >>color-texture
 
     dup color-texture>> 0 <texture-2d-attachment> 1array f f { 320 240 } <framebuffer> >>framebuffer
     drop ;
@@ -135,7 +135,7 @@ M:: fluids-world draw-world* ( world -- )
         { "indexes"        [ nip length 2 / 0 swap <index-range> ] }
         { "framebuffer"    [ drop framebuffer>> ] }
     } 2<render-set> render
-    
+
     world color-texture>> gaussian-blur
     { 0 0 } { 640 480 } <rect> <viewport-state> set-gpu-state
     world ramp>> {
index 0a256549766d1233c3fd0e96c7f3627a0fed183a..ed72b283749290486a23dc2f73dc72a82329c089 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2010 Erik Charlebois.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: destructors fry gpu.render gpu.shaders gpu.state gpu.textures
-gpu.util images kernel locals math math.rectangles sequences ;
+USING: arrays destructors fry gpu.framebuffers gpu.render gpu.shaders
+gpu.state gpu.textures gpu.util images kernel locals math
+math.rectangles sequences ;
 IN: gpu.effects.blur
 
 GLSL-SHADER: blur-fragment-shader fragment-shader
@@ -14,10 +15,10 @@ void main()
     vec4 col = 0.16 * texture2D(texture, texcoord);
     if (horizontal)
     {
-        const vec2 blurX1 = vec2(blurSize, 0.0);
-        const vec2 blurX2 = vec2(blurSize * 2.0, 0.0);
-        const vec2 blurX3 = vec2(blurSize * 3.0, 0.0);
-        const vec2 blurX4 = vec2(blurSize * 4.0, 0.0);
+        vec2 blurX1 = vec2(blurSize, 0.0);
+        vec2 blurX2 = vec2(blurSize * 2.0, 0.0);
+        vec2 blurX3 = vec2(blurSize * 3.0, 0.0);
+        vec2 blurX4 = vec2(blurSize * 4.0, 0.0);
         col += 0.15 * (  texture2D(texture, texcoord - blurX1)
                        + texture2D(texture, texcoord + blurX1));
         col += 0.12 * (  texture2D(texture, texcoord - blurX2)
@@ -29,10 +30,10 @@ void main()
     }
     else
     {
-        const vec2 blurY1 = vec2(0.0, blurSize);
-        const vec2 blurY2 = vec2(0.0, blurSize * 2.0);
-        const vec2 blurY3 = vec2(0.0, blurSize * 3.0);
-        const vec2 blurY4 = vec2(0.0, blurSize * 4.0);
+        vec2 blurY1 = vec2(0.0, blurSize);
+        vec2 blurY2 = vec2(0.0, blurSize * 2.0);
+        vec2 blurY3 = vec2(0.0, blurSize * 3.0);
+        vec2 blurY4 = vec2(0.0, blurSize * 4.0);
         col += 0.15 * (  texture2D(texture, texcoord - blurY1)
                        + texture2D(texture, texcoord + blurY1));
         col += 0.12 * (  texture2D(texture, texcoord - blurY2)
@@ -42,7 +43,7 @@ void main()
         col += 0.05 * (  texture2D(texture, texcoord - blurY4)
                        + texture2D(texture, texcoord + blurY4));
     }
-    gl_FragColor = col ;
+    gl_FragColor = col;
 }
 ;
    
@@ -52,7 +53,7 @@ UNIFORM-TUPLE: blur-uniforms
     { "blurSize"   float-uniform   f } ;
 
 GLSL-PROGRAM: blur-program window-vertex-shader blur-fragment-shader window-vertex-format ;
-
+                        
 :: (blur) ( texture horizontal? framebuffer dim -- )
     { 0 0 } dim <rect> <viewport-state> set-gpu-state
     texture horizontal? 1.0 dim horizontal? [ first ] [ second ] if / blur-uniforms boa framebuffer {
@@ -65,7 +66,7 @@ GLSL-PROGRAM: blur-program window-vertex-shader blur-fragment-shader window-vert
                          
 :: blur ( texture horizontal? -- texture )
     texture 0 texture-dim :> dim
-    dim L ubyte-components <2d-render-texture> :> ( target-framebuffer target-texture )
+    dim RGB float-components <2d-render-texture> :> ( target-framebuffer target-texture )
     texture horizontal? target-framebuffer dim (blur)
     target-framebuffer dispose
     target-texture ;
index ffca3a54780e98e148a45256398c6d4807494cf0..29fe5f13147de476c232b1bb6aab4c1f1d08fa61 100644 (file)
@@ -1,6 +1,7 @@
 ! (c)2009 Joe Groff bsd license
-USING: arrays gpu.buffers gpu.framebuffers gpu.render gpu.shaders
-gpu.textures images kernel locals specialized-arrays ;
+USING: accessors arrays gpu.buffers gpu.framebuffers gpu.render
+gpu.shaders gpu.textures images kernel locals opengl.framebuffers
+specialized-arrays ;
 FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 IN: gpu.util
@@ -83,6 +84,7 @@ void main()
 ;
 
 GLSL-SHADER: window-point-fragment-shader fragment-shader
+#version 120
 uniform sampler2D texture;
 void main()
 {
@@ -113,9 +115,15 @@ CONSTANT: window-vertexes
     [ <window-vertex-buffer> ] dip window-vertex-format <vertex-array*> ; inline
 
 :: <2d-render-texture> ( dim order type -- renderbuffer texture )
-    order type T{ texture-parameters { wrap clamp-texcoord-to-edge }
-       { min-filter filter-linear } { min-mipmap-filter f } } <texture-2d>
-    [ 0 <texture-2d-attachment> 1array f f dim <framebuffer> ] keep ;
+    order type
+    T{ texture-parameters
+       { wrap clamp-texcoord-to-edge }
+       { min-filter filter-linear }
+       { min-mipmap-filter f } }
+    <texture-2d> [
+        0 <texture-2d-attachment> 1array f f dim <framebuffer>
+        dup { { default-attachment { 0 0 0 } } } clear-framebuffer
+    ] keep ;
 
 : draw-texture ( texture -- )
     {