186 lines
4.6 KiB
C++
186 lines
4.6 KiB
C++
|
/****************************************************************************
|
|||
|
Copyright (c) 2011-2013,WebJet Business Division,CYOU
|
|||
|
|
|||
|
http://www.genesis-3d.com.cn
|
|||
|
|
|||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|||
|
of this software and associated documentation files (the "Software"), to deal
|
|||
|
in the Software without restriction, including without limitation the rights
|
|||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||
|
copies of the Software, and to permit persons to whom the Software is
|
|||
|
furnished to do so, subject to the following conditions:
|
|||
|
|
|||
|
The above copyright notice and this permission notice shall be included in
|
|||
|
all copies or substantial portions of the Software.
|
|||
|
|
|||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
|
THE SOFTWARE.
|
|||
|
****************************************************************************/
|
|||
|
|
|||
|
#include "stdneb.h"
|
|||
|
#ifdef __OSX__
|
|||
|
#include "../rendersystem/base/BufferData.h"
|
|||
|
#include "memory/memory.h"
|
|||
|
#else
|
|||
|
#include "rendersystem/base/BufferData.h"
|
|||
|
#include "foundation/memory/memory.h"
|
|||
|
#endif
|
|||
|
namespace RenderBase
|
|||
|
{
|
|||
|
void _copyVertexData(const VertexStream& from, void* to, int vertexByteSize, int vertexCount)
|
|||
|
{
|
|||
|
|
|||
|
//С<><D0A1>λ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ȺŸ<C8BA>ֵ<EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD>ڴ濽<DAB4><E6BFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ܶ<EFBFBD><DCB6>ܶࡣ
|
|||
|
//<2F><>xmemcpy<70><79>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>߾<EFBFBD><DFBE><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD>ɵģ<C9B5><C4A3>ų<EFBFBD>С<EFBFBD><D0A1>120<32>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ڵĿ<DAB5><C4BF><EFBFBD><EFBFBD><EFBFBD>gcc<63><63><EFBFBD>ڴ濽<DAB4><E6BFBD><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD>
|
|||
|
//<2F>ȺŸ<C8BA>ֵ<EFBFBD><D6B5><EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD><=128<32>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD><C7BB><EFBFBD><EFBFBD>ֳ<EFBFBD><D6B3>ı<EFBFBD><C4B1><EFBFBD>
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>Ⱦϵͳ<CFB5>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>С<EFBFBD><D0A1>λ<EFBFBD><CEBB>4byte, <20><>һ<EFBFBD><D2BB>int32<33>Ĵ<EFBFBD>С
|
|||
|
n_assert(vertexByteSize > 0);
|
|||
|
n_assert(NULL != from.data);
|
|||
|
n_assert(NULL != to);
|
|||
|
n_assert((from.elemSizeInByte % 4) == 0);
|
|||
|
n_assert((vertexByteSize % 4) == 0);
|
|||
|
|
|||
|
int data_stride4 = from.elemSizeInByte / 4;
|
|||
|
int vertex_stride4 = vertexByteSize / 4;
|
|||
|
const uint32* buffer32 = (const uint32*)(from.data);
|
|||
|
uint32* dest = (uint32*)(((uint8*)to) + from.offsetInByte);
|
|||
|
|
|||
|
switch(data_stride4)
|
|||
|
{
|
|||
|
case 1:
|
|||
|
{
|
|||
|
while(vertexCount--)
|
|||
|
{
|
|||
|
#if __OSX__
|
|||
|
Memory::CopySmallOne((size_t*)buffer32, (size_t*)dest);
|
|||
|
#else
|
|||
|
Memory::CopySmallOne(buffer32, dest);
|
|||
|
#endif
|
|||
|
++buffer32;
|
|||
|
dest += vertex_stride4;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case 2:
|
|||
|
{
|
|||
|
while(vertexCount--)
|
|||
|
{
|
|||
|
#if __OSX__
|
|||
|
Memory::CopySmallTwo((size_t*)buffer32, (size_t*)dest);
|
|||
|
#else
|
|||
|
Memory::CopySmallTwo(buffer32, dest);
|
|||
|
#endif
|
|||
|
|
|||
|
buffer32 += 2;
|
|||
|
dest += vertex_stride4;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case 3:
|
|||
|
{
|
|||
|
while(vertexCount--)
|
|||
|
{
|
|||
|
#if __OSX__
|
|||
|
Memory::CopySmallThree((size_t*)buffer32, (size_t*)dest);
|
|||
|
#else
|
|||
|
Memory::CopySmallThree(buffer32, dest);
|
|||
|
#endif
|
|||
|
|
|||
|
buffer32 += 3;
|
|||
|
dest += vertex_stride4;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case 4:
|
|||
|
{
|
|||
|
while(vertexCount--)
|
|||
|
{
|
|||
|
#if __OSX__
|
|||
|
Memory::CopySmallFour((size_t*)buffer32, (size_t*)dest);
|
|||
|
#else
|
|||
|
Memory::CopySmallFour(buffer32, dest);
|
|||
|
#endif
|
|||
|
buffer32 += 4;
|
|||
|
dest += vertex_stride4;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case 5:
|
|||
|
{
|
|||
|
while(vertexCount--)
|
|||
|
{
|
|||
|
#if __OSX__
|
|||
|
Memory::CopySmallFive((size_t*)buffer32, (size_t*)dest);
|
|||
|
#else
|
|||
|
Memory::CopySmallFive(buffer32, dest);
|
|||
|
#endif
|
|||
|
|
|||
|
buffer32 += 5;
|
|||
|
dest += vertex_stride4;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case 6://VertexComponent::SkinJIndices<65><73>VertexComponent::SkinWeights<74>Ǻ<EFBFBD><C7BA><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
while(vertexCount--)
|
|||
|
{
|
|||
|
#if __OSX__
|
|||
|
Memory::CopySmallSix((size_t*)buffer32, (size_t*)dest);
|
|||
|
#else
|
|||
|
Memory::CopySmallSix(buffer32, dest);
|
|||
|
#endif
|
|||
|
|
|||
|
buffer32 += 6;
|
|||
|
dest += vertex_stride4;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
default:
|
|||
|
n_error("error vertex data size");//ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>Ǽ<EFBFBD><C7BC>ִ<EFBFBD>С
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void DirectCopyVertexDataToGraphicBuffer(const VertexBufferData& source, void* to, int vertexByteSize)
|
|||
|
{
|
|||
|
const VertexStreams& dataStreams = source.vertex.vertexComponentStreams;
|
|||
|
if (source.vertex.vertexComponentStreams.Size() == 1
|
|||
|
&& source.vertex.vertexComponentStreams[0].elemSizeInByte == vertexByteSize
|
|||
|
&& source.vertex.vertexComponentStreams[0].data)
|
|||
|
{
|
|||
|
Memory::Copy(dataStreams[0].data,to, vertexByteSize * source.vertexCount);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
for (int i = 0; i < dataStreams.Size(); ++i)
|
|||
|
{
|
|||
|
VertexStream stream = dataStreams[i];
|
|||
|
if (stream.data)
|
|||
|
{
|
|||
|
_copyVertexData(stream, to, vertexByteSize, source.vertexCount);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
int IndexBufferData::SizeOf(IndexType type)
|
|||
|
{
|
|||
|
switch(type)
|
|||
|
{
|
|||
|
case Int16:
|
|||
|
return 2;
|
|||
|
case Int32:
|
|||
|
return 4;
|
|||
|
default:
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|