1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
33 #include "main/imports.h"
34 #include "main/image.h"
35 #include "main/bufferobj.h"
36 #include "main/macros.h"
37 #include "main/texformat.h"
38 #include "shader/program.h"
39 #include "shader/prog_parameter.h"
40 #include "shader/prog_print.h"
42 #include "st_context.h"
44 #include "st_atom_constbuf.h"
45 #include "st_program.h"
46 #include "st_cb_bitmap.h"
47 #include "st_cb_program.h"
48 #include "st_mesa_to_tgsi.h"
49 #include "st_texture.h"
50 #include "pipe/p_context.h"
51 #include "pipe/p_defines.h"
52 #include "pipe/p_inlines.h"
53 #include "pipe/p_winsys.h"
54 #include "util/p_tile.h"
55 #include "util/u_draw_quad.h"
56 #include "util/u_simple_shaders.h"
57 #include "shader/prog_instruction.h"
58 #include "cso_cache/cso_context.h"
63 * glBitmaps are drawn as textured quads. The user's bitmap pattern
64 * is stored in a texture image. An alpha8 texture format is used.
65 * The fragment shader samples a bit (texel) from the texture, then
66 * discards the fragment if the bit is off.
68 * Note that we actually store the inverse image of the bitmap to
69 * simplify the fragment program. An "on" bit gets stored as texel=0x0
70 * and an "off" bit is stored as texel=0xff. Then we kill the
71 * fragment if the negated texel value is less than zero.
76 * The bitmap cache attempts to accumulate multiple glBitmap calls in a
77 * buffer which is then rendered en mass upon a flush, state change, etc.
78 * A wide, short buffer is used to target the common case of a series
79 * of glBitmap calls being used to draw text.
81 static GLboolean UseBitmapCache
= GL_TRUE
;
84 #define BITMAP_CACHE_WIDTH 512
85 #define BITMAP_CACHE_HEIGHT 32
89 /** Window pos to render the cached image */
91 /** Bounds of region used in window coords */
92 GLint xmin
, ymin
, xmax
, ymax
;
93 struct pipe_texture
*texture
;
95 /** An I8 texture image: */
96 GLubyte buffer
[BITMAP_CACHE_HEIGHT
][BITMAP_CACHE_WIDTH
];
103 * Make fragment program for glBitmap:
104 * Sample the texture and kill the fragment if the bit is 0.
105 * This program will be combined with the user's fragment program.
107 static struct st_fragment_program
*
108 make_bitmap_fragment_program(GLcontext
*ctx
, GLuint samplerIndex
)
110 struct st_fragment_program
*stfp
;
111 struct gl_program
*p
;
114 p
= ctx
->Driver
.NewProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
, 0);
118 p
->NumInstructions
= 3;
120 p
->Instructions
= _mesa_alloc_instructions(p
->NumInstructions
);
121 if (!p
->Instructions
) {
122 ctx
->Driver
.DeleteProgram(ctx
, p
);
125 _mesa_init_instructions(p
->Instructions
, p
->NumInstructions
);
127 /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */
128 p
->Instructions
[ic
].Opcode
= OPCODE_TEX
;
129 p
->Instructions
[ic
].DstReg
.File
= PROGRAM_TEMPORARY
;
130 p
->Instructions
[ic
].DstReg
.Index
= 0;
131 p
->Instructions
[ic
].SrcReg
[0].File
= PROGRAM_INPUT
;
132 p
->Instructions
[ic
].SrcReg
[0].Index
= FRAG_ATTRIB_TEX0
;
133 p
->Instructions
[ic
].TexSrcUnit
= samplerIndex
;
134 p
->Instructions
[ic
].TexSrcTarget
= TEXTURE_2D_INDEX
;
137 /* KIL if -tmp0 < 0 # texel=0 -> keep / texel=0 -> discard */
138 p
->Instructions
[ic
].Opcode
= OPCODE_KIL
;
139 p
->Instructions
[ic
].SrcReg
[0].File
= PROGRAM_TEMPORARY
;
140 p
->Instructions
[ic
].SrcReg
[0].Index
= 0;
141 p
->Instructions
[ic
].SrcReg
[0].NegateBase
= NEGATE_XYZW
;
145 p
->Instructions
[ic
++].Opcode
= OPCODE_END
;
147 assert(ic
== p
->NumInstructions
);
149 p
->InputsRead
= FRAG_BIT_TEX0
;
150 p
->OutputsWritten
= 0x0;
151 p
->SamplersUsed
= (1 << samplerIndex
);
153 stfp
= (struct st_fragment_program
*) p
;
154 stfp
->Base
.UsesKill
= GL_TRUE
;
155 st_translate_fragment_program(ctx
->st
, stfp
, NULL
);
162 find_free_bit(uint bitfield
)
165 for (i
= 0; i
< 32; i
++) {
166 if ((bitfield
& (1 << i
)) == 0) {
175 * Combine basic bitmap fragment program with the user-defined program.
177 static struct st_fragment_program
*
178 combined_bitmap_fragment_program(GLcontext
*ctx
)
180 struct st_context
*st
= ctx
->st
;
181 struct st_fragment_program
*stfp
= st
->fp
;
183 if (!stfp
->bitmap_program
) {
185 * Generate new program which is the user-defined program prefixed
186 * with the bitmap sampler/kill instructions.
188 struct st_fragment_program
*bitmap_prog
;
191 sampler
= find_free_bit(st
->fp
->Base
.Base
.SamplersUsed
);
192 bitmap_prog
= make_bitmap_fragment_program(ctx
, sampler
);
194 stfp
->bitmap_program
= (struct st_fragment_program
*)
195 _mesa_combine_programs(ctx
,
196 &bitmap_prog
->Base
.Base
, &stfp
->Base
.Base
);
197 stfp
->bitmap_program
->bitmap_sampler
= sampler
;
200 struct gl_program
*p
= &stfp
->bitmap_program
->Base
.Base
;
201 printf("Combined bitmap program:\n");
202 _mesa_print_program(p
);
203 printf("InputsRead: 0x%x\n", p
->InputsRead
);
204 printf("OutputsWritten: 0x%x\n", p
->OutputsWritten
);
205 _mesa_print_parameter_list(p
->Parameters
);
209 /* translate to TGSI tokens */
210 st_translate_fragment_program(st
, stfp
->bitmap_program
, NULL
);
213 /* Ideally we'd have updated the pipe constants during the normal
214 * st/atom mechanism. But we can't since this is specific to glBitmap.
216 st_upload_constants(st
, stfp
->Base
.Base
.Parameters
, PIPE_SHADER_FRAGMENT
);
218 return stfp
->bitmap_program
;
223 * Create a texture which represents a bitmap image.
225 static struct pipe_texture
*
226 make_bitmap_texture(GLcontext
*ctx
, GLsizei width
, GLsizei height
,
227 const struct gl_pixelstore_attrib
*unpack
,
228 const GLubyte
*bitmap
)
230 struct pipe_context
*pipe
= ctx
->st
->pipe
;
231 struct pipe_screen
*screen
= pipe
->screen
;
232 struct pipe_surface
*surface
;
233 uint format
= 0, cpp
, comp
;
235 struct pipe_texture
*pt
;
238 /* find a texture format we know */
239 if (screen
->is_format_supported( screen
, PIPE_FORMAT_U_I8
, PIPE_TEXTURE
)) {
240 format
= PIPE_FORMAT_U_I8
;
244 else if (screen
->is_format_supported( screen
, PIPE_FORMAT_A8R8G8B8_UNORM
, PIPE_TEXTURE
)) {
245 format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
247 comp
= 3; /* alpha channel */ /*XXX little-endian dependency */
250 /* XXX support more formats */
255 bitmap
= _mesa_map_bitmap_pbo(ctx
, unpack
, bitmap
);
261 * Create texture to hold bitmap pattern.
263 pt
= st_texture_create(ctx
->st
, PIPE_TEXTURE_2D
, format
, 0, width
, height
,
266 _mesa_unmap_bitmap_pbo(ctx
, unpack
);
270 surface
= screen
->get_tex_surface(screen
, pt
, 0, 0, 0);
272 /* map texture surface */
273 dest
= pipe_surface_map(surface
);
275 /* Put image into texture surface.
276 * Note that the image is actually going to be upside down in
277 * the texture. We deal with that with texcoords.
280 for (row
= 0; row
< height
; row
++) {
281 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
282 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
283 ubyte
*destRow
= dest
+ row
* surface
->pitch
* cpp
;
285 if (unpack
->LsbFirst
) {
287 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
288 for (col
= 0; col
< width
; col
++) {
290 /* set texel to 255 if bit is set */
291 destRow
[comp
] = (*src
& mask
) ? 0x0 : 0xff;
303 /* get ready for next row */
309 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
310 for (col
= 0; col
< width
; col
++) {
312 /* set texel to 255 if bit is set */
313 destRow
[comp
] =(*src
& mask
) ? 0x0 : 0xff;
325 /* get ready for next row */
332 _mesa_unmap_bitmap_pbo(ctx
, unpack
);
334 /* Release surface */
335 pipe_surface_unmap(surface
);
336 pipe_surface_reference(&surface
, NULL
);
337 pipe
->texture_update(pipe
, pt
, 0, 0x1);
346 setup_bitmap_vertex_data(struct st_context
*st
,
347 int x
, int y
, int width
, int height
,
348 float z
, const float color
[4])
350 struct pipe_context
*pipe
= st
->pipe
;
351 const struct gl_framebuffer
*fb
= st
->ctx
->DrawBuffer
;
352 const GLfloat fb_width
= fb
->Width
;
353 const GLfloat fb_height
= fb
->Height
;
354 const GLfloat x0
= x
;
355 const GLfloat x1
= x
+ width
;
356 const GLfloat y0
= y
;
357 const GLfloat y1
= y
+ height
;
358 const GLfloat sLeft
= 0.0F
, sRight
= 1.0F
;
359 const GLfloat tTop
= 0.0, tBot
= 1.0 - tTop
;
360 const GLfloat clip_x0
= x0
/ fb_width
* 2.0 - 1.0;
361 const GLfloat clip_y0
= y0
/ fb_height
* 2.0 - 1.0;
362 const GLfloat clip_x1
= x1
/ fb_width
* 2.0 - 1.0;
363 const GLfloat clip_y1
= y1
/ fb_height
* 2.0 - 1.0;
367 if (!st
->bitmap
.vbuf
) {
368 st
->bitmap
.vbuf
= pipe
->winsys
->buffer_create(pipe
->winsys
, 32,
369 PIPE_BUFFER_USAGE_VERTEX
,
370 sizeof(st
->bitmap
.vertices
));
373 /* Positions are in clip coords since we need to do clipping in case
374 * the bitmap quad goes beyond the window bounds.
376 st
->bitmap
.vertices
[0][0][0] = clip_x0
;
377 st
->bitmap
.vertices
[0][0][1] = clip_y0
;
378 st
->bitmap
.vertices
[0][2][0] = sLeft
;
379 st
->bitmap
.vertices
[0][2][1] = tTop
;
381 st
->bitmap
.vertices
[1][0][0] = clip_x1
;
382 st
->bitmap
.vertices
[1][0][1] = clip_y0
;
383 st
->bitmap
.vertices
[1][2][0] = sRight
;
384 st
->bitmap
.vertices
[1][2][1] = tTop
;
386 st
->bitmap
.vertices
[2][0][0] = clip_x1
;
387 st
->bitmap
.vertices
[2][0][1] = clip_y1
;
388 st
->bitmap
.vertices
[2][2][0] = sRight
;
389 st
->bitmap
.vertices
[2][2][1] = tBot
;
391 st
->bitmap
.vertices
[3][0][0] = clip_x0
;
392 st
->bitmap
.vertices
[3][0][1] = clip_y1
;
393 st
->bitmap
.vertices
[3][2][0] = sLeft
;
394 st
->bitmap
.vertices
[3][2][1] = tBot
;
396 /* same for all verts: */
397 for (i
= 0; i
< 4; i
++) {
398 st
->bitmap
.vertices
[i
][0][2] = z
;
399 st
->bitmap
.vertices
[i
][0][3] = 1.0;
400 st
->bitmap
.vertices
[i
][1][0] = color
[0];
401 st
->bitmap
.vertices
[i
][1][1] = color
[1];
402 st
->bitmap
.vertices
[i
][1][2] = color
[2];
403 st
->bitmap
.vertices
[i
][1][3] = color
[3];
404 st
->bitmap
.vertices
[i
][2][2] = 0.0; /*R*/
405 st
->bitmap
.vertices
[i
][2][3] = 1.0; /*Q*/
408 /* put vertex data into vbuf */
409 buf
= pipe
->winsys
->buffer_map(pipe
->winsys
, st
->bitmap
.vbuf
,
410 PIPE_BUFFER_USAGE_CPU_WRITE
);
411 memcpy(buf
, st
->bitmap
.vertices
, sizeof(st
->bitmap
.vertices
));
412 pipe
->winsys
->buffer_unmap(pipe
->winsys
, st
->bitmap
.vbuf
);
418 * Render a glBitmap by drawing a textured quad
421 draw_bitmap_quad(GLcontext
*ctx
, GLint x
, GLint y
, GLfloat z
,
422 GLsizei width
, GLsizei height
,
423 struct pipe_texture
*pt
)
425 struct st_context
*st
= ctx
->st
;
426 struct pipe_context
*pipe
= ctx
->st
->pipe
;
427 struct cso_context
*cso
= ctx
->st
->cso_context
;
428 struct st_fragment_program
*stfp
;
431 stfp
= combined_bitmap_fragment_program(ctx
);
434 /* XXX if the bitmap is larger than the max texture size, break
437 maxSize
= 1 << (pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
) - 1);
438 assert(width
<= maxSize
);
439 assert(height
<= maxSize
);
441 cso_save_rasterizer(cso
);
442 cso_save_samplers(cso
);
443 cso_save_sampler_textures(cso
);
444 cso_save_viewport(cso
);
445 cso_save_fragment_shader(cso
);
446 cso_save_vertex_shader(cso
);
448 /* rasterizer state: just scissor */
449 st
->bitmap
.rasterizer
.scissor
= ctx
->Scissor
.Enabled
;
450 cso_set_rasterizer(cso
, &st
->bitmap
.rasterizer
);
452 /* fragment shader state: TEX lookup program */
453 cso_set_fragment_shader_handle(cso
, stfp
->driver_shader
);
455 /* vertex shader state: position + texcoord pass-through */
456 cso_set_vertex_shader_handle(cso
, st
->bitmap
.vs
);
458 /* user samplers, plus our bitmap sampler */
460 struct pipe_sampler_state
*samplers
[PIPE_MAX_SAMPLERS
];
461 uint num
= MAX2(stfp
->bitmap_sampler
+ 1, st
->state
.num_samplers
);
463 for (i
= 0; i
< st
->state
.num_samplers
; i
++) {
464 samplers
[i
] = &st
->state
.samplers
[i
];
466 samplers
[stfp
->bitmap_sampler
] = &st
->bitmap
.sampler
;
467 cso_set_samplers(cso
, num
, (const struct pipe_sampler_state
**) samplers
); }
469 /* user textures, plus the bitmap texture */
471 struct pipe_texture
*textures
[PIPE_MAX_SAMPLERS
];
472 uint num
= MAX2(stfp
->bitmap_sampler
+ 1, st
->state
.num_textures
);
473 memcpy(textures
, st
->state
.sampler_texture
, sizeof(textures
));
474 textures
[stfp
->bitmap_sampler
] = pt
;
475 cso_set_sampler_textures(cso
, num
, textures
);
478 /* viewport state: viewport matching window dims */
480 const struct gl_framebuffer
*fb
= st
->ctx
->DrawBuffer
;
481 const GLboolean invert
= (st_fb_orientation(fb
) == Y_0_TOP
);
482 const float width
= fb
->Width
;
483 const float height
= fb
->Height
;
484 struct pipe_viewport_state vp
;
485 vp
.scale
[0] = 0.5 * width
;
486 vp
.scale
[1] = height
* (invert
? -0.5 : 0.5);
489 vp
.translate
[0] = 0.5 * width
;
490 vp
.translate
[1] = 0.5 * height
;
491 vp
.translate
[2] = 0.0;
492 vp
.translate
[3] = 0.0;
493 cso_set_viewport(cso
, &vp
);
496 /* draw textured quad */
497 setup_bitmap_vertex_data(st
, x
, y
, width
, height
,
498 ctx
->Current
.RasterPos
[2],
499 ctx
->Current
.RasterColor
);
501 util_draw_vertex_buffer(pipe
, st
->bitmap
.vbuf
,
502 PIPE_PRIM_TRIANGLE_FAN
,
504 3); /* attribs/vert */
508 cso_restore_rasterizer(cso
);
509 cso_restore_samplers(cso
);
510 cso_restore_sampler_textures(cso
);
511 cso_restore_viewport(cso
);
512 cso_restore_fragment_shader(cso
);
513 cso_restore_vertex_shader(cso
);
518 reset_cache(struct st_context
*st
)
520 memset(st
->bitmap
.cache
->buffer
, 0xff, sizeof(st
->bitmap
.cache
->buffer
));
521 st
->bitmap
.cache
->empty
= GL_TRUE
;
523 st
->bitmap
.cache
->xmin
= 1000000;
524 st
->bitmap
.cache
->xmax
= -1000000;
525 st
->bitmap
.cache
->ymin
= 1000000;
526 st
->bitmap
.cache
->ymax
= -1000000;
531 init_bitmap_cache(struct st_context
*st
)
533 struct pipe_context
*pipe
= st
->pipe
;
534 struct pipe_screen
*screen
= pipe
->screen
;
535 enum pipe_format format
;
537 st
->bitmap
.cache
= CALLOC_STRUCT(bitmap_cache
);
538 if (!st
->bitmap
.cache
)
541 /* find a usable texture format */
542 if (screen
->is_format_supported(screen
, PIPE_FORMAT_U_I8
, PIPE_TEXTURE
)) {
543 format
= PIPE_FORMAT_U_I8
;
546 /* XXX support more formats */
550 st
->bitmap
.cache
->texture
551 = st_texture_create(st
, PIPE_TEXTURE_2D
, format
, 0,
552 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
, 1, 0);
553 if (!st
->bitmap
.cache
->texture
) {
554 FREE(st
->bitmap
.cache
);
555 st
->bitmap
.cache
= NULL
;
564 * If there's anything in the bitmap cache, draw/flush it now.
567 st_flush_bitmap_cache(struct st_context
*st
)
569 if (!st
->bitmap
.cache
->empty
) {
570 if (st
->ctx
->DrawBuffer
) {
571 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
572 struct pipe_context
*pipe
= st
->pipe
;
573 struct pipe_screen
*screen
= pipe
->screen
;
574 struct pipe_surface
*surf
;
577 assert(cache
->xmin
<= cache
->xmax
);
579 printf("flush size %d x %d at %d, %d\n",
580 cache->xmax - cache->xmin,
581 cache->ymax - cache->ymin,
582 cache->xpos, cache->ypos);
585 /* update the texture map image */
586 surf
= screen
->get_tex_surface(screen
, cache
->texture
, 0, 0, 0);
587 dest
= pipe_surface_map(surf
);
588 memcpy(dest
, cache
->buffer
, sizeof(cache
->buffer
));
589 pipe_surface_unmap(surf
);
590 pipe_surface_reference(&surf
, NULL
);
592 /* flush in case the previous texture contents haven't been
593 * used yet. XXX this is not ideal! Revisit.
595 st
->pipe
->flush( st
->pipe
, 0x0, NULL
);
597 pipe
->texture_update(pipe
, cache
->texture
, 0, 0x1);
599 draw_bitmap_quad(st
->ctx
,
602 st
->ctx
->Current
.RasterPos
[2],
603 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
612 * Try to accumulate this glBitmap call in the bitmap cache.
613 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
616 accum_bitmap(struct st_context
*st
,
617 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
618 const struct gl_pixelstore_attrib
*unpack
,
619 const GLubyte
*bitmap
)
621 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
625 if (width
> BITMAP_CACHE_WIDTH
||
626 height
> BITMAP_CACHE_HEIGHT
)
627 return GL_FALSE
; /* too big to cache */
630 px
= x
- cache
->xpos
; /* pos in buffer */
631 py
= y
- cache
->ypos
;
632 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
633 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
) {
634 /* This bitmap would extend beyond cache bounds,
635 * so flush and continue.
637 st_flush_bitmap_cache(st
);
642 /* Initialize. Center bitmap vertically in the buffer. */
644 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
646 cache
->ypos
= y
- py
;
647 cache
->empty
= GL_FALSE
;
656 if (x
+ width
> cache
->xmax
)
657 cache
->xmax
= x
+ width
;
658 if (y
+ height
> cache
->ymax
)
659 cache
->ymax
= y
+ height
;
661 /* XXX try to combine this code with code in make_bitmap_texture() */
662 #define SET_PIXEL(COL, ROW) \
663 cache->buffer[py + (ROW)][px + (COL)] = 0x0;
665 for (row
= 0; row
< height
; row
++) {
666 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
667 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
669 if (unpack
->LsbFirst
) {
671 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
672 for (col
= 0; col
< width
; col
++) {
687 /* get ready for next row */
693 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
694 for (col
= 0; col
< width
; col
++) {
709 /* get ready for next row */
716 return GL_TRUE
; /* accumulated */
722 * Called via ctx->Driver.Bitmap()
725 st_Bitmap(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei width
, GLsizei height
,
726 const struct gl_pixelstore_attrib
*unpack
, const GLubyte
*bitmap
)
728 struct st_context
*st
= ctx
->st
;
729 struct pipe_texture
*pt
;
731 st_validate_state(st
);
733 if (!st
->bitmap
.vs
) {
734 /* create pass-through vertex shader now */
735 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
737 TGSI_SEMANTIC_GENERIC
};
738 const uint semantic_indexes
[] = { 0, 0, 0 };
739 st
->bitmap
.vs
= util_make_vertex_passthrough_shader(st
->pipe
, 3,
742 &st
->bitmap
.vert_shader
);
745 if (UseBitmapCache
&& accum_bitmap(st
, x
, y
, width
, height
, unpack
, bitmap
))
748 pt
= make_bitmap_texture(ctx
, width
, height
, unpack
, bitmap
);
750 assert(pt
->target
== PIPE_TEXTURE_2D
);
751 draw_bitmap_quad(ctx
, x
, y
, ctx
->Current
.RasterPos
[2],
753 pipe_texture_reference(&pt
, NULL
);
758 /** Per-context init */
760 st_init_bitmap_functions(struct dd_function_table
*functions
)
762 functions
->Bitmap
= st_Bitmap
;
766 /** Per-context init */
768 st_init_bitmap(struct st_context
*st
)
770 struct pipe_sampler_state
*sampler
= &st
->bitmap
.sampler
;
772 /* init sampler state once */
773 memset(sampler
, 0, sizeof(*sampler
));
774 sampler
->wrap_s
= PIPE_TEX_WRAP_CLAMP
;
775 sampler
->wrap_t
= PIPE_TEX_WRAP_CLAMP
;
776 sampler
->wrap_r
= PIPE_TEX_WRAP_CLAMP
;
777 sampler
->min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
778 sampler
->min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
779 sampler
->mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
780 sampler
->normalized_coords
= 1;
782 /* init baseline rasterizer state once */
783 memset(&st
->bitmap
.rasterizer
, 0, sizeof(st
->bitmap
.rasterizer
));
784 st
->bitmap
.rasterizer
.gl_rasterization_rules
= 1;
785 st
->bitmap
.rasterizer
.bypass_vs
= 1;
787 init_bitmap_cache(st
);
791 /** Per-context tear-down */
793 st_destroy_bitmap(struct st_context
*st
)
795 struct pipe_context
*pipe
= st
->pipe
;
798 if (st
->bitmap
.combined_prog
) {
799 st_delete_program(st
->ctx
, &st
->bitmap
.combined_prog
->Base
.Base
);
802 if (st
->bitmap
.program
) {
803 st_delete_program(st
->ctx
, &st
->bitmap
.program
->Base
.Base
);
807 cso_delete_vertex_shader(st
->cso_context
, st
->bitmap
.vs
);
808 st
->bitmap
.vs
= NULL
;
811 if (st
->bitmap
.vbuf
) {
812 pipe
->winsys
->buffer_destroy(pipe
->winsys
, st
->bitmap
.vbuf
);
813 st
->bitmap
.vbuf
= NULL
;
816 if (st
->bitmap
.cache
) {
817 pipe_texture_release(&st
->bitmap
.cache
->texture
);
818 FREE(st
->bitmap
.cache
);
819 st
->bitmap
.cache
= NULL
;