AGALMiniAssembler
The MiniAssembler is tool that uses a simple assembly-like language to write and compile your shader into bytecode.
Can be created with method new:
Lib.Media.Display3D.Shaders.AGLSL.AGALMiniAssembler.new() |
create an AGALMiniAssembler. |
|
created assempler has method:
assemble(programType, shaderSource) |
Compile our AGAL Code into Bytecode using the MiniAssembler. Depending on programType result can be vertex or fragment Shader |
programType - Context3DProgramType object shaderSource - bytecode string |
Examples:
Display3D = Lib.Media.Display3D
stage = Lib.Media.Display.stage
stage3D = stage.stage3Ds[1]
stage3D.addEventListener(Lib.Media.Events.Event.CONTEXT3D_CREATE,
function(e)
print("Context 3D created")
context3D = stage3D.context3D
context3D.configureBackBuffer(stage.stageWidth, stage.stageHeight, 4, true)
context3D.enableErrorChecking = true
-- // // CREATE SHADER PROGRAM // //
-- When you call the createProgram method you are actually allocating some V-Ram space
-- for your shader program.
program = context3D.createProgram()
-- Create an AGALMiniAssembler.
local assembler = Display3D.Shaders.AGLSL.AGALMiniAssembler.new()
-- VERTEX SHADER
local code = "mov op, va0\n" -- Move the Vertex Attribute 0 (va0), which is our Vertex Coordinate, to the Output Point
code = code .. "mov v0, va1\n" -- Move the Vertex Attribute 1 (va1), which is our Vertex Color, to the variable register v0
-- Variable register are memory space shared between your Vertex Shader and your Fragment Shader
-- Compile our AGAL Code into ByteCode using the MiniAssembler
local vertexShader = assembler.assemble(Display3D.Context3DProgramType.VERTEX, code)
code = "mov oc, v0\n" -- Move the Variable register 0 (v0) where we copied our Vertex Color, to the output color
-- Compile our AGAL Code into Bytecode using the MiniAssembler
local fragmentShader = assembler.assemble(Display3D.Context3DProgramType.FRAGMENT, code)
program.upload(vertexShader, fragmentShader)
end, false, 0, false)
stage3D.requestContext3D("")
Created with the Personal Edition of HelpNDoc: Easily create EBooks