GetVertexDataOffset

Returns offset of the required data in a vertex elements array with the specified format settings requiredData is one of the control vertex data bits (FORMAT_VERTEX...) or 0 to get count of all elements in vertex buffer Functions returns -1 if the required data are absent with the settings. Ensure your settings are actual. They may be differ you pass to SetFormat (for example because of mask) It's preferable to inquire resulting setting with GetFormat(model, GetFormat(0, 0)) Note: vertex buffer element is a double or a float number depending on FORMAT_SIZE_VERTEX_DOUBLE flag. If you need offset in bytes multiply by size of element. Compare to SetFormat that returns size of vertex data in bytes.

Syntax

//
//   Linux, MacOS and non-Visual Studio Windows solutions (pure C++11 / C++98)
//
int32_t     GetVertexDataOffset(
                    int64_t             requiredData,
                    int64_t             setting
                );


//
//   Visual Studio for Windows
//
__int32 __declspec(dllexport) __stdcall GetVertexDataOffset(
                                                __int64             requiredData,
                                                __int64             setting
                                            );
    

Property requiredData

Size: 64 bit / 8 byte (value)
The required data.

Property setting

Size: 64 bit / 8 byte (value)
The setting is the data that is defined for bitwise operations, only bits set in the mask will be relevant.

Example (based on pure API calls)

Here you can find code snippits that show how the API call GetVertexDataOffset can be used.

#include    "./include/engine.h"

static  const   uint64_t    flagbit0 = 1;                           // 2^^0                          0000.0000..0000.0001
static  const   uint64_t    flagbit1 = 2;                           // 2^^1                          0000.0000..0000.0010
static  const   uint64_t    flagbit2 = 4;                           // 2^^2                          0000.0000..0000.0100
static  const   uint64_t    flagbit3 = 8;                           // 2^^3                          0000.0000..0000.1000

static  const   uint64_t    flagbit4 = 16;                          // 2^^4                          0000.0000..0001.0000
static  const   uint64_t    flagbit5 = 32;                          // 2^^5                          0000.0000..0010.0000
static  const   uint64_t    flagbit6 = 64;                          // 2^^6                          0000.0000..0100.0000
static  const   uint64_t    flagbit7 = 128;                         // 2^^7                          0000.0000..1000.0000

static  const   uint64_t    flagbit8 = 256;                         // 2^^8                          0000.0001..0000.0000
static  const   uint64_t    flagbit9 = 512;                         // 2^^9                          0000.0010..0000.0000
static  const   uint64_t    flagbit10 = 1024;                       // 2^^10                         0000.0100..0000.0000
static  const   uint64_t    flagbit11 = 2048;                       // 2^^11                         0000.1000..0000.0000

static  const   uint64_t    flagbit12 = 4096;                       // 2^^12                         0001.0000..0000.0000
static  const   uint64_t    flagbit13 = 8192;                       // 2^^13                         0010.0000..0000.0000
static  const   uint64_t    flagbit14 = 16384;                      // 2^^14                         0100.0000..0000.0000
static  const   uint64_t    flagbit15 = 32768;                      // 2^^15                         1000.0000..0000.0000

static  const   uint64_t    flagbit16 = 65536;                      // 2^^16   0000.0000..0000.0001  0000.0000..0000.0000
static  const   uint64_t    flagbit17 = 131072;                     // 2^^17   0000.0000..0000.0010  0000.0000..0000.0000
static  const   uint64_t    flagbit18 = 262144;                     // 2^^18   0000.0000..0000.0100  0000.0000..0000.0000
static  const   uint64_t    flagbit19 = 524288;                     // 2^^19   0000.0000..0000.1000  0000.0000..0000.0000

static  const   uint64_t    flagbit20 = 1048576;                    // 2^^20   0000.0000..0001.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit21 = 2097152;                    // 2^^21   0000.0000..0010.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit22 = 4194304;                    // 2^^22   0000.0000..0100.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit23 = 8388608;                    // 2^^23   0000.0000..1000.0000  0000.0000..0000.0000

static  const   uint64_t    flagbit24 = 16777216;                   // 2^^24   0000.0001..0000.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit25 = 33554432;                   // 2^^25   0000.0010..0000.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit26 = 67108864;                   // 2^^26   0000.0100..0000.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit27 = 134217728;                  // 2^^27   0000.1000..0000.0000  0000.0000..0000.0000

