1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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"
38 #include "program/program.h"
39 #include "program/prog_print.h"
41 #include "st_context.h"
43 #include "st_atom_constbuf.h"
44 #include "st_program.h"
45 #include "st_cb_bitmap.h"
46 #include "st_texture.h"
48 #include "pipe/p_context.h"
49 #include "pipe/p_defines.h"
50 #include "pipe/p_shader_tokens.h"
51 #include "util/u_inlines.h"
52 #include "util/u_draw_quad.h"
53 #include "util/u_simple_shaders.h"
54 #include "util/u_upload_mgr.h"
55 #include "program/prog_instruction.h"
56 #include "cso_cache/cso_context.h"
60 * glBitmaps are drawn as textured quads. The user's bitmap pattern
61 * is stored in a texture image. An alpha8 texture format is used.
62 * The fragment shader samples a bit (texel) from the texture, then
63 * discards the fragment if the bit is off.
65 * Note that we actually store the inverse image of the bitmap to
66 * simplify the fragment program. An "on" bit gets stored as texel=0x0
67 * and an "off" bit is stored as texel=0xff. Then we kill the
68 * fragment if the negated texel value is less than zero.
73 * The bitmap cache attempts to accumulate multiple glBitmap calls in a
74 * buffer which is then rendered en mass upon a flush, state change, etc.
75 * A wide, short buffer is used to target the common case of a series
76 * of glBitmap calls being used to draw text.
78 static GLboolean UseBitmapCache
= GL_TRUE
;
81 #define BITMAP_CACHE_WIDTH 512
82 #define BITMAP_CACHE_HEIGHT 32
86 /** Window pos to render the cached image */
88 /** Bounds of region used in window coords */
89 GLint xmin
, ymin
, xmax
, ymax
;
93 /** Bitmap's Z position */
96 struct pipe_resource
*texture
;
97 struct pipe_transfer
*trans
;
101 /** An I8 texture image: */
106 /** Epsilon for Z comparisons */
107 #define Z_EPSILON 1e-06
111 * Copy user-provide bitmap bits into texture buffer, expanding
113 * "On" bits will set texels to 0x0.
114 * "Off" bits will not modify texels.
115 * Note that the image is actually going to be upside down in
116 * the texture. We deal with that with texcoords.
119 unpack_bitmap(struct st_context
*st
,
120 GLint px
, GLint py
, GLsizei width
, GLsizei height
,
121 const struct gl_pixelstore_attrib
*unpack
,
122 const GLubyte
*bitmap
,
123 ubyte
*destBuffer
, uint destStride
)
125 destBuffer
+= py
* destStride
+ px
;
127 _mesa_expand_bitmap(width
, height
, unpack
, bitmap
,
128 destBuffer
, destStride
, 0x0);
133 * Create a texture which represents a bitmap image.
135 static struct pipe_resource
*
136 make_bitmap_texture(struct gl_context
*ctx
, GLsizei width
, GLsizei height
,
137 const struct gl_pixelstore_attrib
*unpack
,
138 const GLubyte
*bitmap
)
140 struct st_context
*st
= st_context(ctx
);
141 struct pipe_context
*pipe
= st
->pipe
;
142 struct pipe_transfer
*transfer
;
144 struct pipe_resource
*pt
;
147 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
153 * Create texture to hold bitmap pattern.
155 pt
= st_texture_create(st
, st
->internal_target
, st
->bitmap
.tex_format
,
156 0, width
, height
, 1, 1, 0,
157 PIPE_BIND_SAMPLER_VIEW
);
159 _mesa_unmap_pbo_source(ctx
, unpack
);
163 dest
= pipe_transfer_map(st
->pipe
, pt
, 0, 0,
165 0, 0, width
, height
, &transfer
);
167 /* Put image into texture transfer */
168 memset(dest
, 0xff, height
* transfer
->stride
);
169 unpack_bitmap(st
, 0, 0, width
, height
, unpack
, bitmap
,
170 dest
, transfer
->stride
);
172 _mesa_unmap_pbo_source(ctx
, unpack
);
174 /* Release transfer */
175 pipe_transfer_unmap(pipe
, transfer
);
180 setup_bitmap_vertex_data(struct st_context
*st
, bool normalized
,
181 int x
, int y
, int width
, int height
,
182 float z
, const float color
[4],
183 struct pipe_resource
**vbuf
,
184 unsigned *vbuf_offset
)
186 const GLfloat fb_width
= (GLfloat
)st
->state
.framebuffer
.width
;
187 const GLfloat fb_height
= (GLfloat
)st
->state
.framebuffer
.height
;
188 const GLfloat x0
= (GLfloat
)x
;
189 const GLfloat x1
= (GLfloat
)(x
+ width
);
190 const GLfloat y0
= (GLfloat
)y
;
191 const GLfloat y1
= (GLfloat
)(y
+ height
);
192 GLfloat sLeft
= (GLfloat
)0.0, sRight
= (GLfloat
)1.0;
193 GLfloat tTop
= (GLfloat
)0.0, tBot
= (GLfloat
)1.0 - tTop
;
194 const GLfloat clip_x0
= (GLfloat
)(x0
/ fb_width
* 2.0 - 1.0);
195 const GLfloat clip_y0
= (GLfloat
)(y0
/ fb_height
* 2.0 - 1.0);
196 const GLfloat clip_x1
= (GLfloat
)(x1
/ fb_width
* 2.0 - 1.0);
197 const GLfloat clip_y1
= (GLfloat
)(y1
/ fb_height
* 2.0 - 1.0);
199 float (*vertices
)[3][4]; /**< vertex pos + color + texcoord */
203 sRight
= (GLfloat
) width
;
204 tBot
= (GLfloat
) height
;
207 u_upload_alloc(st
->uploader
, 0, 4 * sizeof(vertices
[0]), 4,
208 vbuf_offset
, vbuf
, (void **) &vertices
);
213 /* Positions are in clip coords since we need to do clipping in case
214 * the bitmap quad goes beyond the window bounds.
216 vertices
[0][0][0] = clip_x0
;
217 vertices
[0][0][1] = clip_y0
;
218 vertices
[0][2][0] = sLeft
;
219 vertices
[0][2][1] = tTop
;
221 vertices
[1][0][0] = clip_x1
;
222 vertices
[1][0][1] = clip_y0
;
223 vertices
[1][2][0] = sRight
;
224 vertices
[1][2][1] = tTop
;
226 vertices
[2][0][0] = clip_x1
;
227 vertices
[2][0][1] = clip_y1
;
228 vertices
[2][2][0] = sRight
;
229 vertices
[2][2][1] = tBot
;
231 vertices
[3][0][0] = clip_x0
;
232 vertices
[3][0][1] = clip_y1
;
233 vertices
[3][2][0] = sLeft
;
234 vertices
[3][2][1] = tBot
;
236 /* same for all verts: */
237 for (i
= 0; i
< 4; i
++) {
238 vertices
[i
][0][2] = z
;
239 vertices
[i
][0][3] = 1.0f
;
240 vertices
[i
][1][0] = color
[0];
241 vertices
[i
][1][1] = color
[1];
242 vertices
[i
][1][2] = color
[2];
243 vertices
[i
][1][3] = color
[3];
244 vertices
[i
][2][2] = 0.0; /*R*/
245 vertices
[i
][2][3] = 1.0; /*Q*/
248 u_upload_unmap(st
->uploader
);
254 * Render a glBitmap by drawing a textured quad
257 draw_bitmap_quad(struct gl_context
*ctx
, GLint x
, GLint y
, GLfloat z
,
258 GLsizei width
, GLsizei height
,
259 struct pipe_sampler_view
*sv
,
260 const GLfloat
*color
)
262 struct st_context
*st
= st_context(ctx
);
263 struct pipe_context
*pipe
= st
->pipe
;
264 struct cso_context
*cso
= st
->cso_context
;
265 struct st_fp_variant
*fpv
;
266 struct st_fp_variant_key key
;
269 struct pipe_resource
*vbuf
= NULL
;
271 memset(&key
, 0, sizeof(key
));
272 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
273 key
.bitmap
= GL_TRUE
;
274 key
.clamp_color
= st
->clamp_frag_color_in_shader
&&
275 st
->ctx
->Color
._ClampFragmentColor
;
277 fpv
= st_get_fp_variant(st
, st
->fp
, &key
);
279 /* As an optimization, Mesa's fragment programs will sometimes get the
280 * primary color from a statevar/constant rather than a varying variable.
281 * when that's the case, we need to ensure that we use the 'color'
282 * parameter and not the current attribute color (which may have changed
283 * through glRasterPos and state validation.
284 * So, we force the proper color here. Not elegant, but it works.
287 GLfloat colorSave
[4];
288 COPY_4V(colorSave
, ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
289 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], color
);
290 st_upload_constants(st
, st
->fp
->Base
.Base
.Parameters
,
291 PIPE_SHADER_FRAGMENT
);
292 COPY_4V(ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], colorSave
);
297 /* XXX if the bitmap is larger than the max texture size, break
300 maxSize
= 1 << (pipe
->screen
->get_param(pipe
->screen
,
301 PIPE_CAP_MAX_TEXTURE_2D_LEVELS
) - 1);
302 assert(width
<= (GLsizei
)maxSize
);
303 assert(height
<= (GLsizei
)maxSize
);
305 cso_save_rasterizer(cso
);
306 cso_save_fragment_samplers(cso
);
307 cso_save_fragment_sampler_views(cso
);
308 cso_save_viewport(cso
);
309 cso_save_fragment_shader(cso
);
310 cso_save_stream_outputs(cso
);
311 cso_save_vertex_shader(cso
);
312 cso_save_tessctrl_shader(cso
);
313 cso_save_tesseval_shader(cso
);
314 cso_save_geometry_shader(cso
);
315 cso_save_vertex_elements(cso
);
316 cso_save_aux_vertex_buffer_slot(cso
);
318 /* rasterizer state: just scissor */
319 st
->bitmap
.rasterizer
.scissor
= ctx
->Scissor
.EnableFlags
& 1;
320 cso_set_rasterizer(cso
, &st
->bitmap
.rasterizer
);
322 /* fragment shader state: TEX lookup program */
323 cso_set_fragment_shader_handle(cso
, fpv
->driver_shader
);
325 /* vertex shader state: position + texcoord pass-through */
326 cso_set_vertex_shader_handle(cso
, st
->bitmap
.vs
);
328 /* disable other shaders */
329 cso_set_tessctrl_shader_handle(cso
, NULL
);
330 cso_set_tesseval_shader_handle(cso
, NULL
);
331 cso_set_geometry_shader_handle(cso
, NULL
);
333 /* user samplers, plus our bitmap sampler */
335 struct pipe_sampler_state
*samplers
[PIPE_MAX_SAMPLERS
];
336 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
337 st
->state
.num_samplers
[PIPE_SHADER_FRAGMENT
]);
339 for (i
= 0; i
< st
->state
.num_samplers
[PIPE_SHADER_FRAGMENT
]; i
++) {
340 samplers
[i
] = &st
->state
.samplers
[PIPE_SHADER_FRAGMENT
][i
];
342 samplers
[fpv
->bitmap_sampler
] =
343 &st
->bitmap
.samplers
[sv
->texture
->target
!= PIPE_TEXTURE_RECT
];
344 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, num
,
345 (const struct pipe_sampler_state
**) samplers
);
348 /* user textures, plus the bitmap texture */
350 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
];
351 uint num
= MAX2(fpv
->bitmap_sampler
+ 1,
352 st
->state
.num_sampler_views
[PIPE_SHADER_FRAGMENT
]);
353 memcpy(sampler_views
, st
->state
.sampler_views
[PIPE_SHADER_FRAGMENT
],
354 sizeof(sampler_views
));
355 sampler_views
[fpv
->bitmap_sampler
] = sv
;
356 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, num
, sampler_views
);
359 /* viewport state: viewport matching window dims */
361 const GLboolean invert
= st
->state
.fb_orientation
== Y_0_TOP
;
362 const GLfloat width
= (GLfloat
)st
->state
.framebuffer
.width
;
363 const GLfloat height
= (GLfloat
)st
->state
.framebuffer
.height
;
364 struct pipe_viewport_state vp
;
365 vp
.scale
[0] = 0.5f
* width
;
366 vp
.scale
[1] = height
* (invert
? -0.5f
: 0.5f
);
368 vp
.translate
[0] = 0.5f
* width
;
369 vp
.translate
[1] = 0.5f
* height
;
370 vp
.translate
[2] = 0.5f
;
371 cso_set_viewport(cso
, &vp
);
374 cso_set_vertex_elements(cso
, 3, st
->velems_util_draw
);
375 cso_set_stream_outputs(st
->cso_context
, 0, NULL
, NULL
);
377 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
380 /* draw textured quad */
381 setup_bitmap_vertex_data(st
, sv
->texture
->target
!= PIPE_TEXTURE_RECT
,
382 x
, y
, width
, height
, z
, color
, &vbuf
, &offset
);
385 util_draw_vertex_buffer(pipe
, st
->cso_context
, vbuf
,
386 cso_get_aux_vertex_buffer_slot(st
->cso_context
),
388 PIPE_PRIM_TRIANGLE_FAN
,
390 3); /* attribs/vert */
394 cso_restore_rasterizer(cso
);
395 cso_restore_fragment_samplers(cso
);
396 cso_restore_fragment_sampler_views(cso
);
397 cso_restore_viewport(cso
);
398 cso_restore_fragment_shader(cso
);
399 cso_restore_vertex_shader(cso
);
400 cso_restore_tessctrl_shader(cso
);
401 cso_restore_tesseval_shader(cso
);
402 cso_restore_geometry_shader(cso
);
403 cso_restore_vertex_elements(cso
);
404 cso_restore_aux_vertex_buffer_slot(cso
);
405 cso_restore_stream_outputs(cso
);
407 pipe_resource_reference(&vbuf
, NULL
);
409 /* We uploaded modified constants, need to invalidate them. */
410 st
->dirty
.mesa
|= _NEW_PROGRAM_CONSTANTS
;
415 reset_cache(struct st_context
*st
)
417 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
419 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
420 cache
->empty
= GL_TRUE
;
422 cache
->xmin
= 1000000;
423 cache
->xmax
= -1000000;
424 cache
->ymin
= 1000000;
425 cache
->ymax
= -1000000;
427 assert(!cache
->texture
);
429 /* allocate a new texture */
430 cache
->texture
= st_texture_create(st
, PIPE_TEXTURE_2D
,
431 st
->bitmap
.tex_format
, 0,
432 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
434 PIPE_BIND_SAMPLER_VIEW
);
438 /** Print bitmap image to stdout (debug) */
440 print_cache(const struct bitmap_cache
*cache
)
444 for (i
= 0; i
< BITMAP_CACHE_HEIGHT
; i
++) {
445 k
= BITMAP_CACHE_WIDTH
* (BITMAP_CACHE_HEIGHT
- i
- 1);
446 for (j
= 0; j
< BITMAP_CACHE_WIDTH
; j
++) {
447 if (cache
->buffer
[k
])
459 * Create gallium pipe_transfer object for the bitmap cache.
462 create_cache_trans(struct st_context
*st
)
464 struct pipe_context
*pipe
= st
->pipe
;
465 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
470 /* Map the texture transfer.
471 * Subsequent glBitmap calls will write into the texture image.
473 cache
->buffer
= pipe_transfer_map(pipe
, cache
->texture
, 0, 0,
474 PIPE_TRANSFER_WRITE
, 0, 0,
476 BITMAP_CACHE_HEIGHT
, &cache
->trans
);
478 /* init image to all 0xff */
479 memset(cache
->buffer
, 0xff, cache
->trans
->stride
* BITMAP_CACHE_HEIGHT
);
484 * If there's anything in the bitmap cache, draw/flush it now.
487 st_flush_bitmap_cache(struct st_context
*st
)
489 if (!st
->bitmap
.cache
->empty
) {
490 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
492 struct pipe_context
*pipe
= st
->pipe
;
493 struct pipe_sampler_view
*sv
;
495 assert(cache
->xmin
<= cache
->xmax
);
498 printf("flush bitmap, size %d x %d at %d, %d\n",
499 cache
->xmax
- cache
->xmin
,
500 cache
->ymax
- cache
->ymin
,
501 cache
->xpos
, cache
->ypos
);
503 /* The texture transfer has been mapped until now.
504 * So unmap and release the texture transfer before drawing.
506 if (cache
->trans
&& cache
->buffer
) {
509 pipe_transfer_unmap(pipe
, cache
->trans
);
510 cache
->buffer
= NULL
;
514 sv
= st_create_texture_sampler_view(st
->pipe
, cache
->texture
);
516 draw_bitmap_quad(st
->ctx
,
520 BITMAP_CACHE_WIDTH
, BITMAP_CACHE_HEIGHT
,
524 pipe_sampler_view_reference(&sv
, NULL
);
527 /* release/free the texture */
528 pipe_resource_reference(&cache
->texture
, NULL
);
536 * Try to accumulate this glBitmap call in the bitmap cache.
537 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
540 accum_bitmap(struct gl_context
*ctx
,
541 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
542 const struct gl_pixelstore_attrib
*unpack
,
543 const GLubyte
*bitmap
)
545 struct st_context
*st
= ctx
->st
;
546 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
547 int px
= -999, py
= -999;
548 const GLfloat z
= st
->ctx
->Current
.RasterPos
[2];
550 if (width
> BITMAP_CACHE_WIDTH
||
551 height
> BITMAP_CACHE_HEIGHT
)
552 return GL_FALSE
; /* too big to cache */
555 px
= x
- cache
->xpos
; /* pos in buffer */
556 py
= y
- cache
->ypos
;
557 if (px
< 0 || px
+ width
> BITMAP_CACHE_WIDTH
||
558 py
< 0 || py
+ height
> BITMAP_CACHE_HEIGHT
||
559 !TEST_EQ_4V(st
->ctx
->Current
.RasterColor
, cache
->color
) ||
560 ((fabs(z
- cache
->zpos
) > Z_EPSILON
))) {
561 /* This bitmap would extend beyond cache bounds, or the bitmap
563 * so flush and continue.
565 st_flush_bitmap_cache(st
);
570 /* Initialize. Center bitmap vertically in the buffer. */
572 py
= (BITMAP_CACHE_HEIGHT
- height
) / 2;
574 cache
->ypos
= y
- py
;
576 cache
->empty
= GL_FALSE
;
577 COPY_4FV(cache
->color
, st
->ctx
->Current
.RasterColor
);
587 if (x
+ width
> cache
->xmax
)
588 cache
->xmax
= x
+ width
;
589 if (y
+ height
> cache
->ymax
)
590 cache
->ymax
= y
+ height
;
592 /* create the transfer if needed */
593 create_cache_trans(st
);
596 bitmap
= _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
601 unpack_bitmap(st
, px
, py
, width
, height
, unpack
, bitmap
,
602 cache
->buffer
, BITMAP_CACHE_WIDTH
);
604 _mesa_unmap_pbo_source(ctx
, unpack
);
606 return GL_TRUE
; /* accumulated */
612 * Called via ctx->Driver.Bitmap()
615 st_Bitmap(struct gl_context
*ctx
, GLint x
, GLint y
,
616 GLsizei width
, GLsizei height
,
617 const struct gl_pixelstore_attrib
*unpack
, const GLubyte
*bitmap
)
619 struct st_context
*st
= st_context(ctx
);
620 struct pipe_resource
*pt
;
625 /* We only need to validate state of the st dirty flags are set or
626 * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use
627 * for bitmap drawing uses no constants and the FS constants are
628 * explicitly uploaded in the draw_bitmap_quad() function.
630 if ((st
->dirty
.mesa
& ~_NEW_PROGRAM_CONSTANTS
) || st
->dirty
.st
) {
631 st_validate_state(st
);
634 if (!st
->bitmap
.vs
) {
635 /* create pass-through vertex shader now */
636 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
638 st
->needs_texcoord_semantic
? TGSI_SEMANTIC_TEXCOORD
:
639 TGSI_SEMANTIC_GENERIC
};
640 const uint semantic_indexes
[] = { 0, 0, 0 };
641 st
->bitmap
.vs
= util_make_vertex_passthrough_shader(st
->pipe
, 3,
647 if (UseBitmapCache
&& accum_bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap
))
650 pt
= make_bitmap_texture(ctx
, width
, height
, unpack
, bitmap
);
652 struct pipe_sampler_view
*sv
=
653 st_create_texture_sampler_view(st
->pipe
, pt
);
655 assert(pt
->target
== PIPE_TEXTURE_2D
|| pt
->target
== PIPE_TEXTURE_RECT
);
658 draw_bitmap_quad(ctx
, x
, y
, ctx
->Current
.RasterPos
[2],
660 st
->ctx
->Current
.RasterColor
);
662 pipe_sampler_view_reference(&sv
, NULL
);
665 /* release/free the texture */
666 pipe_resource_reference(&pt
, NULL
);
671 /** Per-context init */
673 st_init_bitmap_functions(struct dd_function_table
*functions
)
675 functions
->Bitmap
= st_Bitmap
;
679 /** Per-context init */
681 st_init_bitmap(struct st_context
*st
)
683 struct pipe_sampler_state
*sampler
= &st
->bitmap
.samplers
[0];
684 struct pipe_context
*pipe
= st
->pipe
;
685 struct pipe_screen
*screen
= pipe
->screen
;
687 /* init sampler state once */
688 memset(sampler
, 0, sizeof(*sampler
));
689 sampler
->wrap_s
= PIPE_TEX_WRAP_CLAMP
;
690 sampler
->wrap_t
= PIPE_TEX_WRAP_CLAMP
;
691 sampler
->wrap_r
= PIPE_TEX_WRAP_CLAMP
;
692 sampler
->min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
693 sampler
->min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
694 sampler
->mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
695 st
->bitmap
.samplers
[1] = *sampler
;
696 st
->bitmap
.samplers
[1].normalized_coords
= 1;
698 /* init baseline rasterizer state once */
699 memset(&st
->bitmap
.rasterizer
, 0, sizeof(st
->bitmap
.rasterizer
));
700 st
->bitmap
.rasterizer
.half_pixel_center
= 1;
701 st
->bitmap
.rasterizer
.bottom_edge_rule
= 1;
702 st
->bitmap
.rasterizer
.depth_clip
= 1;
704 /* find a usable texture format */
705 if (screen
->is_format_supported(screen
, PIPE_FORMAT_I8_UNORM
,
707 PIPE_BIND_SAMPLER_VIEW
)) {
708 st
->bitmap
.tex_format
= PIPE_FORMAT_I8_UNORM
;
710 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_A8_UNORM
,
712 PIPE_BIND_SAMPLER_VIEW
)) {
713 st
->bitmap
.tex_format
= PIPE_FORMAT_A8_UNORM
;
715 else if (screen
->is_format_supported(screen
, PIPE_FORMAT_L8_UNORM
,
717 PIPE_BIND_SAMPLER_VIEW
)) {
718 st
->bitmap
.tex_format
= PIPE_FORMAT_L8_UNORM
;
721 /* XXX support more formats */
725 /* alloc bitmap cache object */
726 st
->bitmap
.cache
= ST_CALLOC_STRUCT(bitmap_cache
);
732 /** Per-context tear-down */
734 st_destroy_bitmap(struct st_context
*st
)
736 struct pipe_context
*pipe
= st
->pipe
;
737 struct bitmap_cache
*cache
= st
->bitmap
.cache
;
740 cso_delete_vertex_shader(st
->cso_context
, st
->bitmap
.vs
);
741 st
->bitmap
.vs
= NULL
;
745 if (cache
->trans
&& cache
->buffer
) {
746 pipe_transfer_unmap(pipe
, cache
->trans
);
748 pipe_resource_reference(&st
->bitmap
.cache
->texture
, NULL
);
749 free(st
->bitmap
.cache
);
750 st
->bitmap
.cache
= NULL
;