st_cb_bitmap.c revision 3ece9ace540447c4f0d340a6f9f27980b54f83fb
13ece9ace540447c4f0d340a6f9f27980b54f83fbBrian/************************************************************************** 23ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * 33ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 43ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * All Rights Reserved. 53ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * 63ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Permission is hereby granted, free of charge, to any person obtaining a 73ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * copy of this software and associated documentation files (the 83ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * "Software"), to deal in the Software without restriction, including 93ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * without limitation the rights to use, copy, modify, merge, publish, 103ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * distribute, sub license, and/or sell copies of the Software, and to 113ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * permit persons to whom the Software is furnished to do so, subject to 123ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * the following conditions: 133ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * 143ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * The above copyright notice and this permission notice (including the 153ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * next paragraph) shall be included in all copies or substantial portions 163ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * of the Software. 173ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * 183ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 193ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 203ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 213ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 223ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 233ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 243ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 253ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * 263ece9ace540447c4f0d340a6f9f27980b54f83fbBrian **************************************************************************/ 273ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 283ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* 293ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Authors: 303ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Brian Paul 313ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 323ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 333ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "main/imports.h" 343ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "main/image.h" 353ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "main/macros.h" 363ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "main/texformat.h" 373ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "shader/program.h" 383ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "shader/prog_parameter.h" 393ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "shader/prog_print.h" 403ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 413ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "st_context.h" 423ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "st_atom.h" 433ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "st_atom_constbuf.h" 443ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "st_program.h" 453ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "st_cb_bitmap.h" 463ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "st_mesa_to_tgsi.h" 473ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "st_texture.h" 483ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "pipe/p_context.h" 493ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "pipe/p_defines.h" 503ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "pipe/p_inlines.h" 513ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "pipe/p_winsys.h" 523ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "util/p_tile.h" 533ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "util/u_draw_quad.h" 543ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "util/u_simple_shaders.h" 553ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "shader/prog_instruction.h" 563ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#include "cso_cache/cso_context.h" 573ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 583ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 593ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 603ece9ace540447c4f0d340a6f9f27980b54f83fbBrian/** 613ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Make fragment program for glBitmap: 623ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Sample the texture and kill the fragment if the bit is 0. 633ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * This program will be combined with the user's fragment program. 643ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 653ece9ace540447c4f0d340a6f9f27980b54f83fbBrianstatic struct st_fragment_program * 663ece9ace540447c4f0d340a6f9f27980b54f83fbBrianmake_bitmap_fragment_program(GLcontext *ctx) 673ece9ace540447c4f0d340a6f9f27980b54f83fbBrian{ 683ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct st_fragment_program *stfp; 693ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct gl_program *p; 703ece9ace540447c4f0d340a6f9f27980b54f83fbBrian GLuint ic = 0; 713ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 723ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); 733ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (!p) 743ece9ace540447c4f0d340a6f9f27980b54f83fbBrian return NULL; 753ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 763ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->NumInstructions = 5; 773ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 783ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions = _mesa_alloc_instructions(p->NumInstructions); 793ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (!p->Instructions) { 803ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ctx->Driver.DeleteProgram(ctx, p); 813ece9ace540447c4f0d340a6f9f27980b54f83fbBrian return NULL; 823ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 833ece9ace540447c4f0d340a6f9f27980b54f83fbBrian _mesa_init_instructions(p->Instructions, p->NumInstructions); 843ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 853ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */ 863ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].Opcode = OPCODE_TEX; 873ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; 883ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].DstReg.Index = 0; 893ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].File = PROGRAM_INPUT; 903ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0; 913ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].TexSrcUnit = 0; 923ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].TexSrcTarget = TEXTURE_2D_INDEX; 933ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ic++; 943ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 953ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* SWZ tmp0.x, tmp0.x, 1111; # tmp0.x = 1.0 */ 963ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].Opcode = OPCODE_SWZ; 973ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; 983ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].DstReg.Index = 0; 993ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].DstReg.WriteMask = WRITEMASK_X; 1003ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; 1013ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].Index = 0; 1023ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].Swizzle 1033ece9ace540447c4f0d340a6f9f27980b54f83fbBrian = MAKE_SWIZZLE4(SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE ); 1043ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ic++; 1053ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1063ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* SUB tmp0, tmp0.wwww, tmp0.xxxx; # tmp0.w -= 1 */ 1073ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].Opcode = OPCODE_SUB; 1083ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].DstReg.File = PROGRAM_TEMPORARY; 1093ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].DstReg.Index = 0; 1103ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; 1113ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].Index = 0; 1123ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].Swizzle = SWIZZLE_WWWW; 1133ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[1].File = PROGRAM_TEMPORARY; 1143ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[1].Index = 0; 1153ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[1].Swizzle = SWIZZLE_XXXX; /* 1.0 */ 1163ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ic++; 1173ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1183ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* KIL if tmp0 < 0 */ 1193ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].Opcode = OPCODE_KIL; 1203ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; 1213ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic].SrcReg[0].Index = 0; 1223ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ic++; 1233ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1243ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* END; */ 1253ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->Instructions[ic++].Opcode = OPCODE_END; 1263ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1273ece9ace540447c4f0d340a6f9f27980b54f83fbBrian assert(ic == p->NumInstructions); 1283ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1293ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->InputsRead = FRAG_BIT_TEX0; 1303ece9ace540447c4f0d340a6f9f27980b54f83fbBrian p->OutputsWritten = 0x0; 1313ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1323ece9ace540447c4f0d340a6f9f27980b54f83fbBrian stfp = (struct st_fragment_program *) p; 1333ece9ace540447c4f0d340a6f9f27980b54f83fbBrian stfp->Base.UsesKill = GL_TRUE; 1343ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st_translate_fragment_program(ctx->st, stfp, NULL); 1353ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1363ece9ace540447c4f0d340a6f9f27980b54f83fbBrian return stfp; 1373ece9ace540447c4f0d340a6f9f27980b54f83fbBrian} 1383ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1393ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1403ece9ace540447c4f0d340a6f9f27980b54f83fbBrian/** 1413ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Combine basic bitmap fragment program with the user-defined program. 1423ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 1433ece9ace540447c4f0d340a6f9f27980b54f83fbBrianstatic struct st_fragment_program * 1443ece9ace540447c4f0d340a6f9f27980b54f83fbBriancombined_bitmap_fragment_program(GLcontext *ctx) 1453ece9ace540447c4f0d340a6f9f27980b54f83fbBrian{ 1463ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct st_context *st = ctx->st; 1473ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct st_fragment_program *stfp; 1483ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1493ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (!st->bitmap.program) { 1503ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* create the basic bitmap fragment program */ 1513ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.program = make_bitmap_fragment_program(ctx); 1523ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 1533ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1543ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (st->bitmap.user_prog_sn == st->fp->serialNo) { 1553ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* re-use */ 1563ece9ace540447c4f0d340a6f9f27980b54f83fbBrian stfp = st->bitmap.combined_prog; 1573ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 1583ece9ace540447c4f0d340a6f9f27980b54f83fbBrian else { 1593ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* Concatenate the bitmap program with the current user-defined program. 1603ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 1613ece9ace540447c4f0d340a6f9f27980b54f83fbBrian stfp = (struct st_fragment_program *) 1623ece9ace540447c4f0d340a6f9f27980b54f83fbBrian _mesa_combine_programs(ctx, 1633ece9ace540447c4f0d340a6f9f27980b54f83fbBrian &st->bitmap.program->Base.Base, 1643ece9ace540447c4f0d340a6f9f27980b54f83fbBrian &st->fp->Base.Base); 1653ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1663ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#if 0 1673ece9ace540447c4f0d340a6f9f27980b54f83fbBrian { 1683ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct gl_program *p = &stfp->Base.Base; 1693ece9ace540447c4f0d340a6f9f27980b54f83fbBrian printf("Combined bitmap program:\n"); 1703ece9ace540447c4f0d340a6f9f27980b54f83fbBrian _mesa_print_program(p); 1713ece9ace540447c4f0d340a6f9f27980b54f83fbBrian printf("InputsRead: 0x%x\n", p->InputsRead); 1723ece9ace540447c4f0d340a6f9f27980b54f83fbBrian printf("OutputsWritten: 0x%x\n", p->OutputsWritten); 1733ece9ace540447c4f0d340a6f9f27980b54f83fbBrian _mesa_print_parameter_list(p->Parameters); 1743ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 1753ece9ace540447c4f0d340a6f9f27980b54f83fbBrian#endif 1763ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1773ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* translate to TGSI tokens */ 1783ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st_translate_fragment_program(st, stfp, NULL); 1793ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1803ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* save new program, update serial numbers */ 1813ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.user_prog_sn = st->fp->serialNo; 1823ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.combined_prog = stfp; 1833ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 1843ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1853ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* Ideally we'd have updated the pipe constants during the normal 1863ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * st/atom mechanism. But we can't since this is specific to glBitmap. 1873ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 1883ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st_upload_constants(st, stfp->Base.Base.Parameters, PIPE_SHADER_FRAGMENT); 1893ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1903ece9ace540447c4f0d340a6f9f27980b54f83fbBrian return stfp; 1913ece9ace540447c4f0d340a6f9f27980b54f83fbBrian} 1923ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1933ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1943ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1953ece9ace540447c4f0d340a6f9f27980b54f83fbBrian/** 1963ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Create a texture which represents a bitmap image. 1973ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 1983ece9ace540447c4f0d340a6f9f27980b54f83fbBrianstatic struct pipe_texture * 1993ece9ace540447c4f0d340a6f9f27980b54f83fbBrianmake_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, 2003ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const struct gl_pixelstore_attrib *unpack, 2013ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLubyte *bitmap) 2023ece9ace540447c4f0d340a6f9f27980b54f83fbBrian{ 2033ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_context *pipe = ctx->st->pipe; 2043ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_screen *screen = pipe->screen; 2053ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_surface *surface; 2063ece9ace540447c4f0d340a6f9f27980b54f83fbBrian uint format = 0, cpp, comp; 2073ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ubyte *dest; 2083ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_texture *pt; 2093ece9ace540447c4f0d340a6f9f27980b54f83fbBrian int row, col; 2103ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2113ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* find a texture format we know */ 2123ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (screen->is_format_supported( screen, PIPE_FORMAT_U_I8, PIPE_TEXTURE )) { 2133ece9ace540447c4f0d340a6f9f27980b54f83fbBrian format = PIPE_FORMAT_U_I8; 2143ece9ace540447c4f0d340a6f9f27980b54f83fbBrian cpp = 1; 2153ece9ace540447c4f0d340a6f9f27980b54f83fbBrian comp = 0; 2163ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2173ece9ace540447c4f0d340a6f9f27980b54f83fbBrian else if (screen->is_format_supported( screen, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_TEXTURE )) { 2183ece9ace540447c4f0d340a6f9f27980b54f83fbBrian format = PIPE_FORMAT_A8R8G8B8_UNORM; 2193ece9ace540447c4f0d340a6f9f27980b54f83fbBrian cpp = 4; 2203ece9ace540447c4f0d340a6f9f27980b54f83fbBrian comp = 3; /* alpha channel */ /*XXX little-endian dependency */ 2213ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2223ece9ace540447c4f0d340a6f9f27980b54f83fbBrian else { 2233ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* XXX support more formats */ 2243ece9ace540447c4f0d340a6f9f27980b54f83fbBrian assert( 0 ); 2253ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2263ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2273ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /** 2283ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Create a texture. 2293ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 2303ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, width, height, 2313ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 1, 0); 2323ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (!pt) 2333ece9ace540447c4f0d340a6f9f27980b54f83fbBrian return NULL; 2343ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2353ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (unpack->BufferObj && unpack->BufferObj->Name) { 2363ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* 2373ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pt->region = buffer_object_region(unpack->BufferObj); 2383ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 2393ece9ace540447c4f0d340a6f9f27980b54f83fbBrian printf("st_Bitmap (sourcing from PBO not implemented yet)\n"); 2403ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2413ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2423ece9ace540447c4f0d340a6f9f27980b54f83fbBrian surface = screen->get_tex_surface(screen, pt, 0, 0, 0); 2433ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2443ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* map texture surface */ 2453ece9ace540447c4f0d340a6f9f27980b54f83fbBrian dest = pipe_surface_map(surface); 2463ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2473ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* Put image into texture surface. 2483ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Note that the image is actually going to be upside down in 2493ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * the texture. We deal with that with texcoords. 2503ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 2513ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2523ece9ace540447c4f0d340a6f9f27980b54f83fbBrian for (row = 0; row < height; row++) { 2533ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, 2543ece9ace540447c4f0d340a6f9f27980b54f83fbBrian bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); 2553ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ubyte *destRow = dest + row * surface->pitch * cpp; 2563ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2573ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (unpack->LsbFirst) { 2583ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* Lsb first */ 2593ece9ace540447c4f0d340a6f9f27980b54f83fbBrian GLubyte mask = 1U << (unpack->SkipPixels & 0x7); 2603ece9ace540447c4f0d340a6f9f27980b54f83fbBrian for (col = 0; col < width; col++) { 2613ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2623ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* set texel to 255 if bit is set */ 2633ece9ace540447c4f0d340a6f9f27980b54f83fbBrian destRow[comp] = (*src & mask) ? 255 : 0; 2643ece9ace540447c4f0d340a6f9f27980b54f83fbBrian destRow += cpp; 2653ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2663ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (mask == 128U) { 2673ece9ace540447c4f0d340a6f9f27980b54f83fbBrian src++; 2683ece9ace540447c4f0d340a6f9f27980b54f83fbBrian mask = 1U; 2693ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2703ece9ace540447c4f0d340a6f9f27980b54f83fbBrian else { 2713ece9ace540447c4f0d340a6f9f27980b54f83fbBrian mask = mask << 1; 2723ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2733ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2743ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2753ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* get ready for next row */ 2763ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (mask != 1) 2773ece9ace540447c4f0d340a6f9f27980b54f83fbBrian src++; 2783ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2793ece9ace540447c4f0d340a6f9f27980b54f83fbBrian else { 2803ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* Msb first */ 2813ece9ace540447c4f0d340a6f9f27980b54f83fbBrian GLubyte mask = 128U >> (unpack->SkipPixels & 0x7); 2823ece9ace540447c4f0d340a6f9f27980b54f83fbBrian for (col = 0; col < width; col++) { 2833ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2843ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* set texel to 255 if bit is set */ 2853ece9ace540447c4f0d340a6f9f27980b54f83fbBrian destRow[comp] =(*src & mask) ? 255 : 0; 2863ece9ace540447c4f0d340a6f9f27980b54f83fbBrian destRow += cpp; 2873ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2883ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (mask == 1U) { 2893ece9ace540447c4f0d340a6f9f27980b54f83fbBrian src++; 2903ece9ace540447c4f0d340a6f9f27980b54f83fbBrian mask = 128U; 2913ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2923ece9ace540447c4f0d340a6f9f27980b54f83fbBrian else { 2933ece9ace540447c4f0d340a6f9f27980b54f83fbBrian mask = mask >> 1; 2943ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2953ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 2963ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 2973ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* get ready for next row */ 2983ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (mask != 128) 2993ece9ace540447c4f0d340a6f9f27980b54f83fbBrian src++; 3003ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 3013ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3023ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } /* row */ 3033ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3043ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* Release surface */ 3053ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe_surface_unmap(surface); 3063ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe_surface_reference(&surface, NULL); 3073ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->texture_update(pipe, pt, 0, 0x1); 3083ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3093ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pt->format = format; 3103ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3113ece9ace540447c4f0d340a6f9f27980b54f83fbBrian return pt; 3123ece9ace540447c4f0d340a6f9f27980b54f83fbBrian} 3133ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3143ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3153ece9ace540447c4f0d340a6f9f27980b54f83fbBrianstatic void 3163ece9ace540447c4f0d340a6f9f27980b54f83fbBriansetup_bitmap_vertex_data(struct st_context *st, 3173ece9ace540447c4f0d340a6f9f27980b54f83fbBrian int x, int y, int width, int height, 3183ece9ace540447c4f0d340a6f9f27980b54f83fbBrian float z, const float color[4]) 3193ece9ace540447c4f0d340a6f9f27980b54f83fbBrian{ 3203ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_context *pipe = st->pipe; 3213ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const struct gl_framebuffer *fb = st->ctx->DrawBuffer; 3223ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP); 3233ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat x0 = x; 3243ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat x1 = x + width; 3253ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat y0 = invert ? (fb->Height - y - height) : y; 3263ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat y1 = invert ? (y0 + height) : y + height; 3273ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat bias = st->bitmap_texcoord_bias; 3283ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat xBias = bias / (x1-x0); 3293ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat yBias = bias / (y1-y0); 3303ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat sLeft = 0.0 + xBias, sRight = 1.0 + xBias; 3313ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const GLfloat tTop = 1.0 - yBias, tBot = 1.0 - tTop - yBias; 3323ece9ace540447c4f0d340a6f9f27980b54f83fbBrian GLuint i; 3333ece9ace540447c4f0d340a6f9f27980b54f83fbBrian void *buf; 3343ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3353ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (!st->bitmap.vbuf) { 3363ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, 3373ece9ace540447c4f0d340a6f9f27980b54f83fbBrian PIPE_BUFFER_USAGE_VERTEX, 3383ece9ace540447c4f0d340a6f9f27980b54f83fbBrian sizeof(st->bitmap.vertices)); 3393ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 3403ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3413ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* positions, texcoords */ 3423ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[0][0][0] = x0; 3433ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[0][0][1] = y0; 3443ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[0][2][0] = sLeft; 3453ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[0][2][1] = tTop; 3463ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3473ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[1][0][0] = x1; 3483ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[1][0][1] = y0; 3493ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[1][2][0] = sRight; 3503ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[1][2][1] = tTop; 3513ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3523ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[2][0][0] = x1; 3533ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[2][0][1] = y1; 3543ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[2][2][0] = sRight; 3553ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[2][2][1] = tBot; 3563ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3573ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[3][0][0] = x0; 3583ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[3][0][1] = y1; 3593ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[3][2][0] = sLeft; 3603ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[3][2][1] = tBot; 3613ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3623ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* same for all verts: */ 3633ece9ace540447c4f0d340a6f9f27980b54f83fbBrian for (i = 0; i < 4; i++) { 3643ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[i][0][2] = z; 3653ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[i][0][3] = 1.0; 3663ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[i][1][0] = color[0]; 3673ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[i][1][1] = color[1]; 3683ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[i][1][2] = color[2]; 3693ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[i][1][3] = color[3]; 3703ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[i][2][2] = 0.0; /*R*/ 3713ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vertices[i][2][3] = 1.0; /*Q*/ 3723ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 3733ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3743ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* put vertex data into vbuf */ 3753ece9ace540447c4f0d340a6f9f27980b54f83fbBrian buf = pipe->winsys->buffer_map(pipe->winsys, st->bitmap.vbuf, 3763ece9ace540447c4f0d340a6f9f27980b54f83fbBrian PIPE_BUFFER_USAGE_CPU_WRITE); 3773ece9ace540447c4f0d340a6f9f27980b54f83fbBrian memcpy(buf, st->bitmap.vertices, sizeof(st->bitmap.vertices)); 3783ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->winsys->buffer_unmap(pipe->winsys, st->bitmap.vbuf); 3793ece9ace540447c4f0d340a6f9f27980b54f83fbBrian} 3803ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3813ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3823ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3833ece9ace540447c4f0d340a6f9f27980b54f83fbBrian/** 3843ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * Render a glBitmap by drawing a textured quad 3853ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 3863ece9ace540447c4f0d340a6f9f27980b54f83fbBrianstatic void 3873ece9ace540447c4f0d340a6f9f27980b54f83fbBriandraw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, 3883ece9ace540447c4f0d340a6f9f27980b54f83fbBrian GLsizei width, GLsizei height, 3893ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_texture *pt, 3903ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct st_fragment_program *stfp) 3913ece9ace540447c4f0d340a6f9f27980b54f83fbBrian{ 3923ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct st_context *st = ctx->st; 3933ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_context *pipe = ctx->st->pipe; 3943ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct cso_context *cso = ctx->st->cso_context; 3953ece9ace540447c4f0d340a6f9f27980b54f83fbBrian GLuint maxSize; 3963ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3973ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* limit checks */ 3983ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* XXX if DrawPixels image is larger than max texture size, break 3993ece9ace540447c4f0d340a6f9f27980b54f83fbBrian * it up into chunks. 4003ece9ace540447c4f0d340a6f9f27980b54f83fbBrian */ 4013ece9ace540447c4f0d340a6f9f27980b54f83fbBrian maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); 4023ece9ace540447c4f0d340a6f9f27980b54f83fbBrian assert(width <= maxSize); 4033ece9ace540447c4f0d340a6f9f27980b54f83fbBrian assert(height <= maxSize); 4043ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4053ece9ace540447c4f0d340a6f9f27980b54f83fbBrian cso_save_rasterizer(cso); 4063ece9ace540447c4f0d340a6f9f27980b54f83fbBrian //cso_save_viewport(cso); 4073ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4083ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* rasterizer state: just scissor */ 4093ece9ace540447c4f0d340a6f9f27980b54f83fbBrian { 4103ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_rasterizer_state rasterizer; 4113ece9ace540447c4f0d340a6f9f27980b54f83fbBrian memset(&rasterizer, 0, sizeof(rasterizer)); 4123ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (ctx->Scissor.Enabled) 4133ece9ace540447c4f0d340a6f9f27980b54f83fbBrian rasterizer.scissor = 1; 4143ece9ace540447c4f0d340a6f9f27980b54f83fbBrian rasterizer.bypass_clipping = 1; 4153ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4163ece9ace540447c4f0d340a6f9f27980b54f83fbBrian cso_set_rasterizer(cso, &rasterizer); 4173ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 4183ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4193ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* fragment shader state: TEX lookup program */ 4203ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->bind_fs_state(pipe, stfp->driver_shader); 4213ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4223ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* vertex shader state: position + texcoord pass-through */ 4233ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->bind_vs_state(pipe, st->bitmap.vs); 4243ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4253ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* sampler / texture state */ 4263ece9ace540447c4f0d340a6f9f27980b54f83fbBrian { 4273ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_sampler_state sampler; 4283ece9ace540447c4f0d340a6f9f27980b54f83fbBrian memset(&sampler, 0, sizeof(sampler)); 4293ece9ace540447c4f0d340a6f9f27980b54f83fbBrian sampler.wrap_s = PIPE_TEX_WRAP_CLAMP; 4303ece9ace540447c4f0d340a6f9f27980b54f83fbBrian sampler.wrap_t = PIPE_TEX_WRAP_CLAMP; 4313ece9ace540447c4f0d340a6f9f27980b54f83fbBrian sampler.wrap_r = PIPE_TEX_WRAP_CLAMP; 4323ece9ace540447c4f0d340a6f9f27980b54f83fbBrian sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; 4333ece9ace540447c4f0d340a6f9f27980b54f83fbBrian sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; 4343ece9ace540447c4f0d340a6f9f27980b54f83fbBrian sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; 4353ece9ace540447c4f0d340a6f9f27980b54f83fbBrian sampler.normalized_coords = 1; 4363ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4373ece9ace540447c4f0d340a6f9f27980b54f83fbBrian cso_single_sampler(cso, 0, &sampler); 4383ece9ace540447c4f0d340a6f9f27980b54f83fbBrian cso_single_sampler_done(cso); 4393ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4403ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->set_sampler_textures(pipe, 1, &pt); 4413ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 4423ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4433ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* draw textured quad */ 4443ece9ace540447c4f0d340a6f9f27980b54f83fbBrian setup_bitmap_vertex_data(st, x, y, width, height, 4453ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ctx->Current.RasterPos[2], 4463ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ctx->Current.RasterColor); 4473ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4483ece9ace540447c4f0d340a6f9f27980b54f83fbBrian util_draw_vertex_buffer(pipe, st->bitmap.vbuf, 4493ece9ace540447c4f0d340a6f9f27980b54f83fbBrian PIPE_PRIM_TRIANGLE_FAN, 4503ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4, /* verts */ 4513ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 3); /* attribs/vert */ 4523ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4533ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4543ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* restore state */ 4553ece9ace540447c4f0d340a6f9f27980b54f83fbBrian cso_restore_rasterizer(cso); 4563ece9ace540447c4f0d340a6f9f27980b54f83fbBrian cso_restore_samplers(cso); 4573ece9ace540447c4f0d340a6f9f27980b54f83fbBrian //cso_restore_viewport(cso); 4583ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* shaders don't go through cso yet */ 4593ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->bind_fs_state(pipe, st->fp->driver_shader); 4603ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->bind_vs_state(pipe, st->vp->driver_shader); 4613ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4623ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->set_sampler_textures(pipe, ctx->st->state.num_textures, 4633ece9ace540447c4f0d340a6f9f27980b54f83fbBrian ctx->st->state.sampler_texture); 4643ece9ace540447c4f0d340a6f9f27980b54f83fbBrian} 4653ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4663ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4673ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4683ece9ace540447c4f0d340a6f9f27980b54f83fbBrianstatic void 4693ece9ace540447c4f0d340a6f9f27980b54f83fbBrianst_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, 4703ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) 4713ece9ace540447c4f0d340a6f9f27980b54f83fbBrian{ 4723ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct st_fragment_program *stfp; 4733ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct st_context *st = ctx->st; 4743ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_texture *pt; 4753ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4763ece9ace540447c4f0d340a6f9f27980b54f83fbBrian stfp = combined_bitmap_fragment_program(ctx); 4773ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4783ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (!st->bitmap.vs) { 4793ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* create pass-through vertex shader now */ 4803ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, 4813ece9ace540447c4f0d340a6f9f27980b54f83fbBrian TGSI_SEMANTIC_COLOR, 4823ece9ace540447c4f0d340a6f9f27980b54f83fbBrian TGSI_SEMANTIC_GENERIC }; 4833ece9ace540447c4f0d340a6f9f27980b54f83fbBrian const uint semantic_indexes[] = { 0, 0, 0 }; 4843ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, 4853ece9ace540447c4f0d340a6f9f27980b54f83fbBrian semantic_names, 4863ece9ace540447c4f0d340a6f9f27980b54f83fbBrian semantic_indexes); 4873ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 4883ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4893ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st_validate_state(st); 4903ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 4913ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); 4923ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (pt) { 4933ece9ace540447c4f0d340a6f9f27980b54f83fbBrian draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2], 4943ece9ace540447c4f0d340a6f9f27980b54f83fbBrian width, height, 4953ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pt, stfp); 4963ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe_texture_reference(&pt, NULL); 4973ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 4983ece9ace540447c4f0d340a6f9f27980b54f83fbBrian} 4993ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 5003ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 5013ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 5023ece9ace540447c4f0d340a6f9f27980b54f83fbBrianvoid st_init_bitmap_functions(struct dd_function_table *functions) 5033ece9ace540447c4f0d340a6f9f27980b54f83fbBrian{ 5043ece9ace540447c4f0d340a6f9f27980b54f83fbBrian functions->Bitmap = st_Bitmap; 5053ece9ace540447c4f0d340a6f9f27980b54f83fbBrian} 5063ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 5073ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 5083ece9ace540447c4f0d340a6f9f27980b54f83fbBrianvoid 5093ece9ace540447c4f0d340a6f9f27980b54f83fbBrianst_destroy_bitmap(struct st_context *st) 5103ece9ace540447c4f0d340a6f9f27980b54f83fbBrian{ 5113ece9ace540447c4f0d340a6f9f27980b54f83fbBrian struct pipe_context *pipe = st->pipe; 5123ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 5133ece9ace540447c4f0d340a6f9f27980b54f83fbBrian /* XXX free frag shader state */ 5143ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 5153ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (st->bitmap.vs) { 5163ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->delete_vs_state(pipe, st->bitmap.vs); 5173ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vs = NULL; 5183ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 5193ece9ace540447c4f0d340a6f9f27980b54f83fbBrian if (st->bitmap.vbuf) { 5203ece9ace540447c4f0d340a6f9f27980b54f83fbBrian pipe->winsys->buffer_destroy(pipe->winsys, st->bitmap.vbuf); 5213ece9ace540447c4f0d340a6f9f27980b54f83fbBrian st->bitmap.vbuf = NULL; 5223ece9ace540447c4f0d340a6f9f27980b54f83fbBrian } 5233ece9ace540447c4f0d340a6f9f27980b54f83fbBrian} 5243ece9ace540447c4f0d340a6f9f27980b54f83fbBrian 525