static  const   uint64_t    flagbit28 = 268435456;                  // 2^^28   0001.0000..0000.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit29 = 536870912;                  // 2^^29   0010.0000..0000.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit30 = (uint64_t) 1073741824;      // 2^^30   0100.0000..0000.0000  0000.0000..0000.0000
static  const   uint64_t    flagbit31 = (uint64_t) 2147483648;      // 2^^31   1000.0000..0000.0000  0000.0000..0000.0000

...

int64_t model = CreateModel();

if (model) {
    {
        //
        //  Initializing the mask with all possible options
        //
        int64_t setting = 0,
                mask = GetFormat(0, 0);

        setting += 0 * flagbit2;        //    SINGLE / DOUBLE PRECISION (float / double)
        setting += 0 * flagbit3;        //    32 / 63 BIT INDEX ARRAY (int32_t / int64_t)

        setting += 1 * flagbit4;        //    OFF / ON VECTORS (x, y, z) 
        setting += 1 * flagbit5;        //    OFF / ON NORMALS (Nx, Ny, Nz)
        setting += 0 * flagbit6;        //    OFF / ON TEXTURE I (u1, v1)
        setting += 0 * flagbit7;        //    OFF / ON TEXTURE II (u2, v2)

        setting += 1 * flagbit8;        //    OFF / ON TRIANGLES
        setting += 1 * flagbit9;        //    OFF / ON LINES
        setting += 1 * flagbit10;       //    OFF / ON POINTS

        setting += 0 * flagbit12;       //    OFF / ON WIREFRAME FACES
        setting += 0 * flagbit13;       //    OFF / ON WIREFRAME CONCEPTUAL FACES

        setting += 0 * flagbit14;       //    OFF / ON STRUCTURE WIREFRAME AS POLYGON / TUPLE
        setting += 0 * flagbit15;       //    OFF / ON ADVANCED NORMALS (I.E. FOLLOWING THE SEMANTIC MEANING OF THE CONCEPT)

        setting += 0 * flagbit16;       //    OFF / ON DIRECTX (COMBINATION SETTING BIT 20, 21, 22, 23)
        setting += 0 * flagbit17;       //    OFF / ON OPENGL (COMBINATION SETTING BIT 20, 21, 22, 23)

        setting += 0 * flagbit18;       //    OFF / ON EXPORT BOTH SIDES OF TRIANGLES

        setting += 0 * flagbit20;       //    OFF / ON EXPERT SETTING TRIANGLE WINDING CW / ACW
        setting += 0 * flagbit21;       //    OFF / ON EXPERT SETTING NONE / VERTEX + NORMAL Y = Z / Z = -Y
        setting += 0 * flagbit22;       //    OFF / ON EXPERT SETTING
        setting += 0 * flagbit23;       //    OFF / ON EXPERT SETTING

        setting += 0 * flagbit24;       //    OFF / ON AMBIENT COLOR COMPONENT
        setting += 0 * flagbit25;       //    OFF / ON DIFFUSE COLOR COMPONENT
        setting += 0 * flagbit26;       //    OFF / ON EMISSIVE COLOR COMPONENT
        setting += 0 * flagbit27;       //    OFF / ON SPECULAR COLOR COMPONENT

        setting += 0 * flagbit28;       //    OFF / ON TEXTURE I TANGENT
        setting += 0 * flagbit29;       //    OFF / ON TEXTURE I BINORMAL

        setting += 0 * flagbit30;       //    OFF / ON TEXTURE II TANGENT (64 BIT ONLY)
        setting += 0 * flagbit31;       //    OFF / ON TEXTURE II BINORMAL (64 BIT ONLY)

        int64_t vertexElementSizeInBytes = SetFormat(model, setting, mask);

        ...

        int64_t vertexBufferSize = 0, indexBufferSize = 0;
        CalculateInstance(myInstance, &vertexBufferSize, &indexBufferSize, nullptr);

        if (vertexBufferSize && indexBufferSize) {
            assert(setting == GetFormat(model, GetFormat(0, 0));

            int32_t vertexSize = GetVertexDataOffset(0, setting);
            assert((int32_t) vertexElementSizeInBytes / sizeof(float) == vertexSize);

            float   * vertices = new float[(int_t) vertexBufferSize * vertexSize];
            int32_t * indices = new int32_t[(int_t) indexBufferSize];

            UpdateInstanceVertexBuffer(myInstance, vertices);
            UpdateInstanceIndexBuffer(myInstance, indices);

            int32_t offset = GetVertexDataOffset(FORMAT_VERTEX_TEXTURE_UV, settings);
            if (offset >= 0) {
                float   * uv = vertices[iVertex * vertexSize + offset];
                
                ...
            }

            ...
        }
    }
}