Implement robust the GetInternalFormativ entry point.

BUG=angleproject:1354

Change-Id: Ib25fe4905fdd6c532c67de1d4ca1ba37932f8e0b
Reviewed-on: https://chromium-review.googlesource.com/401149
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Geoff Lang <geofflang@chromium.org>
This commit is contained in:
Geoff Lang 2016-10-20 10:59:20 -07:00 коммит произвёл Commit Bot
Родитель 635671dc0d
Коммит 0a9661f2b4
11 изменённых файлов: 193 добавлений и 44 удалений

Просмотреть файл

@ -77,6 +77,7 @@ New Procedures and Functions
void GetQueryObjectuivRobustANGLE(uint id, enum pname, sizei bufSize, sizei *length, uint *params)
void GetBufferPointervRobustANGLE(enum target, enum pname, sizei bufSize, sizei *length, void **params)
void GetIntegeri_vRobustANGLE(enum target, uint index, sizei bufSize, sizei *length, int *data)
void GetInternalformativRobustANGLE(enum target, enum internalformat, enum pname, sizei bufSize, sizei *length, int *params)
void GetVertexAttribIivRobustANGLE(uint index, enum pname, sizei bufSize, sizei *length, int *params)
void GetVertexAttribIuivRobustANGLE(uint index, enum pname, sizei bufSize, sizei *length, uint *params)
void GetUniformuivRobustANGLE(uint program, int location, sizei bufSize, sizei *length, uint *params)

Просмотреть файл

@ -3283,6 +3283,7 @@ typedef void (GL_APIENTRYP PFNGLGETQUERYIVROBUSTANGLE) (GLenum target, GLenum pn
typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUIVROBUSTANGLE) (GLuint id, GLenum pname, GLsizei bufSize, GLsizei *length, GLuint *params);
typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVROBUSTANGLE) (GLenum target, GLenum pname, GLsizei bufSize, GLsizei *length, void **params);
typedef void (GL_APIENTRYP PFNGLGETINTEGERI_VROBUSTANGLE) (GLenum target, GLuint index, GLsizei bufSize, GLsizei *length, GLint *data);
typedef void (GL_APIENTRYP PFNGETINTERNALFORMATIVROBUSTANGLE) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *params);
typedef void (GL_APIENTRYP PFNGLGETVERTEXATTRIBIIVROBUSTANGLE) (GLuint index, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *params);
typedef void (GL_APIENTRYP PFNGLGETVERTEXATTRIBIUIVROBUSTANGLE) (GLuint index, GLenum pname, GLsizei bufSize, GLsizei *length, GLuint *params);
typedef void (GL_APIENTRYP PFNGLGETUNIFORMUIVROBUSTANGLE) (GLuint program, GLint location, GLsizei bufSize, GLsizei *length, GLuint *params);
@ -3343,6 +3344,7 @@ GL_APICALL void GL_APIENTRY glGetQueryivRobustANGLE (GLenum target, GLenum pname
GL_APICALL void GL_APIENTRY glGetQueryObjectuivRobustANGLE (GLuint id, GLenum pname, GLsizei bufSize, GLsizei *length, GLuint *params);
GL_APICALL void GL_APIENTRY glGetBufferPointervRobustANGLE (GLenum target, GLenum pname, GLsizei bufSize, GLsizei *length, void **params);
GL_APICALL void GL_APIENTRY glGetIntegeri_vRobustANGLE (GLenum target, GLuint index, GLsizei bufSize, GLsizei *length, GLint *data);
GL_APICALL void GL_APIENTRY glGetInternalformativRobustANGLE (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *params);
GL_APICALL void GL_APIENTRY glGetVertexAttribIivRobustANGLE (GLuint index, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *params);
GL_APICALL void GL_APIENTRY glGetVertexAttribIuivRobustANGLE (GLuint index, GLenum pname, GLsizei bufSize, GLsizei *length, GLuint *params);
GL_APICALL void GL_APIENTRY glGetUniformuivRobustANGLE (GLuint program, GLint location, GLsizei bufSize, GLsizei *length, GLuint *params);

Просмотреть файл

@ -676,6 +676,34 @@ void QueryActiveUniformBlockiv(const Program *program,
}
}
void QueryInternalFormativ(const TextureCaps &format, GLenum pname, GLsizei bufSize, GLint *params)
{
switch (pname)
{
case GL_NUM_SAMPLE_COUNTS:
if (bufSize != 0)
{
*params = static_cast<GLint>(format.sampleCounts.size());
}
break;
case GL_SAMPLES:
{
size_t returnCount = std::min<size_t>(bufSize, format.sampleCounts.size());
auto sampleReverseIt = format.sampleCounts.rbegin();
for (size_t sampleIndex = 0; sampleIndex < returnCount; ++sampleIndex)
{
params[sampleIndex] = *sampleReverseIt++;
}
}
break;
default:
UNREACHABLE();
break;
}
}
void SetTexParameterf(Texture *texture, GLenum pname, GLfloat param)
{
SetTexParameterBase(texture, pname, &param);

Просмотреть файл

@ -21,6 +21,7 @@ class Renderbuffer;
class Sampler;
class Shader;
class Texture;
struct TextureCaps;
struct UniformBlock;
struct VertexAttribute;
struct VertexAttribCurrentValueData;
@ -61,6 +62,8 @@ void QueryActiveUniformBlockiv(const Program *program,
GLenum pname,
GLint *params);
void QueryInternalFormativ(const TextureCaps &format, GLenum pname, GLsizei bufSize, GLint *params);
void SetTexParameterf(Texture *texture, GLenum pname, GLfloat param);
void SetTexParameterfv(Texture *texture, GLenum pname, const GLfloat *params);
void SetTexParameteri(Texture *texture, GLenum pname, GLint param);

Просмотреть файл

@ -1156,6 +1156,73 @@ bool ValidateGetBufferParameterBase(ValidationContext *context,
return true;
}
bool ValidateGetInternalFormativBase(Context *context,
GLenum target,
GLenum internalformat,
GLenum pname,
GLsizei bufSize,
GLsizei *numParams)
{
if (numParams)
{
*numParams = 0;
}
if (context->getClientMajorVersion() < 3)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Context does not support OpenGL ES 3.0."));
return false;
}
const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
if (!formatCaps.renderable)
{
context->handleError(Error(GL_INVALID_ENUM, "Internal format is not renderable."));
return false;
}
switch (target)
{
case GL_RENDERBUFFER:
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Invalid target."));
return false;
}
if (bufSize < 0)
{
context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative."));
return false;
}
GLsizei maxWriteParams = 0;
switch (pname)
{
case GL_NUM_SAMPLE_COUNTS:
maxWriteParams = 1;
break;
case GL_SAMPLES:
maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size());
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown pname."));
return false;
}
if (numParams)
{
// glGetInternalFormativ will not overflow bufSize
*numParams = std::min(bufSize, maxWriteParams);
}
return true;
}
} // anonymous namespace
bool ValidTextureTarget(const ValidationContext *context, GLenum target)
@ -5101,4 +5168,41 @@ bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context,
return true;
}
bool ValidateGetInternalFormativ(Context *context,
GLenum target,
GLenum internalformat,
GLenum pname,
GLsizei bufSize,
GLint *params)
{
return ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize,
nullptr);
}
bool ValidateGetInternalFormativRobustANGLE(Context *context,
GLenum target,
GLenum internalformat,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, length))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *length))
{
return false;
}
return true;
}
} // namespace gl

