Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / VertexAttribute.cpp
1 #include "precompiled.h"
2 //
3 // Copyright 2014 The ANGLE Project Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
6 //
7 // Implementation of the state class for mananging GLES 3 Vertex Array Objects.
8 //
9
10 #include "libGLESv2/VertexAttribute.h"
11
12 namespace gl
13 {
14
15 VertexAttribute::VertexAttribute()
16     : enabled(false),
17       type(GL_FLOAT),
18       size(4),
19       normalized(false),
20       pureInteger(false),
21       stride(0),
22       pointer(NULL),
23       divisor(0)
24 {
25 }
26
27 size_t ComputeVertexAttributeTypeSize(const VertexAttribute& attrib)
28 {
29     GLuint size = attrib.size;
30     switch (attrib.type)
31     {
32       case GL_BYTE:                        return size * sizeof(GLbyte);
33       case GL_UNSIGNED_BYTE:               return size * sizeof(GLubyte);
34       case GL_SHORT:                       return size * sizeof(GLshort);
35       case GL_UNSIGNED_SHORT:              return size * sizeof(GLushort);
36       case GL_INT:                         return size * sizeof(GLint);
37       case GL_UNSIGNED_INT:                return size * sizeof(GLuint);
38       case GL_INT_2_10_10_10_REV:          return 4;
39       case GL_UNSIGNED_INT_2_10_10_10_REV: return 4;
40       case GL_FIXED:                       return size * sizeof(GLfixed);
41       case GL_HALF_FLOAT:                  return size * sizeof(GLhalf);
42       case GL_FLOAT:                       return size * sizeof(GLfloat);
43       default: UNREACHABLE();              return size * sizeof(GLfloat);
44     }
45 }
46
47 size_t ComputeVertexAttributeStride(const VertexAttribute& attrib)
48 {
49     if (!attrib.enabled)
50     {
51         return 16;
52     }
53     return attrib.stride ? attrib.stride : ComputeVertexAttributeTypeSize(attrib);
54 }
55
56 }