summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/texstate.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/texstate.h')
-rw-r--r--src/mesa/main/texstate.h39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h
index 5cd1684f225..2514d104b62 100644
--- a/src/mesa/main/texstate.h
+++ b/src/mesa/main/texstate.h
@@ -33,9 +33,19 @@
#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 >= 0);
+ 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 +53,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;
}