Просмотреть файл

@ -536,6 +536,20 @@ bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context,
GLsizei *length,
GLint *params);
bool ValidateGetInternalFormativ(Context *context,
GLenum target,
GLenum internalformat,
GLenum pname,
GLsizei bufSize,
GLint *params);
bool ValidateGetInternalFormativRobustANGLE(Context *context,
GLenum target,
GLenum internalformat,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params);
// Error messages shared here for use in testing.
extern const char *g_ExceedsMaxElementErrorMessage;
} // namespace gl

Просмотреть файл

@ -1505,6 +1505,7 @@ __eglMustCastToProperFunctionPointerType EGLAPIENTRY GetProcAddress(const char *
INSERT_PROC_ADDRESS(gl, GetQueryObjectuivRobustANGLE);
INSERT_PROC_ADDRESS(gl, GetBufferPointervRobustANGLE);
INSERT_PROC_ADDRESS(gl, GetIntegeri_vRobustANGLE);
INSERT_PROC_ADDRESS(gl, GetInternalformativRobustANGLE);
INSERT_PROC_ADDRESS(gl, GetVertexAttribIivRobustANGLE);
INSERT_PROC_ADDRESS(gl, GetVertexAttribIuivRobustANGLE);
INSERT_PROC_ADDRESS(gl, GetUniformuivRobustANGLE);

Просмотреть файл

@ -2670,6 +2670,34 @@ GetIntegeri_vRobustANGLE(GLenum target, GLuint index, GLsizei bufSize, GLsizei *
UNIMPLEMENTED();
}
ANGLE_EXPORT void GL_APIENTRY GetInternalformativRobustANGLE(GLenum target,
GLenum internalformat,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
EVENT(
"(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize "
"= %d, GLsizei* length = 0x%0.8p, GLint* params = 0x%0.8p)",
target, internalformat, pname, bufSize, length, params);
Context *context = GetValidGlobalContext();
if (context)
{
GLsizei numParams = 0;
if (!ValidateGetInternalFormativRobustANGLE(context, target, internalformat, pname, bufSize,
&numParams, params))
{
return;
}
const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
QueryInternalFormativ(formatCaps, pname, bufSize, params);
SetRobustLengthParam(length, numParams);
}
}
ANGLE_EXPORT void GL_APIENTRY GetVertexAttribIivRobustANGLE(GLuint index,
GLenum pname,
GLsizei bufSize,

Просмотреть файл

@ -417,6 +417,12 @@ ANGLE_EXPORT void GL_APIENTRY GetIntegeri_vRobustANGLE(GLenum target,
GLsizei bufSize,
GLsizei *length,
GLint *data);
ANGLE_EXPORT void GL_APIENTRY GetInternalformativRobustANGLE(GLenum target,
GLenum internalformat,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params);
ANGLE_EXPORT void GL_APIENTRY GetVertexAttribIivRobustANGLE(GLuint index,
GLenum pname,
GLsizei bufSize,

Просмотреть файл

@ -2605,55 +2605,14 @@ void GL_APIENTRY GetInternalformativ(GLenum target, GLenum internalformat, GLenu
Context *context = GetValidGlobalContext();
if (context)
{
if (context->getClientMajorVersion() < 3)
if (!context->skipValidation() &&
!ValidateGetInternalFormativ(context, target, internalformat, pname, bufSize, params))
{
context->handleError(Error(GL_INVALID_OPERATION));
return;
}
const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
if (!formatCaps.renderable)
{
context->handleError(Error(GL_INVALID_ENUM));
return;
}
if (target != GL_RENDERBUFFER)
{
context->handleError(Error(GL_INVALID_ENUM));
return;
}
if (bufSize < 0)
{
context->handleError(Error(GL_INVALID_VALUE));
return;
}
switch (pname)
{
case GL_NUM_SAMPLE_COUNTS:
if (bufSize != 0)
{
*params = static_cast<GLint>(formatCaps.sampleCounts.size());
}
break;
case GL_SAMPLES:
{
size_t returnCount = std::min<size_t>(bufSize, formatCaps.sampleCounts.size());
auto sampleReverseIt = formatCaps.sampleCounts.rbegin();
for (size_t sampleIndex = 0; sampleIndex < returnCount; ++sampleIndex)
{
params[sampleIndex] = *sampleReverseIt++;;
}
}
break;
default:
context->handleError(Error(GL_INVALID_ENUM));
return;
}
QueryInternalFormativ(formatCaps, pname, bufSize, params);
}
}

Просмотреть файл

@ -84,6 +84,8 @@ class RobustClientMemoryTest : public ANGLETest
eglGetProcAddress("glGetBufferPointervRobustANGLE"));
glGetIntegeri_vRobustANGLE = reinterpret_cast<PFNGLGETINTEGERI_VROBUSTANGLE>(
eglGetProcAddress("glGetIntegeri_vRobustANGLE"));
glGetInternalformativRobustANGLE = reinterpret_cast<PFNGETINTERNALFORMATIVROBUSTANGLE>(
eglGetProcAddress("glGetInternalformativRobustANGLE"));
glGetVertexAttribIivRobustANGLE = reinterpret_cast<PFNGLGETVERTEXATTRIBIIVROBUSTANGLE>(
eglGetProcAddress("glGetVertexAttribIivRobustANGLE"));
glGetVertexAttribIuivRobustANGLE = reinterpret_cast<PFNGLGETVERTEXATTRIBIUIVROBUSTANGLE>(
@ -203,6 +205,7 @@ class RobustClientMemoryTest : public ANGLETest
PFNGLGETQUERYOBJECTUIVROBUSTANGLE glGetQueryObjectuivRobustANGLE = nullptr;
PFNGLGETBUFFERPOINTERVROBUSTANGLE glGetBufferPointervRobustANGLE = nullptr;
PFNGLGETINTEGERI_VROBUSTANGLE glGetIntegeri_vRobustANGLE = nullptr;
PFNGETINTERNALFORMATIVROBUSTANGLE glGetInternalformativRobustANGLE = nullptr;
PFNGLGETVERTEXATTRIBIIVROBUSTANGLE glGetVertexAttribIivRobustANGLE = nullptr;
PFNGLGETVERTEXATTRIBIUIVROBUSTANGLE glGetVertexAttribIuivRobustANGLE = nullptr;
PFNGLGETUNIFORMUIVROBUSTANGLE glGetUniformuivRobustANGLE = nullptr;