Commit 3078d0f7 by Jamie Madill

Add VertexFormat internal struct to represent vertex inputs.

A VertexFormat is similar to a simplified VertexAttribute, without extra unncessary data. VertexFormats will be useful for GPU vertex conversions with dynamic shader compilation. Change-Id: I4e60e0a12d5f081fb52d95c8977c43d481b33bff Reviewed-on: https://chromium-review.googlesource.com/184398Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 8ff21aea
......@@ -8,6 +8,8 @@
// angletypes.h : Defines a variety of structures and enum types that are used throughout libGLESv2
#include "libGLESv2/angletypes.h"
#include "libGLESv2/ProgramBinary.h"
#include "libGLESv2/VertexAttribute.h"
namespace gl
{
......@@ -62,4 +64,108 @@ bool ClipRectangle(const Rectangle &source, const Rectangle &clip, Rectangle *in
}
}
VertexFormat::VertexFormat()
: mType(GL_NONE),
mNormalized(GL_FALSE),
mComponents(0),
mPureInteger(false)
{}
VertexFormat::VertexFormat(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
: mType(type),
mNormalized(normalized),
mComponents(components),
mPureInteger(pureInteger)
{
// Float data can not be normalized, so ignore the user setting
if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
{
mNormalized = GL_FALSE;
}
}
VertexFormat::VertexFormat(const VertexAttribute &attribute)
: mType(attribute.mType),
mNormalized(attribute.mNormalized ? GL_TRUE : GL_FALSE),
mComponents(attribute.mSize),
mPureInteger(attribute.mPureInteger)
{
// Ensure we aren't initializing a vertex format which should be using
// the current-value type
ASSERT(attribute.mArrayEnabled);
// Float data can not be normalized, so ignore the user setting
if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
{
mNormalized = GL_FALSE;
}
}
VertexFormat::VertexFormat(const VertexAttribute &attribute, GLenum currentValueType)
: mType(attribute.mType),
mNormalized(attribute.mNormalized ? GL_TRUE : GL_FALSE),
mComponents(attribute.mSize),
mPureInteger(attribute.mPureInteger)
{
if (!attribute.mArrayEnabled)
{
mType = currentValueType;
mNormalized = GL_FALSE;
mComponents = 4;
mPureInteger = (currentValueType != GL_FLOAT);
}
// Float data can not be normalized, so ignore the user setting
if (mType == GL_FLOAT || mType == GL_HALF_FLOAT || mType == GL_FIXED)
{
mNormalized = GL_FALSE;
}
}
void VertexFormat::GetInputLayout(VertexFormat *inputLayout,
ProgramBinary *programBinary,
const VertexAttribute *attributes,
const gl::VertexAttribCurrentValueData *currentValues)
{
for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
{
int semanticIndex = programBinary->getSemanticIndex(attributeIndex);
if (semanticIndex != -1)
{
inputLayout[semanticIndex] = VertexFormat(attributes[attributeIndex], currentValues[attributeIndex].Type);
}
}
}
bool VertexFormat::operator==(const VertexFormat &other) const
{
return (mType == other.mType &&
mComponents == other.mComponents &&
mNormalized == other.mNormalized &&
mPureInteger == other.mPureInteger );
}
bool VertexFormat::operator!=(const VertexFormat &other) const
{
return !(*this == other);
}
bool VertexFormat::operator<(const VertexFormat& other) const
{
if (mType != other.mType)
{
return mType < other.mType;
}
if (mNormalized != other.mNormalized)
{
return mNormalized < other.mNormalized;
}
if (mComponents != other.mComponents)
{
return mComponents < other.mComponents;
}
return mPureInteger < other.mPureInteger;
}
}
......@@ -15,6 +15,9 @@
namespace gl
{
class Buffer;
class ProgramBinary;
class VertexAttribute;
struct VertexAttribCurrentValueData;
enum TextureType
{
......@@ -213,6 +216,28 @@ struct PixelPackState
{}
};
struct VertexFormat
{
GLenum mType;
GLboolean mNormalized;
GLuint mComponents;
bool mPureInteger;
VertexFormat();
VertexFormat(GLenum type, GLboolean normalized, GLuint components, bool pureInteger);
explicit VertexFormat(const VertexAttribute &attribute);
VertexFormat(const VertexAttribute &attribute, GLenum currentValueType);
static void GetInputLayout(VertexFormat *inputLayout,
ProgramBinary *programBinary,
const VertexAttribute *attributes,
const gl::VertexAttribCurrentValueData *currentValues);
bool operator==(const VertexFormat &other) const;
bool operator!=(const VertexFormat &other) const;
bool operator<(const VertexFormat& other) const;
};
}
#endif // LIBGLESV2_ANGLETYPES_H_
......@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_INDEXRANGECACHE_H_
#include "common/angleutils.h"
#include <map>
namespace rx
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment