Commit 93ae1034 by Alexis Hetu Committed by Alexis Hétu

New VertexAttribute data types

Added int and unsigned int as possible internal storage types for VertexAttribute on top of the existing float type by using a union in order to be able to store the new VertexAttribute types in their native types. Change-Id: I5a98aeded065095df6b44fa20f4c293ae230bc37 Reviewed-on: https://swiftshader-review.googlesource.com/2828Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent b6075da3
...@@ -746,6 +746,11 @@ void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) ...@@ -746,6 +746,11 @@ void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled)
mState.vertexAttribute[attribNum].mArrayEnabled = enabled; mState.vertexAttribute[attribNum].mArrayEnabled = enabled;
} }
void Context::setVertexAttribDivisor(unsigned int attribNum, GLuint divisor)
{
mState.vertexAttribute[attribNum].mDivisor = divisor;
}
const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum) const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum)
{ {
return mState.vertexAttribute[attribNum]; return mState.vertexAttribute[attribNum];
...@@ -3408,10 +3413,25 @@ void Context::setVertexAttrib(GLuint index, const GLfloat *values) ...@@ -3408,10 +3413,25 @@ void Context::setVertexAttrib(GLuint index, const GLfloat *values)
{ {
ASSERT(index < MAX_VERTEX_ATTRIBS); ASSERT(index < MAX_VERTEX_ATTRIBS);
mState.vertexAttribute[index].mCurrentValue[0] = values[0]; mState.vertexAttribute[index].setCurrentValue(values);
mState.vertexAttribute[index].mCurrentValue[1] = values[1];
mState.vertexAttribute[index].mCurrentValue[2] = values[2]; mVertexDataManager->dirtyCurrentValue(index);
mState.vertexAttribute[index].mCurrentValue[3] = values[3]; }
void Context::setVertexAttrib(GLuint index, const GLint *values)
{
ASSERT(index < MAX_VERTEX_ATTRIBS);
mState.vertexAttribute[index].setCurrentValue(values);
mVertexDataManager->dirtyCurrentValue(index);
}
void Context::setVertexAttrib(GLuint index, const GLuint *values)
{
ASSERT(index < MAX_VERTEX_ATTRIBS);
mState.vertexAttribute[index].setCurrentValue(values);
mVertexDataManager->dirtyCurrentValue(index); mVertexDataManager->dirtyCurrentValue(index);
} }
......
...@@ -133,12 +133,13 @@ struct Color ...@@ -133,12 +133,13 @@ struct Color
class VertexAttribute class VertexAttribute
{ {
public: public:
VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mPointer(NULL), mArrayEnabled(false) VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mDivisor(0), mPointer(NULL), mArrayEnabled(false)
{ {
mCurrentValue[0] = 0.0f; mCurrentValue[0].f = 0.0f;
mCurrentValue[1] = 0.0f; mCurrentValue[1].f = 0.0f;
mCurrentValue[2] = 0.0f; mCurrentValue[2].f = 0.0f;
mCurrentValue[3] = 1.0f; mCurrentValue[3].f = 1.0f;
mCurrentValueType = ValueUnion::FloatType;
} }
int typeSize() const int typeSize() const
...@@ -160,11 +161,72 @@ class VertexAttribute ...@@ -160,11 +161,72 @@ class VertexAttribute
return mStride ? mStride : typeSize(); return mStride ? mStride : typeSize();
} }
inline float getCurrentValue(int i) const
{
switch(mCurrentValueType)
{
case ValueUnion::FloatType: return mCurrentValue[i].f;
case ValueUnion::IntType: return static_cast<float>(mCurrentValue[i].i);
case ValueUnion::UIntType: return static_cast<float>(mCurrentValue[i].ui);
default: UNREACHABLE(); return mCurrentValue[i].f;
}
}
inline GLint getCurrentValueI(int i) const
{
switch(mCurrentValueType)
{
case ValueUnion::FloatType: return static_cast<GLint>(mCurrentValue[i].f);
case ValueUnion::IntType: return mCurrentValue[i].i;
case ValueUnion::UIntType: return static_cast<GLint>(mCurrentValue[i].ui);
default: UNREACHABLE(); return mCurrentValue[i].i;
}
}
inline GLuint getCurrentValueUI(int i) const
{
switch(mCurrentValueType)
{
case ValueUnion::FloatType: return static_cast<GLuint>(mCurrentValue[i].f);
case ValueUnion::IntType: return static_cast<GLuint>(mCurrentValue[i].i);
case ValueUnion::UIntType: return mCurrentValue[i].ui;
default: UNREACHABLE(); return mCurrentValue[i].ui;
}
}
inline void setCurrentValue(const GLfloat *values)
{
mCurrentValue[0].f = values[0];
mCurrentValue[1].f = values[1];
mCurrentValue[2].f = values[2];
mCurrentValue[3].f = values[3];
mCurrentValueType = ValueUnion::FloatType;
}
inline void setCurrentValue(const GLint *values)
{
mCurrentValue[0].i = values[0];
mCurrentValue[1].i = values[1];
mCurrentValue[2].i = values[2];
mCurrentValue[3].i = values[3];
mCurrentValueType = ValueUnion::IntType;
}
inline void setCurrentValue(const GLuint *values)
{
mCurrentValue[0].ui = values[0];
mCurrentValue[1].ui = values[1];
mCurrentValue[2].ui = values[2];
mCurrentValue[3].ui = values[3];
mCurrentValueType = ValueUnion::UIntType;
}
// From glVertexAttribPointer // From glVertexAttribPointer
GLenum mType; GLenum mType;
GLint mSize; GLint mSize;
bool mNormalized; bool mNormalized;
GLsizei mStride; // 0 means natural stride GLsizei mStride; // 0 means natural stride
GLuint mDivisor; // From glVertexAttribDivisor
union union
{ {
...@@ -175,7 +237,17 @@ class VertexAttribute ...@@ -175,7 +237,17 @@ class VertexAttribute
gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called. gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
bool mArrayEnabled; // From glEnable/DisableVertexAttribArray bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
float mCurrentValue[4]; // From glVertexAttrib private:
union ValueUnion
{
enum Type { FloatType, IntType, UIntType };
float f;
GLint i;
GLuint ui;
};
ValueUnion mCurrentValue[4]; // From glVertexAttrib
ValueUnion::Type mCurrentValueType;
}; };
typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS]; typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
...@@ -353,6 +425,7 @@ public: ...@@ -353,6 +425,7 @@ public:
GLuint getArrayBufferName() const; GLuint getArrayBufferName() const;
void setEnableVertexAttribArray(unsigned int attribNum, bool enabled); void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
void setVertexAttribDivisor(unsigned int attribNum, GLuint divisor);
const VertexAttribute &getVertexAttribState(unsigned int attribNum); const VertexAttribute &getVertexAttribState(unsigned int attribNum);
void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
bool normalized, GLsizei stride, const void *pointer); bool normalized, GLsizei stride, const void *pointer);
...@@ -426,6 +499,8 @@ public: ...@@ -426,6 +499,8 @@ public:
void setRenderbufferStorage(RenderbufferStorage *renderbuffer); void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
void setVertexAttrib(GLuint index, const GLfloat *values); void setVertexAttrib(GLuint index, const GLfloat *values);
void setVertexAttrib(GLuint index, const GLint *values);
void setVertexAttrib(GLuint index, const GLuint *values);
Buffer *getBuffer(GLuint handle); Buffer *getBuffer(GLuint handle);
Fence *getFence(GLuint handle); Fence *getFence(GLuint handle);
......
...@@ -189,7 +189,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat ...@@ -189,7 +189,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
if(mDirtyCurrentValue[i]) if(mDirtyCurrentValue[i])
{ {
delete mCurrentValueBuffer[i]; delete mCurrentValueBuffer[i];
mCurrentValueBuffer[i] = new ConstantVertexBuffer(attribs[i].mCurrentValue[0], attribs[i].mCurrentValue[1], attribs[i].mCurrentValue[2], attribs[i].mCurrentValue[3]); mCurrentValueBuffer[i] = new ConstantVertexBuffer(attribs[i].getCurrentValue(0), attribs[i].getCurrentValue(1), attribs[i].getCurrentValue(2), attribs[i].getCurrentValue(3));
mDirtyCurrentValue[i] = false; mDirtyCurrentValue[i] = false;
} }
......
...@@ -3655,7 +3655,7 @@ void GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params ...@@ -3655,7 +3655,7 @@ void GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params
case GL_CURRENT_VERTEX_ATTRIB: case GL_CURRENT_VERTEX_ATTRIB:
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
params[i] = attribState.mCurrentValue[i]; params[i] = attribState.getCurrentValue(i);
} }
break; break;
case GL_VERTEX_ATTRIB_ARRAY_INTEGER: case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
...@@ -3725,7 +3725,7 @@ void GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params) ...@@ -3725,7 +3725,7 @@ void GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
case GL_CURRENT_VERTEX_ATTRIB: case GL_CURRENT_VERTEX_ATTRIB:
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
float currentValue = attribState.mCurrentValue[i]; float currentValue = attribState.getCurrentValue(i);
params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f)); params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
} }
break; break;
......
...@@ -1761,6 +1761,12 @@ void GL_APIENTRY glGetVertexAttribIiv(GLuint index, GLenum pname, GLint *params) ...@@ -1761,6 +1761,12 @@ void GL_APIENTRY glGetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
*params = attribState.mBoundBuffer.name(); *params = attribState.mBoundBuffer.name();
break; break;
case GL_CURRENT_VERTEX_ATTRIB:
for(int i = 0; i < 4; ++i)
{
params[i] = attribState.getCurrentValueI(i);
}
break;
case GL_VERTEX_ATTRIB_ARRAY_INTEGER: case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
switch(attribState.mType) switch(attribState.mType)
{ {
...@@ -1779,6 +1785,9 @@ void GL_APIENTRY glGetVertexAttribIiv(GLuint index, GLenum pname, GLint *params) ...@@ -1779,6 +1785,9 @@ void GL_APIENTRY glGetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
break; break;
} }
break; break;
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
*params = attribState.mDivisor;
break;
default: return error(GL_INVALID_ENUM); default: return error(GL_INVALID_ENUM);
} }
} }
...@@ -1820,6 +1829,12 @@ void GL_APIENTRY glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *param ...@@ -1820,6 +1829,12 @@ void GL_APIENTRY glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *param
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
*params = attribState.mBoundBuffer.name(); *params = attribState.mBoundBuffer.name();
break; break;
case GL_CURRENT_VERTEX_ATTRIB:
for(int i = 0; i < 4; ++i)
{
params[i] = attribState.getCurrentValueUI(i);
}
break;
case GL_VERTEX_ATTRIB_ARRAY_INTEGER: case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
switch(attribState.mType) switch(attribState.mType)
{ {
...@@ -1838,6 +1853,9 @@ void GL_APIENTRY glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *param ...@@ -1838,6 +1853,9 @@ void GL_APIENTRY glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *param
break; break;
} }
break; break;
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
*params = attribState.mDivisor;
break;
default: return error(GL_INVALID_ENUM); default: return error(GL_INVALID_ENUM);
} }
} }
...@@ -1847,26 +1865,72 @@ void GL_APIENTRY glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLin ...@@ -1847,26 +1865,72 @@ void GL_APIENTRY glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLin
{ {
TRACE("(GLuint index = %d, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)", TRACE("(GLuint index = %d, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
index, x, y, z, w); index, x, y, z, w);
UNIMPLEMENTED();
if(index >= es2::MAX_VERTEX_ATTRIBS)
{
return error(GL_INVALID_VALUE);
}
es2::Context *context = es2::getContext();
if(context)
{
GLint vals[4] = { x, y, z, w };
context->setVertexAttrib(index, vals);
}
} }
void GL_APIENTRY glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w) void GL_APIENTRY glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
{ {
TRACE("(GLuint index = %d, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)", TRACE("(GLuint index = %d, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
index, x, y, z, w); index, x, y, z, w);
UNIMPLEMENTED();
if(index >= es2::MAX_VERTEX_ATTRIBS)
{
return error(GL_INVALID_VALUE);
}
es2::Context *context = es2::getContext();
if(context)
{
GLuint vals[4] = { x, y, z, w };
context->setVertexAttrib(index, vals);
}
} }
void GL_APIENTRY glVertexAttribI4iv(GLuint index, const GLint *v) void GL_APIENTRY glVertexAttribI4iv(GLuint index, const GLint *v)
{ {
TRACE("(GLuint index = %d, GLint *v = 0x%0.8p)", index, v); TRACE("(GLuint index = %d, GLint *v = 0x%0.8p)", index, v);
UNIMPLEMENTED();
if(index >= es2::MAX_VERTEX_ATTRIBS)
{
return error(GL_INVALID_VALUE);
}
es2::Context *context = es2::getContext();
if(context)
{
context->setVertexAttrib(index, v);
}
} }
void GL_APIENTRY glVertexAttribI4uiv(GLuint index, const GLuint *v) void GL_APIENTRY glVertexAttribI4uiv(GLuint index, const GLuint *v)
{ {
TRACE("(GLuint index = %d, GLint *v = 0x%0.8p)", index, v); TRACE("(GLuint index = %d, GLint *v = 0x%0.8p)", index, v);
UNIMPLEMENTED();
if(index >= es2::MAX_VERTEX_ATTRIBS)
{
return error(GL_INVALID_VALUE);
}
es2::Context *context = es2::getContext();
if(context)
{
context->setVertexAttrib(index, v);
}
} }
void GL_APIENTRY glGetUniformuiv(GLuint program, GLint location, GLuint *params) void GL_APIENTRY glGetUniformuiv(GLuint program, GLint location, GLuint *params)
...@@ -3020,7 +3084,18 @@ void GL_APIENTRY glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat * ...@@ -3020,7 +3084,18 @@ void GL_APIENTRY glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *
void GL_APIENTRY glVertexAttribDivisor(GLuint index, GLuint divisor) void GL_APIENTRY glVertexAttribDivisor(GLuint index, GLuint divisor)
{ {
TRACE("(GLuint index = %d, GLuint divisor = %d)", index, divisor); TRACE("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
UNIMPLEMENTED();
es2::Context *context = es2::getContext();
if(context)
{
if(index >= es2::MAX_VERTEX_ATTRIBS)
{
return error(GL_INVALID_VALUE);
}
context->setVertexAttribDivisor(index, divisor);
}
} }
void GL_APIENTRY glBindTransformFeedback(GLenum target, GLuint id) void GL_APIENTRY glBindTransformFeedback(GLenum target, GLuint id)
......
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