Support Rectangle texture from Stage3D

Software: Away3D 4.x

pajzsman, Newbie
Posted: 02 January 2013 09:36 AM   Total Posts: 3

Hi there,

My question is that when do you support rectangle texture from Stage3D which allows to create non-power of two sizes textures?
I am working with some images and it would really help.

Thanks

   

Oussama, Newbie
Posted: 02 January 2013 06:51 PM   Total Posts: 5   [ # 1 ]

Hi,
Textures should be power of 2, that’s stage3d limitation so away3d guys can’t do anything about it, but for your case I think you can make the image a part of a larger texture (make the rest transparent), create a plane with the desired size & play with the uvscale to avoid stretching.

   

pajzsman, Newbie
Posted: 02 January 2013 07:47 PM   Total Posts: 3   [ # 2 ]

Hi,

First, thanks for the idea.
But after a new release in last december, there is a new feature in Stage3D called rectangle texture which allows to have any size of texture.
So after that it will be possible to implement that in Away3D i guess.

   

pajzsman, Newbie
Posted: 02 January 2013 07:48 PM   Total Posts: 3   [ # 3 ]

Hi,

First, thanks for the idea.
But after a new release in last december, there is a new feature in Stage3D called rectangle texture which allows to have any size of texture.
So after that it will be possible to implement it in Away3D I guess.

   

Avatar
alihm, Jr. Member
Posted: 04 January 2013 11:10 AM   Total Posts: 49   [ # 4 ]

It’s possible to have rectangular textures in Stage3d but dimensions must be power of 2. for example 32x64.

   

afrosquared, Newbie
Posted: 05 July 2013 09:37 PM   Total Posts: 5   [ # 5 ]

Rectangular textures, that don’t need to be the power of 2, are possible with Air 3.8.  I’m sure the team already has something cooking up but here are the touch points I’ve found.  I read on the Starling forums that you may not want to use them all of the time.

1. Use Air 3.8+.

2. -swf-version=21

3. In Texture2DBase.as Line 20:
return context.createTexture(_width, _height, Context3DTextureFormat.BGRA, false);
...to…
return context[“createRectangleTexture”](_width, _height, Context3DTextureFormat.BGRA, false);

4. In BitmapTexture.as Line 38-39: Comment them out.

5. In BitmapTexure.as Line 52:
else Texture(texture).uploadFromBitmapData (_bitmapData, 0);
...to…
else texture[“uploadFromBitmapData”](_bitmapData);

6. I don’t think you are able to use MipMaps, so until an official is commited you’ll probably want to force a false on mipmaps.

Hope that helps.

   

ricovitch, Newbie
Posted: 11 April 2014 03:47 PM   Total Posts: 22   [ # 6 ]

I also would like to have support for this in Away3d. A good candidate for this feature is to have a better “webcam billboard” method.

See these post about the advantage of RectangleTexture for this usage :
http://www.flintfabrik.de/blog/webcam-performance-with-stage3d-part-iii-rectangletextures-in-air-3-8-beta-mobile

And an implementation for starling :
http://www.flintfabrik.de/blog/starling-webcamvideo-extension

   

ricovitch, Newbie
Posted: 14 April 2014 12:04 PM   Total Posts: 22   [ # 7 ]

Just tested a proof of concept implementation.
Here is the code in case someone wants to play with it or improve :

package away3d.textures
{
 import flash
.display.BitmapData;
 
import flash.display3D.Context3D;
 
import flash.display3D.Context3DTextureFormat;
 
import flash.display3D.textures.RectangleTexture;
 
import flash.display3D.textures.Texture;
 
import flash.display3D.textures.TextureBase;
 
 
import away3d.tools.utils.TextureUtils;
 
 
/**
  * NPOT : non power of two bitmap texture
  * uses a RectangleTexture instance internally if supported
  * Flash Player 11.8, AIR 3.8
  * 
  * @see http://help.adobe.com/fr_FR/FlashPlatform/reference/actionscript/3/flash/display3D/textures/RectangleTexture.html
  * @see http://away3d.com/forum/viewthread/3733/
  * @see https://github.com/shin10/Starling-WebcamVideo
  */
 
public class NPOTBitmapTexture extends Texture2DBase
 {
  
private var _bitmapData BitmapData;
  private var 
_bitmapDataPOT:Boolean false;
  private var 
_npotSupported:Boolean false;
  
  public function 
NPOTBitmapTexture(bitmapData:BitmapData)
  
{
   super
();
   
   
this.bitmapData bitmapData;
  
}
  
  
public function get bitmapData() : BitmapData
  {
   
return _bitmapData;
  
}
  
  
public function set bitmapData(value BitmapData) : void
  {
   
if (value == _bitmapData) return;
   
   
invalidateContent();
   
setSize(value.widthvalue.height);
   
   
_bitmapData value;
   
_bitmapDataPOT = (TextureUtils.isPowerOfTwo (_width) && TextureUtils.isPowerOfTwo (_height));
  
}
  
  override 
protected function createTexture(context:Context3D):TextureBase
  {
   
// FIXME fallback to normal texture if POT ?
   
if (_bitmapDataPOT) return super.createTexture (context);
   else 
{
    _npotSupported 
= ("createRectangleTexture" in context);
    if (!
_npotSupported) throw new Error("Non power of two textures not supported : requires swfversion 21+");
    return 
context["createRectangleTexture"(_width_heightContext3DTextureFormat.BGRAfalse);
   
}
  }
  
  override 
protected function uploadContent(texture TextureBase) : void
  {
   
if (!_npotSupportedTexture(texture).uploadFromBitmapData (_bitmapData0);
   else 
RectangleTexture(texture).uploadFromBitmapData (_bitmapData);
  
}
 }

A simple class with camera streaming using NPOTBitmapTexture :

package
{
 import flash
.display.BitmapData;
 
import flash.display.Sprite;
 
import flash.events.Event;
 
import flash.media.Camera;
 
import flash.media.Video;
 
import flash.text.TextField;
 
import flash.utils.getTimer;
 
 
import away3d.containers.View3D;
 
import away3d.textures.NPOTBitmapTexture;
 
import away3d.textures.Texture2DBase;
 
 public class 
Away3DWebcamVideo extends Sprite
 {
  
private var _view:View3D;
  private var 
_backgroundTexture:Texture2DBase;
  
  private var 
_camWidth:int;
  private var 
_camHeight:int;
  private var 
_camera:Camera;
  private var 
_video:Video;
  private var 
_backgroundFrame:BitmapData;
  
  private var 
_stats:TextField;
  
  public function 
Away3DWebcamVideo(camWidth:intcamHeight:int)
  
{
   _camWidth 
camWidth;
   
_camHeight camHeight;
   
addEventListener(Event.ADDED_TO_STAGEonAddedToStage);
  
}
  
  
private function onAddedToStage (evt:Event) : void
  {
   _view 
addChild (new View3D ()) as View3D;
   
_view.width stage.stageWidth;
   
_view.height stage.stageHeight;
   
   
_camera Camera.getCamera();
   
_camera.setLoopback(false);
   
_camera.setMode(_camWidth_camHeight30);
   
_video = new Video ();
   
_video.attachCamera (_camera);
   
   
_backgroundFrame = new BitmapData (_camWidth_camHeightfalse0);
   
_backgroundTexture = new NPOTBitmapTexture (_backgroundFrame);
   
_view.background _backgroundTexture;
   
   
_stats addChild (new TextField()) as TextField;
   
_stats.width 200;
   
_stats.height 200;
   
_stats.multiline _stats.wordWrap true;
   
_stats.textColor 0;
   
   
_camera.addEventListener (Event.VIDEO_FRAMEonCameraVideoFrame);
   
_view.addEventListener (Event.ENTER_FRAMErender);
  
}
  
  
private function onCameraVideoFrame (evt:Event) : void
  {
   drawFrame 
();
  
}
  
  
private var _drawFrameCount:int 0;
  private var 
_drawFrameTotal:int 0;
  private function 
drawFrame () : void
  {
   
var start:int getTimer();
   
_camera.drawToBitmapData (_backgroundFrame);
   
_backgroundTexture.invalidateContent ();
   
_drawFrameTotal += (getTimer() - start);
   
_drawFrameCount++;
  
}
  
  
private var _renderCount:int 0;
  private var 
_renderTotal:int 0;
  private function 
render (evt:Event) : void
  {
   
var start:int getTimer();
   
_view.render();
   
_renderTotal += (getTimer() - start);
   
_renderCount++;
   
   var 
output:String "CAM : " _camWidth "x" _camHeight "\n";
   
output += "DRAW : " + (_drawFrameTotal/_drawFrameCount).toFixed(2) + " (" _drawFrameCount ")\n";
   
output += "RENDER : " + (_renderTotal/_renderCount).toFixed(2) + " (" _renderCount ")";
   
_stats.text output;
   
  
}
 }

And the main :

package
{
 import flash
.display.Sprite;
 
 
[SWF(width="800"height="600"frameRate="60"backgroundColor="#ffffff")]
 
public class Main extends Sprite
 {
  
  
public function Main()
  
{
   
// away3d version : http://away3d.com/forum/viewthread/3733/
   
addChild (new Away3DWebcamVideo (640480));
  
}
 }
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X