summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/texstate.h
diff options
context:
space:
mode:
authorLaura Ekstrand <[email protected]>2014-10-30 17:19:24 -0700
committerLaura Ekstrand <[email protected]>2015-01-08 11:37:28 -0800
commit77aabd8be237b68921d2e7c69fd1a0be3d36de01 (patch)
tree818af9caa403960275a6ba1e63e8c06ef9054a97 /src/mesa/main/texstate.h
parent4b381e84db5ee1a03c9b9afca2817d8bd374c0b0 (diff)
main: Added entry point for BindTextureUnit.
The following preparations were made in texstate.c and texstate.h to better facilitate the BindTextureUnit function: Dylan Noblesmith: mesa: add _mesa_get_tex_unit() mesa: factor out _mesa_max_tex_unit() This is about to appear in a lot more places, so reduce boilerplate copy paste. add _mesa_get_tex_unit_err() checking getter function Reduce boilerplate across files. Laura Ekstrand: Made note of why BindTextureUnit should throw GL_INVALID_OPERATION if the unit is out of range. Added assert(unit > 0) to _mesa_get_tex_unit. Reviewed-by: Anuj Phogat <[email protected]>
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;
}