summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/api_exec.c3
-rw-r--r--src/mesa/main/bufferobj.c5
-rw-r--r--src/mesa/main/context.c1
-rw-r--r--src/mesa/main/get.c36
-rw-r--r--src/mesa/main/mtypes.h10
-rw-r--r--src/mesa/main/shared.c2
-rw-r--r--src/mesa/main/teximage.c282
-rw-r--r--src/mesa/main/teximage.h5
-rw-r--r--src/mesa/main/texobj.c9
-rw-r--r--src/mesa/main/texstate.c3
10 files changed, 352 insertions, 4 deletions
diff --git a/src/mesa/main/api_exec.c b/src/mesa/main/api_exec.c
index f7603705b72..91cdea5bb98 100644
--- a/src/mesa/main/api_exec.c
+++ b/src/mesa/main/api_exec.c
@@ -726,6 +726,9 @@ _mesa_create_exec_table(void)
/* GL_NV_texture_barrier */
SET_TextureBarrierNV(exec, _mesa_TextureBarrierNV);
+ /* GL_ARB_texture_buffer_object */
+ SET_TexBufferARB(exec, _mesa_TexBuffer);
+
return exec;
}
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index c969a8da47d..78105883c97 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -93,6 +93,11 @@ get_buffer_target(struct gl_context *ctx, GLenum target)
}
break;
#endif
+ case GL_TEXTURE_BUFFER:
+ if (ctx->Extensions.ARB_texture_buffer_object) {
+ return &ctx->Texture.BufferObject;
+ }
+ break;
default:
return NULL;
}
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index ca74284ca89..9eb1eacba36 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -567,6 +567,7 @@ _mesa_init_constants(struct gl_context *ctx)
ctx->Const.MaxTextureImageUnits);
ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
+ ctx->Const.MaxTextureBufferSize = 65536;
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/get.c b/src/mesa/main/get.c
index 9090ca661e3..6ef8c8792e6 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -323,6 +323,7 @@ EXTRA_EXT(ARB_vertex_buffer_object);
EXTRA_EXT(ARB_geometry_shader4);
EXTRA_EXT(ARB_copy_buffer);
EXTRA_EXT(EXT_framebuffer_sRGB);
+EXTRA_EXT(ARB_texture_buffer_object);
static const int
extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = {
@@ -1236,6 +1237,18 @@ static const struct value_desc values[] = {
CONTEXT_INT(Const.MaxProgramTexelOffset),
extra_EXT_gpu_shader4 },
+ /* GL_ARB_texture_buffer_object */
+ { GL_MAX_TEXTURE_BUFFER_SIZE_ARB, CONTEXT_INT(Const.MaxTextureBufferSize),
+ extra_ARB_texture_buffer_object },
+ { GL_TEXTURE_BINDING_BUFFER_ARB, LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_texture_buffer_object },
+ { GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
+ TEXTURE_BUFFER_INDEX, extra_ARB_texture_buffer_object },
+ { GL_TEXTURE_BUFFER_FORMAT_ARB, LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_texture_buffer_object },
+ { GL_TEXTURE_BUFFER_ARB, LOC_CUSTOM, TYPE_INT, 0,
+ extra_ARB_texture_buffer_object },
+
/* GL 3.0 */
{ GL_NUM_EXTENSIONS, LOC_CUSTOM, TYPE_INT, 0, extra_version_30 },
{ GL_MAJOR_VERSION, CONTEXT_INT(VersionMajor), extra_version_30 },
@@ -1673,6 +1686,29 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
v->value_int = ctx->Const.FragmentProgram.MaxUniformComponents / 4;
break;
+
+ /* GL_ARB_texture_buffer_object */
+ case GL_TEXTURE_BUFFER_ARB:
+ v->value_int = ctx->Texture.BufferObject->Name;
+ break;
+ case GL_TEXTURE_BINDING_BUFFER_ARB:
+ unit = ctx->Texture.CurrentUnit;
+ v->value_int =
+ ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name;
+ break;
+ case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB:
+ {
+ struct gl_buffer_object *buf =
+ ctx->Texture.Unit[ctx->Texture.CurrentUnit]
+ .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject;
+ v->value_int = buf ? buf->Name : 0;
+ }
+ break;
+ case GL_TEXTURE_BUFFER_FORMAT_ARB:
+ v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit]
+ .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat;
+ break;
+
}
}
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 02676006a9f..13e4325ee45 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1139,6 +1139,7 @@ struct gl_stencil_attrib
*/
typedef enum
{
+ TEXTURE_BUFFER_INDEX,
TEXTURE_2D_ARRAY_INDEX,
TEXTURE_1D_ARRAY_INDEX,
TEXTURE_CUBE_INDEX,
@@ -1155,6 +1156,7 @@ typedef enum
* Used for Texture.Unit[]._ReallyEnabled flags.
*/
/*@{*/
+#define TEXTURE_BUFFER_BIT (1 << TEXTURE_BUFFER_INDEX)
#define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
#define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
#define TEXTURE_CUBE_BIT (1 << TEXTURE_CUBE_INDEX)
@@ -1348,6 +1350,10 @@ struct gl_texture_object
/** Actual texture images, indexed by [cube face] and [mipmap level] */
struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
+ /** GL_ARB_texture_buffer_object */
+ struct gl_buffer_object *BufferObject;
+ GLenum BufferObjectFormat;
+
/** GL_EXT_paletted_texture */
struct gl_color_table Palette;
@@ -1458,6 +1464,9 @@ struct gl_texture_attrib
struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
+ /** GL_ARB_texture_buffer_object */
+ struct gl_buffer_object *BufferObject;
+
/** GL_ARB_seamless_cubemap */
GLboolean CubeMapSeamless;
@@ -2630,6 +2639,7 @@ struct gl_constants
GLuint MaxTextureUnits; /**< = MIN(CoordUnits, ImageUnits) */
GLfloat MaxTextureMaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */
GLfloat MaxTextureLodBias; /**< GL_EXT_texture_lod_bias */
+ GLuint MaxTextureBufferSize; /**< GL_ARB_texture_buffer_object */
GLuint MaxArrayLockSize;
diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c
index ce9fc4de327..6604ed07d53 100644
--- a/src/mesa/main/shared.c
+++ b/src/mesa/main/shared.c
@@ -98,6 +98,7 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
/* NOTE: the order of these enums matches the TEXTURE_x_INDEX values */
static const GLenum targets[NUM_TEXTURE_TARGETS] = {
+ GL_TEXTURE_BUFFER,
GL_TEXTURE_2D_ARRAY_EXT,
GL_TEXTURE_1D_ARRAY_EXT,
GL_TEXTURE_CUBE_MAP,
@@ -106,6 +107,7 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
GL_TEXTURE_2D,
GL_TEXTURE_1D
};
+ assert(Elements(targets) == NUM_TEXTURE_TARGETS);
shared->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]);
}
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 6161eb41456..c5c454336fa 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -681,8 +681,10 @@ _mesa_delete_texture_image(struct gl_context *ctx,
GLboolean
_mesa_is_proxy_texture(GLenum target)
{
- /* NUM_TEXTURE_TARGETS should match number of terms below */
- assert(NUM_TEXTURE_TARGETS == 7);
+ /* NUM_TEXTURE_TARGETS should match number of terms below,
+ * except there's no proxy for GL_TEXTURE_BUFFER.
+ */
+ assert(NUM_TEXTURE_TARGETS == 8);
return (target == GL_PROXY_TEXTURE_1D ||
target == GL_PROXY_TEXTURE_2D ||
@@ -794,6 +796,9 @@ _mesa_select_tex_object(struct gl_context *ctx,
return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
+ case GL_TEXTURE_BUFFER:
+ return ctx->Extensions.ARB_texture_buffer_object
+ ? texUnit->CurrentTex[TEXTURE_BUFFER_INDEX] : NULL;
default:
_mesa_problem(NULL, "bad target in _mesa_select_tex_object()");
return NULL;
@@ -981,6 +986,8 @@ _mesa_max_texture_levels(struct gl_context *ctx, GLenum target)
return (ctx->Extensions.MESA_texture_array ||
ctx->Extensions.EXT_texture_array)
? ctx->Const.MaxTextureLevels : 0;
+ case GL_TEXTURE_BUFFER:
+ /* fall-through */
default:
return 0; /* bad target */
}
@@ -1017,6 +1024,8 @@ _mesa_get_texture_dimensions(GLenum target)
case GL_TEXTURE_2D_ARRAY:
case GL_PROXY_TEXTURE_2D_ARRAY:
return 3;
+ case GL_TEXTURE_BUFFER:
+ /* fall-through */
default:
_mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()",
target);
@@ -3551,3 +3560,272 @@ _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset,
width, height, depth, format, imageSize, data);
}
+
+
+/**
+ * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
+ * return the basic data type and number of components for the format.
+ * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
+ */
+static GLboolean
+get_sized_format_info(const struct gl_context *ctx, GLenum internalFormat,
+ GLenum *datatype, GLuint *components)
+{
+ switch (internalFormat) {
+ case GL_ALPHA8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 1;
+ break;
+ case GL_ALPHA16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 1;
+ break;
+ case GL_ALPHA16F_ARB:
+ *datatype = GL_HALF_FLOAT;
+ *components = 1;
+ break;
+ case GL_ALPHA32F_ARB:
+ *datatype = GL_FLOAT;
+ *components = 1;
+ break;
+ case GL_ALPHA8I_EXT:
+ *datatype = GL_BYTE;
+ *components = 1;
+ break;
+ case GL_ALPHA16I_EXT:
+ *datatype = GL_SHORT;
+ *components = 1;
+ break;
+ case GL_ALPHA32I_EXT:
+ *datatype = GL_INT;
+ *components = 1;
+ break;
+ case GL_ALPHA8UI_EXT:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 1;
+ break;
+ case GL_ALPHA16UI_EXT:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 1;
+ break;
+ case GL_ALPHA32UI_EXT:
+ *datatype = GL_UNSIGNED_INT;
+ *components = 1;
+ break;
+ case GL_LUMINANCE8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 1;
+ break;
+ case GL_LUMINANCE16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 1;
+ break;
+ case GL_LUMINANCE16F_ARB:
+ *datatype = GL_HALF_FLOAT;
+ *components = 1;
+ break;
+ case GL_LUMINANCE32F_ARB:
+ *datatype = GL_FLOAT;
+ *components = 1;
+ break;
+ case GL_LUMINANCE8I_EXT:
+ *datatype = GL_BYTE;
+ *components = 1;
+ break;
+ case GL_LUMINANCE16I_EXT:
+ *datatype = GL_SHORT;
+ *components = 1;
+ break;
+ case GL_LUMINANCE32I_EXT:
+ *datatype = GL_INT;
+ *components = 1;
+ break;
+ case GL_LUMINANCE8UI_EXT:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 1;
+ break;
+ case GL_LUMINANCE16UI_EXT:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 1;
+ break;
+ case GL_LUMINANCE32UI_EXT:
+ *datatype = GL_UNSIGNED_INT;
+ *components = 1;
+ break;
+ case GL_LUMINANCE8_ALPHA8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 2;
+ break;
+ case GL_LUMINANCE16_ALPHA16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 2;
+ break;
+ case GL_LUMINANCE_ALPHA16F_ARB:
+ *datatype = GL_HALF_FLOAT;
+ *components = 2;
+ break;
+ case GL_LUMINANCE_ALPHA32F_ARB:
+ *datatype = GL_FLOAT;
+ *components = 2;
+ break;
+ case GL_LUMINANCE_ALPHA8I_EXT:
+ *datatype = GL_BYTE;
+ *components = 2;
+ break;
+ case GL_LUMINANCE_ALPHA16I_EXT:
+ *datatype = GL_SHORT;
+ *components = 2;
+ break;
+ case GL_LUMINANCE_ALPHA32I_EXT:
+ *datatype = GL_INT;
+ *components = 2;
+ break;
+ case GL_LUMINANCE_ALPHA8UI_EXT:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 2;
+ break;
+ case GL_LUMINANCE_ALPHA16UI_EXT:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 2;
+ break;
+ case GL_LUMINANCE_ALPHA32UI_EXT:
+ *datatype = GL_UNSIGNED_INT;
+ *components = 2;
+ break;
+ case GL_INTENSITY8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 1;
+ break;
+ case GL_INTENSITY16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 1;
+ break;
+ case GL_INTENSITY16F_ARB:
+ *datatype = GL_HALF_FLOAT;
+ *components = 1;
+ break;
+ case GL_INTENSITY32F_ARB:
+ *datatype = GL_FLOAT;
+ *components = 1;
+ break;
+ case GL_INTENSITY8I_EXT:
+ *datatype = GL_BYTE;
+ *components = 1;
+ break;
+ case GL_INTENSITY16I_EXT:
+ *datatype = GL_SHORT;
+ *components = 1;
+ break;
+ case GL_INTENSITY32I_EXT:
+ *datatype = GL_INT;
+ *components = 1;
+ break;
+ case GL_INTENSITY8UI_EXT:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 1;
+ break;
+ case GL_INTENSITY16UI_EXT:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 1;
+ break;
+ case GL_INTENSITY32UI_EXT:
+ *datatype = GL_UNSIGNED_INT;
+ *components = 1;
+ break;
+ case GL_RGBA8:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 4;
+ break;
+ case GL_RGBA16:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 4;
+ break;
+ case GL_RGBA16F_ARB:
+ *datatype = GL_HALF_FLOAT;
+ *components = 4;
+ break;
+ case GL_RGBA32F_ARB:
+ *datatype = GL_FLOAT;
+ *components = 4;
+ break;
+ case GL_RGBA8I_EXT:
+ *datatype = GL_BYTE;
+ *components = 4;
+ break;
+ case GL_RGBA16I_EXT:
+ *datatype = GL_SHORT;
+ *components = 4;
+ break;
+ case GL_RGBA32I_EXT:
+ *datatype = GL_INT;
+ *components = 4;
+ break;
+ case GL_RGBA8UI_EXT:
+ *datatype = GL_UNSIGNED_BYTE;
+ *components = 4;
+ break;
+ case GL_RGBA16UI_EXT:
+ *datatype = GL_UNSIGNED_SHORT;
+ *components = 4;
+ break;
+ case GL_RGBA32UI_EXT:
+ *datatype = GL_UNSIGNED_INT;
+ *components = 4;
+ break;
+ default:
+ return GL_FALSE;
+ }
+
+ if (*datatype == GL_FLOAT && !ctx->Extensions.ARB_texture_float)
+ return GL_FALSE;
+
+ if (*datatype == GL_HALF_FLOAT && !ctx->Extensions.ARB_half_float_pixel)
+ return GL_FALSE;
+
+ return GL_TRUE;
+}
+
+
+/** GL_ARB_texture_buffer_object */
+void GLAPIENTRY
+_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
+{
+ struct gl_texture_object *texObj;
+ struct gl_buffer_object *bufObj;
+ GLenum dataType;
+ GLuint comps;
+
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+ if (!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;
+ }
+
+ if (!get_sized_format_info(ctx, internalFormat, &dataType, &comps)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(internalFormat 0x%x)",
+ internalFormat);
+ 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);
+ {
+ _mesa_reference_buffer_object(ctx, &texObj->BufferObject, bufObj);
+ texObj->BufferObjectFormat = internalFormat;
+ }
+ _mesa_unlock_texture(ctx, texObj);
+}
diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
index 252d80afc0f..19abc649898 100644
--- a/src/mesa/main/teximage.h
+++ b/src/mesa/main/teximage.h
@@ -275,6 +275,11 @@ _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
GLsizei height, GLsizei depth, GLenum format,
GLsizei imageSize, const GLvoid *data);
+
+extern void GLAPIENTRY
+_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer);
+
+
/*@}*/
#endif
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index c1e3e4dec79..61b9bc70d77 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -29,6 +29,7 @@
#include "mfeatures.h"
+#include "bufferobj.h"
#include "colortab.h"
#include "context.h"
#include "enums.h"
@@ -105,7 +106,8 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
target == GL_TEXTURE_CUBE_MAP_ARB ||
target == GL_TEXTURE_RECTANGLE_NV ||
target == GL_TEXTURE_1D_ARRAY_EXT ||
- target == GL_TEXTURE_2D_ARRAY_EXT);
+ target == GL_TEXTURE_2D_ARRAY_EXT ||
+ target == GL_TEXTURE_BUFFER);
memset(obj, 0, sizeof(*obj));
/* init the non-zero fields */
@@ -204,6 +206,8 @@ _mesa_delete_texture_object(struct gl_context *ctx,
}
}
+ _mesa_reference_buffer_object(ctx, &texObj->BufferObject, NULL);
+
/* destroy the mutex -- it may have allocated memory (eg on bsd) */
_glthread_DESTROY_MUTEX(texObj->Mutex);
@@ -299,6 +303,7 @@ valid_texture_object(const struct gl_texture_object *tex)
case GL_TEXTURE_RECTANGLE_NV:
case GL_TEXTURE_1D_ARRAY_EXT:
case GL_TEXTURE_2D_ARRAY_EXT:
+ case GL_TEXTURE_BUFFER:
return GL_TRUE;
case 0x99:
_mesa_problem(NULL, "invalid reference to a deleted texture object");
@@ -989,6 +994,8 @@ target_enum_to_index(GLenum target)
return TEXTURE_1D_ARRAY_INDEX;
case GL_TEXTURE_2D_ARRAY_EXT:
return TEXTURE_2D_ARRAY_INDEX;
+ case GL_TEXTURE_BUFFER_ARB:
+ return TEXTURE_BUFFER_INDEX;
default:
return -1;
}
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 41d531f5976..72f80508db7 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -692,7 +692,8 @@ alloc_proxy_textures( struct gl_context *ctx )
GL_TEXTURE_CUBE_MAP_ARB,
GL_TEXTURE_RECTANGLE_NV,
GL_TEXTURE_1D_ARRAY_EXT,
- GL_TEXTURE_2D_ARRAY_EXT
+ GL_TEXTURE_2D_ARRAY_EXT,
+ GL_TEXTURE_BUFFER
};
GLint tgt;