aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/texstate.h
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/main/texstate.h')
-rw-r--r--mesalib/src/mesa/main/texstate.h38
1 files changed, 36 insertions, 2 deletions
diff --git a/mesalib/src/mesa/main/texstate.h b/mesalib/src/mesa/main/texstate.h
index 5cd1684f2..abc07eafb 100644
--- a/mesalib/src/mesa/main/texstate.h
+++ b/mesalib/src/mesa/main/texstate.h
@@ -33,9 +33,18 @@
#include "compiler.h"
+#include "enums.h"
+#include "macros.h"
#include "mtypes.h"
+static inline struct gl_texture_unit *
+_mesa_get_tex_unit(struct gl_context *ctx, GLuint unit)
+{
+ ASSERT(unit < Elements(ctx->Texture.Unit));
+ return &(ctx->Texture.Unit[unit]);
+}
+
/**
* Return pointer to current texture unit.
* This the texture unit set by glActiveTexture(), not glClientActiveTexture().
@@ -43,8 +52,33 @@
static inline struct gl_texture_unit *
_mesa_get_current_tex_unit(struct gl_context *ctx)
{
- ASSERT(ctx->Texture.CurrentUnit < Elements(ctx->Texture.Unit));
- return &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]);
+ return _mesa_get_tex_unit(ctx, ctx->Texture.CurrentUnit);
+}
+
+static inline GLuint
+_mesa_max_tex_unit(struct gl_context *ctx)
+{
+ /* See OpenGL spec for glActiveTexture: */
+ return MAX2(ctx->Const.MaxCombinedTextureImageUnits,
+ ctx->Const.MaxTextureCoordUnits);
+}
+
+static inline struct gl_texture_unit *
+_mesa_get_tex_unit_err(struct gl_context *ctx, GLuint unit, const char *func)
+{
+ if (unit < _mesa_max_tex_unit(ctx))
+ return _mesa_get_tex_unit(ctx, unit);
+
+ /* Note: This error is a precedent set by glBindTextures. From the GL 4.5
+ * specification (30.10.2014) Section 8.1 ("Texture Objects"):
+ *
+ * "An INVALID_OPERATION error is generated if first + count is greater
+ * than the number of texture image units supported by the
+ * implementation."
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unit=%s)", func,
+ _mesa_lookup_enum_by_nr(GL_TEXTURE0+unit));
+ return NULL;
}