예제 #1
0
void Vertex::SetAttribute(string name, void* pvalue, const VertexFormat &vf)
{
    int offset = vf.GetOffsetOf(name);
    if(offset == -1) return;
    int type = vf.GetAttribute(name).GetComponentsType();
    void *pdata  = GetAttributePointer(name, vf);
    for(int i = 0; i < vf.GetAttribute(name).GetComponentsCount(); ++i)
    {
        if(type == GL_DOUBLE)      *((double*)pdata + i)        = *((double*)pvalue + i);
        else if(type == GL_FLOAT)  *((float*)pdata + i)         = *((float*)pvalue + i);
        else if(type == GL_INT)    *((int*)pdata + i)           = *((int*)pvalue + i);
        else if(type == GL_SHORT)  *((short*)pdata + i)         = *((short*)pvalue + i);
        else if(type == GL_BYTE)   *((unsigned char*)pdata + i) = *((unsigned char*)pvalue + i);
    }
}
예제 #2
0
void SkinController::OnFirstUpdate()
{
    // Get access to the vertex buffer positions to store the blended targets.
    Visual* visual = reinterpret_cast<Visual*>(mObject);
    VertexBuffer* vbuffer = visual->GetVertexBuffer().get();
    if (mNumVertices == static_cast<int>(vbuffer->GetNumElements()))
    {
        // Get the position data.
        VertexFormat vformat = vbuffer->GetFormat();
        int const numAttributes = vformat.GetNumAttributes();
        for (int i = 0; i < numAttributes; ++i)
        {
            VASemantic semantic;
            DFType type;
            unsigned int unit, offset;
            if (vformat.GetAttribute(i, semantic, type, unit, offset))
            {
                if (semantic == VA_POSITION && (type == DF_R32G32B32_FLOAT 
                    || type == DF_R32G32B32A32_FLOAT))
                {
                    mPosition = vbuffer->GetData() + offset;
                    mStride = vformat.GetVertexSize();
                    mCanUpdate = true;
                    break;
                }
            }
        }
    }

    mCanUpdate = (mPosition != nullptr);
}