Merge branch 'techniques'

release
Erik Charlebois 2010-04-06 13:12:37 -07:00
commit 1a570a8fc8
5 changed files with 112 additions and 49 deletions

View File

@ -1,6 +1,8 @@
! Copyright (C) 2010 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.syntax classes.struct ;
USING: accessors alien alien.c-types alien.strings alien.syntax arrays
classes.struct io.encodings.ascii kernel locals sequences
specialized-arrays strings typed ;
IN: elf
CONSTANT: EI_NIDENT 16
@ -456,3 +458,46 @@ STRUCT: Elf32_Dyn
STRUCT: Elf64_Dyn
{ d_tag Elf64_Sxword }
{ d_val Elf64_Xword } ;
SPECIALIZED-ARRAYS: Elf32_Shdr Elf64_Shdr uchar ;
UNION: Elf32/64_Ehdr Elf32_Ehdr Elf64_Ehdr ;
UNION: Elf32/64_Shdr Elf32_Shdr Elf64_Shdr ;
UNION: Elf32/64_Shdr-array Elf32_Shdr-array Elf64_Shdr-array ;
TYPED: 64-bit? ( elf: Elf32/64_Ehdr -- ? )
e_ident>> EI_CLASS swap nth ELFCLASS64 = ;
TYPED: elf-header ( c-ptr -- elf: Elf32/64_Ehdr )
[ Elf64_Ehdr memory>struct 64-bit? ] keep swap
[ Elf64_Ehdr memory>struct ]
[ Elf32_Ehdr memory>struct ] if ;
TYPED:: elf-section-headers ( elf: Elf32/64_Ehdr -- headers: Elf32/64_Shdr-array )
elf [ e_shoff>> ] [ e_shnum>> ] bi :> ( off num )
off elf >c-ptr <displaced-alien> num
elf 64-bit?
[ <direct-Elf64_Shdr-array> ]
[ <direct-Elf32_Shdr-array> ] if ;
TYPED:: elf-section-data ( elf: Elf32/64_Ehdr header: Elf32/64_Shdr -- uchar-array/f )
header [ sh_offset>> elf >c-ptr <displaced-alien> ] [ sh_size>> ] bi <direct-uchar-array> ;
TYPED:: elf-section-data-by-name ( elf: Elf32/64_Ehdr name: string -- header/f uchar-array/f )
elf elf-section-headers :> sections
elf e_shstrndx>> :> ndx
elf ndx sections nth elf-section-data >c-ptr :> section-names
sections 1 tail [
sh_name>> section-names <displaced-alien> ascii alien>string name =
] find nip
[ dup elf swap elf-section-data ]
[ f f ] if* ;
TYPED:: elf-section-names ( elf: Elf32/64_Ehdr -- names )
elf elf-section-headers :> sections
elf ".shstrtab" elf-section-data-by-name nip >c-ptr :> section-names
sections 1 tail [
sh_name>> section-names <displaced-alien>
ascii alien>string
] { } map-as ;

View File

