From ca1b5515621d4ab9e90e27533fbc0fafa5cf641b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Feb 2011 18:23:23 -0700 Subject: mesa: s/mesaFormat/attFormat/ --- src/mesa/main/fbobject.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index ab6b2a9b17b..5da6a6cd16a 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -652,7 +652,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx, for (i = -2; i < (GLint) ctx->Const.MaxColorAttachments; i++) { struct gl_renderbuffer_attachment *att; GLenum f; - gl_format mesaFormat; + gl_format attFormat; /* * XXX for ARB_fbo, only check color buffers that are named by @@ -699,7 +699,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx, minHeight = MIN2(minHeight, texImg->Height); maxHeight = MAX2(maxHeight, texImg->Height); f = texImg->_BaseFormat; - mesaFormat = texImg->TexFormat; + attFormat = texImg->TexFormat; numImages++; if (!_mesa_is_legal_color_format(ctx, f) && !is_legal_depth_format(ctx, f)) { @@ -714,7 +714,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx, minHeight = MIN2(minHeight, att->Renderbuffer->Height); maxHeight = MAX2(minHeight, att->Renderbuffer->Height); f = att->Renderbuffer->InternalFormat; - mesaFormat = att->Renderbuffer->Format; + attFormat = att->Renderbuffer->Format; numImages++; } else { @@ -728,7 +728,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx, } /* check if integer color */ - fb->_IntegerColor = _mesa_is_format_integer_color(mesaFormat); + fb->_IntegerColor = _mesa_is_format_integer_color(attFormat); /* Error-check width, height, format, samples */ -- cgit v1.2.3 From b0fceae22f008f3963a392ebd57d7d2a095a5e05 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Feb 2011 18:24:20 -0700 Subject: mesa: reduce calls to _mesa_test_framebuffer_completeness() when doing glCopyTex[Sub]Image() and checking the source buffer's completeness. We only need to determine FBO completeness when the status is indeterminate. --- src/mesa/main/teximage.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index 1f2ad7f266b..d4ae6dd69d8 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -1898,7 +1898,9 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions, /* Check that the source buffer is complete */ if (ctx->ReadBuffer->Name) { - _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); + if (ctx->ReadBuffer->_Status == 0) { + _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); + } if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "glCopyTexImage%dD(invalid readbuffer)", dimensions); @@ -2000,7 +2002,9 @@ copytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions, { /* Check that the source buffer is complete */ if (ctx->ReadBuffer->Name) { - _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); + if (ctx->ReadBuffer->_Status == 0) { + _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer); + } if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) { _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "glCopyTexImage%dD(invalid readbuffer)", dimensions); -- cgit v1.2.3 From 1f9a0a4e6e5566c36c781add5f1e62af3efdfb58 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Feb 2011 18:24:25 -0700 Subject: mesa: reduce calls to _mesa_test_framebuffer_completeness() when updating/validating framebuffer state. The _Status field is set to zero when we need to recompute _Status. Otherwise, it's up to date. --- src/mesa/main/framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index 948b3b7b5a2..139a842925f 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -802,7 +802,7 @@ update_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) /* This is a user-created framebuffer. * Completeness only matters for user-created framebuffers. */ - if (fb->_Status != GL_FRAMEBUFFER_COMPLETE) { + if (fb->_Status == 0) { _mesa_test_framebuffer_completeness(ctx, fb); } } -- cgit v1.2.3 From fec26193fbc279985ba91740f654c82dbd8a7a67 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Feb 2011 18:24:25 -0700 Subject: mesa: remove some old do-nothing code --- src/mesa/main/framebuffer.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index 139a842925f..227b214a55b 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -794,9 +794,6 @@ update_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers, ctx->Color.DrawBuffer, NULL); } - if (fb->ColorReadBuffer != ctx->Pixel.ReadBuffer) { - - } } else { /* This is a user-created framebuffer. -- cgit v1.2.3 From c6991433ef343a8cbaf3f4cfacb74ddcd049c6a4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Feb 2011 18:24:25 -0700 Subject: mesa: consolidate framebuffer target lookup code --- src/mesa/main/fbobject.c | 122 +++++++++++++---------------------------------- 1 file changed, 33 insertions(+), 89 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index 5da6a6cd16a..c242e568d08 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -159,6 +159,29 @@ invalidate_framebuffer(struct gl_framebuffer *fb) } +/** + * Return the gl_framebuffer object which corresponds to the given + * framebuffer target, such as GL_DRAW_FRAMEBUFFER. + * Check support for GL_EXT_framebuffer_blit to determine if certain + * targets are legal. + * \return gl_framebuffer pointer or NULL if target is illegal + */ +static struct gl_framebuffer * +get_framebuffer_target(struct gl_context *ctx, GLenum target) +{ + switch (target) { + case GL_DRAW_FRAMEBUFFER: + return ctx->Extensions.EXT_framebuffer_blit ? ctx->DrawBuffer : NULL; + case GL_READ_FRAMEBUFFER: + return ctx->Extensions.EXT_framebuffer_blit ? ctx->ReadBuffer : NULL; + case GL_FRAMEBUFFER_EXT: + return ctx->DrawBuffer; + default: + return NULL; + } +} + + /** * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding * gl_renderbuffer_attachment object. @@ -1677,29 +1700,10 @@ _mesa_CheckFramebufferStatusEXT(GLenum target) ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0); - switch (target) { -#if FEATURE_EXT_framebuffer_blit - case GL_DRAW_FRAMEBUFFER_EXT: - if (!ctx->Extensions.EXT_framebuffer_blit) { - _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); - return 0; - } - buffer = ctx->DrawBuffer; - break; - case GL_READ_FRAMEBUFFER_EXT: - if (!ctx->Extensions.EXT_framebuffer_blit) { - _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); - return 0; - } - buffer = ctx->ReadBuffer; - break; -#endif - case GL_FRAMEBUFFER_EXT: - buffer = ctx->DrawBuffer; - break; - default: + buffer = get_framebuffer_target(ctx, target); + if (!buffer) { _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)"); - return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */ + return 0; } if (buffer->Name == 0) { @@ -1729,33 +1733,16 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target, struct gl_renderbuffer_attachment *att; struct gl_texture_object *texObj = NULL; struct gl_framebuffer *fb; - GLboolean error = GL_FALSE; ASSERT_OUTSIDE_BEGIN_END(ctx); - switch (target) { - case GL_READ_FRAMEBUFFER_EXT: - error = !ctx->Extensions.EXT_framebuffer_blit; - fb = ctx->ReadBuffer; - break; - case GL_DRAW_FRAMEBUFFER_EXT: - error = !ctx->Extensions.EXT_framebuffer_blit; - /* fall-through */ - case GL_FRAMEBUFFER_EXT: - fb = ctx->DrawBuffer; - break; - default: - error = GL_TRUE; - } - - if (error) { + fb = get_framebuffer_target(ctx, target); + if (!fb) { _mesa_error(ctx, GL_INVALID_ENUM, "glFramebufferTexture%sEXT(target=0x%x)", caller, target); return; } - ASSERT(fb); - /* check framebuffer binding */ if (fb->Name == 0) { _mesa_error(ctx, GL_INVALID_OPERATION, @@ -1936,31 +1923,9 @@ _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment, ASSERT_OUTSIDE_BEGIN_END(ctx); - switch (target) { -#if FEATURE_EXT_framebuffer_blit - case GL_DRAW_FRAMEBUFFER_EXT: - if (!ctx->Extensions.EXT_framebuffer_blit) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glFramebufferRenderbufferEXT(target)"); - return; - } - fb = ctx->DrawBuffer; - break; - case GL_READ_FRAMEBUFFER_EXT: - if (!ctx->Extensions.EXT_framebuffer_blit) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glFramebufferRenderbufferEXT(target)"); - return; - } - fb = ctx->ReadBuffer; - break; -#endif - case GL_FRAMEBUFFER_EXT: - fb = ctx->DrawBuffer; - break; - default: - _mesa_error(ctx, GL_INVALID_ENUM, - "glFramebufferRenderbufferEXT(target)"); + fb = get_framebuffer_target(ctx, target); + if (!fb) { + _mesa_error(ctx, GL_INVALID_ENUM, "glFramebufferRenderbufferEXT(target)"); return; } @@ -2040,29 +2005,8 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, ASSERT_OUTSIDE_BEGIN_END(ctx); - switch (target) { -#if FEATURE_EXT_framebuffer_blit - case GL_DRAW_FRAMEBUFFER_EXT: - if (!ctx->Extensions.EXT_framebuffer_blit) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetFramebufferAttachmentParameterivEXT(target)"); - return; - } - buffer = ctx->DrawBuffer; - break; - case GL_READ_FRAMEBUFFER_EXT: - if (!ctx->Extensions.EXT_framebuffer_blit) { - _mesa_error(ctx, GL_INVALID_ENUM, - "glGetFramebufferAttachmentParameterivEXT(target)"); - return; - } - buffer = ctx->ReadBuffer; - break; -#endif - case GL_FRAMEBUFFER_EXT: - buffer = ctx->DrawBuffer; - break; - default: + buffer = get_framebuffer_target(ctx, target); + if (!buffer) { _mesa_error(ctx, GL_INVALID_ENUM, "glGetFramebufferAttachmentParameterivEXT(target)"); return; -- cgit v1.2.3 From 9d20849516fe34bb0a430b007cef7878858cf0c7 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Feb 2011 18:24:30 -0700 Subject: mesa: remove GL_SGI_texture_color_table support It was only implemented in the swrast driver and probably not used by any applications. A modern app would use a dependent/chained texture lookup in the fragment shader. --- docs/relnotes-7.11.html | 2 + src/mesa/main/attrib.c | 11 ----- src/mesa/main/colortab.c | 99 +----------------------------------------- src/mesa/main/enable.c | 14 ------ src/mesa/main/extensions.c | 2 - src/mesa/main/get.c | 6 --- src/mesa/main/mtypes.h | 12 ----- src/mesa/main/pixel.c | 3 -- src/mesa/main/texstate.c | 3 -- src/mesa/swrast/s_texcombine.c | 5 --- 10 files changed, 3 insertions(+), 154 deletions(-) (limited to 'src/mesa/main') diff --git a/docs/relnotes-7.11.html b/docs/relnotes-7.11.html index 4b1730b17ec..277339bc4ce 100644 --- a/docs/relnotes-7.11.html +++ b/docs/relnotes-7.11.html @@ -53,6 +53,8 @@ tbd
  • The Windows MSVC project files have been removed. They haven't been maintained in quite a while. Building with SCons is an alterantive. +
  • Removed GL_SGI_texture_color_table support from swrast driver - the only +driver that implemented it.
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index 7fd1287368f..ae7f633b8d8 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -125,9 +125,6 @@ struct gl_enable_attrib GLbitfield Texture[MAX_TEXTURE_UNITS]; GLbitfield TexGen[MAX_TEXTURE_UNITS]; - /* SGI_texture_color_table */ - GLboolean TextureColorTable[MAX_TEXTURE_UNITS]; - /* GL_ARB_vertex_program / GL_NV_vertex_program */ GLboolean VertexProgram; GLboolean VertexProgramPointSize; @@ -311,7 +308,6 @@ _mesa_PushAttrib(GLbitfield mask) for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { attr->Texture[i] = ctx->Texture.Unit[i].Enabled; attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled; - attr->TextureColorTable[i] = ctx->Texture.Unit[i].ColorTableEnabled; } /* GL_NV_vertex_program */ attr->VertexProgram = ctx->VertexProgram.Enabled; @@ -657,9 +653,6 @@ pop_enable_group(struct gl_context *ctx, const struct gl_enable_attrib *enable) _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, (genEnabled & Q_BIT) ? GL_TRUE : GL_FALSE); } - - /* GL_SGI_texture_color_table */ - ctx->Texture.Unit[i].ColorTableEnabled = enable->TextureColorTable[i]; } _mesa_ActiveTextureARB(GL_TEXTURE0 + curTexUnitSave); @@ -702,10 +695,6 @@ pop_texture_group(struct gl_context *ctx, struct texture_state *texstate) (unit->Enabled & TEXTURE_2D_ARRAY_BIT) ? GL_TRUE : GL_FALSE); } - if (ctx->Extensions.SGI_texture_color_table) { - _mesa_set_enable(ctx, GL_TEXTURE_COLOR_TABLE_SGI, - unit->ColorTableEnabled); - } _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->EnvMode); _mesa_TexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, unit->EnvColor); _mesa_TexGeni(GL_S, GL_TEXTURE_GEN_MODE, unit->GenS.Mode); diff --git a/src/mesa/main/colortab.c b/src/mesa/main/colortab.c index b0ba31c732f..026fa48786d 100644 --- a/src/mesa/main/colortab.c +++ b/src/mesa/main/colortab.c @@ -300,23 +300,6 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; - case GL_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); - return; - } - table = &(texUnit->ColorTable); - scale = ctx->Pixel.TextureColorTableScale; - bias = ctx->Pixel.TextureColorTableBias; - break; - case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); - return; - } - table = &(texUnit->ProxyColorTable); - proxy = GL_TRUE; - break; default: /* try texture targets */ { @@ -435,15 +418,6 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; - case GL_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); - return; - } - table = &(texUnit->ColorTable); - scale = ctx->Pixel.TextureColorTableScale; - bias = ctx->Pixel.TextureColorTableBias; - break; default: /* try texture targets */ texObj = _mesa_select_tex_object(ctx, texUnit, target); @@ -551,13 +525,6 @@ _mesa_GetColorTable( GLenum target, GLenum format, case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; - case GL_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); - return; - } - table = &(texUnit->ColorTable); - break; default: /* try texture targets */ { @@ -666,10 +633,6 @@ _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); switch (target) { - case GL_TEXTURE_COLOR_TABLE_SGI: - scale = ctx->Pixel.TextureColorTableScale; - bias = ctx->Pixel.TextureColorTableBias; - break; default: _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)"); return; @@ -695,17 +658,7 @@ static void GLAPIENTRY _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params) { GLfloat fparams[4]; - if (pname == GL_TEXTURE_COLOR_TABLE_SGI) { - /* four values */ - fparams[0] = (GLfloat) params[0]; - fparams[1] = (GLfloat) params[1]; - fparams[2] = (GLfloat) params[2]; - fparams[3] = (GLfloat) params[3]; - } - else { - /* one values */ - fparams[0] = (GLfloat) params[0]; - } + fparams[0] = (GLfloat) params[0]; _mesa_ColorTableParameterfv(target, pname, fparams); } @@ -723,28 +676,6 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params ) case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; - case GL_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); - return; - } - table = &(texUnit->ColorTable); - if (pname == GL_COLOR_TABLE_SCALE_SGI) { - COPY_4V(params, ctx->Pixel.TextureColorTableScale); - return; - } - else if (pname == GL_COLOR_TABLE_BIAS_SGI) { - COPY_4V(params, ctx->Pixel.TextureColorTableBias); - return; - } - break; - case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); - return; - } - table = &(texUnit->ProxyColorTable); - break; default: /* try texture targets */ { @@ -808,34 +739,6 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params ) case GL_SHARED_TEXTURE_PALETTE_EXT: table = &ctx->Texture.Palette; break; - case GL_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); - return; - } - table = &(texUnit->ColorTable); - if (pname == GL_COLOR_TABLE_SCALE_SGI) { - params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0]; - params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1]; - params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2]; - params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3]; - return; - } - else if (pname == GL_COLOR_TABLE_BIAS_SGI) { - params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0]; - params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1]; - params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2]; - params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3]; - return; - } - break; - case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: - if (!ctx->Extensions.SGI_texture_color_table) { - _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); - return; - } - table = &(texUnit->ProxyColorTable); - break; default: /* Try texture targets */ { diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index ea3b8214c3b..f247092410b 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -703,15 +703,6 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state) client_state( ctx, cap, state ); return; - /* GL_SGI_texture_color_table */ - case GL_TEXTURE_COLOR_TABLE_SGI: - CHECK_EXTENSION(SGI_texture_color_table, cap); - if (ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled == state) - return; - FLUSH_VERTICES(ctx, _NEW_TEXTURE); - ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled = state; - break; - /* GL_ARB_texture_cube_map */ case GL_TEXTURE_CUBE_MAP_ARB: CHECK_EXTENSION(ARB_texture_cube_map, cap); @@ -1308,11 +1299,6 @@ _mesa_IsEnabled( GLenum cap ) return (ctx->Array.ArrayObj->PointSize.Enabled != 0); #endif - /* GL_SGI_texture_color_table */ - case GL_TEXTURE_COLOR_TABLE_SGI: - CHECK_EXTENSION(SGI_texture_color_table); - return ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled; - /* GL_ARB_texture_cube_map */ case GL_TEXTURE_CUBE_MAP_ARB: CHECK_EXTENSION(ARB_texture_cube_map); diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index b8bb2555acd..3840cdc5d36 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -290,7 +290,6 @@ static const struct extension extension_table[] = { { "GL_SGIS_texture_border_clamp", o(ARB_texture_border_clamp), GL }, { "GL_SGIS_texture_edge_clamp", o(SGIS_texture_edge_clamp), GL }, { "GL_SGIS_texture_lod", o(SGIS_texture_lod), GL }, - { "GL_SGI_texture_color_table", o(SGI_texture_color_table), GL }, { "GL_SUN_multi_draw_arrays", o(EXT_multi_draw_arrays), GL }, { 0, 0, 0 }, @@ -520,7 +519,6 @@ _mesa_enable_sw_extensions(struct gl_context *ctx) #if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program ctx->Extensions.NV_fragment_program_option = GL_TRUE; #endif - ctx->Extensions.SGI_texture_color_table = GL_TRUE; /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/ ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE; #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index fa7aa1121aa..336304c591d 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -290,7 +290,6 @@ EXTRA_EXT(NV_fragment_program); EXTRA_EXT(NV_texture_rectangle); EXTRA_EXT(EXT_stencil_two_side); EXTRA_EXT(NV_light_max_exponent); -EXTRA_EXT(SGI_texture_color_table); EXTRA_EXT(EXT_depth_bounds_test); EXTRA_EXT(ARB_depth_clamp); EXTRA_EXT(ATI_fragment_shader); @@ -911,11 +910,6 @@ static const struct value_desc values[] = { CONTEXT_MATRIX_T(ProjectionMatrixStack.Top), NO_EXTRA }, { GL_TRANSPOSE_TEXTURE_MATRIX_ARB, CONTEXT_MATRIX_T(TextureMatrixStack), NO_EXTRA }, - /* GL_SGI_texture_color_table */ - { GL_TEXTURE_COLOR_TABLE_SGI, LOC_TEXUNIT, TYPE_BOOLEAN, - offsetof(struct gl_texture_unit, ColorTableEnabled), - extra_SGI_texture_color_table }, - /* GL_EXT_secondary_color */ { GL_COLOR_SUM_EXT, CONTEXT_BOOL(Fog.ColorSumEnabled), extra_EXT_secondary_color_ARB_vertex_program }, diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index b237063a6d8..fcb06d49e9e 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1031,10 +1031,6 @@ struct gl_pixel_attrib /** glPixelZoom */ GLfloat ZoomX, ZoomY; - - /** GL_SGI_texture_color_table */ - GLfloat TextureColorTableScale[4]; /**< RGBA */ - GLfloat TextureColorTableBias[4]; /**< RGBA */ }; @@ -1435,13 +1431,6 @@ struct gl_texture_unit /** Points to highest priority, complete and enabled texture object */ struct gl_texture_object *_Current; - - /** GL_SGI_texture_color_table */ - /*@{*/ - struct gl_color_table ColorTable; - struct gl_color_table ProxyColorTable; - GLboolean ColorTableEnabled; - /*@}*/ }; @@ -2859,7 +2848,6 @@ struct gl_extensions GLboolean NV_vertex_program; GLboolean NV_vertex_program1_1; GLboolean OES_read_format; - GLboolean SGI_texture_color_table; GLboolean SGIS_generate_mipmap; GLboolean SGIS_texture_edge_clamp; GLboolean SGIS_texture_lod; diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c index 0254980b89d..08ef8fc8441 100644 --- a/src/mesa/main/pixel.c +++ b/src/mesa/main/pixel.c @@ -685,9 +685,6 @@ _mesa_init_pixel( struct gl_context *ctx ) init_pixelmap(&ctx->PixelMaps.GtoG); init_pixelmap(&ctx->PixelMaps.BtoB); init_pixelmap(&ctx->PixelMaps.AtoA); - /* GL_SGI_texture_color_table */ - ASSIGN_4V(ctx->Pixel.TextureColorTableScale, 1.0, 1.0, 1.0, 1.0); - ASSIGN_4V(ctx->Pixel.TextureColorTableBias, 0.0, 0.0, 0.0, 0.0); if (ctx->Visual.doubleBufferMode) { ctx->Pixel.ReadBuffer = GL_BACK; diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index f4d77189f29..41d531f5976 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -818,9 +818,6 @@ _mesa_free_texture_data(struct gl_context *ctx) /* Free proxy texture objects */ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]); - - for (u = 0; u < Elements(ctx->Texture.Unit); u++) - _mesa_free_colortable_data(&ctx->Texture.Unit[u].ColorTable); } diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c index 99c44413fbe..0c8cc9ff37b 100644 --- a/src/mesa/swrast/s_texcombine.c +++ b/src/mesa/swrast/s_texcombine.c @@ -713,11 +713,6 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) swrast->TextureSample[unit]( ctx, texUnit->_Current, span->end, texcoords, lambda, texels ); - /* GL_SGI_texture_color_table */ - if (texUnit->ColorTableEnabled) { - _mesa_lookup_rgba_float(&texUnit->ColorTable, span->end, texels); - } - /* GL_EXT_texture_swizzle */ if (curObj->_Swizzle != SWIZZLE_NOOP) { swizzle_texels(curObj->_Swizzle, span->end, texels); -- cgit v1.2.3 From 7d8db55148b0861e35ec6bb6323db6dad4c8f17f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Feb 2011 18:24:30 -0700 Subject: mesa: always generate error in glColorTableParameter[fi]v() These were only used by GL_SGI_texture_color_table, which is gone now. --- src/mesa/main/colortab.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/colortab.c b/src/mesa/main/colortab.c index 026fa48786d..cf34997a8d1 100644 --- a/src/mesa/main/colortab.c +++ b/src/mesa/main/colortab.c @@ -628,28 +628,10 @@ _mesa_GetColorTable( GLenum target, GLenum format, static void GLAPIENTRY _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params) { - GLfloat *scale, *bias; + /* no extensions use this function */ GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); - - switch (target) { - default: - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)"); - return; - } - - if (pname == GL_COLOR_TABLE_SCALE_SGI) { - COPY_4V(scale, params); - } - else if (pname == GL_COLOR_TABLE_BIAS_SGI) { - COPY_4V(bias, params); - } - else { - _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); - return; - } - - ctx->NewState |= _NEW_PIXEL; + _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(target)"); } @@ -657,9 +639,10 @@ _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params) static void GLAPIENTRY _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params) { - GLfloat fparams[4]; - fparams[0] = (GLfloat) params[0]; - _mesa_ColorTableParameterfv(target, pname, fparams); + /* no extensions use this function */ + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameteriv(target)"); } -- cgit v1.2.3 From b70610b9823fc7dc3672735c11be1a75fbb1a2a4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Feb 2011 18:24:35 -0700 Subject: mesa: move PBO-related functions into a new file --- src/mesa/SConscript | 1 + src/mesa/drivers/common/meta.c | 1 + src/mesa/drivers/dri/intel/intel_pixel_bitmap.c | 1 + src/mesa/drivers/dri/intel/intel_tex_image.c | 1 + src/mesa/drivers/dri/intel/intel_tex_subimage.c | 1 + src/mesa/drivers/dri/radeon/radeon_texture.c | 1 + src/mesa/drivers/dri/unichrome/via_tex.c | 1 + src/mesa/drivers/x11/xm_dd.c | 1 + src/mesa/main/bufferobj.c | 242 --------------- src/mesa/main/bufferobj.h | 41 --- src/mesa/main/colortab.c | 1 + src/mesa/main/dlist.c | 1 + src/mesa/main/drawpix.c | 1 + src/mesa/main/pbo.c | 372 ++++++++++++++++++++++++ src/mesa/main/pbo.h | 92 ++++++ src/mesa/main/pixel.c | 1 + src/mesa/main/polygon.c | 2 +- src/mesa/main/readpix.c | 1 + src/mesa/main/texgetimage.c | 1 + src/mesa/main/texstore.c | 89 +----- src/mesa/main/texstore.h | 18 -- src/mesa/sources.mak | 1 + src/mesa/state_tracker/st_cb_bitmap.c | 1 + src/mesa/state_tracker/st_cb_drawpixels.c | 1 + src/mesa/state_tracker/st_cb_readpixels.c | 1 + src/mesa/state_tracker/st_cb_texture.c | 1 + src/mesa/swrast/s_bitmap.c | 1 + src/mesa/swrast/s_drawpix.c | 1 + src/mesa/swrast/s_readpix.c | 2 +- 29 files changed, 488 insertions(+), 391 deletions(-) create mode 100644 src/mesa/main/pbo.c create mode 100644 src/mesa/main/pbo.h (limited to 'src/mesa/main') diff --git a/src/mesa/SConscript b/src/mesa/SConscript index 90fec124af9..d65750b93e2 100644 --- a/src/mesa/SConscript +++ b/src/mesa/SConscript @@ -87,6 +87,7 @@ main_sources = [ 'main/multisample.c', 'main/nvprogram.c', 'main/pack.c', + 'main/pbo.c', 'main/pixel.c', 'main/pixelstore.c', 'main/pixeltransfer.c', diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index fd12e4d0a66..2b00e8979d2 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -48,6 +48,7 @@ #include "main/macros.h" #include "main/matrix.h" #include "main/mipmap.h" +#include "main/pbo.h" #include "main/polygon.h" #include "main/readpix.h" #include "main/scissor.h" diff --git a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c index d7561ee689d..d398775906e 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c +++ b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c @@ -31,6 +31,7 @@ #include "main/colormac.h" #include "main/mtypes.h" #include "main/macros.h" +#include "main/pbo.h" #include "main/bufferobj.h" #include "main/state.h" #include "main/texobj.h" diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c index 9dba529c58d..1ffc19756e6 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_image.c +++ b/src/mesa/drivers/dri/intel/intel_tex_image.c @@ -7,6 +7,7 @@ #include "main/bufferobj.h" #include "main/context.h" #include "main/formats.h" +#include "main/pbo.h" #include "main/texcompress.h" #include "main/texstore.h" #include "main/texgetimage.h" diff --git a/src/mesa/drivers/dri/intel/intel_tex_subimage.c b/src/mesa/drivers/dri/intel/intel_tex_subimage.c index c9b992a21b9..6b7f13ff353 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_subimage.c +++ b/src/mesa/drivers/dri/intel/intel_tex_subimage.c @@ -27,6 +27,7 @@ **************************************************************************/ #include "main/mtypes.h" +#include "main/pbo.h" #include "main/texobj.h" #include "main/texstore.h" #include "main/texcompress.h" diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c index cf85a5bb572..9ec53881bb2 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texture.c +++ b/src/mesa/drivers/dri/radeon/radeon_texture.c @@ -35,6 +35,7 @@ #include "main/enums.h" #include "main/mfeatures.h" #include "main/mipmap.h" +#include "main/pbo.h" #include "main/texcompress.h" #include "main/texstore.h" #include "main/teximage.h" diff --git a/src/mesa/drivers/dri/unichrome/via_tex.c b/src/mesa/drivers/dri/unichrome/via_tex.c index 18fb8f33b9f..a2fb010e142 100644 --- a/src/mesa/drivers/dri/unichrome/via_tex.c +++ b/src/mesa/drivers/dri/unichrome/via_tex.c @@ -34,6 +34,7 @@ #include "main/context.h" #include "main/mipmap.h" #include "main/mm.h" +#include "main/pbo.h" #include "main/simple_list.h" #include "main/texobj.h" #include "main/texstore.h" diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c index b8d9e20c426..3031b7b3273 100644 --- a/src/mesa/drivers/x11/xm_dd.c +++ b/src/mesa/drivers/x11/xm_dd.c @@ -41,6 +41,7 @@ #include "main/image.h" #include "main/imports.h" #include "main/mtypes.h" +#include "main/pbo.h" #include "main/state.h" #include "main/texobj.h" #include "main/teximage.h" diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 75afae0add1..35d92616f45 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -658,248 +658,6 @@ _mesa_update_default_objects_buffer_objects(struct gl_context *ctx) } -/** - * When we're about to read pixel data out of a PBO (via glDrawPixels, - * glTexImage, etc) or write data into a PBO (via glReadPixels, - * glGetTexImage, etc) we call this function to check that we're not - * going to read out of bounds. - * - * XXX This would also be a convenient time to check that the PBO isn't - * currently mapped. Whoever calls this function should check for that. - * Remember, we can't use a PBO when it's mapped! - * - * If we're not using a PBO, this is a no-op. - * - * \param width width of image to read/write - * \param height height of image to read/write - * \param depth depth of image to read/write - * \param format format of image to read/write - * \param type datatype of image to read/write - * \param ptr the user-provided pointer/offset - * \return GL_TRUE if the PBO access is OK, GL_FALSE if the access would - * go out of bounds. - */ -GLboolean -_mesa_validate_pbo_access(GLuint dimensions, - const struct gl_pixelstore_attrib *pack, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const GLvoid *ptr) -{ - GLvoid *start, *end; - const GLubyte *sizeAddr; /* buffer size, cast to a pointer */ - - if (!_mesa_is_bufferobj(pack->BufferObj)) - return GL_TRUE; /* no PBO, OK */ - - if (pack->BufferObj->Size == 0) - /* no buffer! */ - return GL_FALSE; - - /* get address of first pixel we'll read */ - start = _mesa_image_address(dimensions, pack, ptr, width, height, - format, type, 0, 0, 0); - - /* get address just past the last pixel we'll read */ - end = _mesa_image_address(dimensions, pack, ptr, width, height, - format, type, depth-1, height-1, width); - - - sizeAddr = ((const GLubyte *) 0) + pack->BufferObj->Size; - - if ((const GLubyte *) start > sizeAddr) { - /* This will catch negative values / wrap-around */ - return GL_FALSE; - } - if ((const GLubyte *) end > sizeAddr) { - /* Image read goes beyond end of buffer */ - return GL_FALSE; - } - - /* OK! */ - return GL_TRUE; -} - - -/** - * For commands that read from a PBO (glDrawPixels, glTexImage, - * glPolygonStipple, etc), if we're reading from a PBO, map it read-only - * and return the pointer into the PBO. If we're not reading from a - * PBO, return \p src as-is. - * If non-null return, must call _mesa_unmap_pbo_source() when done. - * - * \return NULL if error, else pointer to start of data - */ -const GLvoid * -_mesa_map_pbo_source(struct gl_context *ctx, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *src) -{ - const GLubyte *buf; - - if (_mesa_is_bufferobj(unpack->BufferObj)) { - /* unpack from PBO */ - buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, - GL_READ_ONLY_ARB, - unpack->BufferObj); - if (!buf) - return NULL; - - buf = ADD_POINTERS(buf, src); - } - else { - /* unpack from normal memory */ - buf = src; - } - - return buf; -} - - -/** - * Combine PBO-read validation and mapping. - * If any GL errors are detected, they'll be recorded and NULL returned. - * \sa _mesa_validate_pbo_access - * \sa _mesa_map_pbo_source - * A call to this function should have a matching call to - * _mesa_unmap_pbo_source(). - */ -const GLvoid * -_mesa_map_validate_pbo_source(struct gl_context *ctx, - GLuint dimensions, - const struct gl_pixelstore_attrib *unpack, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const GLvoid *ptr, - const char *where) -{ - ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3); - - if (!_mesa_is_bufferobj(unpack->BufferObj)) { - /* non-PBO access: no validation to be done */ - return ptr; - } - - if (!_mesa_validate_pbo_access(dimensions, unpack, - width, height, depth, format, type, ptr)) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "%s(out of bounds PBO access)", where); - return NULL; - } - - if (_mesa_bufferobj_mapped(unpack->BufferObj)) { - /* buffer is already mapped - that's an error */ - _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where); - return NULL; - } - - ptr = _mesa_map_pbo_source(ctx, unpack, ptr); - return ptr; -} - - -/** - * Counterpart to _mesa_map_pbo_source() - */ -void -_mesa_unmap_pbo_source(struct gl_context *ctx, - const struct gl_pixelstore_attrib *unpack) -{ - ASSERT(unpack != &ctx->Pack); /* catch pack/unpack mismatch */ - if (_mesa_is_bufferobj(unpack->BufferObj)) { - ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, - unpack->BufferObj); - } -} - - -/** - * For commands that write to a PBO (glReadPixels, glGetColorTable, etc), - * if we're writing to a PBO, map it write-only and return the pointer - * into the PBO. If we're not writing to a PBO, return \p dst as-is. - * If non-null return, must call _mesa_unmap_pbo_dest() when done. - * - * \return NULL if error, else pointer to start of data - */ -void * -_mesa_map_pbo_dest(struct gl_context *ctx, - const struct gl_pixelstore_attrib *pack, - GLvoid *dest) -{ - void *buf; - - if (_mesa_is_bufferobj(pack->BufferObj)) { - /* pack into PBO */ - buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, - GL_WRITE_ONLY_ARB, - pack->BufferObj); - if (!buf) - return NULL; - - buf = ADD_POINTERS(buf, dest); - } - else { - /* pack to normal memory */ - buf = dest; - } - - return buf; -} - - -/** - * Combine PBO-write validation and mapping. - * If any GL errors are detected, they'll be recorded and NULL returned. - * \sa _mesa_validate_pbo_access - * \sa _mesa_map_pbo_dest - * A call to this function should have a matching call to - * _mesa_unmap_pbo_dest(). - */ -GLvoid * -_mesa_map_validate_pbo_dest(struct gl_context *ctx, - GLuint dimensions, - const struct gl_pixelstore_attrib *unpack, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, GLvoid *ptr, - const char *where) -{ - ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3); - - if (!_mesa_is_bufferobj(unpack->BufferObj)) { - /* non-PBO access: no validation to be done */ - return ptr; - } - - if (!_mesa_validate_pbo_access(dimensions, unpack, - width, height, depth, format, type, ptr)) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "%s(out of bounds PBO access)", where); - return NULL; - } - - if (_mesa_bufferobj_mapped(unpack->BufferObj)) { - /* buffer is already mapped - that's an error */ - _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where); - return NULL; - } - - ptr = _mesa_map_pbo_dest(ctx, unpack, ptr); - return ptr; -} - - -/** - * Counterpart to _mesa_map_pbo_dest() - */ -void -_mesa_unmap_pbo_dest(struct gl_context *ctx, - const struct gl_pixelstore_attrib *pack) -{ - ASSERT(pack != &ctx->Unpack); /* catch pack/unpack mismatch */ - if (_mesa_is_bufferobj(pack->BufferObj)) { - ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, pack->BufferObj); - } -} - - /** * Return the gl_buffer_object for the given ID. diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h index 09ccab31742..91fa073b649 100644 --- a/src/mesa/main/bufferobj.h +++ b/src/mesa/main/bufferobj.h @@ -79,47 +79,6 @@ _mesa_reference_buffer_object(struct gl_context *ctx, struct gl_buffer_object **ptr, struct gl_buffer_object *bufObj); -extern GLboolean -_mesa_validate_pbo_access(GLuint dimensions, - const struct gl_pixelstore_attrib *pack, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const GLvoid *ptr); - -extern const GLvoid * -_mesa_map_pbo_source(struct gl_context *ctx, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *src); - -extern const GLvoid * -_mesa_map_validate_pbo_source(struct gl_context *ctx, - GLuint dimensions, - const struct gl_pixelstore_attrib *unpack, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const GLvoid *ptr, - const char *where); - -extern void -_mesa_unmap_pbo_source(struct gl_context *ctx, - const struct gl_pixelstore_attrib *unpack); - -extern void * -_mesa_map_pbo_dest(struct gl_context *ctx, - const struct gl_pixelstore_attrib *pack, - GLvoid *dest); - -extern GLvoid * -_mesa_map_validate_pbo_dest(struct gl_context *ctx, - GLuint dimensions, - const struct gl_pixelstore_attrib *unpack, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, GLvoid *ptr, - const char *where); - -extern void -_mesa_unmap_pbo_dest(struct gl_context *ctx, - const struct gl_pixelstore_attrib *pack); - - extern void _mesa_init_buffer_object_functions(struct dd_function_table *driver); diff --git a/src/mesa/main/colortab.c b/src/mesa/main/colortab.c index cf34997a8d1..d0c865735ac 100644 --- a/src/mesa/main/colortab.c +++ b/src/mesa/main/colortab.c @@ -32,6 +32,7 @@ #include "mfeatures.h" #include "mtypes.h" #include "pack.h" +#include "pbo.h" #include "state.h" #include "teximage.h" #include "texstate.h" diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index 8e904c7787a..4e463dd06a1 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -54,6 +54,7 @@ #include "light.h" #include "macros.h" #include "pack.h" +#include "pbo.h" #include "queryobj.h" #include "teximage.h" #include "mtypes.h" diff --git a/src/mesa/main/drawpix.c b/src/mesa/main/drawpix.c index df4712de894..98e82ef852b 100644 --- a/src/mesa/main/drawpix.c +++ b/src/mesa/main/drawpix.c @@ -31,6 +31,7 @@ #include "feedback.h" #include "framebuffer.h" #include "mfeatures.h" +#include "pbo.h" #include "readpix.h" #include "state.h" #include "dispatch.h" diff --git a/src/mesa/main/pbo.c b/src/mesa/main/pbo.c new file mode 100644 index 00000000000..dc00d423ba9 --- /dev/null +++ b/src/mesa/main/pbo.c @@ -0,0 +1,372 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009-2011 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/** + * \file pbo.c + * \brief Functions related to Pixel Buffer Objects. + */ + + + +#include "glheader.h" +#include "bufferobj.h" +#include "image.h" +#include "imports.h" +#include "mtypes.h" +#include "pbo.h" + + + +/** + * When we're about to read pixel data out of a PBO (via glDrawPixels, + * glTexImage, etc) or write data into a PBO (via glReadPixels, + * glGetTexImage, etc) we call this function to check that we're not + * going to read out of bounds. + * + * XXX This would also be a convenient time to check that the PBO isn't + * currently mapped. Whoever calls this function should check for that. + * Remember, we can't use a PBO when it's mapped! + * + * If we're not using a PBO, this is a no-op. + * + * \param width width of image to read/write + * \param height height of image to read/write + * \param depth depth of image to read/write + * \param format format of image to read/write + * \param type datatype of image to read/write + * \param ptr the user-provided pointer/offset + * \return GL_TRUE if the PBO access is OK, GL_FALSE if the access would + * go out of bounds. + */ +GLboolean +_mesa_validate_pbo_access(GLuint dimensions, + const struct gl_pixelstore_attrib *pack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *ptr) +{ + GLvoid *start, *end; + const GLubyte *sizeAddr; /* buffer size, cast to a pointer */ + + if (!_mesa_is_bufferobj(pack->BufferObj)) + return GL_TRUE; /* no PBO, OK */ + + if (pack->BufferObj->Size == 0) + /* no buffer! */ + return GL_FALSE; + + /* get address of first pixel we'll read */ + start = _mesa_image_address(dimensions, pack, ptr, width, height, + format, type, 0, 0, 0); + + /* get address just past the last pixel we'll read */ + end = _mesa_image_address(dimensions, pack, ptr, width, height, + format, type, depth-1, height-1, width); + + + sizeAddr = ((const GLubyte *) 0) + pack->BufferObj->Size; + + if ((const GLubyte *) start > sizeAddr) { + /* This will catch negative values / wrap-around */ + return GL_FALSE; + } + if ((const GLubyte *) end > sizeAddr) { + /* Image read goes beyond end of buffer */ + return GL_FALSE; + } + + /* OK! */ + return GL_TRUE; +} + + +/** + * For commands that read from a PBO (glDrawPixels, glTexImage, + * glPolygonStipple, etc), if we're reading from a PBO, map it read-only + * and return the pointer into the PBO. If we're not reading from a + * PBO, return \p src as-is. + * If non-null return, must call _mesa_unmap_pbo_source() when done. + * + * \return NULL if error, else pointer to start of data + */ +const GLvoid * +_mesa_map_pbo_source(struct gl_context *ctx, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *src) +{ + const GLubyte *buf; + + if (_mesa_is_bufferobj(unpack->BufferObj)) { + /* unpack from PBO */ + buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, + GL_READ_ONLY_ARB, + unpack->BufferObj); + if (!buf) + return NULL; + + buf = ADD_POINTERS(buf, src); + } + else { + /* unpack from normal memory */ + buf = src; + } + + return buf; +} + + +/** + * Combine PBO-read validation and mapping. + * If any GL errors are detected, they'll be recorded and NULL returned. + * \sa _mesa_validate_pbo_access + * \sa _mesa_map_pbo_source + * A call to this function should have a matching call to + * _mesa_unmap_pbo_source(). + */ +const GLvoid * +_mesa_map_validate_pbo_source(struct gl_context *ctx, + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *ptr, + const char *where) +{ + ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3); + + if (!_mesa_is_bufferobj(unpack->BufferObj)) { + /* non-PBO access: no validation to be done */ + return ptr; + } + + if (!_mesa_validate_pbo_access(dimensions, unpack, + width, height, depth, format, type, ptr)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(out of bounds PBO access)", where); + return NULL; + } + + if (_mesa_bufferobj_mapped(unpack->BufferObj)) { + /* buffer is already mapped - that's an error */ + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where); + return NULL; + } + + ptr = _mesa_map_pbo_source(ctx, unpack, ptr); + return ptr; +} + + +/** + * Counterpart to _mesa_map_pbo_source() + */ +void +_mesa_unmap_pbo_source(struct gl_context *ctx, + const struct gl_pixelstore_attrib *unpack) +{ + ASSERT(unpack != &ctx->Pack); /* catch pack/unpack mismatch */ + if (_mesa_is_bufferobj(unpack->BufferObj)) { + ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, + unpack->BufferObj); + } +} + + +/** + * For commands that write to a PBO (glReadPixels, glGetColorTable, etc), + * if we're writing to a PBO, map it write-only and return the pointer + * into the PBO. If we're not writing to a PBO, return \p dst as-is. + * If non-null return, must call _mesa_unmap_pbo_dest() when done. + * + * \return NULL if error, else pointer to start of data + */ +void * +_mesa_map_pbo_dest(struct gl_context *ctx, + const struct gl_pixelstore_attrib *pack, + GLvoid *dest) +{ + void *buf; + + if (_mesa_is_bufferobj(pack->BufferObj)) { + /* pack into PBO */ + buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, + GL_WRITE_ONLY_ARB, + pack->BufferObj); + if (!buf) + return NULL; + + buf = ADD_POINTERS(buf, dest); + } + else { + /* pack to normal memory */ + buf = dest; + } + + return buf; +} + + +/** + * Combine PBO-write validation and mapping. + * If any GL errors are detected, they'll be recorded and NULL returned. + * \sa _mesa_validate_pbo_access + * \sa _mesa_map_pbo_dest + * A call to this function should have a matching call to + * _mesa_unmap_pbo_dest(). + */ +GLvoid * +_mesa_map_validate_pbo_dest(struct gl_context *ctx, + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLvoid *ptr, + const char *where) +{ + ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3); + + if (!_mesa_is_bufferobj(unpack->BufferObj)) { + /* non-PBO access: no validation to be done */ + return ptr; + } + + if (!_mesa_validate_pbo_access(dimensions, unpack, + width, height, depth, format, type, ptr)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(out of bounds PBO access)", where); + return NULL; + } + + if (_mesa_bufferobj_mapped(unpack->BufferObj)) { + /* buffer is already mapped - that's an error */ + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where); + return NULL; + } + + ptr = _mesa_map_pbo_dest(ctx, unpack, ptr); + return ptr; +} + + +/** + * Counterpart to _mesa_map_pbo_dest() + */ +void +_mesa_unmap_pbo_dest(struct gl_context *ctx, + const struct gl_pixelstore_attrib *pack) +{ + ASSERT(pack != &ctx->Unpack); /* catch pack/unpack mismatch */ + if (_mesa_is_bufferobj(pack->BufferObj)) { + ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, pack->BufferObj); + } +} + + + +/** + * Check if an unpack PBO is active prior to fetching a texture image. + * If so, do bounds checking and map the buffer into main memory. + * Any errors detected will be recorded. + * The caller _must_ call _mesa_unmap_teximage_pbo() too! + */ +const GLvoid * +_mesa_validate_pbo_teximage(struct gl_context *ctx, GLuint dimensions, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *pixels, + const struct gl_pixelstore_attrib *unpack, + const char *funcName) +{ + GLubyte *buf; + + if (!_mesa_is_bufferobj(unpack->BufferObj)) { + /* no PBO */ + return pixels; + } + if (!_mesa_validate_pbo_access(dimensions, unpack, width, height, depth, + format, type, pixels)) { + _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(invalid PBO access)"); + return NULL; + } + + buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, + GL_READ_ONLY_ARB, unpack->BufferObj); + if (!buf) { + _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(PBO is mapped)"); + return NULL; + } + + return ADD_POINTERS(buf, pixels); +} + + +/** + * Check if an unpack PBO is active prior to fetching a compressed texture + * image. + * If so, do bounds checking and map the buffer into main memory. + * Any errors detected will be recorded. + * The caller _must_ call _mesa_unmap_teximage_pbo() too! + */ +const GLvoid * +_mesa_validate_pbo_compressed_teximage(struct gl_context *ctx, + GLsizei imageSize, const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + const char *funcName) +{ + GLubyte *buf; + + if (!_mesa_is_bufferobj(packing->BufferObj)) { + /* not using a PBO - return pointer unchanged */ + return pixels; + } + if ((const GLubyte *) pixels + imageSize > + ((const GLubyte *) 0) + packing->BufferObj->Size) { + /* out of bounds read! */ + _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(invalid PBO access)"); + return NULL; + } + + buf = (GLubyte*) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, + GL_READ_ONLY_ARB, packing->BufferObj); + if (!buf) { + _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(PBO is mapped"); + return NULL; + } + + return ADD_POINTERS(buf, pixels); +} + + +/** + * This function must be called after either of the validate_pbo_*_teximage() + * functions. It unmaps the PBO buffer if it was mapped earlier. + */ +void +_mesa_unmap_teximage_pbo(struct gl_context *ctx, + const struct gl_pixelstore_attrib *unpack) +{ + if (_mesa_is_bufferobj(unpack->BufferObj)) { + ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, + unpack->BufferObj); + } +} + + diff --git a/src/mesa/main/pbo.h b/src/mesa/main/pbo.h new file mode 100644 index 00000000000..0cddd72ba7f --- /dev/null +++ b/src/mesa/main/pbo.h @@ -0,0 +1,92 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009-2011 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef PBO_H +#define PBO_H + + +#include "mtypes.h" + + +extern GLboolean +_mesa_validate_pbo_access(GLuint dimensions, + const struct gl_pixelstore_attrib *pack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *ptr); + +extern const GLvoid * +_mesa_map_pbo_source(struct gl_context *ctx, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *src); + +extern const GLvoid * +_mesa_map_validate_pbo_source(struct gl_context *ctx, + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *ptr, + const char *where); + +extern void +_mesa_unmap_pbo_source(struct gl_context *ctx, + const struct gl_pixelstore_attrib *unpack); + +extern void * +_mesa_map_pbo_dest(struct gl_context *ctx, + const struct gl_pixelstore_attrib *pack, + GLvoid *dest); + +extern GLvoid * +_mesa_map_validate_pbo_dest(struct gl_context *ctx, + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLvoid *ptr, + const char *where); + +extern void +_mesa_unmap_pbo_dest(struct gl_context *ctx, + const struct gl_pixelstore_attrib *pack); + + +extern const GLvoid * +_mesa_validate_pbo_teximage(struct gl_context *ctx, GLuint dimensions, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *pixels, + const struct gl_pixelstore_attrib *unpack, + const char *funcName); + +extern const GLvoid * +_mesa_validate_pbo_compressed_teximage(struct gl_context *ctx, + GLsizei imageSize, const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + const char *funcName); + +extern void +_mesa_unmap_teximage_pbo(struct gl_context *ctx, + const struct gl_pixelstore_attrib *unpack); + + +#endif diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c index 08ef8fc8441..195fa234be2 100644 --- a/src/mesa/main/pixel.c +++ b/src/mesa/main/pixel.c @@ -35,6 +35,7 @@ #include "macros.h" #include "mfeatures.h" #include "pixel.h" +#include "pbo.h" #include "mtypes.h" #include "main/dispatch.h" diff --git a/src/mesa/main/polygon.c b/src/mesa/main/polygon.c index 9c213b9b4c0..ff4232ecc39 100644 --- a/src/mesa/main/polygon.c +++ b/src/mesa/main/polygon.c @@ -30,11 +30,11 @@ #include "glheader.h" #include "imports.h" -#include "bufferobj.h" #include "context.h" #include "image.h" #include "enums.h" #include "pack.h" +#include "pbo.h" #include "polygon.h" #include "mtypes.h" diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c index 9a4f15f7279..6e09a52c88a 100644 --- a/src/mesa/main/readpix.c +++ b/src/mesa/main/readpix.c @@ -32,6 +32,7 @@ #include "formats.h" #include "image.h" #include "mtypes.h" +#include "pbo.h" #include "state.h" diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index 28829694153..21d9140c550 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -38,6 +38,7 @@ #include "mfeatures.h" #include "mtypes.h" #include "pack.h" +#include "pbo.h" #include "texgetimage.h" #include "teximage.h" diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 8a3e5f77979..cd30fa02149 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -61,6 +61,7 @@ #include "mfeatures.h" #include "mtypes.h" #include "pack.h" +#include "pbo.h" #include "imports.h" #include "pack.h" #include "texcompress.h" @@ -4200,94 +4201,6 @@ _mesa_texstore(TEXSTORE_PARAMS) } -/** - * Check if an unpack PBO is active prior to fetching a texture image. - * If so, do bounds checking and map the buffer into main memory. - * Any errors detected will be recorded. - * The caller _must_ call _mesa_unmap_teximage_pbo() too! - */ -const GLvoid * -_mesa_validate_pbo_teximage(struct gl_context *ctx, GLuint dimensions, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *unpack, - const char *funcName) -{ - GLubyte *buf; - - if (!_mesa_is_bufferobj(unpack->BufferObj)) { - /* no PBO */ - return pixels; - } - if (!_mesa_validate_pbo_access(dimensions, unpack, width, height, depth, - format, type, pixels)) { - _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(invalid PBO access)"); - return NULL; - } - - buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, - GL_READ_ONLY_ARB, unpack->BufferObj); - if (!buf) { - _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(PBO is mapped)"); - return NULL; - } - - return ADD_POINTERS(buf, pixels); -} - - -/** - * Check if an unpack PBO is active prior to fetching a compressed texture - * image. - * If so, do bounds checking and map the buffer into main memory. - * Any errors detected will be recorded. - * The caller _must_ call _mesa_unmap_teximage_pbo() too! - */ -const GLvoid * -_mesa_validate_pbo_compressed_teximage(struct gl_context *ctx, - GLsizei imageSize, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - const char *funcName) -{ - GLubyte *buf; - - if (!_mesa_is_bufferobj(packing->BufferObj)) { - /* not using a PBO - return pointer unchanged */ - return pixels; - } - if ((const GLubyte *) pixels + imageSize > - ((const GLubyte *) 0) + packing->BufferObj->Size) { - /* out of bounds read! */ - _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(invalid PBO access)"); - return NULL; - } - - buf = (GLubyte*) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, - GL_READ_ONLY_ARB, packing->BufferObj); - if (!buf) { - _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(PBO is mapped"); - return NULL; - } - - return ADD_POINTERS(buf, pixels); -} - - -/** - * This function must be called after either of the validate_pbo_*_teximage() - * functions. It unmaps the PBO buffer if it was mapped earlier. - */ -void -_mesa_unmap_teximage_pbo(struct gl_context *ctx, - const struct gl_pixelstore_attrib *unpack) -{ - if (_mesa_is_bufferobj(unpack->BufferObj)) { - ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, - unpack->BufferObj); - } -} - - /** Return texture size in bytes */ static GLuint texture_size(const struct gl_texture_image *texImage) diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h index 2f3c4e821fc..d563187098c 100644 --- a/src/mesa/main/texstore.h +++ b/src/mesa/main/texstore.h @@ -206,22 +206,4 @@ _mesa_store_compressed_texsubimage3d(struct gl_context *ctx, GLenum target, struct gl_texture_image *texImage); -extern const GLvoid * -_mesa_validate_pbo_teximage(struct gl_context *ctx, GLuint dimensions, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *unpack, - const char *funcName); - -extern const GLvoid * -_mesa_validate_pbo_compressed_teximage(struct gl_context *ctx, - GLsizei imageSize, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - const char *funcName); - -extern void -_mesa_unmap_teximage_pbo(struct gl_context *ctx, - const struct gl_pixelstore_attrib *unpack); - - #endif diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak index bdf4126cf58..a8c0bbd2b9a 100644 --- a/src/mesa/sources.mak +++ b/src/mesa/sources.mak @@ -59,6 +59,7 @@ MAIN_SOURCES = \ main/multisample.c \ main/nvprogram.c \ main/pack.c \ + main/pbo.c \ main/pixel.c \ main/pixelstore.c \ main/pixeltransfer.c \ diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 0ea5671557c..149f1ca4450 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -35,6 +35,7 @@ #include "main/bufferobj.h" #include "main/macros.h" #include "main/mfeatures.h" +#include "main/pbo.h" #include "program/program.h" #include "program/prog_print.h" diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c0da1696247..c2b4e1808f5 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -37,6 +37,7 @@ #include "main/mfeatures.h" #include "main/mtypes.h" #include "main/pack.h" +#include "main/pbo.h" #include "main/texformat.h" #include "main/texstore.h" #include "program/program.h" diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 4689a0032b7..f8da2a4d158 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -38,6 +38,7 @@ #include "main/context.h" #include "main/image.h" #include "main/pack.h" +#include "main/pbo.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 08c498b1491..c3c4246d139 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -35,6 +35,7 @@ #include "main/macros.h" #include "main/mipmap.h" #include "main/pack.h" +#include "main/pbo.h" #include "main/pixeltransfer.h" #include "main/texcompress.h" #include "main/texfetch.h" diff --git a/src/mesa/swrast/s_bitmap.c b/src/mesa/swrast/s_bitmap.c index 21488d3ba3e..18f1c1866bf 100644 --- a/src/mesa/swrast/s_bitmap.c +++ b/src/mesa/swrast/s_bitmap.c @@ -33,6 +33,7 @@ #include "main/condrender.h" #include "main/image.h" #include "main/macros.h" +#include "main/pbo.h" #include "s_context.h" #include "s_span.h" diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index 4d0666898b4..11c63457f52 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -31,6 +31,7 @@ #include "main/imports.h" #include "main/macros.h" #include "main/pack.h" +#include "main/pbo.h" #include "main/pixeltransfer.h" #include "main/state.h" diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c index 9fe0752a37f..5c8d7e9c5cf 100644 --- a/src/mesa/swrast/s_readpix.c +++ b/src/mesa/swrast/s_readpix.c @@ -24,7 +24,6 @@ #include "main/glheader.h" -#include "main/bufferobj.h" #include "main/colormac.h" #include "main/feedback.h" #include "main/formats.h" @@ -32,6 +31,7 @@ #include "main/imports.h" #include "main/macros.h" #include "main/pack.h" +#include "main/pbo.h" #include "main/state.h" #include "s_context.h" -- cgit v1.2.3 From 9c16fcc617b8c5c4db825ed290f994e535de8c65 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 1 Mar 2011 11:57:51 +1000 Subject: rgtc: shared the compressor code between signed/unsigned No idea why I didn't do it like this the first time, but share the code like other portions of mesa do using _tmp.h suffix and some #defines for the types. Signed-off-by: Dave Airlie --- src/mesa/main/texcompress_rgtc.c | 723 ++--------------------------------- src/mesa/main/texcompress_rgtc_tmp.h | 376 ++++++++++++++++++ 2 files changed, 403 insertions(+), 696 deletions(-) create mode 100644 src/mesa/main/texcompress_rgtc_tmp.h (limited to 'src/mesa/main') diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c index 1a01755f14d..2f3a0f214ad 100644 --- a/src/mesa/main/texcompress_rgtc.c +++ b/src/mesa/main/texcompress_rgtc.c @@ -46,9 +46,9 @@ #define RGTC_DEBUG 0 -static void encode_rgtc_chan_u(GLubyte *blkaddr, GLubyte srccolors[4][4], - GLint numxpixels, GLint numypixels); -static void encode_rgtc_chan_s(GLbyte *blkaddr, GLbyte srccolors[4][4], +static void unsigned_encode_rgtc_chan(GLubyte *blkaddr, GLubyte srccolors[4][4], + GLint numxpixels, GLint numypixels); +static void signed_encode_rgtc_chan(GLbyte *blkaddr, GLbyte srccolors[4][4], GLint numxpixels, GLint numypixels); static void extractsrc_u( GLubyte srcpixels[4][4], const GLchan *srcaddr, @@ -123,7 +123,7 @@ _mesa_texstore_red_rgtc1(TEXSTORE_PARAMS) if (srcWidth > i + 3) numxpixels = 4; else numxpixels = srcWidth - i; extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1); - encode_rgtc_chan_u(blkaddr, srcpixels, numxpixels, numypixels); + unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); srcaddr += numxpixels; blkaddr += 8; } @@ -177,7 +177,7 @@ _mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS) if (srcWidth > i + 3) numxpixels = 4; else numxpixels = srcWidth - i; extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1); - encode_rgtc_chan_s(blkaddr, srcpixels, numxpixels, numypixels); + signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); srcaddr += numxpixels; blkaddr += 8; } @@ -232,11 +232,11 @@ _mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS) if (srcWidth > i + 3) numxpixels = 4; else numxpixels = srcWidth - i; extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2); - encode_rgtc_chan_u(blkaddr, srcpixels, numxpixels, numypixels); + unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; extractsrc_u(srcpixels, (GLchan *)srcaddr + 1, srcWidth, numxpixels, numypixels, 2); - encode_rgtc_chan_u(blkaddr, srcpixels, numxpixels, numypixels); + unsigned_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; @@ -294,11 +294,11 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS) else numxpixels = srcWidth - i; extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2); - encode_rgtc_chan_s(blkaddr, srcpixels, numxpixels, numypixels); + signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; extractsrc_s(srcpixels, srcaddr + 1, srcWidth, numxpixels, numypixels, 2); - encode_rgtc_chan_s(blkaddr, srcpixels, numxpixels, numypixels); + signed_encode_rgtc_chan(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; srcaddr += numxpixels * 2; @@ -427,696 +427,27 @@ _mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct gl_texture_image *texImage, texel[ACOMP] = 1.0; } -static void write_rgtc_encoded_channel(GLubyte *blkaddr, - GLubyte alphabase1, - GLubyte alphabase2, - GLubyte alphaenc[16]) -{ - *blkaddr++ = alphabase1; - *blkaddr++ = alphabase2; - *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6); - *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7); - *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5); - *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6); - *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7); - *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5); -} - -static void encode_rgtc_chan_u(GLubyte *blkaddr, GLubyte srccolors[4][4], - GLint numxpixels, GLint numypixels) -{ - GLubyte alphabase[2], alphause[2]; - GLshort alphatest[2] = { 0 }; - GLuint alphablockerror1, alphablockerror2, alphablockerror3; - GLubyte i, j, aindex, acutValues[7]; - GLubyte alphaenc1[16], alphaenc2[16], alphaenc3[16]; - GLboolean alphaabsmin = GL_FALSE; - GLboolean alphaabsmax = GL_FALSE; - GLshort alphadist; - - /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */ - alphabase[0] = 0xff; alphabase[1] = 0x0; - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - if (srccolors[j][i] == 0) - alphaabsmin = GL_TRUE; - else if (srccolors[j][i] == 255) - alphaabsmax = GL_TRUE; - else { - if (srccolors[j][i] > alphabase[1]) - alphabase[1] = srccolors[j][i]; - if (srccolors[j][i] < alphabase[0]) - alphabase[0] = srccolors[j][i]; - } - } - } - - - if ((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax)) { /* one color, either max or min */ - /* shortcut here since it is a very common case (and also avoids later problems) */ - /* || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax) */ - /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */ - - *blkaddr++ = srccolors[0][0]; - blkaddr++; - *blkaddr++ = 0; - *blkaddr++ = 0; - *blkaddr++ = 0; - *blkaddr++ = 0; - *blkaddr++ = 0; - *blkaddr++ = 0; -#if RGTC_DEBUG - fprintf(stderr, "enc0 used\n"); -#endif - return; - } - - /* find best encoding for alpha0 > alpha1 */ - /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */ - alphablockerror1 = 0x0; - alphablockerror2 = 0xffffffff; - alphablockerror3 = 0xffffffff; - if (alphaabsmin) alphause[0] = 0; - else alphause[0] = alphabase[0]; - if (alphaabsmax) alphause[1] = 255; - else alphause[1] = alphabase[1]; - /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */ - for (aindex = 0; aindex < 7; aindex++) { - /* don't forget here is always rounded down */ - acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14; - } - - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - /* maybe it's overkill to have the most complicated calculation just for the error - calculation which we only need to figure out if encoding1 or encoding2 is better... */ - if (srccolors[j][i] > acutValues[0]) { - alphaenc1[4*j + i] = 0; - alphadist = srccolors[j][i] - alphause[1]; - } - else if (srccolors[j][i] > acutValues[1]) { - alphaenc1[4*j + i] = 2; - alphadist = srccolors[j][i] - (alphause[1] * 6 + alphause[0] * 1) / 7; - } - else if (srccolors[j][i] > acutValues[2]) { - alphaenc1[4*j + i] = 3; - alphadist = srccolors[j][i] - (alphause[1] * 5 + alphause[0] * 2) / 7; - } - else if (srccolors[j][i] > acutValues[3]) { - alphaenc1[4*j + i] = 4; - alphadist = srccolors[j][i] - (alphause[1] * 4 + alphause[0] * 3) / 7; - } - else if (srccolors[j][i] > acutValues[4]) { - alphaenc1[4*j + i] = 5; - alphadist = srccolors[j][i] - (alphause[1] * 3 + alphause[0] * 4) / 7; - } - else if (srccolors[j][i] > acutValues[5]) { - alphaenc1[4*j + i] = 6; - alphadist = srccolors[j][i] - (alphause[1] * 2 + alphause[0] * 5) / 7; - } - else if (srccolors[j][i] > acutValues[6]) { - alphaenc1[4*j + i] = 7; - alphadist = srccolors[j][i] - (alphause[1] * 1 + alphause[0] * 6) / 7; - } - else { - alphaenc1[4*j + i] = 1; - alphadist = srccolors[j][i] - alphause[0]; - } - alphablockerror1 += alphadist * alphadist; - } - } - -#if RGTC_DEBUG - for (i = 0; i < 16; i++) { - fprintf(stderr, "%d ", alphaenc1[i]); - } - fprintf(stderr, "cutVals "); - for (i = 0; i < 8; i++) { - fprintf(stderr, "%d ", acutValues[i]); - } - fprintf(stderr, "srcVals "); - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - fprintf(stderr, "%d ", srccolors[j][i]); - } - } - fprintf(stderr, "\n"); -#endif - - /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax - are false but try it anyway */ - if (alphablockerror1 >= 32) { - - /* don't bother if encoding is already very good, this condition should also imply - we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */ - alphablockerror2 = 0; - for (aindex = 0; aindex < 5; aindex++) { - /* don't forget here is always rounded down */ - acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10; - } - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - /* maybe it's overkill to have the most complicated calculation just for the error - calculation which we only need to figure out if encoding1 or encoding2 is better... */ - if (srccolors[j][i] == 0) { - alphaenc2[4*j + i] = 6; - alphadist = 0; - } - else if (srccolors[j][i] == 255) { - alphaenc2[4*j + i] = 7; - alphadist = 0; - } - else if (srccolors[j][i] <= acutValues[0]) { - alphaenc2[4*j + i] = 0; - alphadist = srccolors[j][i] - alphabase[0]; - } - else if (srccolors[j][i] <= acutValues[1]) { - alphaenc2[4*j + i] = 2; - alphadist = srccolors[j][i] - (alphabase[0] * 4 + alphabase[1] * 1) / 5; - } - else if (srccolors[j][i] <= acutValues[2]) { - alphaenc2[4*j + i] = 3; - alphadist = srccolors[j][i] - (alphabase[0] * 3 + alphabase[1] * 2) / 5; - } - else if (srccolors[j][i] <= acutValues[3]) { - alphaenc2[4*j + i] = 4; - alphadist = srccolors[j][i] - (alphabase[0] * 2 + alphabase[1] * 3) / 5; - } - else if (srccolors[j][i] <= acutValues[4]) { - alphaenc2[4*j + i] = 5; - alphadist = srccolors[j][i] - (alphabase[0] * 1 + alphabase[1] * 4) / 5; - } - else { - alphaenc2[4*j + i] = 1; - alphadist = srccolors[j][i] - alphabase[1]; - } - alphablockerror2 += alphadist * alphadist; - } - } - - - /* skip this if the error is already very small - this encoding is MUCH better on average than #2 though, but expensive! */ - if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) { - GLshort blockerrlin1 = 0; - GLshort blockerrlin2 = 0; - GLubyte nralphainrangelow = 0; - GLubyte nralphainrangehigh = 0; - alphatest[0] = 0xff; - alphatest[1] = 0x0; - /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */ - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - if ((srccolors[j][i] > alphatest[1]) && (srccolors[j][i] < (255 -(alphabase[1] - alphabase[0]) / 28))) - alphatest[1] = srccolors[j][i]; - if ((srccolors[j][i] < alphatest[0]) && (srccolors[j][i] > (alphabase[1] - alphabase[0]) / 28)) - alphatest[0] = srccolors[j][i]; - } - } - /* shouldn't happen too often, don't really care about those degenerated cases */ - if (alphatest[1] <= alphatest[0]) { - alphatest[0] = 1; - alphatest[1] = 254; - } - for (aindex = 0; aindex < 5; aindex++) { - /* don't forget here is always rounded down */ - acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10; - } - - /* find the "average" difference between the alpha values and the next encoded value. - This is then used to calculate new base values. - Should there be some weighting, i.e. those values closer to alphatest[x] have more weight, - since they will see more improvement, and also because the values in the middle are somewhat - likely to get no improvement at all (because the base values might move in different directions)? - OTOH it would mean the values in the middle are even less likely to get an improvement - */ - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - if (srccolors[j][i] <= alphatest[0] / 2) { - } - else if (srccolors[j][i] > ((255 + alphatest[1]) / 2)) { - } - else if (srccolors[j][i] <= acutValues[0]) { - blockerrlin1 += (srccolors[j][i] - alphatest[0]); - nralphainrangelow += 1; - } - else if (srccolors[j][i] <= acutValues[1]) { - blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5); - blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5); - nralphainrangelow += 1; - nralphainrangehigh += 1; - } - else if (srccolors[j][i] <= acutValues[2]) { - blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5); - blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5); - nralphainrangelow += 1; - nralphainrangehigh += 1; - } - else if (srccolors[j][i] <= acutValues[3]) { - blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5); - blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5); - nralphainrangelow += 1; - nralphainrangehigh += 1; - } - else if (srccolors[j][i] <= acutValues[4]) { - blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5); - blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5); - nralphainrangelow += 1; - nralphainrangehigh += 1; - } - else { - blockerrlin2 += (srccolors[j][i] - alphatest[1]); - nralphainrangehigh += 1; - } - } - } - /* shouldn't happen often, needed to avoid div by zero */ - if (nralphainrangelow == 0) nralphainrangelow = 1; - if (nralphainrangehigh == 0) nralphainrangehigh = 1; - alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow); -#if RGTC_DEBUG - fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow); - fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh); -#endif - /* again shouldn't really happen often... */ - if (alphatest[0] < 0) { - alphatest[0] = 0; - } - alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh); - if (alphatest[1] > 255) { - alphatest[1] = 255; - } - - alphablockerror3 = 0; - for (aindex = 0; aindex < 5; aindex++) { - /* don't forget here is always rounded down */ - acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10; - } - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - /* maybe it's overkill to have the most complicated calculation just for the error - calculation which we only need to figure out if encoding1 or encoding2 is better... */ - if (srccolors[j][i] <= alphatest[0] / 2) { - alphaenc3[4*j + i] = 6; - alphadist = srccolors[j][i]; - } - else if (srccolors[j][i] > ((255 + alphatest[1]) / 2)) { - alphaenc3[4*j + i] = 7; - alphadist = 255 - srccolors[j][i]; - } - else if (srccolors[j][i] <= acutValues[0]) { - alphaenc3[4*j + i] = 0; - alphadist = srccolors[j][i] - alphatest[0]; - } - else if (srccolors[j][i] <= acutValues[1]) { - alphaenc3[4*j + i] = 2; - alphadist = srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5; - } - else if (srccolors[j][i] <= acutValues[2]) { - alphaenc3[4*j + i] = 3; - alphadist = srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5; - } - else if (srccolors[j][i] <= acutValues[3]) { - alphaenc3[4*j + i] = 4; - alphadist = srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5; - } - else if (srccolors[j][i] <= acutValues[4]) { - alphaenc3[4*j + i] = 5; - alphadist = srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5; - } - else { - alphaenc3[4*j + i] = 1; - alphadist = srccolors[j][i] - alphatest[1]; - } - alphablockerror3 += alphadist * alphadist; - } - } - } - } - /* write the alpha values and encoding back. */ - if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) { -#if RGTC_DEBUG - if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1); -#endif - write_rgtc_encoded_channel( blkaddr, alphause[1], alphause[0], alphaenc1 ); - } - else if (alphablockerror2 <= alphablockerror3) { -#if RGTC_DEBUG - if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2); -#endif - write_rgtc_encoded_channel( blkaddr, alphabase[0], alphabase[1], alphaenc2 ); - } - else { -#if RGTC_DEBUG - fprintf(stderr, "enc3 used, error %d\n", alphablockerror3); -#endif - write_rgtc_encoded_channel( blkaddr, (GLubyte)alphatest[0], (GLubyte)alphatest[1], alphaenc3 ); - } -} - - -static void write_rgtc_encoded_channel_s(GLbyte *blkaddr, - GLbyte alphabase1, - GLbyte alphabase2, - GLbyte alphaenc[16]) -{ - *blkaddr++ = alphabase1; - *blkaddr++ = alphabase2; - *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6); - *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7); - *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5); - *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6); - *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7); - *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5); -} - -static void encode_rgtc_chan_s(GLbyte *blkaddr, GLbyte srccolors[4][4], - GLint numxpixels, GLint numypixels) -{ - GLbyte alphabase[2], alphause[2]; - GLshort alphatest[2] = { 0 }; - GLuint alphablockerror1, alphablockerror2, alphablockerror3; - GLbyte i, j, aindex, acutValues[7]; - GLbyte alphaenc1[16], alphaenc2[16], alphaenc3[16]; - GLboolean alphaabsmin = GL_FALSE; - GLboolean alphaabsmax = GL_FALSE; - GLshort alphadist; - - /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */ - alphabase[0] = 0xff; alphabase[1] = 0x0; - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - if (srccolors[j][i] == 0) - alphaabsmin = GL_TRUE; - else if (srccolors[j][i] == 255) - alphaabsmax = GL_TRUE; - else { - if (srccolors[j][i] > alphabase[1]) - alphabase[1] = srccolors[j][i]; - if (srccolors[j][i] < alphabase[0]) - alphabase[0] = srccolors[j][i]; - } - } - } - - - if ((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax)) { /* one color, either max or min */ - /* shortcut here since it is a very common case (and also avoids later problems) */ - /* || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax) */ - /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */ - - *blkaddr++ = srccolors[0][0]; - blkaddr++; - *blkaddr++ = 0; - *blkaddr++ = 0; - *blkaddr++ = 0; - *blkaddr++ = 0; - *blkaddr++ = 0; - *blkaddr++ = 0; -#if RGTC_DEBUG - fprintf(stderr, "enc0 used\n"); -#endif - return; - } - - /* find best encoding for alpha0 > alpha1 */ - /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */ - alphablockerror1 = 0x0; - alphablockerror2 = 0xffffffff; - alphablockerror3 = 0xffffffff; - if (alphaabsmin) alphause[0] = 0; - else alphause[0] = alphabase[0]; - if (alphaabsmax) alphause[1] = 255; - else alphause[1] = alphabase[1]; - /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */ - for (aindex = 0; aindex < 7; aindex++) { - /* don't forget here is always rounded down */ - acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14; - } +#define TAG(x) unsigned_##x - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - /* maybe it's overkill to have the most complicated calculation just for the error - calculation which we only need to figure out if encoding1 or encoding2 is better... */ - if (srccolors[j][i] > acutValues[0]) { - alphaenc1[4*j + i] = 0; - alphadist = srccolors[j][i] - alphause[1]; - } - else if (srccolors[j][i] > acutValues[1]) { - alphaenc1[4*j + i] = 2; - alphadist = srccolors[j][i] - (alphause[1] * 6 + alphause[0] * 1) / 7; - } - else if (srccolors[j][i] > acutValues[2]) { - alphaenc1[4*j + i] = 3; - alphadist = srccolors[j][i] - (alphause[1] * 5 + alphause[0] * 2) / 7; - } - else if (srccolors[j][i] > acutValues[3]) { - alphaenc1[4*j + i] = 4; - alphadist = srccolors[j][i] - (alphause[1] * 4 + alphause[0] * 3) / 7; - } - else if (srccolors[j][i] > acutValues[4]) { - alphaenc1[4*j + i] = 5; - alphadist = srccolors[j][i] - (alphause[1] * 3 + alphause[0] * 4) / 7; - } - else if (srccolors[j][i] > acutValues[5]) { - alphaenc1[4*j + i] = 6; - alphadist = srccolors[j][i] - (alphause[1] * 2 + alphause[0] * 5) / 7; - } - else if (srccolors[j][i] > acutValues[6]) { - alphaenc1[4*j + i] = 7; - alphadist = srccolors[j][i] - (alphause[1] * 1 + alphause[0] * 6) / 7; - } - else { - alphaenc1[4*j + i] = 1; - alphadist = srccolors[j][i] - alphause[0]; - } - alphablockerror1 += alphadist * alphadist; - } - } -#if RGTC_DEBUG - for (i = 0; i < 16; i++) { - fprintf(stderr, "%d ", alphaenc1[i]); - } - fprintf(stderr, "cutVals "); - for (i = 0; i < 8; i++) { - fprintf(stderr, "%d ", acutValues[i]); - } - fprintf(stderr, "srcVals "); - for (j = 0; j < numypixels; j++) - for (i = 0; i < numxpixels; i++) { - fprintf(stderr, "%d ", srccolors[j][i]); - } - - fprintf(stderr, "\n"); -#endif +#define TYPE GLubyte +#define T_MIN 0 +#define T_MAX 0xff - /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax - are false but try it anyway */ - if (alphablockerror1 >= 32) { - - /* don't bother if encoding is already very good, this condition should also imply - we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */ - alphablockerror2 = 0; - for (aindex = 0; aindex < 5; aindex++) { - /* don't forget here is always rounded down */ - acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10; - } - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - /* maybe it's overkill to have the most complicated calculation just for the error - calculation which we only need to figure out if encoding1 or encoding2 is better... */ - if (srccolors[j][i] == 0) { - alphaenc2[4*j + i] = 6; - alphadist = 0; - } - else if (srccolors[j][i] == 255) { - alphaenc2[4*j + i] = 7; - alphadist = 0; - } - else if (srccolors[j][i] <= acutValues[0]) { - alphaenc2[4*j + i] = 0; - alphadist = srccolors[j][i] - alphabase[0]; - } - else if (srccolors[j][i] <= acutValues[1]) { - alphaenc2[4*j + i] = 2; - alphadist = srccolors[j][i] - (alphabase[0] * 4 + alphabase[1] * 1) / 5; - } - else if (srccolors[j][i] <= acutValues[2]) { - alphaenc2[4*j + i] = 3; - alphadist = srccolors[j][i] - (alphabase[0] * 3 + alphabase[1] * 2) / 5; - } - else if (srccolors[j][i] <= acutValues[3]) { - alphaenc2[4*j + i] = 4; - alphadist = srccolors[j][i] - (alphabase[0] * 2 + alphabase[1] * 3) / 5; - } - else if (srccolors[j][i] <= acutValues[4]) { - alphaenc2[4*j + i] = 5; - alphadist = srccolors[j][i] - (alphabase[0] * 1 + alphabase[1] * 4) / 5; - } - else { - alphaenc2[4*j + i] = 1; - alphadist = srccolors[j][i] - alphabase[1]; - } - alphablockerror2 += alphadist * alphadist; - } - } +#include "texcompress_rgtc_tmp.h" +#undef TAG +#undef TYPE +#undef T_MIN +#undef T_MAX - /* skip this if the error is already very small - this encoding is MUCH better on average than #2 though, but expensive! */ - if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) { - GLshort blockerrlin1 = 0; - GLshort blockerrlin2 = 0; - GLubyte nralphainrangelow = 0; - GLubyte nralphainrangehigh = 0; - alphatest[0] = 0xff; - alphatest[1] = 0x0; - /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */ - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - if ((srccolors[j][i] > alphatest[1]) && (srccolors[j][i] < (255 -(alphabase[1] - alphabase[0]) / 28))) - alphatest[1] = srccolors[j][i]; - if ((srccolors[j][i] < alphatest[0]) && (srccolors[j][i] > (alphabase[1] - alphabase[0]) / 28)) - alphatest[0] = srccolors[j][i]; - } - } - /* shouldn't happen too often, don't really care about those degenerated cases */ - if (alphatest[1] <= alphatest[0]) { - alphatest[0] = 1; - alphatest[1] = 254; - } - for (aindex = 0; aindex < 5; aindex++) { - /* don't forget here is always rounded down */ - acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10; - } +#define TAG(x) signed_##x +#define TYPE GLbyte +#define T_MIN (GLbyte)-127 +#define T_MAX (GLbyte)127 - /* find the "average" difference between the alpha values and the next encoded value. - This is then used to calculate new base values. - Should there be some weighting, i.e. those values closer to alphatest[x] have more weight, - since they will see more improvement, and also because the values in the middle are somewhat - likely to get no improvement at all (because the base values might move in different directions)? - OTOH it would mean the values in the middle are even less likely to get an improvement - */ - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - if (srccolors[j][i] <= alphatest[0] / 2) { - } - else if (srccolors[j][i] > ((255 + alphatest[1]) / 2)) { - } - else if (srccolors[j][i] <= acutValues[0]) { - blockerrlin1 += (srccolors[j][i] - alphatest[0]); - nralphainrangelow += 1; - } - else if (srccolors[j][i] <= acutValues[1]) { - blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5); - blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5); - nralphainrangelow += 1; - nralphainrangehigh += 1; - } - else if (srccolors[j][i] <= acutValues[2]) { - blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5); - blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5); - nralphainrangelow += 1; - nralphainrangehigh += 1; - } - else if (srccolors[j][i] <= acutValues[3]) { - blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5); - blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5); - nralphainrangelow += 1; - nralphainrangehigh += 1; - } - else if (srccolors[j][i] <= acutValues[4]) { - blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5); - blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5); - nralphainrangelow += 1; - nralphainrangehigh += 1; - } - else { - blockerrlin2 += (srccolors[j][i] - alphatest[1]); - nralphainrangehigh += 1; - } - } - } - /* shouldn't happen often, needed to avoid div by zero */ - if (nralphainrangelow == 0) nralphainrangelow = 1; - if (nralphainrangehigh == 0) nralphainrangehigh = 1; - alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow); -#if RGTC_DEBUG - fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow); - fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh); -#endif - /* again shouldn't really happen often... */ - if (alphatest[0] < 0) { - alphatest[0] = 0; - } - alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh); - if (alphatest[1] > 255) { - alphatest[1] = 255; - } +#include "texcompress_rgtc_tmp.h" - alphablockerror3 = 0; - for (aindex = 0; aindex < 5; aindex++) { - /* don't forget here is always rounded down */ - acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10; - } - for (j = 0; j < numypixels; j++) { - for (i = 0; i < numxpixels; i++) { - /* maybe it's overkill to have the most complicated calculation just for the error - calculation which we only need to figure out if encoding1 or encoding2 is better... */ - if (srccolors[j][i] <= alphatest[0] / 2) { - alphaenc3[4*j + i] = 6; - alphadist = srccolors[j][i]; - } - else if (srccolors[j][i] > ((255 + alphatest[1]) / 2)) { - alphaenc3[4*j + i] = 7; - alphadist = 255 - srccolors[j][i]; - } - else if (srccolors[j][i] <= acutValues[0]) { - alphaenc3[4*j + i] = 0; - alphadist = srccolors[j][i] - alphatest[0]; - } - else if (srccolors[j][i] <= acutValues[1]) { - alphaenc3[4*j + i] = 2; - alphadist = srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5; - } - else if (srccolors[j][i] <= acutValues[2]) { - alphaenc3[4*j + i] = 3; - alphadist = srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5; - } - else if (srccolors[j][i] <= acutValues[3]) { - alphaenc3[4*j + i] = 4; - alphadist = srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5; - } - else if (srccolors[j][i] <= acutValues[4]) { - alphaenc3[4*j + i] = 5; - alphadist = srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5; - } - else { - alphaenc3[4*j + i] = 1; - alphadist = srccolors[j][i] - alphatest[1]; - } - alphablockerror3 += alphadist * alphadist; - } - } - } - } - /* write the alpha values and encoding back. */ - if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) { -#if RGTC_DEBUG - if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1); -#endif - write_rgtc_encoded_channel_s( blkaddr, alphause[1], alphause[0], alphaenc1 ); - } - else if (alphablockerror2 <= alphablockerror3) { -#if RGTC_DEBUG - if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2); -#endif - write_rgtc_encoded_channel_s( blkaddr, alphabase[0], alphabase[1], alphaenc2 ); - } - else { -#if RGTC_DEBUG - fprintf(stderr, "enc3 used, error %d\n", alphablockerror3); -#endif - write_rgtc_encoded_channel_s( blkaddr, (GLubyte)alphatest[0], (GLubyte)alphatest[1], alphaenc3 ); - } -} +#undef TAG +#undef TYPE +#undef T_MIN +#undef T_MAX diff --git a/src/mesa/main/texcompress_rgtc_tmp.h b/src/mesa/main/texcompress_rgtc_tmp.h new file mode 100644 index 00000000000..0f830a5d904 --- /dev/null +++ b/src/mesa/main/texcompress_rgtc_tmp.h @@ -0,0 +1,376 @@ +/* + * Copyright (C) 2011 Red Hat Inc. + * + * block compression parts are: + * Copyright (C) 2004 Roland Scheidegger All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Author: + * Dave Airlie + */ + +/* included by texcompress_rgtc to define byte/ubyte compressors */ + +static void TAG(write_rgtc_encoded_channel)(TYPE *blkaddr, + TYPE alphabase1, + TYPE alphabase2, + TYPE alphaenc[16]) +{ + *blkaddr++ = alphabase1; + *blkaddr++ = alphabase2; + *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6); + *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7); + *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5); + *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6); + *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7); + *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5); +} +static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4], + GLint numxpixels, GLint numypixels) +{ + TYPE alphabase[2], alphause[2]; + GLshort alphatest[2] = { 0 }; + GLuint alphablockerror1, alphablockerror2, alphablockerror3; + TYPE i, j, aindex, acutValues[7]; + TYPE alphaenc1[16], alphaenc2[16], alphaenc3[16]; + GLboolean alphaabsmin = GL_FALSE; + GLboolean alphaabsmax = GL_FALSE; + GLshort alphadist; + + /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */ + alphabase[0] = T_MAX; alphabase[1] = T_MIN; + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + if (srccolors[j][i] == T_MIN) + alphaabsmin = GL_TRUE; + else if (srccolors[j][i] == T_MAX) + alphaabsmax = GL_TRUE; + else { + if (srccolors[j][i] > alphabase[1]) + alphabase[1] = srccolors[j][i]; + if (srccolors[j][i] < alphabase[0]) + alphabase[0] = srccolors[j][i]; + } + } + } + + + if ((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax)) { /* one color, either max or min */ + /* shortcut here since it is a very common case (and also avoids later problems) */ + /* || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax) */ + /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */ + + *blkaddr++ = srccolors[0][0]; + blkaddr++; + *blkaddr++ = 0; + *blkaddr++ = 0; + *blkaddr++ = 0; + *blkaddr++ = 0; + *blkaddr++ = 0; + *blkaddr++ = 0; +#if RGTC_DEBUG + fprintf(stderr, "enc0 used\n"); +#endif + return; + } + + /* find best encoding for alpha0 > alpha1 */ + /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */ + alphablockerror1 = 0x0; + alphablockerror2 = 0xffffffff; + alphablockerror3 = 0xffffffff; + if (alphaabsmin) alphause[0] = T_MIN; + else alphause[0] = alphabase[0]; + if (alphaabsmax) alphause[1] = T_MAX; + else alphause[1] = alphabase[1]; + /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */ + for (aindex = 0; aindex < 7; aindex++) { + /* don't forget here is always rounded down */ + acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14; + } + + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + /* maybe it's overkill to have the most complicated calculation just for the error + calculation which we only need to figure out if encoding1 or encoding2 is better... */ + if (srccolors[j][i] > acutValues[0]) { + alphaenc1[4*j + i] = 0; + alphadist = srccolors[j][i] - alphause[1]; + } + else if (srccolors[j][i] > acutValues[1]) { + alphaenc1[4*j + i] = 2; + alphadist = srccolors[j][i] - (alphause[1] * 6 + alphause[0] * 1) / 7; + } + else if (srccolors[j][i] > acutValues[2]) { + alphaenc1[4*j + i] = 3; + alphadist = srccolors[j][i] - (alphause[1] * 5 + alphause[0] * 2) / 7; + } + else if (srccolors[j][i] > acutValues[3]) { + alphaenc1[4*j + i] = 4; + alphadist = srccolors[j][i] - (alphause[1] * 4 + alphause[0] * 3) / 7; + } + else if (srccolors[j][i] > acutValues[4]) { + alphaenc1[4*j + i] = 5; + alphadist = srccolors[j][i] - (alphause[1] * 3 + alphause[0] * 4) / 7; + } + else if (srccolors[j][i] > acutValues[5]) { + alphaenc1[4*j + i] = 6; + alphadist = srccolors[j][i] - (alphause[1] * 2 + alphause[0] * 5) / 7; + } + else if (srccolors[j][i] > acutValues[6]) { + alphaenc1[4*j + i] = 7; + alphadist = srccolors[j][i] - (alphause[1] * 1 + alphause[0] * 6) / 7; + } + else { + alphaenc1[4*j + i] = 1; + alphadist = srccolors[j][i] - alphause[0]; + } + alphablockerror1 += alphadist * alphadist; + } + } + +#if RGTC_DEBUG + for (i = 0; i < 16; i++) { + fprintf(stderr, "%d ", alphaenc1[i]); + } + fprintf(stderr, "cutVals "); + for (i = 0; i < 8; i++) { + fprintf(stderr, "%d ", acutValues[i]); + } + fprintf(stderr, "srcVals "); + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + fprintf(stderr, "%d ", srccolors[j][i]); + } + } + fprintf(stderr, "\n"); +#endif + + /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax + are false but try it anyway */ + if (alphablockerror1 >= 32) { + + /* don't bother if encoding is already very good, this condition should also imply + we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */ + alphablockerror2 = 0; + for (aindex = 0; aindex < 5; aindex++) { + /* don't forget here is always rounded down */ + acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10; + } + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + /* maybe it's overkill to have the most complicated calculation just for the error + calculation which we only need to figure out if encoding1 or encoding2 is better... */ + if (srccolors[j][i] == T_MIN) { + alphaenc2[4*j + i] = 6; + alphadist = 0; + } + else if (srccolors[j][i] == T_MAX) { + alphaenc2[4*j + i] = 7; + alphadist = 0; + } + else if (srccolors[j][i] <= acutValues[0]) { + alphaenc2[4*j + i] = 0; + alphadist = srccolors[j][i] - alphabase[0]; + } + else if (srccolors[j][i] <= acutValues[1]) { + alphaenc2[4*j + i] = 2; + alphadist = srccolors[j][i] - (alphabase[0] * 4 + alphabase[1] * 1) / 5; + } + else if (srccolors[j][i] <= acutValues[2]) { + alphaenc2[4*j + i] = 3; + alphadist = srccolors[j][i] - (alphabase[0] * 3 + alphabase[1] * 2) / 5; + } + else if (srccolors[j][i] <= acutValues[3]) { + alphaenc2[4*j + i] = 4; + alphadist = srccolors[j][i] - (alphabase[0] * 2 + alphabase[1] * 3) / 5; + } + else if (srccolors[j][i] <= acutValues[4]) { + alphaenc2[4*j + i] = 5; + alphadist = srccolors[j][i] - (alphabase[0] * 1 + alphabase[1] * 4) / 5; + } + else { + alphaenc2[4*j + i] = 1; + alphadist = srccolors[j][i] - alphabase[1]; + } + alphablockerror2 += alphadist * alphadist; + } + } + + + /* skip this if the error is already very small + this encoding is MUCH better on average than #2 though, but expensive! */ + if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) { + GLshort blockerrlin1 = 0; + GLshort blockerrlin2 = 0; + TYPE nralphainrangelow = 0; + TYPE nralphainrangehigh = 0; + alphatest[0] = 0xff; + alphatest[1] = 0x0; + /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */ + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + if ((srccolors[j][i] > alphatest[1]) && (srccolors[j][i] < (T_MAX -(alphabase[1] - alphabase[0]) / 28))) + alphatest[1] = srccolors[j][i]; + if ((srccolors[j][i] < alphatest[0]) && (srccolors[j][i] > (alphabase[1] - alphabase[0]) / 28)) + alphatest[0] = srccolors[j][i]; + } + } + /* shouldn't happen too often, don't really care about those degenerated cases */ + if (alphatest[1] <= alphatest[0]) { + alphatest[0] = 1; + alphatest[1] = 254; + } + for (aindex = 0; aindex < 5; aindex++) { + /* don't forget here is always rounded down */ + acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10; + } + + /* find the "average" difference between the alpha values and the next encoded value. + This is then used to calculate new base values. + Should there be some weighting, i.e. those values closer to alphatest[x] have more weight, + since they will see more improvement, and also because the values in the middle are somewhat + likely to get no improvement at all (because the base values might move in different directions)? + OTOH it would mean the values in the middle are even less likely to get an improvement + */ + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + if (srccolors[j][i] <= alphatest[0] / 2) { + } + else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) { + } + else if (srccolors[j][i] <= acutValues[0]) { + blockerrlin1 += (srccolors[j][i] - alphatest[0]); + nralphainrangelow += 1; + } + else if (srccolors[j][i] <= acutValues[1]) { + blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5); + blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5); + nralphainrangelow += 1; + nralphainrangehigh += 1; + } + else if (srccolors[j][i] <= acutValues[2]) { + blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5); + blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5); + nralphainrangelow += 1; + nralphainrangehigh += 1; + } + else if (srccolors[j][i] <= acutValues[3]) { + blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5); + blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5); + nralphainrangelow += 1; + nralphainrangehigh += 1; + } + else if (srccolors[j][i] <= acutValues[4]) { + blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5); + blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5); + nralphainrangelow += 1; + nralphainrangehigh += 1; + } + else { + blockerrlin2 += (srccolors[j][i] - alphatest[1]); + nralphainrangehigh += 1; + } + } + } + /* shouldn't happen often, needed to avoid div by zero */ + if (nralphainrangelow == 0) nralphainrangelow = 1; + if (nralphainrangehigh == 0) nralphainrangehigh = 1; + alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow); +#if RGTC_DEBUG + fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow); + fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh); +#endif + /* again shouldn't really happen often... */ + if (alphatest[0] < T_MIN) { + alphatest[0] = T_MIN; + } + alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh); + if (alphatest[1] > T_MAX) { + alphatest[1] = T_MIN; + } + + alphablockerror3 = 0; + for (aindex = 0; aindex < 5; aindex++) { + /* don't forget here is always rounded down */ + acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10; + } + for (j = 0; j < numypixels; j++) { + for (i = 0; i < numxpixels; i++) { + /* maybe it's overkill to have the most complicated calculation just for the error + calculation which we only need to figure out if encoding1 or encoding2 is better... */ + if (srccolors[j][i] <= alphatest[0] / 2) { + alphaenc3[4*j + i] = 6; + alphadist = srccolors[j][i]; + } + else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) { + alphaenc3[4*j + i] = 7; + alphadist = T_MAX - srccolors[j][i]; + } + else if (srccolors[j][i] <= acutValues[0]) { + alphaenc3[4*j + i] = 0; + alphadist = srccolors[j][i] - alphatest[0]; + } + else if (srccolors[j][i] <= acutValues[1]) { + alphaenc3[4*j + i] = 2; + alphadist = srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5; + } + else if (srccolors[j][i] <= acutValues[2]) { + alphaenc3[4*j + i] = 3; + alphadist = srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5; + } + else if (srccolors[j][i] <= acutValues[3]) { + alphaenc3[4*j + i] = 4; + alphadist = srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5; + } + else if (srccolors[j][i] <= acutValues[4]) { + alphaenc3[4*j + i] = 5; + alphadist = srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5; + } + else { + alphaenc3[4*j + i] = 1; + alphadist = srccolors[j][i] - alphatest[1]; + } + alphablockerror3 += alphadist * alphadist; + } + } + } + } + /* write the alpha values and encoding back. */ + if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) { +#if RGTC_DEBUG + if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1); +#endif + TAG(write_rgtc_encoded_channel)( blkaddr, alphause[1], alphause[0], alphaenc1 ); + } + else if (alphablockerror2 <= alphablockerror3) { +#if RGTC_DEBUG + if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2); +#endif + TAG(write_rgtc_encoded_channel)( blkaddr, alphabase[0], alphabase[1], alphaenc2 ); + } + else { +#if RGTC_DEBUG + fprintf(stderr, "enc3 used, error %d\n", alphablockerror3); +#endif + TAG(write_rgtc_encoded_channel)( blkaddr, (TYPE)alphatest[0], (TYPE)alphatest[1], alphaenc3 ); + } +} -- cgit v1.2.3 From 01d5d1e80ee506205e8615356e55e4bca16c6b11 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 2 Mar 2011 09:41:38 +1000 Subject: swrast/rgtc: fix rendering issues introduced when fix constants The max value was wrong and this showed up in the piglit tests. --- src/mesa/main/texcompress_rgtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c index 2f3a0f214ad..f6a1825216d 100644 --- a/src/mesa/main/texcompress_rgtc.c +++ b/src/mesa/main/texcompress_rgtc.c @@ -443,7 +443,7 @@ _mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct gl_texture_image *texImage, #define TAG(x) signed_##x #define TYPE GLbyte #define T_MIN (GLbyte)-127 -#define T_MAX (GLbyte)127 +#define T_MAX (GLbyte)128 #include "texcompress_rgtc_tmp.h" -- cgit v1.2.3 From 8eebd216dd9f32de65e9af4160c042825ca75466 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 2 Mar 2011 09:48:40 +1000 Subject: rgtc: fixup mipmap generation this allows swrast to pass mipmap generation for these formats. --- src/mesa/main/mipmap.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c index d8a56103800..0727e1818f1 100644 --- a/src/mesa/main/mipmap.c +++ b/src/mesa/main/mipmap.c @@ -1755,8 +1755,13 @@ _mesa_generate_mipmap(struct gl_context *ctx, GLenum target, if (srcImage->_BaseFormat == GL_RGB) { convertFormat = MESA_FORMAT_RGB888; components = 3; - } - else if (srcImage->_BaseFormat == GL_RGBA) { + } else if (srcImage->_BaseFormat == GL_RED) { + convertFormat = MESA_FORMAT_R8; + components = 1; + } else if (srcImage->_BaseFormat == GL_RG) { + convertFormat = MESA_FORMAT_RG88; + components = 2; + } else if (srcImage->_BaseFormat == GL_RGBA) { convertFormat = MESA_FORMAT_RGBA8888; components = 4; } -- cgit v1.2.3 From ff0f36f59d58e90e775117beb945ffbec7a5d7e2 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 2 Mar 2011 09:52:53 +1000 Subject: rgtc: fix fetch function limits for signed types --- src/mesa/main/texcompress_rgtc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c index f6a1825216d..dcde4dd5a73 100644 --- a/src/mesa/main/texcompress_rgtc.c +++ b/src/mesa/main/texcompress_rgtc.c @@ -364,9 +364,9 @@ static void _fetch_texel_rgtc_s(GLint srcRowStride, const GLbyte *pixdata, else if (code < 6) decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5); else if (code == 6) - decode = -128; + decode = -127; else - decode = 127; + decode = 128; *value = decode; } -- cgit v1.2.3 From 5f714c2aaf8d25e5d5ba2e4c29cb3046f7639d24 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 2 Mar 2011 13:01:01 +1000 Subject: rgtc: move to using ubyte for fetch instead of chan + fix limit My previous fix to the byte max was incorrect. Signed-off-by: Dave Airlie --- src/mesa/main/texcompress_rgtc.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c index dcde4dd5a73..ebdaaf4755d 100644 --- a/src/mesa/main/texcompress_rgtc.c +++ b/src/mesa/main/texcompress_rgtc.c @@ -313,9 +313,9 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS) } static void _fetch_texel_rgtc_u(GLint srcRowStride, const GLubyte *pixdata, - GLint i, GLint j, GLchan *value, int comps) + GLint i, GLint j, GLubyte *value, int comps) { - GLchan decode; + GLubyte decode; const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps); const GLubyte alpha0 = blksrc[0]; const GLubyte alpha1 = blksrc[1]; @@ -326,17 +326,17 @@ static void _fetch_texel_rgtc_u(GLint srcRowStride, const GLubyte *pixdata, (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7; if (code == 0) - decode = UBYTE_TO_CHAN( alpha0 ); + decode = alpha0; else if (code == 1) - decode = UBYTE_TO_CHAN( alpha1 ); + decode = alpha1; else if (alpha0 > alpha1) - decode = UBYTE_TO_CHAN( ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7) ); + decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7); else if (code < 6) - decode = UBYTE_TO_CHAN( ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5) ); + decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5); else if (code == 6) decode = 0; else - decode = CHAN_MAX; + decode = 255; *value = decode; } @@ -366,7 +366,7 @@ static void _fetch_texel_rgtc_s(GLint srcRowStride, const GLbyte *pixdata, else if (code == 6) decode = -127; else - decode = 128; + decode = 127; *value = decode; } @@ -375,10 +375,10 @@ void _mesa_fetch_texel_2d_f_red_rgtc1(const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { - GLchan red; + GLubyte red; _fetch_texel_rgtc_u(texImage->RowStride, (GLubyte *)(texImage->Data), i, j, &red, 1); - texel[RCOMP] = CHAN_TO_FLOAT(red); + texel[RCOMP] = UBYTE_TO_FLOAT(red); texel[GCOMP] = 0.0; texel[BCOMP] = 0.0; texel[ACOMP] = 1.0; @@ -401,13 +401,13 @@ void _mesa_fetch_texel_2d_f_rg_rgtc2(const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { - GLchan red, green; + GLubyte red, green; _fetch_texel_rgtc_u(texImage->RowStride, (GLubyte *)(texImage->Data), i, j, &red, 2); _fetch_texel_rgtc_u(texImage->RowStride, (GLubyte *)(texImage->Data) + 8, i, j, &green, 2); - texel[RCOMP] = CHAN_TO_FLOAT(red); - texel[GCOMP] = CHAN_TO_FLOAT(green); + texel[RCOMP] = UBYTE_TO_FLOAT(red); + texel[GCOMP] = UBYTE_TO_FLOAT(green); texel[BCOMP] = 0.0; texel[ACOMP] = 1.0; } -- cgit v1.2.3 From 521394a204bd8073846acc7f9861081d29fa24c9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 2 Mar 2011 13:14:34 +1000 Subject: rgtc: don't try to access off the end of the block. if the values are all in the last dword, the high bits can be 0, This fixes a valgrind warning I saw when playing with mipmaps. Signed-off-by: Dave Airlie --- src/mesa/main/texcompress_rgtc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c index ebdaaf4755d..6b4e3b13cbe 100644 --- a/src/mesa/main/texcompress_rgtc.c +++ b/src/mesa/main/texcompress_rgtc.c @@ -321,7 +321,7 @@ static void _fetch_texel_rgtc_u(GLint srcRowStride, const GLubyte *pixdata, const GLubyte alpha1 = blksrc[1]; const GLubyte bit_pos = ((j&3) * 4 + (i&3)) * 3; const GLubyte acodelow = blksrc[2 + bit_pos / 8]; - const GLubyte acodehigh = blksrc[3 + bit_pos / 8]; + const uint8_t acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0; const GLubyte code = (acodelow >> (bit_pos & 0x7) | (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7; @@ -351,7 +351,7 @@ static void _fetch_texel_rgtc_s(GLint srcRowStride, const GLbyte *pixdata, const GLbyte alpha1 = blksrc[1]; const GLbyte bit_pos = ((j&3) * 4 + (i&3)) * 3; const GLbyte acodelow = blksrc[2 + bit_pos / 8]; - const GLbyte acodehigh = blksrc[3 + bit_pos / 8]; + const uint8_t acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0; const GLbyte code = (acodelow >> (bit_pos & 0x7) | (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7; -- cgit v1.2.3 From fb6ecca0a556dcca1f77bfb84a835e2b9c2e2e6a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 2 Mar 2011 14:08:59 +1000 Subject: rgtc: fix issues with compressor and signed types. With signed types we weren't hitting this test however the comment stating this doesn't happen often doesn't apply when using signed types since an all 0 block is quite common which isn't abs min or max. this fixes the limits correctly again also. Signed-off-by: Dave Airlie --- src/mesa/main/texcompress_rgtc.c | 6 +++--- src/mesa/main/texcompress_rgtc_tmp.h | 27 ++++++++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c index 6b4e3b13cbe..1b873035b68 100644 --- a/src/mesa/main/texcompress_rgtc.c +++ b/src/mesa/main/texcompress_rgtc.c @@ -364,7 +364,7 @@ static void _fetch_texel_rgtc_s(GLint srcRowStride, const GLbyte *pixdata, else if (code < 6) decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5); else if (code == 6) - decode = -127; + decode = -128; else decode = 127; @@ -442,8 +442,8 @@ _mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct gl_texture_image *texImage, #define TAG(x) signed_##x #define TYPE GLbyte -#define T_MIN (GLbyte)-127 -#define T_MAX (GLbyte)128 +#define T_MIN (GLbyte)-128 +#define T_MAX (GLbyte)127 #include "texcompress_rgtc_tmp.h" diff --git a/src/mesa/main/texcompress_rgtc_tmp.h b/src/mesa/main/texcompress_rgtc_tmp.h index 0f830a5d904..9377a6bd3be 100644 --- a/src/mesa/main/texcompress_rgtc_tmp.h +++ b/src/mesa/main/texcompress_rgtc_tmp.h @@ -73,9 +73,9 @@ static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4], } - if ((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax)) { /* one color, either max or min */ + if (((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax)) + || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax)) { /* one color, either max or min */ /* shortcut here since it is a very common case (and also avoids later problems) */ - /* || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax) */ /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */ *blkaddr++ = srccolors[0][0]; @@ -223,8 +223,8 @@ static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4], GLshort blockerrlin2 = 0; TYPE nralphainrangelow = 0; TYPE nralphainrangehigh = 0; - alphatest[0] = 0xff; - alphatest[1] = 0x0; + alphatest[0] = T_MAX; + alphatest[1] = T_MIN; /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */ for (j = 0; j < numypixels; j++) { for (i = 0; i < numxpixels; i++) { @@ -236,8 +236,8 @@ static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4], } /* shouldn't happen too often, don't really care about those degenerated cases */ if (alphatest[1] <= alphatest[0]) { - alphatest[0] = 1; - alphatest[1] = 254; + alphatest[0] = T_MIN+1; + alphatest[1] = T_MAX-1; } for (aindex = 0; aindex < 5; aindex++) { /* don't forget here is always rounded down */ @@ -305,7 +305,7 @@ static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4], } alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh); if (alphatest[1] > T_MAX) { - alphatest[1] = T_MIN; + alphatest[1] = T_MAX; } alphablockerror3 = 0; @@ -354,23 +354,36 @@ static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4], } } } + /* write the alpha values and encoding back. */ if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) { #if RGTC_DEBUG if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1); + fprintf(stderr,"w1: min %d max %d au0 %d au1 %d\n", + T_MIN, T_MAX, + alphause[1], alphause[0]); #endif + TAG(write_rgtc_encoded_channel)( blkaddr, alphause[1], alphause[0], alphaenc1 ); } else if (alphablockerror2 <= alphablockerror3) { #if RGTC_DEBUG if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2); + fprintf(stderr,"w2: min %d max %d au0 %d au1 %d\n", + T_MIN, T_MAX, + alphabase[0], alphabase[1]); #endif + TAG(write_rgtc_encoded_channel)( blkaddr, alphabase[0], alphabase[1], alphaenc2 ); } else { #if RGTC_DEBUG fprintf(stderr, "enc3 used, error %d\n", alphablockerror3); + fprintf(stderr,"w3: min %d max %d au0 %d au1 %d\n", + T_MIN, T_MAX, + alphatest[0], alphatest[1]); #endif + TAG(write_rgtc_encoded_channel)( blkaddr, (TYPE)alphatest[0], (TYPE)alphatest[1], alphaenc3 ); } } -- cgit v1.2.3 From 531c336fa39d8e823d05728cb7ddb3cc8a44d199 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 2 Mar 2011 14:16:39 +1000 Subject: rgtc: move the texel fetch into common unsigned/signed code. This function can be done in the include file also. Signed-off-by: Dave Airlie --- src/mesa/main/texcompress_rgtc.c | 77 ++++++------------------------------ src/mesa/main/texcompress_rgtc_tmp.h | 29 ++++++++++++++ 2 files changed, 41 insertions(+), 65 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c index 1b873035b68..26dca2d760b 100644 --- a/src/mesa/main/texcompress_rgtc.c +++ b/src/mesa/main/texcompress_rgtc.c @@ -51,6 +51,12 @@ static void unsigned_encode_rgtc_chan(GLubyte *blkaddr, GLubyte srccolors[4][4], static void signed_encode_rgtc_chan(GLbyte *blkaddr, GLbyte srccolors[4][4], GLint numxpixels, GLint numypixels); +static void unsigned_fetch_texel_rgtc(unsigned srcRowStride, const GLubyte *pixdata, + unsigned i, unsigned j, GLubyte *value, unsigned comps); + +static void signed_fetch_texel_rgtc(unsigned srcRowStride, const GLbyte *pixdata, + unsigned i, unsigned j, GLbyte *value, unsigned comps); + static void extractsrc_u( GLubyte srcpixels[4][4], const GLchan *srcaddr, GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps) { @@ -312,71 +318,12 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS) return GL_TRUE; } -static void _fetch_texel_rgtc_u(GLint srcRowStride, const GLubyte *pixdata, - GLint i, GLint j, GLubyte *value, int comps) -{ - GLubyte decode; - const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps); - const GLubyte alpha0 = blksrc[0]; - const GLubyte alpha1 = blksrc[1]; - const GLubyte bit_pos = ((j&3) * 4 + (i&3)) * 3; - const GLubyte acodelow = blksrc[2 + bit_pos / 8]; - const uint8_t acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0; - const GLubyte code = (acodelow >> (bit_pos & 0x7) | - (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7; - - if (code == 0) - decode = alpha0; - else if (code == 1) - decode = alpha1; - else if (alpha0 > alpha1) - decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7); - else if (code < 6) - decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5); - else if (code == 6) - decode = 0; - else - decode = 255; - - *value = decode; -} - - -static void _fetch_texel_rgtc_s(GLint srcRowStride, const GLbyte *pixdata, - GLint i, GLint j, GLbyte *value, int comps) -{ - GLbyte decode; - const GLbyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps); - const GLbyte alpha0 = blksrc[0]; - const GLbyte alpha1 = blksrc[1]; - const GLbyte bit_pos = ((j&3) * 4 + (i&3)) * 3; - const GLbyte acodelow = blksrc[2 + bit_pos / 8]; - const uint8_t acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0; - const GLbyte code = (acodelow >> (bit_pos & 0x7) | - (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7; - - if (code == 0) - decode = alpha0; - else if (code == 1) - decode = alpha1; - else if (alpha0 > alpha1) - decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7); - else if (code < 6) - decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5); - else if (code == 6) - decode = -128; - else - decode = 127; - - *value = decode; -} - void _mesa_fetch_texel_2d_f_red_rgtc1(const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { GLubyte red; - _fetch_texel_rgtc_u(texImage->RowStride, (GLubyte *)(texImage->Data), + unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data), i, j, &red, 1); texel[RCOMP] = UBYTE_TO_FLOAT(red); texel[GCOMP] = 0.0; @@ -389,7 +336,7 @@ _mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { GLbyte red; - _fetch_texel_rgtc_s(texImage->RowStride, (GLbyte *)(texImage->Data), + signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data), i, j, &red, 1); texel[RCOMP] = BYTE_TO_FLOAT_TEX(red); texel[GCOMP] = 0.0; @@ -402,9 +349,9 @@ _mesa_fetch_texel_2d_f_rg_rgtc2(const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { GLubyte red, green; - _fetch_texel_rgtc_u(texImage->RowStride, (GLubyte *)(texImage->Data), + unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data), i, j, &red, 2); - _fetch_texel_rgtc_u(texImage->RowStride, (GLubyte *)(texImage->Data) + 8, + unsigned_fetch_texel_rgtc(texImage->RowStride, (GLubyte *)(texImage->Data) + 8, i, j, &green, 2); texel[RCOMP] = UBYTE_TO_FLOAT(red); texel[GCOMP] = UBYTE_TO_FLOAT(green); @@ -417,9 +364,9 @@ _mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { GLbyte red, green; - _fetch_texel_rgtc_s(texImage->RowStride, (GLbyte *)(texImage->Data), + signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data), i, j, &red, 2); - _fetch_texel_rgtc_s(texImage->RowStride, (GLbyte *)(texImage->Data) + 8, + signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8, i, j, &green, 2); texel[RCOMP] = BYTE_TO_FLOAT_TEX(red); texel[GCOMP] = BYTE_TO_FLOAT_TEX(green); diff --git a/src/mesa/main/texcompress_rgtc_tmp.h b/src/mesa/main/texcompress_rgtc_tmp.h index 9377a6bd3be..404f7fe3fd2 100644 --- a/src/mesa/main/texcompress_rgtc_tmp.h +++ b/src/mesa/main/texcompress_rgtc_tmp.h @@ -29,6 +29,35 @@ /* included by texcompress_rgtc to define byte/ubyte compressors */ +static void TAG(fetch_texel_rgtc)(unsigned srcRowStride, const TYPE *pixdata, + unsigned i, unsigned j, TYPE *value, unsigned comps) +{ + TYPE decode; + const TYPE *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps); + const TYPE alpha0 = blksrc[0]; + const TYPE alpha1 = blksrc[1]; + const char bit_pos = ((j&3) * 4 + (i&3)) * 3; + const TYPE acodelow = blksrc[2 + bit_pos / 8]; + const TYPE acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0; + const TYPE code = (acodelow >> (bit_pos & 0x7) | + (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7; + + if (code == 0) + decode = alpha0; + else if (code == 1) + decode = alpha1; + else if (alpha0 > alpha1) + decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7); + else if (code < 6) + decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5); + else if (code == 6) + decode = T_MIN; + else + decode = T_MAX; + + *value = decode; +} + static void TAG(write_rgtc_encoded_channel)(TYPE *blkaddr, TYPE alphabase1, TYPE alphabase2, -- cgit v1.2.3 From 59cae3eee105b8522bc9b17cd60ad1e98b1e8825 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 2 Mar 2011 14:33:35 +1000 Subject: rgtc: remove GL types from this file. I'd like to share this file with gallium u_format stuff. Signed-off-by: Dave Airlie --- src/mesa/main/texcompress_rgtc_tmp.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/texcompress_rgtc_tmp.h b/src/mesa/main/texcompress_rgtc_tmp.h index 404f7fe3fd2..c8bf082a158 100644 --- a/src/mesa/main/texcompress_rgtc_tmp.h +++ b/src/mesa/main/texcompress_rgtc_tmp.h @@ -72,26 +72,26 @@ static void TAG(write_rgtc_encoded_channel)(TYPE *blkaddr, *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7); *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5); } + static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4], - GLint numxpixels, GLint numypixels) + int numxpixels, int numypixels) { TYPE alphabase[2], alphause[2]; - GLshort alphatest[2] = { 0 }; - GLuint alphablockerror1, alphablockerror2, alphablockerror3; + short alphatest[2] = { 0 }; + unsigned int alphablockerror1, alphablockerror2, alphablockerror3; TYPE i, j, aindex, acutValues[7]; TYPE alphaenc1[16], alphaenc2[16], alphaenc3[16]; - GLboolean alphaabsmin = GL_FALSE; - GLboolean alphaabsmax = GL_FALSE; - GLshort alphadist; + int alphaabsmin = 0, alphaabsmax = 0; + short alphadist; /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */ alphabase[0] = T_MAX; alphabase[1] = T_MIN; for (j = 0; j < numypixels; j++) { for (i = 0; i < numxpixels; i++) { if (srccolors[j][i] == T_MIN) - alphaabsmin = GL_TRUE; + alphaabsmin = 1; else if (srccolors[j][i] == T_MAX) - alphaabsmax = GL_TRUE; + alphaabsmax = 1; else { if (srccolors[j][i] > alphabase[1]) alphabase[1] = srccolors[j][i]; @@ -248,8 +248,8 @@ static void TAG(encode_rgtc_chan)(TYPE *blkaddr, TYPE srccolors[4][4], /* skip this if the error is already very small this encoding is MUCH better on average than #2 though, but expensive! */ if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) { - GLshort blockerrlin1 = 0; - GLshort blockerrlin2 = 0; + short blockerrlin1 = 0; + short blockerrlin2 = 0; TYPE nralphainrangelow = 0; TYPE nralphainrangehigh = 0; alphatest[0] = T_MAX; -- cgit v1.2.3 From 5f4d0cc6bcfb34a68a72ebc4091f3ab0cf43f90c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 2 Mar 2011 09:11:43 -0700 Subject: Revert "mesa: reduce calls to _mesa_test_framebuffer_completeness()" This reverts commit 1f9a0a4e6e5566c36c781add5f1e62af3efdfb58. This caused trouble with Lightsmark w/ i965 driver and fbo/fbo-blit-d24s8 (see bug 34894). It's probably something simple but no time to debug now. --- src/mesa/main/framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index 227b214a55b..8916441f455 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -799,7 +799,7 @@ update_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) /* This is a user-created framebuffer. * Completeness only matters for user-created framebuffers. */ - if (fb->_Status == 0) { + if (fb->_Status != GL_FRAMEBUFFER_COMPLETE) { _mesa_test_framebuffer_completeness(ctx, fb); } } -- cgit v1.2.3 From 8ad821df0a2d49964141f2ea4ef8179f4edc052f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 2 Mar 2011 09:32:45 -0700 Subject: mesa: added gl_program_constants::MaxAddressOffset See https://bugs.freedesktop.org/show_bug.cgi?id=29418 --- src/mesa/main/context.c | 1 + src/mesa/main/mtypes.h | 1 + src/mesa/program/program.c | 3 +++ src/mesa/program/program_parse.y | 4 ++-- 4 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index a942314552e..5d581c84002 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -487,6 +487,7 @@ init_program_limits(GLenum type, struct gl_program_constants *prog) prog->MaxEnvParams = MAX_PROGRAM_ENV_PARAMS; prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS; prog->MaxUniformComponents = 4 * MAX_UNIFORMS; + prog->MaxAddressOffset = MAX_PROGRAM_LOCAL_PARAMS; switch (type) { case GL_VERTEX_PROGRAM_ARB: diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index fcb06d49e9e..db3eba20c68 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2573,6 +2573,7 @@ struct gl_program_constants GLuint MaxAttribs; GLuint MaxTemps; GLuint MaxAddressRegs; + GLuint MaxAddressOffset; /**< [-MaxAddressOffset, MaxAddressOffset-1] */ GLuint MaxParameters; GLuint MaxLocalParams; GLuint MaxEnvParams; diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c index 52254e9365f..cfdd0da86d8 100644 --- a/src/mesa/program/program.c +++ b/src/mesa/program/program.c @@ -71,6 +71,9 @@ _mesa_init_program(struct gl_context *ctx) ASSERT(ctx->Const.VertexProgram.MaxUniformComponents <= 4 * MAX_UNIFORMS); ASSERT(ctx->Const.FragmentProgram.MaxUniformComponents <= 4 * MAX_UNIFORMS); + ASSERT(ctx->Const.VertexProgram.MaxAddressOffset <= (1 << INST_INDEX_BITS)); + ASSERT(ctx->Const.FragmentProgram.MaxAddressOffset <= (1 << INST_INDEX_BITS)); + /* If this fails, increase prog_instruction::TexSrcUnit size */ ASSERT(MAX_TEXTURE_UNITS < (1 << 5)); diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y index 784ea28c17a..19aa8ccdb53 100644 --- a/src/mesa/program/program_parse.y +++ b/src/mesa/program/program_parse.y @@ -935,7 +935,7 @@ addrRegRelOffset: { $$ = 0; } addrRegPosOffset: INTEGER { - if (($1 < 0) || ($1 > 4095)) { + if (($1 < 0) || ($1 > (state->limits->MaxAddressOffset - 1))) { char s[100]; _mesa_snprintf(s, sizeof(s), "relative address offset too large (%d)", $1); @@ -949,7 +949,7 @@ addrRegPosOffset: INTEGER addrRegNegOffset: INTEGER { - if (($1 < 0) || ($1 > 4096)) { + if (($1 < 0) || ($1 > state->limits->MaxAddressOffset)) { char s[100]; _mesa_snprintf(s, sizeof(s), "relative address offset too large (%d)", $1); -- cgit v1.2.3