Hi,
> There's a word "add-definition-observer" in compiler.units that lets
> you register an object to have its "definitions-changed" method called
> whenever definitions are added or changed. You can look at
> tools.deprecation for a simple example of how it works.
Thanks, this works great.
> There's a refresh-program word in gpu.shaders that will try to
> recompile and relink the shaders for a GLSL-PROGRAM: definition. After
> you reload your source code, do «your-program-name refresh-program» .
> I thought about making this automatic, but I'm not sure it would be
> robust. As far as I know, there's no way to hook "refresh-all" to pick
> up shader sources stored in files separate from the factor source.
I was trying to code a definition observer for this case, but it doesn't
work as expected. refresh-program says that <program-instance>, et al.,
keep track of existing instances of a program, but when I have shaders
defined in Factor source, refresh-all generates new instances of the
shaders and programs anyway. So I can't really refresh the extant copies
referenced in my scene.
The same goes when I have a shader defined in a file... by the time I
refresh-all, the GLSL-PROGRAM instances are new. (And it's harder to
develop this way, since I'd have to hook up monitors to detect
that the shader files got changed, or touch some vocabulary to trigger
the definitions-changed listener.)
I was able to get this working for now by reloading my scene when any
definitions change at all, which has the side effect of recreating the
shaders and programs, but that seems like a blunt-force instrument. :)
Is there something I'm missing here? Does/could gpu.shaders store some
database of shaders by symbol so I could look them up dynamically, for
instance?
Here's my current definitons-changed instance, in case it could be made to work:
USING: kernel vocabs compiler.units accessors gpu.shaders assocs sequences
words.constant ;
TUPLE: shader-reloader ;
: refresh-if-program ( word -- )
def>> first
dup
program? [ refresh-program ] [ drop ] if
;
M: shader-reloader definitions-changed ( assoc obj -- )
drop keys
[ constant? ] filter [ refresh-if-program ] each
;
shader-reloader new add-definition-observer
Thanks,
-- Ed
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk