diff options
Diffstat (limited to 'src/mesa/drivers/common/meta.c')
-rw-r--r-- | src/mesa/drivers/common/meta.c | 108 |
1 files changed, 84 insertions, 24 deletions
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 9946bf1990..ba8be12571 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -52,6 +52,7 @@ #include "main/readpix.h" #include "main/scissor.h" #include "main/shaderapi.h" +#include "main/shaderobj.h" #include "main/state.h" #include "main/stencil.h" #include "main/texobj.h" @@ -103,6 +104,8 @@ struct save_state /** META_ALPHA_TEST */ GLboolean AlphaEnabled; + GLenum AlphaFunc; + GLclampf AlphaRef; /** META_BLEND */ GLbitfield BlendEnabled; @@ -143,7 +146,10 @@ struct save_state struct gl_vertex_program *VertexProgram; GLboolean FragmentProgramEnabled; struct gl_fragment_program *FragmentProgram; - GLuint Shader; + struct gl_shader_program *VertexShader; + struct gl_shader_program *GeometryShader; + struct gl_shader_program *FragmentShader; + struct gl_shader_program *ActiveShader; /** META_STENCIL_TEST */ struct gl_stencil_attrib Stencil; @@ -324,6 +330,8 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state) if (state & META_ALPHA_TEST) { save->AlphaEnabled = ctx->Color.AlphaEnabled; + save->AlphaFunc = ctx->Color.AlphaFunc; + save->AlphaRef = ctx->Color.AlphaRef; if (ctx->Color.AlphaEnabled) _mesa_set_enable(ctx, GL_ALPHA_TEST, GL_FALSE); } @@ -433,8 +441,15 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state) } if (ctx->Extensions.ARB_shader_objects) { - save->Shader = ctx->Shader.CurrentProgram ? - ctx->Shader.CurrentProgram->Name : 0; + _mesa_reference_shader_program(ctx, &save->VertexShader, + ctx->Shader.CurrentVertexProgram); + _mesa_reference_shader_program(ctx, &save->GeometryShader, + ctx->Shader.CurrentGeometryProgram); + _mesa_reference_shader_program(ctx, &save->FragmentShader, + ctx->Shader.CurrentFragmentProgram); + _mesa_reference_shader_program(ctx, &save->ActiveShader, + ctx->Shader.CurrentFragmentProgram); + _mesa_UseProgramObjectARB(0); } } @@ -463,7 +478,8 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state) _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_FALSE); _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_FALSE); _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_FALSE); - _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE); + if (ctx->Extensions.ARB_texture_cube_map) + _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE); _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_FALSE); _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_FALSE); _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_FALSE); @@ -565,6 +581,7 @@ _mesa_meta_end(struct gl_context *ctx) if (state & META_ALPHA_TEST) { if (ctx->Color.AlphaEnabled != save->AlphaEnabled) _mesa_set_enable(ctx, GL_ALPHA_TEST, save->AlphaEnabled); + _mesa_AlphaFunc(save->AlphaFunc, save->AlphaRef); } if (state & META_BLEND) { @@ -664,9 +681,19 @@ _mesa_meta_end(struct gl_context *ctx) _mesa_reference_fragprog(ctx, &save->FragmentProgram, NULL); } - if (ctx->Extensions.ARB_shader_objects) { - _mesa_UseProgramObjectARB(save->Shader); - } + if (ctx->Extensions.ARB_vertex_shader) + _mesa_use_shader_program(ctx, GL_VERTEX_SHADER, save->VertexShader); + + if (ctx->Extensions.ARB_geometry_shader4) + _mesa_use_shader_program(ctx, GL_GEOMETRY_SHADER_ARB, + save->GeometryShader); + + if (ctx->Extensions.ARB_fragment_shader) + _mesa_use_shader_program(ctx, GL_FRAGMENT_SHADER, + save->FragmentShader); + + _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, + save->ActiveShader); } if (state & META_STENCIL_TEST) { @@ -1953,13 +1980,39 @@ _mesa_meta_DrawPixels(struct gl_context *ctx, _mesa_meta_end(ctx); } +static GLboolean +alpha_test_raster_color(struct gl_context *ctx) +{ + GLfloat alpha = ctx->Current.RasterColor[ACOMP]; + GLfloat ref = ctx->Color.AlphaRef; + + switch (ctx->Color.AlphaFunc) { + case GL_NEVER: + return GL_FALSE; + case GL_LESS: + return alpha < ref; + case GL_EQUAL: + return alpha == ref; + case GL_LEQUAL: + return alpha <= ref; + case GL_GREATER: + return alpha > ref; + case GL_NOTEQUAL: + return alpha != ref; + case GL_GEQUAL: + return alpha >= ref; + case GL_ALWAYS: + return GL_TRUE; + default: + assert(0); + return GL_FALSE; + } +} /** - * Do glBitmap with a alpha texture quad. Use the alpha test to - * cull the 'off' bits. If alpha test is already enabled, fall back - * to swrast (should be a rare case). - * A bitmap cache as in the gallium/mesa state tracker would - * improve performance a lot. + * Do glBitmap with a alpha texture quad. Use the alpha test to cull + * the 'off' bits. A bitmap cache as in the gallium/mesa state + * tracker would improve performance a lot. */ void _mesa_meta_Bitmap(struct gl_context *ctx, @@ -1971,6 +2024,7 @@ _mesa_meta_Bitmap(struct gl_context *ctx, struct temp_texture *tex = get_bitmap_temp_texture(ctx); const GLenum texIntFormat = GL_ALPHA; const struct gl_pixelstore_attrib unpackSave = *unpack; + GLubyte fg, bg; struct vertex { GLfloat x, y, z, s, t, r, g, b, a; }; @@ -1982,7 +2036,7 @@ _mesa_meta_Bitmap(struct gl_context *ctx, * Check if swrast fallback is needed. */ if (ctx->_ImageTransferState || - ctx->Color.AlphaEnabled || + ctx->FragmentProgram._Enabled || ctx->Fog.Enabled || ctx->Texture._EnabledUnits || width > tex->MaxSize || @@ -1991,6 +2045,9 @@ _mesa_meta_Bitmap(struct gl_context *ctx, return; } + if (ctx->Color.AlphaEnabled && !alpha_test_raster_color(ctx)) + return; + /* Most GL state applies to glBitmap (like blending, stencil, etc), * but a there's a few things we need to override: */ @@ -2072,21 +2129,26 @@ _mesa_meta_Bitmap(struct gl_context *ctx, _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); } + /* choose different foreground/background alpha values */ + CLAMPED_FLOAT_TO_UBYTE(fg, ctx->Current.RasterColor[ACOMP]); + bg = (fg > 127 ? 0 : 255); + bitmap1 = _mesa_map_pbo_source(ctx, &unpackSave, bitmap1); if (!bitmap1) { _mesa_meta_end(ctx); return; } - bitmap8 = (GLubyte *) calloc(1, width * height); + bitmap8 = (GLubyte *) malloc(width * height); if (bitmap8) { + memset(bitmap8, bg, width * height); _mesa_expand_bitmap(width, height, &unpackSave, bitmap1, - bitmap8, width, 0xff); + bitmap8, width, fg); _mesa_set_enable(ctx, tex->Target, GL_TRUE); _mesa_set_enable(ctx, GL_ALPHA_TEST, GL_TRUE); - _mesa_AlphaFunc(GL_GREATER, 0.0); + _mesa_AlphaFunc(GL_NOTEQUAL, UBYTE_TO_FLOAT(bg)); setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap8); @@ -2531,7 +2593,6 @@ copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, { struct gl_texture_object *texObj; struct gl_texture_image *texImage; - GLsizei postConvWidth = width, postConvHeight = height; GLenum format, type; GLint bpp; void *buf; @@ -2539,6 +2600,7 @@ copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, texObj = _mesa_get_current_tex_object(ctx, target); texImage = _mesa_get_tex_image(ctx, texObj, target, level); + /* Choose format/type for temporary image buffer */ format = _mesa_base_tex_format(ctx, internalFormat); type = get_temp_image_type(ctx, format); bpp = _mesa_bytes_per_pixel(format, type); @@ -2570,12 +2632,8 @@ copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, ctx->Driver.FreeTexImageData(ctx, texImage); } - _mesa_init_teximage_fields(ctx, target, texImage, - postConvWidth, postConvHeight, 1, - border, internalFormat); - - _mesa_choose_texture_format(ctx, texObj, texImage, target, level, - internalFormat, GL_NONE, GL_NONE); + /* The texture's format was already chosen in _mesa_CopyTexImage() */ + ASSERT(texImage->TexFormat != MESA_FORMAT_NONE); /* * Store texture data (with pixel transfer ops) @@ -2628,7 +2686,8 @@ _mesa_meta_CopyTexImage2D(struct gl_context *ctx, GLenum target, GLint level, * Have to be careful with locking and meta state for pixel transfer. */ static void -copy_tex_sub_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, +copy_tex_sub_image(struct gl_context *ctx, + GLuint dims, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) @@ -2642,6 +2701,7 @@ copy_tex_sub_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint lev texObj = _mesa_get_current_tex_object(ctx, target); texImage = _mesa_select_tex_image(ctx, texObj, target, level); + /* Choose format/type for temporary image buffer */ format = _mesa_get_format_base_format(texImage->TexFormat); type = get_temp_image_type(ctx, format); bpp = _mesa_bytes_per_pixel(format, type); |