Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

randomly corrupted atf texture

Guest
Nov 11, 2013 Nov 11, 2013

I'm trying to render single fullscreen atf texture. And it is rendered corrupted sometimes (repro 4/10).

Only happens if texture is less then 256x256 size (128x128 for example) and has transparency.

Have somebody encountered same problem?

Or is there some atf texture requirements I am missing?

Texture:

test_128.png

Corrupted result: (vertical lines are bug)

bug.jpg

TOPICS
ActionScript
539
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 11, 2013 Nov 11, 2013

How does this issue relate to Actionscript 3? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 11, 2013 Nov 11, 2013
LATEST

A bit more background on the issue:

Texture is rendered using stage3d (and action script of cause).

Air SDK version is 3.8

Platform: android

Texture compression: dxt5

test code:

package {

import com.adobe.utils.AGALMiniAssembler;

import flash.display.Sprite;

import flash.display.Stage3D;

import flash.display.StageAlign;

import flash.display.StageScaleMode;

import flash.display3D.Context3D;

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.Matrix;

import flash.geom.Matrix3D;

import flash.utils.ByteArray;

public class AtfTest1 extends Sprite {

    private static const PAD:Number = 5;

    [Embed(source="test_128.atf", mimeType="application/octet-stream")]

    private static const TEXTURE_ATF:Class;

    private const textureWidth:int = 128;

    private const textureHeight:int = textureWidth;

    private var program:Program3D;

    private var posUV:VertexBuffer3D;

    private var tris:IndexBuffer3D;

    private var textureATF:Texture;

    private var context3D:Context3D;

    public function AtfTest1()

    {

        stage.align = StageAlign.TOP_LEFT;

        stage.scaleMode = StageScaleMode.NO_SCALE;

        stage.frameRate = 60;

        var stage3D:Stage3D = stage.stage3Ds[0];

        stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);

        stage3D.requestContext3D(Context3DRenderMode.AUTO);

    }

    protected function onContextCreated(ev:Event): void

    {

        var stage3D:Stage3D = stage.stage3Ds[0];

        stage3D.removeEventListener(Event.CONTEXT3D_CREATE, onContextCreated);

        context3D = stage3D.context3D;

        context3D.configureBackBuffer(stage.stageWidth, stage.stageHeight, 0, false);

        context3D.enableErrorChecking = true;

        var vertexProgramCode:String =

                "m44 op, va0, vc1 \n" + // 4x4 matrix transform to output clipspace

                        "mov v1, va1      \n";  // pass texture coordinates to fragment program

        var assembler:AGALMiniAssembler = new AGALMiniAssembler();

        assembler.assemble(

                Context3DProgramType.VERTEX,

                vertexProgramCode

        );

        var vertexProgram:ByteArray = assembler.agalcode;

        assembler.assemble(

                Context3DProgramType.FRAGMENT,

                //"tex oc, v1, fs0 <2d,linear,mipnone,clamp,dxt1>"

                "tex oc, v1, fs0 <2d,linear,mipnone,clamp,dxt5>"

        );

        var fragmentProgram:ByteArray = assembler.agalcode;

        program = context3D.createProgram();

        program.upload(vertexProgram, fragmentProgram);

        var u:Number = 1;

        var v:Number = 1;

        posUV = context3D.createVertexBuffer(4, 5);

        posUV.uploadFromVector(

                new <Number>[

                    // X,  Y, Z, U, V

                    -1,   -1, 0, 0, v,

                    -1,    1, 0, 0, 0,

                    1,    1, 0, u, 0,

                    1,   -1, 0, u, v

                ], 0, 4

        );

        // Create the triangles index buffer

        tris = context3D.createIndexBuffer(6);

        tris.uploadFromVector(

                new <uint>[

                    0, 1, 2,

                    2, 3, 0

                ], 0, 6

        );

        var atfBytes:ByteArray = new TEXTURE_ATF() as ByteArray;

        textureATF = context3D.createTexture(

                textureWidth,

                textureHeight,

                //Context3DTextureFormat.COMPRESSED,

                Context3DTextureFormat.COMPRESSED_ALPHA,

                false

        );

        textureATF.uploadCompressedTextureFromByteArray(atfBytes, 0);

        addEventListener(Event.ENTER_FRAME, onEnterFrame);

    }

    private function onEnterFrame(ev:Event): void

    {

        context3D.clear(0.5, 0.5, 0.5);

        context3D.setProgram(program);

        context3D.setTextureAt(0, textureATF);

        context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 1, convertTo3D(new Matrix()), true);

        context3D.setVertexBufferAt(0, posUV, 0, Context3DVertexBufferFormat.FLOAT_3);

        context3D.setVertexBufferAt(1, posUV, 3, Context3DVertexBufferFormat.FLOAT_2);

        context3D.drawTriangles(tris);

        context3D.present();

    }

    private static var sRawData:Vector.<Number> =

            new <Number>[1, 0, 0, 0,  0, 1, 0, 0,  0, 0, 1, 0,  0, 0, 0, 1];

    public static function convertTo3D(matrix:Matrix, resultMatrix:Matrix3D=null):Matrix3D

    {

        if (resultMatrix == null) resultMatrix = new Matrix3D();

        sRawData[0] = matrix.a;

        sRawData[1] = matrix.b;

        sRawData[4] = matrix.c;

        sRawData[5] = matrix.d;

        sRawData[12] = matrix.tx;

        sRawData[13] = matrix.ty;

        resultMatrix.copyRawDataFrom(sRawData);

        return resultMatrix;

    }

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines