Skip to content

Commit

Permalink
Use an explicit header size rather than an attribute offset
Browse files Browse the repository at this point in the history
The total size of the header fields (minus the attributes) are declared
up front at the start of the header. This will prevent future additions
to the header from having to introduce their own "attribute_offset"
field variations.

This also rearranges the padding so that all header fields are
strictly aligned according to their type, and the header field total
is a multiple of 16.

Fix #49
  • Loading branch information
io7m committed Jun 18, 2017
1 parent 1449fee commit a792f93
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 105 deletions.
12 changes: 12 additions & 0 deletions README-CHANGES.xml
Expand Up @@ -2,6 +2,18 @@
<c:changelog xmlns:c="http://schemas.io7m.com/changelog/2.0.0">
<c:project>com.io7m.smfj</c:project>

<c:release c:ticket-system="com.github.io7m.smf">
<c:date>2017-06-18</c:date>
<c:version>0.13.0</c:version>

<c:item>
<c:date>2017-06-18</c:date>
<c:type-code-change/>
<c:ticket>49</c:ticket>
<c:summary>Replace the attribute_offset field.</c:summary>
</c:item>
</c:release>

<c:release c:ticket-system="com.github.io7m.smf">
<c:date>2017-06-18</c:date>
<c:version>0.12.0</c:version>
Expand Down
Expand Up @@ -214,16 +214,8 @@ private static void skipAheadToAttributes(
{
final long position_now =
reader.position();
final long position_attribute_offset_start =
Math.addExact(
position_start,
(long) view.metaAttributeOffsetOffsetFromCursor());
final long position_attribute_offset_value =
(long) view.getAttributeOffset();
final long attribute_offset =
Math.addExact(
position_attribute_offset_start,
position_attribute_offset_value);
Math.addExact(position_start, (long) view.getFieldsSize());
final long seek =
Math.subtractExact(attribute_offset, position_now);

Expand Down
Expand Up @@ -138,7 +138,7 @@ public void serializeHeader(

final SMFTriangles triangles = in_header.triangles();
view.setAttributeCount(in_header.attributesInOrder().size());
view.setAttributeOffset(8);
view.setFieldsSize(buffer.length);
view.setTriangleCount(triangles.triangleCount());
view.setTriangleIndexSizeBits(triangles.triangleIndexSizeBits());
view.setVertexCount(in_header.vertexCount());
Expand Down
Expand Up @@ -26,13 +26,14 @@
[field meta_size [integer unsigned 32]])]

[record SMFBv1_0Header
([field schema SMFBv1SchemaID]
([field fields_size [integer unsigned 32]]
[field schema SMFBv1SchemaID]
[padding-octets 4]
[field vertex_count [integer unsigned 64]]
[field triangle_count [integer unsigned 64]]
[field triangle_index_size_bits [integer unsigned 32]]
[field attribute_count [integer unsigned 32]]
[field attribute_offset [integer unsigned 32]]
[field coordinate_system SMFBv1CoordinateSystems]
[padding-octets 2])]
[padding-octets 14])]

[package-end]
@@ -1,9 +1,10 @@
[record SMFBv1_0Header
([field schema SMFBv1SchemaID]
([field fields_size [integer unsigned 32]]
[field schema SMFBv1SchemaID]
[padding-octets 4]
[field vertex_count [integer unsigned 64]]
[field triangle_count [integer unsigned 64]]
[field triangle_index_size_bits [integer unsigned 32]]
[field attribute_count [integer unsigned 32]]
[field attribute_offset [integer unsigned 32]]
[field coordinate_system SMFBv1CoordinateSystems]
[padding-octets 2])]
[padding-octets 14])]
Expand Up @@ -28,6 +28,12 @@ The [term [type type] smf] section begins with the following structure:
[formal-item [title "SMF Header"] [id smfb.sections.smf.header.def]]
[verbatim [include "binary-smf-header.txt"]]

The [term [type field] fields_size] field specifies the total size of the
header fields, after which a list of attributes will be declared. The purpose
of this field is to allow for forward compatibility: Future updates to this
specification may add extra fields to the end of the header structure, and the
value of this field allows older implementations to skip those newer fields.

[paragraph]
The [term [type field] schema] field specifies the
[link [target smf_model.schema_id] schema identifier] for the model:
Expand All @@ -54,13 +60,7 @@ individual vertex indices within each triangle.

[paragraph]
The [term [type field] attribute_count] field specifies the number of
[link [target smf_model.attribute] attributes] that will be declared. The
[term [type field] attribute_offset] field specifies a relative offset in
octets, from the start of the [term [type field] attribute_offset] field,
at which a list of attributes will be declared. The purpose of this field
is to allow for forward compatibility: Future updates to this specification
may add extra fields to the end of the header structure, and the value of
this field allows older implementations to skip those newer fields.
[link [target smf_model.attribute] attributes] that will be declared.

[paragraph]
The [term [type field] coordinate_system] field specifies the
Expand Down

0 comments on commit a792f93

Please sign in to comment.