]> gitweb.factorcode.org Git - factor.git/commitdiff
opengl.textures: use GL_ARB_texture_non_power_of_two if available
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 8 Apr 2009 02:32:45 +0000 (21:32 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 8 Apr 2009 02:32:45 +0000 (21:32 -0500)
basis/opengl/textures/textures.factor
basis/ui/backend/backend.factor
basis/ui/gadgets/worlds/worlds.factor

index bb232affa4d7395a5ad1a6c5283bff68b19f2305..e13e99e10f320d6279896fee7124af602125e1b3 100755 (executable)
@@ -3,9 +3,11 @@
 USING: accessors assocs cache colors.constants destructors fry kernel
 opengl opengl.gl combinators images images.tesselation grouping
 specialized-arrays.float sequences math math.vectors
-math.matrices generalizations fry arrays ;
+math.matrices generalizations fry arrays namespaces ;
 IN: opengl.textures
 
+SYMBOL: non-power-of-2-textures?
+
 : gen-texture ( -- id ) [ glGenTextures ] (gen-gl-object) ;
 
 : delete-texture ( id -- ) [ glDeleteTextures ] (delete-gl-object) ;
@@ -29,9 +31,14 @@ GENERIC: draw-scaled-texture ( dim texture -- )
 
 TUPLE: single-texture image dim loc texture-coords texture display-list disposed ;
 
+: adjust-texture-dim ( dim -- dim' )
+    non-power-of-2-textures? get [
+        [ next-power-of-2 ] map
+    ] unless ;
+
 : (tex-image) ( image -- )
     [ GL_TEXTURE_2D 0 GL_RGBA ] dip
-    [ dim>> first2 [ next-power-of-2 ] bi@ 0 ]
+    [ dim>> adjust-texture-dim first2 0 ]
     [ component-order>> component-order>format f ] bi
     glTexImage2D ;
 
@@ -81,7 +88,7 @@ TUPLE: single-texture image dim loc texture-coords texture display-list disposed
     ] with-texturing ;
 
 : texture-coords ( texture -- coords )
-    [ [ dim>> ] [ image>> dim>> [ next-power-of-2 ] map ] bi v/ ]
+    [ [ dim>> ] [ image>> dim>> adjust-texture-dim ] bi v/ ]
     [
         image>> upside-down?>>
         { { 0 1 } { 1 1 } { 1 0 } { 0 0 } }
index d72ef13b4467d36f2b8ed4f9afa1c80fee9b46c8..9c844d366386873b725857a14bcb5734b363af58 100755 (executable)
@@ -1,6 +1,6 @@
-! Copyright (C) 2006, 2007 Slava Pestov.
+! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel namespaces opengl opengl.gl ;
+USING: kernel namespaces opengl opengl.gl fry ;
 IN: ui.backend
 
 SYMBOL: ui-backend
@@ -28,7 +28,7 @@ GENERIC: flush-gl-context ( handle -- )
 HOOK: offscreen-pixels ui-backend ( world -- alien w h )
 
 : with-gl-context ( handle quot -- )
-    swap [ select-gl-context call ] keep
-    flush-gl-context gl-error ; inline
+    '[ select-gl-context @ ]
+    [ flush-gl-context gl-error ] bi ; inline
 
 HOOK: (with-ui) ui-backend ( quot -- )
\ No newline at end of file
index 655c9ba49dfa35ac2c1beb9f518c63f2849777db..f671add531257750f8f308a6da0e281c9daad6f7 100644 (file)
@@ -1,9 +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
-namespaces opengl sequences io combinators combinators.short-circuit
-fry math.vectors math.rectangles cache ui.gadgets ui.gestures
-ui.render ui.backend ui.gadgets.tracks ui.commands ;
+namespaces opengl opengl.capabilities opengl.textures sequences io
+combinators combinators.short-circuit fry math.vectors math.rectangles
+cache ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
+ui.commands ;
 IN: ui.gadgets.worlds
 
 TUPLE: world < track
@@ -76,8 +77,13 @@ SYMBOL: flush-layout-cache-hook
 
 flush-layout-cache-hook [ [ ] ] initialize
 
+: check-extensions ( -- )
+    "2.0" { "GL_ARB_texture_non_power_of_two" } has-gl-version-or-extensions?
+    non-power-of-2-textures? set ;
+
 : (draw-world) ( world -- )
     dup handle>> [
+        check-extensions
         {
             [ init-gl ]
             [ draw-gadget ]