diff options
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_draw_upload.c | 20 | ||||
-rw-r--r-- | src/mesa/drivers/dri/intel/intel_context.c | 1 | ||||
-rw-r--r-- | src/mesa/main/arrayobj.c | 108 | ||||
-rw-r--r-- | src/mesa/main/extensions.c | 2 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 2 | ||||
-rw-r--r-- | src/mesa/main/varray.c | 86 | ||||
-rw-r--r-- | src/mesa/tnl/t_draw.c | 31 |
7 files changed, 154 insertions, 96 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_draw_upload.c b/src/mesa/drivers/dri/i965/brw_draw_upload.c index 73d6dea01ee..f89c0c2ba48 100644 --- a/src/mesa/drivers/dri/i965/brw_draw_upload.c +++ b/src/mesa/drivers/dri/i965/brw_draw_upload.c @@ -156,7 +156,13 @@ static GLuint byte_types_scale[5] = { }; -static GLuint get_surface_type( GLenum type, GLuint size, GLboolean normalized ) +/** + * Given vertex array type/size/format/normalized info, return + * the appopriate hardware surface type. + * Format will be GL_RGBA or possibly GL_BGRA for GLubyte[4] color arrays. + */ +static GLuint get_surface_type( GLenum type, GLuint size, + GLenum format, GLboolean normalized ) { if (INTEL_DEBUG & DEBUG_VERTS) _mesa_printf("type %s size %d normalized %d\n", @@ -171,11 +177,20 @@ static GLuint get_surface_type( GLenum type, GLuint size, GLboolean normalized ) case GL_BYTE: return byte_types_norm[size]; case GL_UNSIGNED_INT: return uint_types_norm[size]; case GL_UNSIGNED_SHORT: return ushort_types_norm[size]; - case GL_UNSIGNED_BYTE: return ubyte_types_norm[size]; + case GL_UNSIGNED_BYTE: + if (format == GL_BGRA) { + /* See GL_EXT_vertex_array_bgra */ + assert(size == 4); + return BRW_SURFACEFORMAT_B8G8R8A8_UNORM; + } + else { + return ubyte_types_norm[size]; + } default: assert(0); return 0; } } else { + assert(format == GL_RGBA); /* sanity check */ switch (type) { case GL_DOUBLE: return double_types[size]; case GL_FLOAT: return float_types[size]; @@ -484,6 +499,7 @@ static void brw_emit_vertices(struct brw_context *brw) struct brw_vertex_element *input = enabled[i]; uint32_t format = get_surface_type(input->glarray->Type, input->glarray->Size, + input->glarray->Format, input->glarray->Normalized); uint32_t comp0 = BRW_VE1_COMPONENT_STORE_SRC; uint32_t comp1 = BRW_VE1_COMPONENT_STORE_SRC; diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c index e080594ee42..a68e2176471 100644 --- a/src/mesa/drivers/dri/intel/intel_context.c +++ b/src/mesa/drivers/dri/intel/intel_context.c @@ -416,6 +416,7 @@ static const struct dri_extension brw_extensions[] = { { "GL_EXT_shadow_funcs", NULL }, { "GL_EXT_stencil_two_side", GL_EXT_stencil_two_side_functions }, { "GL_EXT_texture_sRGB", NULL }, + { "GL_EXT_vertex_array_bgra", NULL }, { "GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions }, { "GL_ATI_texture_env_combine3", NULL }, { NULL, NULL } diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c index f3f482f8c87..b04095fd16b 100644 --- a/src/mesa/main/arrayobj.c +++ b/src/mesa/main/arrayobj.c @@ -98,6 +98,28 @@ _mesa_delete_array_object( GLcontext *ctx, struct gl_array_object *obj ) } +static void +init_array(GLcontext *ctx, + struct gl_client_array *array, GLint size, GLint type) +{ + array->Size = size; + array->Type = type; + array->Format = GL_RGBA; /* only significant for GL_EXT_vertex_array_bgra */ + array->Stride = 0; + array->StrideB = 0; + array->Ptr = NULL; + array->Enabled = GL_FALSE; + array->Normalized = GL_FALSE; +#if FEATURE_ARB_vertex_buffer_object + /* Vertex array buffers */ + array->BufferObj = ctx->Array.NullBufferObj; +#endif +} + + +/** + * Initialize a gl_array_object's arrays. + */ void _mesa_initialize_array_object( GLcontext *ctx, struct gl_array_object *obj, @@ -107,87 +129,23 @@ _mesa_initialize_array_object( GLcontext *ctx, obj->Name = name; - /* Vertex arrays */ - obj->Vertex.Size = 4; - obj->Vertex.Type = GL_FLOAT; - obj->Vertex.Stride = 0; - obj->Vertex.StrideB = 0; - obj->Vertex.Ptr = NULL; - obj->Vertex.Enabled = GL_FALSE; - obj->Normal.Type = GL_FLOAT; - obj->Normal.Stride = 0; - obj->Normal.StrideB = 0; - obj->Normal.Ptr = NULL; - obj->Normal.Enabled = GL_FALSE; - obj->Color.Size = 4; - obj->Color.Type = GL_FLOAT; - obj->Color.Stride = 0; - obj->Color.StrideB = 0; - obj->Color.Ptr = NULL; - obj->Color.Enabled = GL_FALSE; - obj->SecondaryColor.Size = 4; - obj->SecondaryColor.Type = GL_FLOAT; - obj->SecondaryColor.Stride = 0; - obj->SecondaryColor.StrideB = 0; - obj->SecondaryColor.Ptr = NULL; - obj->SecondaryColor.Enabled = GL_FALSE; - obj->FogCoord.Size = 1; - obj->FogCoord.Type = GL_FLOAT; - obj->FogCoord.Stride = 0; - obj->FogCoord.StrideB = 0; - obj->FogCoord.Ptr = NULL; - obj->FogCoord.Enabled = GL_FALSE; - obj->Index.Type = GL_FLOAT; - obj->Index.Stride = 0; - obj->Index.StrideB = 0; - obj->Index.Ptr = NULL; - obj->Index.Enabled = GL_FALSE; + /* Init the individual arrays */ + init_array(ctx, &obj->Vertex, 4, GL_FLOAT); + init_array(ctx, &obj->Normal, 3, GL_FLOAT); + init_array(ctx, &obj->Color, 4, GL_FLOAT); + init_array(ctx, &obj->SecondaryColor, 4, GL_FLOAT); + init_array(ctx, &obj->FogCoord, 1, GL_FLOAT); + init_array(ctx, &obj->Index, 1, GL_FLOAT); for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { - obj->TexCoord[i].Size = 4; - obj->TexCoord[i].Type = GL_FLOAT; - obj->TexCoord[i].Stride = 0; - obj->TexCoord[i].StrideB = 0; - obj->TexCoord[i].Ptr = NULL; - obj->TexCoord[i].Enabled = GL_FALSE; + init_array(ctx, &obj->TexCoord[i], 4, GL_FLOAT); } - obj->EdgeFlag.Stride = 0; - obj->EdgeFlag.StrideB = 0; - obj->EdgeFlag.Ptr = NULL; - obj->EdgeFlag.Enabled = GL_FALSE; + init_array(ctx, &obj->EdgeFlag, 1, GL_BOOL); for (i = 0; i < VERT_ATTRIB_MAX; i++) { - obj->VertexAttrib[i].Size = 4; - obj->VertexAttrib[i].Type = GL_FLOAT; - obj->VertexAttrib[i].Stride = 0; - obj->VertexAttrib[i].StrideB = 0; - obj->VertexAttrib[i].Ptr = NULL; - obj->VertexAttrib[i].Enabled = GL_FALSE; - obj->VertexAttrib[i].Normalized = GL_FALSE; + init_array(ctx, &obj->VertexAttrib[i], 4, GL_FLOAT); } #if FEATURE_point_size_array - obj->PointSize.Type = GL_FLOAT; - obj->PointSize.Stride = 0; - obj->PointSize.StrideB = 0; - obj->PointSize.Ptr = NULL; - obj->PointSize.Enabled = GL_FALSE; - obj->PointSize.BufferObj = ctx->Array.NullBufferObj; -#endif - -#if FEATURE_ARB_vertex_buffer_object - /* Vertex array buffers */ - obj->Vertex.BufferObj = ctx->Array.NullBufferObj; - obj->Normal.BufferObj = ctx->Array.NullBufferObj; - obj->Color.BufferObj = ctx->Array.NullBufferObj; - obj->SecondaryColor.BufferObj = ctx->Array.NullBufferObj; - obj->FogCoord.BufferObj = ctx->Array.NullBufferObj; - obj->Index.BufferObj = ctx->Array.NullBufferObj; - for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { - obj->TexCoord[i].BufferObj = ctx->Array.NullBufferObj; - } - obj->EdgeFlag.BufferObj = ctx->Array.NullBufferObj; - for (i = 0; i < VERT_ATTRIB_MAX; i++) { - obj->VertexAttrib[i].BufferObj = ctx->Array.NullBufferObj; - } + init_array(ctx, &obj->PointSize, 1, GL_FLOAT); #endif } diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 738fda34ddb..43c9d4a7885 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -129,6 +129,7 @@ static const struct { { OFF, "GL_EXT_texture_sRGB", F(EXT_texture_sRGB) }, { OFF, "GL_EXT_timer_query", F(EXT_timer_query) }, { ON, "GL_EXT_vertex_array", F(EXT_vertex_array) }, + { OFF, "GL_EXT_vertex_array_bgra", F(EXT_vertex_array_bgra) }, { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) }, { OFF, "GL_3DFX_texture_compression_FXT1", F(TDFX_texture_compression_FXT1) }, { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) }, @@ -271,6 +272,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx) #if FEATURE_EXT_texture_sRGB ctx->Extensions.EXT_texture_sRGB = GL_TRUE; #endif + ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE; ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE; ctx->Extensions.MESA_pack_invert = GL_TRUE; #if FEATURE_MESA_program_debug diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 088d45b1566..39c988f3c8f 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1675,6 +1675,7 @@ struct gl_client_array { GLint Size; /**< components per element (1,2,3,4) */ GLenum Type; /**< datatype: GL_FLOAT, GL_INT, etc */ + GLenum Format; /**< default: GL_RGBA, but may be GL_BGRA */ GLsizei Stride; /**< user-specified stride */ GLsizei StrideB; /**< actual stride in bytes */ const GLubyte *Ptr; /**< Points to array data */ @@ -2625,6 +2626,7 @@ struct gl_extensions GLboolean EXT_texture_sRGB; GLboolean EXT_timer_query; GLboolean EXT_vertex_array; + GLboolean EXT_vertex_array_bgra; GLboolean EXT_vertex_array_set; /* vendor extensions */ GLboolean APPLE_client_storage; diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index 9d9b28b5189..106252e4609 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -52,11 +52,13 @@ static void update_array(GLcontext *ctx, struct gl_client_array *array, GLbitfield dirtyBit, GLsizei elementSize, - GLint size, GLenum type, + GLint size, GLenum type, GLenum format, GLsizei stride, GLboolean normalized, const GLvoid *ptr) { + ASSERT(format == GL_RGBA || format == GL_BGRA); array->Size = size; array->Type = type; + array->Format = format; array->Stride = stride; array->StrideB = stride ? stride : elementSize; array->Normalized = normalized; @@ -132,7 +134,7 @@ _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) } update_array(ctx, &ctx->Array.ArrayObj->Vertex, _NEW_ARRAY_VERTEX, - elementSize, size, type, stride, GL_FALSE, ptr); + elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr); if (ctx->Driver.VertexPointer) ctx->Driver.VertexPointer( ctx, size, type, stride, ptr ); @@ -182,7 +184,7 @@ _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr ) } update_array(ctx, &ctx->Array.ArrayObj->Normal, _NEW_ARRAY_NORMAL, - elementSize, 3, type, stride, GL_TRUE, ptr); + elementSize, 3, type, GL_RGBA, stride, GL_TRUE, ptr); if (ctx->Driver.NormalPointer) ctx->Driver.NormalPointer( ctx, type, stride, ptr ); @@ -193,12 +195,15 @@ void GLAPIENTRY _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) { GLsizei elementSize; + GLenum format; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (size < 3 || size > 4) { - _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" ); - return; + if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) { + _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(size)"); + return; + } } if (stride < 0) { _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" ); @@ -209,6 +214,18 @@ _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) _mesa_debug(ctx, "glColorPointer( sz %d type %s stride %d )\n", size, _mesa_lookup_enum_by_nr( type ), stride); + if (size == GL_BGRA) { + if (type != GL_UNSIGNED_BYTE) { + _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(GL_BGRA/GLubyte)"); + return; + } + format = GL_BGRA; + size = 4; + } + else { + format = GL_RGBA; + } + switch (type) { case GL_BYTE: elementSize = size * sizeof(GLbyte); @@ -245,7 +262,7 @@ _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) } update_array(ctx, &ctx->Array.ArrayObj->Color, _NEW_ARRAY_COLOR0, - elementSize, size, type, stride, GL_TRUE, ptr); + elementSize, size, type, format, stride, GL_TRUE, ptr); if (ctx->Driver.ColorPointer) ctx->Driver.ColorPointer( ctx, size, type, stride, ptr ); @@ -277,7 +294,7 @@ _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr) } update_array(ctx, &ctx->Array.ArrayObj->FogCoord, _NEW_ARRAY_FOGCOORD, - elementSize, 1, type, stride, GL_FALSE, ptr); + elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr); if (ctx->Driver.FogCoordPointer) ctx->Driver.FogCoordPointer( ctx, type, stride, ptr ); @@ -318,7 +335,7 @@ _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr) } update_array(ctx, &ctx->Array.ArrayObj->Index, _NEW_ARRAY_INDEX, - elementSize, 1, type, stride, GL_FALSE, ptr); + elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr); if (ctx->Driver.IndexPointer) ctx->Driver.IndexPointer( ctx, type, stride, ptr ); @@ -330,12 +347,15 @@ _mesa_SecondaryColorPointerEXT(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) { GLsizei elementSize; + GLenum format; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (size != 3 && size != 4) { - _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)" ); - return; + if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) { + _mesa_error(ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)"); + return; + } } if (stride < 0) { _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(stride)" ); @@ -346,6 +366,18 @@ _mesa_SecondaryColorPointerEXT(GLint size, GLenum type, _mesa_debug(ctx, "glSecondaryColorPointer( sz %d type %s stride %d )\n", size, _mesa_lookup_enum_by_nr( type ), stride); + if (size == GL_BGRA) { + if (type != GL_UNSIGNED_BYTE) { + _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(GL_BGRA/GLubyte)"); + return; + } + format = GL_BGRA; + size = 4; + } + else { + format = GL_RGBA; + } + switch (type) { case GL_BYTE: elementSize = size * sizeof(GLbyte); @@ -377,7 +409,7 @@ _mesa_SecondaryColorPointerEXT(GLint size, GLenum type, } update_array(ctx, &ctx->Array.ArrayObj->SecondaryColor, _NEW_ARRAY_COLOR1, - elementSize, size, type, stride, GL_TRUE, ptr); + elementSize, size, type, format, stride, GL_TRUE, ptr); if (ctx->Driver.SecondaryColorPointer) ctx->Driver.SecondaryColorPointer( ctx, size, type, stride, ptr ); @@ -437,7 +469,7 @@ _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, update_array(ctx, &ctx->Array.ArrayObj->TexCoord[unit], _NEW_ARRAY_TEXCOORD(unit), - elementSize, size, type, stride, GL_FALSE, ptr); + elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr); if (ctx->Driver.TexCoordPointer) ctx->Driver.TexCoordPointer( ctx, size, type, stride, ptr ); @@ -456,7 +488,8 @@ _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr) } update_array(ctx, &ctx->Array.ArrayObj->EdgeFlag, _NEW_ARRAY_EDGEFLAG, - sizeof(GLboolean), 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, ptr); + sizeof(GLboolean), 1, GL_UNSIGNED_BYTE, GL_RGBA, + stride, GL_FALSE, ptr); if (ctx->Driver.EdgeFlagPointer) ctx->Driver.EdgeFlagPointer( ctx, stride, ptr ); @@ -490,7 +523,7 @@ _mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr) } update_array(ctx, &ctx->Array.ArrayObj->PointSize, _NEW_ARRAY_POINT_SIZE, - elementSize, 1, type, stride, GL_FALSE, ptr); + elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr); } @@ -546,7 +579,7 @@ _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index], _NEW_ARRAY_ATTRIB(index), - elementSize, size, type, stride, normalized, ptr); + elementSize, size, type, GL_RGBA, stride, normalized, ptr); if (ctx->Driver.VertexAttribPointer) ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr ); @@ -561,6 +594,7 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) { GLsizei elementSize; + GLenum format; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); @@ -570,8 +604,10 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type, } if (size < 1 || size > 4) { - _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size)"); - return; + if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) { + _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size)"); + return; + } } if (stride < 0) { @@ -579,6 +615,20 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type, return; } + if (size == GL_BGRA) { + if (type != GL_UNSIGNED_BYTE) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glVertexAttribPointerARB(GL_BGRA/type)"); + return; + } + format = GL_BGRA; + size = 4; + normalized = GL_TRUE; + } + else { + format = GL_RGBA; + } + /* check for valid 'type' and compute StrideB right away */ /* NOTE: more types are supported here than in the NV extension */ switch (type) { @@ -618,7 +668,7 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type, update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index], _NEW_ARRAY_ATTRIB(index), - elementSize, size, type, stride, normalized, ptr); + elementSize, size, type, GL_RGBA, stride, normalized, ptr); if (ctx->Driver.VertexAttribPointer) ctx->Driver.VertexAttribPointer(ctx, index, size, type, stride, ptr); diff --git a/src/mesa/tnl/t_draw.c b/src/mesa/tnl/t_draw.c index fd647c1f4ab..2ec65d53233 100644 --- a/src/mesa/tnl/t_draw.c +++ b/src/mesa/tnl/t_draw.c @@ -88,6 +88,29 @@ static void free_space(GLcontext *ctx) } while (0) +/** + * Convert array of BGRA/GLubyte[4] values to RGBA/float[4] + * \param ptr input/ubyte array + * \param fptr output/float array + */ +static void +convert_bgra_to_float(const struct gl_client_array *input, + const GLubyte *ptr, GLfloat *fptr, + GLuint count ) +{ + GLuint i; + assert(input->Normalized); + assert(input->Size == 4); + for (i = 0; i < count; i++) { + const GLubyte *in = (GLubyte *) ptr; /* in is in BGRA order */ + *fptr++ = UBYTE_TO_FLOAT(in[2]); /* red */ + *fptr++ = UBYTE_TO_FLOAT(in[1]); /* green */ + *fptr++ = UBYTE_TO_FLOAT(in[0]); /* blue */ + *fptr++ = UBYTE_TO_FLOAT(in[3]); /* alpha */ + ptr += input->StrideB; + } +} + /* Adjust pointer to point at first requested element, convert to * floating point, populate VB->AttribPtr[]. @@ -112,7 +135,13 @@ static void _tnl_import_array( GLcontext *ctx, CONVERT(GLbyte, BYTE_TO_FLOAT); break; case GL_UNSIGNED_BYTE: - CONVERT(GLubyte, UBYTE_TO_FLOAT); + if (input->Format == GL_BGRA) { + /* See GL_EXT_vertex_array_bgra */ + convert_bgra_to_float(input, ptr, fptr, count); + } + else { + CONVERT(GLubyte, UBYTE_TO_FLOAT); + } break; case GL_SHORT: CONVERT(GLshort, SHORT_TO_FLOAT); |