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 structures about Generic Vertex Attribute.
7 //
8 
9 #ifndef LIBANGLE_VERTEXATTRIBUTE_H_
10 #define LIBANGLE_VERTEXATTRIBUTE_H_
11 
12 #include "libANGLE/Buffer.h"
13 
14 namespace gl
15 {
16 class VertexArray;
17 
18 //
19 // Implementation of Generic Vertex Attribute Bindings for ES3.1. The members are intentionally made
20 // private in order to hide implementation details.
21 //
22 class VertexBinding final : angle::NonCopyable
23 {
24   public:
25     VertexBinding();
26     VertexBinding(VertexBinding &&binding);
27     ~VertexBinding();
28     VertexBinding &operator=(VertexBinding &&binding);
29 
getStride()30     GLuint getStride() const { return mStride; }
setStride(GLuint strideIn)31     void setStride(GLuint strideIn) { mStride = strideIn; }
32 
getDivisor()33     GLuint getDivisor() const { return mDivisor; }
setDivisor(GLuint divisorIn)34     void setDivisor(GLuint divisorIn) { mDivisor = divisorIn; }
35 
getOffset()36     GLintptr getOffset() const { return mOffset; }
setOffset(GLintptr offsetIn)37     void setOffset(GLintptr offsetIn) { mOffset = offsetIn; }
38 
getBuffer()39     const BindingPointer<Buffer> &getBuffer() const { return mBuffer; }
setBuffer(const gl::Context * context,Buffer * bufferIn)40     void setBuffer(const gl::Context *context, Buffer *bufferIn) { mBuffer.set(context, bufferIn); }
41 
42   private:
43     GLuint mStride;
44     GLuint mDivisor;
45     GLintptr mOffset;
46 
47     BindingPointer<Buffer> mBuffer;
48 };
49 
50 //
51 // Implementation of Generic Vertex Attributes for ES3.1
52 //
53 struct VertexAttribute final : private angle::NonCopyable
54 {
55     explicit VertexAttribute(GLuint bindingIndex);
56     explicit VertexAttribute(VertexAttribute &&attrib);
57     VertexAttribute &operator=(VertexAttribute &&attrib);
58 
59     bool enabled;  // For glEnable/DisableVertexAttribArray
60     GLenum type;
61     GLuint size;
62     bool normalized;
63     bool pureInteger;
64 
65     const void *pointer;
66     GLuint relativeOffset;
67 
68     GLuint vertexAttribArrayStride;  // ONLY for queries of VERTEX_ATTRIB_ARRAY_STRIDE
69     GLuint bindingIndex;
70 };
71 
72 size_t ComputeVertexAttributeTypeSize(const VertexAttribute &attrib);
73 
74 // Warning: you should ensure binding really matches attrib.bindingIndex before using this function.
75 size_t ComputeVertexAttributeStride(const VertexAttribute &attrib, const VertexBinding &binding);
76 
77 // Warning: you should ensure binding really matches attrib.bindingIndex before using this function.
78 GLintptr ComputeVertexAttributeOffset(const VertexAttribute &attrib, const VertexBinding &binding);
79 
80 size_t ComputeVertexBindingElementCount(GLuint divisor, size_t drawCount, size_t instanceCount);
81 
82 GLenum GetVertexAttributeBaseType(const VertexAttribute &attrib);
83 
84 struct VertexAttribCurrentValueData
85 {
86     union {
87         GLfloat FloatValues[4];
88         GLint IntValues[4];
89         GLuint UnsignedIntValues[4];
90     };
91     GLenum Type;
92 
93     VertexAttribCurrentValueData();
94 
95     void setFloatValues(const GLfloat floatValues[4]);
96     void setIntValues(const GLint intValues[4]);
97     void setUnsignedIntValues(const GLuint unsignedIntValues[4]);
98 };
99 
100 bool operator==(const VertexAttribCurrentValueData &a, const VertexAttribCurrentValueData &b);
101 bool operator!=(const VertexAttribCurrentValueData &a, const VertexAttribCurrentValueData &b);
102 
103 }  // namespace gl
104 
105 #include "VertexAttribute.inl"
106 
107 #endif  // LIBANGLE_VERTEXATTRIBUTE_H_
108