示例#1
0
bool D3DCodePath::loadGeometryShader(DataStream& stream)
{
    if ( stream.getDataSize() > 0 )
    {
        HRESULT hr = mDevice.getDevice().CreateGeometryShader(stream.getData(), stream.getDataSize(), NULL, &mpGeometryShader);
        if ( FAILED(hr) )
        {
            return false;
        }
    }
    return true;
}
示例#2
0
bool D3DCodePath::loadVertexShader(DataStream& stream)
{
    HRESULT hr = mDevice.getDevice().CreateVertexShader(stream.getData(), stream.getDataSize(), NULL, &mpVertexShader);
    if ( FAILED(hr) )
    {
        return false;
    }

    if ( !createInputLayout(stream) )
    {
        return false;
    }

    return true;
}
示例#3
0
bool D3DCodePath::createInputLayout(const DataStream& stream)
{
    const VertexLayout& layout = getVertexLayout();

    D3D11_INPUT_ELEMENT_DESC* pdescs = new D3D11_INPUT_ELEMENT_DESC[layout.getSize()];
    for ( int index = 0; index < layout.getSize(); ++index )
    {
        const VertexLayoutElement& element = layout[index];
        D3D11_INPUT_ELEMENT_DESC& desc = pdescs[index];

        memset(&desc, 0, sizeof(D3D11_INPUT_ELEMENT_DESC));
        desc.SemanticName = _strdup(element.semantic.toUtf8().c_str());
        switch ( element.size )
        {
        case 1:
            desc.Format = DXGI_FORMAT_R32_FLOAT;
            break;
        case 2:
            desc.Format = DXGI_FORMAT_R32G32_FLOAT;
            break;
        case 3:
            desc.Format = DXGI_FORMAT_R32G32B32_FLOAT;
            break;
        case 4:
            desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
            break;
        default:
            return false;
        }

        desc.AlignedByteOffset = element.pos;
        desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
    }

    HRESULT hr = mDevice.getDevice().CreateInputLayout(pdescs, layout.getSize(), stream.getData(), stream.getDataSize(), &mpInputLayout);

    for ( int index = 0; index < layout.getSize(); ++index )
    {
        D3D11_INPUT_ELEMENT_DESC& desc = pdescs[index];
        delete[] desc.SemanticName;
    }
    delete[] pdescs;

    if ( FAILED(hr) )
    {
        return false;
    }

    return true;
}
示例#4
0
void DataStream::write(const DataStream& that)
{
   writeInt(that.getDataSize());
   writeBytes(that.getData(), that.getDataSize());
}