* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*/
-
/**
* \file texstorage.c
* GL_ARB_texture_storage functions
*/
-
-
#include "glheader.h"
#include "context.h"
#include "enums.h"
-#include "imports.h"
+
#include "macros.h"
-#include "mfeatures.h"
#include "teximage.h"
#include "texobj.h"
+#include "mipmap.h"
#include "texstorage.h"
+#include "textureview.h"
#include "mtypes.h"
-
+#include "glformats.h"
+#include "hash.h"
/**
* This is a bit different than legal_teximage_target() when it comes
* to cube maps.
*/
-static GLboolean
-legal_texobj_target(struct gl_context *ctx, GLuint dims, GLenum target)
+static bool
+legal_texobj_target(const struct gl_context *ctx, GLuint dims, GLenum target)
{
+ if (dims < 1 || dims > 3) {
+ _mesa_problem(ctx, "invalid dims=%u in legal_texobj_target()", dims);
+ return false;
+ }
+
+ switch (dims) {
+ case 2:
+ switch (target) {
+ case GL_TEXTURE_2D:
+ return true;
+ case GL_TEXTURE_CUBE_MAP:
+ return ctx->Extensions.ARB_texture_cube_map;
+ }
+ break;
+ case 3:
+ switch (target) {
+ case GL_TEXTURE_3D:
+ return true;
+ case GL_TEXTURE_2D_ARRAY:
+ return ctx->Extensions.EXT_texture_array;
+ case GL_TEXTURE_CUBE_MAP_ARRAY:
+ return _mesa_has_texture_cube_map_array(ctx);
+ }
+ break;
+ }
+
+ if (!_mesa_is_desktop_gl(ctx))
+ return false;
+
switch (dims) {
case 1:
switch (target) {
case GL_TEXTURE_1D:
case GL_PROXY_TEXTURE_1D:
- return GL_TRUE;
+ return true;
default:
- return GL_FALSE;
+ return false;
}
case 2:
switch (target) {
- case GL_TEXTURE_2D:
case GL_PROXY_TEXTURE_2D:
- return GL_TRUE;
- case GL_TEXTURE_CUBE_MAP:
+ return true;
case GL_PROXY_TEXTURE_CUBE_MAP:
return ctx->Extensions.ARB_texture_cube_map;
case GL_TEXTURE_RECTANGLE:
return ctx->Extensions.NV_texture_rectangle;
case GL_TEXTURE_1D_ARRAY:
case GL_PROXY_TEXTURE_1D_ARRAY:
- return (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array);
+ return ctx->Extensions.EXT_texture_array;
default:
- return GL_FALSE;
+ return false;
}
case 3:
switch (target) {
- case GL_TEXTURE_3D:
case GL_PROXY_TEXTURE_3D:
- return GL_TRUE;
- case GL_TEXTURE_2D_ARRAY:
+ return true;
case GL_PROXY_TEXTURE_2D_ARRAY:
- return (ctx->Extensions.MESA_texture_array ||
- ctx->Extensions.EXT_texture_array);
+ return ctx->Extensions.EXT_texture_array;
+ case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY:
+ return ctx->Extensions.ARB_texture_cube_map_array;
default:
- return GL_FALSE;
+ return false;
}
default:
- _mesa_problem(ctx, "invalid dims=%u in legal_texobj_target()", dims);
- return GL_FALSE;
+ unreachable("impossible dimensions");
}
}
-/**
- * Compute the size of the next mipmap level.
- */
-static void
-next_mipmap_level_size(GLenum target,
- GLint *width, GLint *height, GLint *depth)
+/** Helper to get a particular texture image in a texture object */
+static struct gl_texture_image *
+get_tex_image(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLuint face, GLuint level)
{
- if (*width > 1) {
- *width /= 2;
- }
-
- if ((*height > 1) && (target != GL_TEXTURE_1D_ARRAY)) {
- *height /= 2;
- }
-
- if ((*depth > 1) && (target != GL_TEXTURE_2D_ARRAY)) {
- *depth /= 2;
- }
+ const GLenum faceTarget =
+ (texObj->Target == GL_TEXTURE_CUBE_MAP ||
+ texObj->Target == GL_PROXY_TEXTURE_CUBE_MAP)
+ ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + face : texObj->Target;
+ return _mesa_get_tex_image(ctx, texObj, faceTarget, level);
}
-/**
- * Do actual memory allocation for glTexStorage1/2/3D().
- */
-static void
-setup_texstorage(struct gl_context *ctx,
- struct gl_texture_object *texObj,
- GLuint dims,
- gl_format texFormat,
- GLsizei levels, GLenum internalFormat,
- GLsizei width, GLsizei height, GLsizei depth)
+
+static GLboolean
+initialize_texture_fields(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLint levels,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum internalFormat, mesa_format texFormat)
{
const GLenum target = texObj->Target;
const GLuint numFaces = _mesa_num_tex_faces(target);
GLint level, levelWidth = width, levelHeight = height, levelDepth = depth;
GLuint face;
- assert(levels > 0);
- assert(width > 0);
- assert(height > 0);
- assert(depth > 0);
-
/* Set up all the texture object's gl_texture_images */
for (level = 0; level < levels; level++) {
for (face = 0; face < numFaces; face++) {
- const GLenum faceTarget =
- (target == GL_TEXTURE_CUBE_MAP)
- ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + face : target;
struct gl_texture_image *texImage =
- _mesa_get_tex_image(ctx, texObj, faceTarget, level);
+ get_tex_image(ctx, texObj, face, level);
if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uD", dims);
- return;
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage");
+ return GL_FALSE;
}
_mesa_init_teximage_fields(ctx, texImage,
0, internalFormat, texFormat);
}
- next_mipmap_level_size(target, &levelWidth, &levelHeight, &levelDepth);
- }
-
- assert(levelWidth > 0);
- assert(levelHeight > 0);
- assert(levelDepth > 0);
-
- if (!_mesa_is_proxy_texture(texObj->Target)) {
- /* Do actual texture memory allocation */
- if (!ctx->Driver.AllocTextureStorage(ctx, texObj, levels,
- width, height, depth)) {
- /* Reset the texture images' info to zeros.
- * Strictly speaking, we probably don't have to do this since
- * generating GL_OUT_OF_MEMORY can leave things in an undefined
- * state but this puts things in a consistent state.
- */
- for (level = 0; level < levels; level++) {
- for (face = 0; face < numFaces; face++) {
- struct gl_texture_image *texImage = texObj->Image[face][level];
- if (texImage) {
- _mesa_init_teximage_fields(ctx, texImage,
- 0, 0, 0, 0,
- GL_NONE, MESA_FORMAT_NONE);
- }
- }
- }
-
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage%uD", dims);
-
- return;
- }
-
- /* Only set this field for non-proxy texture objects */
- texObj->Immutable = GL_TRUE;
+ _mesa_next_mipmap_level_size(target, 0,
+ levelWidth, levelHeight, levelDepth,
+ &levelWidth, &levelHeight, &levelDepth);
}
+ return GL_TRUE;
}
/**
- * Clear all fields of texture object to zeros. Used for proxy texture tests.
+ * Clear all fields of texture object to zeros. Used for proxy texture tests
+ * and to clean up when a texture memory allocation fails.
*/
static void
-clear_image_fields(struct gl_context *ctx,
- GLuint dims,
- struct gl_texture_object *texObj)
+clear_texture_fields(struct gl_context *ctx,
+ struct gl_texture_object *texObj)
{
const GLenum target = texObj->Target;
const GLuint numFaces = _mesa_num_tex_faces(target);
GLint level;
GLuint face;
- for (level = 0; level < Elements(texObj->Image[0]); level++) {
+ for (level = 0; level < ARRAY_SIZE(texObj->Image[0]); level++) {
for (face = 0; face < numFaces; face++) {
- const GLenum faceTarget =
- (target == GL_TEXTURE_CUBE_MAP)
- ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + face : target;
struct gl_texture_image *texImage =
- _mesa_get_tex_image(ctx, texObj, faceTarget, level);
+ get_tex_image(ctx, texObj, face, level);
if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage%uD", dims);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage");
return;
}
- _mesa_init_teximage_fields(ctx, texImage,
- 0, 0, 0, 0, GL_NONE, MESA_FORMAT_NONE);
+ _mesa_clear_texture_image(ctx, texImage);
}
}
}
/**
- * Do error checking for calls to glTexStorage1/2/3D().
- * If an error is found, record it with _mesa_error(), unless the target
- * is a proxy texture.
- * \return GL_TRUE if any error, GL_FALSE otherwise.
+ * Update/re-validate framebuffer object.
*/
-static GLboolean
-tex_storage_error_check(struct gl_context *ctx, GLuint dims, GLenum target,
- GLsizei levels, GLenum internalformat,
- GLsizei width, GLsizei height, GLsizei depth)
+static void
+update_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
{
- struct gl_texture_object *texObj;
- GLuint maxDim;
- GLboolean legalFormat;
+ const unsigned numFaces = _mesa_num_tex_faces(texObj->Target);
+ for (int level = 0; level < ARRAY_SIZE(texObj->Image[0]); level++) {
+ for (unsigned face = 0; face < numFaces; face++)
+ _mesa_update_fbo_texture(ctx, texObj, face, level);
+ }
+}
+
+GLboolean
+_mesa_is_legal_tex_storage_format(const struct gl_context *ctx,
+ GLenum internalformat)
+{
/* check internal format - note that only sized formats are allowed */
switch (internalformat) {
case GL_ALPHA:
case GL_LUMINANCE_INTEGER_EXT:
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
/* these unsized formats are illegal */
- legalFormat = GL_FALSE;
- break;
+ return GL_FALSE;
default:
- legalFormat = _mesa_base_tex_format(ctx, internalformat) > 0;
+ return _mesa_base_tex_format(ctx, internalformat) > 0;
}
+}
- if (!legalFormat) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glTexStorage%uD(internalformat = %s)", dims,
- _mesa_lookup_enum_by_nr(internalformat));
- return GL_TRUE;
+
+/**
+ * Default ctx->Driver.AllocTextureStorage() handler.
+ *
+ * The driver can override this with a more specific implementation if it
+ * desires, but this can be used to get the texture images allocated using the
+ * usual texture image handling code. The immutability of
+ * GL_ARB_texture_storage texture layouts is handled by texObj->Immutable
+ * checks at glTexImage* time.
+ */
+GLboolean
+_mesa_AllocTextureStorage_sw(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLsizei levels, GLsizei width,
+ GLsizei height, GLsizei depth)
+{
+ const int numFaces = _mesa_num_tex_faces(texObj->Target);
+ int face;
+ int level;
+
+ (void) width;
+ (void) height;
+ (void) depth;
+
+ for (face = 0; face < numFaces; face++) {
+ for (level = 0; level < levels; level++) {
+ struct gl_texture_image *const texImage = texObj->Image[face][level];
+ if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage))
+ return GL_FALSE;
+ }
}
+ return GL_TRUE;
+}
+
+
+/**
+ * Do error checking for calls to glTexStorage1/2/3D().
+ * If an error is found, record it with _mesa_error(), unless the target
+ * is a proxy texture.
+ * \return GL_TRUE if any error, GL_FALSE otherwise.
+ */
+static GLboolean
+tex_storage_error_check(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ struct gl_memory_object *memObj,
+ GLuint dims, GLenum target,
+ GLsizei levels, GLenum internalformat,
+ GLsizei width, GLsizei height, GLsizei depth,
+ bool dsa)
+{
+ const char* suffix = dsa ? (memObj ? "tureMem" : "ture") :
+ (memObj ? "Mem" : "");
+
+ /* Legal format checking has been moved to texstorage and texturestorage in
+ * order to allow meta functions to use legacy formats. */
+
/* size check */
- if (width < 1 || height < 1 || depth < 1) {
+ if (!_mesa_valid_tex_storage_dim(width, height, depth)) {
_mesa_error(ctx, GL_INVALID_VALUE,
- "glTexStorage%uD(width, height or depth < 1)", dims);
+ "glTex%sStorage%uD(width, height or depth < 1)",
+ suffix, dims);
return GL_TRUE;
- }
+ }
- /* levels check */
- if (levels < 1 || height < 1 || depth < 1) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexStorage%uD(levels < 1)",
- dims);
- return GL_TRUE;
- }
+ if (_mesa_is_compressed_format(ctx, internalformat)) {
+ GLenum err;
+ if (!_mesa_target_can_be_compressed(ctx, target, internalformat, &err)) {
+ _mesa_error(ctx, err,
+ "glTex%sStorage%dD(internalformat = %s)", suffix, dims,
+ _mesa_enum_to_string(internalformat));
+ return GL_TRUE;
+ }
+ }
- /* target check */
- if (!legal_texobj_target(ctx, dims, target)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glTexStorage%uD(illegal target=%s)",
- dims, _mesa_lookup_enum_by_nr(target));
+ /* levels check */
+ if (levels < 1) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sStorage%uD(levels < 1)",
+ suffix, dims);
return GL_TRUE;
}
- /* check levels against maximum */
- if (levels > _mesa_max_texture_levels(ctx, target)) {
+ /* check levels against maximum (note different error than above) */
+ if (levels > (GLint) _mesa_max_texture_levels(ctx, target)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexStorage%uD(levels too large)", dims);
+ "glTex%sStorage%uD(levels too large)",
+ suffix, dims);
return GL_TRUE;
}
/* check levels against width/height/depth */
- maxDim = MAX3(width, height, depth);
- if (levels > _mesa_logbase2(maxDim) + 1) {
+ if (levels > _mesa_get_tex_max_num_levels(target, width, height, depth)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexStorage%uD(too many levels for max texture dimension)",
- dims);
+ "glTex%sStorage%uD(too many levels"
+ " for max texture dimension)",
+ suffix, dims);
return GL_TRUE;
}
/* non-default texture object check */
- texObj = _mesa_get_current_tex_object(ctx, target);
- if (!texObj || (texObj->Name == 0)) {
+ if (!_mesa_is_proxy_texture(target) && (!texObj || (texObj->Name == 0))) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glTexStorage%uD(texture object 0)", dims);
+ "glTex%sStorage%uD(texture object 0)",
+ suffix, dims);
return GL_TRUE;
}
/* Check if texObj->Immutable is set */
- if (texObj->Immutable) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glTexStorage%uD(immutable)",
- dims);
+ if (!_mesa_is_proxy_texture(target) && texObj->Immutable) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sStorage%uD(immutable)",
+ suffix, dims);
+ return GL_TRUE;
+ }
+
+ /* additional checks for depth textures */
+ if (!_mesa_legal_texture_base_format_for_target(ctx, target, internalformat)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sStorage%uD(bad target for texture)",
+ suffix, dims);
return GL_TRUE;
}
/**
- * Helper used by _mesa_TexStorage1/2/3D().
+ * Helper that does the storage allocation for _mesa_TexStorage1/2/3D()
+ * and _mesa_TextureStorage1/2/3D().
*/
-static void
-texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,
- GLsizei width, GLsizei height, GLsizei depth)
+static ALWAYS_INLINE void
+texture_storage(struct gl_context *ctx, GLuint dims,
+ struct gl_texture_object *texObj,
+ struct gl_memory_object *memObj, GLenum target,
+ GLsizei levels, GLenum internalformat, GLsizei width,
+ GLsizei height, GLsizei depth, GLuint64 offset, bool dsa,
+ bool no_error)
{
- struct gl_texture_object *texObj;
- GLboolean sizeOK;
- gl_format texFormat;
+ GLboolean sizeOK = GL_TRUE, dimensionsOK = GL_TRUE;
+ mesa_format texFormat;
+ const char* suffix = dsa ? (memObj ? "tureMem" : "ture") :
+ (memObj ? "Mem" : "");
- GET_CURRENT_CONTEXT(ctx);
+ assert(texObj);
- if (tex_storage_error_check(ctx, dims, target, levels,
- internalformat, width, height, depth)) {
- return; /* error was recorded */
+ if (!no_error) {
+ if (tex_storage_error_check(ctx, texObj, memObj, dims, target, levels,
+ internalformat, width, height, depth, dsa)) {
+ return; /* error was recorded */
+ }
}
- texObj = _mesa_get_current_tex_object(ctx, target);
- assert(texObj);
-
texFormat = _mesa_choose_texture_format(ctx, texObj, target, 0,
internalformat, GL_NONE, GL_NONE);
- assert(texFormat != MESA_FORMAT_NONE);
- sizeOK = ctx->Driver.TestProxyTexImage(ctx, target, 0, texFormat,
- width, height, depth, 0);
+ if (!no_error) {
+ /* check that width, height, depth are legal for the mipmap level */
+ dimensionsOK = _mesa_legal_texture_dimensions(ctx, target, 0,
+ width, height, depth, 0);
- if (!sizeOK) {
- if (_mesa_is_proxy_texture(texObj->Target)) {
- /* clear all image fields for [levels] */
- clear_image_fields(ctx, dims, texObj);
+ sizeOK = ctx->Driver.TestProxyTexImage(ctx, target, levels, 0, texFormat,
+ 1, width, height, depth);
+ }
+
+ if (_mesa_is_proxy_texture(target)) {
+ if (dimensionsOK && sizeOK) {
+ initialize_texture_fields(ctx, texObj, levels, width, height, depth,
+ internalformat, texFormat);
}
else {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexStorage%uD(invalid width, height or depth)",
- dims);
- return;
+ /* clear all image fields for [levels] */
+ clear_texture_fields(ctx, texObj);
}
}
else {
- setup_texstorage(ctx, texObj, dims, texFormat, levels, internalformat,
- width, height, depth);
+ if (!no_error) {
+ if (!dimensionsOK) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTex%sStorage%uD(invalid width, height or depth)",
+ suffix, dims);
+ return;
+ }
+
+ if (!sizeOK) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY,
+ "glTex%sStorage%uD(texture too large)",
+ suffix, dims);
+ return;
+ }
+ }
+
+ assert(levels > 0);
+ assert(width > 0);
+ assert(height > 0);
+ assert(depth > 0);
+
+ if (!initialize_texture_fields(ctx, texObj, levels, width, height, depth,
+ internalformat, texFormat)) {
+ return;
+ }
+
+ /* Setup the backing memory */
+ if (memObj) {
+ if (!ctx->Driver.SetTextureStorageForMemoryObject(ctx, texObj, memObj,
+ levels,
+ width, height, depth,
+ offset)) {
+
+ clear_texture_fields(ctx, texObj);
+ return;
+ }
+ }
+ else {
+ if (!ctx->Driver.AllocTextureStorage(ctx, texObj, levels,
+ width, height, depth)) {
+ /* Reset the texture images' info to zeros.
+ * Strictly speaking, we probably don't have to do this since
+ * generating GL_OUT_OF_MEMORY can leave things in an undefined
+ * state but this puts things in a consistent state.
+ */
+ clear_texture_fields(ctx, texObj);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTex%sStorage%uD",
+ suffix, dims);
+ return;
+ }
+ }
+
+ _mesa_set_texture_view_state(ctx, texObj, target, levels);
+
+ update_fbo_texture(ctx, texObj);
+ }
+}
+
+
+static void
+texture_storage_error(struct gl_context *ctx, GLuint dims,
+ struct gl_texture_object *texObj,
+ GLenum target, GLsizei levels,
+ GLenum internalformat, GLsizei width,
+ GLsizei height, GLsizei depth, bool dsa)
+{
+ texture_storage(ctx, dims, texObj, NULL, target, levels, internalformat,
+ width, height, depth, dsa, 0, false);
+}
+
+
+static void
+texture_storage_no_error(struct gl_context *ctx, GLuint dims,
+ struct gl_texture_object *texObj,
+ GLenum target, GLsizei levels,
+ GLenum internalformat, GLsizei width,
+ GLsizei height, GLsizei depth, bool dsa)
+{
+ texture_storage(ctx, dims, texObj, NULL, target, levels, internalformat,
+ width, height, depth, dsa, 0, true);
+}
+
+
+/**
+ * Helper used by _mesa_TexStorage1/2/3D().
+ */
+static void
+texstorage_error(GLuint dims, GLenum target, GLsizei levels,
+ GLenum internalformat, GLsizei width, GLsizei height,
+ GLsizei depth, const char *caller)
+{
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+
+ /* Check target. This is done here so that texture_storage
+ * can receive unsized formats.
+ */
+ if (!legal_texobj_target(ctx, dims, target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "%s(illegal target=%s)",
+ caller, _mesa_enum_to_string(target));
+ return;
+ }
+
+ if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+ _mesa_debug(ctx, "%s %s %d %s %d %d %d\n", caller,
+ _mesa_enum_to_string(target), levels,
+ _mesa_enum_to_string(internalformat),
+ width, height, depth);
+
+ /* Check the format to make sure it is sized. */
+ if (!_mesa_is_legal_tex_storage_format(ctx, internalformat)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "%s(internalformat = %s)", caller,
+ _mesa_enum_to_string(internalformat));
+ return;
+ }
+
+ texObj = _mesa_get_current_tex_object(ctx, target);
+ if (!texObj)
+ return;
+
+ texture_storage_error(ctx, dims, texObj, target, levels,
+ internalformat, width, height, depth, false);
+}
+
+
+static void
+texstorage_no_error(GLuint dims, GLenum target, GLsizei levels,
+ GLenum internalformat, GLsizei width, GLsizei height,
+ GLsizei depth)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_texture_object *texObj = _mesa_get_current_tex_object(ctx, target);
+ texture_storage_no_error(ctx, dims, texObj, target, levels,
+ internalformat, width, height, depth, false);
+}
+
+
+/**
+ * Helper used by _mesa_TextureStorage1/2/3D().
+ */
+static void
+texturestorage_error(GLuint dims, GLuint texture, GLsizei levels,
+ GLenum internalformat, GLsizei width, GLsizei height,
+ GLsizei depth, const char *caller)
+{
+ struct gl_texture_object *texObj;
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+ _mesa_debug(ctx, "%s %d %d %s %d %d %d\n",
+ caller, texture, levels,
+ _mesa_enum_to_string(internalformat),
+ width, height, depth);
+
+ /* Check the format to make sure it is sized. */
+ if (!_mesa_is_legal_tex_storage_format(ctx, internalformat)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "%s(internalformat = %s)", caller,
+ _mesa_enum_to_string(internalformat));
+ return;
}
+
+ texObj = _mesa_lookup_texture_err(ctx, texture, caller);
+ if (!texObj)
+ return;
+
+ /* Check target. This is done here so that texture_storage
+ * can receive unsized formats.
+ */
+ if (!legal_texobj_target(ctx, dims, texObj->Target)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(illegal target=%s)", caller,
+ _mesa_enum_to_string(texObj->Target));
+ return;
+ }
+
+ texture_storage_error(ctx, dims, texObj, texObj->Target,
+ levels, internalformat, width, height, depth, true);
+}
+
+
+static void
+texturestorage_no_error(GLuint dims, GLuint texture, GLsizei levels,
+ GLenum internalformat, GLsizei width, GLsizei height,
+ GLsizei depth)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_texture_object *texObj = _mesa_lookup_texture(ctx, texture);
+ texture_storage_no_error(ctx, dims, texObj, texObj->Target,
+ levels, internalformat, width, height, depth, true);
+}
+
+
+void GLAPIENTRY
+_mesa_TexStorage1D_no_error(GLenum target, GLsizei levels,
+ GLenum internalformat, GLsizei width)
+{
+ texstorage_no_error(1, target, levels, internalformat, width, 1, 1);
}
_mesa_TexStorage1D(GLenum target, GLsizei levels, GLenum internalformat,
GLsizei width)
{
- texstorage(1, target, levels, internalformat, width, 1, 1);
+ texstorage_error(1, target, levels, internalformat, width, 1, 1,
+ "glTexStorage1D");
+}
+
+
+void GLAPIENTRY
+_mesa_TexStorage2D_no_error(GLenum target, GLsizei levels,
+ GLenum internalformat, GLsizei width,
+ GLsizei height)
+{
+ texstorage_no_error(2, target, levels, internalformat, width, height, 1);
}
_mesa_TexStorage2D(GLenum target, GLsizei levels, GLenum internalformat,
GLsizei width, GLsizei height)
{
- texstorage(2, target, levels, internalformat, width, height, 1);
+ texstorage_error(2, target, levels, internalformat, width, height, 1,
+ "glTexStorage2D");
+}
+
+
+void GLAPIENTRY
+_mesa_TexStorage3D_no_error(GLenum target, GLsizei levels,
+ GLenum internalformat, GLsizei width,
+ GLsizei height, GLsizei depth)
+{
+ texstorage_no_error(3, target, levels, internalformat, width, height, depth);
}
_mesa_TexStorage3D(GLenum target, GLsizei levels, GLenum internalformat,
GLsizei width, GLsizei height, GLsizei depth)
{
- texstorage(3, target, levels, internalformat, width, height, depth);
+ texstorage_error(3, target, levels, internalformat, width, height, depth,
+ "glTexStorage3D");
}
+void GLAPIENTRY
+_mesa_TextureStorage1D_no_error(GLuint texture, GLsizei levels,
+ GLenum internalformat, GLsizei width)
+{
+ texturestorage_no_error(1, texture, levels, internalformat, width, 1, 1);
+}
-/*
- * Note: we don't support GL_EXT_direct_state_access and the spec says
- * we don't need the following functions. However, glew checks for the
- * presence of all six functions and will say that GL_ARB_texture_storage
- * is not supported if these functions are missing.
- */
+
+void GLAPIENTRY
+_mesa_TextureStorage1D(GLuint texture, GLsizei levels, GLenum internalformat,
+ GLsizei width)
+{
+ texturestorage_error(1, texture, levels, internalformat, width, 1, 1,
+ "glTextureStorage1D");
+}
+
+
+void GLAPIENTRY
+_mesa_TextureStorage2D_no_error(GLuint texture, GLsizei levels,
+ GLenum internalformat,
+ GLsizei width, GLsizei height)
+{
+ texturestorage_no_error(2, texture, levels, internalformat, width, height, 1);
+}
+
+
+void GLAPIENTRY
+_mesa_TextureStorage2D(GLuint texture, GLsizei levels,
+ GLenum internalformat,
+ GLsizei width, GLsizei height)
+{
+ texturestorage_error(2, texture, levels, internalformat, width, height, 1,
+ "glTextureStorage2D");
+}
+
+
+void GLAPIENTRY
+_mesa_TextureStorage3D_no_error(GLuint texture, GLsizei levels,
+ GLenum internalformat, GLsizei width,
+ GLsizei height, GLsizei depth)
+{
+ texturestorage_no_error(3, texture, levels, internalformat, width, height,
+ depth);
+}
+
+
+void GLAPIENTRY
+_mesa_TextureStorage3D(GLuint texture, GLsizei levels, GLenum internalformat,
+ GLsizei width, GLsizei height, GLsizei depth)
+{
+ texturestorage_error(3, texture, levels, internalformat, width, height, depth,
+ "glTextureStorage3D");
+}
void GLAPIENTRY
GLenum internalformat,
GLsizei width)
{
- /* no-op */
+ GET_CURRENT_CONTEXT(ctx);
+ /* 'texture' must always be initialized, even if the call to
+ * glTextureStorage1DEXT will generate an error.
+ */
+ if (!_mesa_lookup_or_create_texture(ctx, target, texture, false, true,
+ "glTextureStorage1DEXT"))
+ return;
+ texturestorage_error(1, texture, levels, internalformat, width, 1, 1,
+ "glTextureStorage1DEXT");
}
GLenum internalformat,
GLsizei width, GLsizei height)
{
- /* no-op */
+ GET_CURRENT_CONTEXT(ctx);
+ /* 'texture' must always be initialized, even if the call to
+ * glTextureStorage2DEXT will generate an error.
+ */
+ if (!_mesa_lookup_or_create_texture(ctx, target, texture, false, true,
+ "glTextureStorage2DEXT"))
+ return;
+ texturestorage_error(2, texture, levels, internalformat, width, height, 1,
+ "glTextureStorage2DEXT");
}
-
void GLAPIENTRY
_mesa_TextureStorage3DEXT(GLuint texture, GLenum target, GLsizei levels,
GLenum internalformat,
GLsizei width, GLsizei height, GLsizei depth)
{
- /* no-op */
+ GET_CURRENT_CONTEXT(ctx);
+ /* 'texture' must always be initialized, even if the call to
+ * glTextureStorage3DEXT will generate an error.
+ */
+ if (!_mesa_lookup_or_create_texture(ctx, target, texture, false, true,
+ "glTextureStorage3DEXT"))
+ return;
+ texturestorage_error(3, texture, levels, internalformat, width, height, depth,
+ "glTextureStorage3DEXT");
+}
+
+
+void
+_mesa_texture_storage_memory(struct gl_context *ctx, GLuint dims,
+ struct gl_texture_object *texObj,
+ struct gl_memory_object *memObj,
+ GLenum target, GLsizei levels,
+ GLenum internalformat, GLsizei width,
+ GLsizei height, GLsizei depth,
+ GLuint64 offset, bool dsa)
+{
+ assert(memObj);
+
+ texture_storage(ctx, dims, texObj, memObj, target, levels, internalformat,
+ width, height, depth, offset, dsa, false);
}