Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何实现纹理的运行时压缩?_Actionscript 3_Flash_Stage3d_Agal - Fatal编程技术网

Actionscript 3 如何实现纹理的运行时压缩?

Actionscript 3 如何实现纹理的运行时压缩?,actionscript-3,flash,stage3d,agal,Actionscript 3,Flash,Stage3d,Agal,我在这里读过文件: Flash Player 11.4和AIR 3.4支持运行时纹理压缩, 这在某些情况下很有用,例如渲染Dynamic时 来自矢量艺术的纹理。要使用运行时纹理压缩,请执行 以下步骤: 通过调用Context3D.createTexture()创建纹理对象 方法,通过 flash.display3D.Context3DTextureFormat.COMPRESSED orflash.display3D.Context3DTextureFormat.COMPRESSED_ALPH

我在这里读过文件:

Flash Player 11.4和AIR 3.4支持运行时纹理压缩, 这在某些情况下很有用,例如渲染Dynamic时 来自矢量艺术的纹理。要使用运行时纹理压缩,请执行 以下步骤:

通过调用Context3D.createTexture()创建纹理对象 方法,通过 flash.display3D.Context3DTextureFormat.COMPRESSED orflash.display3D.Context3DTextureFormat.COMPRESSED_ALPHA位于第三个 参数使用flash.display3D.textures.Texture实例 由createTexture()返回,调用 flash.display3D.textures.Texture.uploadFromBitmapData() orflash.display3D.textures.Texture.uploadFromByteArray()。这些 方法一步上传并压缩纹理

我尝试按照步骤操作,但出现错误:

错误:错误#3763:采样器0绑定不匹配的纹理 AGAL中指定的读取模式。读取压缩或单/双 通道纹理必须显式声明。 在flash.display3D::Context3D/drawTriangles()中

我应该把一些指示也放在背面吗

以下是完整的代码:

注意:我没有使用嵌入的png作为纹理,因为我尝试了,但失败了,只是创建了一个空的bitmapdata运行时,在我的macos flash player 11.8上不起作用

从这里抓到了AGALMiniAssembler.as:

