Commit 5f4ee797 by Alexis Hetu Committed by Alexis Hétu

glGetActiveUniformsiv implementation

Added proper structures to implement glGetActiveUniformsiv and added it to the Program class. Change-Id: I41b8fd17b6e533ad2638778de9854206d10fe13d Reviewed-on: https://swiftshader-review.googlesource.com/3435Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 3ef0c0a8
...@@ -35,7 +35,9 @@ namespace es2 ...@@ -35,7 +35,9 @@ namespace es2
return buffer; return buffer;
} }
Uniform::Uniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize) : type(type), precision(precision), name(name), arraySize(arraySize) Uniform::Uniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize,
const int blockIndex, const BlockMemberInfo &blockInfo)
: type(type), precision(precision), name(name), arraySize(arraySize), blockIndex(blockIndex), blockInfo(blockInfo)
{ {
int bytes = UniformTypeSize(type) * size(); int bytes = UniformTypeSize(type) * size();
data = new unsigned char[bytes]; data = new unsigned char[bytes];
...@@ -1382,7 +1384,7 @@ namespace es2 ...@@ -1382,7 +1384,7 @@ namespace es2
} }
else else
{ {
uniform = new Uniform(type, precision, name, arraySize); uniform = new Uniform(type, precision, name, arraySize, -1, Uniform::BlockMemberInfo::getDefaultBlockInfo());
} }
if(!uniform) if(!uniform)
...@@ -2500,6 +2502,26 @@ namespace es2 ...@@ -2500,6 +2502,26 @@ namespace es2
return maxLength; return maxLength;
} }
GLint Program::getActiveUniformi(GLuint index, GLenum pname) const
{
const Uniform& uniform = *uniforms[index];
switch(pname)
{
case GL_UNIFORM_TYPE: return static_cast<GLint>(uniform.type);
case GL_UNIFORM_SIZE: return static_cast<GLint>(uniform.size());
case GL_UNIFORM_NAME_LENGTH: return static_cast<GLint>(uniform.name.size() + 1 + (uniform.isArray() ? 3 : 0));
case GL_UNIFORM_BLOCK_INDEX: return uniform.blockIndex;
case GL_UNIFORM_OFFSET: return uniform.blockInfo.offset;
case GL_UNIFORM_ARRAY_STRIDE: return uniform.blockInfo.arrayStride;
case GL_UNIFORM_MATRIX_STRIDE: return uniform.blockInfo.matrixStride;
case GL_UNIFORM_IS_ROW_MAJOR: return static_cast<GLint>(uniform.blockInfo.isRowMajorMatrix);
default:
UNREACHABLE();
break;
}
return 0;
}
void Program::getActiveUniformBlockName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const void Program::getActiveUniformBlockName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const
{ {
ASSERT(index < getActiveUniformBlockCount()); ASSERT(index < getActiveUniformBlockCount());
......
...@@ -34,7 +34,25 @@ namespace es2 ...@@ -34,7 +34,25 @@ namespace es2
// Helper struct representing a single shader uniform // Helper struct representing a single shader uniform
struct Uniform struct Uniform
{ {
Uniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize); struct BlockMemberInfo
{
BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix)
: offset(offset), arrayStride(arrayStride), matrixStride(matrixStride), isRowMajorMatrix(isRowMajorMatrix)
{}
static BlockMemberInfo getDefaultBlockInfo()
{
return BlockMemberInfo(-1, -1, -1, false);
}
int offset;
int arrayStride;
int matrixStride;
bool isRowMajorMatrix;
};
Uniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize,
const int blockIndex, const BlockMemberInfo &blockInfo);
~Uniform(); ~Uniform();
...@@ -46,6 +64,8 @@ namespace es2 ...@@ -46,6 +64,8 @@ namespace es2
const GLenum precision; const GLenum precision;
const std::string name; const std::string name;
const unsigned int arraySize; const unsigned int arraySize;
const int blockIndex;
const BlockMemberInfo blockInfo;
unsigned char *data; unsigned char *data;
bool dirty; bool dirty;
...@@ -154,6 +174,7 @@ namespace es2 ...@@ -154,6 +174,7 @@ namespace es2
void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const;
GLint getActiveUniformCount() const; GLint getActiveUniformCount() const;
GLint getActiveUniformMaxLength() const; GLint getActiveUniformMaxLength() const;
GLint getActiveUniformi(GLuint index, GLenum pname) const;
void getActiveUniformBlockName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const; void getActiveUniformBlockName(GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name) const;
GLint getActiveUniformBlockCount() const; GLint getActiveUniformBlockCount() const;
......
...@@ -2735,9 +2735,23 @@ GL_APICALL void GL_APIENTRY glGetActiveUniformsiv(GLuint program, GLsizei unifor ...@@ -2735,9 +2735,23 @@ GL_APICALL void GL_APIENTRY glGetActiveUniformsiv(GLuint program, GLsizei unifor
{ {
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
for(int uniformId = 0; uniformId < uniformCount; uniformId++)
{
const GLuint index = uniformIndices[uniformId];
if(index >= static_cast<GLuint>(programObject->getActiveUniformCount()))
{
return error(GL_INVALID_VALUE);
}
} }
UNIMPLEMENTED(); for(int uniformId = 0; uniformId < uniformCount; uniformId++)
{
const GLuint index = uniformIndices[uniformId];
params[uniformId] = programObject->getActiveUniformi(index, pname);
}
}
} }
GL_APICALL GLuint GL_APIENTRY glGetUniformBlockIndex(GLuint program, const GLchar *uniformBlockName) GL_APICALL GLuint GL_APIENTRY glGetUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
......
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