Mesh.cpp revision 3f84483382be2d528918cc1a6fbc6a7d68e0b181
1/*
2 * Copyright 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Mesh.h"
18
19namespace android {
20
21Mesh::Mesh(Primitive primitive, size_t vertexCount, size_t vertexSize, size_t texCoordSize)
22    : mVertexCount(vertexCount), mVertexSize(vertexSize), mTexCoordsSize(texCoordSize),
23      mPrimitive(primitive)
24{
25    mVertices = new float[(vertexSize + texCoordSize) * vertexCount];
26    mStride = mVertexSize + mTexCoordsSize;
27}
28
29Mesh::~Mesh() {
30    delete [] mVertices;
31}
32
33float const* Mesh::operator[](size_t index) const {
34    return &mVertices[index * mStride];
35}
36
37float* Mesh::operator[](size_t index) {
38    return &mVertices[index * mStride];
39}
40
41Mesh::Primitive Mesh::getPrimitive() const {
42    return mPrimitive;
43}
44
45
46float const* Mesh::getVertices() const {
47    return mVertices;
48}
49float* Mesh::getVertices() {
50    return mVertices;
51}
52
53float const* Mesh::getTexCoords() const {
54    return mVertices + mVertexSize;
55}
56float* Mesh::getTexCoords() {
57    return mVertices + mVertexSize;
58}
59
60
61size_t Mesh::getVertexCount() const {
62    return mVertexCount;
63}
64
65size_t Mesh::getVertexSize() const {
66    return mVertexSize;
67}
68
69size_t Mesh::getTexCoordsSize() const {
70    return mTexCoordsSize;
71}
72
73size_t Mesh::getByteStride() const {
74    return mStride*sizeof(float);
75}
76
77size_t Mesh::getStride() const {
78    return mStride;
79}
80
81} /* namespace android */
82