15a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#include "rs_core.rsh"
25a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#include "rs_structs.h"
35a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
45a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/**
55a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines* Element
65a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines*/
75a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable))
85a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetSubElementCount(rs_element e) {
95a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL) {
115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return 0;
125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return element->mHal.state.fieldsCount;
145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern rs_element __attribute__((overloadable))
175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetSubElement(rs_element e, uint32_t index) {
185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL || index >= element->mHal.state.fieldsCount) {
205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rs_element nullElem = {0};
215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return nullElem;
225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    rs_element returnElem = {element->mHal.state.fields[index]};
245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return returnElem;
255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable))
285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetSubElementNameLength(rs_element e, uint32_t index) {
295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL || index >= element->mHal.state.fieldsCount) {
315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return 0;
325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return element->mHal.state.fieldNameLengths[index];
345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable))
375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetSubElementName(rs_element e, uint32_t index, char *name, uint32_t nameLength) {
385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL || index >= element->mHal.state.fieldsCount ||
405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        nameLength == 0 || name == 0) {
415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return 0;
425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    uint32_t numToCopy = element->mHal.state.fieldNameLengths[index];
455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (nameLength < numToCopy) {
465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        numToCopy = nameLength;
475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    // Place the null terminator manually, in case of partial string
495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    numToCopy --;
505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    name[numToCopy] = '\0';
515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    const char *nameSource = element->mHal.state.fieldNames[index];
525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    for (uint32_t i = 0; i < numToCopy; i ++) {
535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        name[i] = nameSource[i];
545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return numToCopy;
565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable))
595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetSubElementArraySize(rs_element e, uint32_t index) {
605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL || index >= element->mHal.state.fieldsCount) {
625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return 0;
635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return element->mHal.state.fieldArraySizes[index];
655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable))
685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetSubElementOffsetBytes(rs_element e, uint32_t index) {
695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL || index >= element->mHal.state.fieldsCount) {
715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return 0;
725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return element->mHal.state.fieldOffsetBytes[index];
745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable))
775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetBytesSize(rs_element e) {
785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL) {
805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return 0;
815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return element->mHal.state.elementSizeBytes;
835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern rs_data_type __attribute__((overloadable))
865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetDataType(rs_element e) {
875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL) {
895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return RS_TYPE_INVALID;
905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return element->mHal.state.dataType;
925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern rs_data_kind __attribute__((overloadable))
955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetDataKind(rs_element e) {
965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL) {
985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return RS_KIND_INVALID;
995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
1005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return element->mHal.state.dataKind;
1015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
1025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable))
1045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        rsElementGetVectorSize(rs_element e) {
1055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    Element_t *element = (Element_t *)e.p;
1065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    if (element == NULL) {
1075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines        return 0;
1085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    }
1095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return element->mHal.state.vectorSize;
1105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
111