Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // Helper structure describing a single vertex attribute |
| 7 | // |
| 8 | |
| 9 | #ifndef LIBGLESV2_VERTEXATTRIBUTE_H_ |
| 10 | #define LIBGLESV2_VERTEXATTRIBUTE_H_ |
| 11 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 12 | #include "libGLESv2/Buffer.h" |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 13 | |
| 14 | namespace gl |
| 15 | { |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 16 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame^] | 17 | struct VertexAttribute |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 18 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame^] | 19 | bool enabled; // From glEnable/DisableVertexAttribArray |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 20 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame^] | 21 | GLenum type; |
| 22 | GLuint size; |
| 23 | bool normalized; |
| 24 | bool pureInteger; |
| 25 | GLuint stride; // 0 means natural stride |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 26 | |
| 27 | union |
| 28 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame^] | 29 | const GLvoid *pointer; |
| 30 | GLintptr offset; |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 31 | }; |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame^] | 32 | BindingPointer<Buffer> buffer; // Captured when glVertexAttribPointer is called. |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 33 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame^] | 34 | GLuint divisor; |
| 35 | |
| 36 | VertexAttribute(); |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 37 | }; |
| 38 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame^] | 39 | template <typename T> |
| 40 | T QuerySingleVertexAttributeParameter(const VertexAttribute& attrib, GLenum pname) |
| 41 | { |
| 42 | switch (pname) |
| 43 | { |
| 44 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 45 | return static_cast<T>(attrib.enabled ? GL_TRUE : GL_FALSE); |
| 46 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 47 | return static_cast<T>(attrib.size); |
| 48 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 49 | return static_cast<T>(attrib.stride); |
| 50 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 51 | return static_cast<T>(attrib.type); |
| 52 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 53 | return static_cast<T>(attrib.normalized ? GL_TRUE : GL_FALSE); |
| 54 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 55 | return static_cast<T>(attrib.buffer.id()); |
| 56 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 57 | return static_cast<T>(attrib.divisor); |
| 58 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 59 | return static_cast<T>(attrib.pureInteger ? GL_TRUE : GL_FALSE); |
| 60 | default: |
| 61 | UNREACHABLE(); |
| 62 | return static_cast<T>(0); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | size_t ComputeVertexAttributeTypeSize(const VertexAttribute& attrib); |
| 67 | size_t ComputeVertexAttributeStride(const VertexAttribute& attrib); |
| 68 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 69 | struct VertexAttribCurrentValueData |
| 70 | { |
| 71 | union |
| 72 | { |
| 73 | GLfloat FloatValues[4]; |
| 74 | GLint IntValues[4]; |
| 75 | GLuint UnsignedIntValues[4]; |
| 76 | }; |
| 77 | GLenum Type; |
| 78 | |
| 79 | void setFloatValues(const GLfloat floatValues[4]) |
| 80 | { |
| 81 | for (unsigned int valueIndex = 0; valueIndex < 4; valueIndex++) |
| 82 | { |
| 83 | FloatValues[valueIndex] = floatValues[valueIndex]; |
| 84 | } |
| 85 | Type = GL_FLOAT; |
| 86 | } |
| 87 | |
| 88 | void setIntValues(const GLint intValues[4]) |
| 89 | { |
| 90 | for (unsigned int valueIndex = 0; valueIndex < 4; valueIndex++) |
| 91 | { |
| 92 | IntValues[valueIndex] = intValues[valueIndex]; |
| 93 | } |
| 94 | Type = GL_INT; |
| 95 | } |
| 96 | |
| 97 | void setUnsignedIntValues(const GLuint unsignedIntValues[4]) |
| 98 | { |
| 99 | for (unsigned int valueIndex = 0; valueIndex < 4; valueIndex++) |
| 100 | { |
| 101 | UnsignedIntValues[valueIndex] = unsignedIntValues[valueIndex]; |
| 102 | } |
| 103 | Type = GL_UNSIGNED_INT; |
| 104 | } |
Geoff Lang | 89bf4bf | 2013-10-31 10:32:46 -0400 | [diff] [blame] | 105 | |
| 106 | bool operator==(const VertexAttribCurrentValueData &other) |
| 107 | { |
| 108 | return (Type == other.Type && memcmp(FloatValues, other.FloatValues, sizeof(float) * 4) == 0); |
| 109 | } |
| 110 | |
| 111 | bool operator!=(const VertexAttribCurrentValueData &other) |
| 112 | { |
| 113 | return !(*this == other); |
| 114 | } |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 115 | }; |
| 116 | |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | #endif // LIBGLESV2_VERTEXATTRIBUTE_H_ |