images, opengl.textures, images.cocoa: add support for premultiplied alpha so we can use data from cocoa images

db4
Joe Groff 2010-06-27 13:44:16 -07:00
parent 3029a94756
commit 0d35e277ea
5 changed files with 39 additions and 7 deletions

View File

@ -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>

View 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

View 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

View 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 )

View 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 f ]
[ read-texture ] 2tri
image boa ; inline