validate_image_unit(struct gl_context *ctx, struct gl_image_unit *u)
{
struct gl_texture_object *t = u->TexObj;
- struct gl_texture_image *img;
+ mesa_format tex_format;
if (!t || u->Level < t->BaseLevel ||
u->Level > t->_MaxLevel)
u->Layer >= _mesa_get_texture_layers(t, u->Level))
return GL_FALSE;
- if (t->Target == GL_TEXTURE_CUBE_MAP)
- img = t->Image[u->Layer][u->Level];
- else
- img = t->Image[0][u->Level];
+ if (t->Target == GL_TEXTURE_BUFFER) {
+ tex_format = t->_BufferObjectFormat;
- if (!img || img->Border ||
- get_image_format_class(img->TexFormat) == IMAGE_FORMAT_CLASS_NONE ||
- img->NumSamples > ctx->Const.MaxImageSamples)
+ } else {
+ struct gl_texture_image *img = (t->Target == GL_TEXTURE_CUBE_MAP ?
+ t->Image[u->Layer][u->Level] :
+ t->Image[0][u->Level]);
+
+ if (!img || img->Border || img->NumSamples > ctx->Const.MaxImageSamples)
+ return GL_FALSE;
+
+ tex_format = img->TexFormat;
+ }
+
+ if (get_image_format_class(tex_format) == IMAGE_FORMAT_CLASS_NONE)
return GL_FALSE;
switch (t->ImageFormatCompatibilityType) {
case GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE:
- if (_mesa_get_format_bytes(img->TexFormat) !=
+ if (_mesa_get_format_bytes(tex_format) !=
_mesa_get_format_bytes(u->_ActualFormat))
return GL_FALSE;
break;
case GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS:
- if (get_image_format_class(img->TexFormat) !=
+ if (get_image_format_class(tex_format) !=
get_image_format_class(u->_ActualFormat))
return GL_FALSE;
break;
if (texture != 0) {
struct gl_texture_object *texObj;
- struct gl_texture_image *image;
- mesa_format actualFormat;
+ GLenum tex_format;
if (!u->TexObj || u->TexObj->Name != texture) {
texObj = _mesa_lookup_texture_locked(ctx, texture);
texObj = u->TexObj;
}
- image = texObj->Image[0][0];
+ if (texObj->Target == GL_TEXTURE_BUFFER) {
+ tex_format = texObj->BufferObjectFormat;
+ } else {
+ struct gl_texture_image *image = texObj->Image[0][0];
- if (!image || image->Width == 0 || image->Height == 0 || image->Depth == 0) {
- /* The ARB_multi_bind spec says:
- *
- * "An INVALID_OPERATION error is generated if the width,
- * height, or depth of the level zero texture image of
- * any texture in <textures> is zero (per binding)."
- */
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindImageTextures(the width, height or depth "
- "of the level zero texture image of "
- "textures[%d]=%u is zero)", i, texture);
- continue;
- }
+ if (!image || image->Width == 0 || image->Height == 0 ||
+ image->Depth == 0) {
+ /* The ARB_multi_bind spec says:
+ *
+ * "An INVALID_OPERATION error is generated if the width,
+ * height, or depth of the level zero texture image of
+ * any texture in <textures> is zero (per binding)."
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBindImageTextures(the width, height or depth "
+ "of the level zero texture image of "
+ "textures[%d]=%u is zero)", i, texture);
+ continue;
+ }
- actualFormat = _mesa_get_shader_image_format(image->InternalFormat);
+ tex_format = image->InternalFormat;
+ }
- if (actualFormat == MESA_FORMAT_NONE) {
+ if (_mesa_get_shader_image_format(tex_format) == MESA_FORMAT_NONE) {
/* The ARB_multi_bind spec says:
*
* "An INVALID_OPERATION error is generated if the internal
"glBindImageTextures(the internal format %s of "
"the level zero texture image of textures[%d]=%u "
"is not supported)",
- _mesa_lookup_enum_by_nr(image->InternalFormat),
+ _mesa_lookup_enum_by_nr(tex_format),
i, texture);
continue;
}
u->Layered = _mesa_tex_target_is_layered(texObj->Target);
u->Layer = 0;
u->Access = GL_READ_WRITE;
- u->Format = image->InternalFormat;
- u->_ActualFormat = actualFormat;
+ u->Format = tex_format;
+ u->_ActualFormat = _mesa_get_shader_image_format(tex_format);
u->_Valid = validate_image_unit(ctx, u);
} else {
/* Unbind the texture from the unit */