blob: e9757b618b41f02c38455b90b2b96649e86ebbed [file] [log] [blame]
Jamie Madill87939712013-07-02 11:57:01 -04001//
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 Madill57a89722013-07-02 11:57:03 -040012#include "libGLESv2/Buffer.h"
Jamie Madill87939712013-07-02 11:57:01 -040013
14namespace gl
15{
Jamie Madill87939712013-07-02 11:57:01 -040016
Brandon Jones5bf98292014-06-06 17:19:38 -070017struct VertexAttribute
Jamie Madill87939712013-07-02 11:57:01 -040018{
Brandon Jones5bf98292014-06-06 17:19:38 -070019 bool enabled; // From glEnable/DisableVertexAttribArray
Jamie Madill87939712013-07-02 11:57:01 -040020
Brandon Jones5bf98292014-06-06 17:19:38 -070021 GLenum type;
22 GLuint size;
23 bool normalized;
24 bool pureInteger;
25 GLuint stride; // 0 means natural stride
Jamie Madill87939712013-07-02 11:57:01 -040026
27 union
28 {
Brandon Jones5bf98292014-06-06 17:19:38 -070029 const GLvoid *pointer;
30 GLintptr offset;
Jamie Madill87939712013-07-02 11:57:01 -040031 };
Brandon Jones5bf98292014-06-06 17:19:38 -070032 BindingPointer<Buffer> buffer; // Captured when glVertexAttribPointer is called.
Jamie Madill87939712013-07-02 11:57:01 -040033
Brandon Jones5bf98292014-06-06 17:19:38 -070034 GLuint divisor;
35
36 VertexAttribute();
Jamie Madill87939712013-07-02 11:57:01 -040037};
38
Brandon Jones5bf98292014-06-06 17:19:38 -070039template <typename T>
40T 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
66size_t ComputeVertexAttributeTypeSize(const VertexAttribute& attrib);
67size_t ComputeVertexAttributeStride(const VertexAttribute& attrib);
68
Jamie Madilla857c362013-07-02 11:57:02 -040069struct 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 Lang89bf4bf2013-10-31 10:32:46 -0400105
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 Madilla857c362013-07-02 11:57:02 -0400115};
116
Jamie Madill87939712013-07-02 11:57:01 -0400117}
118
119#endif // LIBGLESV2_VERTEXATTRIBUTE_H_