AGAL programs. Where to save them (stage3D support)


(Martí Angelats i Ribera) #1

Let me explain what this is about:

When using stage3D, you program the GPU using binary instructions saved in a little endian byte array. Of course make this is hard so we have an Assembler lenguage called AGAL. To transform one to another you need to use an assembler. This is a bit low and requires an external class (but it’s already made by Adobe itself), so i’ll save directly an Array of bytes and then transfor it into a ByteArray.

Obviously, the binary code is unreadable so the think is to have the AGAL codes aviable. The question is where to save them. As commentaries ahead of every program or should just exist a flain text file with all the programs?

Thanks for your opinion.


PD: i’m also thinking of making Draw functions using AGAL wich will be way faster but requires stage3D.


(Jacob Albano) #2

The way I’ve seen it done most often is in an XML document with CDATA tags:

<shader>
    <vert>
    <![CDATA[
        m44 vt0, va0, vc0
        mov v0, va1
        mov v1, va2
        mov op, vt0
    ]]>
    </vert>
    <frag>
    <![CDATA[
        tex ft0, v1, fs0 <2d,repeat,linear,nomip> 
        mov oc, ft0
    ]]>
    </frag>
</shader>

You can embed it like any other asset (as Flashpunk does with the default font already) and get the shader text from it when the engine starts up.


(Martí Angelats i Ribera) #3

The problem here is that you need to asseble it using an external class. I was thinking of already give it in machine code and add the AGAL code in a comment or another file (i don’t think anyone can read machine code).


(Jacob Albano) #4

As a matter of principle you shouldn’t be including machine code in an open source library. I’m surprised Adobe even allows precompiled shaders to be used, if that’s indeed possible.


(Martí Angelats i Ribera) #5

So i have to add the assembler class in the library? (I haven’t done this class and it have copyright)

The program is actually a ByteArray with little endian so you actually can save it as a Array and then write the ByteArray.


(Jacob Albano) #6

I assume you’re talking about this? That license doesn’t preclude its usage in Flashpunk. I wouldn’t be surprised if every class that’s built into as3 uses it.


(Martí Angelats i Ribera) #7

Oh so OK. I’ll simply use the AGALMiniAssembler.


(Ultima2876) #8

That’s what we did in Stage3DPunk :slight_smile: