]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.*: move some of the gl initing to set-up-window, should fix #1510
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 1 Dec 2015 03:49:36 +0000 (04:49 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Tue, 1 Dec 2015 03:49:36 +0000 (04:49 +0100)
it's also more efficent to run the check-extensions "1.0"
require-gl-version code only once when the window is created, rather
than once for each draw

basis/ui/gadgets/worlds/worlds.factor
basis/ui/render/render-docs.factor
basis/ui/render/render.factor
basis/ui/ui-docs.factor
basis/ui/ui.factor

index 43366603be8252c975a4ec368d7d1cc6d406082d..a374d9fa8f9d5f0989c9c4ce4a574ef33317694b 100644 (file)
@@ -3,8 +3,8 @@
 USING: accessors assocs cache colors combinators
 combinators.short-circuit concurrency.promises continuations
 destructors fry kernel literals math models namespaces opengl
-opengl.capabilities opengl.textures sequences strings ui.backend
-ui.gadgets ui.gadgets.tracks ui.gestures ui.pixel-formats
+opengl.capabilities opengl.gl opengl.textures sequences strings
+ui.backend ui.gadgets ui.gadgets.tracks ui.gestures ui.pixel-formats
 ui.render ;
 IN: ui.gadgets.worlds
 
@@ -187,10 +187,8 @@ M: world dim<<
 GENERIC: draw-world* ( world -- )
 
 M: world draw-world*
-    check-extensions
-    "1.0" require-gl-version
     {
-        [ init-gl ]
+        [ gl-draw-init ]
         [ draw-gadget ]
         [ text-handle>> [ purge-cache ] when* ]
         [ images>> [ purge-cache ] when* ]
index 4a7b5e8dc2b97d84012f8d91df00c84e20b1caf5..37c2b4d34071a5d23e37a95403e12372240a1586 100644 (file)
@@ -1,14 +1,22 @@
-USING: ui.gadgets ui.pens ui.gestures help.markup help.syntax
-kernel classes strings opengl opengl.gl models
-math.rectangles math colors ;
+USING: help.markup help.syntax math.rectangles models opengl.gl
+ui.gadgets ui.gadgets.worlds ui.gestures ui.pens ;
 IN: ui.render
 
+HELP: clip
+{ $var-description "The current clipping rectangle." } ;
+
+HELP: draw-gadget*
+{ $values { "gadget" gadget } }
+{ $contract "Draws the gadget by making OpenGL calls. The top-left corner of the gadget should be drawn at the location stored in the " { $link origin } " variable." }
+{ $notes "This word should not be called directly. To force a gadget to redraw, call " { $link relayout-1 } "." } ;
+
 HELP: gadget
 { $class-description "An object which displays itself on the screen and acts on user input gestures. Gadgets have the following slots:"
     { $list
         { { $snippet "pref-dim" } " - a cached value for " { $link pref-dim } "; do not read or write this slot directly." }
         { { $snippet "parent" } " - the gadget containing this one, or " { $link f } " if this gadget is not part of the visible gadget hierarchy." }
         { { $snippet "children" } " - a vector of child gadgets. Do not modify this vector directly, instead use " { $link add-gadget } ", " { $link add-gadgets } ", " { $link unparent } " or " { $link clear-gadget } "." }
+      { { $snippet "graft-state" } { "This two tuple represents the current graft state of the gadget and what its next state will become." } }
         { { $snippet "orientation" } " - an orientation specifier. This slot is used by layout gadgets." }
         { { $snippet "layout-state" } " - stores the layout state of the gadget. Do not read or write this slot directly, instead call " { $link relayout } " and " { $link relayout-1 } " if the gadget needs to be re-laid out." }
         { { $snippet "visible?" } " - a boolean indicating if the gadget should display and receive user input." }
@@ -22,13 +30,9 @@ HELP: gadget
 { $notes
 "Other classes may inherit from " { $link gadget } " in order to re-implement generic words such as " { $link draw-gadget* } " and " { $link user-input* } ", or to define gestures with " { $link set-gestures } "." } ;
 
-HELP: clip
-{ $var-description "The current clipping rectangle." } ;
-
-HELP: draw-gadget*
-{ $values { "gadget" gadget } }
-{ $contract "Draws the gadget by making OpenGL calls. The top-left corner of the gadget should be drawn at the location stored in the " { $link origin } " variable." }
-{ $notes "This word should not be called directly. To force a gadget to redraw, call " { $link relayout-1 } "." } ;
+HELP: gl-draw-init
+{ $values { "world" world } }
+{ $description "Does some OpenGL setup that is required each time the world is to be redrawn." } ;
 
 ARTICLE: "ui-paint" "Customizing gadget appearance"
 "The UI carries out the following steps when drawing a gadget:"
index 5f9bcb0e9d417fc9bccdf69eb272b413b27048d5..0fb9e6cc1be8a70c00658a9c567248720c8ae8f7 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: math.rectangles math.vectors namespaces kernel accessors
-assocs combinators sequences sets opengl opengl.gl colors
-colors.constants ui.gadgets ui.pens ;
+USING: accessors colors colors.constants combinators kernel
+math.rectangles math.vectors namespaces opengl opengl.capabilities
+opengl.gl opengl.textures sequences sets ui.gadgets ui.pens ;
 IN: ui.render
 
 SYMBOL: clip
@@ -17,7 +17,7 @@ SYMBOL: viewport-translation
 
 : do-clip ( -- ) clip get flip-rect gl-set-clip ;
 
-: init-clip ( clip-rect -- )
+: init-clip ( gadget -- )
     [
         dim>>
         [ { 0 1 } v* viewport-translation set ]
@@ -29,14 +29,17 @@ SYMBOL: viewport-translation
 
 SLOT: background-color
 
-: init-gl ( world -- )
+: gl-init ( -- )
+    check-extensions "1.0" require-gl-version
     GL_SMOOTH glShadeModel
-    GL_SCISSOR_TEST glEnable
     GL_BLEND glEnable
     GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
     GL_VERTEX_ARRAY glEnableClientState
     GL_PACK_ALIGNMENT 1 glPixelStorei
-    GL_UNPACK_ALIGNMENT 1 glPixelStorei
+    GL_UNPACK_ALIGNMENT 1 glPixelStorei ;
+
+: gl-draw-init ( world -- )
+    GL_SCISSOR_TEST glEnable
     init-matrices
     [ init-clip ]
     [
index 7a5a4562778e58809d0afc9da2563c4250fa7799..e060dff42b932fd3244d0cd1cea02ae49c1632bf 100644 (file)
@@ -35,6 +35,10 @@ HELP: set-fullscreen
 { $values { "gadget" gadget } { "?" boolean } }
 { $description "Sets and unsets fullscreen mode for the gadget's world." } ;
 
+HELP: set-up-window
+{ $values { "world" world } }
+{ $description "Initializes the window that shows the world." } ;
+
 HELP: fullscreen?
 { $values { "gadget" gadget } { "?" boolean } }
 { $description "Queries the gadget's world to see if it is running in fullscreen mode." } ;
index dbbe7e7e1964ec24c32ad98eb6e000ca32b3f647..289dd23d0f2bd9710c880f8555cb71df55b17d21 100644 (file)
@@ -3,10 +3,10 @@
 USING: accessors arrays assocs boxes classes.tuple
 classes.tuple.parser combinators combinators.short-circuit
 concurrency.flags concurrency.promises continuations deques
-destructors dlists fry init kernel lexer make math namespaces parser
-sequences sets strings threads ui.backend ui.gadgets
-ui.gadgets.private ui.gadgets.worlds ui.gestures vectors vocabs.parser
-words ;
+destructors dlists fry init io.streams.c kernel lexer make math
+namespaces parser sequences sets strings threads ui.backend ui.gadgets
+ui.gadgets.private ui.gadgets.worlds ui.gestures ui.render vectors
+vocabs.parser words ;
 IN: ui
 
 <PRIVATE
@@ -65,7 +65,7 @@ SYMBOL: ui-windows
         [ begin-world ]
         [ resize-world ]
         [ request-focus ]
-    } cleave ;
+    } cleave gl-init ;
 
 : clean-up-broken-window ( world -- )
     [