@ -1,12 +1,12 @@
! Copyright (C) 2010 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays classes.struct destructors game.loop
game.worlds gpu gpu.buffers gpu.framebuffers gpu.render gpu.shaders
gpu.state gpu.textures gpu.util images images.loader kernel literals
locals make math math.rectangles math.vectors namespaces opengl.gl
sequences specialized-arrays ui.gadgets.worlds images.ppm
ui.gestures ui.pixel-formats images.pgm gpu.effects.blur
gpu.effects.step ;
game.worlds gpu gpu.buffers gpu.effects.blur gpu.framebuffers
gpu.render gpu.shaders gpu.state gpu.textures gpu.util images
images.loader kernel literals locals make math math.rectangles
math.vectors namespaces opengl.gl sequences specialized-arrays
ui.gadgets.worlds ui.gestures ui.pixel-formats gpu.effects.step
images.pgm images.ppm ;
FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: float
IN: fluids
@ -65,7 +65,7 @@ particle_t-array{
[ verlet-integrate-particle ] curry map! ;
TUPLE: fluids-world < game-world
particles texture framebuffer color-texture ramp { paused boolean initial: f } ;
particles texture ramp { paused boolean initial: f } ;
: make-texture ( pathname -- texture )
load-image
@ -100,50 +100,27 @@ M: fluids-world begin-game-world
initial-particles clone >>particles
"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
dup color-texture>> 0 <texture-2d-attachment> 1array f f { 320 240 } <framebuffer> >>framebuffer
drop ;
M: fluids-world end-game-world
framebuffer>> dispose ;
drop ;
M: fluids-world tick-game-world
dup paused>> [ drop ] [ integrate ] if ;
M:: fluids-world draw-world* ( world -- )
world framebuffer>> { { default-attachment { 0 0 0 } } } clear-framebuffer
system-framebuffer { { default-attachment { 0 0 0 } } } clear-framebuffer
f eq-add func-one func-one <blend-mode> dup <blend-state> set-gpu-state
f origin-upper-left 1.0 <point-state> set-gpu-state
world particles>> [
[ p>> [ x>> , ] [ y>> , ] bi ] each
] curry float-array{ } make :> verts
{ 0 0 } { 320 240 } <rect> <viewport-state> set-gpu-state
GL_POINT_SPRITE glEnable
world verts {
{ "primitive-mode" [ 2drop points-mode ] }
{ "uniforms" [ drop texture>> 50.0 window-point-uniforms boa ] }
{ "vertex-array" [ nip stream-upload draw-usage vertex-buffer byte-array>buffer &dispose window-point-program <program-instance> &dispose <vertex-array> &dispose ] }
{ "indexes" [ nip length 2 / 0 swap <index-range> ] }
{ "framebuffer" [ drop framebuffer>> ] }
} 2<render-set> render
[
verts world texture>> 50.0 { 320 240 } blended-point-sprite-batch &dispose
world color-texture>> gaussian-blur
{ 0 0 } { 640 480 } <rect> <viewport-state> set-gpu-state
world ramp>> {
{ "primitive-mode" [ 2drop triangle-strip-mode ] }
{ "uniforms" [ step-uniforms boa ] }
{ "vertex-array" [ 2drop <window-vertex-buffer> step-program <program-instance> <vertex-array> ] }
{ "indexes" [ 2drop T{ index-range f 0 4 } ] }
} 2<render-set> render
blend-state new set-gpu-state
gaussian-blur &dispose world ramp>> { 1024 768 } step-texture &dispose
{ 1024 768 } draw-texture
] with-destructors
;
GAME: fluids {
@ -151,7 +128,7 @@ GAME: fluids {
{ title "Fluids Test" }
{ pixel-format-attributes {
windowed double-buffered T{ depth-bits { value 24 } } } }
{ pref-dim { 640 480 } }
{ pref-dim { 1024 768 } }
{ tick-interval-micros $[ 60 fps ] }
} ;
@ -159,7 +136,7 @@ MAIN: fluids
fluids-world H{
{ T{ button-down } [ [
hand-loc get { 640 480 } v/ 2 v*n 1 v-n { 1 -1 } v* first2 float2_t <struct-boa>
hand-loc get { 1024 768 } v/ 2 v*n 1 v-n { 1 -1 } v* first2 float2_t <struct-boa>
dup 2.0 particle_t <struct-boa> suffix
] change-particles drop ] }
} set-gestures

View File

@ -1,6 +1,7 @@
! Copyright (C) 2010 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
USING: gpu.render gpu.shaders gpu.util ;
USING: destructors gpu.render gpu.shaders gpu.state gpu.textures
gpu.util images kernel locals math.rectangles ;
IN: gpu.effects.step
GLSL-SHADER: step-fragment-shader fragment-shader
@ -21,3 +22,19 @@ UNIFORM-TUPLE: step-uniforms
{ "ramp" texture-uniform f } ;
GLSL-PROGRAM: step-program window-vertex-shader step-fragment-shader window-vertex-format ;
: (step-texture) ( texture ramp texture dim -- )
{ 0 0 } swap <rect> <viewport-state> set-gpu-state
[ step-uniforms boa ] dip {
{ "primitive-mode" [ 2drop triangle-strip-mode ] }
{ "uniforms" [ drop ] }
{ "vertex-array" [ 2drop <window-vertex-buffer> step-program <program-instance> <vertex-array> ] }
{ "indexes" [ 2drop T{ index-range f 0 4 } ] }
{ "framebuffer" [ nip ] }
} 2<render-set> render ;
:: step-texture ( texture ramp dim -- texture )
dim RGB float-components <2d-render-texture> :> ( target-framebuffer target-texture )
texture ramp target-framebuffer dim (step-texture)
target-framebuffer dispose
target-texture ;

View File

@ -1,7 +1,7 @@
! (c)2009 Joe Groff bsd license
USING: accessors arrays gpu.buffers gpu.framebuffers gpu.render
gpu.shaders gpu.textures images kernel locals opengl.framebuffers
specialized-arrays ;
USING: arrays destructors gpu.buffers gpu.framebuffers gpu.render
gpu.shaders gpu.state gpu.textures images kernel locals math
math.rectangles opengl.gl sequences specialized-arrays ;
FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: float
IN: gpu.util
@ -125,10 +125,34 @@ CONSTANT: window-vertexes
dup { { default-attachment { 0 0 0 } } } clear-framebuffer
] keep ;
: draw-texture ( texture -- )
: draw-texture ( texture dim -- )
{ 0 0 } swap <rect> <viewport-state> set-gpu-state
{
{ "primitive-mode" [ drop triangle-strip-mode ] }
{ "uniforms" [ window-uniforms boa ] }
{ "vertex-array" [ drop <window-vertex-buffer> window-program <program-instance> <vertex-array> ] }
{ "vertex-array" [ drop window-program <program-instance> <window-vertex-array> &dispose ] }
{ "indexes" [ drop T{ index-range f 0 4 } ] }
} <render-set> render ;
:: <streamed-vertex-array> ( verts program-instance -- vertex-array )
verts stream-upload draw-usage vertex-buffer byte-array>buffer &dispose
program-instance <vertex-array> &dispose ;
: (blended-point-sprite-batch) ( verts framebuffer texture point-size dim -- )
f eq-add func-one func-one <blend-mode> dup <blend-state> set-gpu-state
f origin-upper-left 1.0 <point-state> set-gpu-state
GL_POINT_SPRITE glEnable
{ 0 0 } swap <rect> <viewport-state> set-gpu-state
window-point-uniforms boa {
{ "primitive-mode" [ 3drop points-mode ] }
{ "uniforms" [ 2nip ] }
{ "vertex-array" [ 2drop window-point-program <program-instance> <streamed-vertex-array> ] }
{ "indexes" [ 2drop length 2 / 0 swap <index-range> ] }
{ "framebuffer" [ drop nip ] }
} 3<render-set> render ;
:: blended-point-sprite-batch ( verts texture point-size dim -- texture )
dim RGB float-components <2d-render-texture> :> ( target-framebuffer target-texture )
verts target-framebuffer texture point-size dim (blended-point-sprite-batch)
target-framebuffer dispose
target-texture ;

View File

@ -118,7 +118,7 @@
(format "\\_<\\(%s\\)?: +\\_<\\(\\w+\\)\\_>"
(regexp-opt
'(":" "GENERIC" "DEFER" "HOOK" "MAIN" "MATH" "POSTPONE"
"SYMBOL" "SYNTAX" "TYPED" "RENAME"))))
"SYMBOL" "SYNTAX" "TYPED" "TYPED:" "RENAME"))))
(defconst fuel-syntax--alias-definition-regex
"^ALIAS: +\\(\\_<.+?\\_>\\) +\\(\\_<.+?\\_>\\)")