opengl.texture-cache is not necessary; simplify code

db4
Slava Pestov 2009-02-15 04:33:43 -06:00
parent 9a1d324342
commit 628c219495
6 changed files with 13 additions and 52 deletions

View File

@ -1 +0,0 @@
Slava Pestov

View File

@ -1,4 +0,0 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test opengl.texture-cache ;
IN: opengl.texture-cache.tests

View File

@ -1,25 +0,0 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs cache colors.constants destructors fry
opengl.textures kernel ;
IN: opengl.texture-cache
TUPLE: texture-cache renderer cache disposed ;
: <texture-cache> ( renderer -- cache )
texture-cache new
swap >>renderer
<cache-assoc> >>cache ;
GENERIC: render-texture ( key renderer -- image )
: get-texture ( key texture-cache -- texture )
dup check-disposed
[ cache>> ] keep
'[ _ renderer>> render-texture <texture> ] cache ;
M: texture-cache dispose*
cache>> values dispose-each ;
: purge-texture-cache ( texture-cache -- )
cache>> purge-cache ;

View File

@ -1,10 +1,10 @@
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs continuations kernel math models call
namespaces opengl opengl.texture-cache sequences io combinators
USING: accessors arrays assocs continuations kernel math models
call namespaces opengl sequences io combinators
combinators.short-circuit fry math.vectors math.rectangles cache
ui.gadgets ui.gestures ui.render ui.text ui.text.private ui.backend
ui.gadgets.tracks ;
ui.gadgets ui.gestures ui.render ui.text ui.text.private
ui.backend ui.gadgets.tracks ;
IN: ui.gadgets.worlds
TUPLE: world < track
@ -67,7 +67,7 @@ M: world children-on nip children>> ;
[ init-gl ]
[ draw-gadget ]
[ finish-text-rendering ]
[ images>> [ purge-texture-cache ] when* ]
[ images>> [ purge-cache ] when* ]
} cleave
] with-gl-context ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces cache images images.loader accessors assocs kernel
opengl opengl.gl opengl.textures opengl.texture-cache ui.gadgets.worlds ;
USING: namespaces cache images images.loader accessors assocs
kernel opengl opengl.gl opengl.textures ui.gadgets.worlds ;
IN: ui.images
TUPLE: image-name path ;
@ -21,21 +21,15 @@ PRIVATE>
<PRIVATE
SINGLETON: image-renderer
M: image-renderer render-texture
drop cached-image ;
SLOT: images
: image-texture-cache ( world -- texture-cache )
[ [ image-renderer <texture-cache> ] unless* ] change-images
images>> ;
[ [ <cache-assoc> ] unless* ] change-images images>> ;
PRIVATE>
: rendered-image ( path -- texture )
world get image-texture-cache get-texture ;
world get image-texture-cache [ cached-image <texture> ] cache ;
: draw-image ( image-name -- )
rendered-image display-list>> glCallList ;

View File

@ -3,7 +3,7 @@
USING: assocs accessors alien core-graphics.types core-text
core-text.fonts kernel hashtables namespaces sequences
ui.gadgets.worlds ui.text ui.text.private opengl opengl.gl
opengl.texture-cache destructors combinators core-foundation
opengl.textures destructors combinators core-foundation
core-foundation.strings math math.vectors init colors colors.constants
cache arrays ;
IN: ui.text.core-text
@ -11,22 +11,19 @@ IN: ui.text.core-text
SINGLETON: core-text-renderer
M: core-text-renderer init-text-rendering
core-text-renderer <texture-cache> >>text-handle drop ;
<cache-assoc> >>text-handle drop ;
M: core-text-renderer string-dim
[ " " string-dim { 0 1 } v* ]
[ cached-line image>> dim>> ]
if-empty ;
M: core-text-renderer render-texture
drop first2 cached-line image>> ;
M: core-text-renderer finish-text-rendering
text-handle>> purge-texture-cache
text-handle>> purge-cache
cached-lines get purge-cache ;
: rendered-line ( font string -- texture )
2array world get text-handle>> get-texture ;
world get text-handle>> [ cached-line image>> <texture> ] 2cache ;
M: core-text-renderer draw-string ( font string -- )
rendered-line display-list>> glCallList ;