Commit 874a2c0b authored by Brian Paul's avatar Brian Paul

mesa: core support for GL_ARB_texture_buffer_object

No GLSL or driver support yet.
parent 9a77e285
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
}
}
......
......@@ -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;
......
......@@ -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]);
}
......
......@@ -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);
}
......@@ -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
......@@ -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;
}
......
......@@ -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;
......
......@@ -75,10 +75,10 @@ _mesa_init_program(struct gl_context *ctx)
ASSERT(ctx->Const.FragmentProgram.MaxAddressOffset <= (1 << INST_INDEX_BITS));
/* If this fails, increase prog_instruction::TexSrcUnit size */
ASSERT(MAX_TEXTURE_UNITS < (1 << 5));
ASSERT(MAX_TEXTURE_UNITS <= (1 << 5));
/* If this fails, increase prog_instruction::TexSrcTarget size */
ASSERT(NUM_TEXTURE_TARGETS < (1 << 3));
ASSERT(NUM_TEXTURE_TARGETS <= (1 << 3));
ctx->Program.ErrorPos = -1;
ctx->Program.ErrorString = _mesa_strdup("");
......
......@@ -87,6 +87,8 @@ gl_target_to_pipe(GLenum target)
return PIPE_TEXTURE_1D_ARRAY;
case GL_TEXTURE_2D_ARRAY_EXT:
return PIPE_TEXTURE_2D_ARRAY;
case GL_TEXTURE_BUFFER:
return PIPE_BUFFER;
default:
assert(0);
return 0;
......@@ -245,6 +247,7 @@ get_texture_dims(GLenum target)
switch (target) {
case GL_TEXTURE_1D:
case GL_TEXTURE_1D_ARRAY_EXT:
case GL_TEXTURE_BUFFER:
return 1;
case GL_TEXTURE_2D:
case GL_TEXTURE_CUBE_MAP_ARB:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment