Element HAL sturct, script side getters
Change-Id: If98dd4c22bce58dca2c9739c8aee935a2dd0b493
diff --git a/rsElement.cpp b/rsElement.cpp
index 56c31b6..8b60701 100644
--- a/rsElement.cpp
+++ b/rsElement.cpp
@@ -47,6 +47,12 @@
mFields = NULL;
mFieldCount = 0;
mHasReference = false;
+
+ delete [] mHal.state.fields;
+ delete [] mHal.state.fieldArraySizes;
+ delete [] mHal.state.fieldNames;
+ delete [] mHal.state.fieldNameLengths;
+ delete [] mHal.state.fieldOffsetBytes;
}
size_t Element::getSizeBits() const {
@@ -157,13 +163,26 @@
}
void Element::compute() {
+ mHal.state.dataType = mComponent.getType();
+ mHal.state.dataKind = mComponent.getKind();
+ mHal.state.vectorSize = mComponent.getVectorSize();
+
if (mFieldCount == 0) {
mBits = mComponent.getBits();
mBitsUnpadded = mComponent.getBitsUnpadded();
mHasReference = mComponent.isReference();
+
+ mHal.state.elementSizeBytes = getSizeBytes();
return;
}
+ mHal.state.fields = new const Element*[mFieldCount];
+ mHal.state.fieldArraySizes = new uint32_t[mFieldCount];
+ mHal.state.fieldNames = new const char*[mFieldCount];
+ mHal.state.fieldNameLengths = new uint32_t[mFieldCount];
+ mHal.state.fieldOffsetBytes = new uint32_t[mFieldCount];
+ mHal.state.fieldsCount = mFieldCount;
+
size_t bits = 0;
size_t bitsUnpadded = 0;
for (size_t ct=0; ct < mFieldCount; ct++) {
@@ -175,8 +194,15 @@
if (mFields[ct].e->mHasReference) {
mHasReference = true;
}
+
+ mHal.state.fields[ct] = mFields[ct].e.get();
+ mHal.state.fieldArraySizes[ct] = mFields[ct].arraySize;
+ mHal.state.fieldNames[ct] = mFields[ct].name.string();
+ mHal.state.fieldNameLengths[ct] = mFields[ct].name.length();
+ mHal.state.fieldOffsetBytes[ct] = mFields[ct].offsetBits >> 3;
}
+ mHal.state.elementSizeBytes = getSizeBytes();
}
ObjectBaseRef<const Element> Element::createRef(Context *rsc, RsDataType dt, RsDataKind dk,
diff --git a/rsElement.h b/rsElement.h
index 04010fa..010c612 100644
--- a/rsElement.h
+++ b/rsElement.h
@@ -28,6 +28,27 @@
// An element is a group of Components that occupies one cell in a structure.
class Element : public ObjectBase {
public:
+ struct Hal {
+ mutable void *drv;
+
+ struct State {
+ RsDataType dataType;
+ RsDataKind dataKind;
+ uint32_t vectorSize;
+ uint32_t elementSizeBytes;
+
+ // Subelements
+ const Element **fields;
+ uint32_t *fieldArraySizes;
+ const char **fieldNames;
+ uint32_t *fieldNameLengths;
+ uint32_t *fieldOffsetBytes;
+ uint32_t fieldsCount;
+ };
+ State state;
+ };
+ Hal mHal;
+
class Builder {
public:
Builder();
diff --git a/rsMesh.h b/rsMesh.h
index 0fc73fb..84a57ca 100644
--- a/rsMesh.h
+++ b/rsMesh.h
@@ -28,15 +28,6 @@
// An element is a group of Components that occupies one cell in a structure.
class Mesh : public ObjectBase {
public:
- Mesh(Context *);
- Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
- ~Mesh();
-
- virtual void serialize(OStream *stream) const;
- virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
- static Mesh *createFromStream(Context *rsc, IStream *stream);
- void init();
-
struct Hal {
mutable void *drv;
@@ -57,6 +48,15 @@
};
Hal mHal;
+ Mesh(Context *);
+ Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
+ ~Mesh();
+
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
+ static Mesh *createFromStream(Context *rsc, IStream *stream);
+ void init();
+
void setVertexBuffer(Allocation *vb, uint32_t index) {
mVertexBuffers[index].set(vb);
mHal.state.vertexBuffers[index] = vb;
diff --git a/scriptc/rs_allocation.rsh b/scriptc/rs_allocation.rsh
index 1cb3a99..4d62bfb 100644
--- a/scriptc/rs_allocation.rsh
+++ b/scriptc/rs_allocation.rsh
@@ -168,5 +168,29 @@
extern const void * __attribute__((overloadable))
rsGetElementAt(rs_allocation, uint32_t x, uint32_t y, uint32_t z);
+extern const rs_element __attribute__((overloadable))
+ rsAllocationGetElement(rs_allocation);
+
+extern const uint32_t __attribute__((overloadable))
+ rsMeshGetVertexAllocationCount(rs_mesh);
+
+extern const uint32_t __attribute__((overloadable))
+ rsMeshGetPrimitiveCount(rs_mesh);
+
+extern const uint32_t __attribute__((overloadable))
+ rsMeshGetVertexAllocationCount(rs_mesh);
+
+extern const rs_allocation __attribute__((overloadable))
+ rsMeshGetVertexAllocation(rs_mesh, uint32_t index);
+
+extern const uint32_t __attribute__((overloadable))
+ rsMeshGetPrimitiveCount(rs_mesh);
+
+extern const rs_allocation __attribute__((overloadable))
+ rsMeshGetIndexAllocation(rs_mesh, uint32_t index);
+
+extern const rs_primitive __attribute__((overloadable))
+ rsMeshGetPrimitive(rs_mesh, uint32_t index);
+
#endif
diff --git a/scriptc/rs_types.rsh b/scriptc/rs_types.rsh
index a01807e..5c468bf 100644
--- a/scriptc/rs_types.rsh
+++ b/scriptc/rs_types.rsh
@@ -400,6 +400,15 @@
RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010
} rs_allocation_usage_type;
+typedef enum {
+ RS_PRIMITIVE_POINT,
+ RS_PRIMITIVE_LINE,
+ RS_PRIMITIVE_LINE_STRIP,
+ RS_PRIMITIVE_TRIANGLE,
+ RS_PRIMITIVE_TRIANGLE_STRIP,
+ RS_PRIMITIVE_TRIANGLE_FAN
+} rs_primitive;
+
#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
#endif