}
/* grow list */
- shProg->Shaders = (struct gl_shader **)
- realloc(shProg->Shaders,
- (n + 1) * sizeof(struct gl_shader *));
+ shProg->Shaders = realloc(shProg->Shaders,
+ (n + 1) * sizeof(struct gl_shader *));
if (!shProg->Shaders) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader");
return;
}
-static GLuint
+static GLuint
create_shader_program(struct gl_context *ctx)
{
GLuint name;
/**
- * Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's
- * DeleteProgramARB.
+ * Delete a shader program. Actually, just decrement the program's
+ * reference count and mark it as DeletePending.
+ * Used to implement glDeleteProgram() and glDeleteObjectARB().
*/
static void
delete_shader_program(struct gl_context *ctx, GLuint name)
/* not found */
{
GLenum err;
- if (is_shader(ctx, shader))
- err = GL_INVALID_OPERATION;
- else if (is_program(ctx, shader))
+ if (is_shader(ctx, shader) || is_program(ctx, shader))
err = GL_INVALID_OPERATION;
else
err = GL_INVALID_VALUE;
get_attached_shaders(struct gl_context *ctx, GLuint program, GLsizei maxCount,
GLsizei *count, GLuint *obj)
{
- struct gl_shader_program *shProg =
+ struct gl_shader_program *shProg;
+
+ if (maxCount < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetAttachedShaders(maxCount < 0)");
+ return;
+ }
+
+ shProg =
_mesa_lookup_shader_program_err(ctx, program, "glGetAttachedShaders");
+
if (shProg) {
GLuint i;
for (i = 0; i < (GLuint) maxCount && i < shProg->NumShaders; i++) {
* programs (see glGetProgramivARB).
*/
static void
-get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *params)
+get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
+ GLint *params)
{
struct gl_shader_program *shProg
- = _mesa_lookup_shader_program(ctx, program);
+ = _mesa_lookup_shader_program_err(ctx, program, "glGetProgramiv(program)");
/* Is transform feedback available in this context?
*/
/* Are uniform buffer objects available in this context?
*/
const bool has_ubo =
- (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ARB_uniform_buffer_object)
+ (ctx->API == API_OPENGL_COMPAT &&
+ ctx->Extensions.ARB_uniform_buffer_object)
|| ctx->API == API_OPENGL_CORE
|| _mesa_is_gles3(ctx);
if (!shProg) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramiv(program)");
return;
}
for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) {
/* Add one for the terminating NUL character.
*/
- const GLint len = strlen(shProg->TransformFeedback.VaryingNames[i]) + 1;
+ const GLint len =
+ strlen(shProg->TransformFeedback.VaryingNames[i]) + 1;
if (len > max_len)
max_len = len;
get_program_info_log(struct gl_context *ctx, GLuint program, GLsizei bufSize,
GLsizei *length, GLchar *infoLog)
{
- struct gl_shader_program *shProg
- = _mesa_lookup_shader_program(ctx, program);
+ struct gl_shader_program *shProg;
+
+ /* Section 2.5 GL Errors (page 18) of the OpenGL ES 3.0.4 spec and
+ * section 2.3.1 (Errors) of the OpenGL 4.5 spec say:
+ *
+ * "If a negative number is provided where an argument of type sizei or
+ * sizeiptr is specified, an INVALID_VALUE error is generated."
+ */
+ if (bufSize < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramInfoLog(bufSize < 0)");
+ return;
+ }
+
+ shProg = _mesa_lookup_shader_program_err(ctx, program,
+ "glGetProgramInfoLog(program)");
if (!shProg) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramInfoLog(program)");
return;
}
+
_mesa_copy_string(infoLog, bufSize, length, shProg->InfoLog);
}
get_shader_info_log(struct gl_context *ctx, GLuint shader, GLsizei bufSize,
GLsizei *length, GLchar *infoLog)
{
- struct gl_shader *sh = _mesa_lookup_shader(ctx, shader);
+ struct gl_shader *sh;
+
+ /* Section 2.5 GL Errors (page 18) of the OpenGL ES 3.0.4 spec and
+ * section 2.3.1 (Errors) of the OpenGL 4.5 spec say:
+ *
+ * "If a negative number is provided where an argument of type sizei or
+ * sizeiptr is specified, an INVALID_VALUE error is generated."
+ */
+ if (bufSize < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderInfoLog(bufSize < 0)");
+ return;
+ }
+
+ sh = _mesa_lookup_shader_err(ctx, shader, "glGetShaderInfoLog(shader)");
if (!sh) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderInfoLog(shader)");
return;
}
+
_mesa_copy_string(infoLog, bufSize, length, sh->InfoLog);
}
GLsizei *length, GLchar *sourceOut)
{
struct gl_shader *sh;
+
+ if (maxLength < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderSource(bufSize < 0)");
+ return;
+ }
+
sh = _mesa_lookup_shader_err(ctx, shader, "glGetShaderSource");
if (!sh) {
return;
}
fflush(stderr);
}
-
}
if (!sh->CompileStatus) {
_mesa_glsl_link_shader(ctx, shProg);
- if (shProg->LinkStatus == GL_FALSE &&
+ if (shProg->LinkStatus == GL_FALSE &&
(ctx->_Shader->Flags & GLSL_REPORT_ERRORS)) {
_mesa_debug(ctx, "Error linking program %u:\n%s\n",
shProg->Name, shProg->InfoLog);
}
}
-/**
- */
+
static void
use_shader_program(struct gl_context *ctx, GLenum type,
struct gl_shader_program *shProg,
}
}
+
/**
* Use the named shader program for subsequent rendering.
*/
any active sampler in the current program object refers to a texture
image unit where fixed-function fragment processing accesses a
- texture target that does not match the sampler type, or
+ texture target that does not match the sampler type, or
the sum of the number of active samplers in the program and the
number of texture image units enabled for fixed-function fragment
image units allowed.
*/
-
/*
* Check: any two active samplers in the current program object are of
* different types, but refer to the same texture image unit,
(void) binaryformat;
(void) binary;
(void) length;
- _mesa_error(ctx, GL_INVALID_OPERATION, __FUNCTION__);
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glShaderBinary");
}
GLenum *binaryFormat, GLvoid *binary)
{
struct gl_shader_program *shProg;
+ GLsizei length_dummy;
GET_CURRENT_CONTEXT(ctx);
- shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetProgramBinary");
- if (!shProg)
- return;
-
- if (!shProg->LinkStatus) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetProgramBinary(program %u not linked)",
- shProg->Name);
- return;
- }
-
if (bufSize < 0){
_mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramBinary(bufSize < 0)");
return;
}
+ shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetProgramBinary");
+ if (!shProg)
+ return;
+
/* The ARB_get_program_binary spec says:
*
* "If <length> is NULL, then no length is returned."
+ *
+ * Ensure that length always points to valid storage to avoid multiple NULL
+ * pointer checks below.
*/
if (length != NULL)
+ length = &length_dummy;
+
+
+ /* The ARB_get_program_binary spec says:
+ *
+ * "When a program object's LINK_STATUS is FALSE, its program binary
+ * length is zero, and a call to GetProgramBinary will generate an
+ * INVALID_OPERATION error.
+ */
+ if (!shProg->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetProgramBinary(program %u not linked)",
+ shProg->Name);
*length = 0;
+ return;
+ }
+
+ *length = 0;
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetProgramBinary(driver supports zero binary formats)");
(void) binaryFormat;
(void) binary;
(void) binaryFormat;
(void) binary;
- (void) length;
- _mesa_error(ctx, GL_INVALID_OPERATION, __FUNCTION__);
+
+ /* Section 2.3.1 (Errors) of the OpenGL 4.5 spec says:
+ *
+ * "If a negative number is provided where an argument of type sizei or
+ * sizeiptr is specified, an INVALID_VALUE error is generated."
+ */
+ if (length < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glProgramBinary(length < 0)");
+ return;
+ }
+
+ /* The ARB_get_program_binary spec says:
+ *
+ * "<binaryFormat> and <binary> must be those returned by a previous
+ * call to GetProgramBinary, and <length> must be the length of the
+ * program binary as returned by GetProgramBinary or GetProgramiv with
+ * <pname> PROGRAM_BINARY_LENGTH. Loading the program binary will fail,
+ * setting the LINK_STATUS of <program> to FALSE, if these conditions
+ * are not met."
+ *
+ * Since any value of binaryFormat passed "is not one of those specified as
+ * allowable for [this] command, an INVALID_ENUM error is generated."
+ */
+ shProg->LinkStatus = GL_FALSE;
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramBinary");
}
* ProgramParameteri is not TRUE or FALSE."
*/
if (value != GL_TRUE && value != GL_FALSE) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glProgramParameteri(pname=%s, value=%d): "
- "value must be 0 or 1.",
- _mesa_lookup_enum_by_nr(pname),
- value);
- return;
+ goto invalid_value;
}
/* No need to notify the driver. Any changes will actually take effect
* Chapter 7.3 Program Objects
*/
if (value != GL_TRUE && value != GL_FALSE) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glProgramParameteri(pname=%s, value=%d): "
- "value must be 0 or 1.",
- _mesa_lookup_enum_by_nr(pname),
- value);
- return;
+ goto invalid_value;
}
shProg->SeparateShader = value;
return;
default:
- break;
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameteri(pname=%s)",
+ _mesa_lookup_enum_by_nr(pname));
+ return;
}
- _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameteri(pname=%s)",
- _mesa_lookup_enum_by_nr(pname));
+invalid_value:
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glProgramParameteri(pname=%s, value=%d): "
+ "value must be 0 or 1.",
+ _mesa_lookup_enum_by_nr(pname),
+ value);
}
+
void
_mesa_use_shader_program(struct gl_context *ctx, GLenum type,
struct gl_shader_program *shProg,