When using Context3DVertexBufferFormat.BYTES_4, what is the value range of one field?

413 views Asked by At

If I populate a vertex-buffer by using the byte-array method:

//Example:
var ba:ByteArray = new ByteArray();

//Write vertex #0:
ba.writeFloat(-.5);
ba.writeFloat(-.5);
ba.writeUnsignedInt(0);
ba.writeUnsignedInt(0);

//Write vertex #1:
ba.writeFloat(.5);
ba.writeFloat(-.5);
ba.writeUnsignedInt(1);
ba.writeUnsignedInt(0);

//Write vertex #2:
ba.writeFloat(.5);
ba.writeFloat(.5);
ba.writeUnsignedInt(1);
ba.writeUnsignedInt(1);

//Write vertex #3:
ba.writeFloat(-.5);
ba.writeFloat(.5);
ba.writeUnsignedInt(0);
ba.writeUnsignedInt(1);

myVertexBuffer.uploadFromByteArray(ba, 0, 0, 4);

And then set the vertex-buffer attribute with the following format:

var format:String = Context3DVertexBufferFormat.BYTES_4;
context3D.setVertexBufferAt(0, myVertexBuffer, 0, format);

What is the range of values possible (0 to 255? 0.0 to 1.0? etc.) for the Vertex attribute's field (in this case, va0.x, va0.y, va0.z, va0.w)? Does it vary between which data-type is written to the ByteArray object (writeFloat vs. writeUnsignedInt)?

1

There are 1 answers

0
starmole On BEST ANSWER

BYTES_4 is unpacked as 4 bytes in the [0..1] range. So bytes 0xff, 0x7f, 0, 1 would become 1.0, .5, 0, 1/255 in the vertex program. In you case the WriteUnsignedInt would only populate x with the 1. You should use WriteByte 4 times instead, or even better pack your 4 values into one unsigned int, like a color.