[Mesa-dev] [PATCH 1/3] mesa: implement GL_ARB_texture_buffer_range
Christoph Bumiller
e0425955 at student.tuwien.ac.at
Sat Dec 22 04:49:48 PST 2012
v2: Record texObj.BufferSize as -1 in TexBuffer(non-Range) instead
of the buffer's current size so we know we always have to use the
full size of the buffer object (i.e. even if it changes without the
user calling TexBuffer again) for the texture.
Clarify invalid offset alignment error message.
---
src/mapi/glapi/gen/ARB_texture_buffer_range.xml | 22 ++++++
src/mapi/glapi/gen/Makefile.am | 1 +
src/mapi/glapi/gen/gl_API.xml | 2 +
src/mesa/main/context.c | 1 +
src/mesa/main/extensions.c | 1 +
src/mesa/main/get.c | 1 +
src/mesa/main/get_hash_params.py | 3 +
src/mesa/main/mtypes.h | 6 ++
src/mesa/main/teximage.c | 87 ++++++++++++++++++-----
src/mesa/main/teximage.h | 4 +
src/mesa/main/texparam.c | 8 ++
11 files changed, 117 insertions(+), 19 deletions(-)
create mode 100644 src/mapi/glapi/gen/ARB_texture_buffer_range.xml
diff --git a/src/mapi/glapi/gen/ARB_texture_buffer_range.xml b/src/mapi/glapi/gen/ARB_texture_buffer_range.xml
new file mode 100644
index 0000000..2176c08
--- /dev/null
+++ b/src/mapi/glapi/gen/ARB_texture_buffer_range.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
+
+<OpenGLAPI>
+
+<category name="GL_ARB_texture_buffer_range" number="139">
+
+ <enum name="TEXTURE_BUFFER_OFFSET" value="0x919D"/>
+ <enum name="TEXTURE_BUFFER_SIZE" value="0x919E"/>
+ <enum name="TEXTURE_BUFFER_OFFSET_ALIGNMENT" value="0x919F"/>
+
+ <function name="TexBufferRange" offset="assign">
+ <param name="target" type="GLenum"/>
+ <param name="internalformat" type="GLenum"/>
+ <param name="buffer" type="GLuint"/>
+ <param name="offset" type="GLintptr"/>
+ <param name="size" type="GLsizeiptr"/>
+ </function>
+
+</category>
+
+</OpenGLAPI>
diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am
index 13943e8..4de78dd 100644
--- a/src/mapi/glapi/gen/Makefile.am
+++ b/src/mapi/glapi/gen/Makefile.am
@@ -110,6 +110,7 @@ API_XML = \
ARB_seamless_cube_map.xml \
ARB_sync.xml \
ARB_texture_buffer_object.xml \
+ ARB_texture_buffer_range.xml \
ARB_texture_compression_rgtc.xml \
ARB_texture_float.xml \
ARB_texture_rg.xml \
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index a47316a..d0479f4 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -8151,6 +8151,8 @@
<xi:include href="ARB_texture_buffer_object.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+<xi:include href="ARB_texture_buffer_range.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+
<xi:include href="ARB_texture_compression_rgtc.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
<xi:include href="ARB_texture_rg.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index fc2db12..6dfe454 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -563,6 +563,7 @@ _mesa_init_constants(struct gl_context *ctx)
ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
ctx->Const.MaxTextureBufferSize = 65536;
+ ctx->Const.TextureBufferOffsetAlignment = 1;
ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
ctx->Const.MinPointSize = MIN_POINT_SIZE;
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index 98711b3..83ed196 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -128,6 +128,7 @@ static const struct extension extension_table[] = {
{ "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), GLL, 2000 },
{ "GL_ARB_texture_buffer_object", o(ARB_texture_buffer_object), GLC, 2008 },
{ "GL_ARB_texture_buffer_object_rgb32", o(ARB_texture_buffer_object_rgb32), GLC, 2009 },
+ { "GL_ARB_texture_buffer_range", o(ARB_texture_buffer_range), GLC, 2012 },
{ "GL_ARB_texture_compression", o(dummy_true), GLL, 2000 },
{ "GL_ARB_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL, 2004 },
{ "GL_ARB_texture_cube_map", o(ARB_texture_cube_map), GLL, 1999 },
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 273a79f..ca67281 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -337,6 +337,7 @@ EXTRA_EXT(ARB_uniform_buffer_object);
EXTRA_EXT(ARB_timer_query);
EXTRA_EXT(ARB_map_buffer_alignment);
EXTRA_EXT(ARB_texture_cube_map_array);
+EXTRA_EXT(ARB_texture_buffer_range);
static const int
extra_NV_primitive_restart[] = {
diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
index ac9c79c..f1b5e7f 100644
--- a/src/mesa/main/get_hash_params.py
+++ b/src/mesa/main/get_hash_params.py
@@ -638,6 +638,9 @@ descriptor=[
[ "TEXTURE_BUFFER_FORMAT_ARB", "LOC_CUSTOM, TYPE_INT, 0, extra_texture_buffer_object" ],
[ "TEXTURE_BUFFER_ARB", "LOC_CUSTOM, TYPE_INT, 0, extra_texture_buffer_object" ],
+# GL_ARB_texture_buffer_range
+ [ "TEXTURE_BUFFER_OFFSET_ALIGNMENT", "CONTEXT_INT(Const.TextureBufferOffsetAlignment), extra_ARB_texture_buffer_range" ],
+
# GL_ARB_sampler_objects / GL 3.3
[ "SAMPLER_BINDING", "LOC_CUSTOM, TYPE_INT, GL_SAMPLER_BINDING, NO_EXTRA" ],
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 7c513a1..0391f36 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1295,6 +1295,9 @@ struct gl_texture_object
GLenum BufferObjectFormat;
/** Equivalent Mesa format for BufferObjectFormat. */
gl_format _BufferObjectFormat;
+ /** GL_ARB_texture_buffer_range */
+ GLintptr BufferOffset;
+ GLsizeiptr BufferSize;
/** GL_OES_EGL_image_external */
GLint RequiredTextureImageUnits;
@@ -2808,6 +2811,8 @@ struct gl_constants
GLfloat MaxTextureLodBias; /**< GL_EXT_texture_lod_bias */
GLuint MaxTextureBufferSize; /**< GL_ARB_texture_buffer_object */
+ GLuint TextureBufferOffsetAlignment; /**< GL_ARB_texture_buffer_range */
+
GLuint MaxArrayLockSize;
GLint SubPixelBits;
@@ -3013,6 +3018,7 @@ struct gl_extensions
GLboolean ARB_texture_border_clamp;
GLboolean ARB_texture_buffer_object;
GLboolean ARB_texture_buffer_object_rgb32;
+ GLboolean ARB_texture_buffer_range;
GLboolean ARB_texture_compression_rgtc;
GLboolean ARB_texture_cube_map;
GLboolean ARB_texture_cube_map_array;
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 7a0d944..f1ba230 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -3896,23 +3896,14 @@ validate_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat)
}
-/** GL_ARB_texture_buffer_object */
-void GLAPIENTRY
-_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
+static void
+texbufferrange(struct gl_context *ctx, GLenum target, GLenum internalFormat,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size)
{
struct gl_texture_object *texObj;
- struct gl_buffer_object *bufObj;
gl_format format;
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
- if (!(ctx->API == API_OPENGL_CORE &&
- ctx->Extensions.ARB_texture_buffer_object)) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer");
- return;
- }
-
if (target != GL_TEXTURE_BUFFER_ARB) {
_mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(target)");
return;
@@ -3925,12 +3916,6 @@ _mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
return;
}
- bufObj = _mesa_lookup_bufferobj(ctx, buffer);
- if (buffer && !bufObj) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer);
- return;
- }
-
texObj = _mesa_get_current_tex_object(ctx, target);
_mesa_lock_texture(ctx, texObj);
@@ -3938,6 +3923,70 @@ _mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
_mesa_reference_buffer_object(ctx, &texObj->BufferObject, bufObj);
texObj->BufferObjectFormat = internalFormat;
texObj->_BufferObjectFormat = format;
+ texObj->BufferOffset = offset;
+ texObj->BufferSize = size;
}
_mesa_unlock_texture(ctx, texObj);
}
+
+/** GL_ARB_texture_buffer_object */
+void GLAPIENTRY
+_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
+{
+ struct gl_buffer_object *bufObj;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (!(ctx->API == API_OPENGL_CORE &&
+ ctx->Extensions.ARB_texture_buffer_object)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer");
+ return;
+ }
+
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!bufObj && buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer);
+ return;
+ }
+
+ texbufferrange(ctx, target, internalFormat, bufObj, 0, -1);
+}
+
+/** GL_ARB_texture_buffer_range */
+void GLAPIENTRY
+_mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
+ GLintptr offset, GLsizeiptr size)
+{
+ struct gl_buffer_object *bufObj;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (!(ctx->API == API_OPENGL_CORE &&
+ ctx->Extensions.ARB_texture_buffer_range)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBufferRange");
+ return;
+ }
+
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (bufObj) {
+ if (offset < 0 ||
+ size <= 0 ||
+ (offset + size) > bufObj->Size) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTexBufferRange");
+ return;
+ }
+ if (offset % ctx->Const.TextureBufferOffsetAlignment) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glTexBufferRange(invalid offset alignment)");
+ return;
+ }
+ } else if (buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBufferRange(buffer %u)",
+ buffer);
+ return;
+ }
+
+ texbufferrange(ctx, target, internalFormat, bufObj, offset, size);
+}
diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
index 65e9333..7124cac 100644
--- a/src/mesa/main/teximage.h
+++ b/src/mesa/main/teximage.h
@@ -289,6 +289,10 @@ _mesa_CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset,
extern void GLAPIENTRY
_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer);
+extern void GLAPIENTRY
+_mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
+ GLintptr offset, GLsizeiptr size);
+
/*@}*/
diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
index ca5a21f..95039bf 100644
--- a/src/mesa/main/texparam.c
+++ b/src/mesa/main/texparam.c
@@ -1192,6 +1192,14 @@ get_tex_level_parameter_buffer(struct gl_context *ctx,
*params = _mesa_get_format_bits(texFormat, pname);
break;
+ /* GL_ARB_texture_buffer_range */
+ case GL_TEXTURE_BUFFER_OFFSET:
+ *params = texObj->BufferOffset;
+ break;
+ case GL_TEXTURE_BUFFER_SIZE:
+ *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
+ break;
+
/* GL_ARB_texture_compression */
case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
/* Always illegal for GL_TEXTURE_BUFFER */
--
1.7.3.4
More information about the mesa-dev
mailing list