Optimize copyVertexData.

TRAC #2237 Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1700 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 3c17ba65
...@@ -221,26 +221,28 @@ ID3D11Buffer *VertexBuffer11::getBuffer() const ...@@ -221,26 +221,28 @@ ID3D11Buffer *VertexBuffer11::getBuffer() const
} }
template <typename T, unsigned int componentCount, bool widen, bool normalized> template <typename T, unsigned int componentCount, bool widen, bool normalized>
static void copyVertexData(const void* input, unsigned int stride, unsigned int count, void* output) static void copyVertexData(const void *input, unsigned int stride, unsigned int count, void *output)
{ {
unsigned int typeSize = sizeof(T); unsigned int attribSize = sizeof(T) * componentCount;
unsigned int vertexSize = typeSize * componentCount;
unsigned int outputStride = widen ? 4 : componentCount; if (attribSize == stride && !widen)
T defaultVal = normalized ? std::numeric_limits<T>::max() : T(1);
if (vertexSize == stride && !widen)
{ {
memcpy(output, input, count * vertexSize); memcpy(output, input, count * attribSize);
} }
else else
{ {
unsigned int outputStride = widen ? 4 : componentCount;
T defaultVal = normalized ? std::numeric_limits<T>::max() : T(1);
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
const T* offsetInput = reinterpret_cast<const T*>(reinterpret_cast<const char*>(input) + stride * i); const T *offsetInput = reinterpret_cast<const T*>(reinterpret_cast<const char*>(input) + i * stride);
T* offsetOutput = reinterpret_cast<T*>(output) + i * outputStride; T *offsetOutput = reinterpret_cast<T*>(output) + i * outputStride;
memcpy(offsetOutput, offsetInput, vertexSize); for (unsigned int j = 0; j < componentCount; j++)
{
offsetOutput[j] = offsetInput[j];
}
if (widen) if (widen)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment