From 87e45985811a0c3d2f10fc97ea28cc0e0378aab0 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 7 Apr 2009 21:32:45 -0500 Subject: [PATCH] opengl.textures: use GL_ARB_texture_non_power_of_two if available --- basis/opengl/textures/textures.factor | 13 ++++++++++--- basis/ui/backend/backend.factor | 8 ++++---- basis/ui/gadgets/worlds/worlds.factor | 12 +++++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/basis/opengl/textures/textures.factor b/basis/opengl/textures/textures.factor index bb232affa4..e13e99e10f 100755 --- a/basis/opengl/textures/textures.factor +++ b/basis/opengl/textures/textures.factor @@ -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 } } diff --git a/basis/ui/backend/backend.factor b/basis/ui/backend/backend.factor index d72ef13b44..9c844d3663 100755 --- a/basis/ui/backend/backend.factor +++ b/basis/ui/backend/backend.factor @@ -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 diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index 655c9ba49d..f671add531 100644 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -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 ]