Exemplo n.º 1
0
bool VertexDeclaration::push_back(const VertexElement& element)
{
	if (has(element.usage())) return false;

	_usageMask = _usageMask | vertexAttributeUsageMask(element.usage());
	
	_totalSize += vertexAttributeTypeSize(element.type());
	_list.push_back(element);

	if (_interleaved)
	{
		for (auto& i : _list)
			i.setStride(static_cast<int>(_totalSize));
	}

	return true;
}
Exemplo n.º 2
0
bool
VertexElement::operator != (const VertexElement &src) const
{
    if (_usageIndex != src.usageIndex())
        return true;
    if (_usage != src.usage())
        return true;
    if (_method != src.method())
        return true;
    if (_type != src.type())
        return true;
    if (_offset != src.offset())
        return true;
    if (_stream != src.stream())
        return true;

    return false;
}
Exemplo n.º 3
0
void*
StreamedMesh::internalStreamPtr()
{    
    if (vertexBufferSize() == 0)
    {
        LOG ("Error, internal vertex buffer size is 0");
        return 0;
    }

    if (!_vertexBufferCpuMemory)
    {
        _vertexBufferCpuMemory = (float*)malloc(sizeof(float)*vertexBufferSize());
    }

    // stash the buffer and put it in an array
    std::map <uint32_t, float*> streamMap;

    for (auto it = _vertexStreams.begin();
        it != _vertexStreams.end();
        it++)
    {
        streamMap.insert (std::make_pair(it->first, it->second->stream()));
    }

    const std::vector <VertexElement>& declaration = _vertexDeclaration->getDeclaration();
    float* vb = (float*)_vertexBufferCpuMemory;

    for (uint32_t i = 0; i < vertexCount(); i++)
    {    
        for (uint32_t j = 0; j < declaration.size()-1; j++)
        {
            VertexElement element = declaration[j];
            VertexStream* stream = 0;
            if (findStream (stream, element))
            {
                uint32_t streamId = VertexStream::id(*stream);
                auto streamIt =  streamMap.find(streamId);

                if (streamIt != streamMap.end() &&
                    streamIt->second)
                {
                    for (uint32_t k = 0; k < stream->stride(); k++)
                    {
                        *vb++ = streamIt->second[k];
                    }
                    streamIt->second += stream->stride();
                }
                else
                {
                    uint32_t stride = IVertexDeclaration::elementToSize(element.type());
                    for (uint32_t k = 0; k < stride; stride++)
                    {
                        *vb++ = 0;
                    }
                }
            }
            else
            {
                // can't find a stream for this element.
                // warn user, and 0 the buffer for the stride size
                uint32_t stride = IVertexDeclaration::elementToSize(element.type());
                for (uint32_t k = 0; k < stride; stride++)
                {
                    *vb++ = 0;
                }
            }
        }
    }

    return _vertexBufferCpuMemory;
}