本文整理汇总了C++中Array::GetElements方法的典型用法代码示例。如果您正苦于以下问题:C++ Array::GetElements方法的具体用法?C++ Array::GetElements怎么用?C++ Array::GetElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Array
的用法示例。
在下文中一共展示了Array::GetElements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadMesh
bool Graphics::LoadMesh(Mesh * aMesh, GLuint & aVBO, GLuint & aIBO)
{
//TODO: Load the mesh data into OpenGL
if (aMesh == nullptr)
{
return false;
}
if (aMesh->IsUploaded())
{
Debug::Error("Graphics", "Cannot upload the mesh. It's already uploaded. Release the resources before attempting to upload.");
return false;
}
Array<Vector3> positions = aMesh->GetPositions();
Array<Vector3> normals = aMesh->GetNormals();
Array<Vector2> texCoords = aMesh->GetTexCoords();
Array<Color> colors = aMesh->GetColors();
Array<UInt16> indices = aMesh->GetIndicies();
UInt32 count = positions.GetCount();
if (count != normals.GetCount() ||
count != texCoords.GetCount() ||
count != colors.GetCount()
)
{
Debug::ErrorFormat("Graphics", nullptr, "There is a different number of attributes in this mesh %s", aMesh->GetName().c_str());
return false;
}
Array<VertexAttribute> attributes;
attributes.Allocate(count);
for (unsigned int i = 0; i < count; i++)
{
//Position
attributes[i].position[0] = positions[i].x;
attributes[i].position[1] = positions[i].y;
attributes[i].position[2] = positions[i].z;
//Normals
attributes[i].normal[0] = normals[i].x;
attributes[i].normal[1] = normals[i].y;
attributes[i].normal[2] = normals[i].z;
//Tex Coords
attributes[i].texCoord[0] = texCoords[i].x;
attributes[i].texCoord[1] = texCoords[i].y;
//Colors
attributes[i].color[0] = colors[i].r;
attributes[i].color[1] = colors[i].g;
attributes[i].color[2] = colors[i].b;
attributes[i].color[3] = colors[i].a;
}
//Send to OpenGL
glGenBuffers(1, &aVBO);
glBindBuffer((GLenum)BufferTarget::Array, aVBO);
glBufferData((GLenum)BufferTarget::Array, sizeof(VertexAttribute)* count, attributes.GetElements(), (GLenum)BufferMode::StaticDraw);
glBindBuffer((GLenum)BufferTarget::Array, 0);
glGenBuffers(1, &aIBO);
glBindBuffer((GLenum)BufferTarget::ElementArray, aIBO);
glBufferData((GLenum)BufferTarget::ElementArray, sizeof(GLshort)* indices.GetCount(), indices.GetElements(), (GLenum)BufferMode::StaticDraw);
glBindBuffer((GLenum)BufferTarget::ElementArray, 0);
return true;
}