Hash :
30855b37
Author :
Date :
2013-07-02T11:57:06
Support querying if a vertex attribute is an un-normalized integer. TRAC #23391 Signed-off-by: Shannon Woods Signed-off-by: Geoff Lang Authored-by: Jamie Madill
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
//
// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Helper structure describing a single vertex attribute
//
#ifndef LIBGLESV2_VERTEXATTRIBUTE_H_
#define LIBGLESV2_VERTEXATTRIBUTE_H_
#include "libGLESv2/Buffer.h"
namespace gl
{
class VertexAttribute
{
public:
VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mPureInteger(false),
mStride(0), mPointer(NULL), mArrayEnabled(false), mDivisor(0)
{
}
int typeSize() const
{
switch (mType)
{
case GL_BYTE: return mSize * sizeof(GLbyte);
case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte);
case GL_SHORT: return mSize * sizeof(GLshort);
case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
case GL_INT: return mSize * sizeof(GLint);
case GL_UNSIGNED_INT: return mSize * sizeof(GLuint);
case GL_INT_2_10_10_10_REV: return 4;
case GL_UNSIGNED_INT_2_10_10_10_REV: return 4;
case GL_FIXED: return mSize * sizeof(GLfixed);
case GL_HALF_FLOAT: return mSize * sizeof(GLhalf);
case GL_FLOAT: return mSize * sizeof(GLfloat);
default: UNREACHABLE(); return mSize * sizeof(GLfloat);
}
}
GLsizei stride() const
{
return mStride ? mStride : typeSize();
}
void setState(gl::Buffer *boundBuffer, GLint size, GLenum type, bool normalized,
bool pureInteger, GLsizei stride, const void *pointer)
{
mBoundBuffer.set(boundBuffer);
mSize = size;
mType = type;
mNormalized = normalized;
mPureInteger = pureInteger;
mStride = stride;
mPointer = pointer;
}
template <typename T>
T querySingleParameter(GLenum pname) const
{
switch (pname)
{
case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
return static_cast<T>(mArrayEnabled ? GL_TRUE : GL_FALSE);
case GL_VERTEX_ATTRIB_ARRAY_SIZE:
return static_cast<T>(mSize);
case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
return static_cast<T>(mStride);
case GL_VERTEX_ATTRIB_ARRAY_TYPE:
return static_cast<T>(mType);
case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
return static_cast<T>(mNormalized ? GL_TRUE : GL_FALSE);
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
return static_cast<T>(mBoundBuffer.id());
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
return static_cast<T>(mDivisor);
case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
return static_cast<T>(mPureInteger ? GL_TRUE : GL_FALSE);
default:
UNREACHABLE();
return static_cast<T>(0);
}
}
// From glVertexAttribPointer
GLenum mType;
GLint mSize;
bool mNormalized;
bool mPureInteger;
GLsizei mStride; // 0 means natural stride
union
{
const void *mPointer;
intptr_t mOffset;
};
BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
unsigned int mDivisor;
};
struct VertexAttribCurrentValueData
{
union
{
GLfloat FloatValues[4];
GLint IntValues[4];
GLuint UnsignedIntValues[4];
};
GLenum Type;
void setFloatValues(const GLfloat floatValues[4])
{
for (unsigned int valueIndex = 0; valueIndex < 4; valueIndex++)
{
FloatValues[valueIndex] = floatValues[valueIndex];
}
Type = GL_FLOAT;
}
void setIntValues(const GLint intValues[4])
{
for (unsigned int valueIndex = 0; valueIndex < 4; valueIndex++)
{
IntValues[valueIndex] = intValues[valueIndex];
}
Type = GL_INT;
}
void setUnsignedIntValues(const GLuint unsignedIntValues[4])
{
for (unsigned int valueIndex = 0; valueIndex < 4; valueIndex++)
{
UnsignedIntValues[valueIndex] = unsignedIntValues[valueIndex];
}
Type = GL_UNSIGNED_INT;
}
};
}
#endif // LIBGLESV2_VERTEXATTRIBUTE_H_