]> gitweb.factorcode.org Git - factor.git/commitdiff
images, opengl.textures, images.cocoa: add support for premultiplied alpha so we...
authorJoe Groff <arcata@gmail.com>
Sun, 27 Jun 2010 20:44:16 +0000 (13:44 -0700)
committerJoe Groff <arcata@gmail.com>
Sun, 27 Jun 2010 20:44:25 +0000 (13:44 -0700)
Raytrace.app/Contents/Info.plist [new file with mode: 0644]
basis/images/cocoa/cocoa.factor
basis/images/images.factor
basis/opengl/textures/textures.factor
extra/gpu/textures/textures.factor

diff --git a/Raytrace.app/Contents/Info.plist b/Raytrace.app/Contents/Info.plist
new file mode 100644 (file)
index 0000000..776fd81
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>CFBundleExecutable</key>
+       <string>gpu.demos.raytrace</string>
+       <key>CFBundleIconFile</key>
+       <string>Icon.icns</string>
+       <key>CFBundleIdentifier</key>
+       <string>org.factor.gpu.demos.raytrace</string>
+       <key>CFBundleInfoDictionaryVersion</key>
+       <string>6.0</string>
+       <key>CFBundleName</key>
+       <string>Raytrace.app</string>
+       <key>CFBundlePackageType</key>
+       <string>APPL</string>
+</dict>
+</plist>
index 1d71738904a2368ffb9ccf2a8f222ccfdb7f037b..166a5f8196e6ac54be4d1168969821b6315cc4c5 100644 (file)
@@ -1,7 +1,8 @@
 ! (c)2010 Joe Groff bsd license
 USING: accessors alien.data cocoa cocoa.classes cocoa.messages
 combinators core-foundation.data core-graphics.types fry images
-images.loader io io.streams.limited kernel literals ;
+images.loader io io.streams.limited kernel literals math 
+sequences ;
 IN: images.cocoa
 
 SINGLETON: ns-image
@@ -52,12 +53,13 @@ PRIVATE>
 
 : image-rep>image ( image-rep -- image )
     image new swap {
-        [ -> size CGSize>dim >>dim ]
+        [ -> size CGSize>dim [ >integer ] map >>dim ]
         [ -> bitmapData ]
         [ -> bytesPerPlane memory>byte-array >>bitmap ]
     } cleave
         RGBA >>component-order
         ubyte-components >>component-type
+        t >>premultiplied-alpha?
         f >>upside-down? ;
 
 M: ns-image stream>image
index 6cbcdb9508f7235f4294f5a3fc5e8f7ad0efe306..db731d20452848df476fff541b801a51316ccffd 100644 (file)
@@ -62,7 +62,10 @@ UNION: alpha-channel BGRA RGBA ABGR ARGB LA A INTENSITY ;
 
 UNION: alpha-channel-precedes-colors ABGR ARGB XBGR XRGB ;
 
-TUPLE: image dim component-order component-type upside-down? bitmap ;
+TUPLE: image
+    dim component-order component-type
+    upside-down? premultiplied-alpha?
+    bitmap ;
 
 : <image> ( -- image ) image new ; inline
 
index dacea0888a277fb484d352632e9a85fe1670b8e4..bba41653042da751686322c7d15dc00fcac20c14 100644 (file)
@@ -312,12 +312,21 @@ TUPLE: single-texture < disposable image dim loc texture-coords texture display-
     [ init-texture texture-coords>> gl-texture-coord-pointer ] tri
     swap gl-fill-rect ;
 
+: set-blend-mode ( texture -- )
+    image>> dup has-alpha?
+    [ premultiplied-alpha?>> [ GL_ONE GL_ONE_MINUS_SRC_ALPHA glBlendFunc ] when ]
+    [ drop GL_BLEND glDisable ] if ;
+
+: reset-blend-mode ( texture -- )
+    image>> dup has-alpha?
+    [ premultiplied-alpha?>> [ GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc ] when ]
+    [ drop GL_BLEND glEnable ] if ;
+
 : draw-textured-rect ( dim texture -- )
     [
-        [ image>> has-alpha? [ GL_BLEND glDisable ] unless ]
+        [ set-blend-mode ]
         [ (draw-textured-rect) GL_TEXTURE_2D 0 glBindTexture ]
-        [ image>> has-alpha? [ GL_BLEND glEnable ] unless ]
-        tri
+        [ reset-blend-mode ] tri
     ] with-texturing ;
 
 : texture-coords ( texture -- coords )
index a240aae9452163ff3d4d40cfa2742402c7a669f5..55e6f7c0f4285b85919a544f9672ab51233bd193 100644 (file)
@@ -309,7 +309,7 @@ TYPED: read-compressed-texture ( tdt: texture-data-target level: integer -- byte
 
 : read-texture-image ( tdt level -- image )
     [ texture-dim ]
-    [ drop texture-object [ component-order>> ] [ component-type>> ] bi f ]
+    [ drop texture-object [ component-order>> ] [ component-type>> ] bi f ]
     [ read-texture ] 2tri
     image boa ; inline