包沙箱
{
导入com.adobe.utils.AGALMiniAssembler;
导入com.adobe.utils.PerspectiveMatrix3D;
导入flash.display.BitmapData;
导入flash.display.Sprite;
导入flash.display.Stage3D;
导入flash.display.StageAlign;
导入flash.display.StageScaleMode;
导入flash.display3D.Context3D;
导入flash.display3D.Context3DProfile;
导入flash.display3D.Context3DProgramType;
导入flash.display3D.Context3DRenderMode;
导入flash.display3D.Context3DTextureFormat;
导入flash.display3D.Context3DVertexBufferFormat;
导入flash.display3D.IndexBuffer3D;
导入flash.display3D.Program3D;
导入flash.display3D.VertexBuffer3D;
导入flash.display3D.textures.Texture;
导入flash.events.Event;
导入flash.geom.Matrix3D;
导入core.Scene3D;
[SWF(width=“600”、height=“800”、frameRate=“60”)]
公共类TestCompressedTexture扩展了Sprite
{
[嵌入(source=“../../assets/tex_cube.png”)]
私有多维数据集:类;
私有变量swfHeight:int;
私有变量swfWidth:int;
公共变量context3D:context3D;
public var viewMatrix:Matrix3D=新的Matrix3D();
公共var projectionMatrix:PerspectiveMatrix3D=新的PerspectiveMatrix3D();
公共变量meshIndexData:Vector.=Vector。
([
0, 1, 2, 0, 2, 3,   
]);
公共变量meshVertexData:Vector.=Vector([
//x、 y,z u,v nx,ny,nz
-1, -1,  1, 0, 0,  0, 0, 1,
1, -1,  1, 1, 0,  0, 0, 1,
1,  1,  1, 1, 1,  0, 0, 1,
-1,  1,  1, 0, 1,  0, 0, 1,
]);
私有var indexBuffer:IndexBuffer3D;
私有变量vertexBuffer:VertexBuffer3D;
私人var计划:Program3D;
private var_modelViewProjection:Matrix3D=new Matrix3D();
私有var模型矩阵:Matrix3D=新Matrix3D();
纹理:纹理;
私有变量uvBuffer:VertexBuffer3D;
公共函数测试CompressedTexture()
{
_SWFHight=600;
_swfWidth=800;
如果(阶段!=null){
init();
}否则{
addEventListener(事件。添加到\u阶段,初始化);
}
projectionMatrix.identity();
投影矩阵透视视场RH(45.0,宽/高,0.001100.0);
modelMatrix.identity();
identity();
viewMatrix.prependTranslation(0,0,-5);
超级();
}
私有函数init(e:Event=null):void{
if(hasEventListener(将Event.ADDED_添加到_阶段))
removeEventListener(将事件添加到初始阶段);
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP\u左;
stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE,onContext3DCreate);
stage.stage3Ds[0].requestContext3D(Context3DRenderMode.AUTO,Context3DProfile.BASELINE\u扩展);
}
受保护函数onContext3DCreate(e:事件):无效
{
removeEventListener(事件。输入帧,输入帧);
变量t:Stage3D=e。目标为Stage3D;
context3D=t.context3D;
if(context3D==null){
返回;
}
context3D.enableErrorChecking=true;
configureBackBuffer(_-swfWidth,_-swfHeight,0,true);
dispatchEvent(新事件(Scene3D.Scene3D_已创建));
createProgram();
createTexture();
createBuffer();
addEventListener(事件。输入帧,输入帧);
}
公共函数createProgram():void{
var vsa:AGALMiniAssembler=新的AGALMiniAssembler();
变量vs:String=
m44操作,va0,vc0\n+
“mov v0,va1\n”//uv
;
var-fs:String=
tex ft0,v0,fs0\n+
“mov oc ft0\n”
;
程序=vsa.assemble2(context3D,1,vs,fs);
context3D.setProgram(program);
}
公共函数createBuffer():void{
indexBuffer=context3D.createIndexBuffer(meshIndexData.length);
上传自向量(meshIndexData,0,meshIndexData.length);
vertexBuffer=context3D.createVertexBuffer(meshVertexData.length/8,8);
vertexBuffer.uploadFromVector(meshVertexData,0,meshVertexData.length/8);
}
package sandbox
{
    import com.adobe.utils.AGALMiniAssembler;
    import com.adobe.utils.PerspectiveMatrix3D;

    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.Stage3D;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display3D.Context3D;
    import flash.display3D.Context3DProfile;
    import flash.display3D.Context3DProgramType;
    import flash.display3D.Context3DRenderMode;
    import flash.display3D.Context3DTextureFormat;
    import flash.display3D.Context3DVertexBufferFormat;
    import flash.display3D.IndexBuffer3D;
    import flash.display3D.Program3D;
    import flash.display3D.VertexBuffer3D;
    import flash.display3D.textures.Texture;
    import flash.events.Event;
    import flash.geom.Matrix3D;

    import core.Scene3D;

    [SWF(width="600",height="800",frameRate="60")]
    public class TestCompressedTexture extends Sprite
    {
        [Embed(source="../../assets/tex_cube.png")]
        private var TexCube:Class;
        private var _swfHeight:int;
        private var _swfWidth:int;
        public var context3D:Context3D;
        public var viewMatrix:Matrix3D = new Matrix3D();
        public var projectionMatrix:PerspectiveMatrix3D = new PerspectiveMatrix3D();

        public var meshIndexData:Vector.<uint> = Vector.<uint>
            ([
                0, 1, 2, 0, 2, 3,   
            ]);

        public var meshVertexData:Vector.<Number> = Vector.<Number>([
            //x,y,z     u,v    nx,ny,nz
            -1, -1,  1, 0, 0,  0, 0, 1,
            1, -1,  1, 1, 0,  0, 0, 1,
            1,  1,  1, 1, 1,  0, 0, 1,
            -1,  1,  1, 0, 1,  0, 0, 1,
        ]);
        private var indexBuffer:IndexBuffer3D;
        private var vertexBuffer:VertexBuffer3D;
        private var program:Program3D;
        private var _modelViewProjection:Matrix3D = new Matrix3D();
        private var modelMatrix:Matrix3D = new Matrix3D();
        private var texture:Texture;
        private var uvBuffer:VertexBuffer3D;

        public function TestCompressedTexture()
        {
            _swfHeight = 600;
            _swfWidth = 800;
            if (stage!=null){
                init();
            }else{
                addEventListener(Event.ADDED_TO_STAGE,init);
            }
            projectionMatrix.identity();
            projectionMatrix.perspectiveFieldOfViewRH(45.0,_swfWidth/_swfHeight,0.001,100.0);
            modelMatrix.identity();
            viewMatrix.identity();
            viewMatrix.prependTranslation(0,0,-5);
            super();
        }

        private function init(e:Event=null):void{
            if (hasEventListener(Event.ADDED_TO_STAGE))
                removeEventListener(Event.ADDED_TO_STAGE,init);
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE,onContext3DCreate);
            stage.stage3Ds[0].requestContext3D(Context3DRenderMode.AUTO,Context3DProfile.BASELINE_EXTENDED);
        }

        protected function onContext3DCreate(e:Event):void
        {
            removeEventListener(Event.ENTER_FRAME,enterFrame);
            var t:Stage3D = e.target as Stage3D;
            context3D = t.context3D;
            if (context3D == null){
                return;
            }
            context3D.enableErrorChecking = true;

            context3D.configureBackBuffer(_swfWidth,_swfHeight,0,true);
            dispatchEvent(new Event(Scene3D.SCENE3D_CREATED));

            createProgram();
            createTexture();
            createBuffer();
            addEventListener(Event.ENTER_FRAME,enterFrame);
        }

        public function createProgram():void{
            var vsa:AGALMiniAssembler = new AGALMiniAssembler();

            var vs:String = 
                "m44 op, va0, vc0\n" +
                "mov v0, va1\n" //uv
                ;
            var fs:String =
                "tex ft0, v0, fs0 <2d,repeat,nomip>\n"+
                "mov oc ft0 \n"
                ;
            program = vsa.assemble2(context3D,1,vs,fs);
            context3D.setProgram(program);
        }

        public function createBuffer():void{
            indexBuffer = context3D.createIndexBuffer(meshIndexData.length);
            indexBuffer.uploadFromVector(meshIndexData,0,meshIndexData.length);


            vertexBuffer = context3D.createVertexBuffer(meshVertexData.length/8,8);
            vertexBuffer.uploadFromVector(meshVertexData,0,meshVertexData.length /8);


        }

        public function createTexture():void{
//          texture = context3D.createTexture(512, 512, Context3DTextureFormat.BGRA, false);
            texture = context3D.createTexture(512, 512, Context3DTextureFormat.COMPRESSED, false);
//          var texCube:BitmapData = new TexCube().bitmapData;
//          trace(texCube.height,texCube.width);
            var bmd:BitmapData = new BitmapData(512,512);

            texture.uploadFromBitmapData(bmd);
        }

        protected function enterFrame(event:Event):void
        {
            context3D.clear();

            _modelViewProjection.identity();
            _modelViewProjection.append(modelMatrix);
            _modelViewProjection.append(viewMatrix);
            _modelViewProjection.append(projectionMatrix);
            // pass our matrix data to the shader program
            context3D.setProgramConstantsFromMatrix(
                Context3DProgramType.VERTEX,
                0, _modelViewProjection, true );

            context3D.setVertexBufferAt(0, vertexBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);
            context3D.setVertexBufferAt(1, vertexBuffer, 3, Context3DVertexBufferFormat.FLOAT_2);
            context3D.setTextureAt(0,texture);

            context3D.drawTriangles(indexBuffer);

            context3D.present();
        }
    }
}