2009-02-10 03:45:43 -05:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: accessors assocs cache colors.constants destructors fry
|
2009-02-10 19:47:34 -05:00
|
|
|
kernel opengl opengl.gl combinators ;
|
2009-02-10 03:45:43 -05:00
|
|
|
IN: opengl.texture-cache
|
|
|
|
|
2009-02-10 23:05:13 -05:00
|
|
|
TUPLE: texture texture display-list disposed ;
|
2009-02-10 03:45:43 -05:00
|
|
|
|
|
|
|
: make-texture-display-list ( dim texture -- dlist )
|
2009-02-11 05:54:06 -05:00
|
|
|
GL_COMPILE [ draw-textured-rect ] make-dlist ;
|
2009-02-10 03:45:43 -05:00
|
|
|
|
2009-02-10 19:47:34 -05:00
|
|
|
TUPLE: texture-info dim bitmap format type ;
|
|
|
|
|
|
|
|
C: <texture-info> texture-info
|
|
|
|
|
|
|
|
: <texture> ( info -- texture )
|
|
|
|
[
|
|
|
|
{ [ dim>> ] [ bitmap>> ] [ format>> ] [ type>> ] }
|
|
|
|
cleave make-texture
|
|
|
|
] [ dim>> ] bi
|
2009-02-10 23:05:13 -05:00
|
|
|
over make-texture-display-list f texture boa ;
|
2009-02-10 03:45:43 -05:00
|
|
|
|
|
|
|
M: texture dispose*
|
|
|
|
[ texture>> delete-texture ]
|
|
|
|
[ display-list>> delete-dlist ] bi ;
|
|
|
|
|
2009-02-10 19:47:34 -05:00
|
|
|
TUPLE: texture-cache renderer cache disposed ;
|
2009-02-10 03:45:43 -05:00
|
|
|
|
2009-02-10 19:47:34 -05:00
|
|
|
: <texture-cache> ( renderer -- cache )
|
2009-02-10 03:45:43 -05:00
|
|
|
texture-cache new
|
2009-02-10 19:47:34 -05:00
|
|
|
swap >>renderer
|
2009-02-10 03:45:43 -05:00
|
|
|
<cache-assoc> >>cache ;
|
|
|
|
|
2009-02-10 19:47:34 -05:00
|
|
|
GENERIC: render-texture ( key renderer -- texture-info )
|
2009-02-10 03:45:43 -05:00
|
|
|
|
2009-02-11 05:54:06 -05:00
|
|
|
: get-texture ( key texture-cache -- texture )
|
2009-02-10 03:45:43 -05:00
|
|
|
dup check-disposed
|
|
|
|
[ cache>> ] keep
|
2009-02-11 05:54:06 -05:00
|
|
|
'[ _ renderer>> render-texture <texture> ] cache ;
|
2009-02-10 03:45:43 -05:00
|
|
|
|
|
|
|
M: texture-cache dispose*
|
|
|
|
cache>> values dispose-each ;
|
|
|
|
|
|
|
|
: purge-texture-cache ( texture-cache -- )
|
|
|
|
cache>> purge-cache ;
|