0

I'm trying to generate Unique ID's for a buffer unless they contain the same content. Inother words if the buffer has the same content as another, the ID should be the same; otherwise different.

I've found someone using this algorithm for the same kind of buffer:

DWORD CalcChecksum(DWORD *pData, int size)
{
    if(!pData) { return 0x0; }

    DWORD sum;
    DWORD tmp;
    sum = *pData;

    for(int i = 1; i < (size); i++)
    {
        tmp = pData[i];
        tmp = (DWORD)(sum >> 29) + tmp;
        tmp = (DWORD)(sum >> 17) + tmp;
        sum = (DWORD)(sum << 3)  ^ tmp;
    }

    return sum;
}

But I want to use:

uint32_t CRC32Value(int I)
{
    uint32_t Result = I;
    for (int J = 8; J > 0; J--)
    {
        if (Result & 1)
            Result = (Result >> 1) ^ 0xEDB88320;
        else
            Result >>= 1;
    }
    return Result;
}

uint32_t ModelCheckSum(DWORD* Data, size_t Size)
{
    uint32_t Result = 0;
    for (; Size != 0; Size--)
    {
        uint32_t Tmp = (Result >> 8) & 0x00FFFFFF;
        uint32_t Tmp2 = CRC32Value((static_cast<int>(Result) ^ *Data++) & 0xFF);
        Result = Tmp ^ Tmp2;
    }
    return Result;
}

And it gets used like:

void Detour_glBufferData(GLenum target, GLsizei size, const void* data, GLenum usage)
{
    bufferData[lastBuffer] = (void*) data;
    bufferSize[lastBuffer] = size;
    bufferCRC[lastBuffer] = CalcCheckSum((DWORD*)data, size); //Or ModelCheckSum

    original_glBufferDataARB(target, size, data, usage);
}

Which one should I use? Is mine overkill? Also what's wrong with my checksum :S? It crashes badly. I followed what Wikipedia said.

Edited by triumphost

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by triumphost
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.